From 8a7b6124023956a2aff031a635f2fd7811915fba Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Tue, 4 Mar 2014 21:03:37 +0100 Subject: [PATCH] migrated model of blueprint support, now slot-specific instead of block-type-specific --- common/buildcraft/BuildCraftBuilders.java | 115 +++++++------- common/buildcraft/BuildCraftEnergy.java | 3 +- common/buildcraft/BuildCraftFactory.java | 9 +- common/buildcraft/BuildCraftSilicon.java | 5 +- common/buildcraft/BuildCraftTransport.java | 3 +- .../api/blueprints/BlueprintManager.java | 47 +++++- .../buildcraft/api/blueprints/BptBlock.java | 146 ++++++++++++++---- .../api/blueprints/BptBlockUtils.java | 17 +- .../api/blueprints/BptSlotInfo.java | 61 -------- .../buildcraft/api/bptblocks/BptBlockBed.java | 42 +++-- .../api/bptblocks/BptBlockCustomStack.java | 8 +- .../api/bptblocks/BptBlockDelegate.java | 63 -------- .../api/bptblocks/BptBlockDirt.java | 15 +- .../api/bptblocks/BptBlockDoor.java | 38 ++--- .../api/bptblocks/BptBlockFluid.java | 28 ++-- .../api/bptblocks/BptBlockIgnore.java | 18 +-- .../api/bptblocks/BptBlockIgnoreMeta.java | 16 +- .../api/bptblocks/BptBlockInventory.java | 13 +- .../api/bptblocks/BptBlockLever.java | 18 +-- .../api/bptblocks/BptBlockPiston.java | 12 +- .../api/bptblocks/BptBlockPumpkin.java | 28 ++-- .../bptblocks/BptBlockRedstoneRepeater.java | 22 +-- .../bptblocks/BptBlockRotateInventory.java | 13 +- .../api/bptblocks/BptBlockRotateMeta.java | 30 ++-- .../api/bptblocks/BptBlockSign.java | 16 +- .../api/bptblocks/BptBlockStairs.java | 28 ++-- .../api/bptblocks/BptBlockWallSide.java | 24 ++- common/buildcraft/builders/TileBuilder.java | 4 +- .../builders/blueprints/BlockSchematic.java | 2 +- .../builders/blueprints/BlueprintBuilder.java | 6 +- .../builders/blueprints/ItemSchematic.java | 2 +- .../builders/blueprints/MaskSchematic.java | 2 +- .../blueprints/SchematicBlueprint.java | 24 +-- .../{Schematic.java => SchematicOld.java} | 10 +- common/buildcraft/core/IBptContributor.java | 21 --- .../buildcraft/core/blueprints/Blueprint.java | 21 +-- .../core/blueprints/BlueprintBase.java | 14 +- .../core/blueprints/BptActionBuild.java | 15 -- .../core/blueprints/BptBuilderBase.java | 3 +- .../core/blueprints/BptBuilderBlueprint.java | 57 +++---- .../core/blueprints/BptBuilderTemplate.java | 41 ++--- .../buildcraft/core/blueprints/BptItem.java | 38 ----- .../buildcraft/core/blueprints/BptSlot.java | 139 ----------------- common/buildcraft/energy/BptBlockEngine.java | 24 ++- .../factory/BptBlockAutoWorkbench.java | 28 ++-- common/buildcraft/factory/BptBlockFrame.java | 8 +- .../buildcraft/factory/BptBlockRefinery.java | 32 ++-- common/buildcraft/factory/BptBlockTank.java | 12 +- .../transport/blueprints/BptBlockPipe.java | 60 ++++--- .../blueprints/BptItemPipeFilters.java | 4 +- .../blueprints/BptPipeExtension.java | 6 +- .../transport/blueprints/BptPipeIron.java | 4 +- .../transport/blueprints/BptPipeWooden.java | 4 +- 53 files changed, 547 insertions(+), 872 deletions(-) mode change 100644 => 100755 common/buildcraft/api/blueprints/BptBlock.java delete mode 100644 common/buildcraft/api/blueprints/BptSlotInfo.java delete mode 100644 common/buildcraft/api/bptblocks/BptBlockDelegate.java rename common/buildcraft/builders/blueprints/{Schematic.java => SchematicOld.java} (88%) delete mode 100644 common/buildcraft/core/IBptContributor.java delete mode 100644 common/buildcraft/core/blueprints/BptActionBuild.java delete mode 100644 common/buildcraft/core/blueprints/BptItem.java delete mode 100644 common/buildcraft/core/blueprints/BptSlot.java diff --git a/common/buildcraft/BuildCraftBuilders.java b/common/buildcraft/BuildCraftBuilders.java index 3e08a6a3..25720c21 100644 --- a/common/buildcraft/BuildCraftBuilders.java +++ b/common/buildcraft/BuildCraftBuilders.java @@ -17,9 +17,9 @@ import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Property; +import buildcraft.api.blueprints.BlueprintManager; import buildcraft.api.bptblocks.BptBlockBed; import buildcraft.api.bptblocks.BptBlockCustomStack; -import buildcraft.api.bptblocks.BptBlockDelegate; import buildcraft.api.bptblocks.BptBlockDirt; import buildcraft.api.bptblocks.BptBlockDoor; import buildcraft.api.bptblocks.BptBlockFluid; @@ -141,86 +141,85 @@ public class BuildCraftBuilders extends BuildCraftMod { // Register save handler MinecraftForge.EVENT_BUS.register(new EventHandlerBuilders()); - new BptBlockIgnore(Blocks.snow); - new BptBlockIgnore(Blocks.tallgrass); - new BptBlockIgnore(Blocks.ice); - new BptBlockIgnore(Blocks.piston_head); + BlueprintManager.registerSchematicClass(Blocks.snow, BptBlockIgnore.class); + BlueprintManager.registerSchematicClass(Blocks.tallgrass, BptBlockIgnore.class); + BlueprintManager.registerSchematicClass(Blocks.ice, BptBlockIgnore.class); + BlueprintManager.registerSchematicClass(Blocks.piston_head, BptBlockIgnore.class); - new BptBlockDirt(Blocks.dirt); - new BptBlockDirt(Blocks.grass); - new BptBlockDirt(Blocks.farmland); + BlueprintManager.registerSchematicClass(Blocks.dirt, BptBlockDirt.class); + BlueprintManager.registerSchematicClass(Blocks.grass, BptBlockDirt.class); + BlueprintManager.registerSchematicClass(Blocks.farmland, BptBlockDirt.class); - new BptBlockDelegate(Blocks.unlit_redstone_torch, Blocks.redstone_torch); - new BptBlockDelegate(Blocks.lit_furnace, Blocks.furnace); - new BptBlockDelegate(Blocks.piston_extension, Blocks.piston); + BlueprintManager.registerSchematicClass(Blocks.torch, BptBlockWallSide.class); + BlueprintManager.registerSchematicClass(Blocks.redstone_torch, BptBlockWallSide.class); + BlueprintManager.registerSchematicClass(Blocks.unlit_redstone_torch, BptBlockWallSide.class); - new BptBlockWallSide(Blocks.torch); - new BptBlockWallSide(Blocks.redstone_torch); + BlueprintManager.registerSchematicClass(Blocks.ladder, BptBlockRotateMeta.class, new int[]{2, 5, 3, 4}, true); + BlueprintManager.registerSchematicClass(Blocks.fence_gate, BptBlockRotateMeta.class, new int[]{0, 1, 2, 3}, true); - new BptBlockRotateMeta(Blocks.ladder, new int[]{2, 5, 3, 4}, true); - new BptBlockRotateMeta(Blocks.fence_gate, new int[]{0, 1, 2, 3}, true); + BlueprintManager.registerSchematicClass(Blocks.furnace, BptBlockRotateInventory.class, new int[]{2, 5, 3, 4}, true); + BlueprintManager.registerSchematicClass(Blocks.lit_furnace, BptBlockRotateInventory.class, new int[]{2, 5, 3, 4}, true); + BlueprintManager.registerSchematicClass(Blocks.chest, BptBlockRotateInventory.class, new int[]{2, 5, 3, 4}, true); + BlueprintManager.registerSchematicClass(Blocks.dispenser, BptBlockRotateInventory.class, new int[]{2, 5, 3, 4}, true); - new BptBlockRotateInventory(Blocks.furnace, new int[]{2, 5, 3, 4}, true); - new BptBlockRotateInventory(Blocks.chest, new int[]{2, 5, 3, 4}, true); - new BptBlockRotateInventory(Blocks.dispenser, new int[]{2, 5, 3, 4}, true); + BlueprintManager.registerSchematicClass(Blocks.brewing_stand, BptBlockInventory.class); - new BptBlockInventory(Blocks.brewing_stand); + BlueprintManager.registerSchematicClass(Blocks.vine, BptBlockRotateMeta.class, new int[]{1, 4, 8, 2}, false); + BlueprintManager.registerSchematicClass(Blocks.trapdoor, BptBlockRotateMeta.class, new int[]{0, 1, 2, 3}, false); - new BptBlockRotateMeta(Blocks.vine, new int[]{1, 4, 8, 2}, false); - new BptBlockRotateMeta(Blocks.trapdoor, new int[]{0, 1, 2, 3}, false); + BlueprintManager.registerSchematicClass(Blocks.wooden_button, BptBlockLever.class); + BlueprintManager.registerSchematicClass(Blocks.stone_button, BptBlockLever.class); + BlueprintManager.registerSchematicClass(Blocks.lever, BptBlockLever.class); - new BptBlockLever(Blocks.wooden_button); - new BptBlockLever(Blocks.stone_button); - new BptBlockLever(Blocks.lever); - - new BptBlockCustomStack(Blocks.stone, new ItemStack(Blocks.stone)); - new BptBlockCustomStack(Blocks.redstone_wire, new ItemStack(Items.redstone)); - new BptBlockCustomStack(Blocks.cake, new ItemStack(Items.cake)); + BlueprintManager.registerSchematicClass(Blocks.stone, BptBlockCustomStack.class, new ItemStack(Blocks.stone)); + BlueprintManager.registerSchematicClass(Blocks.redstone_wire, BptBlockCustomStack.class, new ItemStack(Items.redstone)); + BlueprintManager.registerSchematicClass(Blocks.cake, BptBlockCustomStack.class, new ItemStack(Items.cake)); //new BptBlockCustomStack(Blocks.crops.blockID, new ItemStack(Items.seeds)); - new BptBlockCustomStack(Blocks.pumpkin_stem, new ItemStack(Items.pumpkin_seeds)); - new BptBlockCustomStack(Blocks.melon_stem, new ItemStack(Items.melon_seeds)); - new BptBlockCustomStack(Blocks.glowstone, new ItemStack(Blocks.glowstone)); + BlueprintManager.registerSchematicClass(Blocks.pumpkin_stem, BptBlockCustomStack.class, new ItemStack(Items.pumpkin_seeds)); + BlueprintManager.registerSchematicClass(Blocks.melon_stem, BptBlockCustomStack.class, new ItemStack(Items.melon_seeds)); + BlueprintManager.registerSchematicClass(Blocks.glowstone, BptBlockCustomStack.class, new ItemStack(Blocks.glowstone)); - new BptBlockRedstoneRepeater(Blocks.powered_repeater); - new BptBlockRedstoneRepeater(Blocks.unpowered_repeater); + BlueprintManager.registerSchematicClass(Blocks.powered_repeater, BptBlockRedstoneRepeater.class); + BlueprintManager.registerSchematicClass(Blocks.unpowered_repeater, BptBlockRedstoneRepeater.class); - new BptBlockFluid(Blocks.water, new ItemStack(Items.water_bucket)); - new BptBlockFluid(Blocks.flowing_water, new ItemStack(Items.water_bucket)); - new BptBlockFluid(Blocks.lava, new ItemStack(Items.lava_bucket)); - new BptBlockFluid(Blocks.flowing_lava, new ItemStack(Items.lava_bucket)); + BlueprintManager.registerSchematicClass(Blocks.water, BptBlockFluid.class, new ItemStack(Items.water_bucket)); + BlueprintManager.registerSchematicClass(Blocks.flowing_water, BptBlockFluid.class, new ItemStack(Items.water_bucket)); + BlueprintManager.registerSchematicClass(Blocks.lava, BptBlockFluid.class, new ItemStack(Items.lava_bucket)); + BlueprintManager.registerSchematicClass(Blocks.flowing_lava, BptBlockFluid.class, new ItemStack(Items.lava_bucket)); - new BptBlockIgnoreMeta(Blocks.rail); - new BptBlockIgnoreMeta(Blocks.detector_rail); - new BptBlockIgnoreMeta(Blocks.glass_pane); + BlueprintManager.registerSchematicClass(Blocks.rail, BptBlockIgnoreMeta.class); + BlueprintManager.registerSchematicClass(Blocks.detector_rail, BptBlockIgnoreMeta.class); + BlueprintManager.registerSchematicClass(Blocks.glass_pane, BptBlockIgnoreMeta.class); - new BptBlockPiston(Blocks.piston); - new BptBlockPiston(Blocks.sticky_piston); + BlueprintManager.registerSchematicClass(Blocks.piston, BptBlockPiston.class); + BlueprintManager.registerSchematicClass(Blocks.piston_extension, BptBlockPiston.class); + BlueprintManager.registerSchematicClass(Blocks.sticky_piston, BptBlockPiston.class); - new BptBlockPumpkin(Blocks.lit_pumpkin); + BlueprintManager.registerSchematicClass(Blocks.lit_pumpkin, BptBlockPumpkin.class); - new BptBlockStairs(Blocks.stone_stairs); - new BptBlockStairs(Blocks.oak_stairs); - new BptBlockStairs(Blocks.nether_brick_stairs); - new BptBlockStairs(Blocks.brick_stairs); - new BptBlockStairs(Blocks.stone_brick_stairs); + BlueprintManager.registerSchematicClass(Blocks.stone_stairs, BptBlockStairs.class); + BlueprintManager.registerSchematicClass(Blocks.oak_stairs, BptBlockStairs.class); + BlueprintManager.registerSchematicClass(Blocks.nether_brick_stairs, BptBlockStairs.class); + BlueprintManager.registerSchematicClass(Blocks.brick_stairs, BptBlockStairs.class); + BlueprintManager.registerSchematicClass(Blocks.stone_brick_stairs, BptBlockStairs.class); - new BptBlockDoor(Blocks.wooden_button, new ItemStack(Items.wooden_door)); - new BptBlockDoor(Blocks.iron_door, new ItemStack(Items.iron_door)); + BlueprintManager.registerSchematicClass(Blocks.wooden_button, BptBlockDoor.class, new ItemStack(Items.wooden_door)); + BlueprintManager.registerSchematicClass(Blocks.iron_door, BptBlockDoor.class, new ItemStack(Items.iron_door)); - new BptBlockBed(Blocks.bed); + BlueprintManager.registerSchematicClass(Blocks.bed, BptBlockBed.class); - new BptBlockSign(Blocks.wall_sign, true); - new BptBlockSign(Blocks.standing_sign, false); + BlueprintManager.registerSchematicClass(Blocks.wall_sign, BptBlockSign.class, true); + BlueprintManager.registerSchematicClass(Blocks.standing_sign, BptBlockSign.class, false); // BUILDCRAFT BLOCKS - new BptBlockRotateInventory(architectBlock, new int[]{2, 5, 3, 4}, true); - new BptBlockRotateInventory(builderBlock, new int[]{2, 5, 3, 4}, true); + BlueprintManager.registerSchematicClass(architectBlock, BptBlockRotateInventory.class, new int[]{2, 5, 3, 4}, true); + BlueprintManager.registerSchematicClass(builderBlock, BptBlockRotateInventory.class, new int[]{2, 5, 3, 4}, true); - new BptBlockInventory(libraryBlock); + BlueprintManager.registerSchematicClass(libraryBlock, BptBlockInventory.class); - new BptBlockWallSide(markerBlock); - new BptBlockWallSide(pathMarkerBlock); + BlueprintManager.registerSchematicClass(markerBlock, BptBlockWallSide.class); + BlueprintManager.registerSchematicClass(pathMarkerBlock, BptBlockWallSide.class); if (BuildCraftCore.loadDefaultRecipes) { loadRecipes(); diff --git a/common/buildcraft/BuildCraftEnergy.java b/common/buildcraft/BuildCraftEnergy.java index 6be73091..292c9d51 100644 --- a/common/buildcraft/BuildCraftEnergy.java +++ b/common/buildcraft/BuildCraftEnergy.java @@ -24,6 +24,7 @@ import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; +import buildcraft.api.blueprints.BlueprintManager; import buildcraft.api.fuels.IronEngineCoolant; import buildcraft.api.fuels.IronEngineFuel; import buildcraft.api.recipes.BuildcraftRecipes; @@ -250,7 +251,7 @@ public class BuildCraftEnergy extends BuildCraftMod { NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler()); - new BptBlockEngine(engineBlock); + BlueprintManager.registerSchematicClass(engineBlock, BptBlockEngine.class); if (BuildCraftCore.loadDefaultRecipes) { loadRecipes(); diff --git a/common/buildcraft/BuildCraftFactory.java b/common/buildcraft/BuildCraftFactory.java index 826ccf58..e1065566 100644 --- a/common/buildcraft/BuildCraftFactory.java +++ b/common/buildcraft/BuildCraftFactory.java @@ -22,6 +22,7 @@ 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.api.blueprints.BlueprintManager; import buildcraft.core.DefaultProps; import buildcraft.core.InterModComms; import buildcraft.core.Version; @@ -145,10 +146,10 @@ public class BuildCraftFactory extends BuildCraftMod { FactoryProxy.proxy.initializeTileEntities(); - new BptBlockAutoWorkbench(autoWorkbenchBlock); - new BptBlockFrame(frameBlock); - new BptBlockRefinery(refineryBlock); - new BptBlockTank(tankBlock); + BlueprintManager.registerSchematicClass(autoWorkbenchBlock, BptBlockAutoWorkbench.class); + BlueprintManager.registerSchematicClass(frameBlock, BptBlockFrame.class); + BlueprintManager.registerSchematicClass(refineryBlock, BptBlockRefinery.class); + BlueprintManager.registerSchematicClass(tankBlock, BptBlockTank.class); if (BuildCraftCore.loadDefaultRecipes) { loadRecipes(); diff --git a/common/buildcraft/BuildCraftSilicon.java b/common/buildcraft/BuildCraftSilicon.java index d32dc416..4a889db8 100644 --- a/common/buildcraft/BuildCraftSilicon.java +++ b/common/buildcraft/BuildCraftSilicon.java @@ -15,6 +15,7 @@ import java.util.List; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; +import buildcraft.api.blueprints.BlueprintManager; import buildcraft.api.bptblocks.BptBlockInventory; import buildcraft.api.bptblocks.BptBlockRotateMeta; import buildcraft.api.recipes.BuildcraftRecipes; @@ -93,8 +94,8 @@ public class BuildCraftSilicon extends BuildCraftMod { 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, new int[]{2, 5, 3, 4}, true); - new BptBlockInventory(assemblyTableBlock); + BlueprintManager.registerSchematicClass(laserBlock, BptBlockRotateMeta.class, new int[]{2, 5, 3, 4}, true); + BlueprintManager.registerSchematicClass(assemblyTableBlock, BptBlockInventory.class); if (BuildCraftCore.loadDefaultRecipes) { loadRecipes(); diff --git a/common/buildcraft/BuildCraftTransport.java b/common/buildcraft/BuildCraftTransport.java index 73472988..6fc5bd76 100644 --- a/common/buildcraft/BuildCraftTransport.java +++ b/common/buildcraft/BuildCraftTransport.java @@ -21,6 +21,7 @@ import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Property; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.oredict.RecipeSorter; +import buildcraft.api.blueprints.BlueprintManager; import buildcraft.api.core.IIconProvider; import buildcraft.api.gates.ActionManager; import buildcraft.api.gates.GateExpansions; @@ -429,7 +430,7 @@ public class BuildCraftTransport extends BuildCraftMod { TransportProxy.proxy.registerTileEntities(); - new BptBlockPipe(genericPipeBlock); + BlueprintManager.registerSchematicClass(genericPipeBlock, BptBlockPipe.class); new BptPipeIron(pipeItemsIron); new BptPipeIron(pipeFluidsIron); diff --git a/common/buildcraft/api/blueprints/BlueprintManager.java b/common/buildcraft/api/blueprints/BlueprintManager.java index 50a29348..c02e6c5d 100644 --- a/common/buildcraft/api/blueprints/BlueprintManager.java +++ b/common/buildcraft/api/blueprints/BlueprintManager.java @@ -8,23 +8,54 @@ */ package buildcraft.api.blueprints; +import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import net.minecraft.block.Block; public class BlueprintManager { - private static final HashMap bptBlockRegistry = new HashMap(); - - public static void registerBptBlock (Block block, BptBlock bptBlock) { - bptBlockRegistry.put(block, bptBlock); + private static class SchematicConstructor { + Class clas; + Object [] params; } - public static BptBlock getBptBlock (Block block) { - if (!bptBlockRegistry.containsKey(block)) { - registerBptBlock(block, new BptBlock(block)); + private static final HashMap schematicClasses = + new HashMap(); + + public static void registerSchematicClass (Block block, Class clas, Object ... params) { + SchematicConstructor c = new SchematicConstructor (); + c.clas = clas; + c.params = params; + + schematicClasses.put(block, c); + } + + public static BptBlock newSchematic (Block block) { + if (!schematicClasses.containsKey(block)) { + registerSchematicClass(block, BptBlock.class); } - return bptBlockRegistry.get(block); + try { + SchematicConstructor c = schematicClasses.get(block); + return (BptBlock) c.clas.getConstructors() [0].newInstance(c.params); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return null; } } diff --git a/common/buildcraft/api/blueprints/BptBlock.java b/common/buildcraft/api/blueprints/BptBlock.java old mode 100644 new mode 100755 index 033a3aca..9c73cdb0 --- a/common/buildcraft/api/blueprints/BptBlock.java +++ b/common/buildcraft/api/blueprints/BptBlock.java @@ -16,7 +16,11 @@ import net.minecraft.block.BlockContainer; import net.minecraft.inventory.IInventory; 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.core.network.NetworkData; +import buildcraft.core.utils.Utils; /** * This class allow to specify specific behavior for blocks stored in @@ -53,24 +57,72 @@ import net.minecraft.tileentity.TileEntity; */ public class BptBlock { - public final Block block; + @NetworkData + public Block block = null; - public BptBlock(Block block) { - this.block = block; - BlueprintManager.registerBptBlock(block, this); + @NetworkData + public int x, y, z, meta = 0; + + /** + * This field contains requirements for a given block when stored in the + * blueprint. Modders can either rely on this list or compute their own int + * BptBlock. + */ + @NetworkData + public ArrayList storedRequirements = new ArrayList(); + + /** + * This tree contains additional data to be stored in the blueprint. By + * default, it will be initialized from BptBlock.initializeFromWorld with + * the standard readNBT function of the corresponding tile (if any) and will + * be loaded from BptBlock.buildBlock using the standard writeNBT function. + */ + @NetworkData + public NBTTagCompound cpt = new NBTTagCompound(); + + public enum Mode { + ClearIfInvalid, Build + }; + + public Mode mode = Mode.Build; + + @SuppressWarnings("unchecked") + @Override + public BptBlock clone() { + BptBlock obj = BlueprintManager.newSchematic(block); + + obj.x = x; + obj.y = y; + obj.z = z; + obj.block = block; + obj.meta = meta; + obj.cpt = (NBTTagCompound) cpt.copy(); + obj.storedRequirements = (ArrayList) storedRequirements.clone(); + obj.mode = mode; + + return obj; } + public final LinkedList getRequirements(IBptContext context) { + LinkedList res = new LinkedList(); + + addRequirements(context, res); + + return res; + } + + /** * Returns the requirements needed to build this block. When the * requirements are met, they will be removed all at once from the builder, * before calling buildBlock. */ - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - if (slot.block != null) { - if (slot.storedRequirements.size() != 0) { - requirements.addAll(slot.storedRequirements); + public void addRequirements(IBptContext context, LinkedList requirements) { + if (block != null) { + if (storedRequirements.size() != 0) { + requirements.addAll(storedRequirements); } else { - requirements.add(new ItemStack(slot.block, 1, slot.meta)); + requirements.add(new ItemStack(block, 1, meta)); } } } @@ -92,7 +144,7 @@ public class BptBlock { * returns: what was used (similer to req, but created from stack, so that * any NBT based differences are drawn from the correct source) */ - public ItemStack useItem(BptSlotInfo slot, IBptContext context, ItemStack req, ItemStack stack) { + public ItemStack useItem(IBptContext context, ItemStack req, ItemStack stack) { ItemStack result = stack.copy(); if (stack.isItemStackDamageable()) { if (req.getItemDamage() + stack.getItemDamage() <= stack.getMaxDamage()) { @@ -130,34 +182,34 @@ public class BptBlock { * the blueprint at the location given by the slot. By default, this * subprogram is permissive and doesn't take into account metadata. */ - public boolean isValid(BptSlotInfo slot, IBptContext context) { - return slot.block == context.world().getBlock(slot.x, slot.y, slot.z) && slot.meta == context.world().getBlockMetadata(slot.x, slot.y, slot.z); + public boolean isValid(IBptContext context) { + return block == context.world().getBlock(x, y, z) && meta == context.world().getBlockMetadata(x, y, z); } /** * Perform a 90 degree rotation to the slot. */ - public void rotateLeft(BptSlotInfo slot, IBptContext context) { + public void rotateLeft(IBptContext context) { } /** * Places the block in the world, at the location specified in the slot. */ - public void buildBlock(BptSlotInfo slot, IBptContext context) { + public void buildBlock(IBptContext context) { // Meta needs to be specified twice, depending on the block behavior - context.world().setBlock(slot.x, slot.y, slot.z, slot.block, slot.meta, 3); + context.world().setBlock(x, y, z, block, meta, 3); //context.world().setBlockMetadataWithNotify(slot.x, slot.y, slot.z, slot.meta, 3); - if (slot.block instanceof BlockContainer) { - TileEntity tile = context.world().getTileEntity(slot.x, slot.y, slot.z); + if (block instanceof BlockContainer) { + TileEntity tile = context.world().getTileEntity(x, y, z); - slot.cpt.setInteger("x", slot.x); - slot.cpt.setInteger("y", slot.y); - slot.cpt.setInteger("z", slot.z); + cpt.setInteger("x", x); + cpt.setInteger("y", y); + cpt.setInteger("z", z); if (tile != null) { - tile.readFromNBT(slot.cpt); + tile.readFromNBT(cpt); } // By default, clear the inventory to avoid possible dupe bugs @@ -175,7 +227,7 @@ public class BptBlock { * Return true if the block should not be placed to the world. Requirements * will not be asked on such a block, and building will not be called. */ - public boolean ignoreBuilding(BptSlotInfo slot) { + public boolean ignoreBuilding() { return false; } @@ -188,21 +240,21 @@ public class BptBlock { * By default, if the block is a BlockContainer, tile information will be to * save / load the block. */ - public void initializeFromWorld(BptSlotInfo slot, IBptContext context, int x, int y, int z) { - if (slot.block instanceof BlockContainer) { + public void initializeFromWorld(IBptContext context, int x, int y, int z) { + if (block instanceof BlockContainer) { TileEntity tile = context.world().getTileEntity(x, y, z); if (tile != null) { - tile.writeToNBT(slot.cpt); + tile.writeToNBT(cpt); } } - if (slot.block != null) { - ArrayList req = slot.block.getDrops(context.world(), x, + if (block != null) { + ArrayList req = block.getDrops(context.world(), x, y, z, context.world().getBlockMetadata(x, y, z), 0); if (req != null) { - slot.storedRequirements.addAll(req); + storedRequirements.addAll(req); } } } @@ -212,11 +264,47 @@ public class BptBlock { * blocks. This may be useful to adjust variable depending on surrounding * blocks that may not be there already at initial building. */ - public void postProcessing(BptSlotInfo slot, IBptContext context) { + public void postProcessing(IBptContext context) { } private boolean starMatch(String s1, String s2) { return s1.equals("*") || s2.equals("*") || s1.equals(s2); } + + public void writeToNBT(NBTTagCompound nbt, MappingRegistry registry) { + nbt.setInteger("blockId", registry.getIdForBlock(block)); + nbt.setInteger("blockMeta", meta); + nbt.setTag("blockCpt", cpt); + + NBTTagList rq = new NBTTagList(); + + for (ItemStack stack : storedRequirements) { + NBTTagCompound sub = new NBTTagCompound(); + stack.writeToNBT(stack.writeToNBT(sub)); + sub.setInteger("id", Item.itemRegistry.getIDForObject(registry + .getItemForId(sub.getInteger("id")))); + rq.appendTag(sub); + } + + nbt.setTag("rq", rq); + } + + public void readFromNBT(NBTTagCompound nbt, MappingRegistry registry) { + block = registry.getBlockForId(nbt.getInteger("blockId")); + meta = nbt.getInteger("blockMeta"); + cpt = nbt.getCompoundTag("blockCpt"); + + NBTTagList rq = nbt.getTagList("rq", Utils.NBTTag_Types.NBTTagList.ordinal()); + + for (int i = 0; i < rq.tagCount(); ++i) { + NBTTagCompound sub = rq.getCompoundTagAt(i); + + // Maps the id in the blueprint to the id in the world + sub.setInteger("id", Item.itemRegistry.getIDForObject(registry + .getItemForId(sub.getInteger("id")))); + + storedRequirements.add(ItemStack.loadItemStackFromNBT(sub)); + } + } } diff --git a/common/buildcraft/api/blueprints/BptBlockUtils.java b/common/buildcraft/api/blueprints/BptBlockUtils.java index 38186ca1..f4708f4a 100644 --- a/common/buildcraft/api/blueprints/BptBlockUtils.java +++ b/common/buildcraft/api/blueprints/BptBlockUtils.java @@ -17,7 +17,7 @@ import net.minecraft.nbt.NBTTagList; public class BptBlockUtils { - public static void requestInventoryContents(BptSlotInfo slot, IBptContext context, LinkedList requirements) { + public static void requestInventoryContents(BptBlock slot, IBptContext context, LinkedList requirements) { ItemStack[] stacks = getItemStacks(slot, context); for (ItemStack stack : stacks) { @@ -27,7 +27,7 @@ public class BptBlockUtils { } } - public static void initializeInventoryContents(BptSlotInfo slot, IBptContext context, IInventory inventory) { + public static void initializeInventoryContents(BptBlock slot, IBptContext context, IInventory inventory) { ItemStack[] stacks = new ItemStack[inventory.getSizeInventory()]; for (int i = 0; i < inventory.getSizeInventory(); ++i) { @@ -37,7 +37,7 @@ public class BptBlockUtils { setItemStacks(slot, context, stacks); } - public static void buildInventoryContents(BptSlotInfo slot, IBptContext context, IInventory inventory) { + public static void buildInventoryContents(BptBlock slot, IBptContext context, IInventory inventory) { ItemStack[] stacks = getItemStacks(slot, context); for (int i = 0; i < stacks.length; ++i) { @@ -45,11 +45,12 @@ public class BptBlockUtils { } } - public static ItemStack[] getItemStacks(BptSlotInfo slot, IBptContext context) { + public static ItemStack[] getItemStacks(BptBlock slot, IBptContext context) { NBTTagList list = (NBTTagList) slot.cpt.getTag("inv"); - if (list == null) + if (list == null) { return new ItemStack[0]; + } ItemStack stacks[] = new ItemStack[list.tagCount()]; @@ -64,14 +65,12 @@ public class BptBlockUtils { return stacks; } - public static void setItemStacks(BptSlotInfo slot, IBptContext context, ItemStack[] stacks) { + public static void setItemStacks(BptBlock slot, IBptContext context, ItemStack[] stacks) { NBTTagList nbttaglist = new NBTTagList(); - for (int i = 0; i < stacks.length; ++i) { + for (ItemStack stack : stacks) { NBTTagCompound cpt = new NBTTagCompound(); nbttaglist.appendTag(cpt); - ItemStack stack = stacks[i]; - if (stack != null && stack.stackSize != 0) { stack.writeToNBT(cpt); //context.storeId(stack.itemID); diff --git a/common/buildcraft/api/blueprints/BptSlotInfo.java b/common/buildcraft/api/blueprints/BptSlotInfo.java deleted file mode 100644 index b3e0a1fc..00000000 --- a/common/buildcraft/api/blueprints/BptSlotInfo.java +++ /dev/null @@ -1,61 +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.api.blueprints; - -import java.util.ArrayList; - -import net.minecraft.block.Block; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import buildcraft.core.network.NetworkData; - -/** - * This class records a slot, either from a blueprint or from a block placed in - * the world. - */ -public class BptSlotInfo { - - @NetworkData - public Block block = null; - - @NetworkData - public int x, y, z, meta = 0; - - /** - * This field contains requirements for a given block when stored in the - * blueprint. Modders can either rely on this list or compute their own int - * BptBlock. - */ - @NetworkData - public ArrayList storedRequirements = new ArrayList(); - - /** - * This tree contains additional data to be stored in the blueprint. By - * default, it will be initialized from BptBlock.initializeFromWorld with - * the standard readNBT function of the corresponding tile (if any) and will - * be loaded from BptBlock.buildBlock using the standard writeNBT function. - */ - @NetworkData - public NBTTagCompound cpt = new NBTTagCompound(); - - @Override - public BptSlotInfo clone() { - BptSlotInfo obj = new BptSlotInfo(); - - obj.x = x; - obj.y = y; - obj.z = z; - obj.block = block; - obj.meta = meta; - obj.cpt = (NBTTagCompound) cpt.copy(); - - return obj; - } - -} diff --git a/common/buildcraft/api/bptblocks/BptBlockBed.java b/common/buildcraft/api/bptblocks/BptBlockBed.java index 66118c9e..ffe79a97 100644 --- a/common/buildcraft/api/bptblocks/BptBlockBed.java +++ b/common/buildcraft/api/bptblocks/BptBlockBed.java @@ -10,59 +10,53 @@ package buildcraft.api.bptblocks; import java.util.LinkedList; -import net.minecraft.block.Block; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; public class BptBlockBed extends BptBlock { - public BptBlockBed(Block block) { - super(block); - } - @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - if ((slot.meta & 8) == 0) { + public void addRequirements(IBptContext context, LinkedList requirements) { + if ((meta & 8) == 0) { requirements.add(new ItemStack(Items.bed)); } } @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { - int orientation = (slot.meta & 7); - int others = slot.meta - orientation; + public void rotateLeft(IBptContext context) { + int orientation = (meta & 7); + int others = meta - orientation; switch (orientation) { case 0: - slot.meta = 1 + others; + meta = 1 + others; break; case 1: - slot.meta = 2 + others; + meta = 2 + others; break; case 2: - slot.meta = 3 + others; + meta = 3 + others; break; case 3: - slot.meta = 0 + others; + meta = 0 + others; break; } } @Override - public void buildBlock(BptSlotInfo slot, IBptContext context) { - if ((slot.meta & 8) != 0) { + public void buildBlock(IBptContext context) { + if ((meta & 8) != 0) { return; } - context.world().setBlock(slot.x, slot.y, slot.z, slot.block, slot.meta,1); + context.world().setBlock(x, y, z, block, meta, 3); - int x2 = slot.x; - int z2 = slot.z; + int x2 = x; + int z2 = z; - switch (slot.meta) { + switch (meta) { case 0: z2++; break; @@ -77,11 +71,11 @@ public class BptBlockBed extends BptBlock { break; } - context.world().setBlock(x2, slot.y, z2, slot.block, slot.meta + 8,1); + context.world().setBlock(x2, y, z2, block, meta + 8,1); } @Override - public boolean ignoreBuilding(BptSlotInfo slot) { - return (slot.meta & 8) != 0; + public boolean ignoreBuilding() { + return (meta & 8) != 0; } } diff --git a/common/buildcraft/api/bptblocks/BptBlockCustomStack.java b/common/buildcraft/api/bptblocks/BptBlockCustomStack.java index 5761ac3b..9bd08ee8 100644 --- a/common/buildcraft/api/bptblocks/BptBlockCustomStack.java +++ b/common/buildcraft/api/bptblocks/BptBlockCustomStack.java @@ -10,24 +10,20 @@ package buildcraft.api.bptblocks; import java.util.LinkedList; -import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; public class BptBlockCustomStack extends BptBlock { final ItemStack customStack; - public BptBlockCustomStack(Block block, ItemStack customStack) { - super(block); - + public BptBlockCustomStack(ItemStack customStack) { this.customStack = customStack; } @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { + public void addRequirements(IBptContext context, LinkedList requirements) { requirements.add(customStack.copy()); } diff --git a/common/buildcraft/api/bptblocks/BptBlockDelegate.java b/common/buildcraft/api/bptblocks/BptBlockDelegate.java deleted file mode 100644 index 7a297e95..00000000 --- a/common/buildcraft/api/bptblocks/BptBlockDelegate.java +++ /dev/null @@ -1,63 +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.api.bptblocks; - -import java.util.LinkedList; - -import net.minecraft.block.Block; -import net.minecraft.item.ItemStack; -import buildcraft.api.blueprints.BlueprintManager; -import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; -import buildcraft.api.blueprints.IBptContext; - -public class BptBlockDelegate extends BptBlock { - - final Block delegateTo; - BptBlock delegated; - - public BptBlockDelegate(Block block, Block delegateTo) { - super(block); - - this.delegateTo = delegateTo; - } - - @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - BptSlotInfo newSlot = slot.clone(); - slot.block = delegateTo; - - getDelegated ().addRequirements(newSlot, context, requirements); - } - - @Override - public boolean isValid(BptSlotInfo slot, IBptContext context) { - BptSlotInfo newSlot = slot.clone(); - slot.block = delegateTo; - - return getDelegated ().isValid(newSlot, context); - } - - @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { - BptSlotInfo newSlot = slot.clone(); - slot.block = delegateTo; - - getDelegated().rotateLeft(newSlot, context); - } - - private BptBlock getDelegated () { - if (delegated == null) { - delegated = BlueprintManager.getBptBlock(delegateTo); - } - - return delegated; - } - -} diff --git a/common/buildcraft/api/bptblocks/BptBlockDirt.java b/common/buildcraft/api/bptblocks/BptBlockDirt.java index 4a35475a..0585747c 100644 --- a/common/buildcraft/api/bptblocks/BptBlockDirt.java +++ b/common/buildcraft/api/bptblocks/BptBlockDirt.java @@ -14,28 +14,23 @@ import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; public class BptBlockDirt extends BptBlock { - public BptBlockDirt(Block block) { - super(block); - } - @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { + public void addRequirements(IBptContext context, LinkedList requirements) { requirements.add(new ItemStack(Blocks.dirt)); } @Override - public void buildBlock(BptSlotInfo slot, IBptContext context) { - context.world().setBlock(slot.x, slot.y, slot.z, Blocks.dirt, slot.meta,1); + public void buildBlock(IBptContext context) { + context.world().setBlock(x, y, z, Blocks.dirt, meta, 3); } @Override - public boolean isValid(BptSlotInfo slot, IBptContext context) { - Block block = context.world().getBlock(slot.x, slot.y, slot.z); + public boolean isValid(IBptContext context) { + Block block = context.world().getBlock(x, y, z); return block == Blocks.dirt || block == Blocks.grass || block == Blocks.farmland; } diff --git a/common/buildcraft/api/bptblocks/BptBlockDoor.java b/common/buildcraft/api/bptblocks/BptBlockDoor.java index 59b54849..dc80441a 100644 --- a/common/buildcraft/api/bptblocks/BptBlockDoor.java +++ b/common/buildcraft/api/bptblocks/BptBlockDoor.java @@ -10,62 +10,58 @@ package buildcraft.api.bptblocks; import java.util.LinkedList; -import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; public class BptBlockDoor extends BptBlock { final ItemStack stack; - public BptBlockDoor(Block block, ItemStack stack) { - super(block); - + public BptBlockDoor(ItemStack stack) { this.stack = stack; } @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - if ((slot.meta & 8) == 0) { + public void addRequirements(IBptContext context, LinkedList requirements) { + if ((meta & 8) == 0) { requirements.add(stack.copy()); } } @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { - int orientation = (slot.meta & 3); - int others = slot.meta - orientation; + public void rotateLeft(IBptContext context) { + int orientation = (meta & 3); + int others = meta - orientation; switch (orientation) { case 0: - slot.meta = 1 + others; + meta = 1 + others; break; case 1: - slot.meta = 2 + others; + meta = 2 + others; break; case 2: - slot.meta = 3 + others; + meta = 3 + others; break; case 3: - slot.meta = 0 + others; + meta = 0 + others; break; } } @Override - public boolean ignoreBuilding(BptSlotInfo slot) { - return (slot.meta & 8) != 0; + public boolean ignoreBuilding() { + return (meta & 8) != 0; } @Override - public void buildBlock(BptSlotInfo slot, IBptContext context) { - context.world().setBlock(slot.x, slot.y, slot.z, slot.block, slot.meta,1); - context.world().setBlock(slot.x, slot.y + 1, slot.z, slot.block, slot.meta + 8,1); + public void buildBlock(IBptContext context) { + context.world().setBlock(x, y, z, block, meta, 3); + context.world().setBlock(x, y + 1, z, block, meta + 8, 3); - context.world().setBlockMetadataWithNotify(slot.x, slot.y + 1, slot.z, slot.meta + 8,1); - context.world().setBlockMetadataWithNotify(slot.x, slot.y, slot.z, slot.meta,1); + context.world().setBlockMetadataWithNotify(x, y + 1, z, meta + 8, 3); + context.world().setBlockMetadataWithNotify(x, y, z, meta, 3); } } diff --git a/common/buildcraft/api/bptblocks/BptBlockFluid.java b/common/buildcraft/api/bptblocks/BptBlockFluid.java index fa96cb91..713ef9ce 100644 --- a/common/buildcraft/api/bptblocks/BptBlockFluid.java +++ b/common/buildcraft/api/bptblocks/BptBlockFluid.java @@ -10,52 +10,48 @@ package buildcraft.api.bptblocks; import java.util.LinkedList; -import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; public class BptBlockFluid extends BptBlock { private final ItemStack bucketStack; - public BptBlockFluid(Block block, ItemStack bucketStack) { - super(block); - + public BptBlockFluid(ItemStack bucketStack) { this.bucketStack = bucketStack; } @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - if (slot.meta == 0) { + public void addRequirements(IBptContext context, LinkedList requirements) { + if (meta == 0) { requirements.add(bucketStack.copy()); } } @Override - public boolean isValid(BptSlotInfo slot, IBptContext context) { - if (slot.meta == 0) { - return slot.block == context.world().getBlock(slot.x, slot.y, slot.z) && context.world().getBlockMetadata(slot.x, slot.y, slot.z) == 0; + public boolean isValid(IBptContext context) { + if (meta == 0) { + return block == context.world().getBlock(x, y, z) && context.world().getBlockMetadata(x, y, z) == 0; } else { return true; } } @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { + public void rotateLeft(IBptContext context) { } @Override - public boolean ignoreBuilding(BptSlotInfo slot) { - return slot.meta != 0; + public boolean ignoreBuilding() { + return meta != 0; } @Override - public void buildBlock(BptSlotInfo slot, IBptContext context) { - if (slot.meta == 0) { - context.world().setBlock(slot.x, slot.y, slot.z, slot.block, 0,1); + public void buildBlock(IBptContext context) { + if (meta == 0) { + context.world().setBlock(x, y, z, block, 0,1); } } diff --git a/common/buildcraft/api/bptblocks/BptBlockIgnore.java b/common/buildcraft/api/bptblocks/BptBlockIgnore.java index 15939e12..7cde6528 100644 --- a/common/buildcraft/api/bptblocks/BptBlockIgnore.java +++ b/common/buildcraft/api/bptblocks/BptBlockIgnore.java @@ -10,35 +10,29 @@ package buildcraft.api.bptblocks; import java.util.LinkedList; -import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; public class BptBlockIgnore extends BptBlock { - public BptBlockIgnore(Block block) { - super(block); + @Override + public void addRequirements(IBptContext context, LinkedList requirements) { + requirements.add(new ItemStack(block, 0, 0)); } @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - requirements.add(new ItemStack(slot.block, 0, 0)); - } - - @Override - public boolean isValid(BptSlotInfo slot, IBptContext context) { + public boolean isValid(IBptContext context) { return true; } @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { + public void rotateLeft(IBptContext context) { } @Override - public boolean ignoreBuilding(BptSlotInfo slot) { + public boolean ignoreBuilding() { return true; } diff --git a/common/buildcraft/api/bptblocks/BptBlockIgnoreMeta.java b/common/buildcraft/api/bptblocks/BptBlockIgnoreMeta.java index abe6c23e..6c263cb7 100644 --- a/common/buildcraft/api/bptblocks/BptBlockIgnoreMeta.java +++ b/common/buildcraft/api/bptblocks/BptBlockIgnoreMeta.java @@ -10,25 +10,19 @@ package buildcraft.api.bptblocks; import java.util.LinkedList; -import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; public class BptBlockIgnoreMeta extends BptBlock { - public BptBlockIgnoreMeta(Block block) { - super(block); + @Override + public void addRequirements(IBptContext context, LinkedList requirements) { + requirements.add(new ItemStack(block, 1, 0)); } @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - requirements.add(new ItemStack(slot.block, 1, 0)); - } - - @Override - public boolean isValid(BptSlotInfo slot, IBptContext context) { - return slot.block == context.world().getBlock(slot.x, slot.y, slot.z); + public boolean isValid(IBptContext context) { + return block == context.world().getBlock(x, y, z); } } diff --git a/common/buildcraft/api/bptblocks/BptBlockInventory.java b/common/buildcraft/api/bptblocks/BptBlockInventory.java index 41408f65..0a0a06d9 100644 --- a/common/buildcraft/api/bptblocks/BptBlockInventory.java +++ b/common/buildcraft/api/bptblocks/BptBlockInventory.java @@ -8,24 +8,17 @@ */ package buildcraft.api.bptblocks; -import net.minecraft.block.Block; import net.minecraft.inventory.IInventory; import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; public class BptBlockInventory extends BptBlock { - public BptBlockInventory(Block block) { - super(block); - - } - @Override - public void buildBlock(BptSlotInfo slot, IBptContext context) { - super.buildBlock(slot, context); + public void buildBlock(IBptContext context) { + super.buildBlock(context); - IInventory inv = (IInventory) context.world().getTileEntity(slot.x, slot.y, slot.z); + IInventory inv = (IInventory) context.world().getTileEntity(x, y, z); for (int i = 0; i < inv.getSizeInventory(); ++i) { inv.setInventorySlotContents(i, null); diff --git a/common/buildcraft/api/bptblocks/BptBlockLever.java b/common/buildcraft/api/bptblocks/BptBlockLever.java index 41bdf6a6..1e0ad759 100644 --- a/common/buildcraft/api/bptblocks/BptBlockLever.java +++ b/common/buildcraft/api/bptblocks/BptBlockLever.java @@ -10,29 +10,23 @@ package buildcraft.api.bptblocks; import java.util.LinkedList; -import net.minecraft.block.Block; import net.minecraft.item.ItemStack; -import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; public class BptBlockLever extends BptBlockWallSide { - public BptBlockLever(Block block) { - super(block); - } - @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { + public void addRequirements(IBptContext context, LinkedList requirements) { //requirements.add(new ItemStack(slot.blockId, 1, 0)); } @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { - int status = slot.meta - (slot.meta & 7); + public void rotateLeft(IBptContext context) { + int status = meta - (meta & 7); - slot.meta -= status; - super.rotateLeft(slot, context); - slot.meta += status; + meta -= status; + super.rotateLeft(context); + meta += status; } } diff --git a/common/buildcraft/api/bptblocks/BptBlockPiston.java b/common/buildcraft/api/bptblocks/BptBlockPiston.java index 41fc2227..1d3a85ac 100644 --- a/common/buildcraft/api/bptblocks/BptBlockPiston.java +++ b/common/buildcraft/api/bptblocks/BptBlockPiston.java @@ -8,21 +8,19 @@ */ package buildcraft.api.bptblocks; -import net.minecraft.block.Block; -import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; public class BptBlockPiston extends BptBlockRotateMeta { - public BptBlockPiston(Block block) { - super(block, new int[] { 2, 5, 3, 4 }, true); + public BptBlockPiston() { + super(new int[] { 2, 5, 3, 4 }, true); } @Override - public void buildBlock(BptSlotInfo slot, IBptContext context) { - int meta = slot.meta & 7; + public void buildBlock(IBptContext context) { + int localMeta = meta & 7; - //context.world().setBlock(slot.x, slot.y, slot.z, slot.blockId, meta,1); + context.world().setBlock(x, y, z, block, localMeta, 3); } } diff --git a/common/buildcraft/api/bptblocks/BptBlockPumpkin.java b/common/buildcraft/api/bptblocks/BptBlockPumpkin.java index f6897d6d..4e1d0f4b 100644 --- a/common/buildcraft/api/bptblocks/BptBlockPumpkin.java +++ b/common/buildcraft/api/bptblocks/BptBlockPumpkin.java @@ -10,42 +10,36 @@ package buildcraft.api.bptblocks; import java.util.LinkedList; -import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; public class BptBlockPumpkin extends BptBlock { - public BptBlockPumpkin(Block block) { - super(block); + @Override + public void addRequirements(IBptContext context, LinkedList requirements) { + requirements.add(new ItemStack(block, 1, 0)); } @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - requirements.add(new ItemStack(slot.block, 1, 0)); + public boolean isValid(IBptContext context) { + return block == context.world().getBlock(x, y, z); } @Override - public boolean isValid(BptSlotInfo slot, IBptContext context) { - return slot.block == context.world().getBlock(slot.x, slot.y, slot.z); - } - - @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { - switch (slot.meta) { + public void rotateLeft(IBptContext context) { + switch (meta) { case 0: - slot.meta = 1; + meta = 1; break; case 1: - slot.meta = 2; + meta = 2; break; case 2: - slot.meta = 3; + meta = 3; break; case 3: - slot.meta = 0; + meta = 0; break; } } diff --git a/common/buildcraft/api/bptblocks/BptBlockRedstoneRepeater.java b/common/buildcraft/api/bptblocks/BptBlockRedstoneRepeater.java index b055edcb..c5f23f17 100644 --- a/common/buildcraft/api/bptblocks/BptBlockRedstoneRepeater.java +++ b/common/buildcraft/api/bptblocks/BptBlockRedstoneRepeater.java @@ -10,40 +10,34 @@ package buildcraft.api.bptblocks; import java.util.LinkedList; -import net.minecraft.block.Block; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; public class BptBlockRedstoneRepeater extends BptBlock { - public BptBlockRedstoneRepeater(Block block) { - super(block); - } - @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { + public void addRequirements(IBptContext context, LinkedList requirements) { requirements.add(new ItemStack(Items.repeater)); } @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { - int step = slot.meta - (slot.meta & 3); + public void rotateLeft(IBptContext context) { + int step = meta - (meta & 3); - switch (slot.meta - step) { + switch (meta - step) { case 0: - slot.meta = 1 + step; + meta = 1 + step; break; case 1: - slot.meta = 2 + step; + meta = 2 + step; break; case 2: - slot.meta = 3 + step; + meta = 3 + step; break; case 3: - slot.meta = 0 + step; + meta = 0 + step; break; } } diff --git a/common/buildcraft/api/bptblocks/BptBlockRotateInventory.java b/common/buildcraft/api/bptblocks/BptBlockRotateInventory.java index a6f20364..3d24bbbb 100644 --- a/common/buildcraft/api/bptblocks/BptBlockRotateInventory.java +++ b/common/buildcraft/api/bptblocks/BptBlockRotateInventory.java @@ -8,24 +8,21 @@ */ package buildcraft.api.bptblocks; -import net.minecraft.block.Block; import net.minecraft.inventory.IInventory; -import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; -@Deprecated public class BptBlockRotateInventory extends BptBlockRotateMeta { - public BptBlockRotateInventory(Block block, int[] rotations, boolean rotateForward) { - super(block, rotations, rotateForward); + public BptBlockRotateInventory(int[] rotations, boolean rotateForward) { + super(rotations, rotateForward); } @Override - public void buildBlock(BptSlotInfo slot, IBptContext context) { - super.buildBlock(slot, context); + public void buildBlock(IBptContext context) { + super.buildBlock(context); - IInventory inv = (IInventory) context.world().getTileEntity(slot.x, slot.y, slot.z); + IInventory inv = (IInventory) context.world().getTileEntity(x, y, z); for (int i = 0; i < inv.getSizeInventory(); ++i) { inv.setInventorySlotContents(i, null); diff --git a/common/buildcraft/api/bptblocks/BptBlockRotateMeta.java b/common/buildcraft/api/bptblocks/BptBlockRotateMeta.java index 61fd2b04..b360bf01 100644 --- a/common/buildcraft/api/bptblocks/BptBlockRotateMeta.java +++ b/common/buildcraft/api/bptblocks/BptBlockRotateMeta.java @@ -10,10 +10,8 @@ package buildcraft.api.bptblocks; import java.util.LinkedList; -import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; public class BptBlockRotateMeta extends BptBlock { @@ -23,17 +21,15 @@ public class BptBlockRotateMeta extends BptBlock { int infoMask = 0; - public BptBlockRotateMeta(Block block, int[] rotations, boolean rotateForward) { - super(block); - + public BptBlockRotateMeta(int[] rotations, boolean rotateForward) { rot = rotations; - for (int i = 0; i < rot.length; ++i) { - if (rot[i] < 4) { + for (int element : rot) { + if (element < 4) { infoMask = (infoMask < 3 ? 3 : infoMask); - } else if (rot[i] < 8) { + } else if (element < 8) { infoMask = (infoMask < 7 ? 7 : infoMask); - } else if (rot[i] < 16) { + } else if (element < 16) { infoMask = (infoMask < 15 ? 15 : infoMask); } } @@ -42,19 +38,19 @@ public class BptBlockRotateMeta extends BptBlock { } @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - requirements.add(new ItemStack(slot.block, 1, 0)); + public void addRequirements(IBptContext context, LinkedList requirements) { + requirements.add(new ItemStack(block, 1, 0)); } @Override - public boolean isValid(BptSlotInfo slot, IBptContext context) { - return slot.block == context.world().getBlock(slot.x, slot.y, slot.z); + public boolean isValid(IBptContext context) { + return block == context.world().getBlock(x, y, z); } @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { - int pos = slot.meta & infoMask; - int others = slot.meta - pos; + public void rotateLeft(IBptContext context) { + int pos = meta & infoMask; + int others = meta - pos; if (rotateForward) { if (pos == rot[0]) { @@ -78,7 +74,7 @@ public class BptBlockRotateMeta extends BptBlock { } } - slot.meta = pos + others; + meta = pos + others; } } diff --git a/common/buildcraft/api/bptblocks/BptBlockSign.java b/common/buildcraft/api/bptblocks/BptBlockSign.java index e3b18510..cc558806 100644 --- a/common/buildcraft/api/bptblocks/BptBlockSign.java +++ b/common/buildcraft/api/bptblocks/BptBlockSign.java @@ -10,40 +10,36 @@ package buildcraft.api.bptblocks; import java.util.LinkedList; -import net.minecraft.block.Block; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraftforge.common.util.ForgeDirection; import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; public class BptBlockSign extends BptBlock { boolean isWall; - public BptBlockSign(Block block, boolean isWall) { - super(block); - + public BptBlockSign(boolean isWall) { this.isWall = isWall; } @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { + public void addRequirements(IBptContext context, LinkedList requirements) { requirements.add(new ItemStack(Items.sign)); } @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { + public void rotateLeft(IBptContext context) { if (!isWall) { - double angle = ((slot.meta) * 360.0) / 16.0; + double angle = ((meta) * 360.0) / 16.0; angle += 90.0; if (angle >= 360) { angle -= 360; } - slot.meta = (int) (angle / 360.0 * 16.0); + meta = (int) (angle / 360.0 * 16.0); } else { - slot.meta = ForgeDirection.values()[slot.meta].getRotation(ForgeDirection.UP).ordinal(); + meta = ForgeDirection.values()[meta].getRotation(ForgeDirection.UP).ordinal(); } } } diff --git a/common/buildcraft/api/bptblocks/BptBlockStairs.java b/common/buildcraft/api/bptblocks/BptBlockStairs.java index 5d77d1fd..5b8bf1d1 100644 --- a/common/buildcraft/api/bptblocks/BptBlockStairs.java +++ b/common/buildcraft/api/bptblocks/BptBlockStairs.java @@ -10,42 +10,36 @@ package buildcraft.api.bptblocks; import java.util.LinkedList; -import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; public class BptBlockStairs extends BptBlock { - public BptBlockStairs(Block block) { - super(block); + @Override + public void addRequirements(IBptContext context, LinkedList requirements) { + requirements.add(new ItemStack(block, 1, 0)); } @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - requirements.add(new ItemStack(slot.block, 1, 0)); + public boolean isValid(IBptContext context) { + return block == context.world().getBlock(x, y, z); } @Override - public boolean isValid(BptSlotInfo slot, IBptContext context) { - return slot.block == context.world().getBlock(slot.x, slot.y, slot.z); - } - - @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { - switch (slot.meta) { + public void rotateLeft(IBptContext context) { + switch (meta) { case 0: - slot.meta = 2; + meta = 2; break; case 1: - slot.meta = 3; + meta = 3; break; case 2: - slot.meta = 1; + meta = 1; break; case 3: - slot.meta = 0; + meta = 0; break; } } diff --git a/common/buildcraft/api/bptblocks/BptBlockWallSide.java b/common/buildcraft/api/bptblocks/BptBlockWallSide.java index 9e0beae0..75616dde 100644 --- a/common/buildcraft/api/bptblocks/BptBlockWallSide.java +++ b/common/buildcraft/api/bptblocks/BptBlockWallSide.java @@ -10,42 +10,36 @@ package buildcraft.api.bptblocks; import java.util.LinkedList; -import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; public class BptBlockWallSide extends BptBlock { - public BptBlockWallSide(Block block) { - super(block); + @Override + public void addRequirements(IBptContext context, LinkedList requirements) { + requirements.add(new ItemStack(block, 1, 0)); } @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - requirements.add(new ItemStack(slot.block, 1, 0)); - } - - @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { + public void rotateLeft(IBptContext context) { final int XPos = 2; final int XNeg = 1; final int ZPos = 4; final int ZNeg = 3; - switch (slot.meta) { + switch (meta) { case XPos: - slot.meta = ZPos; + meta = ZPos; break; case ZNeg: - slot.meta = XPos; + meta = XPos; break; case XNeg: - slot.meta = ZNeg; + meta = ZNeg; break; case ZPos: - slot.meta = XNeg; + meta = XNeg; break; } } diff --git a/common/buildcraft/builders/TileBuilder.java b/common/buildcraft/builders/TileBuilder.java index 00b8c267..115b58bb 100644 --- a/common/buildcraft/builders/TileBuilder.java +++ b/common/buildcraft/builders/TileBuilder.java @@ -20,6 +20,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraftforge.common.util.ForgeDirection; import buildcraft.BuildCraftBuilders; +import buildcraft.api.blueprints.BptBlock; import buildcraft.api.gates.IAction; import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.PowerHandler; @@ -38,7 +39,6 @@ import buildcraft.core.blueprints.BlueprintBase; import buildcraft.core.blueprints.BptBuilderBase; import buildcraft.core.blueprints.BptBuilderBlueprint; import buildcraft.core.blueprints.BptContext; -import buildcraft.core.blueprints.BptSlot; import buildcraft.core.network.NetworkData; import buildcraft.core.robots.EntityRobot; import buildcraft.core.utils.Utils; @@ -637,7 +637,7 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, public void debugForceBlueprintCompletion () { if (bluePrintBuilder != null) { - BptSlot slot = bluePrintBuilder.getNextBlock(worldObj, this); + BptBlock slot = bluePrintBuilder.getNextBlock(worldObj, this); if (slot != null) { slot.buildBlock(bluePrintBuilder.context); diff --git a/common/buildcraft/builders/blueprints/BlockSchematic.java b/common/buildcraft/builders/blueprints/BlockSchematic.java index e79b9782..228f06cf 100644 --- a/common/buildcraft/builders/blueprints/BlockSchematic.java +++ b/common/buildcraft/builders/blueprints/BlockSchematic.java @@ -12,7 +12,7 @@ import buildcraft.api.builder.BlockHandler; import net.minecraft.block.Block; import net.minecraft.nbt.NBTTagCompound; -public final class BlockSchematic extends Schematic { +public final class BlockSchematic extends SchematicOld { public static BlockSchematic create(NBTTagCompound nbt) { return null; diff --git a/common/buildcraft/builders/blueprints/BlueprintBuilder.java b/common/buildcraft/builders/blueprints/BlueprintBuilder.java index f451d636..902281c3 100644 --- a/common/buildcraft/builders/blueprints/BlueprintBuilder.java +++ b/common/buildcraft/builders/blueprints/BlueprintBuilder.java @@ -33,7 +33,7 @@ public class BlueprintBuilder implements IAreaProvider { this.y = y - blueprint.anchorY; this.z = translateZ(z, -blueprint.anchorX, -blueprint.anchorZ); builders = new ArrayList(blueprint.schematicSequence.size()); - for (Schematic schematic : blueprint.schematicSequence) { + for (SchematicOld schematic : blueprint.schematicSequence) { BlockHandler handler = schematic.getHandler(); if (handler != null) { builders.add(new SchematicBuilder(schematic, handler)); @@ -107,11 +107,11 @@ public class BlueprintBuilder implements IAreaProvider { public class SchematicBuilder { - public final Schematic schematic; + public final SchematicOld schematic; public final BlockHandler handler; private boolean complete; - private SchematicBuilder(Schematic schematic, BlockHandler handler) { + private SchematicBuilder(SchematicOld schematic, BlockHandler handler) { this.schematic = schematic; this.handler = handler; } diff --git a/common/buildcraft/builders/blueprints/ItemSchematic.java b/common/buildcraft/builders/blueprints/ItemSchematic.java index a17bbd25..ce89d4c5 100755 --- a/common/buildcraft/builders/blueprints/ItemSchematic.java +++ b/common/buildcraft/builders/blueprints/ItemSchematic.java @@ -12,7 +12,7 @@ import buildcraft.api.builder.BlockHandler; import net.minecraft.item.Item; import net.minecraft.nbt.NBTTagCompound; -public final class ItemSchematic extends Schematic { +public final class ItemSchematic extends SchematicOld { public static ItemSchematic create(NBTTagCompound nbt) { return null; diff --git a/common/buildcraft/builders/blueprints/MaskSchematic.java b/common/buildcraft/builders/blueprints/MaskSchematic.java index 68f787ab..26f7030e 100644 --- a/common/buildcraft/builders/blueprints/MaskSchematic.java +++ b/common/buildcraft/builders/blueprints/MaskSchematic.java @@ -11,7 +11,7 @@ package buildcraft.builders.blueprints; import buildcraft.api.builder.BlockHandler; import net.minecraft.nbt.NBTTagCompound; -public final class MaskSchematic extends Schematic { +public final class MaskSchematic extends SchematicOld { private static MaskHandler handler = new MaskHandler(); diff --git a/common/buildcraft/builders/blueprints/SchematicBlueprint.java b/common/buildcraft/builders/blueprints/SchematicBlueprint.java index 41af4fa4..3724c1bd 100644 --- a/common/buildcraft/builders/blueprints/SchematicBlueprint.java +++ b/common/buildcraft/builders/blueprints/SchematicBlueprint.java @@ -37,11 +37,11 @@ public class SchematicBlueprint { public BlueprintMeta meta; @NetworkData - public Schematic[][][] schematics; + public SchematicOld[][][] schematics; // TODO: Save this somewhere, this is the sequence in which blocks are // ordered to be build - public ArrayList schematicSequence = new ArrayList(); + public ArrayList schematicSequence = new ArrayList(); @NetworkData public int sizeX, sizeY, sizeZ; @@ -72,7 +72,7 @@ public class SchematicBlueprint { this.sizeY = sizeY; this.sizeZ = sizeZ; - schematics = new Schematic[sizeX][sizeY][sizeZ]; + schematics = new SchematicOld[sizeX][sizeY][sizeZ]; } public SchematicBlueprint(BlueprintMeta meta, int sizeX, int sizeY, int sizeZ) { @@ -82,7 +82,7 @@ public class SchematicBlueprint { this.sizeY = sizeY; this.sizeZ = sizeZ; - schematics = new Schematic[sizeX][sizeY][sizeZ]; + schematics = new SchematicOld[sizeX][sizeY][sizeZ]; } protected SchematicBlueprint(BlueprintMeta meta, NBTTagCompound nbt) { @@ -100,7 +100,7 @@ public class SchematicBlueprint { for (int i = 0; i < blockList.tagCount(); i++) { NBTTagCompound blockNBT = (NBTTagCompound) blockList.getCompoundTagAt(i); - Schematic schematic = Schematic.createSchematicFromNBT(blockNBT); + SchematicOld schematic = SchematicOld.createSchematicFromNBT(blockNBT); schematics[schematic.x][schematic.y][schematic.z] = schematic; } } @@ -139,7 +139,7 @@ public class SchematicBlueprint { meta.setCreator(creator); } - public void setSchematic(int x, int y, int z, Schematic schematic) { + public void setSchematic(int x, int y, int z, SchematicOld schematic) { schematic.x = x; schematic.y = y; schematic.z = z; @@ -151,7 +151,7 @@ public class SchematicBlueprint { BlockHandler handler = BlockHandler.get(block); try { if (handler.canSaveToSchematic(world, x, y, z)) { - Schematic schematic = BlockSchematic.create(block); + SchematicOld schematic = BlockSchematic.create(block); handler.saveToSchematic(world, x, y, z, schematic.data); setSchematic(x, y, z, schematic); } @@ -168,7 +168,7 @@ public class SchematicBlueprint { BlockHandler handler = BlockHandler.get(item.getItem()); try { if (handler.canSaveToSchematic(item)) { - Schematic schematic = ItemSchematic.create(item.getItem()); + SchematicOld schematic = ItemSchematic.create(item.getItem()); handler.saveToSchematic(item, schematic.data); setSchematic(x, y, z, schematic); } @@ -196,7 +196,7 @@ public class SchematicBlueprint { setSchematic(x, y, z, schematic); } - public Schematic getBlock(int x, int y, int z) { + public SchematicOld getBlock(int x, int y, int z) { return schematics[x][y][z]; } @@ -209,8 +209,8 @@ public class SchematicBlueprint { * * @return List */ - public LinkedList getBuildList() { - LinkedList list = new LinkedList(); + public LinkedList getBuildList() { + LinkedList list = new LinkedList(); for (int y = 0; y < sizeY; y++) { for (int x = 0; x < sizeX; x++) { @@ -228,7 +228,7 @@ public class SchematicBlueprint { if (costs != null) return costs; List stacks = new ArrayList(); - for (Schematic schematic : getBuildList()) { + for (SchematicOld schematic : getBuildList()) { BlockHandler handler = BlockHandler.get(schematic.id); List requirements = handler.getCostForSchematic(schematic.data); for (ItemStack newStack : requirements) { diff --git a/common/buildcraft/builders/blueprints/Schematic.java b/common/buildcraft/builders/blueprints/SchematicOld.java similarity index 88% rename from common/buildcraft/builders/blueprints/Schematic.java rename to common/buildcraft/builders/blueprints/SchematicOld.java index f64b969b..7e74f66d 100644 --- a/common/buildcraft/builders/blueprints/Schematic.java +++ b/common/buildcraft/builders/blueprints/SchematicOld.java @@ -12,7 +12,7 @@ import buildcraft.api.builder.BlockHandler; import buildcraft.core.network.NetworkData; import net.minecraft.nbt.NBTTagCompound; -public abstract class Schematic { +public abstract class SchematicOld { @NetworkData public int id; @@ -32,11 +32,11 @@ public abstract class Schematic { /** * Only to be class by the serializer */ - public Schematic() { + public SchematicOld() { } - protected Schematic(int id) { + protected SchematicOld(int id) { this.id = id; } @@ -56,9 +56,9 @@ public abstract class Schematic { data = nbt.getCompoundTag("data"); } - public static Schematic createSchematicFromNBT(NBTTagCompound nbt) { + public static SchematicOld createSchematicFromNBT(NBTTagCompound nbt) { String schematicType = nbt.getString("schematicType"); - Schematic schematic; + SchematicOld schematic; if (schematicType.equals("block")) { schematic = BlockSchematic.create(nbt); } else if (schematicType.equals("item")) { diff --git a/common/buildcraft/core/IBptContributor.java b/common/buildcraft/core/IBptContributor.java deleted file mode 100644 index e199622b..00000000 --- a/common/buildcraft/core/IBptContributor.java +++ /dev/null @@ -1,21 +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.core; - -import buildcraft.api.blueprints.BptSlotInfo; -import buildcraft.core.blueprints.BlueprintBase; -import net.minecraft.tileentity.TileEntity; - -public interface IBptContributor { - - public void saveToBluePrint(TileEntity builder, BlueprintBase bluePrint, BptSlotInfo slot); - - public void loadFromBluePrint(TileEntity builder, BlueprintBase bluePrint, BptSlotInfo slot); - -} diff --git a/common/buildcraft/core/blueprints/Blueprint.java b/common/buildcraft/core/blueprints/Blueprint.java index 2738ce21..a66871c4 100644 --- a/common/buildcraft/core/blueprints/Blueprint.java +++ b/common/buildcraft/core/blueprints/Blueprint.java @@ -8,12 +8,14 @@ */ package buildcraft.core.blueprints; +import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; +import buildcraft.api.blueprints.BlueprintManager; +import buildcraft.api.blueprints.BptBlock; import buildcraft.api.blueprints.IBptContext; -import buildcraft.core.IBptContributor; import buildcraft.core.utils.BCLog; import buildcraft.core.utils.Utils; @@ -27,22 +29,18 @@ public class Blueprint extends BlueprintBase { } public void readFromWorld(IBptContext context, TileEntity anchorTile, int x, int y, int z) { - BptSlot slot = new BptSlot(); + Block block = anchorTile.getWorldObj().getBlock(x, y, z); + + BptBlock slot = BlueprintManager.newSchematic(block); slot.x = (int) (x - context.surroundingBox().pMin().x); slot.y = (int) (y - context.surroundingBox().pMin().y); slot.z = (int) (z - context.surroundingBox().pMin().z); - slot.block = anchorTile.getWorldObj().getBlock(x, y, z); + slot.block = block; slot.meta = anchorTile.getWorldObj().getBlockMetadata(x, y, z); if (slot.block instanceof BlockContainer) { TileEntity tile = anchorTile.getWorldObj().getTileEntity(x, y, z); - - if (tile != null && tile instanceof IBptContributor) { - IBptContributor contributor = (IBptContributor) tile; - - contributor.saveToBluePrint(anchorTile, this, slot); - } } try { @@ -91,7 +89,10 @@ public class Blueprint extends BlueprintBase { for (int z = 0; z < sizeZ; ++z) { NBTTagCompound cpt = nbtContents.getCompoundTagAt(index); index++; - contents[x][y][z] = new BptSlot(); + + int blockId = cpt.getInteger("blockId"); + + contents[x][y][z] = BlueprintManager.newSchematic(mapping.getBlockForId(blockId)); contents[x][y][z].readFromNBT(cpt, mapping); } } diff --git a/common/buildcraft/core/blueprints/BlueprintBase.java b/common/buildcraft/core/blueprints/BlueprintBase.java index 109fadef..754f7ddb 100644 --- a/common/buildcraft/core/blueprints/BlueprintBase.java +++ b/common/buildcraft/core/blueprints/BlueprintBase.java @@ -11,6 +11,8 @@ package buildcraft.core.blueprints; import net.minecraft.block.Block; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; +import buildcraft.api.blueprints.BlueprintManager; +import buildcraft.api.blueprints.BptBlock; import buildcraft.api.blueprints.MappingRegistry; import buildcraft.builders.blueprints.BlueprintId; import buildcraft.core.Box; @@ -21,7 +23,7 @@ import buildcraft.core.utils.BCLog; public abstract class BlueprintBase { @NetworkData - public BptSlot contents[][][]; + public BptBlock contents[][][]; @NetworkData public int anchorX, anchorY, anchorZ; @@ -45,7 +47,7 @@ public abstract class BlueprintBase { } public BlueprintBase(int sizeX, int sizeY, int sizeZ) { - contents = new BptSlot[sizeX][sizeY][sizeZ]; + contents = new BptBlock[sizeX][sizeY][sizeZ]; this.sizeX = sizeX; this.sizeY = sizeY; @@ -58,7 +60,7 @@ public abstract class BlueprintBase { public void setBlock(int x, int y, int z, Block block) { if (contents[x][y][z] == null) { - contents[x][y][z] = new BptSlot(); + contents[x][y][z] = BlueprintManager.newSchematic(block); contents[x][y][z].x = x; contents[x][y][z].y = y; contents[x][y][z].z = z; @@ -68,7 +70,7 @@ public abstract class BlueprintBase { } public void rotateLeft(BptContext context) { - BptSlot newContents[][][] = new BptSlot[sizeZ][sizeY][sizeX]; + BptBlock newContents[][][] = new BptBlock[sizeZ][sizeY][sizeX]; for (int x = 0; x < sizeZ; ++x) { for (int y = 0; y < sizeY; ++y) { @@ -159,7 +161,7 @@ public abstract class BlueprintBase { author = nbt.getString("author"); - contents = new BptSlot [sizeX][sizeY][sizeZ]; + contents = new BptBlock [sizeX][sizeY][sizeZ]; try { loadContents (nbt); @@ -231,7 +233,7 @@ public abstract class BlueprintBase { res.id = id; res.author = author; - res.contents = new BptSlot[sizeX][sizeY][sizeZ]; + res.contents = new BptBlock[sizeX][sizeY][sizeZ]; res.mapping = mapping.clone (); diff --git a/common/buildcraft/core/blueprints/BptActionBuild.java b/common/buildcraft/core/blueprints/BptActionBuild.java deleted file mode 100644 index 38af87fc..00000000 --- a/common/buildcraft/core/blueprints/BptActionBuild.java +++ /dev/null @@ -1,15 +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.core.blueprints; - -import buildcraft.api.blueprints.BptSlotInfo; - -public class BptActionBuild extends BptSlotInfo { - -} diff --git a/common/buildcraft/core/blueprints/BptBuilderBase.java b/common/buildcraft/core/blueprints/BptBuilderBase.java index ca62eb23..d3d4de2a 100644 --- a/common/buildcraft/core/blueprints/BptBuilderBase.java +++ b/common/buildcraft/core/blueprints/BptBuilderBase.java @@ -10,6 +10,7 @@ package buildcraft.core.blueprints; import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.World; +import buildcraft.api.blueprints.BptBlock; import buildcraft.api.core.IAreaProvider; import buildcraft.core.Box; import buildcraft.core.IBuilderInventory; @@ -34,7 +35,7 @@ public abstract class BptBuilderBase implements IAreaProvider { context = bluePrint.getContext(world, box); } - public abstract BptSlot getNextBlock(World world, IBuilderInventory inv); + public abstract BptBlock getNextBlock(World world, IBuilderInventory inv); @Override public int xMin() { diff --git a/common/buildcraft/core/blueprints/BptBuilderBlueprint.java b/common/buildcraft/core/blueprints/BptBuilderBlueprint.java index 95b9c030..f7993328 100644 --- a/common/buildcraft/core/blueprints/BptBuilderBlueprint.java +++ b/common/buildcraft/core/blueprints/BptBuilderBlueprint.java @@ -18,19 +18,20 @@ import java.util.Map.Entry; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraft.world.WorldSettings.GameType; +import buildcraft.api.blueprints.BptBlock; +import buildcraft.api.blueprints.BptBlock.Mode; import buildcraft.api.core.StackKey; import buildcraft.core.IBuilderInventory; -import buildcraft.core.blueprints.BptSlot.Mode; import buildcraft.core.utils.BCLog; import buildcraft.core.utils.BlockUtil; public class BptBuilderBlueprint extends BptBuilderBase { - LinkedList clearList = new LinkedList(); - LinkedList primaryList = new LinkedList(); - LinkedList secondaryList = new LinkedList(); + LinkedList clearList = new LinkedList(); + LinkedList primaryList = new LinkedList(); + LinkedList secondaryList = new LinkedList(); - LinkedList postProcessingList = new LinkedList(); + LinkedList postProcessingList = new LinkedList(); public LinkedList neededItems = new LinkedList (); @@ -44,12 +45,12 @@ public class BptBuilderBlueprint extends BptBuilderBase { int yCoord = j + y - bluePrint.anchorY; int zCoord = k + z - bluePrint.anchorZ; - BptSlot slot = bluePrint.contents[i][j][k]; + BptBlock slot = bluePrint.contents[i][j][k]; if (slot != null) { slot = slot.clone(); } else { - slot = new BptSlot(); + slot = new BptBlock(); slot.meta = 0; slot.block = null; } @@ -73,12 +74,12 @@ public class BptBuilderBlueprint extends BptBuilderBase { int yCoord = j + y - bluePrint.anchorY; int zCoord = k + z - bluePrint.anchorZ; - BptSlot slot = bluePrint.contents[i][j][k]; + BptBlock slot = bluePrint.contents[i][j][k]; if (slot != null) { slot = slot.clone(); } else { - slot = new BptSlot(); + slot = new BptBlock(); slot.meta = 0; slot.block = null; } @@ -116,9 +117,9 @@ public class BptBuilderBlueprint extends BptBuilderBase { } @Override - public BptSlot getNextBlock(World world, IBuilderInventory inv) { + public BptBlock getNextBlock(World world, IBuilderInventory inv) { if (clearList.size() != 0) { - BptSlot slot = internalGetNextBlock(world, inv, clearList); + BptBlock slot = internalGetNextBlock(world, inv, clearList); checkDone(); if (slot != null) { @@ -127,7 +128,7 @@ public class BptBuilderBlueprint extends BptBuilderBase { } if (primaryList.size() != 0) { - BptSlot slot = internalGetNextBlock(world, inv, primaryList); + BptBlock slot = internalGetNextBlock(world, inv, primaryList); checkDone(); if (slot != null) { @@ -136,7 +137,7 @@ public class BptBuilderBlueprint extends BptBuilderBase { } if (secondaryList.size() != 0) { - BptSlot slot = internalGetNextBlock(world, inv, secondaryList); + BptBlock slot = internalGetNextBlock(world, inv, secondaryList); checkDone(); if (slot != null) { @@ -149,13 +150,13 @@ public class BptBuilderBlueprint extends BptBuilderBase { return null; } - public BptSlot internalGetNextBlock(World world, IBuilderInventory inv, LinkedList list) { - LinkedList failSlots = new LinkedList(); + public BptBlock internalGetNextBlock(World world, IBuilderInventory inv, LinkedList list) { + LinkedList failSlots = new LinkedList(); - BptSlot result = null; + BptBlock result = null; while (list.size() > 0) { - BptSlot slot = list.removeFirst(); + BptBlock slot = list.removeFirst(); boolean getNext = false; @@ -168,7 +169,7 @@ public class BptBuilderBlueprint extends BptBuilderBase { getNext = false; } - if (getNext) + if (getNext) { if (slot.mode == Mode.ClearIfInvalid) { if (!BlockUtil.isSoftBlock(world, slot.x, slot.y, slot.z)) { result = slot; @@ -188,6 +189,7 @@ public class BptBuilderBlueprint extends BptBuilderBase { } else { failSlots.add(slot); } + } } list.addAll(failSlots); @@ -195,7 +197,7 @@ public class BptBuilderBlueprint extends BptBuilderBase { return result; } - public boolean checkRequirements(IBuilderInventory inv, BptSlot slot) { + public boolean checkRequirements(IBuilderInventory inv, BptBlock slot) { if (slot.block == null) { return true; } @@ -204,10 +206,11 @@ public class BptBuilderBlueprint extends BptBuilderBase { LinkedList tmpInv = new LinkedList(); try { - for (ItemStack stk : slot.getRequirements(context)) + for (ItemStack stk : slot.getRequirements(context)) { if (stk != null) { tmpReq.add(stk.copy()); } + } } catch (Throwable t) { // Defensive code against errors in implementers t.printStackTrace(); @@ -255,7 +258,7 @@ public class BptBuilderBlueprint extends BptBuilderBase { return true; } - public void useRequirements(IBuilderInventory inv, BptSlot slot) { + public void useRequirements(IBuilderInventory inv, BptBlock slot) { if (slot.block == null) { return; } @@ -263,10 +266,11 @@ public class BptBuilderBlueprint extends BptBuilderBase { LinkedList tmpReq = new LinkedList(); try { - for (ItemStack stk : slot.getRequirements(context)) + for (ItemStack stk : slot.getRequirements(context)) { if (stk != null) { tmpReq.add(stk.copy()); } + } } catch (Throwable t) { // Defensive code against errors in implementers t.printStackTrace(); @@ -314,8 +318,9 @@ public class BptBuilderBlueprint extends BptBuilderBase { }*/ } - if (reqStk.stackSize != 0) + if (reqStk.stackSize != 0) { return; + } if (smallStack) { itr.set(usedStack); // set to the actual item used. } @@ -329,7 +334,7 @@ public class BptBuilderBlueprint extends BptBuilderBase { HashMap computeStacks = new HashMap (); - for (BptSlot slot : primaryList) { + for (BptBlock slot : primaryList) { LinkedList stacks = new LinkedList(); @@ -360,7 +365,7 @@ public class BptBuilderBlueprint extends BptBuilderBase { } } - for (BptSlot slot : secondaryList) { + for (BptBlock slot : secondaryList) { LinkedList stacks = slot.getRequirements(context); for (ItemStack stack : stacks) { @@ -409,7 +414,7 @@ public class BptBuilderBlueprint extends BptBuilderBase { @Override public void postProcessing(World world) { - for (BptSlot s : postProcessingList) { + for (BptBlock s : postProcessingList) { try { s.postProcessing(context); } catch (Throwable t) { diff --git a/common/buildcraft/core/blueprints/BptBuilderTemplate.java b/common/buildcraft/core/blueprints/BptBuilderTemplate.java index 7621ed3c..b3c64cfd 100644 --- a/common/buildcraft/core/blueprints/BptBuilderTemplate.java +++ b/common/buildcraft/core/blueprints/BptBuilderTemplate.java @@ -8,16 +8,17 @@ */ package buildcraft.core.blueprints; -import buildcraft.core.IBuilderInventory; -import buildcraft.core.blueprints.BptSlot.Mode; import java.util.LinkedList; -import net.minecraft.item.ItemStack; + import net.minecraft.world.World; +import buildcraft.api.blueprints.BptBlock; +import buildcraft.api.blueprints.BptBlock.Mode; +import buildcraft.core.IBuilderInventory; public class BptBuilderTemplate extends BptBuilderBase { - LinkedList clearList = new LinkedList(); - LinkedList buildList = new LinkedList(); + LinkedList clearList = new LinkedList(); + LinkedList buildList = new LinkedList(); public BptBuilderTemplate(BlueprintBase bluePrint, World world, int x, int y, int z) { super(bluePrint, world, x, y, z); @@ -29,10 +30,10 @@ public class BptBuilderTemplate extends BptBuilderBase { int yCoord = j + y - bluePrint.anchorY; int zCoord = k + z - bluePrint.anchorZ; - BptSlot slot = bluePrint.contents[i][j][k]; + BptBlock slot = bluePrint.contents[i][j][k]; if (slot == null || slot.block == null) { - slot = new BptSlot(); + slot = new BptBlock(); slot.meta = 0; slot.block = null; slot.x = xCoord; @@ -54,12 +55,12 @@ public class BptBuilderTemplate extends BptBuilderBase { int yCoord = j + y - bluePrint.anchorY; int zCoord = k + z - bluePrint.anchorZ; - BptSlot slot = bluePrint.contents[i][j][k]; + BptBlock slot = bluePrint.contents[i][j][k]; if (slot != null) { slot = slot.clone(); } else { - slot = new BptSlot(); + slot = new BptBlock(); slot.meta = 0; slot.block = null; } @@ -87,25 +88,27 @@ public class BptBuilderTemplate extends BptBuilderBase { } @Override - public BptSlot getNextBlock(World world, IBuilderInventory inv) { + public BptBlock getNextBlock(World world, IBuilderInventory inv) { if (clearList.size() != 0) { - BptSlot slot = internalGetNextBlock(world, inv, clearList); + BptBlock slot = internalGetNextBlock(world, inv, clearList); checkDone(); - if (slot != null) + if (slot != null) { return slot; - else + } else { return null; + } } if (buildList.size() != 0) { - BptSlot slot = internalGetNextBlock(world, inv, buildList); + BptBlock slot = internalGetNextBlock(world, inv, buildList); checkDone(); - if (slot != null) + if (slot != null) { return slot; - else + } else { return null; + } } checkDone(); @@ -113,11 +116,11 @@ public class BptBuilderTemplate extends BptBuilderBase { return null; } - public BptSlot internalGetNextBlock(World world, IBuilderInventory inv, LinkedList list) { - BptSlot result = null; + public BptBlock internalGetNextBlock(World world, IBuilderInventory inv, LinkedList list) { + BptBlock result = null; while (list.size() > 0) { - BptSlot slot = list.getFirst(); + BptBlock slot = list.getFirst(); // Note from CJ: I have no idea what this code is supposed to do, so I'm not touching it. /*if (slot.blockId == world.getBlockId(slot.x, slot.y, slot.z)) { diff --git a/common/buildcraft/core/blueprints/BptItem.java b/common/buildcraft/core/blueprints/BptItem.java deleted file mode 100644 index 64215151..00000000 --- a/common/buildcraft/core/blueprints/BptItem.java +++ /dev/null @@ -1,38 +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.core.blueprints; - -import buildcraft.api.blueprints.BptSlotInfo; -import buildcraft.api.blueprints.IBptContext; -import java.util.LinkedList; -import net.minecraft.item.ItemStack; - -public class BptItem { - - public void addRequirements(BptSlotInfo slot, LinkedList requirements) { - - } - - public void rotateLeft(BptSlotInfo slot, IBptContext context) { - - } - - public void buildBlock(BptSlotInfo slot, IBptContext context) { - - } - - public void initializeFromWorld(BptSlotInfo slot, IBptContext context, int x, int y, int z) { - - } - - public void postProcessing(BptSlotInfo slot, IBptContext context) { - - } - -} diff --git a/common/buildcraft/core/blueprints/BptSlot.java b/common/buildcraft/core/blueprints/BptSlot.java deleted file mode 100644 index 471aeaba..00000000 --- a/common/buildcraft/core/blueprints/BptSlot.java +++ /dev/null @@ -1,139 +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.core.blueprints; - -import java.util.ArrayList; -import java.util.LinkedList; - -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import buildcraft.api.blueprints.BlueprintManager; -import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; -import buildcraft.api.blueprints.IBptContext; -import buildcraft.api.blueprints.MappingRegistry; -import buildcraft.core.utils.Utils; - -public class BptSlot extends BptSlotInfo { - - public enum Mode { - ClearIfInvalid, Build - }; - - public Mode mode = Mode.Build; - public ItemStack stackToUse; - - BptBlock bptBlock = null; - - public boolean isValid(IBptContext context) { - return getBpt().isValid(this, context); - } - - public void rotateLeft(IBptContext context) { - getBpt().rotateLeft(this, context); - } - - public boolean ignoreBuilding() { - return getBpt().ignoreBuilding(this); - } - - public void initializeFromWorld(IBptContext context, int xs, int ys, int zs) { - getBpt().initializeFromWorld(this, context, xs, ys, zs); - } - - public void postProcessing(IBptContext context) { - getBpt().postProcessing(this, context); - } - - public LinkedList getRequirements(IBptContext context) { - LinkedList res = new LinkedList(); - - getBpt().addRequirements(this, context, res); - - return res; - } - - public final void buildBlock(IBptContext context) { - getBpt ().buildBlock(this, context); - } - - // returns what was used - public ItemStack useItem(IBptContext context, ItemStack req, ItemStack stack) { - return getBpt().useItem(this, context, req, stack); - } - - @SuppressWarnings("unchecked") - @Override - public BptSlot clone() { - BptSlot obj = new BptSlot(); - - obj.x = x; - obj.y = y; - obj.z = z; - obj.block = block; - obj.meta = meta; - obj.cpt = (NBTTagCompound) cpt.copy(); - obj.storedRequirements = (ArrayList) storedRequirements.clone(); - - if (stackToUse != null) { - obj.stackToUse = stackToUse.copy(); - } - - obj.mode = mode; - - return obj; - } - - public void writeToNBT(NBTTagCompound nbt, MappingRegistry registry) { - nbt.setInteger("blockId", registry.getIdForBlock(block)); - nbt.setInteger("blockMeta", meta); - nbt.setTag("blockCpt", cpt); - - NBTTagList rq = new NBTTagList(); - - for (ItemStack stack : storedRequirements) { - NBTTagCompound sub = new NBTTagCompound(); - stack.writeToNBT(stack.writeToNBT(sub)); - sub.setInteger("id", Item.itemRegistry.getIDForObject(registry - .getItemForId(sub.getInteger("id")))); - rq.appendTag(sub); - } - - nbt.setTag("rq", rq); - } - - public void readFromNBT(NBTTagCompound nbt, MappingRegistry registry) { - - block = registry.getBlockForId(nbt.getInteger("blockId")); - meta = nbt.getInteger("blockMeta"); - cpt = nbt.getCompoundTag("blockCpt"); - - NBTTagList rq = nbt.getTagList("rq", Utils.NBTTag_Types.NBTTagList.ordinal()); - - for (int i = 0; i < rq.tagCount(); ++i) { - NBTTagCompound sub = rq.getCompoundTagAt(i); - - // Maps the id in the blueprint to the id in the world - sub.setInteger("id", Item.itemRegistry.getIDForObject(registry - .getItemForId(sub.getInteger("id")))); - - storedRequirements.add(ItemStack.loadItemStackFromNBT(sub)); - } - } - - public BptBlock getBpt () { - if (bptBlock == null) { - bptBlock = BlueprintManager.getBptBlock(block); - } - - return bptBlock; - } -} diff --git a/common/buildcraft/energy/BptBlockEngine.java b/common/buildcraft/energy/BptBlockEngine.java index b280c1ff..8f1fb2c9 100644 --- a/common/buildcraft/energy/BptBlockEngine.java +++ b/common/buildcraft/energy/BptBlockEngine.java @@ -8,41 +8,35 @@ */ package buildcraft.energy; -import net.minecraft.block.Block; import net.minecraftforge.common.util.ForgeDirection; import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; public class BptBlockEngine extends BptBlock { - public BptBlockEngine(Block block) { - super(block); - } - @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { - int o = slot.cpt.getInteger("orientation"); + public void rotateLeft(IBptContext context) { + int o = cpt.getInteger("orientation"); o = ForgeDirection.values()[o].getRotation(ForgeDirection.DOWN).ordinal(); - slot.cpt.setInteger("orientation", o); + cpt.setInteger("orientation", o); } @Override - public void initializeFromWorld(BptSlotInfo bptSlot, IBptContext context, int x, int y, int z) { + public void initializeFromWorld(IBptContext context, int x, int y, int z) { TileEngine engine = (TileEngine) context.world().getTileEntity(x, y, z); - bptSlot.cpt.setInteger("orientation", engine.orientation.ordinal()); + cpt.setInteger("orientation", engine.orientation.ordinal()); } @Override - public void buildBlock(BptSlotInfo slot, IBptContext context) { - context.world().setBlock(slot.x, slot.y, slot.z, slot.block, slot.meta,1); + public void buildBlock(IBptContext context) { + context.world().setBlock(x, y, z, block, meta,1); - TileEngine engine = (TileEngine) context.world().getTileEntity(slot.x, slot.y, slot.z); + TileEngine engine = (TileEngine) context.world().getTileEntity(x, y, z); - engine.orientation = ForgeDirection.getOrientation(slot.cpt.getInteger("orientation")); + engine.orientation = ForgeDirection.getOrientation(cpt.getInteger("orientation")); } } diff --git a/common/buildcraft/factory/BptBlockAutoWorkbench.java b/common/buildcraft/factory/BptBlockAutoWorkbench.java index 7b8bc156..8e3973e1 100644 --- a/common/buildcraft/factory/BptBlockAutoWorkbench.java +++ b/common/buildcraft/factory/BptBlockAutoWorkbench.java @@ -10,41 +10,35 @@ package buildcraft.factory; import java.util.LinkedList; -import net.minecraft.block.Block; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import buildcraft.api.blueprints.BptBlock; import buildcraft.api.blueprints.BptBlockUtils; -import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; public class BptBlockAutoWorkbench extends BptBlock { - public BptBlockAutoWorkbench(Block block) { - super(block); + @Override + public void addRequirements(IBptContext context, LinkedList requirements) { + super.addRequirements(context, requirements); + + BptBlockUtils.requestInventoryContents(this, context, requirements); } @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - super.addRequirements(slot, context, requirements); - - BptBlockUtils.requestInventoryContents(slot, context, requirements); - } - - @Override - public void initializeFromWorld(BptSlotInfo bptSlot, IBptContext context, int x, int y, int z) { + public void initializeFromWorld(IBptContext context, int x, int y, int z) { IInventory inventory = (IInventory) context.world().getTileEntity(x, y, z); - BptBlockUtils.initializeInventoryContents(bptSlot, context, inventory); + BptBlockUtils.initializeInventoryContents(this, context, inventory); } @Override - public void buildBlock(BptSlotInfo slot, IBptContext context) { - super.buildBlock(slot, context); + public void buildBlock(IBptContext context) { + super.buildBlock(context); - IInventory inventory = (IInventory) context.world().getTileEntity(slot.x, slot.y, slot.z); + IInventory inventory = (IInventory) context.world().getTileEntity(x, y, z); - BptBlockUtils.buildInventoryContents(slot, context, inventory); + BptBlockUtils.buildInventoryContents(this, context, inventory); } } diff --git a/common/buildcraft/factory/BptBlockFrame.java b/common/buildcraft/factory/BptBlockFrame.java index 2bc4d0a7..df22f89f 100644 --- a/common/buildcraft/factory/BptBlockFrame.java +++ b/common/buildcraft/factory/BptBlockFrame.java @@ -10,20 +10,14 @@ package buildcraft.factory; import java.util.LinkedList; -import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; public class BptBlockFrame extends BptBlock { - public BptBlockFrame(Block block) { - super(block); - } - @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { + public void addRequirements(IBptContext context, LinkedList requirements) { } diff --git a/common/buildcraft/factory/BptBlockRefinery.java b/common/buildcraft/factory/BptBlockRefinery.java index d7ec3772..8813fcd1 100644 --- a/common/buildcraft/factory/BptBlockRefinery.java +++ b/common/buildcraft/factory/BptBlockRefinery.java @@ -8,25 +8,19 @@ */ package buildcraft.factory; -import net.minecraft.block.Block; import net.minecraftforge.common.util.ForgeDirection; import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; public class BptBlockRefinery extends BptBlock { - public BptBlockRefinery(Block block) { - super(block); + @Override + public void rotateLeft(IBptContext context) { + meta = ForgeDirection.values()[meta].getRotation(ForgeDirection.DOWN).ordinal(); } @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { - slot.meta = ForgeDirection.values()[slot.meta].getRotation(ForgeDirection.DOWN).ordinal(); - } - - @Override - public void initializeFromWorld(BptSlotInfo slot, IBptContext context, int x, int y, int z) { + public void initializeFromWorld(IBptContext context, int x, int y, int z) { TileRefinery refinery = (TileRefinery) context.world().getTileEntity(x, y, z); // slot.cpt.setInteger("filter0", refinery.getFilter(0)); @@ -34,21 +28,21 @@ public class BptBlockRefinery extends BptBlock { } @Override - public void buildBlock(BptSlotInfo slot, IBptContext context) { - super.buildBlock(slot, context); + public void buildBlock(IBptContext context) { + super.buildBlock(context); - TileRefinery refinery = (TileRefinery) context.world().getTileEntity(slot.x, slot.y, slot.z); + TileRefinery refinery = (TileRefinery) context.world().getTileEntity(x, y, z); - int filter0 = slot.cpt.getInteger("filter0"); - int filter1 = slot.cpt.getInteger("filter1"); + int filter0 = cpt.getInteger("filter0"); + int filter1 = cpt.getInteger("filter1"); int filterMeta0 = 0; int filterMeta1 = 0; - if (slot.cpt.hasKey("filterMeta0")) { - filterMeta0 = slot.cpt.getInteger("filterMeta0"); + if (cpt.hasKey("filterMeta0")) { + filterMeta0 = cpt.getInteger("filterMeta0"); } - if (slot.cpt.hasKey("filterMeta1")) { - filterMeta1 = slot.cpt.getInteger("filterMeta1"); + if (cpt.hasKey("filterMeta1")) { + filterMeta1 = cpt.getInteger("filterMeta1"); } // refinery.setFilter(0, filter0, filterMeta0); diff --git a/common/buildcraft/factory/BptBlockTank.java b/common/buildcraft/factory/BptBlockTank.java index b1ea0acd..718e24c7 100644 --- a/common/buildcraft/factory/BptBlockTank.java +++ b/common/buildcraft/factory/BptBlockTank.java @@ -8,25 +8,19 @@ */ package buildcraft.factory; -import net.minecraft.block.Block; import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; public class BptBlockTank extends BptBlock { - public BptBlockTank(Block block) { - super(block); - } - @Override - public void initializeFromWorld(BptSlotInfo slot, IBptContext context, int x, int y, int z) { + public void initializeFromWorld(IBptContext context, int x, int y, int z) { } @Override - public void buildBlock(BptSlotInfo slot, IBptContext context) { - context.world().setBlock(slot.x, slot.y, slot.z, slot.block, slot.meta,1); + public void buildBlock(IBptContext context) { + context.world().setBlock(x, y, z, block, meta, 3); } } diff --git a/common/buildcraft/transport/blueprints/BptBlockPipe.java b/common/buildcraft/transport/blueprints/BptBlockPipe.java index 04f3b84a..9c1efb99 100644 --- a/common/buildcraft/transport/blueprints/BptBlockPipe.java +++ b/common/buildcraft/transport/blueprints/BptBlockPipe.java @@ -10,12 +10,10 @@ package buildcraft.transport.blueprints; import java.util.LinkedList; -import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; import buildcraft.api.blueprints.IBptContext; import buildcraft.transport.BlockGenericPipe; import buildcraft.transport.Pipe; @@ -23,84 +21,80 @@ import buildcraft.transport.TileGenericPipe.SideProperties; public class BptBlockPipe extends BptBlock { - public BptBlockPipe(Block block) { - super(block); - } - @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - Item pipeItem = context.getMappingRegistry().getItemForId (slot.cpt.getInteger("pipeId")); + public void addRequirements(IBptContext context, LinkedList requirements) { + Item pipeItem = context.getMappingRegistry().getItemForId (cpt.getInteger("pipeId")); requirements.add(new ItemStack(pipeItem)); - requirements.addAll(slot.storedRequirements); + requirements.addAll(storedRequirements); } @Override - public boolean isValid(BptSlotInfo slot, IBptContext context) { - Pipe pipe = BlockGenericPipe.getPipe(context.world(), slot.x, slot.y, slot.z); + public boolean isValid(IBptContext context) { + Pipe pipe = BlockGenericPipe.getPipe(context.world(), x, y, z); if (BlockGenericPipe.isValid(pipe)) { return pipe.item == context.getMappingRegistry().getItemForId( - slot.cpt.getInteger("pipeId")); + cpt.getInteger("pipeId")); } else { return false; } } @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { + public void rotateLeft(IBptContext context) { SideProperties props = new SideProperties (); - props.readFromNBT(slot.cpt); + props.readFromNBT(cpt); props.rotateLeft(); - props.writeToNBT(slot.cpt); + props.writeToNBT(cpt); - Item pipeItem = context.getMappingRegistry().getItemForId(slot.cpt.getInteger("pipeId")); + Item pipeItem = context.getMappingRegistry().getItemForId(cpt.getInteger("pipeId")); if (BptPipeExtension.contains(pipeItem)) { - BptPipeExtension.get(pipeItem).rotateLeft(slot, context); + BptPipeExtension.get(pipeItem).rotateLeft(this, context); } } @Override - public void buildBlock(BptSlotInfo slot, IBptContext context) { - slot.cpt.setInteger("x", slot.x); - slot.cpt.setInteger("y", slot.y); - slot.cpt.setInteger("z", slot.z); - slot.cpt.setInteger( + public void buildBlock(IBptContext context) { + cpt.setInteger("x", x); + cpt.setInteger("y", y); + cpt.setInteger("z", z); + cpt.setInteger( "pipeId", Item.getIdFromItem(context.getMappingRegistry().getItemForId( - slot.cpt.getInteger("pipeId")))); + cpt.getInteger("pipeId")))); - context.world().setBlock(slot.x, slot.y, slot.z, slot.block, slot.meta, 3); + context.world().setBlock(x, y, z, block, meta, 3); - TileEntity tile = context.world().getTileEntity(slot.x, slot.y, slot.z); - tile.readFromNBT(slot.cpt); + TileEntity tile = context.world().getTileEntity(x, y, z); + tile.readFromNBT(cpt); } @Override - public void initializeFromWorld(BptSlotInfo slot, IBptContext context, int x, int y, int z) { + public void initializeFromWorld(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)) { - slot.storedRequirements.addAll(pipe.computeItemDrop ()); + storedRequirements.addAll(pipe.computeItemDrop ()); - tile.writeToNBT(slot.cpt); + tile.writeToNBT(cpt); // This overrides the default pipeId - slot.cpt.setInteger("pipeId", context.getMappingRegistry() + cpt.setInteger("pipeId", context.getMappingRegistry() .getIdForItem(pipe.item)); } } @Override - public void postProcessing(BptSlotInfo slot, IBptContext context) { - Item pipeItem = context.getMappingRegistry().getItemForId(slot.cpt.getInteger("pipeId")); + public void postProcessing(IBptContext context) { + Item pipeItem = context.getMappingRegistry().getItemForId(cpt.getInteger("pipeId")); if (BptPipeExtension.contains(pipeItem)) { - BptPipeExtension.get(pipeItem).postProcessing(slot, context); + BptPipeExtension.get(pipeItem).postProcessing(this, context); } } } diff --git a/common/buildcraft/transport/blueprints/BptItemPipeFilters.java b/common/buildcraft/transport/blueprints/BptItemPipeFilters.java index 259ec928..cbe87545 100644 --- a/common/buildcraft/transport/blueprints/BptItemPipeFilters.java +++ b/common/buildcraft/transport/blueprints/BptItemPipeFilters.java @@ -10,7 +10,7 @@ package buildcraft.transport.blueprints; import net.minecraft.item.Item; import net.minecraftforge.common.util.ForgeDirection; -import buildcraft.api.blueprints.BptSlotInfo; +import buildcraft.api.blueprints.BptBlock; import buildcraft.api.blueprints.IBptContext; import buildcraft.core.inventory.SimpleInventory; @@ -22,7 +22,7 @@ public class BptItemPipeFilters extends BptPipeExtension { @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { + public void rotateLeft(BptBlock slot, IBptContext context) { SimpleInventory inv = new SimpleInventory(54, "Filters", 1); SimpleInventory newInv = new SimpleInventory(54, "Filters", 1); inv.readFromNBT(slot.cpt); diff --git a/common/buildcraft/transport/blueprints/BptPipeExtension.java b/common/buildcraft/transport/blueprints/BptPipeExtension.java index c965c4e9..5e17bff4 100755 --- a/common/buildcraft/transport/blueprints/BptPipeExtension.java +++ b/common/buildcraft/transport/blueprints/BptPipeExtension.java @@ -3,7 +3,7 @@ package buildcraft.transport.blueprints; import java.util.HashMap; import net.minecraft.item.Item; -import buildcraft.api.blueprints.BptSlotInfo; +import buildcraft.api.blueprints.BptBlock; import buildcraft.api.blueprints.IBptContext; public class BptPipeExtension { @@ -14,11 +14,11 @@ public class BptPipeExtension { bptPipeExtensionRegistry.put(i, this); } - public void postProcessing(BptSlotInfo slot, IBptContext context) { + public void postProcessing(BptBlock slot, IBptContext context) { } - public void rotateLeft(BptSlotInfo slot, IBptContext context) { + public void rotateLeft(BptBlock slot, IBptContext context) { } diff --git a/common/buildcraft/transport/blueprints/BptPipeIron.java b/common/buildcraft/transport/blueprints/BptPipeIron.java index bb91d602..4e079e61 100644 --- a/common/buildcraft/transport/blueprints/BptPipeIron.java +++ b/common/buildcraft/transport/blueprints/BptPipeIron.java @@ -10,7 +10,7 @@ package buildcraft.transport.blueprints; import net.minecraft.item.Item; import net.minecraftforge.common.util.ForgeDirection; -import buildcraft.api.blueprints.BptSlotInfo; +import buildcraft.api.blueprints.BptBlock; import buildcraft.api.blueprints.IBptContext; public class BptPipeIron extends BptPipeExtension { @@ -20,7 +20,7 @@ public class BptPipeIron extends BptPipeExtension { } @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { + public void rotateLeft(BptBlock slot, IBptContext context) { int orientation = slot.meta & 7; int others = slot.meta - orientation; diff --git a/common/buildcraft/transport/blueprints/BptPipeWooden.java b/common/buildcraft/transport/blueprints/BptPipeWooden.java index 2c102223..22d2874d 100644 --- a/common/buildcraft/transport/blueprints/BptPipeWooden.java +++ b/common/buildcraft/transport/blueprints/BptPipeWooden.java @@ -10,7 +10,7 @@ package buildcraft.transport.blueprints; import net.minecraft.item.Item; import net.minecraftforge.common.util.ForgeDirection; -import buildcraft.api.blueprints.BptSlotInfo; +import buildcraft.api.blueprints.BptBlock; import buildcraft.api.blueprints.IBptContext; public class BptPipeWooden extends BptPipeExtension { @@ -20,7 +20,7 @@ public class BptPipeWooden extends BptPipeExtension { } @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { + public void rotateLeft(BptBlock slot, IBptContext context) { int orientation = slot.meta & 7; int others = slot.meta - orientation;