diff --git a/api/buildcraft/api/core/EnumColor.java b/api/buildcraft/api/core/EnumColor.java index 10e7121d..c5ea8899 100644 --- a/api/buildcraft/api/core/EnumColor.java +++ b/api/buildcraft/api/core/EnumColor.java @@ -36,6 +36,7 @@ public enum EnumColor { MAGENTA, ORANGE, WHITE; + public static final EnumColor[] VALUES = values(); public static final String[] DYES = { "dyeBlack", diff --git a/api/buildcraft/api/items/IList.java b/api/buildcraft/api/items/IList.java new file mode 100644 index 00000000..f7d60c2d --- /dev/null +++ b/api/buildcraft/api/items/IList.java @@ -0,0 +1,8 @@ +package buildcraft.api.items; + +import net.minecraft.item.ItemStack; + +public interface IList { + String getLabel(ItemStack stack); + boolean matches(ItemStack stackList, ItemStack item); +} diff --git a/api/buildcraft/api/items/IMapLocation.java b/api/buildcraft/api/items/IMapLocation.java new file mode 100644 index 00000000..2b8b87ee --- /dev/null +++ b/api/buildcraft/api/items/IMapLocation.java @@ -0,0 +1,57 @@ +package buildcraft.api.items; + +import java.util.List; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; +import buildcraft.api.core.BlockIndex; +import buildcraft.api.core.IBox; +import buildcraft.api.core.IZone; + +/** + * Created by asie on 2/28/15. + */ +public interface IMapLocation { + public enum MapLocationType { + CLEAN, SPOT, AREA, PATH, ZONE + } + + MapLocationType getType(ItemStack stack); + + /** + * This function can be used for SPOT types. + * @param stack + * @return The point representing the map location. + */ + BlockIndex getPoint(ItemStack stack); + + /** + * This function can be used for SPOT and AREA types. + * @param stack + * @return The box representing the map location. + */ + IBox getBox(ItemStack stack); + + /** + * This function can be used for SPOT, AREA and ZONE types. + * The PATH type needs to be handled separately. + * @param stack + * @return An IZone representing the map location - also an instance of + * IBox for SPOT and AREA types. + */ + IZone getZone(ItemStack stack); + + /** + * This function can be used for SPOT and PATH types. + * @param stack + * @return A list of BlockIndexes representing the path the Map Location + * stores. + */ + List getPath(ItemStack stack); + + /** + * This function can be used for SPOT types only. + * @param stack + * @return The side of the spot. + */ + ForgeDirection getPointSide(ItemStack stack); +} diff --git a/api/buildcraft/api/items/package-info.java b/api/buildcraft/api/items/package-info.java new file mode 100644 index 00000000..fa3a9554 --- /dev/null +++ b/api/buildcraft/api/items/package-info.java @@ -0,0 +1,12 @@ +/** + * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. + * Please check the contents of the license, which should be located + * as "LICENSE.API" in the BuildCraft source code distribution. + */ +@API(apiVersion = "1.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|items") +package buildcraft.api.items; +import cpw.mods.fml.common.API; + diff --git a/buildcraft_resources/changelog/6.4.2 b/buildcraft_resources/changelog/6.4.2 new file mode 100644 index 00000000..de6b0670 --- /dev/null +++ b/buildcraft_resources/changelog/6.4.2 @@ -0,0 +1,16 @@ +Additions: +* IList, IMapLocation APIs for modders in the new buildcraft.api.items + +Bugfixes: +* [#2518] Exceptions in Pump Robots (hea3ven) +* [#2517] Programming Table crash in certain Java configurations (asie) +* [#2510] Entity stripes handler duplicating items (hea3ven) +* {#2509] Robot gets stuck in recharge mode (asie) +* [#2506] Builder causes lag in 6.4.1 (asie) +* [#2502] Combustion Engine not recognized as tank from front (asie) +* Incorrect Forge version dependency (Vexatos) +* Infinite loop when looping through direction parameters and no pipes are connected (hea3ven) +* Invalid power scale for laser colours (asie) +* Low/High Energy Stored trigger works as expected again (asie) +* Robots fly away when searching for a station to recharge (hea3ven) +* Robots are charged wirelessly (asie) diff --git a/buildcraft_resources/versions.txt b/buildcraft_resources/versions.txt index e2841c0e..d0c3b8d9 100755 --- a/buildcraft_resources/versions.txt +++ b/buildcraft_resources/versions.txt @@ -1,3 +1,3 @@ 1.6.4:BuildCraft:4.2.2 1.7.2:BuildCraft:6.0.16 -1.7.10:BuildCraft:6.4.1 +1.7.10:BuildCraft:6.4.2 diff --git a/common/buildcraft/BuildCraftCore.java b/common/buildcraft/BuildCraftCore.java index 76663dcd..13ec8953 100644 --- a/common/buildcraft/BuildCraftCore.java +++ b/common/buildcraft/BuildCraftCore.java @@ -185,7 +185,7 @@ import buildcraft.robots.boards.BoardRobotPump; import buildcraft.robots.boards.BoardRobotShovelman; import buildcraft.robots.boards.BoardRobotStripes; -@Mod(name = "BuildCraft", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Core", acceptedMinecraftVersions = "[1.7.10,1.8)", dependencies = "required-after:Forge@[10.13.0.1236,)") +@Mod(name = "BuildCraft", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Core", acceptedMinecraftVersions = "[1.7.10,1.8)", dependencies = "required-after:Forge@[10.13.2.1236,)") public class BuildCraftCore extends BuildCraftMod { @Mod.Instance("BuildCraft|Core") @@ -215,7 +215,7 @@ public class BuildCraftCore extends BuildCraftMod { public static Item diamondGearItem; public static Item wrenchItem; public static Item mapLocationItem; - public static Item listItem; + public static ItemList listItem; @SideOnly(Side.CLIENT) public static IIcon redLaserTexture; @SideOnly(Side.CLIENT) @@ -347,7 +347,7 @@ public class BuildCraftCore extends BuildCraftMod { mapLocationItem = (new ItemMapLocation()).setUnlocalizedName("mapLocation"); CoreProxy.proxy.registerItem(mapLocationItem); - listItem = (new ItemList()).setUnlocalizedName("list"); + listItem = (ItemList) ((new ItemList()).setUnlocalizedName("list")); CoreProxy.proxy.registerItem(listItem); Property modifyWorldProp = BuildCraftCore.mainConfiguration.get("general", "modifyWorld", true); diff --git a/common/buildcraft/BuildCraftTransport.java b/common/buildcraft/BuildCraftTransport.java index 81766ceb..b92b4ca9 100644 --- a/common/buildcraft/BuildCraftTransport.java +++ b/common/buildcraft/BuildCraftTransport.java @@ -151,6 +151,7 @@ import buildcraft.transport.statements.TriggerRedstoneFaderInput; import buildcraft.transport.stripes.StripesHandlerArrow; import buildcraft.transport.stripes.StripesHandlerBucket; import buildcraft.transport.stripes.StripesHandlerEntityInteract; +import buildcraft.transport.stripes.StripesHandlerHoe; import buildcraft.transport.stripes.StripesHandlerPipes; import buildcraft.transport.stripes.StripesHandlerPlaceBlock; import buildcraft.transport.stripes.StripesHandlerRightClick; @@ -467,6 +468,7 @@ public class BuildCraftTransport extends BuildCraftMod { PipeManager.registerStripesHandler(new StripesHandlerPipes()); PipeManager.registerStripesHandler(new StripesHandlerEntityInteract()); PipeManager.registerStripesHandler(new StripesHandlerPlaceBlock()); + PipeManager.registerStripesHandler(new StripesHandlerHoe()); PipeManager.registerPipePluggable(FacadePluggable.class, "facade"); PipeManager.registerPipePluggable(GatePluggable.class, "gate"); diff --git a/common/buildcraft/builders/BlockMarker.java b/common/buildcraft/builders/BlockMarker.java index 7872881b..376b7967 100644 --- a/common/buildcraft/builders/BlockMarker.java +++ b/common/buildcraft/builders/BlockMarker.java @@ -25,9 +25,9 @@ import net.minecraftforge.common.util.ForgeDirection; import buildcraft.BuildCraftCore; import buildcraft.api.events.BlockInteractionEvent; +import buildcraft.api.items.IMapLocation; import buildcraft.core.BlockBuildCraft; import buildcraft.core.CreativeTabBuildCraft; -import buildcraft.core.ItemMapLocation; import buildcraft.core.utils.Utils; public class BlockMarker extends BlockBuildCraft { @@ -98,7 +98,7 @@ public class BlockMarker extends BlockBuildCraft { @Override public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int par6, float par7, float par8, float par9) { if (entityplayer.inventory.getCurrentItem() != null - && entityplayer.inventory.getCurrentItem().getItem() instanceof ItemMapLocation) { + && entityplayer.inventory.getCurrentItem().getItem() instanceof IMapLocation) { return false; } diff --git a/common/buildcraft/compat/CompatHooks.java b/common/buildcraft/compat/CompatHooks.java index 4a18318e..c49aa486 100644 --- a/common/buildcraft/compat/CompatHooks.java +++ b/common/buildcraft/compat/CompatHooks.java @@ -10,6 +10,7 @@ package buildcraft.compat; import net.minecraft.block.Block; import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.IBlockAccess; import cpw.mods.fml.common.Loader; @@ -44,6 +45,14 @@ public class CompatHooks { return null; } + public Block getVisualBlock(IBlockAccess world, int x, int y, int z, ForgeDirection side) { + return null; + } + + public int getVisualMeta(IBlockAccess world, int x, int y, int z, ForgeDirection side) { + return -1; + } + public Block getBlock(Class klazz) { Block block = null; diff --git a/common/buildcraft/core/IMachine.java b/common/buildcraft/core/IMachine.java index f46e600b..e9f81ef6 100644 --- a/common/buildcraft/core/IMachine.java +++ b/common/buildcraft/core/IMachine.java @@ -10,7 +10,7 @@ package buildcraft.core; /** * Left only to stop certain mods depending on it from crashing. - * Please move to the classes contained in builcraft.api.tiles + * Please move to the classes contained in buildcraft.api.tiles * and IPipeConnection from .transport. */ @Deprecated diff --git a/common/buildcraft/core/ItemList.java b/common/buildcraft/core/ItemList.java index 769704cb..eaa5393e 100644 --- a/common/buildcraft/core/ItemList.java +++ b/common/buildcraft/core/ItemList.java @@ -30,10 +30,11 @@ import cpw.mods.fml.relauncher.SideOnly; import net.minecraftforge.oredict.OreDictionary; import buildcraft.BuildCraftCore; +import buildcraft.api.items.IList; import buildcraft.core.inventory.StackHelper; import buildcraft.core.utils.NBTUtils; -public class ItemList extends ItemBuildCraft { +public class ItemList extends ItemBuildCraft implements IList { private IIcon baseIcon; private IIcon writtenIcon; @@ -288,11 +289,13 @@ public class ItemList extends ItemBuildCraft { return result; } - public static String getLabel(ItemStack stack) { + @Override + public String getLabel(ItemStack stack) { return NBTUtils.getItemData(stack).getString("label"); } - public static boolean matches(ItemStack stackList, ItemStack item) { + @Override + public boolean matches(ItemStack stackList, ItemStack item) { StackLine[] lines = getLines(stackList); for (StackLine line : lines) { diff --git a/common/buildcraft/core/ItemMapLocation.java b/common/buildcraft/core/ItemMapLocation.java index c2f41308..1f3f6fc5 100755 --- a/common/buildcraft/core/ItemMapLocation.java +++ b/common/buildcraft/core/ItemMapLocation.java @@ -8,6 +8,7 @@ */ package buildcraft.core; +import java.util.ArrayList; import java.util.List; import net.minecraft.client.renderer.texture.IIconRegister; @@ -29,12 +30,13 @@ import buildcraft.api.boards.RedstoneBoardRegistry; import buildcraft.api.core.BlockIndex; import buildcraft.api.core.IBox; import buildcraft.api.core.IZone; +import buildcraft.api.items.IMapLocation; import buildcraft.builders.TileMarker; import buildcraft.builders.TilePathMarker; import buildcraft.core.utils.NBTUtils; import buildcraft.core.utils.StringUtils; -public class ItemMapLocation extends ItemBuildCraft { +public class ItemMapLocation extends ItemBuildCraft implements IMapLocation { public IIcon clean; public IIcon spot; @@ -181,21 +183,8 @@ public class ItemMapLocation extends ItemBuildCraft { return true; } - public static BlockIndex getBlockIndex(ItemStack item) { - NBTTagCompound cpt = NBTUtils.getItemData(item); - - if (cpt.hasKey("kind") && cpt.getByte("kind") == 0) { - int x = cpt.getInteger("x"); - int y = cpt.getInteger("y"); - int z = cpt.getInteger("z"); - - return new BlockIndex(x, y, z); - } else { - return null; - } - } - - public static IBox getBox(ItemStack item) { + @Override + public IBox getBox(ItemStack item) { NBTTagCompound cpt = NBTUtils.getItemData(item); if (cpt.hasKey("kind") && cpt.getByte("kind") == 1) { @@ -207,6 +196,8 @@ public class ItemMapLocation extends ItemBuildCraft { int zMax = cpt.getInteger("zMax"); return new Box(xMin, yMin, zMin, xMax, yMax, zMax); + } else if (cpt.hasKey("kind") && cpt.getByte("kind") == 0) { + return getPointBox(item); } else { return null; } @@ -226,7 +217,8 @@ public class ItemMapLocation extends ItemBuildCraft { } } - public static ForgeDirection getSide(ItemStack item) { + @Override + public ForgeDirection getPointSide(ItemStack item) { NBTTagCompound cpt = NBTUtils.getItemData(item); if (cpt.hasKey("kind") && cpt.getByte("kind") == 0) { @@ -236,7 +228,19 @@ public class ItemMapLocation extends ItemBuildCraft { } } - public static IZone getZone(ItemStack item) { + @Override + public BlockIndex getPoint(ItemStack item) { + NBTTagCompound cpt = NBTUtils.getItemData(item); + + if (cpt.hasKey("kind") && cpt.getByte("kind") == 0) { + return new BlockIndex(cpt.getInteger("x"), cpt.getInteger("y"), cpt.getInteger("z")); + } else { + return null; + } + } + + @Override + public IZone getZone(ItemStack item) { NBTTagCompound cpt = NBTUtils.getItemData(item); if (cpt.hasKey("kind") && cpt.getByte("kind") == 3) { @@ -253,10 +257,36 @@ public class ItemMapLocation extends ItemBuildCraft { } } + @Override + public List getPath(ItemStack item) { + NBTTagCompound cpt = NBTUtils.getItemData(item); + + if (cpt.hasKey("kind") && cpt.getByte("kind") == 2) { + List indexList = new ArrayList(); + NBTTagList pathNBT = cpt.getTagList("path", Constants.NBT.TAG_COMPOUND); + for (int i = 0; i < pathNBT.tagCount(); i++) { + indexList.add(new BlockIndex(pathNBT.getCompoundTagAt(i))); + } + return indexList; + } else if (cpt.hasKey("kind") && cpt.getByte("kind") == 0) { + List indexList = new ArrayList(); + indexList.add(new BlockIndex(cpt.getInteger("x"), cpt.getInteger("y"), cpt.getInteger("z"))); + return indexList; + } else { + return null; + } + } + public static void setZone(ItemStack item, ZonePlan plan) { NBTTagCompound cpt = NBTUtils.getItemData(item); cpt.setByte("kind", (byte) 3); plan.writeToNBT(cpt); } + + @Override + public MapLocationType getType(ItemStack stack) { + NBTTagCompound cpt = NBTUtils.getItemData(stack); + return MapLocationType.values()[cpt.getByte("kind")]; + } } diff --git a/common/buildcraft/core/blueprints/BptBuilderBlueprint.java b/common/buildcraft/core/blueprints/BptBuilderBlueprint.java index fb9ede67..4e56e384 100644 --- a/common/buildcraft/core/blueprints/BptBuilderBlueprint.java +++ b/common/buildcraft/core/blueprints/BptBuilderBlueprint.java @@ -198,7 +198,9 @@ public class BptBuilderBlueprint extends BptBuilderBase { initialize(); for (BuildingSlotBlock b : buildList) { - if (!b.schematic.doNotBuild()) { + if (b.mode == Mode.ClearIfInvalid) { + context.world.setBlockToAir(b.x, b.y, b.z); + } else if (!b.schematic.doNotBuild()) { b.stackConsumed = new LinkedList(); try { diff --git a/common/buildcraft/core/gui/GuiList.java b/common/buildcraft/core/gui/GuiList.java index 522d8077..35522960 100755 --- a/common/buildcraft/core/gui/GuiList.java +++ b/common/buildcraft/core/gui/GuiList.java @@ -13,6 +13,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; +import buildcraft.BuildCraftCore; import buildcraft.core.DefaultProps; import buildcraft.core.ItemList; @@ -118,7 +119,7 @@ public class GuiList extends GuiAdvancedInterface { textField = new GuiTextField(this.fontRendererObj, 10, 10, 156, 12); textField.setMaxStringLength(32); - textField.setText(ItemList.getLabel(player.getCurrentEquippedItem())); + textField.setText(BuildCraftCore.listItem.getLabel(player.getCurrentEquippedItem())); textField.setFocused(false); } diff --git a/common/buildcraft/core/inventory/StackHelper.java b/common/buildcraft/core/inventory/StackHelper.java index 5ac30083..91121bfc 100644 --- a/common/buildcraft/core/inventory/StackHelper.java +++ b/common/buildcraft/core/inventory/StackHelper.java @@ -12,7 +12,7 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.OreDictionary; -import buildcraft.core.ItemList; +import buildcraft.api.items.IList; public class StackHelper { @@ -46,10 +46,12 @@ public class StackHelper { return false; } - if (stack1.getItem() instanceof ItemList) { - return ItemList.matches(stack1, stack2); - } else if (stack2.getItem() instanceof ItemList) { - return ItemList.matches(stack2, stack1); + if (stack1.getItem() instanceof IList) { + IList list = (IList) stack1.getItem(); + return list.matches(stack1, stack2); + } else if (stack2.getItem() instanceof IList) { + IList list = (IList) stack2.getItem(); + return list.matches(stack2, stack1); } if (!stack1.isItemEqual(stack2)) { @@ -137,10 +139,12 @@ public class StackHelper { return false; } - if (a.getItem() instanceof ItemList) { - return ItemList.matches(a, b); - } else if (b.getItem() instanceof ItemList) { - return ItemList.matches(b, a); + if (a.getItem() instanceof IList) { + IList list = (IList) a.getItem(); + return list.matches(a, b); + } else if (b.getItem() instanceof IList) { + IList list = (IList) b.getItem(); + return list.matches(b, a); } return isMatchingItem(a, b, true, false); diff --git a/common/buildcraft/core/statements/DefaultTriggerProvider.java b/common/buildcraft/core/statements/DefaultTriggerProvider.java index ca6f5a22..947c8382 100644 --- a/common/buildcraft/core/statements/DefaultTriggerProvider.java +++ b/common/buildcraft/core/statements/DefaultTriggerProvider.java @@ -17,11 +17,6 @@ import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; -import cofh.api.energy.IEnergyConnection; -import cofh.api.energy.IEnergyHandler; -import cofh.api.energy.IEnergyProvider; -import cofh.api.energy.IEnergyReceiver; - import buildcraft.BuildCraftCore; import buildcraft.api.statements.IStatementContainer; import buildcraft.api.statements.ITriggerExternal; @@ -63,20 +58,18 @@ public class DefaultTriggerProvider implements ITriggerProvider { res.add(BuildCraftCore.triggerMachineInactive); } - if (tile instanceof IEnergyConnection && ((IEnergyConnection) tile).canConnectEnergy(side.getOpposite())) { - if ((tile instanceof IEnergyHandler && ((IEnergyHandler) tile).getMaxEnergyStored(side.getOpposite()) > 0) - || (tile instanceof IEnergyReceiver && ((IEnergyReceiver) tile).getMaxEnergyStored(side.getOpposite()) > 0) - || (tile instanceof IEnergyProvider && ((IEnergyProvider) tile).getMaxEnergyStored(side.getOpposite()) > 0)) { - res.add((ITriggerExternal) BuildCraftCore.triggerEnergyHigh); - res.add((ITriggerExternal) BuildCraftCore.triggerEnergyLow); - } - } - return res; } @Override public LinkedList getInternalTriggers(IStatementContainer container) { - return null; + LinkedList res = new LinkedList(); + + if (TriggerEnergy.isTriggeringPipe(container.getTile()) || TriggerEnergy.getTriggeringNeighbor(container.getTile()) != null) { + res.add((ITriggerInternal) BuildCraftCore.triggerEnergyHigh); + res.add((ITriggerInternal) BuildCraftCore.triggerEnergyLow); + } + + return res; } } diff --git a/common/buildcraft/core/statements/StatementParameterDirection.java b/common/buildcraft/core/statements/StatementParameterDirection.java index 6cb0be0f..06505ae6 100644 --- a/common/buildcraft/core/statements/StatementParameterDirection.java +++ b/common/buildcraft/core/statements/StatementParameterDirection.java @@ -49,9 +49,13 @@ public class StatementParameterDirection implements IStatementParameter { @Override public void onClick(IStatementContainer source, IStatement stmt, ItemStack stack, StatementMouseClick mouse) { if (source.getTile() instanceof TileGenericPipe) { - do { + for (int i = 0; i < 6; i++) { direction = ForgeDirection.getOrientation((direction.ordinal() + (mouse.getButton() > 0 ? -1 : 1)) % 6); - } while (!((TileGenericPipe) source.getTile()).isPipeConnected(direction)); + if (((TileGenericPipe) source.getTile()).isPipeConnected(direction)) { + return; + } + } + direction = ForgeDirection.UNKNOWN; } } diff --git a/common/buildcraft/core/statements/TriggerEnergy.java b/common/buildcraft/core/statements/TriggerEnergy.java index 53992728..55ecc7dd 100644 --- a/common/buildcraft/core/statements/TriggerEnergy.java +++ b/common/buildcraft/core/statements/TriggerEnergy.java @@ -23,10 +23,20 @@ import cofh.api.energy.IEnergyReceiver; import buildcraft.api.statements.IStatementContainer; import buildcraft.api.statements.IStatementParameter; -import buildcraft.api.statements.ITriggerExternal; +import buildcraft.api.statements.ITriggerInternal; +import buildcraft.api.transport.IPipeTile; import buildcraft.core.utils.StringUtils; -public class TriggerEnergy extends BCStatement implements ITriggerExternal { +public class TriggerEnergy extends BCStatement implements ITriggerInternal { + public static class Neighbor { + public TileEntity tile; + public ForgeDirection side; + + public Neighbor(TileEntity tile, ForgeDirection side) { + this.tile = tile; + this.side = side; + } + } private boolean high; @@ -67,20 +77,69 @@ public class TriggerEnergy extends BCStatement implements ITriggerExternal { return false; } - @Override - public boolean isTriggerActive(TileEntity tile, ForgeDirection side, IStatementContainer container, IStatementParameter[] parameters) { - if (tile instanceof IEnergyHandler || tile instanceof IEnergyProvider || tile instanceof IEnergyReceiver) { - if (((IEnergyConnection) tile).canConnectEnergy(side.getOpposite())) { + protected static boolean isTriggered(Object tile, ForgeDirection side) { + return (tile instanceof IEnergyHandler || tile instanceof IEnergyProvider || tile instanceof IEnergyReceiver) + && (((IEnergyConnection) tile).canConnectEnergy(side.getOpposite())); + } + + protected boolean isActive(Object tile, ForgeDirection side) { + if (isTriggered(tile, side)) { return isTriggeredEnergyHandler((IEnergyConnection) tile, side.getOpposite()); - } } return false; } + public static boolean isTriggeringPipe(TileEntity tile) { + if (tile instanceof IPipeTile) { + IPipeTile pipeTile = (IPipeTile) tile; + if (pipeTile.getPipeType() == IPipeTile.PipeType.POWER && pipeTile.getPipe() instanceof IEnergyHandler) { + return true; + } + } + return false; + } + @Override @SideOnly(Side.CLIENT) public void registerIcons(IIconRegister iconRegister) { icon = iconRegister.registerIcon("buildcraft:triggers/trigger_machine_energy_" + (high ? "high" : "low")); } + + @Override + public boolean isTriggerActive(IStatementContainer source, IStatementParameter[] parameters) { + // Internal check + if (isTriggeringPipe(source.getTile())) { + return isActive(((IPipeTile) source.getTile()).getPipe(), ForgeDirection.UNKNOWN); + } + + Neighbor triggeringNeighbor = getTriggeringNeighbor(source.getTile()); + if (triggeringNeighbor != null) { + return isActive(triggeringNeighbor.tile, triggeringNeighbor.side); + } + return false; + } + + public static Neighbor getTriggeringNeighbor(TileEntity parent) { + if (parent instanceof IPipeTile) { + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + TileEntity tile = ((IPipeTile) parent).getNeighborTile(side); + if (tile != null && isTriggered(tile, side)) { + return new Neighbor(tile, side); + } + } + } else { + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + TileEntity tile = parent.getWorldObj().getTileEntity( + parent.xCoord + side.offsetX, + parent.yCoord + side.offsetY, + parent.zCoord + side.offsetZ + ); + if (tile != null && isTriggered(tile, side)) { + return new Neighbor(tile, side); + } + } + } + return null; + } } diff --git a/common/buildcraft/core/utils/concurrency/PathFindingSearch.java b/common/buildcraft/core/utils/concurrency/PathFindingSearch.java index e89c77e9..445fa76c 100644 --- a/common/buildcraft/core/utils/concurrency/PathFindingSearch.java +++ b/common/buildcraft/core/utils/concurrency/PathFindingSearch.java @@ -65,7 +65,9 @@ public class PathFindingSearch implements IIterableAlgorithm { } BlockIndex delta = blockIter.next(); - BlockIndex block = new BlockIndex(start.x + delta.x, start.y + delta.y, start.z + delta.z); + BlockIndex block = new BlockIndex(start.x + delta.x, + ((start.y + delta.y) > 0) ? start.y + delta.y : 0, + start.z + delta.z); if (isLoadedChunk(block.x, block.z)) { if (isTarget(block)) { pathFinders.add(new PathFinding(world, start, block, 0, maxDistance)); diff --git a/common/buildcraft/energy/TileEngineIron.java b/common/buildcraft/energy/TileEngineIron.java index c800641e..e2164a37 100644 --- a/common/buildcraft/energy/TileEngineIron.java +++ b/common/buildcraft/energy/TileEngineIron.java @@ -393,9 +393,6 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan @Override public FluidTankInfo[] getTankInfo(ForgeDirection direction) { - if (direction == orientation) { - return null; - } return tankManager.getTankInfo(direction); } diff --git a/common/buildcraft/robots/RobotStationPluggable.java b/common/buildcraft/robots/RobotStationPluggable.java index a6f0689c..cc5efa3d 100644 --- a/common/buildcraft/robots/RobotStationPluggable.java +++ b/common/buildcraft/robots/RobotStationPluggable.java @@ -255,7 +255,8 @@ public class RobotStationPluggable extends PipePluggable implements IPipePluggab @Override public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) { - if (station != null && station.isTaken() && station.robotTaking() != null && station.robotTaking().getBattery() != null) { + if (station != null && station.isTaken() && station.robotTaking() != null && station.robotTaking().getBattery() != null + && station.robotTaking().getDockingStation() == station) { return station.robotTaking().getBattery().receiveEnergy(maxReceive, simulate); } return 0; diff --git a/common/buildcraft/robots/ai/AIRobotMain.java b/common/buildcraft/robots/ai/AIRobotMain.java index 39098f81..c1bdc1af 100755 --- a/common/buildcraft/robots/ai/AIRobotMain.java +++ b/common/buildcraft/robots/ai/AIRobotMain.java @@ -19,10 +19,15 @@ public class AIRobotMain extends AIRobot { super(iRobot); } + @Override + public int getEnergyCost() { + return 0; + } + @Override public void preempt(AIRobot ai) { if (!(ai instanceof AIRobotRecharge)) { - if (robot.getEnergy() < EntityRobotBase.SAFETY_ENERGY) { + if (robot.getEnergy() < EntityRobotBase.SAFETY_ENERGY) { startDelegateAI(new AIRobotRecharge(robot)); } else if (overridingAI != null && ai != overridingAI) { startDelegateAI(overridingAI); diff --git a/common/buildcraft/robots/ai/AIRobotRecharge.java b/common/buildcraft/robots/ai/AIRobotRecharge.java index c6e8e7fc..e136e1bb 100755 --- a/common/buildcraft/robots/ai/AIRobotRecharge.java +++ b/common/buildcraft/robots/ai/AIRobotRecharge.java @@ -26,6 +26,9 @@ public class AIRobotRecharge extends AIRobot { @Override public void start() { robot.getRegistry().releaseResources(robot); + robot.motionX = 0; + robot.motionY = 0; + robot.motionZ = 0; startDelegateAI(new AIRobotSearchAndGotoStation(robot, new IStationFilter() { @Override @@ -35,6 +38,11 @@ public class AIRobotRecharge extends AIRobot { }, null)); } + @Override + public int getEnergyCost() { + return 0; + } + @Override public void update() { if (robot.getEnergy() >= EntityRobotBase.MAX_ENERGY) { diff --git a/common/buildcraft/robots/ai/AIRobotSearchBlockBase.java b/common/buildcraft/robots/ai/AIRobotSearchBlockBase.java index f65a5023..3d128171 100644 --- a/common/buildcraft/robots/ai/AIRobotSearchBlockBase.java +++ b/common/buildcraft/robots/ai/AIRobotSearchBlockBase.java @@ -11,6 +11,7 @@ import buildcraft.api.robots.EntityRobotBase; import buildcraft.core.utils.IBlockFilter; import buildcraft.core.utils.concurrency.IterableAlgorithmRunner; import buildcraft.core.utils.concurrency.PathFindingSearch; +import buildcraft.robots.ResourceIdBlock; public class AIRobotSearchBlockBase extends AIRobot { @@ -26,6 +27,8 @@ public class AIRobotSearchBlockBase extends AIRobot { pathFound = iPathFound; blockIter = iBlockIter; + blockFound = null; + path = null; } @Override @@ -66,6 +69,11 @@ public class AIRobotSearchBlockBase extends AIRobot { } } + @Override + public boolean success() { + return blockFound != null; + } + @Override public void writeSelfToNBT(NBTTagCompound nbt) { super.writeSelfToNBT(nbt); @@ -86,6 +94,15 @@ public class AIRobotSearchBlockBase extends AIRobot { } } + public boolean takeResource() { + boolean taken = false; + if (robot.getRegistry().take(new ResourceIdBlock(blockFound), robot)) { + taken = true; + } + unreserve(); + return taken; + } + public void unreserve() { blockScanner.unreserve(blockFound); } diff --git a/common/buildcraft/robots/ai/AIRobotStripesHandler.java b/common/buildcraft/robots/ai/AIRobotStripesHandler.java index 9b313c1f..0955a9af 100644 --- a/common/buildcraft/robots/ai/AIRobotStripesHandler.java +++ b/common/buildcraft/robots/ai/AIRobotStripesHandler.java @@ -24,12 +24,8 @@ import buildcraft.api.transport.IStripesHandler.StripesHandlerType; import buildcraft.api.transport.PipeManager; import buildcraft.core.inventory.InvUtils; import buildcraft.core.proxy.CoreProxy; -import buildcraft.transport.stripes.StripesHandlerDefault; public class AIRobotStripesHandler extends AIRobot implements IStripesActivator { - - private static IStripesHandler defaultItemsHandler = new StripesHandlerDefault(); - private BlockIndex useToBlock; private int useCycles = 0; @@ -77,17 +73,11 @@ public class AIRobotStripesHandler extends AIRobot implements IStripesActivator } } } - - if (defaultItemsHandler.handle(robot.worldObj, (int) p.x, (int) p.y, - (int) p.z, direction, stack, player, this)) { - robot.setItemInUse(null); - } terminate(); } } private ForgeDirection getDirection() { - return null; } diff --git a/common/buildcraft/robots/boards/BoardRobotFarmer.java b/common/buildcraft/robots/boards/BoardRobotFarmer.java index caec42f1..00445767 100644 --- a/common/buildcraft/robots/boards/BoardRobotFarmer.java +++ b/common/buildcraft/robots/boards/BoardRobotFarmer.java @@ -22,7 +22,6 @@ import buildcraft.api.robots.EntityRobotBase; import buildcraft.core.inventory.filters.IStackFilter; import buildcraft.core.utils.IBlockFilter; import buildcraft.robots.ResourceIdBlock; -import buildcraft.robots.RobotRegistry; import buildcraft.robots.ai.AIRobotFetchAndEquipItemStack; import buildcraft.robots.ai.AIRobotGotoBlock; import buildcraft.robots.ai.AIRobotGotoSleep; @@ -66,24 +65,17 @@ public class BoardRobotFarmer extends RedstoneBoardRobot { @Override public void delegateAIEnded(AIRobot ai) { if (ai instanceof AIRobotSearchBlock) { - AIRobotSearchBlock searchAI = (AIRobotSearchBlock) ai; - - if (searchAI.blockFound != null - && RobotRegistry.getRegistry(robot.worldObj).take( - new ResourceIdBlock(searchAI.blockFound), robot)) { - ((AIRobotSearchBlock) ai).unreserve(); - - if (blockFound != null) { - robot.getRegistry().release(new ResourceIdBlock(blockFound)); - } - - blockFound = searchAI.blockFound; - startDelegateAI(new AIRobotGotoBlock(robot, searchAI.path)); - } else { - if (searchAI.blockFound != null) { - ((AIRobotSearchBlock) ai).unreserve(); - } + if (!ai.success()) { startDelegateAI(new AIRobotGotoSleep(robot)); + } else { + releaseBlockFound(); + AIRobotSearchBlock searchAI = (AIRobotSearchBlock) ai; + if (searchAI.takeResource()) { + blockFound = searchAI.blockFound; + startDelegateAI(new AIRobotGotoBlock(robot, searchAI.path)); + } else { + startDelegateAI(new AIRobotGotoSleep(robot)); + } } } else if (ai instanceof AIRobotGotoBlock) { startDelegateAI(new AIRobotUseToolOnBlock(robot, blockFound)); @@ -92,6 +84,12 @@ public class BoardRobotFarmer extends RedstoneBoardRobot { startDelegateAI(new AIRobotGotoSleep(robot)); } } else if (ai instanceof AIRobotUseToolOnBlock) { + releaseBlockFound(); + } + } + + private void releaseBlockFound() { + if (blockFound != null) { robot.getRegistry().release(new ResourceIdBlock(blockFound)); blockFound = null; } @@ -99,9 +97,7 @@ public class BoardRobotFarmer extends RedstoneBoardRobot { @Override public void end() { - if (blockFound != null) { - robot.getRegistry().release(new ResourceIdBlock(blockFound)); - } + releaseBlockFound(); } @Override diff --git a/common/buildcraft/robots/boards/BoardRobotGenericBreakBlock.java b/common/buildcraft/robots/boards/BoardRobotGenericBreakBlock.java index dd1ee60c..96d7f642 100644 --- a/common/buildcraft/robots/boards/BoardRobotGenericBreakBlock.java +++ b/common/buildcraft/robots/boards/BoardRobotGenericBreakBlock.java @@ -92,23 +92,28 @@ public abstract class BoardRobotGenericBreakBlock extends RedstoneBoardRobot { @Override public void delegateAIEnded(AIRobot ai) { if (ai instanceof AIRobotSearchBlock) { - if (indexStored != null) { - robot.getRegistry().release(new ResourceIdBlock(indexStored)); - } - - indexStored = ((AIRobotSearchBlock) ai).blockFound; - - if (indexStored == null) { + if (!ai.success()) { startDelegateAI(new AIRobotGotoSleep(robot)); } else { - if (robot.getRegistry().take(new ResourceIdBlock(indexStored), robot)) { - startDelegateAI(new AIRobotGotoBlock(robot, ((AIRobotSearchBlock) ai).path)); + releaseBlockFound(); + AIRobotSearchBlock searchAI = (AIRobotSearchBlock) ai; + if (searchAI.takeResource()) { + indexStored = searchAI.blockFound; + startDelegateAI(new AIRobotGotoBlock(robot, searchAI.path)); + } else { + startDelegateAI(new AIRobotGotoSleep(robot)); } - ((AIRobotSearchBlock) ai).unreserve(); } } else if (ai instanceof AIRobotGotoBlock) { startDelegateAI(new AIRobotBreak(robot, indexStored)); } else if (ai instanceof AIRobotBreak) { + releaseBlockFound(); + startDelegateAI(new AIRobotGotoSleep(robot)); + } + } + + private void releaseBlockFound() { + if (indexStored != null) { robot.getRegistry().release(new ResourceIdBlock(indexStored)); indexStored = null; } @@ -116,9 +121,7 @@ public abstract class BoardRobotGenericBreakBlock extends RedstoneBoardRobot { @Override public void end() { - if (indexStored != null) { - robot.getRegistry().release(new ResourceIdBlock(indexStored)); - } + releaseBlockFound(); } public final void updateFilter() { diff --git a/common/buildcraft/robots/boards/BoardRobotPlanter.java b/common/buildcraft/robots/boards/BoardRobotPlanter.java index 9ca92700..f636de55 100644 --- a/common/buildcraft/robots/boards/BoardRobotPlanter.java +++ b/common/buildcraft/robots/boards/BoardRobotPlanter.java @@ -36,7 +36,6 @@ import buildcraft.robots.ResourceIdBlock; import buildcraft.robots.ai.AIRobotFetchAndEquipItemStack; import buildcraft.robots.ai.AIRobotGotoBlock; import buildcraft.robots.ai.AIRobotGotoSleep; -import buildcraft.robots.ai.AIRobotSearchBlockBase; import buildcraft.robots.ai.AIRobotSearchRandomBlock; import buildcraft.robots.ai.AIRobotUseToolOnBlock; import buildcraft.robots.statements.ActionRobotFilter; @@ -122,28 +121,23 @@ public class BoardRobotPlanter extends RedstoneBoardRobot { @Override public void delegateAIEnded(AIRobot ai) { if (ai instanceof AIRobotSearchRandomBlock) { - AIRobotSearchBlockBase gotoBlock = (AIRobotSearchBlockBase) ai; - - if (gotoBlock.blockFound != null - && robot.getRegistry().take(new ResourceIdBlock(gotoBlock.blockFound), robot)) { - - if (blockFound != null) { - robot.getRegistry().release(new ResourceIdBlock(blockFound)); - } - - gotoBlock.unreserve(); - - blockFound = gotoBlock.blockFound; - gotoBlock.path.removeLast(); - startDelegateAI(new AIRobotGotoBlock(robot, gotoBlock.path)); - } else { - if (gotoBlock.blockFound != null) { - gotoBlock.unreserve(); - } + if (!ai.success()) { startDelegateAI(new AIRobotGotoSleep(robot)); + } else { + releaseBlockFound(); + AIRobotSearchRandomBlock searchAI = (AIRobotSearchRandomBlock) ai; + if (searchAI.takeResource()) { + blockFound = searchAI.blockFound; + searchAI.path.removeLast(); + startDelegateAI(new AIRobotGotoBlock(robot, searchAI.path)); + } else { + startDelegateAI(new AIRobotGotoSleep(robot)); + } } } else if (ai instanceof AIRobotGotoBlock) { startDelegateAI(new AIRobotUseToolOnBlock(robot, blockFound)); + } else if (ai instanceof AIRobotUseToolOnBlock) { + releaseBlockFound(); } else if (ai instanceof AIRobotFetchAndEquipItemStack) { if (robot.getHeldItem() == null) { startDelegateAI(new AIRobotGotoSleep(robot)); @@ -151,6 +145,13 @@ public class BoardRobotPlanter extends RedstoneBoardRobot { } } + private void releaseBlockFound() { + if (blockFound != null) { + robot.getRegistry().release(new ResourceIdBlock(blockFound)); + blockFound = null; + } + } + private static class PlantableFilter implements IStackFilter { @Override public boolean matches(ItemStack stack) { diff --git a/common/buildcraft/robots/boards/BoardRobotPump.java b/common/buildcraft/robots/boards/BoardRobotPump.java index 3fbcaa25..77dd1470 100644 --- a/common/buildcraft/robots/boards/BoardRobotPump.java +++ b/common/buildcraft/robots/boards/BoardRobotPump.java @@ -84,15 +84,14 @@ public class BoardRobotPump extends RedstoneBoardRobot { if (!ai.success()) { startDelegateAI(new AIRobotGotoSleep(robot)); } else { - blockFound = ((AIRobotSearchBlock) ai).blockFound; - - if (!robot.getRegistry().take(new ResourceIdBlock (blockFound), robot)) { - blockFound = null; - startDelegateAI(new AIRobotGotoSleep(robot)); + releaseBlockFound(); + AIRobotSearchBlock searchAI = (AIRobotSearchBlock) ai; + if (searchAI.takeResource()) { + blockFound = searchAI.blockFound; + startDelegateAI(new AIRobotGotoBlock(robot, searchAI.path)); } else { - startDelegateAI(new AIRobotGotoBlock(robot, ((AIRobotSearchBlock) ai).path)); + startDelegateAI(new AIRobotGotoSleep(robot)); } - ((AIRobotSearchBlock) ai).unreserve(); } } else if (ai instanceof AIRobotGotoBlock) { if (!ai.success()) { @@ -101,7 +100,7 @@ public class BoardRobotPump extends RedstoneBoardRobot { startDelegateAI(new AIRobotPumpBlock(robot, blockFound)); } } else if (ai instanceof AIRobotGotoStationAndUnloadFluids) { - robot.getRegistry().take(new ResourceIdBlock (blockFound), robot); + releaseBlockFound(); if (!ai.success()) { startDelegateAI(new AIRobotGotoSleep(robot)); @@ -109,6 +108,13 @@ public class BoardRobotPump extends RedstoneBoardRobot { } } + private void releaseBlockFound() { + if (blockFound != null) { + robot.getRegistry().release(new ResourceIdBlock(blockFound)); + blockFound = null; + } + } + public void updateFilter() { fluidFilter.clear(); diff --git a/common/buildcraft/robots/boards/BoardRobotStripes.java b/common/buildcraft/robots/boards/BoardRobotStripes.java index a6f7c463..aadf1051 100644 --- a/common/buildcraft/robots/boards/BoardRobotStripes.java +++ b/common/buildcraft/robots/boards/BoardRobotStripes.java @@ -20,7 +20,6 @@ import buildcraft.api.robots.EntityRobotBase; import buildcraft.core.inventory.filters.IStackFilter; import buildcraft.core.utils.IBlockFilter; import buildcraft.robots.ResourceIdBlock; -import buildcraft.robots.RobotRegistry; import buildcraft.robots.ai.AIRobotFetchAndEquipItemStack; import buildcraft.robots.ai.AIRobotGotoBlock; import buildcraft.robots.ai.AIRobotGotoSleep; @@ -63,24 +62,17 @@ public class BoardRobotStripes extends RedstoneBoardRobot { @Override public void delegateAIEnded(AIRobot ai) { if (ai instanceof AIRobotSearchRandomBlock) { - AIRobotSearchRandomBlock searchAI = (AIRobotSearchRandomBlock) ai; - - if (searchAI.blockFound != null - && RobotRegistry.getRegistry(robot.worldObj).take( - new ResourceIdBlock(searchAI.blockFound), robot)) { - searchAI.unreserve(); - - if (blockFound != null) { - robot.getRegistry().release(new ResourceIdBlock(blockFound)); - } - - blockFound = searchAI.blockFound; - startDelegateAI(new AIRobotGotoBlock(robot, searchAI.path)); - } else { - if (searchAI.blockFound != null) { - searchAI.unreserve(); - } + if (!ai.success()) { startDelegateAI(new AIRobotGotoSleep(robot)); + } else { + releaseBlockFound(); + AIRobotSearchRandomBlock searchAI = (AIRobotSearchRandomBlock) ai; + if (searchAI.takeResource()) { + blockFound = searchAI.blockFound; + startDelegateAI(new AIRobotGotoBlock(robot, searchAI.path)); + } else { + startDelegateAI(new AIRobotGotoSleep(robot)); + } } } else if (ai instanceof AIRobotGotoBlock) { startDelegateAI(new AIRobotStripesHandler(robot, blockFound)); @@ -89,6 +81,12 @@ public class BoardRobotStripes extends RedstoneBoardRobot { startDelegateAI(new AIRobotGotoSleep(robot)); } } else if (ai instanceof AIRobotStripesHandler) { + releaseBlockFound(); + } + } + + private void releaseBlockFound() { + if (blockFound != null) { robot.getRegistry().release(new ResourceIdBlock(blockFound)); blockFound = null; } diff --git a/common/buildcraft/robots/statements/ActionRobotGotoStation.java b/common/buildcraft/robots/statements/ActionRobotGotoStation.java index 9575e502..f4009be7 100644 --- a/common/buildcraft/robots/statements/ActionRobotGotoStation.java +++ b/common/buildcraft/robots/statements/ActionRobotGotoStation.java @@ -14,13 +14,13 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.common.util.ForgeDirection; import buildcraft.api.core.BlockIndex; +import buildcraft.api.items.IMapLocation; import buildcraft.api.robots.AIRobot; import buildcraft.api.statements.IActionInternal; import buildcraft.api.statements.IStatementContainer; import buildcraft.api.statements.IStatementParameter; import buildcraft.api.statements.StatementParameterItemStack; import buildcraft.api.transport.IPipeTile; -import buildcraft.core.ItemMapLocation; import buildcraft.core.statements.BCStatement; import buildcraft.core.utils.StringUtils; import buildcraft.robots.DockingStation; @@ -71,11 +71,12 @@ public class ActionRobotGotoStation extends BCStatement implements IActionIntern StatementParameterItemStack stackParam = (StatementParameterItemStack) parameters[0]; ItemStack item = stackParam.getItemStack(); - if (item != null && item.getItem() instanceof ItemMapLocation) { - BlockIndex index = ItemMapLocation.getBlockIndex(item); + if (item != null && item.getItem() instanceof IMapLocation) { + IMapLocation map = (IMapLocation) item.getItem(); + BlockIndex index = map.getPoint(item); if (index != null) { - ForgeDirection side = ItemMapLocation.getSide(item); + ForgeDirection side = map.getPointSide(item); DockingStation paramStation = (DockingStation) registry.getStation(index.x, index.y, index.z, side); diff --git a/common/buildcraft/robots/statements/ActionRobotWorkInArea.java b/common/buildcraft/robots/statements/ActionRobotWorkInArea.java index 0528549f..4ad70d9b 100755 --- a/common/buildcraft/robots/statements/ActionRobotWorkInArea.java +++ b/common/buildcraft/robots/statements/ActionRobotWorkInArea.java @@ -12,11 +12,11 @@ import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.item.ItemStack; import buildcraft.api.core.IZone; +import buildcraft.api.items.IMapLocation; import buildcraft.api.statements.IActionInternal; import buildcraft.api.statements.IStatementContainer; import buildcraft.api.statements.IStatementParameter; import buildcraft.api.statements.StatementParameterItemStack; -import buildcraft.core.ItemMapLocation; import buildcraft.core.statements.BCStatement; import buildcraft.core.utils.StringUtils; import buildcraft.transport.gates.StatementSlot; @@ -44,11 +44,12 @@ public class ActionRobotWorkInArea extends BCStatement implements IActionInterna ItemStack stack = slot.parameters[0].getItemStack(); - if (!(stack.getItem() instanceof ItemMapLocation)) { + if (stack == null || !(stack.getItem() instanceof IMapLocation)) { return null; } - return ItemMapLocation.getZone(stack); + IMapLocation map = (IMapLocation) stack.getItem(); + return map.getZone(stack); } @Override diff --git a/common/buildcraft/silicon/TileLaser.java b/common/buildcraft/silicon/TileLaser.java index fc2bfc38..67d816ac 100644 --- a/common/buildcraft/silicon/TileLaser.java +++ b/common/buildcraft/silicon/TileLaser.java @@ -137,7 +137,6 @@ public class TileLaser extends TileBuildCraft implements IHasWork, IControllable } protected boolean isValidTable() { - if (laserTarget == null || laserTarget.isInvalidTarget() || !laserTarget.requiresLaserEnergy()) { return false; } @@ -308,11 +307,11 @@ public class TileLaser extends TileBuildCraft implements IHasWork, IControllable public ResourceLocation getTexture() { double avg = powerAverage / POWER_AVERAGING; - if (avg <= 1.0) { + if (avg <= 10.0) { return EntityLaser.LASER_TEXTURES[0]; - } else if (avg <= 2.0) { + } else if (avg <= 20.0) { return EntityLaser.LASER_TEXTURES[1]; - } else if (avg <= 3.0) { + } else if (avg <= 30.0) { return EntityLaser.LASER_TEXTURES[2]; } else { return EntityLaser.LASER_TEXTURES[3]; diff --git a/common/buildcraft/silicon/boards/BoardProgrammingRecipe.java b/common/buildcraft/silicon/boards/BoardProgrammingRecipe.java index dd7eca0a..257266dd 100644 --- a/common/buildcraft/silicon/boards/BoardProgrammingRecipe.java +++ b/common/buildcraft/silicon/boards/BoardProgrammingRecipe.java @@ -1,6 +1,7 @@ package buildcraft.silicon.boards; import java.util.ArrayList; +import java.util.Collections; import java.util.Comparator; import java.util.List; import net.minecraft.item.ItemStack; @@ -38,7 +39,7 @@ public class BoardProgrammingRecipe implements IProgrammingRecipe { nbt.createBoard(NBTUtils.getItemData(stack)); options.add(stack); } - options.sort(new BoardSorter(this)); + Collections.sort(options, new BoardSorter(this)); return options; } diff --git a/common/buildcraft/transport/BlockGenericPipe.java b/common/buildcraft/transport/BlockGenericPipe.java index 15e03378..03687a73 100644 --- a/common/buildcraft/transport/BlockGenericPipe.java +++ b/common/buildcraft/transport/BlockGenericPipe.java @@ -55,6 +55,7 @@ import buildcraft.api.events.PipePlacedEvent; import buildcraft.api.events.RobotPlacementEvent; import buildcraft.api.gates.GateExpansions; import buildcraft.api.gates.IGateExpansion; +import buildcraft.api.items.IMapLocation; import buildcraft.api.tools.IToolWrench; import buildcraft.api.transport.IPipe; import buildcraft.api.transport.IPipeTile; @@ -64,7 +65,6 @@ import buildcraft.api.transport.pluggable.PipePluggable; import buildcraft.core.BlockBuildCraft; import buildcraft.core.CoreConstants; import buildcraft.core.CreativeTabBuildCraft; -import buildcraft.core.ItemMapLocation; import buildcraft.core.TileBuffer; import buildcraft.core.utils.MatrixTranformations; import buildcraft.core.utils.Utils; @@ -617,7 +617,7 @@ public class BlockGenericPipe extends BlockBuildCraft { // Only check the instance at this point. Call the IToolWrench // interface callbacks for the individual pipe/logic calls return pipe.blockActivated(player); - } else if (currentItem.getItem() instanceof ItemMapLocation) { + } else if (currentItem.getItem() instanceof IMapLocation) { // We want to be able to record pipe locations return false; } else if (PipeWire.RED.isPipeWire(currentItem)) { diff --git a/common/buildcraft/transport/PipeTransportPower.java b/common/buildcraft/transport/PipeTransportPower.java index 510cf39b..6f809568 100644 --- a/common/buildcraft/transport/PipeTransportPower.java +++ b/common/buildcraft/transport/PipeTransportPower.java @@ -193,54 +193,56 @@ public class PipeTransportPower extends PipeTransport { for (int j = 0; j < 6; ++j) { if (j != i && powerQuery[j] > 0) { Object ep = getEnergyProvider(j); - if (ep instanceof TileGenericPipe || ep instanceof IEnergyReceiver || ep instanceof IEnergyHandler) { + if (ep instanceof IPipeTile || ep instanceof IEnergyReceiver || ep instanceof IEnergyHandler) { totalPowerQuery += powerQuery[j]; } } } - for (int j = 0; j < 6; ++j) { - if (j != i && powerQuery[j] > 0) { - Object ep = getEnergyProvider(j); - int watts = (int) Math.floor(internalPower[i] * powerQuery[j] / totalPowerQuery); + if (totalPowerQuery > 0) { + for (int j = 0; j < 6; ++j) { + if (j != i && powerQuery[j] > 0) { + Object ep = getEnergyProvider(j); + int watts = (int) Math.floor(internalPower[i] * powerQuery[j] / totalPowerQuery); - if (ep instanceof IPipeTile) { - Pipe nearbyPipe = (Pipe) ((IPipeTile) ep).getPipe(); - PipeTransportPower nearbyTransport = (PipeTransportPower) nearbyPipe.transport; - watts = nearbyTransport.receiveEnergy( - ForgeDirection.VALID_DIRECTIONS[j].getOpposite(), - watts); - internalPower[i] -= watts; - } else if (ep instanceof IEnergyHandler) { - IEnergyHandler handler = (IEnergyHandler) ep; - if (handler.canConnectEnergy(ForgeDirection.VALID_DIRECTIONS[j].getOpposite())) { - watts = handler.receiveEnergy(ForgeDirection.VALID_DIRECTIONS[j].getOpposite(), - watts, false); - internalPower[i] -= watts; - } - } else if (ep instanceof IEnergyReceiver) { - IEnergyReceiver handler = (IEnergyReceiver) ep; - if (handler.canConnectEnergy(ForgeDirection.VALID_DIRECTIONS[j].getOpposite())) { - watts = handler.receiveEnergy(ForgeDirection.VALID_DIRECTIONS[j].getOpposite(), - watts, false); + if (ep instanceof IPipeTile) { + Pipe nearbyPipe = (Pipe) ((IPipeTile) ep).getPipe(); + PipeTransportPower nearbyTransport = (PipeTransportPower) nearbyPipe.transport; + watts = nearbyTransport.receiveEnergy( + ForgeDirection.VALID_DIRECTIONS[j].getOpposite(), + watts); internalPower[i] -= watts; + } else if (ep instanceof IEnergyHandler) { + IEnergyHandler handler = (IEnergyHandler) ep; + if (handler.canConnectEnergy(ForgeDirection.VALID_DIRECTIONS[j].getOpposite())) { + watts = handler.receiveEnergy(ForgeDirection.VALID_DIRECTIONS[j].getOpposite(), + watts, false); + internalPower[i] -= watts; + } + } else if (ep instanceof IEnergyReceiver) { + IEnergyReceiver handler = (IEnergyReceiver) ep; + if (handler.canConnectEnergy(ForgeDirection.VALID_DIRECTIONS[j].getOpposite())) { + watts = handler.receiveEnergy(ForgeDirection.VALID_DIRECTIONS[j].getOpposite(), + watts, false); + internalPower[i] -= watts; + } } + + displayPower[j] += watts; + displayPower[i] += watts; } - - displayPower[j] += watts; - displayPower[i] += watts; } } } } - double highestPower = 0.0; + float highestPower = 0.0F; for (int i = 0; i < 6; i++) { - displayPower[i] = (short) ((prevDisplayPower[i] * (DISPLAY_SMOOTHING - 1.0F) + displayPower[i]) / DISPLAY_SMOOTHING); + displayPower[i] = (short) Math.floor((float) (prevDisplayPower[i] * (DISPLAY_SMOOTHING - 1) + displayPower[i]) / DISPLAY_SMOOTHING); if (displayPower[i] > highestPower) { highestPower = displayPower[i]; } } - overload += highestPower > ((double) maxPower) * 0.95 ? 1 : -1; + overload += highestPower > ((float) maxPower) * 0.95F ? 1 : -1; if (overload < 0) { overload = 0; } @@ -248,7 +250,7 @@ public class PipeTransportPower extends PipeTransport { overload = OVERLOAD_TICKS; } - // Compute the tiles requesting energy that are not power pipes + // Compute the tiles requesting energy that are not power pipes for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { if (!outputOpen(dir)) { continue; @@ -295,17 +297,15 @@ public class PipeTransportPower extends PipeTransport { // Transfer the requested energy to nearby pipes for (int i = 0; i < 6; ++i) { - if (transferQuery[i] != 0) { - if (tiles[i] != null) { - TileEntity entity = tiles[i]; - if (entity instanceof TileGenericPipe) { - TileGenericPipe nearbyTile = (TileGenericPipe) entity; - if (nearbyTile.pipe == null) { - continue; - } - PipeTransportPower nearbyTransport = (PipeTransportPower) nearbyTile.pipe.transport; - nearbyTransport.requestEnergy(ForgeDirection.VALID_DIRECTIONS[i].getOpposite(), transferQuery[i]); + if (transferQuery[i] != 0 && tiles[i] != null) { + TileEntity entity = tiles[i]; + if (entity instanceof IPipeTile) { + IPipeTile nearbyTile = (IPipeTile) entity; + if (nearbyTile.getPipe() == null) { + continue; } + PipeTransportPower nearbyTransport = (PipeTransportPower) ((Pipe) nearbyTile.getPipe()).transport; + nearbyTransport.requestEnergy(ForgeDirection.VALID_DIRECTIONS[i].getOpposite(), transferQuery[i]); } } } diff --git a/common/buildcraft/transport/PipeTriggerProvider.java b/common/buildcraft/transport/PipeTriggerProvider.java index e59e796a..74809760 100644 --- a/common/buildcraft/transport/PipeTriggerProvider.java +++ b/common/buildcraft/transport/PipeTriggerProvider.java @@ -14,8 +14,6 @@ import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; -import cofh.api.energy.IEnergyHandler; - import buildcraft.BuildCraftCore; import buildcraft.api.statements.IStatementContainer; import buildcraft.api.statements.ITriggerExternal; @@ -74,11 +72,6 @@ public class PipeTriggerProvider implements ITriggerProvider { public LinkedList getExternalTriggers(ForgeDirection side, TileEntity tile) { LinkedList result = new LinkedList(); - if (tile instanceof IEnergyHandler && ((IEnergyHandler) tile).getMaxEnergyStored(side) > 0) { - result.add((ITriggerExternal) BuildCraftCore.triggerEnergyHigh); - result.add((ITriggerExternal) BuildCraftCore.triggerEnergyLow); - } - return result; } } diff --git a/common/buildcraft/transport/pipes/PipeItemsStripes.java b/common/buildcraft/transport/pipes/PipeItemsStripes.java index 279b0c0c..75094328 100644 --- a/common/buildcraft/transport/pipes/PipeItemsStripes.java +++ b/common/buildcraft/transport/pipes/PipeItemsStripes.java @@ -37,13 +37,9 @@ import buildcraft.transport.PipeTransportItems; import buildcraft.transport.TileGenericPipe; import buildcraft.transport.TravelingItem; import buildcraft.transport.pipes.events.PipeEventItem; -import buildcraft.transport.stripes.StripesHandlerDefault; import buildcraft.transport.utils.TransportUtils; public class PipeItemsStripes extends Pipe implements IEnergyHandler, IStripesPipe { - - private static IStripesHandler defaultItemsHandler = new StripesHandlerDefault(); - public PipeItemsStripes(Item item) { super(new PipeTransportItems(), item); } @@ -112,11 +108,6 @@ public class PipeItemsStripes extends Pipe implements IEnerg } } } - - if (defaultItemsHandler.handle(getWorld(), (int) p.x, (int) p.y, (int) p.z, - event.direction, stack, player, this)) { - event.entity = null; - } } @Override diff --git a/common/buildcraft/transport/render/FacadeBlockAccess.java b/common/buildcraft/transport/render/FacadeBlockAccess.java index 9d205911..7a79e10a 100644 --- a/common/buildcraft/transport/render/FacadeBlockAccess.java +++ b/common/buildcraft/transport/render/FacadeBlockAccess.java @@ -8,6 +8,7 @@ import net.minecraft.world.biome.BiomeGenBase; import net.minecraftforge.common.util.ForgeDirection; import buildcraft.api.transport.pluggable.IFacadePluggable; import buildcraft.api.transport.pluggable.PipePluggable; +import buildcraft.compat.CompatHooks; import buildcraft.transport.BlockGenericPipe; import buildcraft.transport.TileGenericPipe; @@ -22,12 +23,15 @@ public class FacadeBlockAccess implements IBlockAccess { @Override public Block getBlock(int x, int y, int z) { - //System.out.println("Querying block at " + x + ", " + y + ", " + z); + Block compatBlock = CompatHooks.INSTANCE.getVisualBlock(world, x, y, z, side); + if (compatBlock != null) { + return compatBlock; + } + TileEntity tile = world.getTileEntity(x, y, z); if (tile instanceof TileGenericPipe) { PipePluggable p = ((TileGenericPipe) tile).getPipePluggable(side); if (p instanceof IFacadePluggable) { - //System.out.println("Found facade"); return ((IFacadePluggable) p).getCurrentBlock(); } } @@ -46,7 +50,11 @@ public class FacadeBlockAccess implements IBlockAccess { @Override public int getBlockMetadata(int x, int y, int z) { - //System.out.println("Querying block metadata at " + x + ", " + y + ", " + z); + int compatMeta = CompatHooks.INSTANCE.getVisualMeta(world, x, y, z, side); + if (compatMeta >= 0) { + return compatMeta; + } + TileEntity tile = world.getTileEntity(x, y, z); if (tile instanceof TileGenericPipe) { PipePluggable p = ((TileGenericPipe) tile).getPipePluggable(side); diff --git a/common/buildcraft/transport/stripes/StripesHandlerEntityInteract.java b/common/buildcraft/transport/stripes/StripesHandlerEntityInteract.java index c0e6b689..420b4eb8 100644 --- a/common/buildcraft/transport/stripes/StripesHandlerEntityInteract.java +++ b/common/buildcraft/transport/stripes/StripesHandlerEntityInteract.java @@ -66,7 +66,7 @@ public class StripesHandlerEntityInteract implements IStripesHandler { successful = true; dropItemsExcept(stack, player, activator, direction); } - if (stack.stackSize > 0) { + if (stack.stackSize > 0 && successful) { activator.sendItem(stack, direction.getOpposite()); } diff --git a/common/buildcraft/transport/stripes/StripesHandlerDefault.java b/common/buildcraft/transport/stripes/StripesHandlerHoe.java similarity index 71% rename from common/buildcraft/transport/stripes/StripesHandlerDefault.java rename to common/buildcraft/transport/stripes/StripesHandlerHoe.java index f8860e52..709c5112 100644 --- a/common/buildcraft/transport/stripes/StripesHandlerDefault.java +++ b/common/buildcraft/transport/stripes/StripesHandlerHoe.java @@ -9,38 +9,36 @@ package buildcraft.transport.stripes; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemHoe; import net.minecraft.item.ItemStack; import net.minecraft.world.World; - import net.minecraftforge.common.util.ForgeDirection; - import buildcraft.api.transport.IStripesActivator; import buildcraft.api.transport.IStripesHandler; -public class StripesHandlerDefault implements IStripesHandler { +public class StripesHandlerHoe implements IStripesHandler { @Override public StripesHandlerType getType() { return StripesHandlerType.ITEM_USE; } - + @Override public boolean shouldHandle(ItemStack stack) { - return true; + return stack.getItem() instanceof ItemHoe; } @Override public boolean handle(World world, int x, int y, int z, ForgeDirection direction, ItemStack stack, EntityPlayer player, IStripesActivator activator) { - if (!world.isAirBlock(x, y, z)) { - return false; + if (!world.isAirBlock(x, y - 1, z) && stack.tryPlaceItemIntoWorld(player, world, x, y - 1, z, 1, 0.0f, 0.0f, 0.0f)) { + if (stack.stackSize > 0) { + activator.sendItem(stack, direction.getOpposite()); + } + return true; } - if (!stack.tryPlaceItemIntoWorld(player, world, x, y - 1, z, 1, 0.0f, 0.0f, 0.0f)) { - return false; - } - activator.sendItem(stack, direction.getOpposite()); - return true; + return false; } } diff --git a/common/buildcraft/transport/stripes/StripesHandlerPlaceBlock.java b/common/buildcraft/transport/stripes/StripesHandlerPlaceBlock.java index 2ae8def7..0c83b0a0 100644 --- a/common/buildcraft/transport/stripes/StripesHandlerPlaceBlock.java +++ b/common/buildcraft/transport/stripes/StripesHandlerPlaceBlock.java @@ -34,10 +34,10 @@ public class StripesHandlerPlaceBlock implements IStripesHandler { public boolean handle(World world, int x, int y, int z, ForgeDirection direction, ItemStack stack, EntityPlayer player, IStripesActivator activator) { - if (!world.isAirBlock(x, y, z)) { - return false; + if (!world.isAirBlock(x, y, z) && stack.tryPlaceItemIntoWorld(player, world, x, y, z, 1, 0.0f, 0.0f, 0.0f)) { + return true; } - return stack.tryPlaceItemIntoWorld(player, world, x, y, z, 1, 0.0f, 0.0f, 0.0f); + return false; } }