From 91b8b8df83d7d25fa89c347cc0074107add46417 Mon Sep 17 00:00:00 2001 From: Adrian Date: Fri, 11 Sep 2015 20:20:49 +0200 Subject: [PATCH] fix #2565, clean up, filler/builder improvements --- .../api/blueprints/SchematicMask.java | 18 ++++-- buildcraft_resources/changelog/7.0.23 | 10 ++++ common/buildcraft/BuildCraftCore.java | 5 +- common/buildcraft/builders/TileFiller.java | 10 ---- .../core/builders/BuildingItem.java | 27 +++++---- .../core/builders/BuildingSlot.java | 4 +- .../core/builders/BuildingSlotBlock.java | 21 +++++-- .../core/builders/BuildingSlotEntity.java | 3 +- .../WorldPropertyIsReplaceable.java | 21 +++++++ common/buildcraft/factory/TileRefinery.java | 59 +------------------ .../factory/gui/ContainerRefinery.java | 4 +- .../buildcraft/factory/gui/GuiRefinery.java | 8 +-- 12 files changed, 89 insertions(+), 101 deletions(-) create mode 100755 common/buildcraft/core/properties/WorldPropertyIsReplaceable.java diff --git a/api/buildcraft/api/blueprints/SchematicMask.java b/api/buildcraft/api/blueprints/SchematicMask.java index e05e6360..788b83d1 100755 --- a/api/buildcraft/api/blueprints/SchematicMask.java +++ b/api/buildcraft/api/blueprints/SchematicMask.java @@ -10,11 +10,14 @@ package buildcraft.api.blueprints; import java.util.LinkedList; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.WorldServer; +import net.minecraftforge.common.util.ForgeDirection; + import buildcraft.api.core.BuildCraftAPI; public class SchematicMask extends SchematicBlockBase { @@ -36,14 +39,19 @@ public class SchematicMask extends SchematicBlockBase { return; } else { ItemStack stack = stacks.getFirst(); + EntityPlayer player = BuildCraftAPI.proxy.getBuildCraftPlayer((WorldServer) context.world()).get(); // force the block to be air block, in case it's just a soft // block which replacement is not straightforward context.world().setBlock(x, y, z, Blocks.air, 0, 3); - stack.tryPlaceItemIntoWorld( - BuildCraftAPI.proxy.getBuildCraftPlayer((WorldServer) context.world()).get(), - context.world(), x, y, z, 1, 0.0f, 0.0f, 0.0f); + // Find nearest solid surface to place on + ForgeDirection dir = ForgeDirection.DOWN; + while (dir != ForgeDirection.UNKNOWN && BuildCraftAPI.isSoftBlock(context.world(), x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ)) { + dir = ForgeDirection.getOrientation(dir.ordinal() + 1); + } + + stack.tryPlaceItemIntoWorld(player, context.world(), x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ, dir.getOpposite().ordinal(), 0.0f, 0.0f, 0.0f); } } else { context.world().setBlock(x, y, z, Blocks.air, 0, 3); @@ -53,9 +61,9 @@ public class SchematicMask extends SchematicBlockBase { @Override public boolean isAlreadyBuilt(IBuilderContext context, int x, int y, int z) { if (isConcrete) { - return !BuildCraftAPI.isSoftBlock(context.world(), x, y, z); + return !BuildCraftAPI.getWorldProperty("replaceable").get(context.world(), x, y, z); } else { - return BuildCraftAPI.isSoftBlock(context.world(), x, y, z); + return BuildCraftAPI.getWorldProperty("replaceable").get(context.world(), x, y, z); } } diff --git a/buildcraft_resources/changelog/7.0.23 b/buildcraft_resources/changelog/7.0.23 index 6c8e2bad..d578295d 100644 --- a/buildcraft_resources/changelog/7.0.23 +++ b/buildcraft_resources/changelog/7.0.23 @@ -1,3 +1,13 @@ +Improvements: + +* Architect Tables are less server-intensive now (asie) +* More Ore Dictionary support for recipes (Adaptivity) + Bugs fixed: +* [#3008] Rare crash on strange Minecraft world in MapChunk (asie) +* [#3007] "Energy Stored" trigger has incorrect behaviour (asie) * [#3001] NPE in RobotStationPluggableRenderer (asie) +* [#2922, #2975] Composite blueprints not working (asie) +* [#2565] Fillers not liking certain blocks (asie) +* Fillers and Builders not dropping item on inability to place (asie) diff --git a/common/buildcraft/BuildCraftCore.java b/common/buildcraft/BuildCraftCore.java index aba26311..1dfabf3a 100644 --- a/common/buildcraft/BuildCraftCore.java +++ b/common/buildcraft/BuildCraftCore.java @@ -45,7 +45,6 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.client.event.TextureStitchEvent; -import net.minecraftforge.common.IPlantable; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.fluids.BlockFluidBase; @@ -131,6 +130,7 @@ import buildcraft.core.properties.WorldPropertyIsFluidSource; import buildcraft.core.properties.WorldPropertyIsHarvestable; import buildcraft.core.properties.WorldPropertyIsLeaf; import buildcraft.core.properties.WorldPropertyIsOre; +import buildcraft.core.properties.WorldPropertyIsReplaceable; import buildcraft.core.properties.WorldPropertyIsShoveled; import buildcraft.core.properties.WorldPropertyIsSoft; import buildcraft.core.properties.WorldPropertyIsWood; @@ -463,7 +463,7 @@ public class BuildCraftCore extends BuildCraftMod { for (Object o : Block.blockRegistry) { Block block = (Block) o; - if (block instanceof BlockFluidBase || block instanceof BlockLiquid || block instanceof IPlantable) { + if (block instanceof BlockFluidBase || block instanceof BlockLiquid) { BuildCraftAPI.softBlocks.add(block); } } @@ -477,6 +477,7 @@ public class BuildCraftCore extends BuildCraftMod { CropManager.setDefaultHandler(new CropHandlerPlantable()); CropManager.registerHandler(new CropHandlerReeds()); + BuildCraftAPI.registerWorldProperty("replaceable", new WorldPropertyIsReplaceable()); BuildCraftAPI.registerWorldProperty("soft", new WorldPropertyIsSoft()); BuildCraftAPI.registerWorldProperty("wood", new WorldPropertyIsWood()); BuildCraftAPI.registerWorldProperty("leaves", new WorldPropertyIsLeaf()); diff --git a/common/buildcraft/builders/TileFiller.java b/common/buildcraft/builders/TileFiller.java index 04b5a6ad..40637977 100644 --- a/common/buildcraft/builders/TileFiller.java +++ b/common/buildcraft/builders/TileFiller.java @@ -420,16 +420,6 @@ public class TileFiller extends TileAbstractBuilder implements IHasWork, IContro })); } - public int getIconGlowLevel(int renderPass) { - if (renderPass == 1) { // Red LED - return done ? 15 : 0; - } else if (renderPass == 2) { // Green LED - return 0; - } else { - return -1; - } - } - @Override public int getLEDLevel(int led) { return (led == 0 ? done : buildersInAction.size() > 0) ? 15 : 0; diff --git a/common/buildcraft/core/builders/BuildingItem.java b/common/buildcraft/core/builders/BuildingItem.java index 16583690..f8ed52fa 100755 --- a/common/buildcraft/core/builders/BuildingItem.java +++ b/common/buildcraft/core/builders/BuildingItem.java @@ -27,6 +27,7 @@ import buildcraft.api.blueprints.MappingRegistry; import buildcraft.api.core.ISerializable; import buildcraft.api.core.Position; import buildcraft.core.StackAtPosition; +import buildcraft.core.lib.inventory.InvUtils; public class BuildingItem implements IBuildingItem, ISerializable { @@ -161,23 +162,27 @@ public class BuildingItem implements IBuildingItem, ISerializable { private void build() { if (slotToBuild != null) { - int destX = (int) Math.floor(destination.x); - int destY = (int) Math.floor(destination.y); - int destZ = (int) Math.floor(destination.z); - Block block = context.world().getBlock(destX, destY, destZ); - int meta = context.world().getBlockMetadata(destX, destY, destZ); - - context.world().playAuxSFXAtEntity(null, 2001, - destX, destY, destZ, - Block.getIdFromBlock(block) + (meta << 12)); - /*if (BlockUtil.isToughBlock(context.world(), destX, destY, destZ)) { BlockUtil.breakBlock(context.world(), destX, destY, destZ, BuildCraftBuilders.fillerLifespanTough); } else { BlockUtil.breakBlock(context.world(), destX, destY, destZ, BuildCraftBuilders.fillerLifespanNormal); }*/ - slotToBuild.writeToWorld(context); + int destX = (int) Math.floor(destination.x); + int destY = (int) Math.floor(destination.y); + int destZ = (int) Math.floor(destination.z); + Block oldBlock = context.world().getBlock(destX, destY, destZ); + int oldMeta = context.world().getBlockMetadata(destX, destY, destZ); + + if (slotToBuild.writeToWorld(context)) { + context.world().playAuxSFXAtEntity(null, 2001, + destX, destY, destZ, + Block.getIdFromBlock(oldBlock) + (oldMeta << 12)); + } else { + for (ItemStack s : slotToBuild.stackConsumed) { + InvUtils.dropItems(context.world(), s, destX, destY, destZ); + } + } } } diff --git a/common/buildcraft/core/builders/BuildingSlot.java b/common/buildcraft/core/builders/BuildingSlot.java index a333c40a..af8c3711 100755 --- a/common/buildcraft/core/builders/BuildingSlot.java +++ b/common/buildcraft/core/builders/BuildingSlot.java @@ -27,8 +27,8 @@ public abstract class BuildingSlot { public boolean built = false; - public void writeToWorld(IBuilderContext context) { - + public boolean writeToWorld(IBuilderContext context) { + return false; } public void writeCompleted (IBuilderContext context, double complete) { diff --git a/common/buildcraft/core/builders/BuildingSlotBlock.java b/common/buildcraft/core/builders/BuildingSlotBlock.java index 17538b54..f9a61284 100755 --- a/common/buildcraft/core/builders/BuildingSlotBlock.java +++ b/common/buildcraft/core/builders/BuildingSlotBlock.java @@ -57,22 +57,28 @@ public class BuildingSlotBlock extends BuildingSlot { } @Override - public void writeToWorld(IBuilderContext context) { + public boolean writeToWorld(IBuilderContext context) { if (mode == Mode.ClearIfInvalid) { if (!getSchematic().isAlreadyBuilt(context, x, y, z)) { if (BuildCraftBuilders.dropBrokenBlocks) { - BlockUtils.breakBlock((WorldServer) context.world(), x, y, z); + return BlockUtils.breakBlock((WorldServer) context.world(), x, y, z); } else { context.world().setBlockToAir(x, y, z); + return true; } } } else { try { getSchematic().placeInWorld(context, x, y, z, stackConsumed); - // This is slightly hackish, but it's a very important way to verify - // the stored requirements. + // This is also slightly hackish, but that's what you get when + // you're unable to break an API too much. + if (!getSchematic().isAlreadyBuilt(context, x, y, z)) { + return false; + } + // This is slightly hackish, but it's a very important way to verify + // the stored requirements for anti-cheating purposes. if (!context.world().isAirBlock(x, y, z) && getSchematic().getBuildingPermission() == BuildingPermission.ALL && getSchematic() instanceof SchematicBlock) { @@ -95,7 +101,7 @@ public class BuildingSlotBlock extends BuildingSlot { BCLog.logger.warn("Location: " + x + ", " + y + ", " + z + " - ItemStack: " + s.toString()); context.world().removeTileEntity(x, y, z); context.world().setBlockToAir(x, y, z); - return; + return false; } } // Restore the stored requirements. @@ -114,11 +120,16 @@ public class BuildingSlotBlock extends BuildingSlot { if (e != null) { e.updateEntity(); } + + return true; } catch (Throwable t) { t.printStackTrace(); context.world().setBlockToAir(x, y, z); + return false; } } + + return false; } @Override diff --git a/common/buildcraft/core/builders/BuildingSlotEntity.java b/common/buildcraft/core/builders/BuildingSlotEntity.java index af39071d..86c6e768 100755 --- a/common/buildcraft/core/builders/BuildingSlotEntity.java +++ b/common/buildcraft/core/builders/BuildingSlotEntity.java @@ -34,8 +34,9 @@ public class BuildingSlotEntity extends BuildingSlot { public int sequenceNumber; @Override - public void writeToWorld(IBuilderContext context) { + public boolean writeToWorld(IBuilderContext context) { schematic.writeToWorld(context); + return true; } @Override diff --git a/common/buildcraft/core/properties/WorldPropertyIsReplaceable.java b/common/buildcraft/core/properties/WorldPropertyIsReplaceable.java new file mode 100755 index 00000000..918d0d57 --- /dev/null +++ b/common/buildcraft/core/properties/WorldPropertyIsReplaceable.java @@ -0,0 +1,21 @@ +/** + * 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.properties; + +import net.minecraft.block.Block; +import net.minecraft.world.IBlockAccess; + +public class WorldPropertyIsReplaceable extends WorldProperty { + @Override + public boolean get(IBlockAccess blockAccess, Block block, int meta, int x, int y, int z) { + return block == null + || block.isAir(blockAccess, x, y, z) + || block.isReplaceable(blockAccess, x, y, z); + } +} diff --git a/common/buildcraft/factory/TileRefinery.java b/common/buildcraft/factory/TileRefinery.java index a1506f61..94531020 100644 --- a/common/buildcraft/factory/TileRefinery.java +++ b/common/buildcraft/factory/TileRefinery.java @@ -39,7 +39,7 @@ import buildcraft.core.lib.network.command.ICommandReceiver; import buildcraft.core.lib.utils.NetworkUtils; import buildcraft.core.recipes.RefineryRecipeManager; -public class TileRefinery extends TileBuildCraft implements IFluidHandler, IInventory, IHasWork, IFlexibleCrafter, ICommandReceiver { +public class TileRefinery extends TileBuildCraft implements IFluidHandler, IHasWork, IFlexibleCrafter, ICommandReceiver { public static int LIQUID_PER_SLOT = FluidContainerRegistry.BUCKET_VOLUME * 4; @@ -65,50 +65,6 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IInve this.setBattery(new RFBattery(10000, 1500, 0)); } - @Override - public int getSizeInventory() { - return 0; - } - - @Override - public ItemStack getStackInSlot(int i) { - return null; - } - - @Override - public ItemStack decrStackSize(int i, int j) { - return null; - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) { - } - - @Override - public String getInventoryName() { - return null; - } - - @Override - public int getInventoryStackLimit() { - return 0; - } - - @Override - public boolean isItemValidForSlot(int i, ItemStack itemstack) { - return false; - } - - @Override - public boolean isUseableByPlayer(EntityPlayer entityplayer) { - return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this; - } - - @Override - public ItemStack getStackInSlotOnClosing(int var1) { - return null; - } - @Override public void updateEntity() { super.updateEntity(); @@ -228,14 +184,6 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IInve } } - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - public void resetFilters() { for (SingleUseTank tank : tankManager) { tank.setAcceptedFluid(null); @@ -357,11 +305,6 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IInve return true; } - @Override - public boolean hasCustomInventoryName() { - return false; - } - @Override public int getCraftingItemStackSize() { return 0; diff --git a/common/buildcraft/factory/gui/ContainerRefinery.java b/common/buildcraft/factory/gui/ContainerRefinery.java index 30de8d2d..dab19429 100644 --- a/common/buildcraft/factory/gui/ContainerRefinery.java +++ b/common/buildcraft/factory/gui/ContainerRefinery.java @@ -26,7 +26,7 @@ public class ContainerRefinery extends BuildCraftContainer { public TileRefinery refinery; public ContainerRefinery(InventoryPlayer inventory, TileRefinery refinery) { - super(refinery.getSizeInventory()); + super(0); for (int l = 0; l < 3; l++) { for (int k1 = 0; k1 < 9; k1++) { @@ -43,7 +43,7 @@ public class ContainerRefinery extends BuildCraftContainer { @Override public boolean canInteractWith(EntityPlayer entityplayer) { - return refinery.isUseableByPlayer(entityplayer); + return entityplayer.worldObj.getTileEntity(refinery.xCoord, refinery.yCoord, refinery.zCoord) == refinery; } /* SETTING AND GETTING FILTERS */ diff --git a/common/buildcraft/factory/gui/GuiRefinery.java b/common/buildcraft/factory/gui/GuiRefinery.java index 58039b01..d8c36381 100644 --- a/common/buildcraft/factory/gui/GuiRefinery.java +++ b/common/buildcraft/factory/gui/GuiRefinery.java @@ -28,7 +28,7 @@ public class GuiRefinery extends GuiAdvancedInterface { private final ContainerRefinery container; public GuiRefinery(InventoryPlayer inventory, TileRefinery refinery) { - super(new ContainerRefinery(inventory, refinery), refinery, TEXTURE); + super(new ContainerRefinery(inventory, refinery), null, TEXTURE); xSize = 175; ySize = 207; @@ -83,12 +83,10 @@ public class GuiRefinery extends GuiAdvancedInterface { container.refinery.tankManager.get(position).colorRenderCache = 0xFFFFFF; } } else { - TileRefinery ref = (TileRefinery) this.tile; - if (position == 0) { - container.setFilter(position, ref.tanks[0].getFluidType()); + container.setFilter(position, container.refinery.tanks[0].getFluidType()); } else if (position == 1) { - container.setFilter(position, ref.tanks[1].getFluidType()); + container.setFilter(position, container.refinery.tanks[1].getFluidType()); } } }