diff --git a/src/main/java/techreborn/client/IconSupplier.java b/src/main/java/techreborn/client/IconSupplier.java index 88a921ae0..9e1d210b2 100644 --- a/src/main/java/techreborn/client/IconSupplier.java +++ b/src/main/java/techreborn/client/IconSupplier.java @@ -25,8 +25,8 @@ public class IconSupplier { 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"); + insulatedCopperCable = reg.registerIcon("ic2" + ":wiring/cable/blockCable"); + copperCable = reg.registerIcon("ic2" + ":wiring/cable/blockCableO"); goldCable = reg.registerIcon("ic2" + ":wiring/cable/blockGoldCable"); insulatedGoldCable = reg.registerIcon("ic2" + ":wiring/cable/blockGoldCableI"); doubleInsulatedGoldCable = reg.registerIcon("ic2" + ":wiring/cable/blockGoldCableII"); diff --git a/src/main/java/techreborn/client/texture/CasingConnectedTextureGenerator.java b/src/main/java/techreborn/client/texture/CasingConnectedTextureGenerator.java index f9a96de76..ddcfd80cd 100644 --- a/src/main/java/techreborn/client/texture/CasingConnectedTextureGenerator.java +++ b/src/main/java/techreborn/client/texture/CasingConnectedTextureGenerator.java @@ -127,7 +127,6 @@ public class CasingConnectedTextureGenerator extends TextureAtlasSprite { if (iconRegister instanceof TextureMap) { TextureMap map = (TextureMap) iconRegister; String name = CasingConnectedTextureGenerator.getDerivedName(types[meta] + "." + texNum); - System.out.println(name); TextureAtlasSprite texture = map.getTextureExtry(name); if (texture == null) { texture = new CasingConnectedTextureGenerator(name, types[meta], connectedTexture); diff --git a/src/main/java/techreborn/client/texture/LesuConnectedTextureGenerator.java b/src/main/java/techreborn/client/texture/LesuConnectedTextureGenerator.java index 8ed13ac9c..0d2de3c5e 100644 --- a/src/main/java/techreborn/client/texture/LesuConnectedTextureGenerator.java +++ b/src/main/java/techreborn/client/texture/LesuConnectedTextureGenerator.java @@ -129,7 +129,6 @@ public class LesuConnectedTextureGenerator extends TextureAtlasSprite { if (iconRegister instanceof TextureMap) { TextureMap map = (TextureMap) iconRegister; String name = LesuConnectedTextureGenerator.getDerivedName("lesu." + texNum); - System.out.println(name); TextureAtlasSprite texture = map.getTextureExtry(name); if (texture == null) { texture = new LesuConnectedTextureGenerator(name, "lesu", connectedTexture); diff --git a/src/main/java/techreborn/partSystem/IModPart.java b/src/main/java/techreborn/partSystem/IModPart.java index c4a7e4f9a..087c11de2 100644 --- a/src/main/java/techreborn/partSystem/IModPart.java +++ b/src/main/java/techreborn/partSystem/IModPart.java @@ -115,4 +115,6 @@ public interface IModPart { public void onRemoved(); public IModPart copy(); + + public boolean needsItem(); } diff --git a/src/main/java/techreborn/partSystem/IPartProvider.java b/src/main/java/techreborn/partSystem/IPartProvider.java index 94761f275..bd0bcf986 100644 --- a/src/main/java/techreborn/partSystem/IPartProvider.java +++ b/src/main/java/techreborn/partSystem/IPartProvider.java @@ -29,4 +29,6 @@ public interface IPartProvider { public boolean isTileFromProvider(TileEntity tileEntity); public IModPart getPartFromWorld(World world, Location location, String name); + + public void init(); } diff --git a/src/main/java/techreborn/partSystem/ModPart.java b/src/main/java/techreborn/partSystem/ModPart.java index 38e61fd23..59735b1a7 100644 --- a/src/main/java/techreborn/partSystem/ModPart.java +++ b/src/main/java/techreborn/partSystem/ModPart.java @@ -95,4 +95,9 @@ public abstract class ModPart extends TileEntity implements IModPart { public String getItemTextureName() { return ""; } + + @Override + public boolean needsItem() { + return true; + } } diff --git a/src/main/java/techreborn/partSystem/ModPartRegistry.java b/src/main/java/techreborn/partSystem/ModPartRegistry.java index 88ecd5afc..049a27bf5 100644 --- a/src/main/java/techreborn/partSystem/ModPartRegistry.java +++ b/src/main/java/techreborn/partSystem/ModPartRegistry.java @@ -33,19 +33,25 @@ public class ModPartRegistry { } public static void addAllPartsToSystems() { + for (IPartProvider iPartProvider : providers) { + iPartProvider.init(); + } + LogHelper.info("Started to load all parts"); for (ModPart modPart : ModPartRegistry.parts) { - Item part = new ModPartItem(modPart) - .setUnlocalizedName(modPart.getName()) - .setCreativeTab(TechRebornCreativeTab.instance) - .setTextureName(modPart.getItemTextureName()); - GameRegistry.registerItem(part, modPart.getName()); - itemParts.put(modPart.getName(), part); - if (modPart instanceof CablePart) { - GameRegistry.addShapelessRecipe(new ItemStack(part), IC2Items.getItem(CablePart.getTextureNameFromType(((CablePart) modPart).type))); - ((CablePart) modPart).stack = new ItemStack(part); - ModParts.stackCable.put(((CablePart) modPart).type, new ItemStack(part)); + if(modPart.needsItem()){ + Item part = new ModPartItem(modPart) + .setUnlocalizedName(modPart.getName()) + .setCreativeTab(TechRebornCreativeTab.instance) + .setTextureName(modPart.getItemTextureName()); + GameRegistry.registerItem(part, modPart.getName()); + itemParts.put(modPart.getName(), part); + if (modPart instanceof CablePart) { + GameRegistry.addShapelessRecipe(new ItemStack(part), IC2Items.getItem(CablePart.getTextureNameFromType(((CablePart) modPart).type))); + ((CablePart) modPart).stack = new ItemStack(part); + ModParts.stackCable.put(((CablePart) modPart).type, new ItemStack(part)); + } } } diff --git a/src/main/java/techreborn/partSystem/QLib/QModPartFactory.java b/src/main/java/techreborn/partSystem/QLib/QModPartFactory.java index 7924afac4..266fd6d30 100644 --- a/src/main/java/techreborn/partSystem/QLib/QModPartFactory.java +++ b/src/main/java/techreborn/partSystem/QLib/QModPartFactory.java @@ -72,6 +72,11 @@ public class QModPartFactory implements IPartFactory, IPartProvider { return null; } + @Override + public void init() { + + } + public String getCreatedPartType(ItemStack item, EntityPlayer player, World world, MovingObjectPosition mop, ModPart modPart) { return modPart.getName(); diff --git a/src/main/java/techreborn/partSystem/fmp/FMPFactory.java b/src/main/java/techreborn/partSystem/fmp/FMPFactory.java index 5715df3fb..1393365bd 100644 --- a/src/main/java/techreborn/partSystem/fmp/FMPFactory.java +++ b/src/main/java/techreborn/partSystem/fmp/FMPFactory.java @@ -4,6 +4,7 @@ package techreborn.partSystem.fmp; +import codechicken.lib.data.MCDataInput; import codechicken.lib.vec.BlockCoord; import codechicken.lib.vec.Cuboid6; import codechicken.multipart.MultiPartRegistry; @@ -12,6 +13,7 @@ import codechicken.multipart.TMultiPart; import codechicken.multipart.TileMultipart; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import techreborn.lib.Location; @@ -20,15 +22,14 @@ import techreborn.partSystem.IModPart; import techreborn.partSystem.IPartProvider; import techreborn.partSystem.ModPart; import techreborn.partSystem.ModPartRegistry; +import techreborn.partSystem.parts.CableConverter; import java.util.List; -/** - * Created by mark on 09/12/14. - */ -public class FMPFactory implements MultiPartRegistry.IPartFactory, +public class FMPFactory implements MultiPartRegistry.IPartFactory2, IPartProvider { - @Override + + public TMultiPart createPart(String type, boolean client) { for (ModPart modPart : ModPartRegistry.parts) { if (modPart.getName().equals(type)) { @@ -50,12 +51,34 @@ public class FMPFactory implements MultiPartRegistry.IPartFactory, return tileEntity instanceof TileMultipart; } - //TODO @Override public IModPart getPartFromWorld(World world, Location location, String name) { + TileEntity tileEntity = world.getTileEntity(location.getX(), + location.getY(), location.getZ()); + if (tileEntity instanceof TileMultipart) { + TileMultipart mp = (TileMultipart) tileEntity; + boolean ret = false; + List t = mp.jPartList(); + for (TMultiPart p : t) { + if (ret == false) { + if (p.getType().equals(name)) { + if(p instanceof FMPModPart){ + return ((FMPModPart) p).iModPart; + } + ret = true; + } + } + } + return null; + } return null; } + @Override + public void init() { + MultiPartRegistry.registerConverter(new CableConverter()); + } + @Override public String modID() { return "ForgeMultipart"; @@ -100,4 +123,14 @@ public class FMPFactory implements MultiPartRegistry.IPartFactory, } return false; } + + @Override + public TMultiPart createPart(String s, NBTTagCompound nbtTagCompound) { + return createPart(s, false); + } + + @Override + public TMultiPart createPart(String s, MCDataInput mcDataInput) { + return createPart(s, false); + } } diff --git a/src/main/java/techreborn/partSystem/fmp/FMPModPart.java b/src/main/java/techreborn/partSystem/fmp/FMPModPart.java index 10dbfc446..9aa0670c1 100644 --- a/src/main/java/techreborn/partSystem/fmp/FMPModPart.java +++ b/src/main/java/techreborn/partSystem/fmp/FMPModPart.java @@ -59,23 +59,6 @@ public class FMPModPart extends TMultiPart implements TSlottedPart, return NormalOcclusionTest.apply(this, npart); } - public void addCollisionBoxesToList(List l, - AxisAlignedBB bounds, Entity entity) { - List boxes = new ArrayList(); - List boxes_ = new ArrayList(); - iModPart.addCollisionBoxesToList(boxes_, entity); - for (Vecs3dCube c : boxes_) { - Vecs3dCube cube = c.clone(); - cube.add(getX(), getY(), getZ()); - boxes.add(cube); - } - boxes_.clear(); - - for (Vecs3dCube c : boxes) { - if (c.toAABB().intersectsWith(bounds)) - l.add(c); - } - } @Override public Iterable getCollisionBoxes() { diff --git a/src/main/java/techreborn/partSystem/parts/CableConverter.java b/src/main/java/techreborn/partSystem/parts/CableConverter.java new file mode 100644 index 000000000..c7212a2ff --- /dev/null +++ b/src/main/java/techreborn/partSystem/parts/CableConverter.java @@ -0,0 +1,37 @@ +package techreborn.partSystem.parts; + +import codechicken.lib.vec.BlockCoord; +import codechicken.multipart.MultiPartRegistry; +import codechicken.multipart.TMultiPart; +import ic2.api.item.IC2Items; +import ic2.core.block.wiring.BlockCable; +import ic2.core.block.wiring.TileEntityCable; +import net.minecraft.block.Block; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import techreborn.partSystem.fmp.FMPModPart; + +import java.util.Arrays; + +public class CableConverter implements MultiPartRegistry.IPartConverter { + @Override + public Iterable blockTypes() { + return Arrays.asList(Block.getBlockFromItem(IC2Items.getItem("copperCableBlock").getItem())); + } + + @Override + public TMultiPart convert(World world, BlockCoord blockCoord) { + Block block = world.getBlock(blockCoord.x, blockCoord.y, blockCoord.z); + if (block instanceof BlockCable) { + TileEntity tileEntity = world.getTileEntity(blockCoord.x, blockCoord.y, blockCoord.z); + if (tileEntity instanceof TileEntityCable) { + TileEntityCable cable = (TileEntityCable) tileEntity; + int type = cable.cableType; + CablePart newPart = new CablePart(); + newPart.setType(type); + return new FMPModPart(newPart); + } + } + return null; + } +} diff --git a/src/main/java/techreborn/partSystem/parts/CablePart.java b/src/main/java/techreborn/partSystem/parts/CablePart.java index b2ba75025..8b241d86f 100644 --- a/src/main/java/techreborn/partSystem/parts/CablePart.java +++ b/src/main/java/techreborn/partSystem/parts/CablePart.java @@ -21,6 +21,7 @@ import net.minecraftforge.common.util.ForgeDirection; import techreborn.client.render.RenderCablePart; import techreborn.init.ModParts; import techreborn.lib.Functions; +import techreborn.lib.Location; import techreborn.lib.vecmath.Vecs3d; import techreborn.lib.vecmath.Vecs3dCube; import techreborn.partSystem.IModPart; @@ -114,12 +115,7 @@ public class CablePart extends ModPart implements IEnergyConductor, INetworkTile @Override public List getOcclusionBoxes() { List vecs3dCubesList = new ArrayList(); - - for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { - if (connectedSides.containsKey(dir)) - vecs3dCubesList.add(boundingBoxes[Functions - .getIntDirFromDirection(dir)]); - } + vecs3dCubesList.add(boundingBoxes[6]); return vecs3dCubesList; } @@ -176,6 +172,14 @@ public class CablePart extends ModPart implements IEnergyConductor, INetworkTile @Override public void nearByChange() { checkConnectedSides(); + for(ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS){ + worldObj.markBlockForUpdate(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ); + IModPart part = ModPartUtils.getPartFromWorld(world, new Location(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ) , this.getName()); + if(part != null){ + CablePart cablePart = (CablePart) part; + cablePart.checkConnectedSides(); + } + } } @Override @@ -186,7 +190,7 @@ public class CablePart extends ModPart implements IEnergyConductor, INetworkTile this.addedToEnergyNet = true; nearByChange(); } - checkConnectedSides(); + nearByChange(); } @Override @@ -206,7 +210,7 @@ public class CablePart extends ModPart implements IEnergyConductor, INetworkTile @Override public ItemStack getItem() { - return ModParts.stackCable.get(type); + return new ItemStack(IC2Items.getItem("copperCableItem").getItem(), 1, type); } public boolean shouldConnectTo(TileEntity entity, ForgeDirection dir) { @@ -215,8 +219,21 @@ public class CablePart extends ModPart implements IEnergyConductor, INetworkTile } else if (entity instanceof IEnergyTile) { return true; } else { - return ModPartUtils.hasPart(entity.getWorldObj(), entity.xCoord, - entity.yCoord, entity.zCoord, this.getName()); + if(ModPartUtils.hasPart(entity.getWorldObj(), entity.xCoord, entity.yCoord, entity.zCoord, this.getName())){ + CablePart otherCable = (CablePart) ModPartUtils.getPartFromWorld(entity.getWorldObj(), new Location(entity.xCoord, entity.yCoord, entity.zCoord), this.getName()); + int thisDir = Functions.getIntDirFromDirection(dir); + int thereDir = Functions.getIntDirFromDirection(dir.getOpposite()); + boolean hasconnection = otherCable.connections[thereDir]; + + otherCable.connections[thereDir] = false; + + if(ModPartUtils.checkOcclusion(entity.getWorldObj(), entity.xCoord, entity.yCoord, entity.zCoord, boundingBoxes[thereDir])){ + otherCable.connections[thereDir] = true; + return true; + } + otherCable.connections[thereDir] = hasconnection; + } + return false; } } @@ -386,10 +403,10 @@ public class CablePart extends ModPart implements IEnergyConductor, INetworkTile String p = null; switch (cableType) { case 0: - p = "copperCable"; + p = "insulatedCopperCable"; break; case 1: - p = "insulatedCopperCable"; + p = "copperCable"; break; case 2: p = "goldCable"; @@ -438,10 +455,10 @@ public class CablePart extends ModPart implements IEnergyConductor, INetworkTile String p = null; switch (cableType) { case 0: - p = "copperCableItem"; + p = "insulatedCopperCableItem"; break; case 1: - p = "insulatedCopperCableItem"; + p = "copperCableItem"; break; case 2: p = "goldCableItem"; @@ -567,4 +584,9 @@ public class CablePart extends ModPart implements IEnergyConductor, INetworkTile public void writeDesc(NBTTagCompound tagCompound) { writeConnectedSidesToNBT(tagCompound); } + + @Override + public boolean needsItem() { + return false; + } } \ No newline at end of file