emerald fluid pipes can now filter the liquid

This commit is contained in:
asiekierka 2014-11-16 13:56:26 +01:00
parent 82391bf728
commit b299537a13
17 changed files with 297 additions and 47 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 497 B

View file

@ -32,7 +32,7 @@ import buildcraft.api.tools.IToolWrench;
import buildcraft.core.BlockBuildCraft;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.GuiIds;
import buildcraft.core.fluids.FluidUtils;
import buildcraft.core.fluids.TankUtils;
import buildcraft.core.utils.Utils;
public class BlockBuilder extends BlockBuildCraft {
@ -116,7 +116,7 @@ public class BlockBuilder extends BlockBuildCraft {
}
return true;
} else if (builder != null && FluidUtils.handleRightClick(builder, ForgeDirection.UNKNOWN, entityplayer, true, false)) {
} else if (builder != null && TankUtils.handleRightClick(builder, ForgeDirection.UNKNOWN, entityplayer, true, false)) {
return true;
} else {
if (!world.isRemote) {

View file

@ -32,6 +32,7 @@ public final class GuiIds {
public static final int GATES = 51;
public static final int PIPE_EMERALD_ITEM = 52;
public static final int PIPE_LOGEMERALD_ITEM = 53;
public static final int PIPE_EMERALD_FLUID = 54;
public static final int FILTERED_BUFFER = 60;

View file

@ -25,12 +25,12 @@ import net.minecraftforge.fluids.IFluidTank;
import buildcraft.core.TileBuffer;
import buildcraft.core.inventory.InvUtils;
public final class FluidUtils {
public final class TankUtils {
/**
* Deactivate constructor
*/
private FluidUtils() {
private TankUtils() {
}
public static boolean handleRightClick(IFluidHandler tank, ForgeDirection side, EntityPlayer player, boolean fill, boolean drain) {

View file

@ -0,0 +1,31 @@
package buildcraft.core.utils;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.IFluidContainerItem;
public final class FluidUtils {
private FluidUtils () {
}
public static Fluid getFluidFromItemStack(ItemStack stack) {
if (stack != null) {
if (stack.getItem() instanceof IFluidContainerItem) {
IFluidContainerItem ctr = (IFluidContainerItem) stack.getItem();
if (ctr.getFluid(stack) != null) {
return ctr.getFluid(stack).getFluid();
}
} else if (FluidContainerRegistry.isFilledContainer(stack) &&
FluidContainerRegistry.getFluidForFilledItem(stack) != null) {
return FluidContainerRegistry.getFluidForFilledItem(stack).getFluid();
}
}
return null;
}
public static boolean isFluidContainer(ItemStack stack) {
return stack.getItem() instanceof IFluidContainerItem || FluidContainerRegistry.isFilledContainer(stack);
}
}

View file

@ -28,7 +28,7 @@ import buildcraft.api.fuels.IFuel;
import buildcraft.api.fuels.ISolidCoolant;
import buildcraft.core.GuiIds;
import buildcraft.core.IItemPipe;
import buildcraft.core.fluids.FluidUtils;
import buildcraft.core.fluids.TankUtils;
import buildcraft.core.fluids.Tank;
import buildcraft.core.fluids.TankManager;
import buildcraft.core.inventory.InvUtils;
@ -76,7 +76,7 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan
return false;
}
if (!worldObj.isRemote) {
if (FluidUtils.handleRightClick(this, side, player, true, true)) {
if (TankUtils.handleRightClick(this, side, player, true, true)) {
return true;
}
} else {

View file

@ -33,7 +33,7 @@ import buildcraft.api.tools.IToolWrench;
import buildcraft.core.BlockBuildCraft;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.GuiIds;
import buildcraft.core.fluids.FluidUtils;
import buildcraft.core.fluids.TankUtils;
import buildcraft.core.utils.Utils;
public class BlockRefinery extends BlockBuildCraft {
@ -126,7 +126,7 @@ public class BlockRefinery extends BlockBuildCraft {
if (current != null && current.getItem() != Items.bucket) {
if (!world.isRemote) {
if (FluidUtils.handleRightClick((TileRefinery) tile, ForgeDirection.getOrientation(side), player, true, false)) {
if (TankUtils.handleRightClick((TileRefinery) tile, ForgeDirection.getOrientation(side), player, true, false)) {
return true;
}
} else if (FluidContainerRegistry.isContainer(current)) {

View file

@ -29,7 +29,7 @@ import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.api.core.BlockIndex;
import buildcraft.api.core.BuildCraftAPI;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.fluids.FluidUtils;
import buildcraft.core.fluids.TankUtils;
import buildcraft.core.fluids.Tank;
import buildcraft.core.utils.BlockUtil;
import buildcraft.core.utils.Utils;
@ -108,7 +108,7 @@ public class TileFloodGate extends TileBuildCraft implements IFluidHandler {
if (canPlaceFluidAt(block, x, y, z)) {
boolean placed;
Block b = FluidUtils.getFluidBlock(fluid, true);
Block b = TankUtils.getFluidBlock(fluid, true);
if (b instanceof BlockFluidBase) {
BlockFluidBase blockFluid = (BlockFluidBase) b;

View file

@ -19,7 +19,6 @@ import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
@ -37,7 +36,7 @@ import buildcraft.core.EntityBlock;
import buildcraft.core.RFBattery;
import buildcraft.core.TileBuffer;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.fluids.FluidUtils;
import buildcraft.core.fluids.TankUtils;
import buildcraft.core.fluids.SingleUseTank;
import buildcraft.core.network.PacketPayload;
import buildcraft.core.network.PacketUpdate;
@ -160,7 +159,7 @@ public class TilePump extends TileBuildCraft implements IHasWork, IFluidHandler
cache = TileBuffer.makeBuffer(worldObj, xCoord, yCoord, zCoord, false);
}
FluidUtils.pushFluidToConsumers(tank, 400, cache);
TankUtils.pushFluidToConsumers(tank, 400, cache);
}
private void createTube() {

View file

@ -19,15 +19,18 @@ import cpw.mods.fml.common.network.IGuiHandler;
import buildcraft.api.core.BCLog;
import buildcraft.core.GuiIds;
import buildcraft.transport.gui.ContainerDiamondPipe;
import buildcraft.transport.gui.ContainerEmeraldFluidPipe;
import buildcraft.transport.gui.ContainerEmeraldPipe;
import buildcraft.transport.gui.ContainerEmzuliPipe;
import buildcraft.transport.gui.ContainerFilteredBuffer;
import buildcraft.transport.gui.ContainerGateInterface;
import buildcraft.transport.gui.GuiDiamondPipe;
import buildcraft.transport.gui.GuiEmeraldFluidPipe;
import buildcraft.transport.gui.GuiEmeraldPipe;
import buildcraft.transport.gui.GuiEmzuliPipe;
import buildcraft.transport.gui.GuiFilteredBuffer;
import buildcraft.transport.gui.GuiGateInterface;
import buildcraft.transport.pipes.PipeFluidsEmerald;
import buildcraft.transport.pipes.PipeItemsDiamond;
import buildcraft.transport.pipes.PipeItemsEmerald;
import buildcraft.transport.pipes.PipeItemsEmzuli;
@ -68,6 +71,9 @@ public class GuiHandler implements IGuiHandler {
case GuiIds.PIPE_LOGEMERALD_ITEM:
return new ContainerEmzuliPipe(player.inventory, (PipeItemsEmzuli) pipe.pipe);
case GuiIds.PIPE_EMERALD_FLUID:
return new ContainerEmeraldFluidPipe(player.inventory, (PipeFluidsEmerald) pipe.pipe);
case GuiIds.GATES:
return new ContainerGateInterface(player.inventory, pipe.pipe);
@ -114,6 +120,9 @@ public class GuiHandler implements IGuiHandler {
case GuiIds.PIPE_LOGEMERALD_ITEM:
return new GuiEmzuliPipe(player.inventory, (PipeItemsEmzuli) pipe.pipe);
case GuiIds.PIPE_EMERALD_FLUID:
return new GuiEmeraldFluidPipe(player.inventory, (PipeFluidsEmerald) pipe.pipe);
case GuiIds.GATES:
return new GuiGateInterface(player.inventory, pipe.pipe);

View file

@ -0,0 +1,38 @@
package buildcraft.transport;
import net.minecraft.nbt.NBTTagCompound;
public interface IEmeraldPipe extends IFilteredPipe {
public enum FilterMode {
WHITE_LIST, BLACK_LIST, ROUND_ROBIN;
}
public class EmeraldPipeSettings {
private FilterMode filterMode;
public EmeraldPipeSettings(FilterMode defaultMode) {
filterMode = defaultMode;
}
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());
}
}
EmeraldPipeSettings getSettings();
boolean isValidFilterMode(FilterMode mode);
}

View file

@ -0,0 +1,9 @@
package buildcraft.transport;
import buildcraft.core.network.IClientState;
import net.minecraft.inventory.IInventory;
public interface IFilteredPipe extends IClientState {
IInventory getFilters();
}

View file

@ -0,0 +1,47 @@
/**
* 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.transport.gui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import buildcraft.core.gui.BuildCraftContainer;
import buildcraft.core.gui.slots.SlotPhantom;
import buildcraft.transport.pipes.PipeFluidsEmerald;
public class ContainerEmeraldFluidPipe extends BuildCraftContainer {
private final PipeFluidsEmerald pipe;
private final IInventory playerInv;
private final IInventory filterInv;
public ContainerEmeraldFluidPipe(IInventory playerInventory, PipeFluidsEmerald pipe) {
super(pipe.getFilters().getSizeInventory());
this.pipe = pipe;
this.playerInv = playerInventory;
this.filterInv = pipe.getFilters();
addSlotToContainer(new SlotPhantom(filterInv, 0, 80, 18));
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));
}
}
for (int i1 = 0; i1 < 9; i1++) {
addSlotToContainer(new Slot(playerInventory, i1, 8 + i1 * 18, 108));
}
}
@Override
public boolean canInteractWith(EntityPlayer entityplayer) {
return pipe.container.isUseableByPlayer(entityplayer);
}
}

View file

@ -0,0 +1,45 @@
/**
* 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.transport.gui;
import org.lwjgl.opengl.GL11;
import net.minecraft.inventory.IInventory;
import net.minecraft.util.ResourceLocation;
import buildcraft.core.DefaultProps;
import buildcraft.core.gui.GuiBuildCraft;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.pipes.PipeFluidsEmerald;
public class GuiEmeraldFluidPipe extends GuiBuildCraft {
private static final ResourceLocation TEXTURE = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_GUI + "/generic_one_slot.png");
IInventory playerInventory;
IInventory filterInventory;
public GuiEmeraldFluidPipe(IInventory playerInventory, PipeFluidsEmerald pipe) {
super(new ContainerEmeraldFluidPipe(playerInventory, pipe), pipe.getFilters(), TEXTURE);
this.playerInventory = playerInventory;
this.filterInventory = pipe.getFilters();
xSize = 176;
ySize = 132;
}
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
fontRendererObj.drawString(filterInventory.getInventoryName(), getCenteredOffset(filterInventory.getInventoryName()), 6, 0x404040);
fontRendererObj.drawString(StringUtils.localize("gui.inventory"), 8, ySize - 97, 0x404040);
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int x, int y) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.renderEngine.bindTexture(TEXTURE);
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
}
}

View file

@ -13,6 +13,7 @@ import buildcraft.api.core.IIconProvider;
import buildcraft.core.GuiIds;
import buildcraft.core.inventory.SimpleInventory;
import buildcraft.core.network.IClientState;
import buildcraft.core.utils.FluidUtils;
import buildcraft.core.utils.Utils;
import buildcraft.transport.BlockGenericPipe;
import buildcraft.transport.IDiamondPipe;
@ -46,8 +47,7 @@ public class PipeFluidsDiamond extends Pipe<PipeTransportFluids> implements IDia
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
return stack == null || stack.getItem() instanceof IFluidContainerItem
|| FluidContainerRegistry.isFilledContainer(stack);
return stack == null || FluidUtils.isFluidContainer(stack);
}
@Override
@ -58,23 +58,9 @@ public class PipeFluidsDiamond extends Pipe<PipeTransportFluids> implements IDia
}
for (int i = 0; i < 54; i++) {
fluids[i] = null;
ItemStack stack = getStackInSlot(i);
if (stack != null) {
if (stack.getItem() instanceof IFluidContainerItem) {
IFluidContainerItem ctr = (IFluidContainerItem) stack.getItem();
if (ctr.getFluid(stack) != null) {
fluids[i] = ctr.getFluid(stack).getFluid();
filteredDirections[i / 9] = true;
}
} else if (FluidContainerRegistry.isFilledContainer(stack) &&
FluidContainerRegistry.getFluidForFilledItem(stack) != null) {
fluids[i] = FluidContainerRegistry.getFluidForFilledItem(stack).getFluid();
filteredDirections[i / 9] = true;
}
}
fluids[i] = FluidUtils.getFluidFromItemStack(getStackInSlot(i));
if (fluids[i] != null) {
System.out.println("fluid at " + i + " is " + fluids[i].getName());
filteredDirections[i / 9] = true;
}
}
}

View file

@ -8,11 +8,28 @@
*/
package buildcraft.transport.pipes;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.BuildCraftTransport;
import buildcraft.core.GuiIds;
import buildcraft.core.inventory.SimpleInventory;
import buildcraft.core.network.IClientState;
import buildcraft.core.utils.FluidUtils;
import buildcraft.core.utils.Utils;
import buildcraft.transport.BlockGenericPipe;
import buildcraft.transport.PipeIconProvider;
public class PipeFluidsEmerald extends PipeFluidsWood {
public class PipeFluidsEmerald extends PipeFluidsWood implements IClientState {
private SimpleInventory filters = new SimpleInventory(1, "Filters", 1);
public PipeFluidsEmerald(Item item) {
super(item);
@ -23,4 +40,70 @@ public class PipeFluidsEmerald extends PipeFluidsWood {
transport.initFromPipe(getClass());
transport.travelDelay = 4;
}
public IInventory getFilters() {
return filters;
}
@Override
public int extractFluid(IFluidHandler fluidHandler, ForgeDirection side) {
Fluid targetFluid = FluidUtils.getFluidFromItemStack(filters.getStackInSlot(0));
if (targetFluid == null) {
return super.extractFluid(fluidHandler, side);
}
int flowRate = transport.flowRate;
FluidStack toExtract = new FluidStack(targetFluid, liquidToExtract > flowRate ? flowRate : liquidToExtract);
FluidStack extracted = fluidHandler.drain(side.getOpposite(), toExtract, false);
if (extracted != null) {
toExtract.amount = transport.fill(side, extracted, true);
fluidHandler.drain(side.getOpposite(), toExtract, true);
}
return toExtract.amount;
}
@Override
public boolean blockActivated(EntityPlayer entityplayer) {
if (entityplayer.getCurrentEquippedItem() != null) {
if (Block.getBlockFromItem(entityplayer.getCurrentEquippedItem().getItem()) instanceof BlockGenericPipe) {
return false;
}
}
if (super.blockActivated(entityplayer)) {
return true;
}
if (!container.getWorldObj().isRemote) {
entityplayer.openGui(BuildCraftTransport.instance, GuiIds.PIPE_EMERALD_FLUID, container.getWorldObj(), container.xCoord, container.yCoord, container.zCoord);
}
return true;
}
@Override
public void writeData(ByteBuf data) {
NBTTagCompound nbt = new NBTTagCompound();
writeToNBT(nbt);
Utils.writeNBT(data, nbt);
}
@Override
public void readData(ByteBuf data) {
NBTTagCompound nbt = Utils.readNBT(data);
readFromNBT(nbt);
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
filters.readFromNBT(nbt);
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
filters.writeToNBT(nbt);
}
}

View file

@ -16,6 +16,7 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
@ -94,20 +95,7 @@ public class PipeFluidsWood extends Pipe<PipeTransportFluids> implements IEnergy
TileEntity tile = container.getTile(side);
if (tile instanceof IFluidHandler) {
IFluidHandler fluidHandler = (IFluidHandler) tile;
int flowRate = transport.flowRate;
FluidStack extracted = fluidHandler.drain(side.getOpposite(), liquidToExtract > flowRate ? flowRate : liquidToExtract, false);
int inserted = 0;
if (extracted != null) {
inserted = transport.fill(side, extracted, true);
fluidHandler.drain(side.getOpposite(), inserted, true);
}
liquidToExtract -= inserted;
liquidToExtract -= extractFluid((IFluidHandler) tile, side);
}
}
@ -131,7 +119,21 @@ public class PipeFluidsWood extends Pipe<PipeTransportFluids> implements IEnergy
}
}
}
public int extractFluid(IFluidHandler fluidHandler, ForgeDirection side) {
int flowRate = transport.flowRate;
FluidStack extracted = fluidHandler.drain(side.getOpposite(), liquidToExtract > flowRate ? flowRate : liquidToExtract, false);
int inserted = 0;
if (extracted != null) {
inserted = transport.fill(side, extracted, true);
fluidHandler.drain(side.getOpposite(), inserted, true);
}
return inserted;
}
@Override
@SideOnly(Side.CLIENT)
public IIconProvider getIconProvider() {