add diamond liquid pipes
This commit is contained in:
parent
70396e7e24
commit
82391bf728
6 changed files with 96 additions and 3 deletions
|
@ -222,6 +222,7 @@ item.PipeFluidsIron.name=Iron Fluid Pipe
|
|||
item.PipeFluidsQuartz.name=Quartz Fluid Pipe
|
||||
item.PipeFluidsGold.name=Golden Fluid Pipe
|
||||
item.PipeFluidsEmerald.name=Emerald Fluid Pipe
|
||||
item.PipeFluidsDiamond.name=Diamond Fluid Pipe
|
||||
item.PipePowerWood.name=Wooden Kinesis Pipe
|
||||
item.PipePowerCobblestone.name=Cobblestone Kinesis Pipe
|
||||
item.PipePowerStone.name=Stone Kinesis Pipe
|
||||
|
|
|
@ -13,6 +13,7 @@ import java.util.ArrayList;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import buildcraft.transport.pipes.PipeFluidsDiamond;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
|
@ -192,6 +193,7 @@ public class BuildCraftTransport extends BuildCraftMod {
|
|||
public static Item pipeFluidsVoid;
|
||||
public static Item pipeFluidsSandstone;
|
||||
public static Item pipeFluidsEmerald;
|
||||
public static Item pipeFluidsDiamond;
|
||||
public static Item pipePowerWood;
|
||||
public static Item pipePowerCobblestone;
|
||||
public static Item pipePowerStone;
|
||||
|
@ -402,6 +404,7 @@ public class BuildCraftTransport extends BuildCraftMod {
|
|||
pipeFluidsIron = buildPipe(PipeFluidsIron.class, "Iron Waterproof Pipe", CreativeTabBuildCraft.PIPES, pipeWaterproof, pipeItemsIron);
|
||||
pipeFluidsGold = buildPipe(PipeFluidsGold.class, "Golden Waterproof Pipe", CreativeTabBuildCraft.PIPES, pipeWaterproof, pipeItemsGold);
|
||||
pipeFluidsEmerald = buildPipe(PipeFluidsEmerald.class, "Emerald Waterproof Pipe", CreativeTabBuildCraft.PIPES, pipeWaterproof, pipeItemsEmerald);
|
||||
pipeFluidsDiamond = buildPipe(PipeFluidsDiamond.class, "Diamond Waterproof Pipe", CreativeTabBuildCraft.PIPES, pipeWaterproof, pipeItemsDiamond);
|
||||
pipeFluidsSandstone = buildPipe(PipeFluidsSandstone.class, "Sandstone Waterproof Pipe", CreativeTabBuildCraft.PIPES, pipeWaterproof, pipeItemsSandstone);
|
||||
pipeFluidsVoid = buildPipe(PipeFluidsVoid.class, "Void Waterproof Pipe", CreativeTabBuildCraft.PIPES, pipeWaterproof, pipeItemsVoid);
|
||||
|
||||
|
|
|
@ -100,8 +100,8 @@ public class PipeIconProvider implements IIconProvider {
|
|||
PipeFluidsStone("pipeFluidsStone"),
|
||||
PipeFluidsVoid("pipeFluidsVoid"),
|
||||
//
|
||||
PipeFluidsDiamond_Item("pipFluidsDiamond_item"),
|
||||
PipeFluidsDiamond_Center("pipFluidsDiamond_center"),
|
||||
PipeFluidsDiamond_Item("pipeFluidsDiamond_item"),
|
||||
PipeFluidsDiamond_Center("pipeFluidsDiamond_center"),
|
||||
PipeFluidsDiamond_Down("pipeFluidsDiamond_down"),
|
||||
PipeFluidsDiamond_Up("pipeFluidsDiamond_up"),
|
||||
PipeFluidsDiamond_North("pipeFluidsDiamond_north"),
|
||||
|
|
|
@ -62,6 +62,7 @@ public class TransportProxyClient extends TransportProxy {
|
|||
MinecraftForgeClient.registerItemRenderer(BuildCraftTransport.pipeFluidsQuartz, pipeItemRenderer);
|
||||
MinecraftForgeClient.registerItemRenderer(BuildCraftTransport.pipeFluidsIron, pipeItemRenderer);
|
||||
MinecraftForgeClient.registerItemRenderer(BuildCraftTransport.pipeFluidsGold, pipeItemRenderer);
|
||||
MinecraftForgeClient.registerItemRenderer(BuildCraftTransport.pipeFluidsDiamond, pipeItemRenderer);
|
||||
MinecraftForgeClient.registerItemRenderer(BuildCraftTransport.pipeFluidsEmerald, pipeItemRenderer);
|
||||
|
||||
MinecraftForgeClient.registerItemRenderer(BuildCraftTransport.pipePowerWood, pipeItemRenderer);
|
||||
|
|
|
@ -26,12 +26,61 @@ import net.minecraft.block.Block;
|
|||
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 net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidContainerItem;
|
||||
|
||||
public class PipeFluidsDiamond extends Pipe<PipeTransportFluids> implements IDiamondPipe {
|
||||
|
||||
private SimpleInventory filters = new SimpleInventory(54, "Filters", 1);
|
||||
private class FilterInventory extends SimpleInventory {
|
||||
public boolean[] filteredDirections = new boolean[6];
|
||||
public Fluid[] fluids = new Fluid[54];
|
||||
|
||||
public FilterInventory(int size, String invName, int invStackLimit) {
|
||||
super(size, invName, invStackLimit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
return stack == null || stack.getItem() instanceof IFluidContainerItem
|
||||
|| FluidContainerRegistry.isFilledContainer(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
// calculate fluid cache
|
||||
for (int i = 0; i < 6; i++) {
|
||||
filteredDirections[i] = false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (fluids[i] != null) {
|
||||
System.out.println("fluid at " + i + " is " + fluids[i].getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private FilterInventory filters = new FilterInventory(54, "Filters", 1);
|
||||
|
||||
public PipeFluidsDiamond(Item item) {
|
||||
super(new PipeTransportFluids(), item);
|
||||
|
@ -40,6 +89,7 @@ public class PipeFluidsDiamond extends Pipe<PipeTransportFluids> implements IDia
|
|||
transport.travelDelay = 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getFilters() {
|
||||
return filters;
|
||||
}
|
||||
|
@ -92,11 +142,48 @@ public class PipeFluidsDiamond extends Pipe<PipeTransportFluids> implements IDia
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean outputOpen(ForgeDirection to) {
|
||||
if (!super.outputOpen(to))
|
||||
return false;
|
||||
|
||||
// get center tank, from which outputs are checked; ignore if has no fluid
|
||||
FluidTankInfo[] tanks = transport.getTankInfo(ForgeDirection.UNKNOWN);
|
||||
if (tanks == null || tanks[0] == null || tanks[0].fluid == null || tanks[0].fluid.amount == 0)
|
||||
return true;
|
||||
|
||||
Fluid fluidInTank = tanks[0].fluid.getFluid();
|
||||
boolean[] validFilter = new boolean[6];
|
||||
boolean isFiltered = false;
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
if (container.isPipeConnected(dir) && filters.filteredDirections[dir.ordinal()]) {
|
||||
for (int slot = dir.ordinal() * 9; slot < dir.ordinal() * 9 + 9; ++slot) {
|
||||
if (filters.fluids[slot] != null && filters.fluids[slot].getID() == fluidInTank.getID()) {
|
||||
validFilter[dir.ordinal()] = true;
|
||||
isFiltered = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// the direction is filtered and liquids match
|
||||
if (filters.filteredDirections[to.ordinal()] && validFilter[to.ordinal()])
|
||||
return true;
|
||||
|
||||
// we haven't found a filter for this liquid and the direction is free
|
||||
if (!isFiltered && !filters.filteredDirections[to.ordinal()])
|
||||
return true;
|
||||
|
||||
// we have a filter for the liquid, but not a valid direction
|
||||
return false;
|
||||
}
|
||||
|
||||
/* SAVING & LOADING */
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
filters.readFromNBT(nbt);
|
||||
filters.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -46,6 +46,7 @@ public class PipeItemsDiamond extends Pipe<PipeTransportItems> implements IDiamo
|
|||
super(new PipeTransportItems(), item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getFilters() {
|
||||
return filters;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue