Some more work on the multiblock system

This commit is contained in:
Modmuss50 2015-04-17 17:42:57 +01:00
parent b505eeaf30
commit 1eb3ef3db6
13 changed files with 158 additions and 27 deletions

View file

@ -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");
}

View file

@ -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;
}
}

View file

@ -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

View file

@ -0,0 +1,7 @@
package techreborn.api.multiblock;
public interface IMultiBlockController {
IMultiBlock getMultiBlock();
}

View file

@ -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();
}

View file

@ -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;
}
}

View file

@ -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

View file

@ -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();
}
}

View file

@ -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();
}
}
}

View file

@ -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");

View file

@ -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<TileEntity> getTiles() {
return null;
}
@Override
public void recompute() {
com
}
}

View file

@ -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;

View file

@ -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;
}
}