Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

(forge 9.11.1.965)

Pardon me if I'm writing total nonsense (I'm kind of close to madness right now) but I've wasted hours trying to get my TileFluidHandler based TileEntitys to sync up properly when I found this in the TileFluidHandler class

 

    @Override
    public void readFromNBT(NBTTagCompound tag)
    {
        super.readFromNBT(tag);
        tank.writeToNBT(tag);
    }

    @Override
    public void writeToNBT(NBTTagCompound tag)
    {
        super.writeToNBT(tag);
        tank.readFromNBT(tag);
    }

 

Aren't the tank.writeToNBT() and tank.readFromNBT() swapped ?

Nope that makes sense. It tells the Tile to save its data onto a NBT tag and then makes the IFluidTank read that data. Thats how forge syncs them.

 

If you post your TileEntity code and packet handing code, we might be able to help you track down your problem.

nvm.. Just opened the code. It wasnt doing what I thought it was. You could always try switching them and seeing if it works.

  • Author

@Op: Yes, looks like a bug to me. Fix: Don't use TileFluidHandler.

 

Yeah that's what I figured. I ended up basically copying the TileFluidHandler code into my own IFluidHandler implementation, switched the NBT read/write around and added the syncing. Seems to work for now. It's neither pretty nor does it do much on it's own but here is the code if someone is interested.

 

package simplefluidtanks;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet132TileEntityData;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;

public class ValveBlockEntity extends TileEntity implements IFluidHandler
{
protected FluidTank tank;

public ValveBlockEntity()
{
	super();
	this.tank = new FluidTank(SimpleFluidTanks.bucketsPerTank * FluidContainerRegistry.BUCKET_VOLUME);
}

    @Override
    public void readFromNBT(NBTTagCompound tag)
    {
        super.readFromNBT(tag);
        tank.readFromNBT(tag);
    }

    @Override
    public void writeToNBT(NBTTagCompound tag)
    {
        super.writeToNBT(tag);
        tank.writeToNBT(tag);
    }

    @Override
    public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
    {
    	int fillAmount = tank.fill(resource, doFill);
this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
    	
        return fillAmount;
    }

    @Override
    public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
    {
        if (resource == null || !resource.isFluidEqual(tank.getFluid()))
        {
            return null;
        }
        
        FluidStack drainedFluid = tank.drain(resource.amount, doDrain);
        this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
        
        return drainedFluid;
    }

    @Override
    public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
    {
    	this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
    	FluidStack drainedFluid =  tank.drain(maxDrain, doDrain);
    	
    	return drainedFluid;
    }

    @Override
    public boolean canFill(ForgeDirection from, Fluid fluid)
    {
        return true;
    }

    @Override
    public boolean canDrain(ForgeDirection from, Fluid fluid)
    {
        return true;
    }

    @Override
    public FluidTankInfo[] getTankInfo(ForgeDirection from)
    {
        return new FluidTankInfo[] { tank.getInfo() };
    }

@Override
public Packet getDescriptionPacket()
{
	NBTTagCompound tag = new NBTTagCompound();
	writeToNBT(tag);

	return new Packet132TileEntityData(xCoord, yCoord, zCoord, 1, tag);
}

@Override
public void onDataPacket(INetworkManager net, Packet132TileEntityData packet)
{
	readFromNBT(packet.data);
}

public int getCapacity()
{
	return tank.getCapacity();
}

public int getFluidAmount()
{
	return tank.getFluidAmount();
}

public FluidStack getFluid()
{
	return tank.getFluid();
}
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.