diff --git a/common/buildcraft/BuildCraftEnergy.java b/common/buildcraft/BuildCraftEnergy.java index 72fd3b7c..6be73091 100644 --- a/common/buildcraft/BuildCraftEnergy.java +++ b/common/buildcraft/BuildCraftEnergy.java @@ -39,6 +39,7 @@ import buildcraft.energy.BlockBuildcraftFluid; import buildcraft.energy.BlockEnergyEmitter; import buildcraft.energy.BlockEnergyReceiver; import buildcraft.energy.BlockEngine; +import buildcraft.energy.BptBlockEngine; import buildcraft.energy.EnergyProxy; import buildcraft.energy.GuiHandler; import buildcraft.energy.ItemBucketBuildcraft; @@ -249,7 +250,7 @@ public class BuildCraftEnergy extends BuildCraftMod { NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler()); - //new BptBlockEngine(engineBlock.blockID); + new BptBlockEngine(engineBlock); if (BuildCraftCore.loadDefaultRecipes) { loadRecipes(); diff --git a/common/buildcraft/BuildCraftFactory.java b/common/buildcraft/BuildCraftFactory.java index 6722954a..826ccf58 100644 --- a/common/buildcraft/BuildCraftFactory.java +++ b/common/buildcraft/BuildCraftFactory.java @@ -8,10 +8,23 @@ */ package buildcraft; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.client.event.TextureStitchEvent; +import net.minecraftforge.common.ForgeChunkManager; +import net.minecraftforge.common.ForgeChunkManager.Ticket; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.common.config.Property; import buildcraft.core.DefaultProps; import buildcraft.core.InterModComms; import buildcraft.core.Version; -import buildcraft.core.network.PacketHandler; import buildcraft.core.proxy.CoreProxy; import buildcraft.core.utils.ConfigUtils; import buildcraft.factory.BlockAutoWorkbench; @@ -56,22 +69,6 @@ import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import java.util.List; - -import net.minecraft.block.Block; -import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; -import net.minecraftforge.client.event.TextureStitchEvent; -import net.minecraftforge.common.config.Configuration; -import net.minecraftforge.common.ForgeChunkManager; -import net.minecraftforge.common.ForgeChunkManager.Ticket; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.common.config.Property; - @Mod(name = "BuildCraft Factory", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Factory", dependencies = DefaultProps.DEPENDENCY_CORE) public class BuildCraftFactory extends BuildCraftMod { @@ -148,10 +145,10 @@ public class BuildCraftFactory extends BuildCraftMod { FactoryProxy.proxy.initializeTileEntities(); - //new BptBlockAutoWorkbench(autoWorkbenchBlock.blockID); - //new BptBlockFrame(frameBlock.blockID); - //new BptBlockRefinery(refineryBlock.blockID); - //new BptBlockTank(tankBlock.blockID); + new BptBlockAutoWorkbench(autoWorkbenchBlock); + new BptBlockFrame(frameBlock); + new BptBlockRefinery(refineryBlock); + new BptBlockTank(tankBlock); if (BuildCraftCore.loadDefaultRecipes) { loadRecipes(); @@ -162,7 +159,7 @@ public class BuildCraftFactory extends BuildCraftMod { public void initialize(FMLPreInitializationEvent evt) { channels = NetworkRegistry.INSTANCE.newChannel (DefaultProps.NET_CHANNEL_NAME + "-FACTORY", new PacketHandlerFactory()); - + ConfigUtils genCat = new ConfigUtils(BuildCraftCore.mainConfiguration, Configuration.CATEGORY_GENERAL); allowMining = genCat.get("mining.enabled", true, "disables the recipes for automated mining machines"); @@ -176,42 +173,42 @@ public class BuildCraftFactory extends BuildCraftMod { + "Entries are comma seperated, banned fluids have precedence over allowed ones." + "Default is \"+/*/*,+/-1/Lava\" - the second redundant entry (\"+/-1/lava\") is there to show the format."; pumpDimensionList = new PumpDimensionList(pumpList.getString()); - + if (BuildCraftCore.mainConfiguration.hasChanged()) { BuildCraftCore.mainConfiguration.save(); } - + miningWellBlock = new BlockMiningWell(); CoreProxy.proxy.registerBlock(miningWellBlock.setBlockName("miningWellBlock")); - + plainPipeBlock = new BlockPlainPipe(); CoreProxy.proxy.registerBlock(plainPipeBlock.setBlockName("plainPipeBlock")); - + autoWorkbenchBlock = new BlockAutoWorkbench(); CoreProxy.proxy.registerBlock(autoWorkbenchBlock.setBlockName("autoWorkbenchBlock")); - + frameBlock = new BlockFrame(); CoreProxy.proxy.registerBlock(frameBlock.setBlockName("frameBlock")); - + quarryBlock = new BlockQuarry(); CoreProxy.proxy.registerBlock(quarryBlock.setBlockName("machineBlock")); - + tankBlock = new BlockTank(); CoreProxy.proxy.registerBlock(tankBlock.setBlockName("tankBlock")); pumpBlock = new BlockPump(); CoreProxy.proxy.registerBlock(pumpBlock.setBlockName("pumpBlock")); - + floodGateBlock = new BlockFloodGate(); CoreProxy.proxy.registerBlock(floodGateBlock.setBlockName("floodGateBlock")); - + refineryBlock = new BlockRefinery(); CoreProxy.proxy.registerBlock(refineryBlock.setBlockName("refineryBlock")); - + hopperBlock = new BlockHopper(); CoreProxy.proxy.registerBlock(hopperBlock.setBlockName("blockHopper")); - + FactoryProxy.proxy.initializeEntityRenders(); if (BuildCraftCore.mainConfiguration.hasChanged()) { @@ -224,7 +221,7 @@ public class BuildCraftFactory extends BuildCraftMod { public static void loadRecipes() { if (allowMining) { - if (miningWellBlock != null) + if (miningWellBlock != null) { CoreProxy.proxy.addCraftingRecipe(new ItemStack(miningWellBlock, 1), "ipi", "igi", @@ -233,8 +230,9 @@ public class BuildCraftFactory extends BuildCraftMod { 'i', Items.iron_ingot, 'g', BuildCraftCore.ironGearItem, 'P', Items.iron_pickaxe); + } - if (quarryBlock != null) + if (quarryBlock != null) { CoreProxy.proxy.addCraftingRecipe( new ItemStack(quarryBlock), "ipi", @@ -245,17 +243,19 @@ public class BuildCraftFactory extends BuildCraftMod { 'g', BuildCraftCore.goldGearItem, 'd', BuildCraftCore.diamondGearItem, 'D', Items.diamond_pickaxe); + } - if (pumpBlock != null && miningWellBlock != null) + if (pumpBlock != null && miningWellBlock != null) { CoreProxy.proxy.addCraftingRecipe(new ItemStack(pumpBlock), "T", "W", 'T', tankBlock != null ? tankBlock : Blocks.glass, 'W', miningWellBlock); + } } if (!allowMining || miningWellBlock == null) { - if (pumpBlock != null) + if (pumpBlock != null) { CoreProxy.proxy.addCraftingRecipe(new ItemStack(pumpBlock), "iri", "iTi", @@ -265,33 +265,37 @@ public class BuildCraftFactory extends BuildCraftMod { 'T', tankBlock != null ? tankBlock : Blocks.glass, 'g', BuildCraftCore.ironGearItem, 'p', BuildCraftTransport.pipeFluidsGold); + } } - if (autoWorkbenchBlock != null) + if (autoWorkbenchBlock != null) { CoreProxy.proxy.addCraftingRecipe(new ItemStack(autoWorkbenchBlock), " g ", "gwg", " g ", 'w', Blocks.crafting_table, 'g', BuildCraftCore.woodenGearItem); + } - if (tankBlock != null) + if (tankBlock != null) { CoreProxy.proxy.addCraftingRecipe(new ItemStack(tankBlock), "ggg", "g g", "ggg", 'g', Blocks.glass); + } - if (refineryBlock != null) + if (refineryBlock != null) { CoreProxy.proxy.addCraftingRecipe(new ItemStack(refineryBlock), "RTR", "TGT", 'T', tankBlock != null ? tankBlock : Blocks.glass, 'G', BuildCraftCore.diamondGearItem, 'R', Blocks.redstone_torch); + } - if (hopperBlock != null) + if (hopperBlock != null) { CoreProxy.proxy.addCraftingRecipe(new ItemStack(hopperBlock), "ICI", "IGI", @@ -299,8 +303,9 @@ public class BuildCraftFactory extends BuildCraftMod { 'I', Items.iron_ingot, 'C', Blocks.chest, 'G', BuildCraftCore.stoneGearItem); + } - if (floodGateBlock != null) + if (floodGateBlock != null) { CoreProxy.proxy.addCraftingRecipe(new ItemStack(floodGateBlock), "IGI", "FTF", @@ -309,6 +314,7 @@ public class BuildCraftFactory extends BuildCraftMod { 'T', tankBlock != null ? tankBlock : Blocks.glass, 'G', BuildCraftCore.ironGearItem, 'F', new ItemStack(Blocks.iron_bars)); + } } @EventHandler diff --git a/common/buildcraft/BuildCraftSilicon.java b/common/buildcraft/BuildCraftSilicon.java index 252081bd..d32dc416 100644 --- a/common/buildcraft/BuildCraftSilicon.java +++ b/common/buildcraft/BuildCraftSilicon.java @@ -8,32 +8,38 @@ */ package buildcraft; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; + +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; import buildcraft.api.bptblocks.BptBlockInventory; import buildcraft.api.bptblocks.BptBlockRotateMeta; import buildcraft.api.recipes.BuildcraftRecipes; import buildcraft.api.transport.PipeWire; import buildcraft.core.DefaultProps; import buildcraft.core.InterModComms; -import buildcraft.silicon.ItemRedstoneChipset; -import buildcraft.silicon.ItemRedstoneChipset.Chipset; import buildcraft.core.Version; -import buildcraft.core.network.PacketHandler; import buildcraft.core.proxy.CoreProxy; import buildcraft.silicon.BlockLaser; import buildcraft.silicon.BlockLaserTable; import buildcraft.silicon.GuiHandler; import buildcraft.silicon.ItemLaserTable; +import buildcraft.silicon.ItemRedstoneChipset; +import buildcraft.silicon.ItemRedstoneChipset.Chipset; import buildcraft.silicon.SiliconProxy; import buildcraft.silicon.TileAdvancedCraftingTable; import buildcraft.silicon.TileAssemblyTable; import buildcraft.silicon.TileIntegrationTable; import buildcraft.silicon.TileLaser; import buildcraft.silicon.network.PacketHandlerSilicon; -import buildcraft.transport.gates.GateDefinition.GateMaterial; -import buildcraft.transport.gates.GateExpansionPulsar; import buildcraft.silicon.recipes.GateExpansionRecipe; import buildcraft.silicon.recipes.GateLogicSwapRecipe; import buildcraft.transport.gates.GateDefinition.GateLogic; +import buildcraft.transport.gates.GateDefinition.GateMaterial; +import buildcraft.transport.gates.GateExpansionPulsar; import buildcraft.transport.gates.GateExpansionRedstoneFader; import buildcraft.transport.gates.GateExpansionTimer; import buildcraft.transport.gates.ItemGate; @@ -46,17 +52,6 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.registry.LanguageRegistry; -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.List; - -import net.minecraft.block.Block; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraftforge.common.config.Property; - @Mod(name = "BuildCraft Silicon", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Silicon", dependencies = DefaultProps.DEPENDENCY_TRANSPORT) public class BuildCraftSilicon extends BuildCraftMod { @@ -67,7 +62,7 @@ public class BuildCraftSilicon extends BuildCraftMod { public static BuildCraftSilicon instance; @EventHandler - public void preInit(FMLPreInitializationEvent evt) { + public void preInit(FMLPreInitializationEvent evt) { BuildCraftCore.mainConfiguration.save(); laserBlock = new BlockLaser(); @@ -91,15 +86,15 @@ public class BuildCraftSilicon extends BuildCraftMod { public void init(FMLInitializationEvent evt) { channels = NetworkRegistry.INSTANCE.newChannel (DefaultProps.NET_CHANNEL_NAME + "-SILICON", new PacketHandlerSilicon()); - + NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler()); CoreProxy.proxy.registerTileEntity(TileLaser.class, "net.minecraft.src.buildcraft.factory.TileLaser"); CoreProxy.proxy.registerTileEntity(TileAssemblyTable.class, "net.minecraft.src.buildcraft.factory.TileAssemblyTable"); CoreProxy.proxy.registerTileEntity(TileAdvancedCraftingTable.class, "net.minecraft.src.buildcraft.factory.TileAssemblyAdvancedWorkbench"); CoreProxy.proxy.registerTileEntity(TileIntegrationTable.class, "net.minecraft.src.buildcraft.factory.TileIntegrationTable"); - //new BptBlockRotateMeta(laserBlock.blockID, new int[]{2, 5, 3, 4}, true); - //new BptBlockInventory(assemblyTableBlock.blockID); + new BptBlockRotateMeta(laserBlock, new int[]{2, 5, 3, 4}, true); + new BptBlockInventory(assemblyTableBlock); if (BuildCraftCore.loadDefaultRecipes) { loadRecipes(); diff --git a/common/buildcraft/BuildCraftTransport.java b/common/buildcraft/BuildCraftTransport.java index b316128e..73472988 100644 --- a/common/buildcraft/BuildCraftTransport.java +++ b/common/buildcraft/BuildCraftTransport.java @@ -52,6 +52,9 @@ import buildcraft.transport.PipeTriggerProvider; import buildcraft.transport.TransportProxy; import buildcraft.transport.WireIconProvider; import buildcraft.transport.blueprints.BptBlockPipe; +import buildcraft.transport.blueprints.BptItemPipeFilters; +import buildcraft.transport.blueprints.BptPipeIron; +import buildcraft.transport.blueprints.BptPipeWooden; import buildcraft.transport.gates.GateExpansionPulsar; import buildcraft.transport.gates.GateExpansionRedstoneFader; import buildcraft.transport.gates.GateExpansionTimer; @@ -212,8 +215,9 @@ public class BuildCraftTransport extends BuildCraftMod { private boolean testStrings(String[] excludedBlocks, World world, int i, int j, int k) { Block block = world.getBlock(i, j, k); - if (block == null) + if (block == null) { return false; + } int meta = world.getBlockMetadata(i, j, k); @@ -247,8 +251,9 @@ public class BuildCraftTransport extends BuildCraftMod { for (int j = 0; j < excludedItemBlocks.length; ++j) { excludedItemBlocks[j] = excludedItemBlocks[j].trim(); } - } else + } else { excludedItemBlocks = new String[0]; + } Property exclusionFluidList = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL, "woodenPipe.liquid.exclusion", new String[0]); @@ -257,8 +262,9 @@ public class BuildCraftTransport extends BuildCraftMod { for (int j = 0; j < excludedFluidBlocks.length; ++j) { excludedFluidBlocks[j] = excludedFluidBlocks[j].trim(); } - } else + } else { excludedFluidBlocks = new String[0]; + } filteredBufferBlock = new BlockFilteredBuffer(); CoreProxy.proxy.registerBlock(filteredBufferBlock.setBlockName("filteredBufferBlock")); @@ -423,23 +429,18 @@ public class BuildCraftTransport extends BuildCraftMod { TransportProxy.proxy.registerTileEntities(); - // dockingStationBlock = new - // BlockDockingStation(Integer.parseInt(dockingStationId.value)); - // ModLoader.registerBlock(dockingStationBlock); - // CoreProxy.addName(dockingStationBlock.setBlockName("dockingStation"), - // "Docking Station"); - - // ModLoader.RegisterTileEntity(TileDockingStation.class, - // "net.minecraft.src.buildcraft.TileDockingStation"); - new BptBlockPipe(genericPipeBlock); - //BuildCraftCore.itemBptProps[pipeItemsWood.itemID] = new BptItemPipeWooden(); - //BuildCraftCore.itemBptProps[pipeFluidsWood.itemID] = new BptItemPipeWooden(); - //BuildCraftCore.itemBptProps[pipeItemsIron.itemID] = new BptItemPipeIron(); - //BuildCraftCore.itemBptProps[pipeFluidsIron.itemID] = new BptItemPipeIron(); - //BuildCraftCore.itemBptProps[pipeItemsDiamond.itemID] = new BptItemPipeDiamond(); - //BuildCraftCore.itemBptProps[pipeItemsEmerald.itemID] = new BptItemPipeEmerald(); + new BptPipeIron(pipeItemsIron); + new BptPipeIron(pipeFluidsIron); + new BptPipeIron(pipePowerIron); + + new BptPipeWooden(pipeItemsWood); + new BptPipeWooden(pipeFluidsWood); + new BptPipeWooden(pipePowerWood); + + new BptItemPipeFilters(pipeItemsDiamond); + new BptItemPipeFilters(pipeItemsEmerald); ActionManager.registerTriggerProvider(new PipeTriggerProvider()); diff --git a/common/buildcraft/api/bptblocks/BptBlockInventory.java b/common/buildcraft/api/bptblocks/BptBlockInventory.java index c9764e27..41408f65 100644 --- a/common/buildcraft/api/bptblocks/BptBlockInventory.java +++ b/common/buildcraft/api/bptblocks/BptBlockInventory.java @@ -1,4 +1,3 @@ - /** * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team * http://www.mod-buildcraft.com diff --git a/common/buildcraft/builders/TileBuilder.java b/common/buildcraft/builders/TileBuilder.java index 380549ec..1f10ffaf 100644 --- a/common/buildcraft/builders/TileBuilder.java +++ b/common/buildcraft/builders/TileBuilder.java @@ -122,8 +122,9 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, bpt = instanciateBluePrint(newX, newY, newZ, o); - if (bpt == null) + if (bpt == null) { return null; + } AxisAlignedBB boundingBox = bpt.getBoundingBox(); @@ -131,8 +132,9 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, oldBoundingBox = boundingBox; - if (bpt != null) + if (bpt != null) { return bpt; + } } ix += cx; @@ -142,9 +144,9 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, double distance = (ix - to.x) * (ix - to.x) + (iy - to.y) * (iy - to.y) + (iz - to.z) * (iz - to.z); - if (distance > lastDistance) + if (distance > lastDistance) { return null; - else { + } else { lastDistance = distance; } } @@ -156,17 +158,21 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, next.oldBoundingBox = oldBoundingBox; return next; - } else + } else { return null; + } } public boolean collision(AxisAlignedBB left, AxisAlignedBB right) { - if (left.maxX < right.minX || left.minX > right.maxX) + if (left.maxX < right.minX || left.minX > right.maxX) { return false; - if (left.maxY < right.minY || left.minY > right.maxY) + } + if (left.maxY < right.minY || left.minY > right.maxY) { return false; - if (left.maxZ < right.minZ || left.minZ > right.maxZ) + } + if (left.maxZ < right.minZ || left.minZ > right.maxZ) { return false; + } return true; } } @@ -278,7 +284,7 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, result = null; } - //debugForceBlueprintCompletion(result, context); + debugForceBlueprintCompletion(result, context); return result; } @@ -424,16 +430,19 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, public void setInventorySlotContents(int i, ItemStack itemstack) { items[i] = itemstack; - if (i == 0) { - iterateBpt(); - done = false; + if (!worldObj.isRemote) { + if (i == 0) { + iterateBpt(); + done = false; + } } } @Override public ItemStack getStackInSlotOnClosing(int slot) { - if (items[slot] == null) + if (items[slot] == null) { return null; + } ItemStack toReturn = items[slot]; items[slot] = null; return toReturn; diff --git a/common/buildcraft/transport/BlockGenericPipe.java b/common/buildcraft/transport/BlockGenericPipe.java index 52c12876..f4ed3a6d 100644 --- a/common/buildcraft/transport/BlockGenericPipe.java +++ b/common/buildcraft/transport/BlockGenericPipe.java @@ -1076,6 +1076,7 @@ public class BlockGenericPipe extends BlockBuildCraft { item.setPipeIconIndex(dummyPipe.getIconIndexForItem()); TransportProxy.proxy.setIconProviderFromPipe(item, dummyPipe); } + return item; } diff --git a/common/buildcraft/transport/Pipe.java b/common/buildcraft/transport/Pipe.java index e3e19345..bb3333dc 100644 --- a/common/buildcraft/transport/Pipe.java +++ b/common/buildcraft/transport/Pipe.java @@ -89,17 +89,22 @@ public abstract class Pipe implements IDropControlInven public final void handlePipeEvent(PipeEvent event) { Map, EventHandler> handlerMap = eventHandlers.get(getClass()); + if (handlerMap == null) { handlerMap = new HashMap, EventHandler>(); eventHandlers.put(getClass(), handlerMap); } + EventHandler handler = handlerMap.get(event.getClass()); + if (handler == null) { handler = makeEventHandler(event, handlerMap); } + if (handler.method == null) { return; } + try { handler.method.invoke(this, event); } catch (Exception ex) { @@ -108,12 +113,14 @@ public abstract class Pipe implements IDropControlInven private EventHandler makeEventHandler(PipeEvent event, Map, EventHandler> handlerMap) { EventHandler handler; + try { Method method = getClass().getDeclaredMethod("eventHandler", event.getClass()); handler = new EventHandler(method); } catch (Exception ex) { handler = new EventHandler(null); } + handlerMap.put(event.getClass(), handler); return handler; } @@ -137,9 +144,9 @@ public abstract class Pipe implements IDropControlInven public boolean canPipeConnect(TileEntity tile, ForgeDirection side) { Pipe otherPipe; + if (tile instanceof TileGenericPipe) { otherPipe = ((TileGenericPipe) tile).pipe; - if (!BlockGenericPipe.isFullyDefined(otherPipe)) { return false; } @@ -148,6 +155,7 @@ public abstract class Pipe implements IDropControlInven return false; } } + return transport.canPipeConnect(tile, side); } @@ -182,7 +190,6 @@ public abstract class Pipe implements IDropControlInven public abstract int getIconIndex(ForgeDirection direction); public void updateEntity() { - transport.updateEntity(); if (internalUpdateScheduled) { diff --git a/common/buildcraft/transport/TileGenericPipe.java b/common/buildcraft/transport/TileGenericPipe.java index e3dc70e7..23fcf3d9 100644 --- a/common/buildcraft/transport/TileGenericPipe.java +++ b/common/buildcraft/transport/TileGenericPipe.java @@ -108,10 +108,66 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui private boolean pipeBound = false; private boolean resyncGateExpansions = false; public int redstoneInput = 0; - private Block[] facadeBlocks = new Block[ForgeDirection.VALID_DIRECTIONS.length]; - private int[] facadeMeta = new int[ForgeDirection.VALID_DIRECTIONS.length]; - private boolean[] plugs = new boolean[ForgeDirection.VALID_DIRECTIONS.length]; - private boolean[] robotStations = new boolean[ForgeDirection.VALID_DIRECTIONS.length]; + + public static class SideProperties { + Block[] facadeBlocks = new Block[ForgeDirection.VALID_DIRECTIONS.length]; + int[] facadeMeta = new int[ForgeDirection.VALID_DIRECTIONS.length]; + boolean[] plugs = new boolean[ForgeDirection.VALID_DIRECTIONS.length]; + boolean[] robotStations = new boolean[ForgeDirection.VALID_DIRECTIONS.length]; + + public void writeToNBT (NBTTagCompound nbt) { + for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) { + if (facadeBlocks[i] == null) { + nbt.setInteger("facadeBlocks[" + i + "]", 0); + } else { + nbt.setInteger("facadeBlocks[" + i + "]", Block.blockRegistry.getIDForObject(facadeBlocks[i])); + } + + nbt.setInteger("facadeMeta[" + i + "]", facadeMeta[i]); + nbt.setBoolean("plug[" + i + "]", plugs[i]); + nbt.setBoolean("robotStation[" + i + "]", robotStations[i]); + } + } + + public void readFromNBT (NBTTagCompound nbt) { + for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) { + int blockId = nbt.getInteger("facadeBlocks[" + i + "]"); + + if (blockId != 0) { + facadeBlocks[i] = (Block) Block.blockRegistry.getObjectById(blockId); + } else { + facadeBlocks[i] = null; + } + + facadeMeta[i] = nbt.getInteger("facadeMeta[" + i + "]"); + plugs[i] = nbt.getBoolean("plug[" + i + "]"); + robotStations[i] = nbt.getBoolean("robotStation[" + i + "]"); + } + } + + public void rotateLeft() { + Block[] newFacadeBlocks = new Block[ForgeDirection.VALID_DIRECTIONS.length]; + int[] newFacadeMeta = new int[ForgeDirection.VALID_DIRECTIONS.length]; + boolean[] newPlugs = new boolean[ForgeDirection.VALID_DIRECTIONS.length]; + boolean[] newRobotStations = new boolean[ForgeDirection.VALID_DIRECTIONS.length]; + + for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { + ForgeDirection r = dir.getRotation(ForgeDirection.UP); + + newFacadeBlocks [r.ordinal()] = facadeBlocks [dir.ordinal()]; + newFacadeMeta [r.ordinal()] = facadeMeta [dir.ordinal()]; + newPlugs [r.ordinal()] = plugs [dir.ordinal()]; + newRobotStations [r.ordinal()] = robotStations [dir.ordinal()]; + } + + facadeBlocks = newFacadeBlocks; + facadeMeta = newFacadeMeta; + plugs = newPlugs; + robotStations = newRobotStations; + } + } + + private SideProperties sideProperties = new SideProperties(); public TileGenericPipe() { } @@ -129,17 +185,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui nbt.setInteger("pipeId", coreState.pipeId); } - for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) { - if (facadeBlocks[i] == null) { - nbt.setInteger("facadeBlocks[" + i + "]", 0); - } else { - nbt.setInteger("facadeBlocks[" + i + "]", Block.blockRegistry.getIDForObject(facadeBlocks[i])); - } - - nbt.setInteger("facadeMeta[" + i + "]", facadeMeta[i]); - nbt.setBoolean("plug[" + i + "]", plugs[i]); - nbt.setBoolean("robotStation[" + i + "]", robotStations[i]); - } + sideProperties.writeToNBT(nbt); } @Override @@ -159,28 +205,16 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui deletePipe = true; } - for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) { - int blockId = nbt.getInteger("facadeBlocks[" + i + "]"); - - if (blockId != 0) { - facadeBlocks[i] = (Block) Block.blockRegistry.getObjectById(blockId); - } else { - facadeBlocks[i] = null; - } - - facadeMeta[i] = nbt.getInteger("facadeMeta[" + i + "]"); - plugs[i] = nbt.getBoolean("plug[" + i + "]"); - robotStations[i] = nbt.getBoolean("robotStation[" + i + "]"); - } - + sideProperties.readFromNBT(nbt); } @Override public void invalidate() { initialized = false; tileBuffer = null; - if (pipe != null) + if (pipe != null) { pipe.invalidate(); + } super.invalidate(); } @@ -190,8 +224,9 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui initialized = false; tileBuffer = null; bindPipe(); - if (pipe != null) + if (pipe != null) { pipe.validate(); + } } public boolean initialized = false; @@ -309,18 +344,18 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui // Facades for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { - Block block = this.facadeBlocks[direction.ordinal()]; - renderState.facadeMatrix.setFacade(direction, block, this.facadeMeta[direction.ordinal()]); + Block block = sideProperties.facadeBlocks[direction.ordinal()]; + renderState.facadeMatrix.setFacade(direction, block, sideProperties.facadeMeta[direction.ordinal()]); } //Plugs for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { - renderState.plugMatrix.setConnected(direction, plugs[direction.ordinal()]); + renderState.plugMatrix.setConnected(direction, sideProperties.plugs[direction.ordinal()]); } //RobotStations for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { - renderState.robotStationMatrix.setConnected(direction, robotStations[direction.ordinal()]); + renderState.robotStationMatrix.setConnected(direction, sideProperties.robotStations[direction.ordinal()]); } if (renderState.isDirty()) { @@ -330,7 +365,6 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui } public void initialize(Pipe pipe) { - this.blockType = getBlockType(); if (pipe == null) { @@ -344,10 +378,12 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) { TileEntity tile = getTile(o); - if (tile instanceof ITileBufferHolder) + if (tile instanceof ITileBufferHolder) { ((ITileBufferHolder) tile).blockCreated(o, BuildCraftTransport.genericPipeBlock, this); - if (tile instanceof TileGenericPipe) + } + if (tile instanceof TileGenericPipe) { ((TileGenericPipe) tile).scheduleNeighborChange(); + } } bindPipe(); @@ -355,18 +391,16 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui computeConnections(); scheduleRenderUpdate(); - if (pipe.needsInit()) + if (pipe.needsInit()) { pipe.initialize(); + } initialized = true; } private void bindPipe() { - if (!pipeBound && pipe != null) { - pipe.setTile(this); - coreState.pipeId = Item.getIdFromItem(pipe.item); pipeBound = true; } @@ -378,16 +412,18 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui @Override public PowerHandler.PowerReceiver getPowerReceiver(ForgeDirection side) { - if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor) + if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor) { return ((IPowerReceptor) pipe).getPowerReceiver(null); - else + } else { return null; + } } @Override public void doWork(PowerHandler workProvider) { - if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor) + if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor) { ((IPowerReceptor) pipe).doWork(workProvider); + } } public void scheduleNeighborChange() { @@ -412,8 +448,9 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui @Override public PipeType getPipeType() { - if (BlockGenericPipe.isValid(pipe)) + if (BlockGenericPipe.isValid(pipe)) { return pipe.transport.getPipeType(); + } return null; } @@ -436,8 +473,9 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui coreState.gateLogic = -1; } - if (pipe != null && pipe.transport != null) + if (pipe != null && pipe.transport != null) { pipe.transport.sendDescriptionPacket(); + } packet.addStateForSerialization((byte) 0, coreState); packet.addStateForSerialization((byte) 1, renderState); @@ -476,34 +514,38 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui } public TileBuffer[] getTileCache() { - if (tileBuffer == null && pipe != null) + if (tileBuffer == null && pipe != null) { tileBuffer = TileBuffer.makeBuffer(worldObj, xCoord, yCoord, zCoord, pipe.transport.delveIntoUnloadedChunks()); + } return tileBuffer; } @Override public void blockCreated(ForgeDirection from, Block block, TileEntity tile) { TileBuffer[] cache = getTileCache(); - if (cache != null) + if (cache != null) { cache[from.getOpposite().ordinal()].set(block, tile); + } } @Override public Block getBlock(ForgeDirection to) { TileBuffer[] cache = getTileCache(); - if (cache != null) + if (cache != null) { return cache[to.ordinal()].getBlock(); - else + } else { return null; + } } @Override public TileEntity getTile(ForgeDirection to) { TileBuffer[] cache = getTileCache(); - if (cache != null) + if (cache != null) { return cache[to.ordinal()].getTile(); - else + } else { return null; + } } /** @@ -514,32 +556,40 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui * @return true if pipes are considered connected */ protected boolean canPipeConnect(TileEntity with, ForgeDirection side) { - if (with == null) + if (with == null) { return false; + } - if (hasPlug(side) || hasRobotStation(side)) + if (hasPlug(side) || hasRobotStation(side)) { return false; + } - if (!BlockGenericPipe.isValid(pipe)) + if (!BlockGenericPipe.isValid(pipe)) { return false; + } - if (!(pipe instanceof IPipeConnectionForced) || !((IPipeConnectionForced) pipe).ignoreConnectionOverrides(side)) + if (!(pipe instanceof IPipeConnectionForced) || !((IPipeConnectionForced) pipe).ignoreConnectionOverrides(side)) { if (with instanceof IPipeConnection) { IPipeConnection.ConnectOverride override = ((IPipeConnection) with).overridePipeConnection(pipe.transport.getPipeType(), side.getOpposite()); - if (override != IPipeConnection.ConnectOverride.DEFAULT) + if (override != IPipeConnection.ConnectOverride.DEFAULT) { return override == IPipeConnection.ConnectOverride.CONNECT ? true : false; + } } + } if (with instanceof TileGenericPipe) { - if (((TileGenericPipe) with).hasPlug(side.getOpposite())) + if (((TileGenericPipe) with).hasPlug(side.getOpposite())) { return false; + } Pipe otherPipe = ((TileGenericPipe) with).pipe; - if (!BlockGenericPipe.isValid(otherPipe)) + if (!BlockGenericPipe.isValid(otherPipe)) { return false; + } - if (!otherPipe.canPipeConnect(this, side.getOpposite())) + if (!otherPipe.canPipeConnect(this, side.getOpposite())) { return false; + } } return pipe.canPipeConnect(with, side); @@ -547,8 +597,9 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui private void computeConnections() { TileBuffer[] cache = getTileCache(); - if (cache == null) + if (cache == null) { return; + } for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { TileBuffer t = cache[side.ordinal()]; @@ -560,30 +611,34 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui @Override public boolean isPipeConnected(ForgeDirection with) { - if (worldObj.isRemote) + if (worldObj.isRemote) { return renderState.pipeConnectionMatrix.isConnected(with); + } return pipeConnectionsBuffer[with.ordinal()]; } @Override public boolean isWireActive(PipeWire wire) { - if (pipe == null) + if (pipe == null) { return false; + } return pipe.signalStrength[wire.ordinal()] > 0; } @Override public boolean doDrop() { - if (BlockGenericPipe.isValid(pipe)) + if (BlockGenericPipe.isValid(pipe)) { return pipe.doDrop(); - else + } else { return false; + } } @Override public void onChunkUnload() { - if (pipe != null) + if (pipe != null) { pipe.onChunkUnload(); + } } /** @@ -591,42 +646,47 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui */ @Override public int fill(ForgeDirection from, FluidStack resource, boolean doFill) { - if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof IFluidHandler && !hasPlug(from) && !hasRobotStation(from)) + if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof IFluidHandler && !hasPlug(from) && !hasRobotStation(from)) { return ((IFluidHandler) pipe.transport).fill(from, resource, doFill); - else + } else { return 0; + } } @Override public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) { - if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof IFluidHandler && !hasPlug(from) && !hasRobotStation(from)) + if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof IFluidHandler && !hasPlug(from) && !hasRobotStation(from)) { return ((IFluidHandler) pipe.transport).drain(from, maxDrain, doDrain); - else + } else { return null; + } } @Override public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) { - if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof IFluidHandler && !hasPlug(from) && !hasRobotStation(from)) + if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof IFluidHandler && !hasPlug(from) && !hasRobotStation(from)) { return ((IFluidHandler) pipe.transport).drain(from, resource, doDrain); - else + } else { return null; + } } @Override public boolean canFill(ForgeDirection from, Fluid fluid) { - if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof IFluidHandler && !hasPlug(from) && !hasRobotStation(from)) + if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof IFluidHandler && !hasPlug(from) && !hasRobotStation(from)) { return ((IFluidHandler) pipe.transport).canFill(from, fluid); - else + } else { return false; + } } @Override public boolean canDrain(ForgeDirection from, Fluid fluid) { - if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof IFluidHandler && !hasPlug(from) &&!hasRobotStation(from)) + if (BlockGenericPipe.isValid(pipe) && pipe.transport instanceof IFluidHandler && !hasPlug(from) &&!hasRobotStation(from)) { return ((IFluidHandler) pipe.transport).canDrain(from, fluid); - else + } else { return false; + } } @Override @@ -643,7 +703,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui return false; } - if (this.facadeBlocks[direction.ordinal()] == block) { + if (sideProperties.facadeBlocks[direction.ordinal()] == block) { return false; } @@ -651,8 +711,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui dropFacadeItem(direction); } - this.facadeBlocks[direction.ordinal()] = block; - this.facadeMeta[direction.ordinal()] = meta; + sideProperties.facadeBlocks[direction.ordinal()] = block; + sideProperties.facadeMeta[direction.ordinal()] = meta; worldObj.notifyBlockChange(this.xCoord, this.yCoord, this.zCoord, getBlock()); scheduleRenderUpdate(); @@ -665,7 +725,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui } else if (this.getWorldObj().isRemote) { return renderState.facadeMatrix.getFacadeBlock(direction) != null; } else { - return (this.facadeBlocks[direction.ordinal()] != null); + return (sideProperties.facadeBlocks[direction.ordinal()] != null); } } @@ -674,7 +734,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui } public ItemStack getFacade (ForgeDirection direction) { - return ItemFacade.getStack(this.facadeBlocks[direction.ordinal()], this.facadeMeta[direction.ordinal()]); + return ItemFacade.getStack(sideProperties.facadeBlocks[direction.ordinal()], sideProperties.facadeMeta[direction.ordinal()]); } public boolean dropFacade(ForgeDirection direction) { @@ -684,8 +744,8 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui if (!worldObj.isRemote) { dropFacadeItem(direction); - this.facadeBlocks[direction.ordinal()] = null; - this.facadeMeta[direction.ordinal()] = 0; + sideProperties.facadeBlocks[direction.ordinal()] = null; + sideProperties.facadeMeta[direction.ordinal()] = 0; worldObj.notifyBlockChange(this.xCoord, this.yCoord, this.zCoord, getBlock()); scheduleRenderUpdate(); } @@ -695,8 +755,9 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui @SideOnly(Side.CLIENT) public IIconProvider getPipeIcons() { - if (pipe == null) + if (pipe == null) { return null; + } return pipe.getIconProvider(); } @@ -715,8 +776,9 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui @Override public void afterStateUpdated(byte stateId) { - if (!worldObj.isRemote) + if (!worldObj.isRemote) { return; + } switch (stateId) { case 0: @@ -755,8 +817,9 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui for (byte id : coreState.expansions) { IGateExpansion ex = GateExpansions.getExpansionClient(id); if (ex != null) { - if (!pipe.gate.expansions.containsKey(ex)) + if (!pipe.gate.expansions.containsKey(ex)) { pipe.gate.addGateExpansion(ex); + } } else { resyncGateExpansions = true; } @@ -777,12 +840,15 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui @Override public boolean isSolidOnSide(ForgeDirection side) { - if (hasFacade(side)) + if (hasFacade(side)) { return true; + } - if (BlockGenericPipe.isValid(pipe) && pipe instanceof ISolidSideTile) - if (((ISolidSideTile) pipe).isSolidOnSide(side)) + if (BlockGenericPipe.isValid(pipe) && pipe instanceof ISolidSideTile) { + if (((ISolidSideTile) pipe).isSolidOnSide(side)) { return true; + } + } return false; } @@ -795,7 +861,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui return renderState.plugMatrix.isConnected(side); } - return plugs[side.ordinal()]; + return sideProperties.plugs[side.ordinal()]; } public boolean hasRobotStation(ForgeDirection side) { @@ -807,7 +873,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui return renderState.robotStationMatrix.isConnected(side); } - return robotStations[side.ordinal()]; + return sideProperties.robotStations[side.ordinal()]; } public boolean removeAndDropPlug(ForgeDirection side) { @@ -816,7 +882,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui } if (!worldObj.isRemote) { - plugs[side.ordinal()] = false; + sideProperties.plugs[side.ordinal()] = false; InvUtils.dropItems(worldObj, new ItemStack(BuildCraftTransport.plugItem), this.xCoord, this.yCoord, this.zCoord); worldObj.notifyBlockChange(this.xCoord, this.yCoord, this.zCoord, getBlock()); scheduleNeighborChange(); //To force recalculation of connections @@ -832,7 +898,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui } if (!worldObj.isRemote) { - robotStations[side.ordinal()] = false; + sideProperties.robotStations[side.ordinal()] = false; InvUtils.dropItems(worldObj, new ItemStack(BuildCraftTransport.robotStationItem), this.xCoord, this.yCoord, this.zCoord); worldObj.notifyBlockChange(this.xCoord, this.yCoord, this.zCoord, getBlock()); scheduleNeighborChange(); //To force recalculation of connections @@ -847,7 +913,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui return false; } - plugs[forgeDirection.ordinal()] = true; + sideProperties.plugs[forgeDirection.ordinal()] = true; worldObj.notifyBlockChange(this.xCoord, this.yCoord, this.zCoord, getBlock()); scheduleNeighborChange(); //To force recalculation of connections scheduleRenderUpdate(); @@ -859,7 +925,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui return false; } - robotStations[forgeDirection.ordinal()] = true; + sideProperties.robotStations[forgeDirection.ordinal()] = true; worldObj.notifyBlockChange(this.xCoord, this.yCoord, this.zCoord, getBlock()); scheduleNeighborChange(); //To force recalculation of connections scheduleRenderUpdate(); @@ -882,13 +948,15 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui @Override public void writeGuiData(ByteBuf data) { - if (BlockGenericPipe.isValid(pipe) && pipe instanceof IGuiReturnHandler) + if (BlockGenericPipe.isValid(pipe) && pipe instanceof IGuiReturnHandler) { ((IGuiReturnHandler) pipe).writeGuiData(data); + } } @Override public void readGuiData(ByteBuf data, EntityPlayer sender) { - if (BlockGenericPipe.isValid(pipe) && pipe instanceof IGuiReturnHandler) + if (BlockGenericPipe.isValid(pipe) && pipe instanceof IGuiReturnHandler) { ((IGuiReturnHandler) pipe).readGuiData(data, sender); + } } } diff --git a/common/buildcraft/transport/blueprints/BptBlockPipe.java b/common/buildcraft/transport/blueprints/BptBlockPipe.java index 750ac345..da313603 100644 --- a/common/buildcraft/transport/blueprints/BptBlockPipe.java +++ b/common/buildcraft/transport/blueprints/BptBlockPipe.java @@ -8,20 +8,18 @@ */ package buildcraft.transport.blueprints; -import java.util.ArrayList; import java.util.LinkedList; import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; +import net.minecraft.tileentity.TileEntity; import buildcraft.api.blueprints.BptBlock; import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; -import buildcraft.core.utils.Utils; import buildcraft.transport.BlockGenericPipe; import buildcraft.transport.Pipe; +import buildcraft.transport.TileGenericPipe.SideProperties; public class BptBlockPipe extends BptBlock { @@ -35,12 +33,7 @@ public class BptBlockPipe extends BptBlock { requirements.add(new ItemStack(pipeItem)); - NBTTagList nbtDrops = slot.cpt.getTagList("drops", Utils.NBTTag_Types.NBTTagCompound.ordinal()); - - for (int i = 0; i < nbtDrops.tagCount(); ++i) { - NBTTagCompound nbt = nbtDrops.getCompoundTagAt(i); - requirements.add(ItemStack.loadItemStackFromNBT(nbt)); - } + requirements.addAll(slot.storedRequirements); } @Override @@ -57,73 +50,54 @@ public class BptBlockPipe extends BptBlock { @Override public void rotateLeft(BptSlotInfo slot, IBptContext context) { - int pipeId = slot.cpt.getInteger("pipeId"); + SideProperties props = new SideProperties (); - /*if (BuildCraftCore.itemBptProps[pipeId] != null) { - BuildCraftCore.itemBptProps[pipeId].rotateLeft(slot, context); - }*/ + props.readFromNBT(slot.cpt); + props.rotateLeft(); + props.writeToNBT(slot.cpt); + + Item pipeItem = context.getMappingRegistry().getItemForId(slot.cpt.getInteger("pipeId")); + + if (BptPipeExtension.contains(pipeItem)) { + BptPipeExtension.get(pipeItem).rotateLeft(slot, context); + } } @Override public void buildBlock(BptSlotInfo slot, IBptContext context) { - int pipeId = slot.cpt.getInteger("pipeId"); + slot.cpt.setInteger("x", slot.x); + slot.cpt.setInteger("y", slot.y); + slot.cpt.setInteger("z", slot.z); - Pipe pipe = BlockGenericPipe.createPipe(context.getMappingRegistry() - .getItemForId(pipeId)); + context.world().setBlock(slot.x, slot.y, slot.z, slot.block); + context.world().setBlockMetadataWithNotify(slot.x, slot.y, slot.z, slot.meta, 0); - for (int i = 0; i < pipe.wireSet.length; ++i) { - if (slot.cpt.hasKey("wire" + i)) { - pipe.wireSet[i] = true; - } - } - - - - BlockGenericPipe.placePipe(pipe, context.world(), slot.x, slot.y, - slot.z, slot.block, slot.meta); - - /*if (BuildCraftCore.itemBptProps[pipeId] != null) { - BuildCraftCore.itemBptProps[pipeId].buildBlock(slot, context); - }*/ + TileEntity tile = context.world().getTileEntity(slot.x, slot.y, slot.z); + tile.readFromNBT(slot.cpt); } @Override - public void initializeFromWorld(BptSlotInfo bptSlot, IBptContext context, int x, int y, int z) { + public void initializeFromWorld(BptSlotInfo slot, IBptContext context, int x, int y, int z) { + TileEntity tile = context.world().getTileEntity(x, y, z); Pipe pipe = BlockGenericPipe.getPipe(context.world(), x, y, z); if (BlockGenericPipe.isValid(pipe)) { context.getMappingRegistry().setIdForItem(pipe.item, Item.getIdFromItem(pipe.item)); - bptSlot.cpt.setInteger("pipeId", context.getMappingRegistry() + slot.cpt.setInteger("pipeId", context.getMappingRegistry() .getIdForItem(pipe.item)); - NBTTagList nbtDrops = new NBTTagList(); + slot.storedRequirements.addAll(pipe.computeItemDrop ()); - ArrayList drops = pipe.computeItemDrop (); - - for (ItemStack s : drops) { - NBTTagCompound nbtStack = new NBTTagCompound(); - s.writeToNBT(nbtStack); - nbtDrops.appendTag(nbtStack); - } - - bptSlot.cpt.setTag("drops", nbtDrops); - - NBTTagCompound worldNbt = new NBTTagCompound(); - pipe.writeToNBT(worldNbt); - - bptSlot.cpt.setTag("worldNBT", worldNbt); - - // TODO: store the pipe nbt on disk as well... + tile.writeToNBT(slot.cpt); } } @Override public void postProcessing(BptSlotInfo slot, IBptContext context) { - int pipeId = slot.cpt.getInteger("pipeId"); + Item pipeItem = context.getMappingRegistry().getItemForId(slot.cpt.getInteger("pipeId")); - //if (BuildCraftCore.itemBptProps[pipeId] != null) { - // BuildCraftCore.itemBptProps[pipeId].postProcessing(slot, context); - //} + if (BptPipeExtension.contains(pipeItem)) { + BptPipeExtension.get(pipeItem).postProcessing(slot, context); + } } - } diff --git a/common/buildcraft/transport/blueprints/BptItemPipeDiamond.java b/common/buildcraft/transport/blueprints/BptItemPipeDiamond.java deleted file mode 100644 index b6bfdebd..00000000 --- a/common/buildcraft/transport/blueprints/BptItemPipeDiamond.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com - * - * BuildCraft is distributed under the terms of the Minecraft Mod Public - * License 1.0, or MMPL. Please check the contents of the license located in - * http://www.mod-buildcraft.com/MMPL-1.0.txt - */ -package buildcraft.transport.blueprints; - -import buildcraft.api.blueprints.BptBlockUtils; -import buildcraft.api.blueprints.BptSlotInfo; -import buildcraft.api.blueprints.IBptContext; -import buildcraft.core.blueprints.BptItem; -import java.util.LinkedList; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraftforge.common.util.ForgeDirection; - -public class BptItemPipeDiamond extends BptItem { - - public BptItemPipeDiamond() { - } - - @Override - public void addRequirements(BptSlotInfo slot, LinkedList requirements) { - - } - - @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { - ItemStack inv[] = BptBlockUtils.getItemStacks(slot, context); - ItemStack newInv[] = new ItemStack[54]; - - for (int dir = 0; dir <= 1; ++dir) { - for (int s = 0; s < 9; ++s) { - newInv[dir * 9 + s] = inv[dir * 9 + s]; - } - } - - for (int dir = 2; dir <= 5; ++dir) { - ForgeDirection r = ForgeDirection.values()[dir].getRotation(ForgeDirection.DOWN); - - for (int s = 0; s < 9; ++s) { - newInv[r.ordinal() * 9 + s] = inv[dir * 9 + s]; - } - } - - BptBlockUtils.setItemStacks(slot, context, newInv); - } - - @Override - public void initializeFromWorld(BptSlotInfo bptSlot, IBptContext context, int x, int y, int z) { - IInventory inventory = (IInventory) context.world().getTileEntity(x, y, z); - - BptBlockUtils.initializeInventoryContents(bptSlot, context, inventory); - } - - @Override - public void buildBlock(BptSlotInfo slot, IBptContext context) { - IInventory inventory = (IInventory) context.world().getTileEntity(slot.x, slot.y, slot.z); - - BptBlockUtils.buildInventoryContents(slot, context, inventory); - } - -} diff --git a/common/buildcraft/transport/blueprints/BptItemPipeEmerald.java b/common/buildcraft/transport/blueprints/BptItemPipeEmerald.java deleted file mode 100644 index 508f8d26..00000000 --- a/common/buildcraft/transport/blueprints/BptItemPipeEmerald.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com - * - * BuildCraft is distributed under the terms of the Minecraft Mod Public - * License 1.0, or MMPL. Please check the contents of the license located in - * http://www.mod-buildcraft.com/MMPL-1.0.txt - */ -package buildcraft.transport.blueprints; - -import buildcraft.api.blueprints.BptBlockUtils; -import buildcraft.api.blueprints.BptSlotInfo; -import buildcraft.api.blueprints.IBptContext; -import buildcraft.core.blueprints.BptItem; -import java.util.LinkedList; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; - -public class BptItemPipeEmerald extends BptItem { - - public BptItemPipeEmerald() { - } - - @Override - public void addRequirements(BptSlotInfo slot, LinkedList requirements) { - - } - - @Override - public void initializeFromWorld(BptSlotInfo bptSlot, IBptContext context, int x, int y, int z) { - IInventory inventory = (IInventory) context.world().getTileEntity(x, y, z); - - BptBlockUtils.initializeInventoryContents(bptSlot, context, inventory); - } - - @Override - public void buildBlock(BptSlotInfo slot, IBptContext context) { - IInventory inventory = (IInventory) context.world().getTileEntity(slot.x, slot.y, slot.z); - - BptBlockUtils.buildInventoryContents(slot, context, inventory); - } - -} diff --git a/common/buildcraft/transport/blueprints/BptItemPipeFilters.java b/common/buildcraft/transport/blueprints/BptItemPipeFilters.java new file mode 100644 index 00000000..259ec928 --- /dev/null +++ b/common/buildcraft/transport/blueprints/BptItemPipeFilters.java @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package buildcraft.transport.blueprints; + +import net.minecraft.item.Item; +import net.minecraftforge.common.util.ForgeDirection; +import buildcraft.api.blueprints.BptSlotInfo; +import buildcraft.api.blueprints.IBptContext; +import buildcraft.core.inventory.SimpleInventory; + +public class BptItemPipeFilters extends BptPipeExtension { + + public BptItemPipeFilters(Item i) { + super (i); + } + + + @Override + public void rotateLeft(BptSlotInfo slot, IBptContext context) { + SimpleInventory inv = new SimpleInventory(54, "Filters", 1); + SimpleInventory newInv = new SimpleInventory(54, "Filters", 1); + inv.readFromNBT(slot.cpt); + + for (int dir = 2; dir <= 5; ++dir) { + ForgeDirection r = ForgeDirection.values()[dir].getRotation(ForgeDirection.UP); + + for (int s = 0; s < 9; ++s) { + newInv.setInventorySlotContents(r.ordinal() * 9 + s, inv.getStackInSlot(dir * 9 + s)); + } + } + + newInv.writeToNBT(slot.cpt); + } +} diff --git a/common/buildcraft/transport/blueprints/BptPipeExtension.java b/common/buildcraft/transport/blueprints/BptPipeExtension.java new file mode 100755 index 00000000..c965c4e9 --- /dev/null +++ b/common/buildcraft/transport/blueprints/BptPipeExtension.java @@ -0,0 +1,32 @@ +package buildcraft.transport.blueprints; + +import java.util.HashMap; + +import net.minecraft.item.Item; +import buildcraft.api.blueprints.BptSlotInfo; +import buildcraft.api.blueprints.IBptContext; + +public class BptPipeExtension { + + private static final HashMap bptPipeExtensionRegistry = new HashMap(); + + public BptPipeExtension (Item i) { + bptPipeExtensionRegistry.put(i, this); + } + + public void postProcessing(BptSlotInfo slot, IBptContext context) { + + } + + public void rotateLeft(BptSlotInfo slot, IBptContext context) { + + } + + public static boolean contains (Item i) { + return bptPipeExtensionRegistry.containsKey(i); + } + + public static BptPipeExtension get (Item i) { + return bptPipeExtensionRegistry.get(i); + } +} diff --git a/common/buildcraft/transport/blueprints/BptItemPipeIron.java b/common/buildcraft/transport/blueprints/BptPipeIron.java similarity index 59% rename from common/buildcraft/transport/blueprints/BptItemPipeIron.java rename to common/buildcraft/transport/blueprints/BptPipeIron.java index 64eb3b98..bb91d602 100644 --- a/common/buildcraft/transport/blueprints/BptItemPipeIron.java +++ b/common/buildcraft/transport/blueprints/BptPipeIron.java @@ -8,27 +8,15 @@ */ package buildcraft.transport.blueprints; +import net.minecraft.item.Item; +import net.minecraftforge.common.util.ForgeDirection; import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; -import buildcraft.core.blueprints.BptItem; -import java.util.LinkedList; -import net.minecraft.item.ItemStack; -import net.minecraftforge.common.util.ForgeDirection; -public class BptItemPipeIron extends BptItem { +public class BptPipeIron extends BptPipeExtension { - public BptItemPipeIron() { - - } - - @Override - public void addRequirements(BptSlotInfo slot, LinkedList requirements) { - - } - - @Override - public void postProcessing(BptSlotInfo slot, IBptContext context) { - context.world().setBlockMetadataWithNotify(slot.x, slot.y, slot.z, slot.meta,0); + public BptPipeIron(Item i) { + super(i); } @Override @@ -36,7 +24,7 @@ public class BptItemPipeIron extends BptItem { int orientation = slot.meta & 7; int others = slot.meta - orientation; - slot.meta = ForgeDirection.values()[orientation].getRotation(ForgeDirection.DOWN).ordinal() + others; + slot.meta = ForgeDirection.values()[orientation].getRotation(ForgeDirection.UP).ordinal() + others; } } diff --git a/common/buildcraft/transport/blueprints/BptItemPipeWooden.java b/common/buildcraft/transport/blueprints/BptPipeWooden.java similarity index 59% rename from common/buildcraft/transport/blueprints/BptItemPipeWooden.java rename to common/buildcraft/transport/blueprints/BptPipeWooden.java index 161af8db..2c102223 100644 --- a/common/buildcraft/transport/blueprints/BptItemPipeWooden.java +++ b/common/buildcraft/transport/blueprints/BptPipeWooden.java @@ -8,27 +8,15 @@ */ package buildcraft.transport.blueprints; +import net.minecraft.item.Item; +import net.minecraftforge.common.util.ForgeDirection; import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; -import buildcraft.core.blueprints.BptItem; -import java.util.LinkedList; -import net.minecraft.item.ItemStack; -import net.minecraftforge.common.util.ForgeDirection; -public class BptItemPipeWooden extends BptItem { +public class BptPipeWooden extends BptPipeExtension { - public BptItemPipeWooden() { - - } - - @Override - public void addRequirements(BptSlotInfo slot, LinkedList requirements) { - - } - - @Override - public void postProcessing(BptSlotInfo slot, IBptContext context) { - context.world().setBlockMetadataWithNotify(slot.x, slot.y, slot.z, slot.meta,0); + public BptPipeWooden(Item i) { + super (i); } @Override @@ -36,7 +24,7 @@ public class BptItemPipeWooden extends BptItem { int orientation = slot.meta & 7; int others = slot.meta - orientation; - slot.meta = ForgeDirection.values()[orientation].getRotation(ForgeDirection.DOWN).ordinal() + others; + slot.meta = ForgeDirection.values()[orientation].getRotation(ForgeDirection.UP).ordinal() + others; } } diff --git a/common/buildcraft/transport/pipes/PipeItemsWood.java b/common/buildcraft/transport/pipes/PipeItemsWood.java index 4c0dd9ca..a851710f 100644 --- a/common/buildcraft/transport/pipes/PipeItemsWood.java +++ b/common/buildcraft/transport/pipes/PipeItemsWood.java @@ -8,6 +8,13 @@ */ package buildcraft.transport.pipes; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; import buildcraft.BuildCraftTransport; import buildcraft.api.core.IIconProvider; import buildcraft.api.core.Position; @@ -19,20 +26,13 @@ import buildcraft.api.power.PowerHandler.Type; import buildcraft.api.transport.IPipeTile; import buildcraft.api.transport.PipeManager; import buildcraft.core.inventory.InvUtils; -import buildcraft.transport.TravelingItem; import buildcraft.core.inventory.InventoryWrapper; import buildcraft.transport.Pipe; import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeTransportItems; +import buildcraft.transport.TravelingItem; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.ISidedInventory; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.util.ForgeDirection; public class PipeItemsWood extends Pipe implements IPowerReceptor { @@ -42,12 +42,15 @@ public class PipeItemsWood extends Pipe implements IPowerRec private PipeLogicWood logic = new PipeLogicWood(this) { @Override protected boolean isValidConnectingTile(TileEntity tile) { - if (tile instanceof IPipeTile) + if (tile instanceof IPipeTile) { return false; - if (!(tile instanceof IInventory)) + } + if (!(tile instanceof IInventory)) { return false; - if (!PipeManager.canExtractItems(pipe, tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord)) + } + if (!PipeManager.canExtractItems(pipe, tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord)) { return false; + } return true; } }; @@ -85,15 +88,16 @@ public class PipeItemsWood extends Pipe implements IPowerRec @Override public int getIconIndex(ForgeDirection direction) { - if (direction == ForgeDirection.UNKNOWN) + if (direction == ForgeDirection.UNKNOWN) { return standardIconIndex; - else { + } else { int metadata = container.getBlockMetadata(); - if (metadata == direction.ordinal()) + if (metadata == direction.ordinal()) { return solidIconIndex; - else + } else { return standardIconIndex; + } } } @@ -104,35 +108,41 @@ public class PipeItemsWood extends Pipe implements IPowerRec @Override public void doWork(PowerHandler workProvider) { - if(container.getWorldObj().isRemote) - return; - - if (powerHandler.getEnergyStored() <= 0) + if(container.getWorldObj().isRemote) { return; + } - if (transport.getNumberOfStacks() < PipeTransportItems.MAX_PIPE_STACKS) + if (powerHandler.getEnergyStored() <= 0) { + return; + } + + if (transport.getNumberOfStacks() < PipeTransportItems.MAX_PIPE_STACKS) { extractItems(); + } powerHandler.setEnergy(0); } private void extractItems() { int meta = container.getBlockMetadata(); - if (meta > 5) + if (meta > 5) { return; + } ForgeDirection side = ForgeDirection.getOrientation(meta); TileEntity tile = container.getTile(side); if (tile instanceof IInventory) { - if (!PipeManager.canExtractItems(this, tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord)) + if (!PipeManager.canExtractItems(this, tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord)) { return; + } IInventory inventory = (IInventory) tile; ItemStack[] extracted = checkExtract(inventory, true, side.getOpposite()); - if (extracted == null) + if (extracted == null) { return; + } tile.markDirty(); @@ -180,8 +190,9 @@ public class PipeItemsWood extends Pipe implements IPowerRec IInventory inv = InvUtils.getInventory(inventory); ItemStack result = checkExtractGeneric(inv, doRemove, from); - if (result != null) + if (result != null) { return new ItemStack[]{result}; + } } return null; @@ -193,8 +204,9 @@ public class PipeItemsWood extends Pipe implements IPowerRec } public ItemStack checkExtractGeneric(ISidedInventory inventory, boolean doRemove, ForgeDirection from) { - if (inventory == null) + if (inventory == null) { return null; + } for (int k : inventory.getAccessibleSlotsFromSide(from.ordinal())) { ItemStack slot = inventory.getStackInSlot(k);