From 76e01f100508a324a6f7c2216e3ee9f85285eca8 Mon Sep 17 00:00:00 2001 From: Hea3veN Date: Wed, 4 Feb 2015 23:48:18 -0300 Subject: [PATCH] add builder support for most of the blocks in the factory module, fixes #2430 --- common/buildcraft/BuildCraftBuilders.java | 1 + common/buildcraft/BuildCraftFactory.java | 10 ++- .../schematics/SchematicAutoWorkbench.java | 82 +++++++++++++++++++ ...ank.java => SchematicTileIgnoreState.java} | 2 +- 4 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 common/buildcraft/factory/schematics/SchematicAutoWorkbench.java rename common/buildcraft/factory/schematics/{SchematicTank.java => SchematicTileIgnoreState.java} (94%) diff --git a/common/buildcraft/BuildCraftBuilders.java b/common/buildcraft/BuildCraftBuilders.java index d0ef0b3c..133b755d 100644 --- a/common/buildcraft/BuildCraftBuilders.java +++ b/common/buildcraft/BuildCraftBuilders.java @@ -324,6 +324,7 @@ public class BuildCraftBuilders extends BuildCraftMod { schemes.registerSchematicBlock(Blocks.furnace, SchematicRotateMeta.class, new int[]{2, 5, 3, 4}, true); schemes.registerSchematicBlock(Blocks.lit_furnace, SchematicRotateMeta.class, new int[]{2, 5, 3, 4}, true); schemes.registerSchematicBlock(Blocks.chest, SchematicRotateMeta.class, new int[]{2, 5, 3, 4}, true); + schemes.registerSchematicBlock(Blocks.trapped_chest, SchematicRotateMeta.class, new int[]{2, 5, 3, 4}, true); schemes.registerSchematicBlock(Blocks.dispenser, SchematicRotateMeta.class, new int[]{2, 5, 3, 4}, true); schemes.registerSchematicBlock(Blocks.dropper, SchematicRotateMeta.class, new int[]{2, 5, 3, 4}, true); diff --git a/common/buildcraft/BuildCraftFactory.java b/common/buildcraft/BuildCraftFactory.java index 2b322046..c690b365 100644 --- a/common/buildcraft/BuildCraftFactory.java +++ b/common/buildcraft/BuildCraftFactory.java @@ -37,6 +37,7 @@ import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Property; import buildcraft.api.blueprints.BuilderAPI; +import buildcraft.api.blueprints.SchematicTile; import buildcraft.builders.schematics.SchematicIgnoreMeta; import buildcraft.compat.CompatHooks; import buildcraft.core.DefaultProps; @@ -68,9 +69,10 @@ import buildcraft.factory.TileQuarry; import buildcraft.factory.TileRefinery; import buildcraft.factory.TileTank; import buildcraft.factory.network.PacketHandlerFactory; +import buildcraft.factory.schematics.SchematicAutoWorkbench; import buildcraft.factory.schematics.SchematicPump; import buildcraft.factory.schematics.SchematicRefinery; -import buildcraft.factory.schematics.SchematicTank; +import buildcraft.factory.schematics.SchematicTileIgnoreState; @Mod(name = "BuildCraft Factory", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Factory", dependencies = DefaultProps.DEPENDENCY_CORE) public class BuildCraftFactory extends BuildCraftMod { @@ -160,9 +162,13 @@ public class BuildCraftFactory extends BuildCraftMod { FactoryProxy.proxy.initializeTileEntities(); BuilderAPI.schematicRegistry.registerSchematicBlock(refineryBlock, SchematicRefinery.class); - BuilderAPI.schematicRegistry.registerSchematicBlock(tankBlock, SchematicTank.class); + BuilderAPI.schematicRegistry.registerSchematicBlock(tankBlock, SchematicTileIgnoreState.class); BuilderAPI.schematicRegistry.registerSchematicBlock(frameBlock, SchematicIgnoreMeta.class); BuilderAPI.schematicRegistry.registerSchematicBlock(pumpBlock, SchematicPump.class); + BuilderAPI.schematicRegistry.registerSchematicBlock(miningWellBlock, SchematicTileIgnoreState.class); + BuilderAPI.schematicRegistry.registerSchematicBlock(floodGateBlock, SchematicTileIgnoreState.class); + BuilderAPI.schematicRegistry.registerSchematicBlock(autoWorkbenchBlock, SchematicAutoWorkbench.class); + BuilderAPI.schematicRegistry.registerSchematicBlock(hopperBlock, SchematicTile.class); if (BuildCraftCore.loadDefaultRecipes) { loadRecipes(); diff --git a/common/buildcraft/factory/schematics/SchematicAutoWorkbench.java b/common/buildcraft/factory/schematics/SchematicAutoWorkbench.java new file mode 100644 index 00000000..65c5ae78 --- /dev/null +++ b/common/buildcraft/factory/schematics/SchematicAutoWorkbench.java @@ -0,0 +1,82 @@ +/** + * 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.factory.schematics; + +import java.util.ArrayList; +import java.util.LinkedList; + +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import buildcraft.BuildCraftFactory; +import buildcraft.api.blueprints.IBuilderContext; +import buildcraft.api.blueprints.SchematicTile; +import buildcraft.api.core.IInvSlot; +import buildcraft.api.core.JavaTools; +import buildcraft.core.inventory.InventoryIterator; +import buildcraft.factory.TileAutoWorkbench; + +public class SchematicAutoWorkbench extends SchematicTile { + + @Override + public void storeRequirements(IBuilderContext context, int x, int y, int z) { + TileAutoWorkbench autoWb = getTile(context, x, y, z); + if (autoWb != null) { + ArrayList rqs = new ArrayList(); + rqs.add(new ItemStack(BuildCraftFactory.autoWorkbenchBlock)); + + for (IInvSlot slot : InventoryIterator.getIterable(autoWb.craftMatrix, ForgeDirection.UP)) { + ItemStack stack = slot.getStackInSlot(); + if (stack != null) { + stack = stack.copy(); + stack.stackSize = 1; + rqs.add(stack); + } + } + + storedRequirements = JavaTools.concat(storedRequirements, rqs + .toArray(new ItemStack[rqs.size()])); + } + } + + @Override + public void initializeFromObjectAt(IBuilderContext context, int x, int y, int z) { + super.initializeFromObjectAt(context, x, y, z); + + tileNBT.removeTag("Items"); + } + + @Override + public void placeInWorld(IBuilderContext context, int x, int y, int z, LinkedList stacks) { + super.placeInWorld(context, x, y, z, stacks); + + TileAutoWorkbench autoWb = getTile(context, x, y, z); + if (autoWb != null) { + for (IInvSlot slot : InventoryIterator.getIterable(autoWb.craftMatrix, ForgeDirection.UP)) { + ItemStack stack = slot.getStackInSlot(); + if (stack != null) { + stack.stackSize = 1; + } + } + } + } + + @Override + public BuildingStage getBuildStage() { + return BuildingStage.STANDALONE; + } + + private TileAutoWorkbench getTile(IBuilderContext context, int x, int y, int z) { + TileEntity tile = context.world().getTileEntity(x, y, z); + if (tile != null && tile instanceof TileAutoWorkbench) { + return (TileAutoWorkbench) tile; + } + return null; + } +} diff --git a/common/buildcraft/factory/schematics/SchematicTank.java b/common/buildcraft/factory/schematics/SchematicTileIgnoreState.java similarity index 94% rename from common/buildcraft/factory/schematics/SchematicTank.java rename to common/buildcraft/factory/schematics/SchematicTileIgnoreState.java index 2207aa7a..cf6ebcc0 100644 --- a/common/buildcraft/factory/schematics/SchematicTank.java +++ b/common/buildcraft/factory/schematics/SchematicTileIgnoreState.java @@ -15,7 +15,7 @@ import net.minecraft.item.ItemStack; import buildcraft.api.blueprints.IBuilderContext; import buildcraft.api.blueprints.SchematicTile; -public class SchematicTank extends SchematicTile { +public class SchematicTileIgnoreState extends SchematicTile { @Override public void getRequirementsForPlacement(IBuilderContext context, LinkedList requirements) {