From 7edc5a9308051484b7853493d6ca10dd8baf3fd5 Mon Sep 17 00:00:00 2001 From: asiekierka Date: Sun, 20 Sep 2015 13:06:43 +0200 Subject: [PATCH] fix #2967, fix blueprint placement issues, improve block schematic heuristics --- common/buildcraft/BuildCraftBuilders.java | 39 +----------- .../builders/HeuristicBlockDetection.java | 13 +++- .../builders/LibraryBlueprintTypeHandler.java | 4 +- .../builders/schematics/SchematicLever.java | 23 -------- .../schematics/SchematicSilverfish.java | 59 +++++++++++++++++++ .../core/blueprints/BptBuilderBlueprint.java | 6 +- .../core/blueprints/IndexRequirementMap.java | 1 + .../schematics/SchematicStandalone.java | 20 ------- .../schematics/SchematicWallSide.java | 12 ++-- .../pluggable/PowerAdapterPluggable.java | 2 +- 10 files changed, 87 insertions(+), 92 deletions(-) delete mode 100644 common/buildcraft/builders/schematics/SchematicLever.java create mode 100755 common/buildcraft/builders/schematics/SchematicSilverfish.java delete mode 100755 common/buildcraft/core/builders/schematics/SchematicStandalone.java diff --git a/common/buildcraft/BuildCraftBuilders.java b/common/buildcraft/BuildCraftBuilders.java index 788f8544..6141dcd5 100644 --- a/common/buildcraft/BuildCraftBuilders.java +++ b/common/buildcraft/BuildCraftBuilders.java @@ -105,7 +105,6 @@ import buildcraft.builders.schematics.SchematicFire; import buildcraft.builders.schematics.SchematicGlassPane; import buildcraft.builders.schematics.SchematicGravel; import buildcraft.builders.schematics.SchematicHanging; -import buildcraft.builders.schematics.SchematicLever; import buildcraft.builders.schematics.SchematicMinecart; import buildcraft.builders.schematics.SchematicPiston; import buildcraft.builders.schematics.SchematicPortal; @@ -119,6 +118,7 @@ import buildcraft.builders.schematics.SchematicSign; import buildcraft.builders.schematics.SchematicSkull; import buildcraft.builders.schematics.SchematicStairs; import buildcraft.builders.schematics.SchematicStone; +import buildcraft.builders.schematics.SchematicSilverfish; import buildcraft.builders.schematics.SchematicTripWireHook; import buildcraft.builders.statements.BuildersActionProvider; import buildcraft.core.CompatHooks; @@ -134,9 +134,7 @@ import buildcraft.core.builders.schematics.SchematicFree; import buildcraft.core.builders.schematics.SchematicIgnore; import buildcraft.core.builders.schematics.SchematicRotateMeta; import buildcraft.core.builders.schematics.SchematicRotateMetaSupported; -import buildcraft.core.builders.schematics.SchematicStandalone; import buildcraft.core.builders.schematics.SchematicTileCreative; -import buildcraft.core.builders.schematics.SchematicWallSide; import buildcraft.core.config.ConfigManager; import buildcraft.core.proxy.CoreProxy; @@ -365,10 +363,6 @@ public class BuildCraftBuilders extends BuildCraftMod { schemes.registerSchematicBlock(Blocks.melon_stem, SchematicSeeds.class, Items.melon_seeds); schemes.registerSchematicBlock(Blocks.nether_wart, SchematicSeeds.class, Items.nether_wart); - schemes.registerSchematicBlock(Blocks.torch, SchematicWallSide.class); - schemes.registerSchematicBlock(Blocks.redstone_torch, SchematicWallSide.class); - schemes.registerSchematicBlock(Blocks.unlit_redstone_torch, SchematicWallSide.class); - schemes.registerSchematicBlock(Blocks.tripwire, SchematicBlockFloored.class); schemes.registerSchematicBlock(Blocks.tripwire_hook, SchematicTripWireHook.class); @@ -395,13 +389,7 @@ public class BuildCraftBuilders extends BuildCraftMod { schemes.registerSchematicBlock(Blocks.vine, SchematicRotateMeta.class, new int[]{1, 4, 8, 2}, false); schemes.registerSchematicBlock(Blocks.trapdoor, SchematicRotateMeta.class, new int[]{0, 1, 2, 3}, false); - schemes.registerSchematicBlock(Blocks.wooden_button, SchematicLever.class); - schemes.registerSchematicBlock(Blocks.stone_button, SchematicLever.class); - schemes.registerSchematicBlock(Blocks.lever, SchematicLever.class); - schemes.registerSchematicBlock(Blocks.stone, SchematicStone.class); - schemes.registerSchematicBlock(Blocks.gold_ore, SchematicStone.class); - schemes.registerSchematicBlock(Blocks.iron_ore, SchematicStone.class); schemes.registerSchematicBlock(Blocks.coal_ore, SchematicStone.class); schemes.registerSchematicBlock(Blocks.lapis_ore, SchematicStone.class); schemes.registerSchematicBlock(Blocks.diamond_ore, SchematicStone.class); @@ -409,6 +397,8 @@ public class BuildCraftBuilders extends BuildCraftMod { schemes.registerSchematicBlock(Blocks.lit_redstone_ore, SchematicStone.class); schemes.registerSchematicBlock(Blocks.emerald_ore, SchematicStone.class); + schemes.registerSchematicBlock(Blocks.monster_egg, SchematicSilverfish.class); + schemes.registerSchematicBlock(Blocks.gravel, SchematicGravel.class); schemes.registerSchematicBlock(Blocks.redstone_wire, SchematicRedstoneWire.class, new ItemStack(Items.redstone)); @@ -432,19 +422,6 @@ public class BuildCraftBuilders extends BuildCraftMod { schemes.registerSchematicBlock(Blocks.lit_pumpkin, SchematicPumpkin.class); - schemes.registerSchematicBlock(Blocks.oak_stairs, SchematicStairs.class); - schemes.registerSchematicBlock(Blocks.stone_stairs, SchematicStairs.class); - schemes.registerSchematicBlock(Blocks.brick_stairs, SchematicStairs.class); - schemes.registerSchematicBlock(Blocks.stone_brick_stairs, SchematicStairs.class); - schemes.registerSchematicBlock(Blocks.nether_brick_stairs, SchematicStairs.class); - schemes.registerSchematicBlock(Blocks.sandstone_stairs, SchematicStairs.class); - schemes.registerSchematicBlock(Blocks.spruce_stairs, SchematicStairs.class); - schemes.registerSchematicBlock(Blocks.birch_stairs, SchematicStairs.class); - schemes.registerSchematicBlock(Blocks.jungle_stairs, SchematicStairs.class); - schemes.registerSchematicBlock(Blocks.quartz_stairs, SchematicStairs.class); - schemes.registerSchematicBlock(Blocks.acacia_stairs, SchematicStairs.class); - schemes.registerSchematicBlock(Blocks.dark_oak_stairs, SchematicStairs.class); - schemes.registerSchematicBlock(Blocks.wooden_door, SchematicDoor.class, new ItemStack(Items.wooden_door)); schemes.registerSchematicBlock(Blocks.iron_door, SchematicDoor.class, new ItemStack(Items.iron_door)); @@ -466,16 +443,6 @@ public class BuildCraftBuilders extends BuildCraftMod { schemes.registerSchematicBlock(Blocks.mob_spawner, SchematicTileCreative.class); - schemes.registerSchematicBlock(Blocks.glass, SchematicStandalone.class); - schemes.registerSchematicBlock(Blocks.stone_slab, SchematicStandalone.class); - schemes.registerSchematicBlock(Blocks.double_stone_slab, SchematicStandalone.class); - schemes.registerSchematicBlock(Blocks.wooden_slab, SchematicStandalone.class); - schemes.registerSchematicBlock(Blocks.double_wooden_slab, SchematicStandalone.class); - schemes.registerSchematicBlock(Blocks.stained_glass, SchematicStandalone.class); - schemes.registerSchematicBlock(Blocks.fence, SchematicStandalone.class); - schemes.registerSchematicBlock(Blocks.daylight_detector, SchematicStandalone.class); - schemes.registerSchematicBlock(Blocks.iron_bars, SchematicStandalone.class); - // Standard entities schemes.registerSchematicEntity(EntityMinecartEmpty.class, SchematicMinecart.class, Items.minecart); diff --git a/common/buildcraft/builders/HeuristicBlockDetection.java b/common/buildcraft/builders/HeuristicBlockDetection.java index 952272f4..4ca1fcd2 100644 --- a/common/buildcraft/builders/HeuristicBlockDetection.java +++ b/common/buildcraft/builders/HeuristicBlockDetection.java @@ -3,7 +3,12 @@ package buildcraft.builders; import java.util.Iterator; import net.minecraft.block.Block; +import net.minecraft.block.BlockBasePressurePlate; import net.minecraft.block.BlockBush; +import net.minecraft.block.BlockButton; +import net.minecraft.block.BlockLever; +import net.minecraft.block.BlockStairs; +import net.minecraft.block.BlockTorch; import net.minecraft.block.IGrowable; import net.minecraft.init.Blocks; @@ -13,9 +18,11 @@ import net.minecraftforge.fluids.IFluidBlock; import buildcraft.api.blueprints.SchematicBlock; import buildcraft.api.blueprints.SchematicFluid; +import buildcraft.builders.schematics.SchematicStairs; import buildcraft.core.blueprints.SchematicRegistry; import buildcraft.core.builders.schematics.SchematicBlockFloored; import buildcraft.core.builders.schematics.SchematicTileCreative; +import buildcraft.core.builders.schematics.SchematicWallSide; public final class HeuristicBlockDetection { private HeuristicBlockDetection() { @@ -47,8 +54,12 @@ public final class HeuristicBlockDetection { SchematicRegistry.INSTANCE.registerSchematicBlock(block, meta, SchematicFluid.class, new FluidStack(fblock.getFluid(), 1000)); } } else { - if (block instanceof BlockBush || block instanceof IPlantable || block instanceof IGrowable) { + if (block instanceof BlockBush || block instanceof IPlantable || block instanceof IGrowable || block instanceof BlockBasePressurePlate) { SchematicRegistry.INSTANCE.registerSchematicBlock(block, meta, SchematicBlockFloored.class); + } else if (block instanceof BlockLever || block instanceof BlockTorch || block instanceof BlockButton) { + SchematicRegistry.INSTANCE.registerSchematicBlock(block, meta, SchematicWallSide.class); + } else if (block instanceof BlockStairs) { + SchematicRegistry.INSTANCE.registerSchematicBlock(block, meta, SchematicStairs.class); } else { SchematicRegistry.INSTANCE.registerSchematicBlock(block, meta, SchematicBlock.class); } diff --git a/common/buildcraft/builders/LibraryBlueprintTypeHandler.java b/common/buildcraft/builders/LibraryBlueprintTypeHandler.java index 273dd9ed..f8f38cbf 100644 --- a/common/buildcraft/builders/LibraryBlueprintTypeHandler.java +++ b/common/buildcraft/builders/LibraryBlueprintTypeHandler.java @@ -19,9 +19,9 @@ public class LibraryBlueprintTypeHandler extends LibraryTypeHandlerNBT { @Override public boolean isHandler(ItemStack stack, HandlerType type) { if (isBlueprint) { - return stack.getItem() instanceof ItemBlueprintStandard && ItemBlueprint.isContentReadable(stack); + return stack.getItem() instanceof ItemBlueprintStandard && (type == HandlerType.LOAD || ItemBlueprint.isContentReadable(stack)); } else { - return stack.getItem() instanceof ItemBlueprintTemplate && ItemBlueprint.isContentReadable(stack); + return stack.getItem() instanceof ItemBlueprintTemplate && (type == HandlerType.LOAD || ItemBlueprint.isContentReadable(stack)); } } diff --git a/common/buildcraft/builders/schematics/SchematicLever.java b/common/buildcraft/builders/schematics/SchematicLever.java deleted file mode 100644 index fd647d63..00000000 --- a/common/buildcraft/builders/schematics/SchematicLever.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright (c) 2011-2015, 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.builders.schematics; - -import buildcraft.api.blueprints.IBuilderContext; -import buildcraft.core.builders.schematics.SchematicWallSide; - -public class SchematicLever extends SchematicWallSide { - @Override - public void rotateLeft(IBuilderContext context) { - int status = meta & 8; - - meta -= status; - super.rotateLeft(context); - meta += status; - } -} diff --git a/common/buildcraft/builders/schematics/SchematicSilverfish.java b/common/buildcraft/builders/schematics/SchematicSilverfish.java new file mode 100755 index 00000000..6a1e7453 --- /dev/null +++ b/common/buildcraft/builders/schematics/SchematicSilverfish.java @@ -0,0 +1,59 @@ +/** + * Copyright (c) 2011-2015, 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.builders.schematics; + +import java.util.LinkedList; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; + +import buildcraft.api.blueprints.IBuilderContext; +import buildcraft.api.blueprints.SchematicBlock; + +public class SchematicSilverfish extends SchematicBlock { + private Block getRealBlock() { + if (meta == 0) { + return Blocks.stone; + } else if (meta == 1) { + return Blocks.cobblestone; + } else if (meta <= 5) { + return Blocks.stonebrick; + } else { + return Blocks.stone; + } + } + + private int getRealMetadata() { + if (meta >= 2 && meta <= 5) { + return meta - 2; + } + return 0; + } + + @Override + public void getRequirementsForPlacement(IBuilderContext context, LinkedList requirements) { + requirements.add(new ItemStack(getRealBlock(), 0, getRealMetadata())); + } + + @Override + public void storeRequirements(IBuilderContext context, int x, int y, int z) { + + } + + @Override + public void placeInWorld(IBuilderContext context, int x, int y, int z, LinkedList stacks) { + context.world().setBlock(x, y, z, getRealBlock(), getRealMetadata(), 3); + } + + @Override + public boolean isAlreadyBuilt(IBuilderContext context, int x, int y, int z) { + return context.world().getBlock(x, y, z) == getRealBlock() && context.world().getBlockMetadata(x, y, z) == getRealMetadata(); + } +} diff --git a/common/buildcraft/core/blueprints/BptBuilderBlueprint.java b/common/buildcraft/core/blueprints/BptBuilderBlueprint.java index 5bfdf6b3..35c42926 100644 --- a/common/buildcraft/core/blueprints/BptBuilderBlueprint.java +++ b/common/buildcraft/core/blueprints/BptBuilderBlueprint.java @@ -378,9 +378,9 @@ public class BptBuilderBlueprint extends BptBuilderBase { try { if (slot.isAlreadyBuilt(context)) { - requirementMap.remove(slot); - if (slot.mode == Mode.Build) { + requirementMap.remove(slot); + // Even slots that considered already built may need // post processing calls. For example, flowing water // may need to be adjusted, engines may need to be @@ -404,7 +404,6 @@ public class BptBuilderBlueprint extends BptBuilderBase { || isBlockBreakCanceled(world, slot.x, slot.y, slot.z)) { iterator.remove(); markLocationUsed(slot.x, slot.y, slot.z); - requirementMap.remove(slot); } else { if (builder == null) { createDestroyItems(slot); @@ -415,7 +414,6 @@ public class BptBuilderBlueprint extends BptBuilderBase { iterator.remove(); markLocationUsed(slot.x, slot.y, slot.z); - requirementMap.remove(slot); return slot; } } diff --git a/common/buildcraft/core/blueprints/IndexRequirementMap.java b/common/buildcraft/core/blueprints/IndexRequirementMap.java index 1842cabf..ea6bf2c2 100644 --- a/common/buildcraft/core/blueprints/IndexRequirementMap.java +++ b/common/buildcraft/core/blueprints/IndexRequirementMap.java @@ -7,6 +7,7 @@ import com.google.common.collect.Multimap; import buildcraft.api.blueprints.IBuilderContext; import buildcraft.api.blueprints.SchematicBlock; +import buildcraft.api.core.BCLog; import buildcraft.api.core.BlockIndex; import buildcraft.api.core.Position; import buildcraft.core.builders.BuildingSlotBlock; diff --git a/common/buildcraft/core/builders/schematics/SchematicStandalone.java b/common/buildcraft/core/builders/schematics/SchematicStandalone.java deleted file mode 100755 index 8f7b5604..00000000 --- a/common/buildcraft/core/builders/schematics/SchematicStandalone.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright (c) 2011-2015, 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.builders.schematics; - -import buildcraft.api.blueprints.SchematicBlock; - -public class SchematicStandalone extends SchematicBlock { - - @Override - public BuildingStage getBuildStage() { - return BuildingStage.STANDALONE; - } - -} diff --git a/common/buildcraft/core/builders/schematics/SchematicWallSide.java b/common/buildcraft/core/builders/schematics/SchematicWallSide.java index 26718186..ee60e0f1 100644 --- a/common/buildcraft/core/builders/schematics/SchematicWallSide.java +++ b/common/buildcraft/core/builders/schematics/SchematicWallSide.java @@ -34,8 +34,10 @@ public class SchematicWallSide extends SchematicBlock { case xNeg: return Sets.newHashSet(RELATIVE_INDEXES[ForgeDirection.WEST.ordinal()]); case yPos: + case 7: return Sets.newHashSet(RELATIVE_INDEXES[ForgeDirection.UP.ordinal()]); case yNeg: + case 6: return Sets.newHashSet(RELATIVE_INDEXES[ForgeDirection.DOWN.ordinal()]); case zPos: return Sets.newHashSet(RELATIVE_INDEXES[ForgeDirection.SOUTH.ordinal()]); @@ -52,18 +54,18 @@ public class SchematicWallSide extends SchematicBlock { final int zPos = 4; final int zNeg = 3; - switch (meta) { + switch (meta & 7) { case xPos: - meta = zPos; + meta = (meta & 8) | zPos; break; case zNeg: - meta = xPos; + meta = (meta & 8) | xPos; break; case xNeg: - meta = zNeg; + meta = (meta & 8) | zNeg; break; case zPos: - meta = xNeg; + meta = (meta & 8) | xNeg; break; } } diff --git a/common/buildcraft/transport/pluggable/PowerAdapterPluggable.java b/common/buildcraft/transport/pluggable/PowerAdapterPluggable.java index bffd045f..962ef6b3 100644 --- a/common/buildcraft/transport/pluggable/PowerAdapterPluggable.java +++ b/common/buildcraft/transport/pluggable/PowerAdapterPluggable.java @@ -152,7 +152,7 @@ public class PowerAdapterPluggable extends PipePluggable implements IEnergyHandl @Override public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) { int maxR = Math.min(MAX_POWER, maxReceive); - if (container.getPipe() instanceof IEnergyHandler) { + if (container != null && container.getPipe() instanceof IEnergyHandler) { int energyCanReceive = ((IEnergyHandler) container.getPipe()).receiveEnergy(from, maxR, true); if (!simulate) { return ((IEnergyHandler) container.getPipe()).receiveEnergy(from, energyCanReceive, false);