From 083c24c9016c21f3f591601a37d8323be0698d8c Mon Sep 17 00:00:00 2001 From: Modmuss50 Date: Fri, 24 Apr 2015 21:22:09 +0100 Subject: [PATCH] Added all cables, needs a lot of testing :P --- src/main/java/techreborn/Core.java | 2 + .../java/techreborn/client/IconSupplier.java | 44 +++ src/main/java/techreborn/init/ModParts.java | 4 +- .../techreborn/partSystem/ModPartItem.java | 21 +- .../partSystem/ModPartRegistry.java | 1 + .../partSystem/QLib/QModPartFactory.java | 11 + .../partSystem/block/TileEntityModPart.java | 15 +- .../techreborn/partSystem/fmp/FMPFactory.java | 12 +- .../partSystem/parts/CablePart.java | 302 ++++++++++++++++-- .../java/techreborn/proxies/ClientProxy.java | 8 + .../java/techreborn/proxies/CommonProxy.java | 4 + 11 files changed, 396 insertions(+), 28 deletions(-) create mode 100644 src/main/java/techreborn/client/IconSupplier.java diff --git a/src/main/java/techreborn/Core.java b/src/main/java/techreborn/Core.java index 462860ddf..ef3a83556 100644 --- a/src/main/java/techreborn/Core.java +++ b/src/main/java/techreborn/Core.java @@ -73,6 +73,8 @@ public class Core { FMLCommonHandler.instance().bus() .register(new MultiblockServerTickHandler()); + proxy.init(); + LogHelper.info("Initialization Compleate"); } diff --git a/src/main/java/techreborn/client/IconSupplier.java b/src/main/java/techreborn/client/IconSupplier.java new file mode 100644 index 000000000..c3908e919 --- /dev/null +++ b/src/main/java/techreborn/client/IconSupplier.java @@ -0,0 +1,44 @@ +package techreborn.client; + +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.util.IIcon; +import net.minecraftforge.client.event.TextureStitchEvent; + +public class IconSupplier { + public static IIcon insulatedCopperCable; + public static IIcon copperCable; + public static IIcon goldCable; + public static IIcon insulatedGoldCable; + public static IIcon doubleInsulatedGoldCable; + public static IIcon ironCable; + public static IIcon insulatedIronCable; + public static IIcon doubleInsulatedIronCable; + public static IIcon trippleInsulatedIronCable; + public static IIcon glassFiberCable; + public static IIcon tinCable; + public static IIcon detectorCableBlock; + public static IIcon splitterCableBlock; + public static IIcon insulatedtinCableBlock; + + @SubscribeEvent + public void onTextureStitch(TextureStitchEvent.Pre event) { + TextureMap reg = event.map; + if (reg.getTextureType() == 0) { + insulatedCopperCable = reg.registerIcon("ic2" + ":wiring/cable/blockCableO"); + copperCable = reg.registerIcon("ic2" + ":wiring/cable/blockCable"); + goldCable = reg.registerIcon("ic2" + ":wiring/cable/blockGoldCable"); + insulatedGoldCable = reg.registerIcon("ic2" + ":wiring/cable/blockGoldCableI"); + doubleInsulatedGoldCable = reg.registerIcon("ic2" + ":wiring/cable/blockGoldCableII"); + ironCable = reg.registerIcon("ic2" + ":wiring/cable/blockIronCable"); + insulatedIronCable = reg.registerIcon("ic2" + ":wiring/cable/blockIronCableI"); + doubleInsulatedIronCable = reg.registerIcon("ic2" + ":wiring/cable/blockIronCableII"); + trippleInsulatedIronCable = reg.registerIcon("ic2" + ":wiring/cable/blockIronCableIII"); + glassFiberCable = reg.registerIcon("ic2" + ":wiring/cable/blockGlassCable"); + tinCable= reg.registerIcon("ic2" + ":wiring/cable/blockTinCable"); + detectorCableBlock= reg.registerIcon("ic2" + ":wiring/cable/blockDetectorCable"); + splitterCableBlock= reg.registerIcon("ic2" + ":wiring/cable/blockSplitterCable"); + insulatedtinCableBlock= reg.registerIcon("ic2" + ":wiring/cable/blockTinCableI"); + } + } +} diff --git a/src/main/java/techreborn/init/ModParts.java b/src/main/java/techreborn/init/ModParts.java index 762a580ed..44c9dbdb8 100644 --- a/src/main/java/techreborn/init/ModParts.java +++ b/src/main/java/techreborn/init/ModParts.java @@ -8,7 +8,9 @@ public class ModParts { public static void init() { - ModPartRegistry.registerPart(new CablePart()); + for (int i = 0; i < 14; i++) { + ModPartRegistry.registerPart(new CablePart(i)); + } ModPartRegistry.addProvider( "techreborn.partSystem.QLib.QModPartFactory", "qmunitylib"); ModPartRegistry.addProvider("techreborn.partSystem.fmp.FMPFactory", diff --git a/src/main/java/techreborn/partSystem/ModPartItem.java b/src/main/java/techreborn/partSystem/ModPartItem.java index 6c3281506..006f880af 100644 --- a/src/main/java/techreborn/partSystem/ModPartItem.java +++ b/src/main/java/techreborn/partSystem/ModPartItem.java @@ -8,8 +8,11 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; +import techreborn.partSystem.parts.CablePart; import uk.co.qmunity.lib.ref.Names; +import java.lang.reflect.InvocationTargetException; + public class ModPartItem extends Item { ModPart modPart; @@ -38,10 +41,22 @@ public class ModPartItem extends Item { } else { for (IPartProvider partProvider : ModPartRegistry.providers) { try { - if (partProvider.placePart(item, player, world, x, y, z, - face, x_, y_, z_, modPart.getClass().newInstance())) { - return true; + if(modPart instanceof CablePart){ + try { + if (partProvider.placePart(item, player, world, x, y, z, face, x_, y_, z_, modPart.getClass().getDeclaredConstructor(int.class).newInstance(((CablePart) modPart).type))) { + return true; + } + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + } else { + if (partProvider.placePart(item, player, world, x, y, z, face, x_, y_, z_, modPart.getClass().newInstance())) { + return true; + } } + } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { diff --git a/src/main/java/techreborn/partSystem/ModPartRegistry.java b/src/main/java/techreborn/partSystem/ModPartRegistry.java index 43e534fbe..75aa10005 100644 --- a/src/main/java/techreborn/partSystem/ModPartRegistry.java +++ b/src/main/java/techreborn/partSystem/ModPartRegistry.java @@ -32,6 +32,7 @@ public class ModPartRegistry { LogHelper.info("Started to load all parts"); for (ModPart modPart : ModPartRegistry.parts) { + System.out.println(modPart.getName()); Item part = new ModPartItem(modPart) .setUnlocalizedName(modPart.getName()) .setCreativeTab(TechRebornCreativeTab.instance) diff --git a/src/main/java/techreborn/partSystem/QLib/QModPartFactory.java b/src/main/java/techreborn/partSystem/QLib/QModPartFactory.java index 7e1d0d8e4..d92086d5f 100644 --- a/src/main/java/techreborn/partSystem/QLib/QModPartFactory.java +++ b/src/main/java/techreborn/partSystem/QLib/QModPartFactory.java @@ -16,6 +16,7 @@ import techreborn.lib.vecmath.Vecs3dCube; import techreborn.partSystem.IPartProvider; import techreborn.partSystem.ModPart; import techreborn.partSystem.ModPartRegistry; +import techreborn.partSystem.parts.CablePart; import uk.co.qmunity.lib.QLModInfo; import uk.co.qmunity.lib.part.IPart; import uk.co.qmunity.lib.part.IPartFactory; @@ -25,6 +26,7 @@ import uk.co.qmunity.lib.tile.TileMultipart; import uk.co.qmunity.lib.vec.Vec3dCube; import uk.co.qmunity.lib.vec.Vec3i; +import java.lang.reflect.InvocationTargetException; import java.util.List; public class QModPartFactory implements IPartFactory, IPartProvider { @@ -33,6 +35,15 @@ public class QModPartFactory implements IPartFactory, IPartProvider { for (ModPart modPart : ModPartRegistry.parts) { if (modPart.getName().equals(type)) { try { + if(modPart instanceof CablePart){ + try { + return new QModPart(modPart.getClass().getDeclaredConstructor(int.class).newInstance(((CablePart) modPart).type)); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + } return new QModPart(modPart.getClass().newInstance()); } catch (InstantiationException e) { e.printStackTrace(); diff --git a/src/main/java/techreborn/partSystem/block/TileEntityModPart.java b/src/main/java/techreborn/partSystem/block/TileEntityModPart.java index ff32255eb..be95f508f 100644 --- a/src/main/java/techreborn/partSystem/block/TileEntityModPart.java +++ b/src/main/java/techreborn/partSystem/block/TileEntityModPart.java @@ -17,8 +17,10 @@ import techreborn.lib.Location; import techreborn.lib.vecmath.Vecs3dCube; import techreborn.partSystem.ModPart; import techreborn.partSystem.ModPartRegistry; +import techreborn.partSystem.parts.CablePart; import techreborn.partSystem.parts.NullPart; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -161,8 +163,19 @@ public class TileEntityModPart extends TileEntity { } public void addPart(ModPart modPart) { + ModPart newPart = null; try { - ModPart newPart = modPart.getClass().newInstance(); + if(modPart instanceof CablePart){ + try { + newPart = modPart.getClass().getDeclaredConstructor(int.class).newInstance(((CablePart) modPart).type); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + } else { + newPart = modPart.getClass().newInstance(); + } newPart.setWorld(getWorldObj()); newPart.setLocation(new Location(xCoord, yCoord, zCoord)); parts.put(newPart.getName(), newPart); diff --git a/src/main/java/techreborn/partSystem/fmp/FMPFactory.java b/src/main/java/techreborn/partSystem/fmp/FMPFactory.java index 82ed50b88..77cc01d5d 100644 --- a/src/main/java/techreborn/partSystem/fmp/FMPFactory.java +++ b/src/main/java/techreborn/partSystem/fmp/FMPFactory.java @@ -19,7 +19,9 @@ import techreborn.lib.vecmath.Vecs3dCube; import techreborn.partSystem.IPartProvider; import techreborn.partSystem.ModPart; import techreborn.partSystem.ModPartRegistry; +import techreborn.partSystem.parts.CablePart; +import java.lang.reflect.InvocationTargetException; import java.util.List; /** @@ -32,11 +34,19 @@ public class FMPFactory implements MultiPartRegistry.IPartFactory, for (ModPart modPart : ModPartRegistry.parts) { if (modPart.getName().equals(type)) { try { - return new FMPModPart(modPart.getClass().newInstance()); + if(modPart instanceof CablePart){ + return new FMPModPart(modPart.getClass().getDeclaredConstructor(int.class).newInstance(((CablePart) modPart).type)); + } else { + return new FMPModPart(modPart.getClass().newInstance()); + } } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); } } } diff --git a/src/main/java/techreborn/partSystem/parts/CablePart.java b/src/main/java/techreborn/partSystem/parts/CablePart.java index d6261f705..f194f1ed7 100644 --- a/src/main/java/techreborn/partSystem/parts/CablePart.java +++ b/src/main/java/techreborn/partSystem/parts/CablePart.java @@ -5,14 +5,23 @@ import ic2.api.energy.event.EnergyTileUnloadEvent; import ic2.api.energy.tile.IEnergyConductor; import ic2.api.energy.tile.IEnergyTile; import ic2.core.IC2; +import ic2.core.block.wiring.TileEntityCable; +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.client.network.NetHandlerPlayClient; import net.minecraft.entity.Entity; -import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.EnumDifficulty; import net.minecraft.world.World; +import net.minecraft.world.WorldSettings; +import net.minecraft.world.WorldType; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.ForgeDirection; +import techreborn.client.IconSupplier; import techreborn.lib.Functions; import techreborn.lib.vecmath.Vecs3d; import techreborn.lib.vecmath.Vecs3dCube; @@ -27,18 +36,30 @@ import java.util.List; import java.util.Map; public class CablePart extends ModPart implements IEnergyConductor { - public static Vecs3dCube[] boundingBoxes = new Vecs3dCube[14]; - public static float center = 0.6F; - public static float offset = 0.10F; + public Vecs3dCube[] boundingBoxes = new Vecs3dCube[14]; + public float center = 0.6F; + public float offset = 0.10F; public Map connectedSides; public int ticks = 0; protected ForgeDirection[] dirs = ForgeDirection.values(); private boolean[] connections = new boolean[6]; public boolean addedToEnergyNet = false; + TileEntityCable entityCable = new TileEntityCable(); - public static void refreshBounding() { + public int type = 3; + + public CablePart(int type) { + this.type = type; + if(Minecraft.getMinecraft().theWorld != null){ + entityCable = new TileEntityCable(); + entityCable.setWorldObj(new fakeWorld()); + entityCable.changeType((short) type); + } + } + + public void refreshBounding() { float centerFirst = center - offset; - double w = 0.2D / 2; + double w = getCableThickness(type) / 2; boundingBoxes[6] = new Vecs3dCube(centerFirst - w - 0.03, centerFirst - w - 0.08, centerFirst - w - 0.03, centerFirst + w + 0.08, centerFirst + w + 0.04, centerFirst + w + 0.08); @@ -118,17 +139,32 @@ public class CablePart extends ModPart implements IEnergyConductor { @Override public boolean renderStatic(Vecs3d translation, RenderHelper renderer, int pass) { - renderer.setOverrideTexture(Blocks.coal_block.getIcon(0, 0)); - renderer.renderBox(ModLib2QLib.convert(boundingBoxes[6])); - if (connectedSides != null) { - for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { - if (connectedSides.containsKey(dir)) - renderer.renderBox(ModLib2QLib.convert(boundingBoxes[Functions.getIntDirFromDirection(dir)])); + renderer.setOverrideTexture(getIconFromType(type)); + renderer.renderBox(ModLib2QLib.convert(boundingBoxes[6])); + if (connectedSides != null) { + for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { + if (connectedSides.containsKey(dir)) + renderer.renderBox(ModLib2QLib.convert(boundingBoxes[Functions.getIntDirFromDirection(dir)])); + } } - } + return true; } + + public class fakeWorld extends WorldClient{ + public fakeWorld() { + super(new NetHandlerPlayClient(Minecraft.getMinecraft(), null, new NetworkManager(true)), new WorldSettings(0, WorldSettings.GameType.NOT_SET, + false, false, WorldType.DEFAULT), 0, EnumDifficulty.PEACEFUL, Minecraft.getMinecraft().theWorld.theProfiler); + } + + @Override + public boolean setBlockMetadataWithNotify(int p_72921_1_, int p_72921_2_, int p_72921_3_, int p_72921_4_, int p_72921_5_) { + return true; + } + } + + @Override public void writeToNBT(NBTTagCompound tag) { @@ -141,7 +177,7 @@ public class CablePart extends ModPart implements IEnergyConductor { @Override public String getName() { - return "Cable"; + return "Cable." + getNameFromType(type); } @Override @@ -236,24 +272,246 @@ public class CablePart extends ModPart implements IEnergyConductor { world.func_147479_m(x, y, z); } - @Override public double getConductionLoss() { - return 0D; + switch(this.type) { + case 0: + return 0.2D; + case 1: + return 0.3D; + case 2: + return 0.5D; + case 3: + return 0.45D; + case 4: + return 0.4D; + case 5: + return 1.0D; + case 6: + return 0.95D; + case 7: + return 0.9D; + case 8: + return 0.8D; + case 9: + return 0.025D; + case 10: + return 0.025D; + case 11: + return 0.5D; + case 12: + return 0.5D; + case 13: + default: + return 0.025D; + case 14: + return 0.2D; + } + } + + public static int getMaxCapacity(int type) { + switch(type) { + case 0: + return 128; + case 1: + return 128; + case 2: + return 512; + case 3: + return 512; + case 4: + return 512; + case 5: + return 2048; + case 6: + return 2048; + case 7: + return 2048; + case 8: + return 2048; + case 9: + return 8192; + case 10: + return 32; + case 11: + return 8192; + case 12: + return 8192; + case 13: + return 32; + case 14: + return 32; + default: + return 0; + } + } + + public static float getCableThickness(int cableType) { + float p = 1.0F; + switch(cableType) { + case 0: + p = 6.0F; + break; + case 1: + p = 4.0F; + break; + case 2: + p = 3.0F; + break; + case 3: + p = 6.0F; + break; + case 4: + p = 6.0F; + break; + case 5: + p = 6.0F; + break; + case 6: + p = 10.0F; + break; + case 7: + p = 10.0F; + break; + case 8: + p = 12.0F; + break; + case 9: + p = 4.0F; + break; + case 10: + p = 4.0F; + break; + case 11: + p = 8.0F; + break; + case 12: + p = 8.0F; + break; + case 13: + p = 16.0F; + break; + case 14: + p = 6.0F; + } + + return p / 16.0F; + } + + public static IIcon getIconFromType(int cableType){ + IIcon p = null; + switch(cableType) { + case 0: + p = IconSupplier.insulatedCopperCable; + break; + case 1: + p = IconSupplier.copperCable; + break; + case 2: + p = IconSupplier.goldCable; + break; + case 3: + p = IconSupplier.insulatedGoldCable; + break; + case 4: + p = IconSupplier.doubleInsulatedGoldCable; + break; + case 5: + p = IconSupplier.ironCable; + break; + case 6: + p = IconSupplier.insulatedIronCable; + break; + case 7: + p = IconSupplier.doubleInsulatedIronCable; + break; + case 8: + p = IconSupplier.trippleInsulatedIronCable; + break; + case 9: + p = IconSupplier.glassFiberCable; + break; + case 10: + p = IconSupplier.tinCable; + break; + case 11: + p = IconSupplier.detectorCableBlock;//Detector + break; + case 12: + p = IconSupplier.splitterCableBlock;// Splitter + break; + case 13: + p = IconSupplier.insulatedtinCableBlock; + break; + case 14: + p = IconSupplier.copperCable; // unused? + } + + return p; + } + + + public static String getNameFromType(int cableType){ + String p = null; + switch(cableType) { + case 0: + p = "insulatedCopperCable"; + break; + case 1: + p = "copperCable"; + break; + case 2: + p = "goldCable"; + break; + case 3: + p = "insulatedGoldCable"; + break; + case 4: + p = "doubleInsulatedGoldCable"; + break; + case 5: + p = "ironCable"; + break; + case 6: + p = "insulatedIronCable"; + break; + case 7: + p = "doubleInsulatedIronCable"; + break; + case 8: + p = "trippleInsulatedIronCable"; + break; + case 9: + p = "glassFiberCable"; + break; + case 10: + p = "tinCable"; + break; + case 11: + p = "detectorCableBlock";//Detector + break; + case 12: + p = "splitterCableBlock";// Splitter + break; + case 13: + p = "insulatedtinCable"; + break; + case 14: + p = "unused"; // unused? + } + + return p; } - @Override public double getInsulationEnergyAbsorption() { - return 256; + return (double)getMaxCapacity(this.type); } - @Override public double getInsulationBreakdownEnergy() { - return 2048; + return 9001.0D; } - @Override public double getConductorBreakdownEnergy() { - return 2048; + return (double)(getMaxCapacity(this.type) + 1); } @Override diff --git a/src/main/java/techreborn/proxies/ClientProxy.java b/src/main/java/techreborn/proxies/ClientProxy.java index e5eaa7922..098e9caa9 100644 --- a/src/main/java/techreborn/proxies/ClientProxy.java +++ b/src/main/java/techreborn/proxies/ClientProxy.java @@ -1,5 +1,13 @@ package techreborn.proxies; +import net.minecraftforge.common.MinecraftForge; +import techreborn.client.IconSupplier; + public class ClientProxy extends CommonProxy { + @Override + public void init() { + super.init(); + MinecraftForge.EVENT_BUS.register(new IconSupplier()); + } } diff --git a/src/main/java/techreborn/proxies/CommonProxy.java b/src/main/java/techreborn/proxies/CommonProxy.java index b893d30ea..b0aab902d 100644 --- a/src/main/java/techreborn/proxies/CommonProxy.java +++ b/src/main/java/techreborn/proxies/CommonProxy.java @@ -2,4 +2,8 @@ package techreborn.proxies; public class CommonProxy { + public void init(){ + + } + }