diff --git a/build.gradle b/build.gradle index 402f98de..7a4ca6f2 100755 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ buildscript { } } dependencies { - classpath 'net.minecraftforge.gradle:ForgeGradle:1.1-SNAPSHOT' + classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT' } } @@ -26,7 +26,7 @@ group= "com.mod-buildcraft" archivesBaseName = "buildcraft" // the name that all artifacts will use as a base. artifacts names follow this pattern: [baseName]-[appendix]-[version]-[classifier].[extension] minecraft { - version = "1.7.2-10.12.0.1047" // McVersion-ForgeVersion this variable is later changed to contain only the MC version, while the apiVersion variable is used for the forge version. Yeah its stupid, and will be changed eentually. + version = "1.7.2-10.12.1.1060" // McVersion-ForgeVersion this variable is later changed to contain only the MC version, while the apiVersion variable is used for the forge version. Yeah its stupid, and will be changed eentually. assetDir = "run/assets" // the place for ForgeGradle to download the assets. The assets that the launcher gets and stuff diff --git a/buildcraft_resources/assets/buildcraft/lang/en_US.lang b/buildcraft_resources/assets/buildcraft/lang/en_US.lang index 9be648c0..21102245 100755 --- a/buildcraft_resources/assets/buildcraft/lang/en_US.lang +++ b/buildcraft_resources/assets/buildcraft/lang/en_US.lang @@ -98,6 +98,7 @@ gui.heat=Heat gui.assemblyRate=Energy Rate gui.assemblyCurrentRequired=Energy Required gui.clickcraft=-Click to Craft- +gui.pipes.emerald.title=Filters gui.pipes.emerald.blocking=Blocking gui.pipes.emerald.blocking.tip=Extraction is blocked if one element in filter is missing gui.pipes.emerald.nonblocking=Non Blocking diff --git a/buildcraft_resources/assets/buildcraft/textures/gui/icon_button.png b/buildcraft_resources/assets/buildcraft/textures/gui/icon_button.png new file mode 100644 index 00000000..36e215a3 Binary files /dev/null and b/buildcraft_resources/assets/buildcraft/textures/gui/icon_button.png differ diff --git a/buildcraft_resources/assets/buildcraft/textures/gui/logemerald_pipe_gui.png b/buildcraft_resources/assets/buildcraft/textures/gui/logemerald_pipe_gui.png deleted file mode 100644 index 3d62f71e..00000000 Binary files a/buildcraft_resources/assets/buildcraft/textures/gui/logemerald_pipe_gui.png and /dev/null differ diff --git a/buildcraft_resources/assets/buildcraft/textures/gui/filter_2.png b/buildcraft_resources/assets/buildcraft/textures/gui/pipe_emerald.png similarity index 54% rename from buildcraft_resources/assets/buildcraft/textures/gui/filter_2.png rename to buildcraft_resources/assets/buildcraft/textures/gui/pipe_emerald.png index 47cebdd4..a6f8e848 100644 Binary files a/buildcraft_resources/assets/buildcraft/textures/gui/filter_2.png and b/buildcraft_resources/assets/buildcraft/textures/gui/pipe_emerald.png differ diff --git a/common/buildcraft/BuildCraftSilicon.java b/common/buildcraft/BuildCraftSilicon.java index 4a953b1f..8cb4fc72 100644 --- a/common/buildcraft/BuildCraftSilicon.java +++ b/common/buildcraft/BuildCraftSilicon.java @@ -152,8 +152,8 @@ public class BuildCraftSilicon extends BuildCraftMod { BuildcraftRecipes.assemblyTable.addRecipe(10000, ItemGate.makeGateItem(GateMaterial.REDSTONE, GateLogic.AND), Chipset.RED.getStack(), PipeWire.RED.getStack()); addGateRecipe(20000, GateMaterial.IRON, Chipset.IRON, PipeWire.RED, PipeWire.BLUE); - addGateRecipe(40000, GateMaterial.GOLD, Chipset.GOLD, PipeWire.RED, PipeWire.BLUE, PipeWire.YELLOW); - addGateRecipe(80000, GateMaterial.DIAMOND, Chipset.DIAMOND, PipeWire.RED, PipeWire.BLUE, PipeWire.YELLOW, PipeWire.GREEN); + addGateRecipe(40000, GateMaterial.GOLD, Chipset.GOLD, PipeWire.RED, PipeWire.BLUE, PipeWire.GREEN); + addGateRecipe(80000, GateMaterial.DIAMOND, Chipset.DIAMOND, PipeWire.RED, PipeWire.BLUE, PipeWire.GREEN, PipeWire.YELLOW); // REVERSAL RECIPES EnumSet materials = EnumSet.allOf(GateMaterial.class); diff --git a/common/buildcraft/builders/BlockBlueprintLibrary.java b/common/buildcraft/builders/BlockBlueprintLibrary.java index 77384dc1..bf2fa20f 100644 --- a/common/buildcraft/builders/BlockBlueprintLibrary.java +++ b/common/buildcraft/builders/BlockBlueprintLibrary.java @@ -42,12 +42,15 @@ public class BlockBlueprintLibrary extends BlockContainer { if (entityplayer.isSneaking()) return false; - TileBlueprintLibrary tile = (TileBlueprintLibrary) world.getTileEntity(i, j, k); + TileEntity tile = world.getTileEntity(i, j, k); + if (tile instanceof TileBlueprintLibrary) { + TileBlueprintLibrary tileBlueprint = (TileBlueprintLibrary)tile; + if (!tileBlueprint.locked || entityplayer.getDisplayName().equals(tileBlueprint.owner)) + if (!world.isRemote) { + entityplayer.openGui(BuildCraftBuilders.instance, GuiIds.BLUEPRINT_LIBRARY, world, i, j, k); + } + } - if (!tile.locked || entityplayer.getDisplayName().equals(tile.owner)) - if (!world.isRemote) { - entityplayer.openGui(BuildCraftBuilders.instance, GuiIds.BLUEPRINT_LIBRARY, world, i, j, k); - } return true; } @@ -71,8 +74,9 @@ public class BlockBlueprintLibrary extends BlockContainer { @Override public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityliving, ItemStack stack) { if (!world.isRemote && entityliving instanceof EntityPlayer) { - TileBlueprintLibrary tile = (TileBlueprintLibrary) world.getTileEntity(i, j, k); - tile.owner = ((EntityPlayer) entityliving).getDisplayName(); + TileEntity tile = world.getTileEntity(i, j, k); + if (tile instanceof TileBlueprintLibrary) + ((TileBlueprintLibrary)tile).owner = ((EntityPlayer) entityliving).getDisplayName(); } } diff --git a/common/buildcraft/builders/BlockMarker.java b/common/buildcraft/builders/BlockMarker.java index 8d98f479..8b81fae9 100644 --- a/common/buildcraft/builders/BlockMarker.java +++ b/common/buildcraft/builders/BlockMarker.java @@ -85,7 +85,9 @@ public class BlockMarker extends BlockContainer { @Override public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int par6, float par7, float par8, float par9) { - ((TileMarker) world.getTileEntity(i, j, k)).tryConnection(); + TileEntity tile = world.getTileEntity(i, j, k); + if (tile instanceof TileMarker) + ((TileMarker) tile).tryConnection(); return true; } @@ -112,7 +114,9 @@ public class BlockMarker extends BlockContainer { @Override public void onNeighborBlockChange(World world, int x, int y, int z, Block block) { - ((TileMarker) world.getTileEntity(x, y, z)).updateSignals(); + TileEntity tile = world.getTileEntity(x, y, z); + if (tile instanceof TileMarker) + ((TileMarker) tile).updateSignals(); dropTorchIfCantStay(world, x, y, z); } diff --git a/common/buildcraft/core/gui/buttons/GuiImageButton.java b/common/buildcraft/core/gui/buttons/GuiImageButton.java new file mode 100644 index 00000000..b3f69c12 --- /dev/null +++ b/common/buildcraft/core/gui/buttons/GuiImageButton.java @@ -0,0 +1,154 @@ +/** + * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ + +package buildcraft.core.gui.buttons; + +import java.util.ArrayList; +import java.util.Locale; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.util.ResourceLocation; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import org.lwjgl.opengl.GL11; + +import buildcraft.core.DefaultProps; + +@SideOnly(Side.CLIENT) +public class GuiImageButton extends GuiButton implements IButtonClickEventTrigger { + + public enum ButtonImage { + BLANK(1, 19), + WHITE_LIST(19, 19), + BLACK_LIST(37, 19), + ROUND_ROBIN(55, 19); + + private final int u, v; + + ButtonImage(int u, int v) { + this.u = u; + this.v = v; + } + + public int getU(){ + return u; + } + + public int getV(){ + return v; + } + } + + public static final ResourceLocation ICON_BUTTON_TEXTURES = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_GUI + "/icon_button.png"); + + public static final int SIZE = 18; + + private ArrayList listeners = new ArrayList(); + private ButtonImage image = ButtonImage.BLANK; + private boolean active = false; + + public GuiImageButton(int id, int x, int y, ButtonImage image) { + super(id, x, y, SIZE, SIZE, ""); + + this.image = image; + } + + public boolean IsActive() + { + return active; + } + + public void Activate() + { + active = true; + } + + public void DeActivate() + { + active = false; + } + + @Override + public void drawButton(Minecraft minecraft, int x, int y) { + + if (!visible) { + return; + } + + minecraft.renderEngine.bindTexture(ICON_BUTTON_TEXTURES); + + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + + int buttonState = getButtonState(x, y); + + drawTexturedModalRect(xPosition, yPosition, buttonState * SIZE, 0, SIZE, SIZE); + + drawTexturedModalRect(xPosition + 1, yPosition + 1, image.getU(), image.getV(), SIZE - 2, SIZE - 2); + + mouseDragged(minecraft, x, y); + } + + @Override + public boolean mousePressed(Minecraft par1Minecraft, int par2, int par3) { + boolean pressed = super.mousePressed(par1Minecraft, par2, par3); + + if (pressed) { + active = !active; + notifyAllListeners(); + } + + return pressed; + } + + @Override + public void registerListener(IButtonClickEventListener listener) { + listeners.add(listener); + } + + @Override + public void removeListener(IButtonClickEventListener listener) { + listeners.remove(listener); + } + + @Override + public void notifyAllListeners() { + for (IButtonClickEventListener listener : listeners) { + listener.handleButtonClick(this, this.id); + } + } + + private int getButtonState(int mouseX, int mouseY) { + if (!this.enabled) { + return 0; + } + + if (isMouseOverButton(mouseX, mouseY)) { + if (!this.active) { + return 2; + } + else { + return 4; + } + } + + if (!this.active) { + return 1; + } + else { + return 3; + } + } + + private boolean isMouseOverButton(int mouseX, int mouseY) { + return mouseX >= xPosition && mouseY >= yPosition && mouseX < xPosition + SIZE && mouseY < yPosition + SIZE; + } +} diff --git a/common/buildcraft/core/gui/buttons/IButtonClickEventListener.java b/common/buildcraft/core/gui/buttons/IButtonClickEventListener.java new file mode 100644 index 00000000..960d0c0f --- /dev/null +++ b/common/buildcraft/core/gui/buttons/IButtonClickEventListener.java @@ -0,0 +1,14 @@ +/** + * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ + +package buildcraft.core.gui.buttons; + +public interface IButtonClickEventListener { + public void handleButtonClick(IButtonClickEventTrigger button, int buttonId); +} diff --git a/common/buildcraft/core/gui/buttons/IButtonClickEventTrigger.java b/common/buildcraft/core/gui/buttons/IButtonClickEventTrigger.java new file mode 100644 index 00000000..1060414e --- /dev/null +++ b/common/buildcraft/core/gui/buttons/IButtonClickEventTrigger.java @@ -0,0 +1,16 @@ +/** + * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ + +package buildcraft.core.gui.buttons; + +public interface IButtonClickEventTrigger { + public void registerListener(IButtonClickEventListener listener); + public void removeListener(IButtonClickEventListener listener); + public void notifyAllListeners(); +} diff --git a/common/buildcraft/energy/BlockEngine.java b/common/buildcraft/energy/BlockEngine.java index 652dd7bb..d633203d 100644 --- a/common/buildcraft/energy/BlockEngine.java +++ b/common/buildcraft/energy/BlockEngine.java @@ -8,13 +8,11 @@ */ package buildcraft.energy; -import buildcraft.BuildCraftCore; -import buildcraft.core.BlockBuildCraft; -import buildcraft.core.CreativeTabBuildCraft; -import buildcraft.core.ICustomHighlight; -import buildcraft.core.IItemPipe; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; +import static net.minecraft.util.AxisAlignedBB.getBoundingBox; + +import java.util.List; +import java.util.Random; + import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; @@ -31,11 +29,13 @@ import net.minecraft.util.Vec3; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; - -import java.util.List; -import java.util.Random; - -import static net.minecraft.util.AxisAlignedBB.getBoundingBox; +import buildcraft.BuildCraftCore; +import buildcraft.core.BlockBuildCraft; +import buildcraft.core.CreativeTabBuildCraft; +import buildcraft.core.ICustomHighlight; +import buildcraft.core.IItemPipe; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; public class BlockEngine extends BlockBuildCraft implements ICustomHighlight { @@ -121,7 +121,7 @@ public class BlockEngine extends BlockBuildCraft implements ICustomHighlight { @Override public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer player, int side, float par7, float par8, float par9) { - TileEngine tile = (TileEngine) world.getTileEntity(i, j, k); + TileEntity tile = world.getTileEntity(i, j, k); // REMOVED DUE TO CREATIVE ENGINE REQUIREMENTS - dmillerw // Drop through if the player is sneaking @@ -137,7 +137,7 @@ public class BlockEngine extends BlockBuildCraft implements ICustomHighlight { } if (tile instanceof TileEngine) { - return tile.onBlockActivated(player, ForgeDirection.getOrientation(side)); + return ((TileEngine) tile).onBlockActivated(player, ForgeDirection.getOrientation(side)); } return false; @@ -204,11 +204,13 @@ public class BlockEngine extends BlockBuildCraft implements ICustomHighlight { @Override public void onPostBlockPlaced(World world, int x, int y, int z, int par5) { - TileEngine tile = (TileEngine) world.getTileEntity(x, y, z); - tile.orientation = ForgeDirection.UP; - - if (!tile.isOrientationValid()) { - tile.switchOrientation(true); + TileEntity tile = world.getTileEntity(x, y, z); + if (tile instanceof TileEngine) { + TileEngine engine = (TileEngine)tile; + engine.orientation = ForgeDirection.UP; + if (!engine.isOrientationValid()) { + engine.switchOrientation(true); + } } } @@ -220,9 +222,9 @@ public class BlockEngine extends BlockBuildCraft implements ICustomHighlight { @SuppressWarnings({"all"}) @Override public void randomDisplayTick(World world, int i, int j, int k, Random random) { - TileEngine tile = (TileEngine) world.getTileEntity(i, j, k); + TileEntity tile = world.getTileEntity(i, j, k); - if (!tile.isBurning()) { + if (tile instanceof TileEngine && !((TileEngine) tile).isBurning()) { return; } @@ -252,10 +254,10 @@ public class BlockEngine extends BlockBuildCraft implements ICustomHighlight { @Override public void onNeighborBlockChange(World world, int x, int y, int z, Block block) { - TileEngine tile = (TileEngine) world.getTileEntity(x, y, z); + TileEntity tile = world.getTileEntity(x, y, z); - if (tile != null) { - tile.checkRedstonePower(); + if (tile instanceof TileEngine) { + ((TileEngine) tile).checkRedstonePower(); } } diff --git a/common/buildcraft/energy/worldgen/OilPopulate.java b/common/buildcraft/energy/worldgen/OilPopulate.java index a1d8dc50..0deec4f7 100644 --- a/common/buildcraft/energy/worldgen/OilPopulate.java +++ b/common/buildcraft/energy/worldgen/OilPopulate.java @@ -19,6 +19,7 @@ import java.util.Set; import net.minecraft.block.Block; import net.minecraft.block.BlockFlower; +import net.minecraft.block.BlockStaticLiquid; import net.minecraft.block.material.Material; import net.minecraft.init.Blocks; import net.minecraft.world.World; @@ -260,7 +261,7 @@ public class OilPopulate { private boolean isReplaceableFluid(World world, int x, int y, int z) { Block block = world.getBlock(x, y, z); - return (block instanceof BlockFluidBase || block instanceof IFluidBlock) && block.getMaterial() != Material.lava; + return (block instanceof BlockStaticLiquid || block instanceof BlockFluidBase || block instanceof IFluidBlock) && block.getMaterial() != Material.lava; } private boolean isOil(World world, int x, int y, int z) { @@ -357,6 +358,10 @@ public class OilPopulate { continue; } + if (block instanceof BlockStaticLiquid) { + return y; + } + if (block instanceof BlockFluidBase) { return y; } diff --git a/common/buildcraft/factory/BlockQuarry.java b/common/buildcraft/factory/BlockQuarry.java index 2357d127..bbece4cb 100644 --- a/common/buildcraft/factory/BlockQuarry.java +++ b/common/buildcraft/factory/BlockQuarry.java @@ -54,8 +54,9 @@ public class BlockQuarry extends BlockBuildCraft { world.setBlockMetadataWithNotify(i, j, k, orientation.getOpposite().ordinal(), 1); if (entityliving instanceof EntityPlayer) { - TileQuarry tq = (TileQuarry) world.getTileEntity(i, j, k); - tq.placedBy = (EntityPlayer) entityliving; + TileEntity tile = world.getTileEntity(i, j, k); + if (tile instanceof TileQuarry) + ((TileQuarry) tile).placedBy = (EntityPlayer) entityliving; } } diff --git a/common/buildcraft/factory/BlockTank.java b/common/buildcraft/factory/BlockTank.java index 25e92b7a..4ab454a1 100644 --- a/common/buildcraft/factory/BlockTank.java +++ b/common/buildcraft/factory/BlockTank.java @@ -89,44 +89,47 @@ public class BlockTank extends BlockContainer { if (current != null) { FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(current); - TileTank tank = (TileTank) world.getTileEntity(i, j, k); + TileEntity tile = world.getTileEntity(i, j, k); + if(tile instanceof TileTank) + { + TileTank tank = (TileTank)tile; + // Handle filled containers + if (liquid != null) { + int qty = tank.fill(ForgeDirection.UNKNOWN, liquid, true); - // Handle filled containers - if (liquid != null) { - int qty = tank.fill(ForgeDirection.UNKNOWN, liquid, true); + if (qty != 0 && !BuildCraftCore.debugMode && !entityplayer.capabilities.isCreativeMode) { + entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, InvUtils.consumeItem(current)); + } - if (qty != 0 && !BuildCraftCore.debugMode && !entityplayer.capabilities.isCreativeMode) { - entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, InvUtils.consumeItem(current)); - } + return true; - return true; + // Handle empty containers + } else { + FluidStack available = tank.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid; - // Handle empty containers - } else { - FluidStack available = tank.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid; + if (available != null) { + ItemStack filled = FluidContainerRegistry.fillFluidContainer(available, current); - if (available != null) { - ItemStack filled = FluidContainerRegistry.fillFluidContainer(available, current); + liquid = FluidContainerRegistry.getFluidForFilledItem(filled); - liquid = FluidContainerRegistry.getFluidForFilledItem(filled); - - if (liquid != null) { - if (!BuildCraftCore.debugMode && !entityplayer.capabilities.isCreativeMode) { - if (current.stackSize > 1) { - if (!entityplayer.inventory.addItemStackToInventory(filled)) - return false; - else { + if (liquid != null) { + if (!BuildCraftCore.debugMode && !entityplayer.capabilities.isCreativeMode) { + if (current.stackSize > 1) { + if (!entityplayer.inventory.addItemStackToInventory(filled)) { + return false; + } else { + entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, InvUtils.consumeItem(current)); + } + } else { entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, InvUtils.consumeItem(current)); + entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, filled); } - } else { - entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, InvUtils.consumeItem(current)); - entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, filled); } + + tank.drain(ForgeDirection.UNKNOWN, liquid.amount, true); + + return true; } - - tank.drain(ForgeDirection.UNKNOWN, liquid.amount, true); - - return true; } } } diff --git a/common/buildcraft/transport/BlockGenericPipe.java b/common/buildcraft/transport/BlockGenericPipe.java index 697d9084..32ae3033 100644 --- a/common/buildcraft/transport/BlockGenericPipe.java +++ b/common/buildcraft/transport/BlockGenericPipe.java @@ -1123,9 +1123,12 @@ public class BlockGenericPipe extends BlockBuildCraft { boolean placed = world.setBlock(i, j, k, block, meta, 3); if (placed) { - TileGenericPipe tile = (TileGenericPipe) world.getTileEntity(i, j, k); - tile.initialize(pipe); - tile.sendUpdateToClient(); + TileEntity tile = world.getTileEntity(i, j, k); + if (tile instanceof TileGenericPipe) { + TileGenericPipe tilePipe = (TileGenericPipe) tile; + tilePipe.initialize(pipe); + tilePipe.sendUpdateToClient(); + } } return placed; diff --git a/common/buildcraft/transport/PipeConnectionBans.java b/common/buildcraft/transport/PipeConnectionBans.java index 53bf43ab..632e46d9 100644 --- a/common/buildcraft/transport/PipeConnectionBans.java +++ b/common/buildcraft/transport/PipeConnectionBans.java @@ -9,9 +9,11 @@ package buildcraft.transport; import buildcraft.transport.pipes.PipeFluidsCobblestone; +import buildcraft.transport.pipes.PipeFluidsEmerald; import buildcraft.transport.pipes.PipeFluidsStone; import buildcraft.transport.pipes.PipeFluidsWood; import buildcraft.transport.pipes.PipeItemsCobblestone; +import buildcraft.transport.pipes.PipeItemsEmerald; import buildcraft.transport.pipes.PipeItemsEmzuli; import buildcraft.transport.pipes.PipeItemsObsidian; import buildcraft.transport.pipes.PipeItemsQuartz; @@ -33,11 +35,15 @@ public class PipeConnectionBans { banConnection(PipeFluidsStone.class, PipeFluidsCobblestone.class); banConnection(PipeFluidsWood.class); + + banConnection(PipeFluidsEmerald.class); // Item Pipes banConnection(PipeItemsStone.class, PipeItemsCobblestone.class, PipeItemsQuartz.class); banConnection(PipeItemsWood.class); + + banConnection(PipeItemsEmerald.class); banConnection(PipeItemsObsidian.class); diff --git a/common/buildcraft/transport/PipeTransportFluids.java b/common/buildcraft/transport/PipeTransportFluids.java index 5fd79865..d2d32d61 100644 --- a/common/buildcraft/transport/PipeTransportFluids.java +++ b/common/buildcraft/transport/PipeTransportFluids.java @@ -337,7 +337,7 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler private void moveFluids() { short newTimeSlot = (short) (container.getWorldObj().getTotalWorldTime() % travelDelay); - short outputCount = computeCurrentConnectionStatesAndTickFlows(newTimeSlot); + short outputCount = computeCurrentConnectionStatesAndTickFlows(newTimeSlot > 0 && newTimeSlot < travelDelay ? newTimeSlot : 0); moveFromPipe(outputCount); moveFromCenter(outputCount); moveToCenter(); diff --git a/common/buildcraft/transport/gui/ContainerEmeraldPipe.java b/common/buildcraft/transport/gui/ContainerEmeraldPipe.java index 7acbc334..7e21c0cf 100644 --- a/common/buildcraft/transport/gui/ContainerEmeraldPipe.java +++ b/common/buildcraft/transport/gui/ContainerEmeraldPipe.java @@ -33,12 +33,12 @@ public class ContainerEmeraldPipe extends BuildCraftContainer { for (int l = 0; l < 3; l++) { for (int k1 = 0; k1 < 9; k1++) { - addSlotToContainer(new Slot(playerInventory, k1 + l * 9 + 9, 8 + k1 * 18, 50 + l * 18)); + addSlotToContainer(new Slot(playerInventory, k1 + l * 9 + 9, 8 + k1 * 18, 79 + l * 18)); } } for (int i1 = 0; i1 < 9; i1++) { - addSlotToContainer(new Slot(playerInventory, i1, 8 + i1 * 18, 108)); + addSlotToContainer(new Slot(playerInventory, i1, 8 + i1 * 18, 137)); } } diff --git a/common/buildcraft/transport/gui/GuiEmeraldPipe.java b/common/buildcraft/transport/gui/GuiEmeraldPipe.java index 00c91dff..8cab020f 100644 --- a/common/buildcraft/transport/gui/GuiEmeraldPipe.java +++ b/common/buildcraft/transport/gui/GuiEmeraldPipe.java @@ -15,30 +15,42 @@ import org.lwjgl.opengl.GL11; import buildcraft.core.DefaultProps; import buildcraft.core.gui.GuiBuildCraft; -import buildcraft.core.gui.buttons.GuiMultiButton; +import buildcraft.core.gui.buttons.GuiImageButton; +import buildcraft.core.gui.buttons.IButtonClickEventTrigger; +import buildcraft.core.gui.buttons.IButtonClickEventListener; import buildcraft.core.network.PacketGuiReturn; -import buildcraft.core.proxy.CoreProxy; import buildcraft.core.utils.StringUtils; import buildcraft.transport.pipes.PipeItemsEmerald; +import buildcraft.transport.pipes.PipeItemsEmerald.EmeraldPipeSettings; +import buildcraft.transport.pipes.PipeItemsEmerald.FilterMode; -public class GuiEmeraldPipe extends GuiBuildCraft { +public class GuiEmeraldPipe extends GuiBuildCraft implements IButtonClickEventListener { - private static final ResourceLocation TEXTURE = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_GUI + "/filter_2.png"); - private GuiMultiButton button; + private static final ResourceLocation TEXTURE = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_GUI + "/pipe_emerald.png"); + + private static final int WHITE_LIST_BUTTON_ID = 1; + private static final int BLACK_LIST_BUTTON_ID = 2; + private static final int ROUND_ROBIN_BUTTON_ID = 3; + + private GuiImageButton whiteListButton; + private GuiImageButton blackListButton; + private GuiImageButton roundRobinButton; IInventory playerInventory; IInventory filterInventory; + PipeItemsEmerald pipe; public GuiEmeraldPipe(IInventory playerInventory, PipeItemsEmerald pipe) { super(new ContainerEmeraldPipe(playerInventory, pipe), pipe.getFilters(), TEXTURE); this.pipe = pipe; + this.playerInventory = playerInventory; this.filterInventory = pipe.getFilters(); xSize = 175; - ySize = 132; + ySize = 161; } @Override @@ -46,24 +58,74 @@ public class GuiEmeraldPipe extends GuiBuildCraft { super.initGui(); this.buttonList.clear(); - this.button = new GuiMultiButton(0, this.guiLeft + this.xSize - (80 + 6), this.guiTop + 34, 80, this.pipe.getStateController().copy()); - this.buttonList.add(this.button); + + this.whiteListButton = new GuiImageButton(WHITE_LIST_BUTTON_ID, this.guiLeft + 7, this.guiTop + 41, GuiImageButton.ButtonImage.WHITE_LIST); + this.whiteListButton.registerListener(this); + this.buttonList.add(this.whiteListButton); + + this.blackListButton = new GuiImageButton(BLACK_LIST_BUTTON_ID, this.guiLeft + 7 + 18, this.guiTop + 41, GuiImageButton.ButtonImage.BLACK_LIST); + this.blackListButton.registerListener(this); + this.buttonList.add(this.blackListButton); + + this.roundRobinButton = new GuiImageButton(ROUND_ROBIN_BUTTON_ID, this.guiLeft + 7 + 36, this.guiTop + 41, GuiImageButton.ButtonImage.ROUND_ROBIN); + this.roundRobinButton.registerListener(this); + this.buttonList.add(this.roundRobinButton); + + switch (pipe.getSettings().getFilterMode()) { + case WHITE_LIST: + this.whiteListButton.Activate(); + break; + case BLACK_LIST: + this.blackListButton.Activate(); + break; + case ROUND_ROBIN: + this.roundRobinButton.Activate(); + break; + } } @Override public void onGuiClosed() { if (pipe.getWorld().isRemote) { - pipe.getStateController().setCurrentState(button.getController().getCurrentState()); PacketGuiReturn pkt = new PacketGuiReturn(pipe.getContainer()); pkt.sendPacket(); } super.onGuiClosed(); } + + @Override + public void handleButtonClick(IButtonClickEventTrigger sender, int buttonId) { + switch (buttonId) { + case WHITE_LIST_BUTTON_ID: + whiteListButton.Activate(); + blackListButton.DeActivate(); + roundRobinButton.DeActivate(); + + pipe.getSettings().setFilterMode(FilterMode.WHITE_LIST); + break; + case BLACK_LIST_BUTTON_ID: + whiteListButton.DeActivate(); + blackListButton.Activate(); + roundRobinButton.DeActivate(); + + pipe.getSettings().setFilterMode(FilterMode.BLACK_LIST); + break; + case ROUND_ROBIN_BUTTON_ID: + whiteListButton.DeActivate(); + blackListButton.DeActivate(); + roundRobinButton.Activate(); + + pipe.getSettings().setFilterMode(FilterMode.ROUND_ROBIN); + break; + } + } @Override protected void drawGuiContainerForegroundLayer(int par1, int par2) { - fontRendererObj.drawString(filterInventory.getInventoryName(), getCenteredOffset(filterInventory.getInventoryName()), 6, 0x404040); + String title = StringUtils.localize("gui.pipes.emerald.title"); + + fontRendererObj.drawString(title, (xSize - fontRendererObj.getStringWidth(title)) / 2, 6, 0x404040); fontRendererObj.drawString(StringUtils.localize("gui.inventory"), 8, ySize - 93, 0x404040); } diff --git a/common/buildcraft/transport/pipes/PipeItemsEmerald.java b/common/buildcraft/transport/pipes/PipeItemsEmerald.java index c5b051f3..15f51773 100644 --- a/common/buildcraft/transport/pipes/PipeItemsEmerald.java +++ b/common/buildcraft/transport/pipes/PipeItemsEmerald.java @@ -12,62 +12,58 @@ import io.netty.buffer.ByteBuf; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; import buildcraft.BuildCraftTransport; import buildcraft.core.GuiIds; -import buildcraft.core.gui.buttons.IButtonTextureSet; -import buildcraft.core.gui.buttons.IMultiButtonState; -import buildcraft.core.gui.buttons.MultiButtonController; -import buildcraft.core.gui.buttons.StandardButtonTextureSets; -import buildcraft.core.gui.tooltips.ToolTip; -import buildcraft.core.gui.tooltips.ToolTipLine; import buildcraft.core.inventory.InvUtils; +import buildcraft.core.inventory.InventoryWrapper; import buildcraft.core.inventory.SimpleInventory; +import buildcraft.core.inventory.StackHelper; import buildcraft.core.network.IClientState; import buildcraft.core.network.IGuiReturnHandler; -import buildcraft.core.utils.StringUtils; import buildcraft.core.utils.Utils; import buildcraft.transport.BlockGenericPipe; import buildcraft.transport.PipeIconProvider; public class PipeItemsEmerald extends PipeItemsWood implements IClientState, IGuiReturnHandler { - public static enum ButtonState implements IMultiButtonState { - - BLOCKING("gui.pipes.emerald.blocking"), NONBLOCKING("gui.pipes.emerald.nonblocking"); - private final String label; - - private ButtonState(String label) { - this.label = label; - } - - @Override - public String getLabel() { - return StringUtils.localize(this.label); - } - - @Override - public IButtonTextureSet getTextureSet() { - return StandardButtonTextureSets.SMALL_BUTTON; - } - - @Override - public ToolTip getToolTip() { - return this.tip; - } - private final ToolTip tip = new ToolTip(500) { - @Override - public void refresh() { - clear(); - tip.add(new ToolTipLine(StringUtils.localize(label + ".tip"))); - } - }; + public enum FilterMode { + WHITE_LIST, BLACK_LIST, ROUND_ROBIN; } - private final MultiButtonController stateController = MultiButtonController.getController(ButtonState.BLOCKING.ordinal(), ButtonState.values()); + + public class EmeraldPipeSettings { + + private FilterMode filterMode; + + public EmeraldPipeSettings() { + filterMode = FilterMode.WHITE_LIST; + } + + public FilterMode getFilterMode() { + return filterMode; + } + + public void setFilterMode(FilterMode mode) { + filterMode = mode; + } + + public void readFromNBT(NBTTagCompound nbt) { + filterMode = FilterMode.values()[nbt.getByte("filterMode")]; + } + + public void writeToNBT(NBTTagCompound nbt) { + nbt.setByte("filterMode", (byte) filterMode.ordinal()); + } + } + + private EmeraldPipeSettings settings = new EmeraldPipeSettings(); + private final SimpleInventory filters = new SimpleInventory(9, "Filters", 1); + private int currentFilter = 0; public PipeItemsEmerald(Item item) { @@ -96,34 +92,100 @@ public class PipeItemsEmerald extends PipeItemsWood implements IClientState, IGu return true; } - /** - * Return the itemstack that can be if something can be extracted from this - * inventory, null if none. On certain cases, the extractable slot depends - * on the position of the pipe. - */ @Override public ItemStack[] checkExtract(IInventory inventory, boolean doRemove, ForgeDirection from) { - IInventory inv = InvUtils.getInventory(inventory); - ItemStack result = checkExtractGeneric(inv, doRemove, from); - - // check through every filter once if non-blocking - if (doRemove - && stateController.getButtonState() == ButtonState.NONBLOCKING - && result == null) { - int count = 1; - while (result == null && count < filters.getSizeInventory()) { - incrementFilter(); - result = checkExtractGeneric(inv, doRemove, from); - count++; - } + if (inventory == null) { + return null; } - if (result != null) { - return new ItemStack[] { result }; + // Handle possible double chests and wrap it in the ISidedInventory interface. + ISidedInventory sidedInventory = InventoryWrapper.getWrappedInventory(InvUtils.getInventory(inventory)); + + if (settings.getFilterMode() == FilterMode.ROUND_ROBIN) { + return checkExtractRoundRobin(sidedInventory, doRemove, from); + } + + return checkExtractFiltered(sidedInventory, doRemove, from); + } + + private ItemStack[] checkExtractFiltered(ISidedInventory inventory, boolean doRemove, ForgeDirection from) { + for (int k : inventory.getAccessibleSlotsFromSide(from.ordinal())) { + ItemStack stack = inventory.getStackInSlot(k); + + if (stack == null || stack.stackSize <= 0) { + continue; + } + + if (!inventory.canExtractItem(k, stack, from.ordinal())) { + continue; + } + + boolean matches = isFiltered(stack); + boolean isBlackList = settings.getFilterMode() == FilterMode.BLACK_LIST; + + if ((isBlackList && matches) || (!isBlackList && !matches)) { + continue; + } + + if (doRemove) { + double energyUsed = mjStored > stack.stackSize ? stack.stackSize : mjStored; + mjStored -= energyUsed; + + stack = inventory.decrStackSize(k, (int) Math.floor(energyUsed)); + } + + return new ItemStack[]{ stack }; } return null; + } + private ItemStack[] checkExtractRoundRobin(ISidedInventory inventory, boolean doRemove, ForgeDirection from) { + for (int i : inventory.getAccessibleSlotsFromSide(from.ordinal())) { + ItemStack stack = inventory.getStackInSlot(i); + + if (stack != null && stack.stackSize > 0) { + ItemStack filter = getCurrentFilter(); + + if (filter == null) { + return null; + } + + if (!StackHelper.instance().isMatchingItem(filter, stack, true, false)) { + continue; + } + + if (!inventory.canExtractItem(i, stack, from.ordinal())) { + continue; + } + + if (doRemove) { + // In Round Robin mode, extract only 1 item regardless of power level. + stack = inventory.decrStackSize(i, 1); + incrementFilter(); + } + + return new ItemStack[]{ stack }; + } + } + + return null; + } + + private boolean isFiltered(ItemStack stack) { + for (int i = 0; i < filters.getSizeInventory(); i++) { + ItemStack filter = filters.getStackInSlot(i); + + if (filter == null) { + return false; + } + + if (StackHelper.instance().isMatchingItem(filter, stack, true, false)) { + return true; + } + } + + return false; } private void incrementFilter() { @@ -143,56 +205,14 @@ public class PipeItemsEmerald extends PipeItemsWood implements IClientState, IGu return filters.getStackInSlot(currentFilter % filters.getSizeInventory()); } - @Override - public ItemStack checkExtractGeneric(net.minecraft.inventory.ISidedInventory inventory, boolean doRemove, ForgeDirection from) { - for (int i : inventory.getAccessibleSlotsFromSide(from.ordinal())) { - ItemStack stack = inventory.getStackInSlot(i); - if (stack != null && stack.stackSize > 0) { - ItemStack filter = getCurrentFilter(); - if (filter == null) { - return null; - } - if (!filter.isItemEqual(stack)) { - continue; - } - if (!inventory.canExtractItem(i, stack, from.ordinal())) { - continue; - } - if (doRemove) { - incrementFilter(); - double energyUsed = mjStored > stack.stackSize ? stack.stackSize : mjStored; - mjStored -= energyUsed; - - return inventory.decrStackSize(i, (int) energyUsed); - } else { - return stack; - } - } - } - - return null; + public IInventory getFilters() { + return filters; } - /* SAVING & LOADING */ - @Override - public void readFromNBT(NBTTagCompound nbt) { - super.readFromNBT(nbt); - filters.readFromNBT(nbt); - currentFilter = nbt.getInteger("currentFilter"); - - stateController.readFromNBT(nbt, "state"); + public EmeraldPipeSettings getSettings() { + return settings; } - @Override - public void writeToNBT(NBTTagCompound nbt) { - super.writeToNBT(nbt); - filters.writeToNBT(nbt); - nbt.setInteger("currentFilter", currentFilter); - - stateController.writeToNBT(nbt, "state"); - } - - // ICLIENTSTATE @Override public void writeData(ByteBuf data) { NBTTagCompound nbt = new NBTTagCompound(); @@ -206,21 +226,33 @@ public class PipeItemsEmerald extends PipeItemsWood implements IClientState, IGu readFromNBT(nbt); } - public IInventory getFilters() { - return filters; + @Override + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + + filters.readFromNBT(nbt); + settings.readFromNBT(nbt); + + currentFilter = nbt.getInteger("currentFilter"); } - public MultiButtonController getStateController() { - return stateController; + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + + filters.writeToNBT(nbt); + settings.writeToNBT(nbt); + + nbt.setInteger("currentFilter", currentFilter); } @Override public void writeGuiData(ByteBuf data) { - data.writeByte(stateController.getCurrentState()); + data.writeByte((byte)settings.getFilterMode().ordinal()); } @Override public void readGuiData(ByteBuf data, EntityPlayer sender) { - stateController.setCurrentState(data.readByte()); + settings.setFilterMode(FilterMode.values()[data.readByte()]); } }