Adding FilteredBuffer

This commit is contained in:
SandGrainOne 2013-06-29 19:03:36 +02:00
parent 8867512f38
commit 370c33ee70
17 changed files with 489 additions and 2 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -109,3 +109,4 @@ tile.oilStill=Oil
tile.spring.water=Water Spring tile.spring.water=Water Spring
tile.spring.oil=Oil Spring tile.spring.oil=Oil Spring
tile.oilMoving=Oil tile.oilMoving=Oil
tile.filteredBufferBlock=Filtered Buffer

Binary file not shown.

After

Width:  |  Height:  |  Size: 494 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 323 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 B

View file

@ -30,6 +30,7 @@ import buildcraft.core.Version;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.triggers.BCAction; import buildcraft.core.triggers.BCAction;
import buildcraft.core.triggers.BCTrigger; import buildcraft.core.triggers.BCTrigger;
import buildcraft.transport.BlockFilteredBuffer;
import buildcraft.transport.BlockGenericPipe; import buildcraft.transport.BlockGenericPipe;
import buildcraft.transport.GateIconProvider; import buildcraft.transport.GateIconProvider;
import buildcraft.transport.GuiHandler; import buildcraft.transport.GuiHandler;
@ -77,6 +78,7 @@ import buildcraft.transport.pipes.PipeStructureCobblestone;
import buildcraft.transport.triggers.ActionEnergyPulser; import buildcraft.transport.triggers.ActionEnergyPulser;
import buildcraft.transport.triggers.ActionSignalOutput; import buildcraft.transport.triggers.ActionSignalOutput;
import buildcraft.transport.triggers.ActionSingleEnergyPulse; import buildcraft.transport.triggers.ActionSingleEnergyPulse;
import buildcraft.transport.triggers.TriggerFilteredBufferInventoryLevel;
import buildcraft.transport.triggers.TriggerPipeContents; import buildcraft.transport.triggers.TriggerPipeContents;
import buildcraft.transport.triggers.TriggerPipeContents.Kind; import buildcraft.transport.triggers.TriggerPipeContents.Kind;
import buildcraft.transport.triggers.TriggerPipeSignal; import buildcraft.transport.triggers.TriggerPipeSignal;
@ -142,6 +144,7 @@ public class BuildCraftTransport {
public static Item pipePowerDiamond; public static Item pipePowerDiamond;
public static Item facadeItem; public static Item facadeItem;
public static Item plugItem; public static Item plugItem;
public static BlockFilteredBuffer filteredBufferBlock;
// public static Item pipeItemsStipes; // public static Item pipeItemsStipes;
public static Item pipeStructureCobblestone; public static Item pipeStructureCobblestone;
public static int groupItemsTrigger; public static int groupItemsTrigger;
@ -159,6 +162,9 @@ public class BuildCraftTransport {
public static BCTrigger triggerGreenSignalInactive = new TriggerPipeSignal(DefaultProps.TRIGGER_GREEN_SIGNAL_INACTIVE, false, IPipe.WireColor.Green); public static BCTrigger triggerGreenSignalInactive = new TriggerPipeSignal(DefaultProps.TRIGGER_GREEN_SIGNAL_INACTIVE, false, IPipe.WireColor.Green);
public static BCTrigger triggerYellowSignalActive = new TriggerPipeSignal(DefaultProps.TRIGGER_YELLOW_SIGNAL_ACTIVE, true, IPipe.WireColor.Yellow); public static BCTrigger triggerYellowSignalActive = new TriggerPipeSignal(DefaultProps.TRIGGER_YELLOW_SIGNAL_ACTIVE, true, IPipe.WireColor.Yellow);
public static BCTrigger triggerYellowSignalInactive = new TriggerPipeSignal(DefaultProps.TRIGGER_YELLOW_SIGNAL_INACTIVE, false, IPipe.WireColor.Yellow); public static BCTrigger triggerYellowSignalInactive = new TriggerPipeSignal(DefaultProps.TRIGGER_YELLOW_SIGNAL_INACTIVE, false, IPipe.WireColor.Yellow);
public static BCTrigger triggerInventoryBelow25 = new TriggerFilteredBufferInventoryLevel(DefaultProps.TRIGGER_INVENTORY_LEVEL_BELOW25, TriggerFilteredBufferInventoryLevel.State.Below25);
public static BCTrigger triggerInventoryBelow50 = new TriggerFilteredBufferInventoryLevel(DefaultProps.TRIGGER_INVENTORY_LEVEL_BELOW50, TriggerFilteredBufferInventoryLevel.State.Below50);
public static BCTrigger triggerInventoryBelow75 = new TriggerFilteredBufferInventoryLevel(DefaultProps.TRIGGER_INVENTORY_LEVEL_BELOW75, TriggerFilteredBufferInventoryLevel.State.Below75);
public static BCAction actionRedSignal = new ActionSignalOutput(DefaultProps.ACTION_RED_SIGNAL, IPipe.WireColor.Red); public static BCAction actionRedSignal = new ActionSignalOutput(DefaultProps.ACTION_RED_SIGNAL, IPipe.WireColor.Red);
public static BCAction actionBlueSignal = new ActionSignalOutput(DefaultProps.ACTION_BLUE_SIGNAL, IPipe.WireColor.Blue); public static BCAction actionBlueSignal = new ActionSignalOutput(DefaultProps.ACTION_BLUE_SIGNAL, IPipe.WireColor.Blue);
public static BCAction actionGreenSignal = new ActionSignalOutput(DefaultProps.ACTION_GREEN_SIGNAL, IPipe.WireColor.Green); public static BCAction actionGreenSignal = new ActionSignalOutput(DefaultProps.ACTION_GREEN_SIGNAL, IPipe.WireColor.Green);
@ -349,6 +355,12 @@ public class BuildCraftTransport {
Property pipePlugId = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_ITEM, "pipePlug.id", DefaultProps.PIPE_PLUG_ID); Property pipePlugId = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_ITEM, "pipePlug.id", DefaultProps.PIPE_PLUG_ID);
plugItem = new ItemPlug(pipePlugId.getInt()); plugItem = new ItemPlug(pipePlugId.getInt());
plugItem.setUnlocalizedName("pipePlug"); plugItem.setUnlocalizedName("pipePlug");
Property filteredBufferId = BuildCraftCore.mainConfiguration.getBlock("filteredBuffer.id", DefaultProps.FILTERED_BUFFER);
filteredBufferBlock = new BlockFilteredBuffer(filteredBufferId.getInt());
CoreProxy.proxy.registerBlock(filteredBufferBlock.setUnlocalizedName("filteredBufferBlock"));
CoreProxy.proxy.addName(filteredBufferBlock, "Filtered Buffer");
AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[]{new ItemStack(pipeStructureCobblestone)}, 1000, new ItemStack(plugItem, 8))); AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(new ItemStack[]{new ItemStack(pipeStructureCobblestone)}, 1000, new ItemStack(plugItem, 8)));
} finally { } finally {
@ -412,6 +424,11 @@ public class BuildCraftTransport {
CoreProxy.proxy.addCraftingRecipe(pipe.result, pipe.input); CoreProxy.proxy.addCraftingRecipe(pipe.result, pipe.input);
} }
} }
CoreProxy.proxy.addCraftingRecipe(new ItemStack(filteredBufferBlock, 1),
new Object[] { "wdw", "wcw", "wpw", Character.valueOf('w'), "plankWood", Character.valueOf('d'),
BuildCraftTransport.pipeItemsDiamond, Character.valueOf('c'), Block.chest, Character.valueOf('p'),
Block.pistonBase });
} }
@IMCCallback @IMCCallback

View file

@ -116,6 +116,7 @@ public class DefaultProps {
public static int OIL_MOVING_ID = 1520; public static int OIL_MOVING_ID = 1520;
public static int OIL_STILL_ID = 1521; public static int OIL_STILL_ID = 1521;
public static int SPRING_ID = 1522; public static int SPRING_ID = 1522;
public static int FILTERED_BUFFER = 1523;
public static boolean CURRENT_CONTINUOUS = false; public static boolean CURRENT_CONTINUOUS = false;
public static double PIPES_DURABILITY = 0.25D; public static double PIPES_DURABILITY = 0.25D;
@ -154,6 +155,9 @@ public class DefaultProps {
public static int TRIGGER_RED_ENGINE_HEAT = 28; public static int TRIGGER_RED_ENGINE_HEAT = 28;
public static int TRIGGER_PIPE_REQUESTS_ENERGY = 29; public static int TRIGGER_PIPE_REQUESTS_ENERGY = 29;
public static int TRIGGER_PIPE_TOO_MUCH_ENERGY = 30; public static int TRIGGER_PIPE_TOO_MUCH_ENERGY = 30;
public static int TRIGGER_INVENTORY_LEVEL_BELOW25 = 31;
public static int TRIGGER_INVENTORY_LEVEL_BELOW50 = 32;
public static int TRIGGER_INVENTORY_LEVEL_BELOW75 = 33;
public static int ACTION_REDSTONE = 1; public static int ACTION_REDSTONE = 1;
public static int ACTION_RED_SIGNAL = 2; public static int ACTION_RED_SIGNAL = 2;

View file

@ -20,4 +20,5 @@ public class GuiIds {
public static final int GATES = 51; public static final int GATES = 51;
public static final int PIPE_EMERALD_ITEM = 52; public static final int PIPE_EMERALD_ITEM = 52;
public static final int FILTERED_BUFFER = 60;
} }

View file

@ -42,8 +42,11 @@ public class ActionTriggerIconProvider implements IIconProvider {
public static final int Trigger_RedstoneInput_Inactive = 30; public static final int Trigger_RedstoneInput_Inactive = 30;
public static final int Trigger_PipeContents_RequestsEnergy = 31; public static final int Trigger_PipeContents_RequestsEnergy = 31;
public static final int Trigger_PipeContents_TooMuchEnergy = 32; public static final int Trigger_PipeContents_TooMuchEnergy = 32;
public static final int Trigger_Inventory_Below25 = 33;
public static final int Trigger_Inventory_Below50 = 34;
public static final int Trigger_Inventory_Below75 = 35;
public static final int MAX = 33; public static final int MAX = 36;
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
@ -94,6 +97,9 @@ public class ActionTriggerIconProvider implements IIconProvider {
icons[ActionTriggerIconProvider.Trigger_PipeSignal_Yellow_Inactive] = iconRegister.registerIcon("buildcraft:triggers/trigger_pipesignal_yellow_inactive"); icons[ActionTriggerIconProvider.Trigger_PipeSignal_Yellow_Inactive] = iconRegister.registerIcon("buildcraft:triggers/trigger_pipesignal_yellow_inactive");
icons[ActionTriggerIconProvider.Trigger_RedstoneInput_Active] = iconRegister.registerIcon("buildcraft:triggers/trigger_redstoneinput_active"); icons[ActionTriggerIconProvider.Trigger_RedstoneInput_Active] = iconRegister.registerIcon("buildcraft:triggers/trigger_redstoneinput_active");
icons[ActionTriggerIconProvider.Trigger_RedstoneInput_Inactive] = iconRegister.registerIcon("buildcraft:triggers/trigger_redstoneinput_inactive"); icons[ActionTriggerIconProvider.Trigger_RedstoneInput_Inactive] = iconRegister.registerIcon("buildcraft:triggers/trigger_redstoneinput_inactive");
icons[ActionTriggerIconProvider.Trigger_Inventory_Below25] = iconRegister.registerIcon("buildcraft:triggers/trigger_inventory_below25");
icons[ActionTriggerIconProvider.Trigger_Inventory_Below50] = iconRegister.registerIcon("buildcraft:triggers/trigger_inventory_below50");
icons[ActionTriggerIconProvider.Trigger_Inventory_Below75] = iconRegister.registerIcon("buildcraft:triggers/trigger_inventory_below75");
} }
} }

View file

@ -0,0 +1,74 @@
package buildcraft.transport;
import java.util.ArrayList;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import buildcraft.BuildCraftTransport;
import buildcraft.core.BlockBuildCraft;
import buildcraft.core.GuiIds;
import buildcraft.core.IItemPipe;
import buildcraft.core.proxy.CoreProxy;
public class BlockFilteredBuffer extends BlockBuildCraft {
private static Icon blockTexture;
public BlockFilteredBuffer(int blockId) {
super(blockId, Material.iron);
setHardness(5F);
}
@Override
public TileEntity createNewTileEntity(World var1) {
return new TileFilteredBuffer();
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer,
int par6, float par7, float par8, float par9) {
super.onBlockActivated(world, x, y, z, entityplayer, par6, par7, par8, par9);
if (entityplayer.isSneaking()) {
return false;
}
if (entityplayer.getCurrentEquippedItem() != null) {
if (entityplayer.getCurrentEquippedItem().getItem() instanceof IItemPipe) {
return false;
}
}
if (!CoreProxy.proxy.isRenderWorld(world)) {
entityplayer.openGui(BuildCraftTransport.instance, GuiIds.FILTERED_BUFFER, world, x, y, z);
}
return true;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void addCreativeItems(ArrayList itemList) {
itemList.add(new ItemStack(this));
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister) {
blockTexture = par1IconRegister.registerIcon("buildcraft:filteredBuffer_all");
}
@Override
@SideOnly(Side.CLIENT)
public Icon getIcon(int i, int j) {
return blockTexture;
}
}

View file

@ -7,9 +7,11 @@ import net.minecraft.world.World;
import buildcraft.core.GuiIds; import buildcraft.core.GuiIds;
import buildcraft.transport.gui.ContainerDiamondPipe; import buildcraft.transport.gui.ContainerDiamondPipe;
import buildcraft.transport.gui.ContainerEmeraldPipe; import buildcraft.transport.gui.ContainerEmeraldPipe;
import buildcraft.transport.gui.ContainerFilteredBuffer;
import buildcraft.transport.gui.ContainerGateInterface; import buildcraft.transport.gui.ContainerGateInterface;
import buildcraft.transport.gui.GuiDiamondPipe; import buildcraft.transport.gui.GuiDiamondPipe;
import buildcraft.transport.gui.GuiEmeraldPipe; import buildcraft.transport.gui.GuiEmeraldPipe;
import buildcraft.transport.gui.GuiFilteredBuffer;
import buildcraft.transport.gui.GuiGateInterface; import buildcraft.transport.gui.GuiGateInterface;
import buildcraft.transport.pipes.PipeLogicDiamond; import buildcraft.transport.pipes.PipeLogicDiamond;
import cpw.mods.fml.common.network.IGuiHandler; import cpw.mods.fml.common.network.IGuiHandler;
@ -22,6 +24,12 @@ public class GuiHandler implements IGuiHandler {
return null; return null;
TileEntity tile = world.getBlockTileEntity(x, y, z); TileEntity tile = world.getBlockTileEntity(x, y, z);
if (tile instanceof TileFilteredBuffer) {
TileFilteredBuffer filteredBuffer = (TileFilteredBuffer) tile;
return new ContainerFilteredBuffer(player.inventory, filteredBuffer);
}
if (!(tile instanceof TileGenericPipe)) if (!(tile instanceof TileGenericPipe))
return null; return null;
@ -51,6 +59,12 @@ public class GuiHandler implements IGuiHandler {
return null; return null;
TileEntity tile = world.getBlockTileEntity(x, y, z); TileEntity tile = world.getBlockTileEntity(x, y, z);
if (tile instanceof TileFilteredBuffer) {
TileFilteredBuffer filteredBuffer = (TileFilteredBuffer) tile;
return new GuiFilteredBuffer(player.inventory, filteredBuffer);
}
if (!(tile instanceof TileGenericPipe)) if (!(tile instanceof TileGenericPipe))
return null; return null;

View file

@ -0,0 +1,130 @@
package buildcraft.transport;
import java.util.LinkedList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import buildcraft.BuildCraftTransport;
import buildcraft.api.gates.IOverrideDefaultTriggers;
import buildcraft.api.gates.ITrigger;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.inventory.SimpleInventory;
public class TileFilteredBuffer extends TileBuildCraft implements IInventory, IOverrideDefaultTriggers {
private final SimpleInventory inventoryFilters = new SimpleInventory(9, "FilteredBufferFilters", 1);
private final SimpleInventory inventoryStorage = new SimpleInventory(9, "FilteredBufferStorage", 64);
@Override
public void updateEntity() {
super.updateEntity();
}
public IInventory getFilters() {
return inventoryFilters;
}
/** IInventory Implementation **/
@Override
public int getSizeInventory() {
return inventoryStorage.getSizeInventory();
}
@Override
public ItemStack getStackInSlot(int slotId) {
return inventoryStorage.getStackInSlot(slotId);
}
@Override
public ItemStack decrStackSize(int slotId, int count) {
return inventoryStorage.decrStackSize(slotId, count);
}
@Override
public ItemStack getStackInSlotOnClosing(int slotId) {
return inventoryStorage.getStackInSlotOnClosing(slotId);
}
@Override
public void setInventorySlotContents(int slotId, ItemStack itemStack) {
inventoryStorage.setInventorySlotContents(slotId, itemStack);
}
@Override
public String getInvName() {
return inventoryStorage.getInvName();
}
@Override
public int getInventoryStackLimit() {
return inventoryStorage.getInventoryStackLimit();
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityPlayer) {
return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this;
}
@Override
public void openChest() {
}
@Override
public void closeChest() {
}
@Override
public boolean isStackValidForSlot(int i, ItemStack itemstack) {
ItemStack filterItemStack = inventoryFilters.getStackInSlot(i);
if ( filterItemStack == null || filterItemStack.itemID != itemstack.itemID)
return false;
if (Item.itemsList[itemstack.itemID].isDamageable())
return true;
if (filterItemStack.getItemDamage() == itemstack.getItemDamage())
return true;
return false;
}
@Override
public LinkedList<ITrigger> getTriggers() {
LinkedList<ITrigger> result = new LinkedList<ITrigger>();
result.add(BuildCraftTransport.triggerInventoryBelow25);
result.add(BuildCraftTransport.triggerInventoryBelow50);
result.add(BuildCraftTransport.triggerInventoryBelow75);
return result;
}
@Override
public void readFromNBT(NBTTagCompound nbtTagCompound) {
super.readFromNBT(nbtTagCompound);
NBTTagCompound inventoryStorageTag = (NBTTagCompound) nbtTagCompound.getTag("inventoryStorage");
inventoryStorage.readFromNBT(inventoryStorageTag);
NBTTagCompound inventoryFiltersTag = (NBTTagCompound) nbtTagCompound.getTag("inventoryFilters");
inventoryFilters.readFromNBT(inventoryFiltersTag);
}
@Override
public void writeToNBT(NBTTagCompound nbtTagCompound) {
super.writeToNBT(nbtTagCompound);
NBTTagCompound inventoryStorageTag = new NBTTagCompound();
inventoryStorage.writeToNBT(inventoryStorageTag);
nbtTagCompound.setTag("inventoryStorage", inventoryStorageTag);
NBTTagCompound inventoryFiltersTag = new NBTTagCompound();
inventoryFilters.writeToNBT(inventoryFiltersTag);
nbtTagCompound.setTag("inventoryFilters", inventoryFiltersTag);
}
}

View file

@ -13,6 +13,7 @@ public class TransportProxy {
GameRegistry.registerTileEntity(TileDummyGenericPipe.class, "net.minecraft.src.buildcraft.GenericPipe"); GameRegistry.registerTileEntity(TileDummyGenericPipe.class, "net.minecraft.src.buildcraft.GenericPipe");
GameRegistry.registerTileEntity(TileDummyGenericPipe2.class, "net.minecraft.src.buildcraft.transport.TileGenericPipe"); GameRegistry.registerTileEntity(TileDummyGenericPipe2.class, "net.minecraft.src.buildcraft.transport.TileGenericPipe");
GameRegistry.registerTileEntity(TileGenericPipe.class, "net.minecraft.src.buildcraft.transport.GenericPipe"); GameRegistry.registerTileEntity(TileGenericPipe.class, "net.minecraft.src.buildcraft.transport.GenericPipe");
GameRegistry.registerTileEntity(TileFilteredBuffer.class, "net.minecraft.src.buildcraft.transport.TileFilteredBuffer");
} }
public void registerRenderers() { public void registerRenderers() {

View file

@ -0,0 +1,79 @@
package buildcraft.transport.gui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import buildcraft.core.gui.BuildCraftContainer;
import buildcraft.core.gui.slots.SlotPhantom;
import buildcraft.transport.TileFilteredBuffer;
public class ContainerFilteredBuffer extends BuildCraftContainer {
private class SlotFiltered extends Slot
{
final TileFilteredBuffer filteredBuffer;
public SlotFiltered(TileFilteredBuffer filteredBuffer, int par2, int par3, int par4) {
super(filteredBuffer, par2, par3, par4);
this.filteredBuffer = filteredBuffer;
}
@Override
public boolean isItemValid(ItemStack itemStack) {
return filteredBuffer.isStackValidForSlot(this.getSlotIndex(), itemStack);
}
}
private class SlotPhantomLockable extends SlotPhantom
{
final IInventory locks;
public SlotPhantomLockable(IInventory storage, IInventory locks, int par2, int par3, int par4) {
super(storage, par2, par3, par4);
this.locks = locks;
}
@Override
public boolean canAdjust() {
return locks.getStackInSlot(this.getSlotIndex()) == null;
}
}
IInventory playerInventory;
TileFilteredBuffer filteredBuffer;
public ContainerFilteredBuffer(InventoryPlayer playerInventory, TileFilteredBuffer tile) {
super(tile.getSizeInventory());
this.playerInventory = playerInventory;
this.filteredBuffer = tile;
IInventory filters = tile.getFilters();
for (int col = 0; col < 9; col++) {
// Filtered Buffer filter slots
addSlotToContainer(new SlotPhantomLockable(filters, tile, col, 8 + col * 18, 27));
// Filtered Buffer inventory slots
addSlotToContainer(new SlotFiltered(tile, col, 8 + col * 18, 61));
}
// Player inventory
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, 86 + l * 18));
}
}
// Player hot bar
for (int i1 = 0; i1 < 9; i1++) {
addSlotToContainer(new Slot(playerInventory, i1, 8 + i1 * 18, 144));
}
}
@Override
public boolean canInteractWith(EntityPlayer entityPlayer) {
return filteredBuffer.isUseableByPlayer(entityPlayer);
}
}

View file

@ -0,0 +1,50 @@
package buildcraft.transport.gui;
import org.lwjgl.opengl.GL11;
import buildcraft.core.DefaultProps;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.TileFilteredBuffer;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
public class GuiFilteredBuffer extends GuiContainer {
IInventory playerInventory;
TileFilteredBuffer filteredBuffer;
public GuiFilteredBuffer(InventoryPlayer playerInventory, TileFilteredBuffer filteredBuffer) {
super(new ContainerFilteredBuffer(playerInventory, filteredBuffer));
this.playerInventory = playerInventory;
this.filteredBuffer = filteredBuffer;
xSize = 175;
ySize = 169;
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int x, int y) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.renderEngine.bindTexture(DefaultProps.TEXTURE_PATH_GUI + "/filteredBuffer_gui.png");
int cornerX = (width - xSize) / 2;
int cornerY = (height - ySize) / 2;
drawTexturedModalRect(cornerX, cornerY, 0, 0, xSize, ySize);
IInventory filters = filteredBuffer.getFilters();
for (int col = 0; col < filters.getSizeInventory(); col++) {
if(filters.getStackInSlot(col) == null) {
drawTexturedModalRect(cornerX + 7 + col * 18, cornerY + 60, 176, 0, 18, 18);
}
}
}
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
String title = StringUtils.localize("tile.filteredBufferBlock");
int xPos = (xSize - fontRenderer.getStringWidth(title)) / 2;
fontRenderer.drawString(title, xPos, 10, 0x404040);
}
}

View file

@ -0,0 +1,110 @@
/**
* Copyright (c) SpaceToad, 2011
* 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.transport.triggers;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.core.triggers.ActionTriggerIconProvider;
import buildcraft.core.triggers.BCTrigger;
import buildcraft.transport.TileFilteredBuffer;
public class TriggerFilteredBufferInventoryLevel extends BCTrigger {
public enum State {
Below25, Below50, Below75
};
public State state;
public TriggerFilteredBufferInventoryLevel(int id, State state) {
super(id);
this.state = state;
}
@Override
public boolean hasParameter() {
return true;
}
@Override
public String getDescription() {
switch (state) {
case Below25:
return "Contains < 25%";
case Below50:
return "Contains < 50%";
default:
return "Contains < 75%";
}
}
@Override
public boolean isTriggerActive(ForgeDirection side, TileEntity tile, ITriggerParameter parameter) {
if (tile instanceof TileFilteredBuffer) {
// A parameter is required
if (parameter == null) {
return false;
}
TileFilteredBuffer filteredBuffer = (TileFilteredBuffer) tile;
ItemStack searchStack = parameter.getItem();
int foundStackCount = 0;
int foundItemCount = 0;
IInventory filters = filteredBuffer.getFilters();
for (int i = 0 ; i < filters.getSizeInventory() ; i++) {
ItemStack filterStack = filters.getStackInSlot(i);
if (filterStack != null && filterStack.isItemEqual(searchStack)) {
ItemStack foundStack = filteredBuffer.getStackInSlot(i);
if(foundStack != null)
foundItemCount += foundStack.stackSize;
foundStackCount++;
}
}
if (foundStackCount > 0) {
float percentage = (float)foundItemCount / ((float)foundStackCount * (float)searchStack.getMaxStackSize());
switch (state) {
case Below25:
return percentage < 0.25f;
case Below50:
return percentage < 0.5f;
default:
return percentage < 0.75f;
}
}
}
return false;
}
@Override
public int getIconIndex() {
switch (state) {
case Below25:
return ActionTriggerIconProvider.Trigger_Inventory_Below25;
case Below50:
return ActionTriggerIconProvider.Trigger_Inventory_Below50;
default:
return ActionTriggerIconProvider.Trigger_Inventory_Below75;
}
}
}