2016-11-08 08:53:30 +01:00
|
|
|
/*
|
|
|
|
* This file ("RenderLaserRelay.java") is part of the Actually Additions mod for Minecraft.
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
|
|
|
* http://ellpeck.de/actaddlicense
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2016-11-08 08:53:30 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
package de.ellpeck.actuallyadditions.mod.blocks.render;
|
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
import com.mojang.blaze3d.vertex.PoseStack;
|
2024-03-03 01:20:53 +01:00
|
|
|
import com.mojang.math.Axis;
|
2016-11-08 08:53:30 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.laser.IConnectionPair;
|
|
|
|
import de.ellpeck.actuallyadditions.api.laser.LaserType;
|
2023-11-26 23:10:19 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.config.CommonConfig;
|
2021-03-01 21:23:52 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.items.ActuallyItems;
|
2017-02-14 18:18:38 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.items.ItemEngineerGoggles;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.items.ItemLaserWrench;
|
2016-11-08 08:53:30 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelay;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
2017-02-13 17:36:55 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
2016-11-08 08:53:30 +01:00
|
|
|
import io.netty.util.internal.ConcurrentSet;
|
2024-03-02 21:23:08 +01:00
|
|
|
import net.minecraft.Util;
|
2017-02-13 17:36:55 +01:00
|
|
|
import net.minecraft.client.Minecraft;
|
2024-03-02 21:23:08 +01:00
|
|
|
import net.minecraft.client.renderer.MultiBufferSource;
|
|
|
|
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
|
|
|
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
import net.minecraft.core.Direction;
|
|
|
|
import net.minecraft.world.entity.player.Player;
|
|
|
|
import net.minecraft.world.item.ItemStack;
|
|
|
|
import net.minecraft.world.level.block.Rotation;
|
|
|
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
|
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
|
|
|
import net.minecraft.world.phys.Vec3;
|
|
|
|
|
|
|
|
public class RenderLaserRelay implements BlockEntityRenderer<TileEntityLaserRelay> {
|
2016-11-08 08:53:30 +01:00
|
|
|
|
2023-01-19 16:27:56 +01:00
|
|
|
private static final int COLOR = 16711680;
|
|
|
|
private static final int COLOR_ITEM = 31760;
|
|
|
|
private static final int COLOR_FLUIDS = 25030;
|
|
|
|
private static final int COLOR_INFRARED = 13743087;
|
2016-11-08 08:53:30 +01:00
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
public RenderLaserRelay(BlockEntityRendererProvider.Context context) {
|
2021-02-28 11:35:10 +01:00
|
|
|
}
|
|
|
|
|
2016-11-08 08:53:30 +01:00
|
|
|
@Override
|
2024-03-02 21:23:08 +01:00
|
|
|
public void render(TileEntityLaserRelay tile, float partialTicks, PoseStack matrices, MultiBufferSource buffer, int combinedLight, int combinedOverlay) {
|
2021-02-28 11:35:10 +01:00
|
|
|
TileEntityLaserRelay relay = tile;
|
2023-01-19 16:27:56 +01:00
|
|
|
BlockState state = tile.getBlockState();
|
2021-02-28 11:35:10 +01:00
|
|
|
boolean hasInvis = false;
|
2017-02-13 17:36:55 +01:00
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
Player player = Minecraft.getInstance().player;
|
2021-02-28 11:35:10 +01:00
|
|
|
boolean hasGoggles = ItemEngineerGoggles.isWearing(player);
|
2017-02-13 17:36:55 +01:00
|
|
|
|
2021-02-28 11:35:10 +01:00
|
|
|
ItemStack upgrade = relay.inv.getStackInSlot(0);
|
|
|
|
if (StackUtil.isValid(upgrade)) {
|
2021-05-02 18:10:21 +02:00
|
|
|
if (upgrade.getItem() == ActuallyItems.LASER_UPGRADE_INVISIBILITY.get()) {
|
2021-02-28 11:35:10 +01:00
|
|
|
hasInvis = true;
|
|
|
|
}
|
2017-02-13 17:36:55 +01:00
|
|
|
|
2021-08-22 17:09:06 +02:00
|
|
|
ItemStack hand = player.getMainHandItem();
|
2023-11-26 23:10:19 +01:00
|
|
|
if (hasGoggles || StackUtil.isValid(hand) && (hand.getItem() == CommonConfig.Other.relayConfigureItem || hand.getItem() instanceof ItemLaserWrench) || "themattabase".equals(player.getName().getString())) {
|
2021-08-22 17:09:06 +02:00
|
|
|
matrices.pushPose();
|
2023-01-19 16:27:56 +01:00
|
|
|
Direction direction = state.hasProperty(BlockStateProperties.FACING) ?
|
|
|
|
state.getValue(BlockStateProperties.FACING) : Direction.UP;
|
2017-02-13 17:36:55 +01:00
|
|
|
|
2023-01-19 16:27:56 +01:00
|
|
|
float yTrans = direction.getAxis() == Direction.Axis.Y ? 0.2f : 0.8F; //tile.getBlockMetadata() == 0 ? 0.2F : 0.8F; // TODO: [port][fix] no clue what this is
|
2021-02-28 11:35:10 +01:00
|
|
|
matrices.translate(0.5F, yTrans, 0.5F);
|
|
|
|
matrices.scale(0.2F, 0.2F, 0.2F);
|
2017-02-13 17:36:55 +01:00
|
|
|
|
2021-08-22 17:09:06 +02:00
|
|
|
double boop = Util.getMillis() / 800D;
|
2024-03-03 01:20:53 +01:00
|
|
|
matrices.mulPose(Axis.YP.rotationDegrees((float) (boop * 40D % 360)));
|
2021-02-28 11:35:10 +01:00
|
|
|
|
|
|
|
AssetUtil.renderItemInWorld(upgrade, combinedLight, combinedOverlay, matrices, buffer);
|
|
|
|
|
2021-08-22 17:09:06 +02:00
|
|
|
matrices.popPose();
|
2017-02-13 17:36:55 +01:00
|
|
|
}
|
2021-02-28 11:35:10 +01:00
|
|
|
}
|
2017-02-13 17:36:55 +01:00
|
|
|
|
2023-01-19 16:27:56 +01:00
|
|
|
ConcurrentSet<IConnectionPair> connections = tile.getConnections();
|
2021-02-28 11:35:10 +01:00
|
|
|
if (connections != null && !connections.isEmpty()) {
|
|
|
|
for (IConnectionPair pair : connections) {
|
2021-08-22 17:09:06 +02:00
|
|
|
if (!pair.doesSuppressRender() && tile.getBlockPos().equals(pair.getPositions()[0])) {
|
|
|
|
BlockPos first = tile.getBlockPos();
|
2021-02-28 11:35:10 +01:00
|
|
|
BlockPos second = pair.getPositions()[1];
|
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
BlockEntity secondTile = tile.getLevel().getBlockEntity(second);
|
2021-02-28 11:35:10 +01:00
|
|
|
if (secondTile instanceof TileEntityLaserRelay) {
|
|
|
|
ItemStack secondUpgrade = ((TileEntityLaserRelay) secondTile).inv.getStackInSlot(0);
|
2021-05-02 18:10:21 +02:00
|
|
|
boolean otherInvis = StackUtil.isValid(secondUpgrade) && secondUpgrade.getItem() == ActuallyItems.LASER_UPGRADE_INVISIBILITY.get();
|
2021-02-28 11:35:10 +01:00
|
|
|
|
|
|
|
if (hasGoggles || !hasInvis || !otherInvis) {
|
2023-01-19 16:27:56 +01:00
|
|
|
int color = hasInvis && otherInvis
|
|
|
|
? COLOR_INFRARED : relay.type == LaserType.ITEM
|
|
|
|
? COLOR_ITEM : relay.type == LaserType.FLUID
|
|
|
|
? COLOR_FLUIDS : COLOR;
|
|
|
|
|
|
|
|
BlockPos offsetStart = first.subtract(tile.getBlockPos());
|
|
|
|
BlockPos offsetEnd = second.subtract(tile.getBlockPos());
|
|
|
|
offsetEnd = offsetEnd.rotate(Rotation.CLOCKWISE_90);
|
|
|
|
|
|
|
|
matrices.pushPose();
|
|
|
|
|
|
|
|
AssetUtil.renderLaser(matrices, buffer,
|
2024-03-02 21:23:08 +01:00
|
|
|
new Vec3(offsetStart.getX(), offsetStart.getY(), offsetStart.getZ()),
|
|
|
|
new Vec3(offsetEnd.getX(), offsetEnd.getY(), offsetEnd.getZ()),
|
2023-01-19 16:27:56 +01:00
|
|
|
120, color,
|
|
|
|
hasInvis && otherInvis
|
|
|
|
? 0.1F
|
|
|
|
: 0.35F, 0.05F);
|
|
|
|
|
|
|
|
matrices.popPose();
|
2017-02-13 17:36:55 +01:00
|
|
|
}
|
2016-11-08 08:53:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-14 15:30:06 +01:00
|
|
|
|
|
|
|
@Override
|
2021-08-22 17:09:06 +02:00
|
|
|
public boolean shouldRenderOffScreen(TileEntityLaserRelay tile) {
|
2016-11-14 15:30:06 +01:00
|
|
|
return true;
|
|
|
|
}
|
2016-11-08 08:53:30 +01:00
|
|
|
}
|