use of net.minecraftforge.fluids.FluidStack in project LogisticsPipes by RS485.
the class PipeFluidProvider method getAvailableFluids.
@Override
public Map<FluidIdentifier, Integer> getAvailableFluids() {
Map<FluidIdentifier, Integer> map = new HashMap<>();
for (Pair<TileEntity, ForgeDirection> pair : getAdjacentTanks(false)) {
boolean fallback = true;
if (SimpleServiceLocator.specialTankHandler.hasHandlerFor(pair.getValue1())) {
ISpecialTankHandler handler = SimpleServiceLocator.specialTankHandler.getTankHandlerFor(pair.getValue1());
if (handler instanceof ISpecialTankAccessHandler) {
fallback = false;
Map<FluidIdentifier, Long> tmp = ((ISpecialTankAccessHandler) handler).getAvailableLiquid(pair.getValue1());
for (Entry<FluidIdentifier, Long> entry : tmp.entrySet()) {
if (map.containsKey(entry.getKey())) {
long addition = ((long) map.get(entry.getKey())) + entry.getValue();
map.put(entry.getKey(), addition > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) addition);
} else {
map.put(entry.getKey(), entry.getValue() > Integer.MAX_VALUE ? Integer.MAX_VALUE : entry.getValue().intValue());
}
}
}
}
if (fallback) {
FluidTankInfo[] tanks = ((IFluidHandler) pair.getValue1()).getTankInfo(pair.getValue2().getOpposite());
if (tanks != null) {
for (FluidTankInfo tank : tanks) {
if (tank == null) {
continue;
}
FluidStack liquid;
if ((liquid = tank.fluid) != null && liquid.getFluidID() != 0) {
FluidIdentifier ident = FluidIdentifier.get(liquid);
if (((IFluidHandler) pair.getValue1()).canDrain(pair.getValue2().getOpposite(), liquid.getFluid())) {
if (((IFluidHandler) pair.getValue1()).drain(pair.getValue2().getOpposite(), 1, false) != null) {
if (map.containsKey(ident)) {
long addition = ((long) map.get(ident)) + tank.fluid.amount;
map.put(ident, addition > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) addition);
} else {
map.put(ident, tank.fluid.amount);
}
}
}
}
}
}
}
}
Map<FluidIdentifier, Integer> result = new HashMap<>();
//Reduce what has been reserved, add.
for (Entry<FluidIdentifier, Integer> fluid : map.entrySet()) {
int remaining = fluid.getValue() - getFluidOrderManager().totalFluidsCountInOrders(fluid.getKey());
if (remaining < 1) {
continue;
}
result.put(fluid.getKey(), remaining);
}
return result;
}
use of net.minecraftforge.fluids.FluidStack in project LogisticsPipes by RS485.
the class AssemblyTable method importRecipe.
@Override
public boolean importRecipe(TileEntity tile, ItemIdentifierInventory inventory) {
if (!(tile instanceof TileAssemblyTable)) {
return false;
}
TileAssemblyTable table = (TileAssemblyTable) tile;
//current pipe inputs/outputs
final ItemIdentifierInventory inputs = new ItemIdentifierInventory(inventory.getSizeInventory() - 2, "AssemblyTableDummyInv", 64, false);
for (int i = 0; i < inventory.getSizeInventory() - 2; i++) {
inputs.setInventorySlotContents(i, inventory.getIDStackInSlot(i));
}
ItemStack output = inventory.getStackInSlot(inventory.getSizeInventory() - 2);
//see if there's a recipe planned in the table that matches the current pipe settings, if yes take the next, otherwise take the first
FlexibleRecipe<ItemStack> firstRecipe = null;
FlexibleRecipe<ItemStack> nextRecipe = null;
boolean takeNext = false;
for (IFlexibleRecipe<ItemStack> r : AssemblyRecipeManager.INSTANCE.getRecipes()) {
if (!(r instanceof FlexibleRecipe)) {
continue;
}
if (!((FlexibleRecipe<ItemStack>) r).inputFluids.isEmpty()) {
continue;
}
if (table.isPlanned(r)) {
if (firstRecipe == null) {
firstRecipe = (FlexibleRecipe<ItemStack>) r;
}
if (takeNext) {
nextRecipe = (FlexibleRecipe<ItemStack>) r;
break;
}
if (output != null && ItemStack.areItemStacksEqual(output, ((FlexibleRecipe<ItemStack>) r).output)) {
if (((FlexibleRecipe<ItemStack>) r).canBeCrafted(new // Read Proxy to IInventory
IFlexibleCrafter() {
@Override
public int getCraftingItemStackSize() {
return inputs.getSizeInventory();
}
@Override
public ItemStack getCraftingItemStack(int paramInt) {
return inputs.getStackInSlot(paramInt);
}
@Override
public int getCraftingFluidStackSize() {
return 0;
}
@Override
public FluidStack getCraftingFluidStack(int paramInt) {
return null;
}
@Override
public ItemStack decrCraftingItemStack(int paramInt1, int paramInt2) {
return null;
}
@Override
public FluidStack decrCraftingFluidStack(int paramInt1, int paramInt2) {
return null;
}
})) {
takeNext = true;
}
}
}
}
if (nextRecipe == null) {
nextRecipe = firstRecipe;
}
if (nextRecipe == null) {
return false;
}
// Import
inventory.setInventorySlotContents(inventory.getSizeInventory() - 2, nextRecipe.output);
try {
for (int i = 0; i < inventory.getSizeInventory() - 2; i++) {
inventory.clearInventorySlotContents(i);
}
int i = 0;
for (Object input : nextRecipe.inputItems) {
ItemStack processed = null;
if (input instanceof String) {
List<ItemStack> ores = OreDictionary.getOres((String) input);
if (ores != null && ores.size() > 0) {
input = ores.get(0);
}
} else if (input instanceof ItemStack) {
processed = (ItemStack) input;
} else if (input instanceof Item) {
processed = new ItemStack((Item) input);
} else if (input instanceof Block) {
processed = new ItemStack((Block) input, 1, 0);
} else if (input instanceof Integer) {
processed = null;
} else {
throw new IllegalArgumentException("Unknown Object passed to recipe!");
}
if (processed != null) {
inventory.setInventorySlotContents(i, processed);
++i;
}
}
} catch (ClassCastException e) {
// TODO: make it show a nice error or
// remove this hack altogether.
}
// Compact
inventory.compact_first(9);
return true;
}
use of net.minecraftforge.fluids.FluidStack in project LogisticsPipes by RS485.
the class LogisticsRenderPipe method renderFluids.
// BC copy, except where marked with XXX
private void renderFluids(CoreUnroutedPipe pipe, double x, double y, double z) {
// XXX PipeTransportFluids trans = pipe.transport;
PipeFluidTransportLogistics trans = (PipeFluidTransportLogistics) (pipe.transport);
boolean needsRender = false;
for (int i = 0; i < 7; ++i) {
FluidStack fluidStack = trans.renderCache[i];
if (fluidStack != null && fluidStack.amount > 0) {
needsRender = true;
break;
}
}
if (!needsRender) {
return;
}
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glTranslatef((float) x, (float) y, (float) z);
int skylight = pipe.container.getWorld().getSkyBlockTypeBrightness(EnumSkyBlock.Sky, pipe.getX(), pipe.getY(), pipe.getZ());
int blocklight = pipe.container.getWorld().getSkyBlockTypeBrightness(EnumSkyBlock.Block, pipe.getX(), pipe.getY(), pipe.getZ());
// sides
boolean sides = false, above = false;
for (int i = 0; i < 6; ++i) {
FluidStack fluidStack = trans.renderCache[i];
if (fluidStack != null && fluidStack.amount > 0) {
DisplayFluidList d = getListFromBuffer(fluidStack, skylight, blocklight, fluidStack.getFluid().getLuminosity(fluidStack), pipe.container.getWorldObj());
if (d == null) {
continue;
}
// XXX int stage = (int) ((float) fluidStack.amount / (float) (trans.getCapacity()) * (LIQUID_STAGES - 1));
int stage = (int) ((float) fluidStack.amount / (float) (trans.getSideCapacity()) * (LogisticsRenderPipe.LIQUID_STAGES - 1));
if (stage >= LogisticsRenderPipe.LIQUID_STAGES) {
stage = LogisticsRenderPipe.LIQUID_STAGES - 1;
}
if (stage < 0) {
stage = 0;
}
GL11.glPushMatrix();
int list = 0;
switch(ForgeDirection.VALID_DIRECTIONS[i]) {
case UP:
above = true;
list = d.sideVertical[stage];
break;
case DOWN:
GL11.glTranslatef(0, -0.75F, 0);
list = d.sideVertical[stage];
break;
case EAST:
case WEST:
case SOUTH:
case NORTH:
sides = true;
// Yes, this is kind of ugly, but was easier than transform the coordinates above.
GL11.glTranslatef(0.5F, 0.0F, 0.5F);
GL11.glRotatef(angleY[i], 0, 1, 0);
GL11.glRotatef(angleZ[i], 0, 0, 1);
GL11.glTranslatef(-0.5F, 0.0F, -0.5F);
list = d.sideHorizontal[stage];
break;
default:
}
bindTexture(TextureMap.locationBlocksTexture);
FluidRenderer.setColorForFluidStack(fluidStack);
GL11.glCallList(list);
GL11.glPopMatrix();
}
}
// CENTER
FluidStack fluidStack = trans.renderCache[ForgeDirection.UNKNOWN.ordinal()];
if (fluidStack != null && fluidStack.amount > 0) {
DisplayFluidList d = getListFromBuffer(fluidStack, skylight, blocklight, fluidStack.getFluid().getLuminosity(fluidStack), pipe.container.getWorldObj());
if (d != null) {
// XXX int stage = (int) ((float) fluidStack.amount / (float) (trans.getCapacity()) * (LIQUID_STAGES - 1));
int stage = (int) ((float) fluidStack.amount / (float) (trans.getInnerCapacity()) * (LogisticsRenderPipe.LIQUID_STAGES - 1));
bindTexture(TextureMap.locationBlocksTexture);
FluidRenderer.setColorForFluidStack(fluidStack);
if (above) {
GL11.glCallList(d.centerVertical[stage]);
}
if (!above || sides) {
GL11.glCallList(d.centerHorizontal[stage]);
}
}
}
GL11.glPopAttrib();
GL11.glPopMatrix();
}
use of net.minecraftforge.fluids.FluidStack in project LogisticsPipes by RS485.
the class BuildCraftTankHandler method getAvailableLiquid.
@Override
public Map<FluidIdentifier, Long> getAvailableLiquid(TileEntity tile) {
Map<FluidIdentifier, Long> map = new HashMap<>();
FluidTankInfo[] tanks = ((IFluidHandler) tile).getTankInfo(ForgeDirection.UNKNOWN);
for (FluidTankInfo tank : tanks) {
if (tank == null) {
continue;
}
FluidStack liquid;
if ((liquid = tank.fluid) != null && liquid.getFluidID() != 0) {
FluidIdentifier ident = FluidIdentifier.get(liquid);
if (((IFluidHandler) tile).drain(ForgeDirection.UNKNOWN, 1, false) != null) {
if (map.containsKey(ident)) {
long addition = map.get(ident) + tank.fluid.amount;
map.put(ident, addition);
} else {
map.put(ident, (long) tank.fluid.amount);
}
}
}
}
return map;
}
use of net.minecraftforge.fluids.FluidStack in project LogisticsPipes by RS485.
the class PipeFluidTransportLogistics method computeFluidUpdate.
/**
* Computes the PacketFluidUpdate packet for transmission to a client
*
* @param initPacket
* everything is sent, no delta stuff ( first packet )
* @param persistChange
* The render cache change is persisted
* @return PacketFluidUpdate liquid update packet
*/
private ModernPacket computeFluidUpdate(boolean initPacket, boolean persistChange) {
boolean changed = false;
if (initClient > 0) {
initClient--;
if (initClient == 1) {
changed = true;
}
}
FluidStack[] renderCache = this.renderCache.clone();
for (ForgeDirection dir : PipeFluidTransportLogistics.orientations) {
FluidStack current;
if (dir != ForgeDirection.UNKNOWN) {
current = sideTanks[dir.ordinal()].getFluid();
} else {
current = internalTank.getFluid();
}
FluidStack prev = renderCache[dir.ordinal()];
if (prev == null && current == null) {
continue;
}
if (prev == null && current != null) {
changed = true;
renderCache[dir.ordinal()] = current.copy();
continue;
}
if (prev != null && current == null) {
changed = true;
renderCache[dir.ordinal()] = null;
continue;
}
if (prev.getFluidID() != current.getFluidID() || initPacket) {
changed = true;
renderCache[dir.ordinal()] = new FluidStack(current.getFluid(), renderCache[dir.ordinal()].amount);
}
if (prev.amount != current.amount || initPacket) {
changed = true;
renderCache[dir.ordinal()].amount = current.amount;
}
}
if (persistChange) {
this.renderCache = renderCache;
}
if (changed || initPacket) {
return PacketHandler.getPacket(PipeFluidUpdate.class).setRenderCache(renderCache).setPosX(container.xCoord).setPosY(container.yCoord).setPosZ(container.zCoord).setChunkDataPacket(initPacket);
}
return null;
}
Aggregations