From f520c87d94d082b33ab3df55712541bcb4833728 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 26 Oct 2015 22:28:49 +0100 Subject: [PATCH] Added Laser Relay Renderer. Differently than originally planned, but it works and looks nice. Thanks to xdjackiexd though --- .../blocks/render/ModelLaserRelay.java | 21 ----- .../blocks/render/RenderLaserRelay.java | 5 -- .../items/ItemLaserWrench.java | 1 + .../items/ItemPhantomConnector.java | 2 +- .../tile/TileEntityLaserRelay.java | 83 +++++-------------- .../actuallyadditions/util/WorldPos.java | 5 ++ 6 files changed, 28 insertions(+), 89 deletions(-) diff --git a/src/main/java/ellpeck/actuallyadditions/blocks/render/ModelLaserRelay.java b/src/main/java/ellpeck/actuallyadditions/blocks/render/ModelLaserRelay.java index ac9b60b27..063fe66c7 100644 --- a/src/main/java/ellpeck/actuallyadditions/blocks/render/ModelLaserRelay.java +++ b/src/main/java/ellpeck/actuallyadditions/blocks/render/ModelLaserRelay.java @@ -10,15 +10,9 @@ package ellpeck.actuallyadditions.blocks.render; -import ellpeck.actuallyadditions.misc.LaserRelayConnectionHandler; -import ellpeck.actuallyadditions.tile.TileEntityLaserRelay; -import ellpeck.actuallyadditions.util.WorldPos; import net.minecraft.client.model.ModelRenderer; -import net.minecraft.tileentity.TileEntity; import org.lwjgl.opengl.GL11; -import java.util.ArrayList; - /** * Made by Canitzp. * Thanks. Seriously. It looks really awesome. I don't think I could do this. @@ -185,21 +179,6 @@ public class ModelLaserRelay extends ModelBaseAA{ return "modelLaserRelay"; } - @Override - public void renderExtra(float f, TileEntity tile){ - TileEntityLaserRelay relay = (TileEntityLaserRelay)tile; - WorldPos firstWP = new WorldPos(relay.getWorldObj(), relay.xCoord, relay.yCoord, relay.zCoord); - ArrayList network = LaserRelayConnectionHandler.getInstance().getNetworkFor(firstWP); - if(network != null){ - for(LaserRelayConnectionHandler.ConnectionPair aPair : network){ - TileEntityLaserRelay firstRelay = (TileEntityLaserRelay) aPair.firstRelay.getTileEntity(); - if(aPair.contains(firstWP) && aPair.firstRelay.isEqual(firstWP)){ - firstRelay.drawLine(aPair.firstRelay, aPair.secondRelay); - } - } - } - } - @Override public boolean doesRotate(){ return true; diff --git a/src/main/java/ellpeck/actuallyadditions/blocks/render/RenderLaserRelay.java b/src/main/java/ellpeck/actuallyadditions/blocks/render/RenderLaserRelay.java index e65b9524a..b80383699 100644 --- a/src/main/java/ellpeck/actuallyadditions/blocks/render/RenderLaserRelay.java +++ b/src/main/java/ellpeck/actuallyadditions/blocks/render/RenderLaserRelay.java @@ -11,7 +11,6 @@ package ellpeck.actuallyadditions.blocks.render; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; @@ -54,11 +53,7 @@ public class RenderLaserRelay extends RenderTileEntity{ } theModel.render(0.0625F); - //A Random texture, so it is a smooth Laser! - bindTexture(new ResourceLocation("actuallyadditions:textures/blocks/blockBreaker.png")); - theModel.renderExtra(0.0625F, tile); GL11.glPopMatrix(); - } } diff --git a/src/main/java/ellpeck/actuallyadditions/items/ItemLaserWrench.java b/src/main/java/ellpeck/actuallyadditions/items/ItemLaserWrench.java index c556a4ffd..ed2d05d5e 100644 --- a/src/main/java/ellpeck/actuallyadditions/items/ItemLaserWrench.java +++ b/src/main/java/ellpeck/actuallyadditions/items/ItemLaserWrench.java @@ -60,6 +60,7 @@ public class ItemLaserWrench extends Item implements IActAddItemOrBlock{ } else{ player.addChatComponentMessage(new ChatComponentText(StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".laser.cantConnect.desc"))); + ItemPhantomConnector.clearStorage(stack); } } } diff --git a/src/main/java/ellpeck/actuallyadditions/items/ItemPhantomConnector.java b/src/main/java/ellpeck/actuallyadditions/items/ItemPhantomConnector.java index 546ff22a9..8eded08e5 100644 --- a/src/main/java/ellpeck/actuallyadditions/items/ItemPhantomConnector.java +++ b/src/main/java/ellpeck/actuallyadditions/items/ItemPhantomConnector.java @@ -83,7 +83,7 @@ public class ItemPhantomConnector extends Item implements IActAddItemOrBlock{ int y = tag.getInteger("YCoordOfTileStored"); int z = tag.getInteger("ZCoordOfTileStored"); World world = DimensionManager.getWorld(tag.getInteger("WorldOfTileStored")); - if(x != 0 && y != 0 && z != 0 && world != null){ + if(!(x == 0 && y == 0 && z == 0) && world != null){ return new WorldPos(world, x, y, z); } } diff --git a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityLaserRelay.java b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityLaserRelay.java index ff0910afe..8de4be113 100644 --- a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityLaserRelay.java +++ b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityLaserRelay.java @@ -13,20 +13,16 @@ package ellpeck.actuallyadditions.tile; import cofh.api.energy.IEnergyReceiver; import ellpeck.actuallyadditions.misc.LaserRelayConnectionHandler; import ellpeck.actuallyadditions.util.WorldPos; -import net.minecraft.client.Minecraft; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; import net.minecraft.network.Packet; import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraftforge.common.util.ForgeDirection; -import org.lwjgl.opengl.GL11; import java.util.ArrayList; public class TileEntityLaserRelay extends TileEntityBase implements IEnergyReceiver{ - private GLColor laserColor = GLColor.RED_PURE; - @Override public void invalidate(){ super.invalidate(); @@ -36,8 +32,27 @@ public class TileEntityLaserRelay extends TileEntityBase implements IEnergyRecei } @Override - public boolean canUpdate(){ - return false; + public void updateEntity(){ + if(this.worldObj.isRemote){ + if(this.worldObj.rand.nextInt(4) == 0){ + WorldPos thisPos = new WorldPos(this.getWorldObj(), this.xCoord, this.yCoord, this.zCoord); + ArrayList network = LaserRelayConnectionHandler.getInstance().getNetworkFor(thisPos); + if(network != null){ + for(LaserRelayConnectionHandler.ConnectionPair aPair : network){ + if(aPair.contains(thisPos) && thisPos.isEqual(aPair.firstRelay)){ + int difX = aPair.firstRelay.getX()-aPair.secondRelay.getX(); + int difY = aPair.firstRelay.getY()-aPair.secondRelay.getY(); + int difZ = aPair.firstRelay.getZ()-aPair.secondRelay.getZ(); + + double distance = aPair.firstRelay.toVec().distanceTo(aPair.secondRelay.toVec()); + for(double i = 0; i <= 1; i += 1/(distance*4)){ + this.worldObj.spawnParticle("reddust", (difX*i)+aPair.secondRelay.getX()+0.5, (difY*i)+aPair.secondRelay.getY()+0.5, (difZ*i)+aPair.secondRelay.getZ()+0.5, 0, 0, 0); + } + } + } + } + } + } } @Override @@ -100,60 +115,4 @@ public class TileEntityLaserRelay extends TileEntityBase implements IEnergyRecei public boolean canConnectEnergy(ForgeDirection from){ return true; } - - public void drawLine(WorldPos firstPos, WorldPos secondPos){ - double x = firstPos.getX() - secondPos.getX(); - double y = firstPos.getY() - secondPos.getY() + 1; - double z = -(firstPos.getZ() - secondPos.getZ()); - double relativePlayerBlockLocation = Minecraft.getMinecraft().thePlayer.posY - firstPos.getY(); - float f; - if(relativePlayerBlockLocation < 10) f=5; - else if(relativePlayerBlockLocation < 20 && relativePlayerBlockLocation > 10) f = 4; - else if(relativePlayerBlockLocation < 30 && relativePlayerBlockLocation > 20) f = 3; - else if(relativePlayerBlockLocation < 40 && relativePlayerBlockLocation > 30) f = 2; - else if(relativePlayerBlockLocation < 50 && relativePlayerBlockLocation > 40) f = 1; - else f=1; - GL11.glPushMatrix(); - GL11.glLineWidth(f); - GL11.glBegin(GL11.GL_LINE_STRIP); - { - GL11.glColor3f(this.laserColor.getRed(), this.laserColor.getGreen(), this.laserColor.getBlue()); - GL11.glVertex3d(x, y, z); - GL11.glVertex3d(0, 1, 0); - } - GL11.glEnd(); - GL11.glLineWidth(1); - GL11.glPopMatrix(); - } - - public void changeLineColor(GLColor color){this.laserColor = color;} - - - //Colors for the Laser: - public enum GLColor{ - - RED_PURE(1.0F, 0, 0), - GREEN_PURE(0, 1.0F, 0), - BLUE_PURE(0, 0, 1.0F), - DARK_YELLOW(1, 1, 0); - - private float red, green, blue; - GLColor(float red, float green, float blue){ - this.red = red; - this.green = green; - this.blue = blue; - } - - public float getRed() { - return red; - } - - public float getGreen() { - return green; - } - - public float getBlue() { - return blue; - } - } } diff --git a/src/main/java/ellpeck/actuallyadditions/util/WorldPos.java b/src/main/java/ellpeck/actuallyadditions/util/WorldPos.java index be5b6f6c1..883fdb591 100644 --- a/src/main/java/ellpeck/actuallyadditions/util/WorldPos.java +++ b/src/main/java/ellpeck/actuallyadditions/util/WorldPos.java @@ -14,6 +14,7 @@ import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.item.Item; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.Vec3; import net.minecraft.world.World; import net.minecraftforge.common.DimensionManager; @@ -84,4 +85,8 @@ public class WorldPos{ public String toString(){ return "["+this.x+", "+this.y+", "+this.z+" in world "+this.worldID+"]"; } + + public Vec3 toVec(){ + return Vec3.createVectorHelper(this.x, this.y, this.z); + } }