List of usage examples for net.minecraftforge.fluids FluidStack writeToNBT
public CompoundNBT writeToNBT(CompoundNBT nbt)
From source file:blusunrize.immersiveengineering.client.gui.GuiFluidSorter.java
public void setFluidInSlot(int side, int slot, FluidStack fluid) { tile.filters[side][slot] = fluid;/* w w w.j ava2s . co m*/ NBTTagCompound tag = new NBTTagCompound(); tag.setInteger("filter_side", side); tag.setInteger("filter_slot", slot); if (fluid != null) tag.setTag("filter", fluid.writeToNBT(new NBTTagCompound())); ImmersiveEngineering.packetHandler.sendToServer(new MessageTileSync(tile, tag)); }
From source file:blusunrize.immersiveengineering.common.util.compat.TConstructHelper.java
public static void sendAlloyForMelting(FluidStack output, Object... input) { assert (input.length % 2 == 0); FluidStack[] inputStacks = new FluidStack[input.length / 2]; for (int i = 0; i < inputStacks.length; i++) if (input[i * 2] instanceof String && input[i * 2 + 1] instanceof Integer) { Fluid f = FluidRegistry.getFluid((String) input[i * 2]); if (f != null) inputStacks[i] = new FluidStack(f, (Integer) input[i * 2 + 1]); }/*ww w.ja v a 2s.c o m*/ NBTTagList tagList = new NBTTagList(); tagList.appendTag(output.writeToNBT(new NBTTagCompound())); for (FluidStack stack : inputStacks) if (stack != null) tagList.appendTag(stack.writeToNBT(new NBTTagCompound())); NBTTagCompound message = new NBTTagCompound(); message.setTag("alloy", tagList); // FMLInterModComms.sendMessage("tconstruct", "alloy", message); // For some reason IMC on this is broken? So direct interaction is required. Oh well. TinkerRegistry.registerAlloy(output, inputStacks); }
From source file:blusunrize.immersiveengineering.common.util.inventory.MultiFluidTank.java
public NBTTagCompound writeToNBT(NBTTagCompound nbt) { NBTTagList tagList = new NBTTagList(); for (FluidStack fs : this.fluids) if (fs != null) tagList.appendTag(fs.writeToNBT(new NBTTagCompound())); nbt.setTag("fluids", tagList); return nbt;//from w w w . jav a2 s . c o m }
From source file:blusunrize.immersiveengineering.common.util.ItemNBTHelper.java
public static void setFluidStack(ItemStack stack, String key, FluidStack val) { if (val != null && val.getFluid() != null) { setTagCompound(stack, key, val.writeToNBT(new NBTTagCompound())); } else//from w w w. j a v a2 s . c o m remove(stack, key); }
From source file:boilerplate.common.utils.helpers.IMCHelper.java
License:Minecraft Mod Public
public static void addNewSmeltable(ItemStack item, Block toRender, FluidStack toProduce, int tempRequired) { NBTTagCompound tag = new NBTTagCompound(); NBTTagCompound itemtag = new NBTTagCompound(); item.writeToNBT(itemtag);/* w w w .j a va2 s . com*/ tag.setTag("Item", itemtag); NBTTagCompound block = new NBTTagCompound(); (new ItemStack(toRender, 1)).writeToNBT(block); tag.setTag("Block", block); toProduce.writeToNBT(tag); tag.setInteger("Temperature", tempRequired); FMLInterModComms.sendMessage("TConstruct", "addSmelteryMelting", tag); }
From source file:cd4017be.automation.Item.ItemTank.java
@Override public int fill(ItemStack item, FluidStack resource, boolean doFill) { if (resource == null) return 0; int n;/*from ww w. j a v a2s .c om*/ FluidStack fluid = this.getFluid(item); if (fluid != null) { if (!fluid.isFluidEqual(resource)) return 0; n = Math.min(this.getCapacity(item) - fluid.amount, resource.amount); if (doFill) { fluid.amount += n; fluid.writeToNBT(item.stackTagCompound); } } else { n = Math.min(this.getCapacity(item), resource.amount); if (doFill) { item.stackTagCompound = new NBTTagCompound(); fluid = resource.copy(); fluid.amount = n; fluid.writeToNBT(item.stackTagCompound); } } return n; }
From source file:cd4017be.automation.Item.ItemTank.java
@Override public FluidStack drain(ItemStack item, int maxDrain, boolean doDrain) { FluidStack fluid = this.getFluid(item); if (fluid == null || maxDrain == 0) return null; FluidStack ret = fluid.copy();//from ww w . j a va 2s . co m ret.amount = Math.min(fluid.amount, maxDrain); if (doDrain) { fluid.amount -= ret.amount; if (fluid.amount <= 0) item.stackTagCompound = null; else fluid.writeToNBT(item.stackTagCompound); } return ret; }
From source file:cd4017be.automation.Item.PipeUpgradeFluid.java
public static NBTTagCompound save(PipeUpgradeFluid upgrade) { NBTTagCompound nbt = new NBTTagCompound(); nbt.setByte("mode", upgrade.mode); nbt.setInteger("maxAm", upgrade.maxAmount); if (upgrade.list.length > 0) { NBTTagList list = new NBTTagList(); for (FluidStack fluid : upgrade.list) { NBTTagCompound tag = new NBTTagCompound(); fluid.writeToNBT(tag); list.appendTag(tag);//ww w. j a va2 s .c o m } nbt.setTag("list", list); } return nbt; }
From source file:com.builtbroken.atomic.content.items.cell.ItemFluidCell.java
@Override public int fill(ItemStack container, FluidStack resource, boolean doFill) { if (canSupportFluid(container, resource)) { if (!doFill) { if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Fluid")) { return Math.min(getCapacity(container), resource.amount); }/*from w w w . j a v a 2 s . com*/ FluidStack stack = FluidStack .loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("Fluid")); if (stack == null) { return Math.min(getCapacity(container), resource.amount); } if (!stack.isFluidEqual(resource)) { return 0; } return Math.min(getCapacity(container) - stack.amount, resource.amount); } if (container.stackTagCompound == null) { container.stackTagCompound = new NBTTagCompound(); } if (!container.stackTagCompound.hasKey("Fluid")) { NBTTagCompound fluidTag = resource.writeToNBT(new NBTTagCompound()); if (getCapacity(container) < resource.amount) { fluidTag.setInteger("Amount", getCapacity(container)); container.stackTagCompound.setTag("Fluid", fluidTag); return getCapacity(container); } container.stackTagCompound.setTag("Fluid", fluidTag); return resource.amount; } else { NBTTagCompound fluidTag = container.stackTagCompound.getCompoundTag("Fluid"); FluidStack stack = FluidStack.loadFluidStackFromNBT(fluidTag); if (!stack.isFluidEqual(resource)) { return 0; } int filled = getCapacity(container) - stack.amount; if (resource.amount < filled) { stack.amount += resource.amount; filled = resource.amount; } else { stack.amount = getCapacity(container); } container.stackTagCompound.setTag("Fluid", stack.writeToNBT(fluidTag)); return filled; } } return 0; }
From source file:com.smithsmodding.smithscore.common.tileentity.TileEntitySmithsCore.java
/** * Standard method to write the fluid data of this TE to the NBTCompound that stores this TE's Data. * * @return A NBTTagList with all fluids in the Tile. *///from w w w.ja v a2s .c om protected NBTBase writeFluidsToCompound() { IFluidContainingEntity fluidContainingEntity = (IFluidContainingEntity) this; NBTTagList fluidData = new NBTTagList(); for (FluidStack stack : fluidContainingEntity.getAllFluids()) { fluidData.appendTag(stack.writeToNBT(new NBTTagCompound())); } return fluidData; }