From 79866e2b2e34277943f134ff63eba97b60b63b0d Mon Sep 17 00:00:00 2001 From: Calclavia Date: Tue, 6 Aug 2013 19:46:08 -0400 Subject: [PATCH] Got wires working --- .../{items => blocks}/wire.aluminum.png | Bin .../{items => blocks}/wire.copper.png | Bin .../textures/{items => blocks}/wire.iron.png | Bin .../{items => blocks}/wire.silver.png | Bin .../{items => blocks}/wire.superconductor.png | Bin .../textures/{items => blocks}/wire.tin.png | Bin .../textures/models/wireCopper.png | Bin 0 -> 798 bytes src/resonantinduction/ClientProxy.java | 5 +- src/resonantinduction/ResonantInduction.java | 5 +- .../contractor/PathfinderEMContractor.java | 16 +-- .../entangler/ItemCoordLink.java | 15 +- .../model/ModelCopperWire.java | 130 ++++++++++++++++++ src/resonantinduction/render/RenderWire.java | 128 +++++++++++++++++ src/resonantinduction/wire/BlockWire.java | 15 ++ src/resonantinduction/wire/EnumWire.java | 3 +- src/resonantinduction/wire/ItemBlockWire.java | 4 +- 16 files changed, 296 insertions(+), 25 deletions(-) rename resources/assets/resonantinduction/textures/{items => blocks}/wire.aluminum.png (100%) rename resources/assets/resonantinduction/textures/{items => blocks}/wire.copper.png (100%) rename resources/assets/resonantinduction/textures/{items => blocks}/wire.iron.png (100%) rename resources/assets/resonantinduction/textures/{items => blocks}/wire.silver.png (100%) rename resources/assets/resonantinduction/textures/{items => blocks}/wire.superconductor.png (100%) rename resources/assets/resonantinduction/textures/{items => blocks}/wire.tin.png (100%) create mode 100644 resources/assets/resonantinduction/textures/models/wireCopper.png create mode 100644 src/resonantinduction/model/ModelCopperWire.java create mode 100644 src/resonantinduction/render/RenderWire.java diff --git a/resources/assets/resonantinduction/textures/items/wire.aluminum.png b/resources/assets/resonantinduction/textures/blocks/wire.aluminum.png similarity index 100% rename from resources/assets/resonantinduction/textures/items/wire.aluminum.png rename to resources/assets/resonantinduction/textures/blocks/wire.aluminum.png diff --git a/resources/assets/resonantinduction/textures/items/wire.copper.png b/resources/assets/resonantinduction/textures/blocks/wire.copper.png similarity index 100% rename from resources/assets/resonantinduction/textures/items/wire.copper.png rename to resources/assets/resonantinduction/textures/blocks/wire.copper.png diff --git a/resources/assets/resonantinduction/textures/items/wire.iron.png b/resources/assets/resonantinduction/textures/blocks/wire.iron.png similarity index 100% rename from resources/assets/resonantinduction/textures/items/wire.iron.png rename to resources/assets/resonantinduction/textures/blocks/wire.iron.png diff --git a/resources/assets/resonantinduction/textures/items/wire.silver.png b/resources/assets/resonantinduction/textures/blocks/wire.silver.png similarity index 100% rename from resources/assets/resonantinduction/textures/items/wire.silver.png rename to resources/assets/resonantinduction/textures/blocks/wire.silver.png diff --git a/resources/assets/resonantinduction/textures/items/wire.superconductor.png b/resources/assets/resonantinduction/textures/blocks/wire.superconductor.png similarity index 100% rename from resources/assets/resonantinduction/textures/items/wire.superconductor.png rename to resources/assets/resonantinduction/textures/blocks/wire.superconductor.png diff --git a/resources/assets/resonantinduction/textures/items/wire.tin.png b/resources/assets/resonantinduction/textures/blocks/wire.tin.png similarity index 100% rename from resources/assets/resonantinduction/textures/items/wire.tin.png rename to resources/assets/resonantinduction/textures/blocks/wire.tin.png diff --git a/resources/assets/resonantinduction/textures/models/wireCopper.png b/resources/assets/resonantinduction/textures/models/wireCopper.png new file mode 100644 index 0000000000000000000000000000000000000000..c92754d8aef86b6595fc196afaf764fd2791eb1a GIT binary patch literal 798 zcmV+(1L6FMP)004R= z004l4008;_004mL004C`008P>0026e000+nl3&F}00009a7bBm000iZ000iZ0XPLy zBme*a8gxZibW?9;ba!ELWdKlNX>N2bPDNB8b~7$DE-^4L^m3s900MqVL_t(&L+zMr zY63A7g9m>jVH)p10tS$D>11m|v|{*9aJmMm_={gT1U~u5|(cA9`Kj z&*yV80WndKLUQsm3VF1E+mHwR>2&e}0hi0g3;o04P)Z11#q07s8UpaRjR5wrIK6!BDyhM4AX8!G^@S!gP zR4X6>se>cg#u6YBLhyJVv19=LUIYl7&3Q!tfY}@HB8f;)1fY2ioeZwdgJqs40tD8E zy!AZbu`AodrhwY2{&l|we?~wZlCn)^;2$zT4qDMEE#JY+L+NMQS1lR&667_6Zag}{afsKj8 zQd@yjnA?}PRoeoc*cKqVfItFmfH7`?F^<<|Ya>7vUJ;;NE{ekEIhP#TXwA{KeT}0V zgNj+e-of?XoGP@f*kKAN0u=f-e{bcv^>mo`b?ZwEwrraj$P8o#G6R``%s^%!Gmsg` c4BTYk3usN|`Kgy1+W-In07*qoM6N<$f~@mmjQ{`u literal 0 HcmV?d00001 diff --git a/src/resonantinduction/ClientProxy.java b/src/resonantinduction/ClientProxy.java index 1c2b2c3bc..1b071a566 100644 --- a/src/resonantinduction/ClientProxy.java +++ b/src/resonantinduction/ClientProxy.java @@ -16,7 +16,9 @@ import resonantinduction.render.RenderBattery; import resonantinduction.render.RenderEMContractor; import resonantinduction.render.RenderMultimeter; import resonantinduction.render.RenderTesla; +import resonantinduction.render.RenderWire; import resonantinduction.tesla.TileEntityTesla; +import resonantinduction.wire.TileEntityWire; import universalelectricity.core.vector.Vector3; import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.client.registry.ClientRegistry; @@ -37,11 +39,12 @@ public class ClientProxy extends CommonProxy MinecraftForge.EVENT_BUS.register(SoundHandler.INSTANCE); RenderingRegistry.registerBlockHandler(BlockRenderingHandler.INSTANCE); - + ClientRegistry.bindTileEntitySpecialRenderer(TileEntityTesla.class, new RenderTesla()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityMultimeter.class, new RenderMultimeter()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityEMContractor.class, new RenderEMContractor()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityBattery.class, new RenderBattery()); + ClientRegistry.bindTileEntitySpecialRenderer(TileEntityWire.class, new RenderWire()); } @Override diff --git a/src/resonantinduction/ResonantInduction.java b/src/resonantinduction/ResonantInduction.java index 0b7976586..29d9e1ac9 100644 --- a/src/resonantinduction/ResonantInduction.java +++ b/src/resonantinduction/ResonantInduction.java @@ -28,6 +28,7 @@ import resonantinduction.tesla.BlockTesla; import resonantinduction.tesla.TileEntityTesla; import resonantinduction.wire.BlockWire; import resonantinduction.wire.ItemBlockWire; +import resonantinduction.wire.TileEntityWire; import universalelectricity.core.item.IItemElectric; import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.Loader; @@ -154,7 +155,6 @@ public class ResonantInduction itemCapacitor = new ItemCapacitor(getNextItemID()); itemLinker = new ItemLinker(getNextItemID()); - // Blocks blockTesla = new BlockTesla(getNextBlockID()); blockMultimeter = new BlockMultimeter(getNextBlockID()); @@ -167,7 +167,7 @@ public class ResonantInduction GameRegistry.registerItem(itemQuantumEntangler, itemQuantumEntangler.getUnlocalizedName()); GameRegistry.registerItem(itemCapacitor, itemCapacitor.getUnlocalizedName()); GameRegistry.registerItem(itemLinker, itemLinker.getUnlocalizedName()); - + GameRegistry.registerBlock(blockTesla, blockTesla.getUnlocalizedName()); GameRegistry.registerBlock(blockMultimeter, ItemBlockMultimeter.class, blockMultimeter.getUnlocalizedName()); GameRegistry.registerBlock(blockEMContractor, ItemBlockContractor.class, blockEMContractor.getUnlocalizedName()); @@ -179,6 +179,7 @@ public class ResonantInduction GameRegistry.registerTileEntity(TileEntityMultimeter.class, blockMultimeter.getUnlocalizedName()); GameRegistry.registerTileEntity(TileEntityEMContractor.class, blockEMContractor.getUnlocalizedName()); GameRegistry.registerTileEntity(TileEntityBattery.class, blockBattery.getUnlocalizedName()); + GameRegistry.registerTileEntity(TileEntityWire.class, blockWire.getUnlocalizedName()); ResonantInduction.proxy.registerRenderers(); diff --git a/src/resonantinduction/contractor/PathfinderEMContractor.java b/src/resonantinduction/contractor/PathfinderEMContractor.java index bbe62a1fe..333024bc3 100644 --- a/src/resonantinduction/contractor/PathfinderEMContractor.java +++ b/src/resonantinduction/contractor/PathfinderEMContractor.java @@ -21,13 +21,13 @@ import universalelectricity.core.vector.Vector3; */ public class PathfinderEMContractor { - public Set openSet, closedSet; + public final Set openSet, closedSet; - public HashMap navMap; + public final HashMap navMap; - public HashMap gScore, fScore; + public final HashMap gScore, fScore; - public Vector3 target; + public final Vector3 target; public List results; @@ -37,10 +37,7 @@ public class PathfinderEMContractor { this.world = world; this.target = target; - } - public boolean find(Vector3 start) - { /** * Instantiate Variables */ @@ -50,9 +47,12 @@ public class PathfinderEMContractor this.gScore = new HashMap(); this.fScore = new HashMap(); this.results = new ArrayList(); + } + public boolean find(Vector3 start) + { this.openSet.add(start); - this.gScore.put(start, (double) 0); + this.gScore.put(start, 0d); this.fScore.put(start, this.gScore.get(start) + getEstimate(start, this.target)); int blockCount = 0; diff --git a/src/resonantinduction/entangler/ItemCoordLink.java b/src/resonantinduction/entangler/ItemCoordLink.java index ab2c99bb8..6569adcef 100644 --- a/src/resonantinduction/entangler/ItemCoordLink.java +++ b/src/resonantinduction/entangler/ItemCoordLink.java @@ -51,28 +51,21 @@ public abstract class ItemCoordLink extends ItemBase public Vector3 getLink(ItemStack itemStack) { - if (itemStack.stackTagCompound == null || !(itemStack.getTagCompound().hasKey("bindX") && itemStack.getTagCompound().hasKey("bindY") && itemStack.getTagCompound().hasKey("bindZ"))) + if (itemStack.stackTagCompound == null || !itemStack.getTagCompound().hasKey("position")) { return null; } - - int x = itemStack.stackTagCompound.getInteger("bindX"); - int y = itemStack.stackTagCompound.getInteger("bindY"); - int z = itemStack.stackTagCompound.getInteger("bindZ"); - - return new Vector3(x, y, z); + return new Vector3(itemStack.getTagCompound().getCompoundTag("position")); } public void setLink(ItemStack itemStack, Vector3 vec, int dimID) { - if (itemStack.stackTagCompound == null) + if (itemStack.getTagCompound() == null) { itemStack.setTagCompound(new NBTTagCompound()); } - itemStack.stackTagCompound.setInteger("bindX", (int) vec.x); - itemStack.stackTagCompound.setInteger("bindY", (int) vec.y); - itemStack.stackTagCompound.setInteger("bindZ", (int) vec.z); + itemStack.getTagCompound().setCompoundTag("position", vec.writeToNBT(new NBTTagCompound())); itemStack.stackTagCompound.setInteger("dimID", dimID); } diff --git a/src/resonantinduction/model/ModelCopperWire.java b/src/resonantinduction/model/ModelCopperWire.java new file mode 100644 index 000000000..cf9f14746 --- /dev/null +++ b/src/resonantinduction/model/ModelCopperWire.java @@ -0,0 +1,130 @@ +package resonantinduction.model; + +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; +import net.minecraft.entity.Entity; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class ModelCopperWire extends ModelBase +{ + // fields + ModelRenderer Middle; + ModelRenderer Right; + ModelRenderer Left; + ModelRenderer Back; + ModelRenderer Front; + ModelRenderer Top; + ModelRenderer Bottom; + + public ModelCopperWire() + { + textureWidth = 64; + textureHeight = 32; + Middle = new ModelRenderer(this, 0, 0); + Middle.addBox(-1F, -1F, -1F, 4, 4, 4); + Middle.setRotationPoint(-1F, 15F, -1F); + Middle.setTextureSize(64, 32); + Middle.mirror = true; + setRotation(Middle, 0F, 0F, 0F); + Right = new ModelRenderer(this, 21, 0); + Right.addBox(0F, 0F, 0F, 6, 4, 4); + Right.setRotationPoint(2F, 14F, -2F); + Right.setTextureSize(64, 32); + Right.mirror = true; + setRotation(Right, 0F, 0F, 0F); + Left = new ModelRenderer(this, 21, 0); + Left.addBox(0F, 0F, 0F, 6, 4, 4); + Left.setRotationPoint(-8F, 14F, -2F); + Left.setTextureSize(64, 32); + Left.mirror = true; + setRotation(Left, 0F, 0F, 0F); + Back = new ModelRenderer(this, 0, 11); + Back.addBox(0F, 0F, 0F, 4, 4, 6); + Back.setRotationPoint(-2F, 14F, 2F); + Back.setTextureSize(64, 32); + Back.mirror = true; + setRotation(Back, 0F, 0F, 0F); + Front = new ModelRenderer(this, 0, 11); + Front.addBox(0F, 0F, 0F, 4, 4, 6); + Front.setRotationPoint(-2F, 14F, -8F); + Front.setTextureSize(64, 32); + Front.mirror = true; + setRotation(Front, 0F, 0F, 0F); + Top = new ModelRenderer(this, 21, 11); + Top.addBox(0F, 0F, 0F, 4, 6, 4); + Top.setRotationPoint(-2F, 8F, -2F); + Top.setTextureSize(64, 32); + Top.mirror = true; + setRotation(Top, 0F, 0F, 0F); + Bottom = new ModelRenderer(this, 21, 11); + Bottom.addBox(0F, 0F, 0F, 4, 6, 4); + Bottom.setRotationPoint(-2F, 18F, -2F); + Bottom.setTextureSize(64, 32); + Bottom.mirror = true; + setRotation(Bottom, 0F, 0F, 0F); + } + + @Override + public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) + { + super.render(entity, f, f1, f2, f3, f4, f5); + this.setRotationAngles(f, f1, f2, f3, f4, f5, entity); + this.renderMiddle(); + this.renderBottom(); + this.renderTop(); + this.renderLeft(); + this.renderRight(); + this.renderBack(); + this.renderFront(); + } + + public void renderMiddle() + { + Middle.render(0.0625F); + } + + public void renderBottom() + { + Bottom.render(0.0625F); + } + + public void renderTop() + { + Top.render(0.0625F); + } + + public void renderLeft() + { + Left.render(0.0625F); + } + + public void renderRight() + { + Right.render(0.0625F); + } + + public void renderBack() + { + Back.render(0.0625F); + } + + public void renderFront() + { + Front.render(0.0625F); + } + + private void setRotation(ModelRenderer model, float x, float y, float z) + { + model.rotateAngleX = x; + model.rotateAngleY = y; + model.rotateAngleZ = z; + } + + @Override + public void setRotationAngles(float x, float y, float z, float f3, float f4, float f5, Entity entity) + { + super.setRotationAngles(x, y, z, f3, f4, f5, entity); + } +} diff --git a/src/resonantinduction/render/RenderWire.java b/src/resonantinduction/render/RenderWire.java new file mode 100644 index 000000000..adefb7caf --- /dev/null +++ b/src/resonantinduction/render/RenderWire.java @@ -0,0 +1,128 @@ +package resonantinduction.render; + +import ic2.api.Direction; +import ic2.api.energy.tile.IEnergyAcceptor; +import ic2.api.energy.tile.IEnergyTile; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.ForgeDirection; + +import org.lwjgl.opengl.GL11; + +import resonantinduction.ResonantInduction; +import resonantinduction.model.ModelCopperWire; +import resonantinduction.wire.TileEntityWire; +import universalelectricity.compatibility.Compatibility; +import universalelectricity.core.block.IConnector; +import universalelectricity.core.vector.Vector3; +import universalelectricity.core.vector.VectorHelper; +import buildcraft.api.power.IPowerReceptor; +import cpw.mods.fml.client.FMLClientHandler; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class RenderWire extends TileEntitySpecialRenderer +{ + private static final ResourceLocation COPPER_TEXTURE = new ResourceLocation(ResonantInduction.DOMAIN, ResonantInduction.MODEL_TEXTURE_DIRECTORY + "wireCopper.png"); + public static final ModelCopperWire WIRE_MODEL = new ModelCopperWire(); + + public void renderModelAt(TileEntityWire tileEntity, double x, double y, double z, float f) + { + // Texture file + FMLClientHandler.instance().getClient().renderEngine.func_110577_a(COPPER_TEXTURE); + GL11.glPushMatrix(); + GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F); + GL11.glScalef(1.0F, -1F, -1F); + + List adjecentConnections = new ArrayList(); + + for (byte i = 0; i < 6; i++) + { + ForgeDirection side = ForgeDirection.getOrientation(i); + TileEntity adjacentTile = VectorHelper.getTileEntityFromSide(tileEntity.worldObj, new Vector3(tileEntity), side); + + if (adjacentTile instanceof IConnector) + { + if (((IConnector) adjacentTile).canConnect(side.getOpposite())) + { + adjecentConnections.add(adjacentTile); + } + else + { + adjecentConnections.add(null); + } + } + else if (Compatibility.isIndustrialCraft2Loaded() && adjacentTile instanceof IEnergyTile) + { + if (adjacentTile instanceof IEnergyAcceptor) + { + if (((IEnergyAcceptor) adjacentTile).acceptsEnergyFrom(tileEntity, Direction.values()[(i + 2) % 6].getInverse())) + { + adjecentConnections.add(adjacentTile); + } + else + { + adjecentConnections.add(null); + } + } + else + { + adjecentConnections.add(adjacentTile); + } + } + else if (Compatibility.isBuildcraftLoaded() && adjacentTile instanceof IPowerReceptor) + { + adjecentConnections.add(adjacentTile); + } + else + { + adjecentConnections.add(null); + } + } + + if (adjecentConnections.toArray()[0] != null) + { + WIRE_MODEL.renderBottom(); + } + + if (adjecentConnections.toArray()[1] != null) + { + WIRE_MODEL.renderTop(); + } + + if (adjecentConnections.toArray()[2] != null) + { + WIRE_MODEL.renderBack(); + } + + if (adjecentConnections.toArray()[3] != null) + { + WIRE_MODEL.renderFront(); + } + + if (adjecentConnections.toArray()[4] != null) + { + WIRE_MODEL.renderLeft(); + } + + if (adjecentConnections.toArray()[5] != null) + { + WIRE_MODEL.renderRight(); + } + + WIRE_MODEL.renderMiddle(); + GL11.glPopMatrix(); + } + + @Override + public void renderTileEntityAt(TileEntity tileEntity, double var2, double var4, double var6, float var8) + { + this.renderModelAt((TileEntityWire) tileEntity, var2, var4, var6, var8); + } +} \ No newline at end of file diff --git a/src/resonantinduction/wire/BlockWire.java b/src/resonantinduction/wire/BlockWire.java index 55ee828c0..568a1083a 100644 --- a/src/resonantinduction/wire/BlockWire.java +++ b/src/resonantinduction/wire/BlockWire.java @@ -1,11 +1,15 @@ package resonantinduction.wire; +import java.util.List; + import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import resonantinduction.ResonantInduction; +import resonantinduction.TabRI; import universalelectricity.prefab.block.BlockConductor; /** @@ -26,6 +30,7 @@ public class BlockWire extends BlockConductor this.setCreativeTab(CreativeTabs.tabRedstone); Block.setBurnProperties(this.blockID, 30, 60); this.func_111022_d(ResonantInduction.PREFIX + "wire"); + this.setCreativeTab(TabRI.INSTANCE); } /** @@ -63,4 +68,14 @@ public class BlockWire extends BlockConductor { return new TileEntityWire(); } + + @Override + public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List) + { + for (int i = 0; i < EnumWire.values().length - 1; i++) + { + par3List.add(new ItemStack(par1, 1, i)); + } + } + } \ No newline at end of file diff --git a/src/resonantinduction/wire/EnumWire.java b/src/resonantinduction/wire/EnumWire.java index 7250ecb25..aab52c3b9 100644 --- a/src/resonantinduction/wire/EnumWire.java +++ b/src/resonantinduction/wire/EnumWire.java @@ -1,7 +1,8 @@ package resonantinduction.wire; /** - * An enumerator for different wire materials. + * An enumerator for different wire materials. The metadata of the wire determines the type of the + * wire. * * @author Calclavia * diff --git a/src/resonantinduction/wire/ItemBlockWire.java b/src/resonantinduction/wire/ItemBlockWire.java index 78df9a6fd..37b0d61f7 100644 --- a/src/resonantinduction/wire/ItemBlockWire.java +++ b/src/resonantinduction/wire/ItemBlockWire.java @@ -47,9 +47,9 @@ public class ItemBlockWire extends ItemBlock @SideOnly(Side.CLIENT) public void registerIcons(IconRegister iconRegister) { - for (int i = 0; i < EnumWire.values().length - 1; i++) + for (int i = 0; i < EnumWire.values().length; i++) { - this.icons[i] = iconRegister.registerIcon(this.getUnlocalizedName(new ItemStack(this.itemID, 1, i)).replaceAll("tile.", ResonantInduction.PREFIX)); + this.icons[i] = iconRegister.registerIcon(this.getUnlocalizedName(new ItemStack(this.itemID, 1, i)).replaceAll("tile.", "")); } }