From 1eb3ef3db67e15b8dc2637c4b4a8020a5a565279 Mon Sep 17 00:00:00 2001 From: Modmuss50 Date: Fri, 17 Apr 2015 17:42:57 +0100 Subject: [PATCH] Some more work on the multiblock system --- src/main/java/techreborn/Core.java | 4 +++ .../api/multiblock/BaseMultiBlock.java | 28 +++++++++++++++ .../api/multiblock/IMultiBlock.java | 9 +++-- .../api/multiblock/IMultiBlockController.java | 7 ++++ .../api/multiblock/IMultiblockComponent.java | 4 +-- .../api/multiblock/MultiBlockController.java | 17 +++++++++ .../techreborn/blocks/BlockBlastFurnace.java | 13 ++++--- .../techreborn/blocks/BlockMachineCasing.java | 19 ++++++---- .../techreborn/event/MultiblockEvent.java | 15 ++++---- src/main/java/techreborn/init/ModBlocks.java | 1 + .../multiblocks/MultiBlastfurnace.java | 36 +++++++++++++++++++ .../techreborn/tiles/TileBlastFurnace.java | 13 ++++--- .../techreborn/tiles/TileMachineCasing.java | 19 ++++++++++ 13 files changed, 158 insertions(+), 27 deletions(-) create mode 100644 src/main/java/techreborn/api/multiblock/BaseMultiBlock.java create mode 100644 src/main/java/techreborn/api/multiblock/IMultiBlockController.java create mode 100644 src/main/java/techreborn/api/multiblock/MultiBlockController.java create mode 100644 src/main/java/techreborn/multiblocks/MultiBlastfurnace.java create mode 100644 src/main/java/techreborn/tiles/TileMachineCasing.java diff --git a/src/main/java/techreborn/Core.java b/src/main/java/techreborn/Core.java index 50b1d6c92..2977456ef 100644 --- a/src/main/java/techreborn/Core.java +++ b/src/main/java/techreborn/Core.java @@ -5,9 +5,11 @@ import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.registry.GameRegistry; +import net.minecraftforge.common.MinecraftForge; import techreborn.client.GuiHandler; import techreborn.compat.CompatManager; import techreborn.config.ConfigTechReborn; +import techreborn.event.MultiblockEvent; import techreborn.init.ModBlocks; import techreborn.init.ModItems; import techreborn.init.ModRecipes; @@ -51,6 +53,8 @@ public class Core { NetworkRegistry.INSTANCE.registerGuiHandler(INSTANCE, new GuiHandler()); //packets PacketHandler.setChannels(NetworkRegistry.INSTANCE.newChannel(ModInfo.MOD_ID + "_packets", new PacketHandler())); + //Events + MinecraftForge.EVENT_BUS.register(new MultiblockEvent()); LogHelper.info("Initialization Compleate"); } diff --git a/src/main/java/techreborn/api/multiblock/BaseMultiBlock.java b/src/main/java/techreborn/api/multiblock/BaseMultiBlock.java new file mode 100644 index 000000000..5375f4fbc --- /dev/null +++ b/src/main/java/techreborn/api/multiblock/BaseMultiBlock.java @@ -0,0 +1,28 @@ +package techreborn.api.multiblock; + +import net.minecraft.tileentity.TileEntity; + +public abstract class BaseMultiBlock implements IMultiBlock { + + boolean isComplete = false; + + TileEntity parent; + + public BaseMultiBlock(TileEntity parent) { + this.parent = parent; + } + + @Override + public boolean isComplete() { + return isComplete; + } + + @Override + public TileEntity getController() { + return parent; + } + + public void setIsComplete(boolean isComplete) { + this.isComplete = isComplete; + } +} diff --git a/src/main/java/techreborn/api/multiblock/IMultiBlock.java b/src/main/java/techreborn/api/multiblock/IMultiBlock.java index 756bf1195..287e370cd 100644 --- a/src/main/java/techreborn/api/multiblock/IMultiBlock.java +++ b/src/main/java/techreborn/api/multiblock/IMultiBlock.java @@ -9,12 +9,17 @@ public interface IMultiBlock { /** * This is the name of the multiblock */ - void getName(); + String getName(); /** * This check to see if the multiblock is complete */ - boolean checkIfComplete(int x, int y, int z); + boolean checkIfComplete(); + + /** + * This check to see if the multiblock is complete + */ + boolean isComplete(); /** * This is a list of all of the tiles that make up the multiblock diff --git a/src/main/java/techreborn/api/multiblock/IMultiBlockController.java b/src/main/java/techreborn/api/multiblock/IMultiBlockController.java new file mode 100644 index 000000000..9f635b7e5 --- /dev/null +++ b/src/main/java/techreborn/api/multiblock/IMultiBlockController.java @@ -0,0 +1,7 @@ +package techreborn.api.multiblock; + +public interface IMultiBlockController { + + IMultiBlock getMultiBlock(); + +} diff --git a/src/main/java/techreborn/api/multiblock/IMultiblockComponent.java b/src/main/java/techreborn/api/multiblock/IMultiblockComponent.java index ca5cac5bb..61471d99e 100644 --- a/src/main/java/techreborn/api/multiblock/IMultiblockComponent.java +++ b/src/main/java/techreborn/api/multiblock/IMultiblockComponent.java @@ -3,7 +3,7 @@ package techreborn.api.multiblock; public interface IMultiblockComponent { /** - * This gets the multiblock type, allow for different meta data for different structures, + * This gets the instance of the multiblock , allow for different meta data for different structures, */ - IMultiBlock getMultiblock(int meta); + Class getMultiblockType(); } diff --git a/src/main/java/techreborn/api/multiblock/MultiBlockController.java b/src/main/java/techreborn/api/multiblock/MultiBlockController.java new file mode 100644 index 000000000..0dc3aaaee --- /dev/null +++ b/src/main/java/techreborn/api/multiblock/MultiBlockController.java @@ -0,0 +1,17 @@ +package techreborn.api.multiblock; + +import net.minecraft.tileentity.TileEntity; + +public class MultiBlockController extends TileEntity implements IMultiBlockController{ + + BaseMultiBlock multiBlock; + + public MultiBlockController(BaseMultiBlock multiBlock) { + this.multiBlock = multiBlock; + } + + @Override + public IMultiBlock getMultiBlock() { + return multiBlock; + } +} diff --git a/src/main/java/techreborn/blocks/BlockBlastFurnace.java b/src/main/java/techreborn/blocks/BlockBlastFurnace.java index e56fa9666..f4a49d5b4 100644 --- a/src/main/java/techreborn/blocks/BlockBlastFurnace.java +++ b/src/main/java/techreborn/blocks/BlockBlastFurnace.java @@ -2,12 +2,6 @@ package techreborn.blocks; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import techreborn.Core; -import techreborn.client.GuiHandler; -import techreborn.client.TechRebornCreativeTab; -import techreborn.tiles.TileBlastFurnace; -import techreborn.tiles.TileCentrifuge; -import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; @@ -15,6 +9,11 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.world.World; +import techreborn.Core; +import techreborn.client.GuiHandler; +import techreborn.client.TechRebornCreativeTab; +import techreborn.multiblocks.MultiBlastfurnace; +import techreborn.tiles.TileBlastFurnace; public class BlockBlastFurnace extends BlockContainer{ @@ -33,7 +32,7 @@ public class BlockBlastFurnace extends BlockContainer{ @Override public TileEntity createNewTileEntity(World world, int p_149915_2_) { - return new TileBlastFurnace(); + return new TileBlastFurnace(new MultiBlastfurnace()); } @Override diff --git a/src/main/java/techreborn/blocks/BlockMachineCasing.java b/src/main/java/techreborn/blocks/BlockMachineCasing.java index 3e6974b4c..76fc5bd9f 100644 --- a/src/main/java/techreborn/blocks/BlockMachineCasing.java +++ b/src/main/java/techreborn/blocks/BlockMachineCasing.java @@ -1,22 +1,25 @@ package techreborn.blocks; -import java.util.List; -import java.util.Random; - import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import techreborn.client.TechRebornCreativeTab; -import net.minecraft.block.Block; +import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.util.MathHelper; +import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; +import techreborn.client.TechRebornCreativeTab; +import techreborn.tiles.TileMachineCasing; -public class BlockMachineCasing extends Block{ +import java.util.List; +import java.util.Random; + +public class BlockMachineCasing extends BlockContainer { public static final String[] types = new String[] {"Standard", "Reinforced", "Advanced"}; private IIcon[] textures; @@ -71,4 +74,8 @@ public class BlockMachineCasing extends Block{ } } + @Override + public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) { + return new TileMachineCasing(); + } } diff --git a/src/main/java/techreborn/event/MultiblockEvent.java b/src/main/java/techreborn/event/MultiblockEvent.java index 3d7d7eb90..2411e0862 100644 --- a/src/main/java/techreborn/event/MultiblockEvent.java +++ b/src/main/java/techreborn/event/MultiblockEvent.java @@ -7,17 +7,20 @@ public class MultiblockEvent { @SubscribeEvent public void blockBreakEvent(net.minecraftforge.event.world.BlockEvent.BreakEvent event){ - if(event.block instanceof IMultiblockComponent){ - IMultiblockComponent component = (IMultiblockComponent) event.block; - component.getMultiblock(event.world.getBlockMetadata(event.x, event.y, event.z)).recompute(); + if(event.world.getTileEntity(event.x, event.y, event.z) instanceof IMultiblockComponent){ + IMultiblockComponent component = (IMultiblockComponent) event.world.getTileEntity(event.x, event.y, event.z); +// if(component.getMultiblock() != null) +// component.getMultiblock().recompute(); + //TODO find all multiblock controllers fo the same type that are near this location and recompute. } } @SubscribeEvent public void blockPlaceEvent(net.minecraftforge.event.world.BlockEvent.PlaceEvent event){ - if(event.block instanceof IMultiblockComponent){ - IMultiblockComponent component = (IMultiblockComponent) event.block; - component.getMultiblock(event.world.getBlockMetadata(event.x, event.y, event.z)).recompute(); + if(event.world.getTileEntity(event.x, event.y, event.z) instanceof IMultiblockComponent){ + IMultiblockComponent component = (IMultiblockComponent) event.world.getTileEntity(event.x, event.y, event.z); +// if(component.getMultiblock() != null) +// component.getMultiblock().recompute(); } } } diff --git a/src/main/java/techreborn/init/ModBlocks.java b/src/main/java/techreborn/init/ModBlocks.java index d4642ddb3..c2539c3c6 100644 --- a/src/main/java/techreborn/init/ModBlocks.java +++ b/src/main/java/techreborn/init/ModBlocks.java @@ -55,6 +55,7 @@ public class ModBlocks { MachineCasing = new BlockMachineCasing(Material.piston); GameRegistry.registerBlock(MachineCasing, ItemBlockMachineCasing.class, "machinecasing"); + GameRegistry.registerTileEntity(TileMachineCasing.class, "TileMachineCasing"); ore = new BlockOre(Material.rock); GameRegistry.registerBlock(ore, ItemBlockOre.class, "techreborn.ore"); diff --git a/src/main/java/techreborn/multiblocks/MultiBlastfurnace.java b/src/main/java/techreborn/multiblocks/MultiBlastfurnace.java new file mode 100644 index 000000000..323602952 --- /dev/null +++ b/src/main/java/techreborn/multiblocks/MultiBlastfurnace.java @@ -0,0 +1,36 @@ +package techreborn.multiblocks; + +import net.minecraft.init.Blocks; +import net.minecraft.tileentity.TileEntity; +import techreborn.api.multiblock.BaseMultiBlock; +import techreborn.init.ModBlocks; + +import java.util.List; + +public class MultiBlastfurnace extends BaseMultiBlock { + + public MultiBlastfurnace(TileEntity parent) { + super(parent); + } + + @Override + public String getName() { + return "BlastFurnaceMultiBlock"; + } + + @Override + public boolean checkIfComplete() { + return getController().getWorldObj().getBlock(getController().xCoord, getController().yCoord + 1, getController().zCoord) == ModBlocks.MachineCasing; + } + + + @Override + public List getTiles() { + return null; + } + + @Override + public void recompute() { + com + } +} diff --git a/src/main/java/techreborn/tiles/TileBlastFurnace.java b/src/main/java/techreborn/tiles/TileBlastFurnace.java index a3adbc690..b08f6863a 100644 --- a/src/main/java/techreborn/tiles/TileBlastFurnace.java +++ b/src/main/java/techreborn/tiles/TileBlastFurnace.java @@ -1,19 +1,24 @@ package techreborn.tiles; -import techreborn.init.ModBlocks; -import techreborn.util.Inventory; import ic2.api.energy.prefab.BasicSink; import ic2.api.tile.IWrenchable; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import techreborn.api.multiblock.IMultiBlock; +import techreborn.api.multiblock.MultiBlockController; +import techreborn.init.ModBlocks; +import techreborn.util.Inventory; -public class TileBlastFurnace extends TileMachineBase implements IWrenchable { +public class TileBlastFurnace extends MultiBlockController implements IWrenchable { public int tickTime; public BasicSink energy; public Inventory inventory = new Inventory(3, "TileBlastFurnace", 64); + public TileBlastFurnace(IMultiBlock multiBlock) { + super(multiBlock); + } + @Override public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) { return false; diff --git a/src/main/java/techreborn/tiles/TileMachineCasing.java b/src/main/java/techreborn/tiles/TileMachineCasing.java new file mode 100644 index 000000000..2138be8c1 --- /dev/null +++ b/src/main/java/techreborn/tiles/TileMachineCasing.java @@ -0,0 +1,19 @@ +package techreborn.tiles; + +import net.minecraft.tileentity.TileEntity; +import techreborn.api.multiblock.IMultiblockComponent; +import techreborn.multiblocks.MultiBlastfurnace; + +public class TileMachineCasing extends TileEntity implements IMultiblockComponent { + + @Override + public boolean canUpdate() { + //No need to update this. + return false; + } + + @Override + public Class getMultiblockType() { + return MultiBlastfurnace.class; + } +}