ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderLaserRelay.java

93 lines
4.7 KiB
Java
Raw Normal View History

package de.ellpeck.actuallyadditions.mod.blocks.render;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.laser.IConnectionPair;
import de.ellpeck.actuallyadditions.api.laser.LaserType;
import de.ellpeck.actuallyadditions.mod.config.ConfigValues;
2017-02-13 17:36:55 +01:00
import de.ellpeck.actuallyadditions.mod.items.InitItems;
2017-02-14 18:18:38 +01:00
import de.ellpeck.actuallyadditions.mod.items.ItemEngineerGoggles;
import de.ellpeck.actuallyadditions.mod.items.ItemLaserWrench;
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;
import io.netty.util.internal.ConcurrentSet;
2017-02-13 17:36:55 +01:00
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
2017-02-14 18:18:38 +01:00
import net.minecraft.entity.player.EntityPlayer;
2017-02-13 17:36:55 +01:00
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
2019-05-02 09:10:29 +02:00
public class RenderLaserRelay extends TileEntitySpecialRenderer<TileEntityLaserRelay> {
2019-05-02 09:10:29 +02:00
private static final float[] COLOR = new float[] { 1F, 0F, 0F };
private static final float[] COLOR_ITEM = new float[] { 0F, 124F / 255F, 16F / 255F };
private static final float[] COLOR_FLUIDS = new float[] { 0F, 97F / 255F, 198F / 255F };
private static final float[] COLOR_INFRARED = new float[] { 209F / 255F, 179F / 255F, 239F / 255F };
@Override
2019-05-02 09:10:29 +02:00
public void render(TileEntityLaserRelay tile, double x, double y, double z, float par5, int par6, float f) {
if (tile instanceof TileEntityLaserRelay) {
2019-02-27 19:53:05 +01:00
TileEntityLaserRelay relay = tile;
2017-02-13 17:36:55 +01:00
boolean hasInvis = false;
2017-02-14 18:18:38 +01:00
EntityPlayer player = Minecraft.getMinecraft().player;
boolean hasGoggles = ItemEngineerGoggles.isWearing(player);
2017-02-13 17:36:55 +01:00
ItemStack upgrade = relay.inv.getStackInSlot(0);
2019-05-02 09:10:29 +02:00
if (StackUtil.isValid(upgrade)) {
if (upgrade.getItem() == InitItems.itemLaserUpgradeInvisibility) {
2017-02-13 17:36:55 +01:00
hasInvis = true;
}
2017-02-14 18:18:38 +01:00
ItemStack hand = player.getHeldItemMainhand();
2019-05-02 09:10:29 +02:00
if (hasGoggles || StackUtil.isValid(hand) && (hand.getItem() == ConfigValues.itemCompassConfigurator || hand.getItem() instanceof ItemLaserWrench) || "themattabase".equals(player.getName())) {
2017-02-14 18:18:38 +01:00
GlStateManager.pushMatrix();
2017-02-13 17:36:55 +01:00
2017-02-14 18:18:38 +01:00
float yTrans = tile.getBlockMetadata() == 0 ? 0.2F : 0.8F;
2019-05-02 09:10:29 +02:00
GlStateManager.translate((float) x + 0.5F, (float) y + yTrans, (float) z + 0.5F);
2017-02-14 18:18:38 +01:00
GlStateManager.scale(0.2F, 0.2F, 0.2F);
2017-02-13 17:36:55 +01:00
2019-05-02 09:10:29 +02:00
double boop = Minecraft.getSystemTime() / 800D;
GlStateManager.rotate((float) (boop * 40D % 360), 0, 1, 0);
2017-02-13 17:36:55 +01:00
2017-02-14 18:18:38 +01:00
AssetUtil.renderItemInWorld(upgrade);
2017-02-13 17:36:55 +01:00
2017-02-14 18:18:38 +01:00
GlStateManager.popMatrix();
}
2017-02-13 17:36:55 +01:00
}
ConcurrentSet<IConnectionPair> connections = ActuallyAdditionsAPI.connectionHandler.getConnectionsFor(tile.getPos(), tile.getWorld());
2019-05-02 09:10:29 +02:00
if (connections != null && !connections.isEmpty()) {
for (IConnectionPair pair : connections) {
if (!pair.doesSuppressRender() && tile.getPos().equals(pair.getPositions()[0])) {
BlockPos first = tile.getPos();
BlockPos second = pair.getPositions()[1];
2017-02-13 17:36:55 +01:00
TileEntity secondTile = tile.getWorld().getTileEntity(second);
2019-05-02 09:10:29 +02:00
if (secondTile instanceof TileEntityLaserRelay) {
ItemStack secondUpgrade = ((TileEntityLaserRelay) secondTile).inv.getStackInSlot(0);
2017-02-13 17:36:55 +01:00
boolean otherInvis = StackUtil.isValid(secondUpgrade) && secondUpgrade.getItem() == InitItems.itemLaserUpgradeInvisibility;
2019-05-02 09:10:29 +02:00
if (hasGoggles || !hasInvis || !otherInvis) {
2019-02-27 19:53:05 +01:00
float[] color = hasInvis && otherInvis ? COLOR_INFRARED : relay.type == LaserType.ITEM ? COLOR_ITEM : relay.type == LaserType.FLUID ? COLOR_FLUIDS : COLOR;
2017-02-13 17:36:55 +01:00
2019-05-02 09:10:29 +02:00
AssetUtil.renderLaser(first.getX() + 0.5, first.getY() + 0.5, first.getZ() + 0.5, second.getX() + 0.5, second.getY() + 0.5, second.getZ() + 0.5, 120, hasInvis && otherInvis ? 0.1F : 0.35F, 0.05, color);
2017-02-13 17:36:55 +01:00
}
}
}
}
}
}
}
@Override
2019-05-02 09:10:29 +02:00
public boolean isGlobalRenderer(TileEntityLaserRelay tile) {
return true;
}
}