From 0c025e1033c2c68fe4addac6e24e5c4ecbc418ab Mon Sep 17 00:00:00 2001 From: aidancbrady Date: Fri, 22 Jan 2016 15:41:34 -0500 Subject: [PATCH] Structural Glass is now real, started on core turbine multiblock code --- .../java/mekanism/client/ClientProxy.java | 2 + .../java/mekanism/common/CommonProxy.java | 2 + src/main/java/mekanism/common/Mekanism.java | 2 - .../mekanism/common/block/BlockBasic.java | 84 ++++++------- .../turbine/TurbineUpdateProtocol.java | 6 - .../mekanism/common/item/ItemBlockBasic.java | 14 +-- .../common/multiblock/IMultiblock.java | 6 + .../multiblock/IStructuralMultiblock.java | 17 +++ .../common/multiblock/UpdateProtocol.java | 88 ++++++++++---- .../common/tile/TileEntityDynamicTank.java | 23 ++++ .../tile/TileEntityInductionCasing.java | 23 +++- .../common/tile/TileEntityMultiblock.java | 8 ++ .../TileEntitySolarEvaporationController.java | 5 +- .../tile/TileEntityStructuralGlass.java | 111 ++++++++++++++++++ .../generators/common/GeneratorsItems.java | 11 +- .../generators/common/MekanismGenerators.java | 49 ++++---- .../turbine/SynchronizedTurbineData.java | 2 +- .../common/content/turbine/TurbineCache.java | 9 +- .../turbine/TurbineUpdateProtocol.java | 48 ++++++++ .../common/item/ItemBlockGenerator.java | 15 ++- .../tile/turbine/TileEntityTurbineCasing.java | 47 ++++++++ .../resources/assets/mekanism/lang/en_US.lang | 2 +- 22 files changed, 462 insertions(+), 112 deletions(-) delete mode 100644 src/main/java/mekanism/common/content/turbine/TurbineUpdateProtocol.java create mode 100644 src/main/java/mekanism/common/multiblock/IStructuralMultiblock.java create mode 100644 src/main/java/mekanism/common/tile/TileEntityStructuralGlass.java rename src/main/java/mekanism/{ => generators}/common/content/turbine/SynchronizedTurbineData.java (73%) rename src/main/java/mekanism/{ => generators}/common/content/turbine/TurbineCache.java (70%) create mode 100644 src/main/java/mekanism/generators/common/content/turbine/TurbineUpdateProtocol.java create mode 100644 src/main/java/mekanism/generators/common/tile/turbine/TileEntityTurbineCasing.java diff --git a/src/main/java/mekanism/client/ClientProxy.java b/src/main/java/mekanism/client/ClientProxy.java index dd6f6ddd3..04aff8781 100644 --- a/src/main/java/mekanism/client/ClientProxy.java +++ b/src/main/java/mekanism/client/ClientProxy.java @@ -167,6 +167,7 @@ import mekanism.common.tile.TileEntityRotaryCondensentrator; import mekanism.common.tile.TileEntitySeismicVibrator; import mekanism.common.tile.TileEntitySolarEvaporationController; import mekanism.common.tile.TileEntitySolarNeutronActivator; +import mekanism.common.tile.TileEntityStructuralGlass; import mekanism.common.tile.TileEntityTeleporter; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; @@ -328,6 +329,7 @@ public class ClientProxy extends CommonProxy GameRegistry.registerTileEntity(TileEntityInductionCell.class, "InductionCell"); GameRegistry.registerTileEntity(TileEntityInductionProvider.class, "InductionProvider"); GameRegistry.registerTileEntity(TileEntityOredictionificator.class, "Oredictionificator"); + GameRegistry.registerTileEntity(TileEntityStructuralGlass.class, "StructuralGlass"); } @Override diff --git a/src/main/java/mekanism/common/CommonProxy.java b/src/main/java/mekanism/common/CommonProxy.java index cf63ef433..cd12536db 100644 --- a/src/main/java/mekanism/common/CommonProxy.java +++ b/src/main/java/mekanism/common/CommonProxy.java @@ -104,6 +104,7 @@ import mekanism.common.tile.TileEntityRotaryCondensentrator; import mekanism.common.tile.TileEntitySeismicVibrator; import mekanism.common.tile.TileEntitySolarEvaporationController; import mekanism.common.tile.TileEntitySolarNeutronActivator; +import mekanism.common.tile.TileEntityStructuralGlass; import mekanism.common.tile.TileEntityTeleporter; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -189,6 +190,7 @@ public class CommonProxy GameRegistry.registerTileEntity(TileEntityInductionCell.class, "InductionCell"); GameRegistry.registerTileEntity(TileEntityInductionProvider.class, "InductionProvider"); GameRegistry.registerTileEntity(TileEntityOredictionificator.class, "Oredictionificator"); + GameRegistry.registerTileEntity(TileEntityStructuralGlass.class, "StructuralGlass"); } public void handleTeleporterUpdate(PortableTeleporterMessage message) {} diff --git a/src/main/java/mekanism/common/Mekanism.java b/src/main/java/mekanism/common/Mekanism.java index 784f2db44..33f8124bc 100644 --- a/src/main/java/mekanism/common/Mekanism.java +++ b/src/main/java/mekanism/common/Mekanism.java @@ -47,7 +47,6 @@ import mekanism.common.content.matrix.SynchronizedMatrixData; import mekanism.common.content.tank.SynchronizedTankData; import mekanism.common.content.transporter.PathfinderCache; import mekanism.common.content.transporter.TransporterManager; -import mekanism.common.content.turbine.SynchronizedTurbineData; import mekanism.common.entity.EntityBabySkeleton; import mekanism.common.entity.EntityBalloon; import mekanism.common.entity.EntityFlame; @@ -171,7 +170,6 @@ public class Mekanism /** MultiblockManagers for various structrures */ public static MultiblockManager tankManager = new MultiblockManager("dynamicTank"); public static MultiblockManager matrixManager = new MultiblockManager("inductionMatrix"); - public static MultiblockManager turbineManager = new MultiblockManager("industrialTurbine"); public static MultiblockManager boilerManager = new BoilerManager("thermoelectricBoiler"); /** FrequencyManagers for various networks */ diff --git a/src/main/java/mekanism/common/block/BlockBasic.java b/src/main/java/mekanism/common/block/BlockBasic.java index d2a115d19..9f93d6d95 100644 --- a/src/main/java/mekanism/common/block/BlockBasic.java +++ b/src/main/java/mekanism/common/block/BlockBasic.java @@ -1,11 +1,10 @@ package mekanism.common.block; -import buildcraft.api.tools.IToolWrench; -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; +import java.util.Arrays; +import java.util.List; +import java.util.Random; + import mekanism.api.Coord4D; -import mekanism.api.Range4D; import mekanism.api.energy.IEnergizedItem; import mekanism.api.energy.IStrictEnergyStorage; import mekanism.client.render.MekanismRenderer; @@ -22,8 +21,21 @@ import mekanism.common.base.IBoundingBlock; import mekanism.common.content.tank.TankUpdateProtocol; import mekanism.common.inventory.InventoryBin; import mekanism.common.item.ItemBlockBasic; -import mekanism.common.network.PacketTileEntity.TileEntityMessage; -import mekanism.common.tile.*; +import mekanism.common.multiblock.IMultiblock; +import mekanism.common.multiblock.IStructuralMultiblock; +import mekanism.common.tile.TileEntityBasicBlock; +import mekanism.common.tile.TileEntityBin; +import mekanism.common.tile.TileEntityDynamicTank; +import mekanism.common.tile.TileEntityDynamicValve; +import mekanism.common.tile.TileEntityInductionCasing; +import mekanism.common.tile.TileEntityInductionCell; +import mekanism.common.tile.TileEntityInductionPort; +import mekanism.common.tile.TileEntityInductionProvider; +import mekanism.common.tile.TileEntityMultiblock; +import mekanism.common.tile.TileEntitySolarEvaporationBlock; +import mekanism.common.tile.TileEntitySolarEvaporationController; +import mekanism.common.tile.TileEntitySolarEvaporationValve; +import mekanism.common.tile.TileEntityStructuralGlass; import mekanism.common.util.MekanismUtils; import net.minecraft.block.Block; import net.minecraft.block.material.Material; @@ -46,11 +58,10 @@ import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidStack; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Random; +import buildcraft.api.tools.IToolWrench; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; /** * Block class for handling multiple metal block IDs. @@ -64,7 +75,7 @@ import java.util.Random; * 0:7: Teleporter Frame * 0:8: Steel Casing * 0:9: Dynamic Tank - * 0:10: Dynamic Glass + * 0:10: Structural Glass * 0:11: Dynamic Valve * 0:12: Copper Block * 0:13: Tin Block @@ -128,6 +139,11 @@ public class BlockBasic extends Block implements IBlockCTM, ICustomBlockIcon { ((TileEntityBasicBlock)tileEntity).onNeighborChange(block); } + + if(tileEntity instanceof IStructuralMultiblock) + { + ((IStructuralMultiblock)tileEntity).update(); + } } } @@ -526,24 +542,13 @@ public class BlockBasic extends Block implements IBlockCTM, ICustomBlockIcon return true; } - else if(metadata == 9 || metadata == 10 || metadata == 11) + else if(metadata == 9 || metadata == 11) { - if(!entityplayer.isSneaking() && ((TileEntityDynamicTank)world.getTileEntity(x, y, z)).structure != null) - { - TileEntityDynamicTank tileEntity = (TileEntityDynamicTank)world.getTileEntity(x, y, z); - - if(!manageInventory(entityplayer, tileEntity)) - { - Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(tileEntity), tileEntity.getNetworkedData(new ArrayList())), new Range4D(Coord4D.get(tileEntity))); - entityplayer.openGui(Mekanism.instance, 18, world, x, y, z); - } - else { - entityplayer.inventory.markDirty(); - tileEntity.sendPacketToRenderer(); - } - - return true; - } + return ((IMultiblock)world.getTileEntity(x, y, z)).onActivate(entityplayer); + } + else if(metadata == 10) + { + return ((IStructuralMultiblock)world.getTileEntity(x, y, z)).onActivate(entityplayer); } } else if(blockType == BasicBlock.BASIC_BLOCK_2) @@ -555,15 +560,7 @@ public class BlockBasic extends Block implements IBlockCTM, ICustomBlockIcon if(metadata == 1 || metadata == 2) { - if(!entityplayer.isSneaking() && ((TileEntityInductionCasing)world.getTileEntity(x, y, z)).structure != null) - { - TileEntityInductionCasing tileEntity = (TileEntityInductionCasing)world.getTileEntity(x, y, z); - - Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(tileEntity), tileEntity.getNetworkedData(new ArrayList())), new Range4D(Coord4D.get(tileEntity))); - entityplayer.openGui(Mekanism.instance, 49, world, x, y, z); - - return true; - } + return ((IMultiblock)world.getTileEntity(x, y, z)).onActivate(entityplayer); } } @@ -576,7 +573,7 @@ public class BlockBasic extends Block implements IBlockCTM, ICustomBlockIcon return !(blockType == BasicBlock.BASIC_BLOCK_1 && world.getBlockMetadata(x, y, z) == 10); } - private boolean manageInventory(EntityPlayer player, TileEntityDynamicTank tileEntity) + public static boolean manageInventory(EntityPlayer player, TileEntityDynamicTank tileEntity) { ItemStack itemStack = player.getCurrentEquippedItem(); @@ -808,7 +805,7 @@ public class BlockBasic extends Block implements IBlockCTM, ICustomBlockIcon case 9: return new TileEntityDynamicTank(); case 10: - return new TileEntityDynamicTank(); + return new TileEntityStructuralGlass(); case 11: return new TileEntityDynamicValve(); case 14: @@ -893,6 +890,11 @@ public class BlockBasic extends Block implements IBlockCTM, ICustomBlockIcon { ((TileEntityMultiblock)tileEntity).update(); } + + if(tileEntity instanceof IStructuralMultiblock) + { + ((IStructuralMultiblock)tileEntity).update(); + } } } diff --git a/src/main/java/mekanism/common/content/turbine/TurbineUpdateProtocol.java b/src/main/java/mekanism/common/content/turbine/TurbineUpdateProtocol.java deleted file mode 100644 index 81d437e28..000000000 --- a/src/main/java/mekanism/common/content/turbine/TurbineUpdateProtocol.java +++ /dev/null @@ -1,6 +0,0 @@ -package mekanism.common.content.turbine; - -public class TurbineUpdateProtocol -{ - -} diff --git a/src/main/java/mekanism/common/item/ItemBlockBasic.java b/src/main/java/mekanism/common/item/ItemBlockBasic.java index 03f1be292..9fb8b0acf 100644 --- a/src/main/java/mekanism/common/item/ItemBlockBasic.java +++ b/src/main/java/mekanism/common/item/ItemBlockBasic.java @@ -1,7 +1,8 @@ package mekanism.common.item; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; +import java.util.ArrayList; +import java.util.List; + import mekanism.api.Coord4D; import mekanism.api.EnumColor; import mekanism.api.Range4D; @@ -28,9 +29,8 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.world.World; - -import java.util.ArrayList; -import java.util.List; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; /** * Item class for handling multiple metal block IDs. @@ -44,7 +44,7 @@ import java.util.List; * 0:7: Teleporter Frame * 0:8: Steel Casing * 0:9: Dynamic Tank - * 0:10: Dynamic Glass + * 0:10: Structural Glass * 0:11: Dynamic Valve * 0:12: Copper Block * 0:13: Tin Block @@ -306,7 +306,7 @@ public class ItemBlockBasic extends ItemBlock implements IEnergizedItem name = "DynamicTank"; break; case 10: - name = "DynamicGlass"; + name = "StructuralGlass"; break; case 11: name = "DynamicValve"; diff --git a/src/main/java/mekanism/common/multiblock/IMultiblock.java b/src/main/java/mekanism/common/multiblock/IMultiblock.java index dc2ae616b..97ec03128 100644 --- a/src/main/java/mekanism/common/multiblock/IMultiblock.java +++ b/src/main/java/mekanism/common/multiblock/IMultiblock.java @@ -1,6 +1,12 @@ package mekanism.common.multiblock; +import net.minecraft.entity.player.EntityPlayer; + public interface IMultiblock> { public T getSynchronizedData(); + + public boolean onActivate(EntityPlayer player); + + public void update(); } diff --git a/src/main/java/mekanism/common/multiblock/IStructuralMultiblock.java b/src/main/java/mekanism/common/multiblock/IStructuralMultiblock.java new file mode 100644 index 000000000..eda5c272a --- /dev/null +++ b/src/main/java/mekanism/common/multiblock/IStructuralMultiblock.java @@ -0,0 +1,17 @@ +package mekanism.common.multiblock; + +import mekanism.api.Coord4D; +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; + +public interface IStructuralMultiblock +{ + public boolean onActivate(EntityPlayer player); + + public boolean canInterface(TileEntity controller); + + public void setController(Coord4D coord); + + public void update(); +} diff --git a/src/main/java/mekanism/common/multiblock/UpdateProtocol.java b/src/main/java/mekanism/common/multiblock/UpdateProtocol.java index 80e20b18a..dd400a896 100644 --- a/src/main/java/mekanism/common/multiblock/UpdateProtocol.java +++ b/src/main/java/mekanism/common/multiblock/UpdateProtocol.java @@ -6,7 +6,6 @@ import java.util.List; import java.util.Set; import mekanism.api.Coord4D; -import mekanism.common.Mekanism; import mekanism.common.tile.TileEntityMultiblock; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; @@ -16,7 +15,7 @@ import net.minecraftforge.common.util.ForgeDirection; public abstract class UpdateProtocol> { /** The multiblock nodes that have already been iterated over. */ - public Set> iteratedNodes = new HashSet>(); + public Set iteratedNodes = new HashSet(); public Set innerNodes = new HashSet(); @@ -35,7 +34,7 @@ public abstract class UpdateProtocol> * Recursively loops through each node connected to the given TileEntity. * @param tile - the TileEntity to loop over */ - public void loopThrough(TileEntityMultiblock tile) + public void loopThrough(TileEntity tile) { World worldObj = tile.getWorldObj(); @@ -200,7 +199,7 @@ public abstract class UpdateProtocol> if(structure.locations.contains(Coord4D.get(pointer)) && isCorrectCorner(Coord4D.get(tile), origX+xmin, origY+ymin, origZ+zmin)) { - if(isInteriorValid(structure)) + if(canForm(structure)) { structureFound = structure; return; @@ -215,19 +214,20 @@ public abstract class UpdateProtocol> for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { - TileEntity tileEntity = Coord4D.get(tile).getFromSide(side).getTileEntity(tile.getWorldObj()); + Coord4D coord = Coord4D.get(tile).getFromSide(side); + TileEntity tileEntity = coord.getTileEntity(tile.getWorldObj()); - if(MultiblockManager.areEqual(tileEntity, pointer)) + if(isViableNode(coord.xCoord, coord.yCoord, coord.zCoord)) { if(!iteratedNodes.contains(tileEntity)) { - loopThrough((TileEntityMultiblock)tileEntity); + loopThrough(tileEntity); } } } } - public boolean isInteriorValid(T structure) + public boolean canForm(T structure) { return true; } @@ -290,6 +290,14 @@ public abstract class UpdateProtocol> { TileEntity tile = pointer.getWorldObj().getTileEntity(x, y, z); + if(tile instanceof IStructuralMultiblock) + { + if(((IStructuralMultiblock)tile).canInterface(pointer)) + { + return true; + } + } + if(MultiblockManager.areEqual(tile, pointer)) { return true; @@ -392,13 +400,20 @@ public abstract class UpdateProtocol> if(structureFound != null) { - for(TileEntityMultiblock tileEntity : iteratedNodes) + for(TileEntity tileEntity : iteratedNodes) { if(!structureFound.locations.contains(Coord4D.get(tileEntity))) { for(TileEntity tile : iteratedNodes) { - ((TileEntityMultiblock)tile).structure = null; + if(tile instanceof TileEntityMultiblock) + { + ((TileEntityMultiblock)tile).structure = null; + } + else if(tile instanceof IStructuralMultiblock) + { + ((IStructuralMultiblock)tile).setController(null); + } } return; @@ -410,11 +425,11 @@ public abstract class UpdateProtocol> for(Coord4D obj : structureFound.locations) { - TileEntityMultiblock tileEntity = (TileEntityMultiblock)obj.getTileEntity(pointer.getWorldObj()); + TileEntity tileEntity = obj.getTileEntity(pointer.getWorldObj()); - if(tileEntity.cachedID != null) + if(tileEntity instanceof TileEntityMultiblock && ((TileEntityMultiblock)tileEntity).cachedID != null) { - idsFound.add(tileEntity.cachedID); + idsFound.add(((TileEntityMultiblock)tileEntity).cachedID); } } @@ -452,24 +467,55 @@ public abstract class UpdateProtocol> onFormed(); structureFound.inventoryID = idToUse; + + List structures = new ArrayList(); + Coord4D toUse = null; for(Coord4D obj : structureFound.locations) { - TileEntityMultiblock tileEntity = (TileEntityMultiblock)obj.getTileEntity(pointer.getWorldObj()); + TileEntity tileEntity = obj.getTileEntity(pointer.getWorldObj()); - tileEntity.structure = (T)structureFound; + if(tileEntity instanceof TileEntityMultiblock) + { + ((TileEntityMultiblock)tileEntity).structure = structureFound; + + if(toUse == null) + { + toUse = obj.clone(); + } + } + else if(tileEntity instanceof IStructuralMultiblock) + { + structures.add((IStructuralMultiblock)tileEntity); + } + } + + //Remove all structural multiblocks from locations, set controllers + for(IStructuralMultiblock node : structures) + { + node.setController(toUse); + structureFound.locations.remove(Coord4D.get((TileEntity)node)); } } else { - for(TileEntityMultiblock tileEntity : iteratedNodes) + for(TileEntity tile : iteratedNodes) { - if(tileEntity.structure != null && !tileEntity.structure.destroyed) + if(tile instanceof TileEntityMultiblock) { - onStructureDestroyed(tileEntity.structure); - tileEntity.structure.destroyed = true; + TileEntityMultiblock tileEntity = (TileEntityMultiblock)tile; + + if(tileEntity.structure != null && !tileEntity.structure.destroyed) + { + onStructureDestroyed(tileEntity.structure); + tileEntity.structure.destroyed = true; + } + + tileEntity.structure = null; + } + else if(tile instanceof IStructuralMultiblock) + { + ((IStructuralMultiblock)tile).setController(null); } - - tileEntity.structure = null; } } } diff --git a/src/main/java/mekanism/common/tile/TileEntityDynamicTank.java b/src/main/java/mekanism/common/tile/TileEntityDynamicTank.java index 5f2f6cf76..490e07163 100644 --- a/src/main/java/mekanism/common/tile/TileEntityDynamicTank.java +++ b/src/main/java/mekanism/common/tile/TileEntityDynamicTank.java @@ -10,6 +10,7 @@ import mekanism.api.Coord4D; import mekanism.api.Range4D; import mekanism.common.Mekanism; import mekanism.common.base.IFluidContainerManager; +import mekanism.common.block.BlockBasic; import mekanism.common.content.tank.SynchronizedTankData; import mekanism.common.content.tank.SynchronizedTankData.ValveData; import mekanism.common.content.tank.TankCache; @@ -18,6 +19,7 @@ import mekanism.common.multiblock.MultiblockManager; import mekanism.common.network.PacketTileEntity.TileEntityMessage; import mekanism.common.util.FluidContainerUtils; import mekanism.common.util.FluidContainerUtils.ContainerEditMode; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidContainerRegistry; @@ -280,6 +282,27 @@ public class TileEntityDynamicTank extends TileEntityMultiblock implements IStrictEnergyStorage, IComputerIntegration { public int clientCells; @@ -52,6 +57,20 @@ public class TileEntityInductionCasing extends TileEntityMultiblock> extend } } + @Override public void update() { if(!worldObj.isRemote && (structure == null || !getSynchronizedData().didTick)) @@ -273,6 +275,12 @@ public abstract class TileEntityMultiblock> extend } } + @Override + public boolean onActivate(EntityPlayer player) + { + return false; + } + @Override @SideOnly(Side.CLIENT) public AxisAlignedBB getRenderBoundingBox() diff --git a/src/main/java/mekanism/common/tile/TileEntitySolarEvaporationController.java b/src/main/java/mekanism/common/tile/TileEntitySolarEvaporationController.java index 3e46ee8c1..672bfe92a 100644 --- a/src/main/java/mekanism/common/tile/TileEntitySolarEvaporationController.java +++ b/src/main/java/mekanism/common/tile/TileEntitySolarEvaporationController.java @@ -758,10 +758,7 @@ public class TileEntitySolarEvaporationController extends TileEntitySolarEvapora } @Override - public void setActive(boolean active) - { - - } + public void setActive(boolean active) {} @Override public boolean renderUpdate() diff --git a/src/main/java/mekanism/common/tile/TileEntityStructuralGlass.java b/src/main/java/mekanism/common/tile/TileEntityStructuralGlass.java new file mode 100644 index 000000000..b13dd889c --- /dev/null +++ b/src/main/java/mekanism/common/tile/TileEntityStructuralGlass.java @@ -0,0 +1,111 @@ +package mekanism.common.tile; + +import java.util.HashSet; +import java.util.Set; + +import mekanism.api.Coord4D; +import mekanism.common.multiblock.IMultiblock; +import mekanism.common.multiblock.IStructuralMultiblock; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; + +public class TileEntityStructuralGlass extends TileEntity implements IStructuralMultiblock +{ + public Coord4D master; + + @Override + public boolean onActivate(EntityPlayer player) + { + if(master != null) + { + if(master.getTileEntity(worldObj) instanceof IMultiblock) + { + return ((IMultiblock)master.getTileEntity(worldObj)).onActivate(player); + } + else { + master = null; + } + } + + return false; + } + + @Override + public void update() + { + if(master != null) + { + if(master.getTileEntity(worldObj) instanceof IMultiblock) + { + ((IMultiblock)master.getTileEntity(worldObj)).update(); + } + else { + master = null; + } + } + else { + IMultiblock multiblock = new ControllerFinder().find(); + + if(multiblock != null) + { + multiblock.update(); + } + } + } + + @Override + public boolean canInterface(TileEntity controller) + { + return true; + } + + @Override + public void setController(Coord4D coord) + { + master = coord; + } + + public class ControllerFinder + { + public IMultiblock found; + + public Set iterated = new HashSet(); + + public void loop(Coord4D pos) + { + if(iterated.size() > 512 || found != null) + { + return; + } + + iterated.add(pos); + + for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) + { + Coord4D coord = pos.getFromSide(side); + TileEntity tile = coord.getTileEntity(worldObj); + + if(!iterated.contains(coord)) + { + if(tile instanceof IMultiblock) + { + found = (IMultiblock)coord.getTileEntity(worldObj); + return; + } + else if(tile instanceof IStructuralMultiblock) + { + loop(coord); + } + } + } + } + + public IMultiblock find() + { + loop(Coord4D.get(TileEntityStructuralGlass.this)); + + return found; + } + } +} diff --git a/src/main/java/mekanism/generators/common/GeneratorsItems.java b/src/main/java/mekanism/generators/common/GeneratorsItems.java index 9eaf8ffe8..a111f5727 100644 --- a/src/main/java/mekanism/generators/common/GeneratorsItems.java +++ b/src/main/java/mekanism/generators/common/GeneratorsItems.java @@ -2,7 +2,10 @@ package mekanism.generators.common; import mekanism.common.item.ItemMekanism; import mekanism.generators.common.item.ItemHohlraum; +import mekanism.generators.common.tile.turbine.TileEntityTurbineRod; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; +import net.minecraft.world.World; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry.ObjectHolder; @@ -11,7 +14,13 @@ public class GeneratorsItems { public static final Item SolarPanel = new ItemMekanism().setUnlocalizedName("SolarPanel"); public static final ItemHohlraum Hohlraum = (ItemHohlraum)new ItemHohlraum().setUnlocalizedName("Hohlraum"); - public static final Item TurbineBlade = new ItemMekanism().setUnlocalizedName("TurbineBlade"); + public static final Item TurbineBlade = new ItemMekanism() { + @Override + public boolean doesSneakBypassUse(World world, int x, int y, int z, EntityPlayer player) + { + return world.getTileEntity(x, y, z) instanceof TileEntityTurbineRod; + } + }.setUnlocalizedName("TurbineBlade"); public static void register() { diff --git a/src/main/java/mekanism/generators/common/MekanismGenerators.java b/src/main/java/mekanism/generators/common/MekanismGenerators.java index eff099f54..4dd72ec76 100644 --- a/src/main/java/mekanism/generators/common/MekanismGenerators.java +++ b/src/main/java/mekanism/generators/common/MekanismGenerators.java @@ -1,5 +1,32 @@ package mekanism.generators.common; +import io.netty.buffer.ByteBuf; + +import java.io.IOException; + +import mekanism.api.MekanismConfig.general; +import mekanism.api.MekanismConfig.generators; +import mekanism.api.gas.Gas; +import mekanism.api.gas.GasRegistry; +import mekanism.api.infuse.InfuseRegistry; +import mekanism.common.FuelHandler; +import mekanism.common.Mekanism; +import mekanism.common.MekanismBlocks; +import mekanism.common.MekanismItems; +import mekanism.common.Tier.BaseTier; +import mekanism.common.Version; +import mekanism.common.base.IModule; +import mekanism.common.multiblock.MultiblockManager; +import mekanism.common.recipe.RecipeHandler; +import mekanism.common.recipe.ShapedMekanismRecipe; +import mekanism.common.util.MekanismUtils; +import mekanism.generators.common.content.turbine.SynchronizedTurbineData; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.CraftingManager; +import net.minecraftforge.fluids.FluidContainerRegistry; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.oredict.OreDictionary; import buildcraft.api.fuels.BuildcraftFuelRegistry; import buildcraft.api.fuels.IFuel; import cpw.mods.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent; @@ -13,26 +40,6 @@ import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.network.NetworkRegistry; -import io.netty.buffer.ByteBuf; -import mekanism.api.MekanismConfig.general; -import mekanism.api.MekanismConfig.generators; -import mekanism.api.gas.Gas; -import mekanism.api.gas.GasRegistry; -import mekanism.api.infuse.InfuseRegistry; -import mekanism.common.*; -import mekanism.common.Tier.BaseTier; -import mekanism.common.base.IModule; -import mekanism.common.recipe.ShapedMekanismRecipe; -import mekanism.common.recipe.RecipeHandler; -import mekanism.common.util.MekanismUtils; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.CraftingManager; -import net.minecraftforge.fluids.FluidContainerRegistry; -import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.oredict.OreDictionary; - -import java.io.IOException; @Mod(modid = "MekanismGenerators", name = "MekanismGenerators", version = "9.0.0", dependencies = "required-after:Mekanism", guiFactory = "mekanism.generators.client.gui.GeneratorsGuiFactory") public class MekanismGenerators implements IModule @@ -48,6 +55,8 @@ public class MekanismGenerators implements IModule /** MekanismGenerators version number */ public static Version versionNumber = new Version(9, 0, 0); + + public static MultiblockManager turbineManager = new MultiblockManager("industrialTurbine"); @EventHandler public void preInit(FMLPreInitializationEvent event) diff --git a/src/main/java/mekanism/common/content/turbine/SynchronizedTurbineData.java b/src/main/java/mekanism/generators/common/content/turbine/SynchronizedTurbineData.java similarity index 73% rename from src/main/java/mekanism/common/content/turbine/SynchronizedTurbineData.java rename to src/main/java/mekanism/generators/common/content/turbine/SynchronizedTurbineData.java index a7291b75a..f29539102 100644 --- a/src/main/java/mekanism/common/content/turbine/SynchronizedTurbineData.java +++ b/src/main/java/mekanism/generators/common/content/turbine/SynchronizedTurbineData.java @@ -1,4 +1,4 @@ -package mekanism.common.content.turbine; +package mekanism.generators.common.content.turbine; import mekanism.common.multiblock.SynchronizedData; diff --git a/src/main/java/mekanism/common/content/turbine/TurbineCache.java b/src/main/java/mekanism/generators/common/content/turbine/TurbineCache.java similarity index 70% rename from src/main/java/mekanism/common/content/turbine/TurbineCache.java rename to src/main/java/mekanism/generators/common/content/turbine/TurbineCache.java index f2ac0a065..424828601 100644 --- a/src/main/java/mekanism/common/content/turbine/TurbineCache.java +++ b/src/main/java/mekanism/generators/common/content/turbine/TurbineCache.java @@ -1,13 +1,12 @@ -package mekanism.common.content.turbine; - -import mekanism.common.multiblock.MultiblockCache; +package mekanism.generators.common.content.turbine; import net.minecraft.nbt.NBTTagCompound; +import mekanism.common.multiblock.MultiblockCache; public class TurbineCache extends MultiblockCache { @Override - public void apply(SynchronizedTurbineData data) + public void apply(SynchronizedTurbineData data) { } @@ -19,7 +18,7 @@ public class TurbineCache extends MultiblockCache } @Override - public void load(NBTTagCompound nbtTags) + public void load(NBTTagCompound nbtTags) { } diff --git a/src/main/java/mekanism/generators/common/content/turbine/TurbineUpdateProtocol.java b/src/main/java/mekanism/generators/common/content/turbine/TurbineUpdateProtocol.java new file mode 100644 index 000000000..2edafd6ce --- /dev/null +++ b/src/main/java/mekanism/generators/common/content/turbine/TurbineUpdateProtocol.java @@ -0,0 +1,48 @@ +package mekanism.generators.common.content.turbine; + +import java.util.List; + +import mekanism.common.multiblock.MultiblockCache; +import mekanism.common.multiblock.MultiblockManager; +import mekanism.common.multiblock.UpdateProtocol; +import mekanism.generators.common.MekanismGenerators; +import mekanism.generators.common.tile.turbine.TileEntityTurbineCasing; +import net.minecraft.item.ItemStack; + +public class TurbineUpdateProtocol extends UpdateProtocol +{ + public TurbineUpdateProtocol(TileEntityTurbineCasing tileEntity) + { + super(tileEntity); + } + + @Override + protected boolean isValidFrame(int x, int y, int z) + { + return false; + } + + @Override + protected MultiblockCache getNewCache() + { + return new TurbineCache(); + } + + @Override + protected SynchronizedTurbineData getNewStructure() + { + return new SynchronizedTurbineData(); + } + + @Override + protected MultiblockManager getManager() + { + return MekanismGenerators.turbineManager; + } + + @Override + protected void mergeCaches(List rejectedItems, MultiblockCache cache, MultiblockCache merge) + { + + } +} diff --git a/src/main/java/mekanism/generators/common/item/ItemBlockGenerator.java b/src/main/java/mekanism/generators/common/item/ItemBlockGenerator.java index 3dd6a8b13..eefe6af17 100644 --- a/src/main/java/mekanism/generators/common/item/ItemBlockGenerator.java +++ b/src/main/java/mekanism/generators/common/item/ItemBlockGenerator.java @@ -65,7 +65,20 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, ISp super(block); metaBlock = block; setHasSubtypes(true); - setMaxStackSize(1); + } + + @Override + public int getItemStackLimit(ItemStack stack) + { + GeneratorType type = GeneratorType.getFromMetadata(stack.getItemDamage()); + + if(type == GeneratorType.TURBINE_ROD || type == GeneratorType.ROTATIONAL_COMPLEX) + { + return 64; + } + else { + return 1; + } } @Override diff --git a/src/main/java/mekanism/generators/common/tile/turbine/TileEntityTurbineCasing.java b/src/main/java/mekanism/generators/common/tile/turbine/TileEntityTurbineCasing.java new file mode 100644 index 000000000..862606378 --- /dev/null +++ b/src/main/java/mekanism/generators/common/tile/turbine/TileEntityTurbineCasing.java @@ -0,0 +1,47 @@ +package mekanism.generators.common.tile.turbine; + +import mekanism.common.multiblock.MultiblockCache; +import mekanism.common.multiblock.MultiblockManager; +import mekanism.common.multiblock.UpdateProtocol; +import mekanism.common.tile.TileEntityMultiblock; +import mekanism.generators.common.MekanismGenerators; +import mekanism.generators.common.content.turbine.SynchronizedTurbineData; +import mekanism.generators.common.content.turbine.TurbineCache; +import mekanism.generators.common.content.turbine.TurbineUpdateProtocol; + +public class TileEntityTurbineCasing extends TileEntityMultiblock +{ + public TileEntityTurbineCasing() + { + this("TurbineCasing"); + } + + public TileEntityTurbineCasing(String name) + { + super(name); + } + + @Override + protected SynchronizedTurbineData getNewStructure() + { + return new SynchronizedTurbineData(); + } + + @Override + public MultiblockCache getNewCache() + { + return new TurbineCache(); + } + + @Override + protected UpdateProtocol getProtocol() + { + return new TurbineUpdateProtocol(this); + } + + @Override + public MultiblockManager getManager() + { + return MekanismGenerators.turbineManager; + } +} diff --git a/src/main/resources/assets/mekanism/lang/en_US.lang b/src/main/resources/assets/mekanism/lang/en_US.lang index 698be237c..203b9c6d2 100644 --- a/src/main/resources/assets/mekanism/lang/en_US.lang +++ b/src/main/resources/assets/mekanism/lang/en_US.lang @@ -77,7 +77,7 @@ tile.BasicBlock.Bin.name=Bin tile.BasicBlock.TeleporterFrame.name=Teleporter Frame tile.BasicBlock.SteelCasing.name=Steel Casing tile.BasicBlock.DynamicTank.name=Dynamic Tank -tile.BasicBlock.DynamicGlass.name=Dynamic Glass +tile.BasicBlock.StructuralGlass.name=Structural Glass tile.BasicBlock.DynamicValve.name=Dynamic Valve tile.BasicBlock.CopperBlock.name=Copper Block tile.BasicBlock.TinBlock.name=Tin Block