Java Code Examples for net.minecraftforge.fluids.FluidStack#loadFluidStackFromNBT()

The following examples show how to use net.minecraftforge.fluids.FluidStack#loadFluidStackFromNBT() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PhantomFluidWidget.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void handleClientAction(int id, PacketBuffer buffer) {
    if (id == 1) {
        ItemStack itemStack = gui.entityPlayer.inventory.getItemStack().copy();
        if (!itemStack.isEmpty()) {
            itemStack.setCount(1);
            IFluidHandlerItem fluidHandler = itemStack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
            if (fluidHandler != null) {
                FluidStack resultFluid = fluidHandler.drain(Integer.MAX_VALUE, false);
                fluidStackUpdater.accept(resultFluid);
            }
        } else {
            fluidStackUpdater.accept(null);
        }
    } else if (id == 2) {
        FluidStack fluidStack;
        try {
            fluidStack = FluidStack.loadFluidStackFromNBT(buffer.readCompoundTag());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        fluidStackUpdater.accept(fluidStack);
    }
}
 
Example 2
Source File: TileEntityPoweredInventoryFluid.java    From BigReactors with MIT License 6 votes vote down vote up
private void readFluidsFromNBT(NBTTagCompound tag) {
	// Initialize tanks to empty, as we send sparse updates.
	for(int i = 0; i < tanks.length; i++) {
		tanks[i].setFluid(null);
	}

	if(tag.hasKey("fluids")) {
		NBTTagList tagList = tag.getTagList("fluids", 10);
		for(int i = 0; i < tagList.tagCount(); i++) {
			NBTTagCompound fluidTag = tagList.getCompoundTagAt(i);
			int fluidIdx = fluidTag.getInteger("tagIdx");
			FluidStack newFluid = FluidStack.loadFluidStackFromNBT(fluidTag);
			tanks[fluidIdx].setFluid(newFluid);
		}
	}
}
 
Example 3
Source File: BlockTank.java    From YouTubeModdingTutorial with MIT License 6 votes vote down vote up
@Override
public void addInformation(ItemStack stack, @Nullable World world, List<String> tooltip, ITooltipFlag flags) {
    NBTTagCompound tagCompound = stack.getTagCompound();
    if (tagCompound != null) {
        NBTTagCompound nbt = tagCompound.getCompoundTag("tank");
        FluidStack fluidStack = null;
        if (!nbt.hasKey("Empty")) {
            fluidStack = FluidStack.loadFluidStackFromNBT(nbt);
        }
        if (fluidStack == null) {
            addInformationLocalized(tooltip, "message.mymod.tank", "empty");
        } else {
            String name = fluidStack.getLocalizedName();
            addInformationLocalized(tooltip, "message.mymod.tank", name + " (" + fluidStack.amount + ")");
        }
    }
}
 
Example 4
Source File: ItemBlockCertusTank.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4)
{
	if (stack != null && stack.hasTagCompound())
	{
		if (FluidStack.loadFluidStackFromNBT(stack.getTagCompound().getCompoundTag("tileEntity")) != null)
			list.add(FluidStack.loadFluidStackFromNBT(stack.getTagCompound().getCompoundTag("tileEntity")).amount + "mB");
	}
}
 
Example 5
Source File: ByteBufUtils.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static FluidStack readFluidStack(PacketBuffer buf) {
    if (!buf.readBoolean()) {
        return null;
    }
    try {
        NBTTagCompound tagCompound = buf.readCompoundTag();
        return FluidStack.loadFluidStackFromNBT(tagCompound);
    } catch (IOException exception) {
        throw new RuntimeException(exception);
    }
}
 
Example 6
Source File: AmadronOffer.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
public static AmadronOffer loadFromNBT(NBTTagCompound tag){
    Object input;
    if(tag.hasKey("inputItem")) {
        input = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("inputItem"));
    } else {
        input = FluidStack.loadFluidStackFromNBT(tag.getCompoundTag("inputFluid"));
    }
    Object output;
    if(tag.hasKey("outputItem")) {
        output = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("outputItem"));
    } else {
        output = FluidStack.loadFluidStackFromNBT(tag.getCompoundTag("outputFluid"));
    }
    return new AmadronOffer(input, output);
}
 
Example 7
Source File: ItemEnderBucket.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
public FluidStack getFluid(ItemStack stack, @Nullable EntityPlayer player)
{
    NBTTagCompound nbt = stack.getTagCompound();

    if (nbt == null)
    {
        return null;
    }

    // The Bucket has been linked to a tank
    if (LinkMode.fromStack(stack) == LinkMode.ENABLED)
    {
        if (OwnerData.canAccessSelectedModule(stack, ModuleType.TYPE_LINKCRYSTAL, player) == false)
        {
            return null;
        }

        IFluidHandler handler = this.getLinkedTank(stack);

        if (handler != null)
        {
            FluidStack fluidStack = handler.drain(Integer.MAX_VALUE, false);

            // Cache the fluid stack into the link crystal's NBT for easier/faster access for tooltip and rendering stuffs
            this.cacheFluid(stack, fluidStack);

            return fluidStack;
        }

        return null;
    }

    // Not linked to a tank, get the internal FluidStack
    if (nbt.hasKey("Fluid", Constants.NBT.TAG_COMPOUND))
    {
        return FluidStack.loadFluidStackFromNBT(nbt.getCompoundTag("Fluid"));
    }

    return null;
}
 
Example 8
Source File: ItemEnderBucket.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
public FluidStack getFluidCached(ItemStack stack)
{
    NBTTagCompound nbt = stack.getTagCompound();

    if (nbt != null)
    {
        // The Bucket has been linked to a tank
        if (LinkMode.fromStack(stack) == LinkMode.ENABLED)
        {
            ItemStack moduleStack = this.getSelectedModuleStack(stack, ModuleType.TYPE_LINKCRYSTAL);

            if (moduleStack.isEmpty() == false && moduleStack.getTagCompound() != null)
            {
                if (moduleStack.getTagCompound().hasKey("FluidCached", Constants.NBT.TAG_COMPOUND))
                {
                    return FluidStack.loadFluidStackFromNBT(moduleStack.getTagCompound().getCompoundTag("FluidCached"));
                }
            }
        }
        // Not linked to a tank, get the internal FluidStack
        else if (nbt.hasKey("Fluid", Constants.NBT.TAG_COMPOUND))
        {
            return FluidStack.loadFluidStackFromNBT(nbt.getCompoundTag("Fluid"));
        }
    }

    return null;
}
 
Example 9
Source File: BarrelModeFluidTransform.java    From ExNihiloAdscensio with MIT License 5 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound tag) {
	if (tag.hasKey("inputTag")) {
		NBTTagCompound inputTag = (NBTTagCompound) tag.getTag("inputTag");
		inputStack = FluidStack.loadFluidStackFromNBT(inputTag);
	}
	if (tag.hasKey("outputTag")) {
		NBTTagCompound outputTag = (NBTTagCompound) tag.getTag("outputTag");
		outputStack = FluidStack.loadFluidStackFromNBT(outputTag);
	}
	if (tag.hasKey("progress")) {
		progress = tag.getFloat("progress");
	}

}
 
Example 10
Source File: PacketSyncContainerFluid.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void fromBytes(ByteBuf buf)
{
    windowId = buf.readByte();
    tank = buf.readByte();

    NBTTagCompound fluidNbt = ByteBufUtils.readTag(buf);
    fluid = FluidStack.loadFluidStackFromNBT(fluidNbt);
}
 
Example 11
Source File: GTBlockQuantumTank.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void addInformation(ItemStack stack, World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
	if (stack.hasTagCompound()) {
		NBTTagCompound nbt;
		nbt = StackUtil.getNbtData(stack);
		if (nbt.hasKey("Fluid")) {
			FluidStack fluid = FluidStack.loadFluidStackFromNBT(nbt.getCompoundTag("Fluid"));
			tooltip.add(TextFormatting.AQUA + I18n.format(fluid.amount + "mB of " + fluid.getLocalizedName()));
		}
	}
	super.addInformation(stack, worldIn, tooltip, flagIn);
}
 
Example 12
Source File: GTBlockDrum.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void addInformation(ItemStack stack, World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
	if (stack.hasTagCompound()) {
		NBTTagCompound nbt;
		nbt = StackUtil.getNbtData(stack);
		if (nbt.hasKey("Fluid")) {
			FluidStack fluid = FluidStack.loadFluidStackFromNBT(nbt.getCompoundTag("Fluid"));
			tooltip.add(I18n.format(fluid.amount + "mB of " + fluid.getLocalizedName()));
		}
	}
	super.addInformation(stack, worldIn, tooltip, flagIn);
}
 
Example 13
Source File: SimpleFluidFilter.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void readFromNBT(NBTTagCompound tagCompound) {
    NBTTagList filterSlots = tagCompound.getTagList("FluidFilter", 10);
    for (NBTBase nbtBase : filterSlots) {
        NBTTagCompound stackTag = (NBTTagCompound) nbtBase;
        FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(stackTag);
        this.fluidFilterSlots[stackTag.getInteger("Slot")] = fluidStack;
    }
}
 
Example 14
Source File: MetaTileEntityCokeOven.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void readFromNBT(NBTTagCompound data) {
    super.readFromNBT(data);
    this.isActive = data.getBoolean("Active");
    this.wasActiveAndNeedUpdate = data.getBoolean("WasActive");
    this.maxProgressDuration = data.getInteger("MaxProgress");
    if (maxProgressDuration > 0) {
        this.currentProgress = data.getInteger("Progress");
        this.outputStack = new ItemStack(data.getCompoundTag("OutputItem"));
        this.outputFluid = FluidStack.loadFluidStackFromNBT(data.getCompoundTag("OutputFluid"));
    }
}
 
Example 15
Source File: MetaTileEntityTank.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, @Nullable World player, List<String> tooltip, boolean advanced) {
    tooltip.add(I18n.format("gregtech.universal.tooltip.fluid_storage_capacity", tankSize));
    tooltip.add(I18n.format("gregtech.machine.fluid_tank.max_multiblock", maxSizeHorizontal, maxSizeVertical, maxSizeHorizontal));
    NBTTagCompound tagCompound = stack.getTagCompound();
    if (tagCompound != null && tagCompound.hasKey("Fluid", NBT.TAG_COMPOUND)) {
        FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(tagCompound.getCompoundTag("Fluid"));
        if (fluidStack != null) {
            tooltip.add(I18n.format("gregtech.machine.fluid_tank.fluid", fluidStack.amount, fluidStack.getLocalizedName()));
        }
    }
}
 
Example 16
Source File: MetaTileEntityTank.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SideOnly(Side.CLIENT)
private FluidStack getFluidForRendering() {
    if (getWorld() == null && renderContextStack != null) {
        NBTTagCompound tagCompound = renderContextStack.getTagCompound();
        if (tagCompound != null && tagCompound.hasKey("Fluid", NBT.TAG_COMPOUND)) {
            return FluidStack.loadFluidStackFromNBT(tagCompound.getCompoundTag("Fluid"));
        }
        return null;
    }
    return getActualTankFluid();
}
 
Example 17
Source File: MetaTileEntityTank.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void initFromItemStackData(NBTTagCompound itemStack) {
    super.initFromItemStackData(itemStack);
    if (itemStack.hasKey(FluidHandlerItemStack.FLUID_NBT_KEY, NBT.TAG_COMPOUND)) {
        FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(itemStack.getCompoundTag(FluidHandlerItemStack.FLUID_NBT_KEY));
        this.multiblockFluidTank.fill(fluidStack, true);
    }
}
 
Example 18
Source File: PhantomFluidWidget.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void readUpdateInfo(int id, PacketBuffer buffer) {
    if (id == 1) {
        if (buffer.readBoolean()) {
            try {
                NBTTagCompound tagCompound = buffer.readCompoundTag();
                this.lastFluidStack = FluidStack.loadFluidStackFromNBT(tagCompound);
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            this.lastFluidStack = null;
        }
    }
}
 
Example 19
Source File: ItemRendererCertusTank.java    From ExtraCells1 with MIT License 4 votes vote down vote up
public void renderItem(ItemRenderType type, ItemStack item, Object... data)
{
	Minecraft.getMinecraft().renderEngine.bindTexture(new ResourceLocation("extracells", "textures/blocks/texmap_tank.png"));
	GL11.glPushMatrix();
	GL11.glTranslatef(0.5F, 0.5F, 0.5F);
	GL11.glScalef(1.0F, -1F, -1F);
	model.render(0.0625f);
	GL11.glScalef(1.0F, -1F, 1.0F);
	model.render(0.0625f);

	if (item != null && item.hasTagCompound())
	{
		FluidStack storedFluid = FluidStack.loadFluidStackFromNBT(item.getTagCompound().getCompoundTag("tileEntity"));
		int tankCapacity = 32000;

		if (storedFluid != null && storedFluid.getFluid() != null)
		{
			Icon fluidIcon = storedFluid.getFluid().getIcon();

			Tessellator tessellator = Tessellator.instance;
			RenderBlocks renderer = new RenderBlocks();

			GL11.glScalef(1.0F, 1.0F, -1.0F);
			renderer.setRenderBounds(0.08F, 0.001F, 0.08F, 0.92, (float) storedFluid.amount / (float) tankCapacity * 0.999F, 0.92F);
			Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture);
			GL11.glTranslatef(-0.5F, -0.5F, -0.5F);

			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);

			tessellator.startDrawingQuads();
			tessellator.setNormal(0.0F, -1F, 0.0F);
			renderer.renderFaceYNeg(Block.blocksList[FluidRegistry.WATER.getBlockID()], 0.0D, 0.0D, 0.0D, fluidIcon);
			tessellator.draw();
			tessellator.startDrawingQuads();
			tessellator.setNormal(0.0F, 1.0F, 0.0F);
			renderer.renderFaceYPos(Block.blocksList[FluidRegistry.WATER.getBlockID()], 0.0D, 0.0D, 0.0D, fluidIcon);
			tessellator.draw();
			tessellator.startDrawingQuads();
			tessellator.setNormal(0.0F, 0.0F, -1F);
			renderer.renderFaceZNeg(Block.blocksList[FluidRegistry.WATER.getBlockID()], 0.0D, 0.0D, 0.0D, fluidIcon);
			tessellator.draw();
			tessellator.startDrawingQuads();
			tessellator.setNormal(0.0F, 0.0F, 1.0F);
			renderer.renderFaceZPos(Block.blocksList[FluidRegistry.WATER.getBlockID()], 0.0D, 0.0D, 0.0D, fluidIcon);
			tessellator.draw();
			tessellator.startDrawingQuads();
			tessellator.setNormal(-1F, 0.0F, 0.0F);
			renderer.renderFaceXNeg(Block.blocksList[FluidRegistry.WATER.getBlockID()], 0.0D, 0.0D, 0.0D, fluidIcon);
			tessellator.draw();
			tessellator.startDrawingQuads();
			tessellator.setNormal(1.0F, 0.0F, 0.0F);
			renderer.renderFaceXPos(Block.blocksList[FluidRegistry.WATER.getBlockID()], 0.0D, 0.0D, 0.0D, fluidIcon);
			tessellator.draw();

			GL11.glPopAttrib();
		}
	}

	GL11.glPopMatrix();
}
 
Example 20
Source File: FluidUtils.java    From CodeChickenCore with MIT License 4 votes vote down vote up
public static FluidStack read(NBTTagCompound tag) {
    FluidStack stack = FluidStack.loadFluidStackFromNBT(tag);
    return stack != null ? stack : new FluidStack(0, 0);
}