Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.12.2] problem with sending fluidtank to client


Tieso2001
 Share

Recommended Posts

I have created a TileEntity that has a fluidtank. Now I am trying to draw the fluid that is in the tank in the TileEntity's gui. The problem is that I have no idea on how to communicate the fluidstack or fluidtank with the client. I know that I can send integers with detectAndSendChanges() in the container class using listeners, but I don't think I can send any other data like a fluidstack or a fluidtank with this method. How do I communicate a fluidtank or a fluidstack from my TileEntity on the server to the gui on the client?

Edited by Tieso2001
Link to comment
Share on other sites

You can use packets.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to comment
Share on other sites

So I created a packet for sending the FluidTank, but I have no idea how I should write and read it to ByteBuf, If it was an integer I could use buf.writeInt(), but how do I do that with a FluidTank.

public class MessageFluidTank implements IMessage
{
    private FluidTank fluidTank;

    public MessageFluidTank(FluidTank fluidTank)
    {
        this.fluidTank = fluidTank;
    }

    @Override
    public void toBytes(ByteBuf buf)
    {
        buf.writeBytes(fluidTank); // How do I write fluidTank to buf
    }

    @Override
    public void fromBytes(ByteBuf buf)
    {
        fluidTank = buf.readBytes(); // How do I read fluidTank from buf
    }
}

 

Link to comment
Share on other sites

ByteBuf isn't magically going to accept any object. As any kind of (de)serialization you need to divide whatever it is you are sending into types that can be written onto a buffer and construct an identical one at the receiving end.

 

Although with a fluidstack you would serialize it to a NBTTagCompound and send that over the network in case a mod stores additional NBT data in the fluid stack.

Link to comment
Share on other sites

Okay so I think I have figured out how to write and read a FluidStack from ByteBuf, Here is the code I have:

 

Packet class:

Spoiler

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;

public class PacketFluidTankUpdate implements IMessage
{
    private FluidStack fluidStack;

    public PacketFluidTankUpdate(FluidStack fluidStack)
    {
        this.fluidStack = fluidStack;
    }

    @Override
    public void toBytes(ByteBuf buf)
    {
        PacketBufferMod data = new PacketBufferMod(Unpooled.buffer());
        data.writeFluidStack(fluidStack);
        buf.writeBytes(data);
    }

    @Override
    public void fromBytes(ByteBuf buf)
    {
        PacketBufferMod data = (PacketBufferMod) buf.readBytes(buf);
        fluidStack = data.readFluidStack();
    }
}

 

 

PacketHandler class:

Spoiler

import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

public class PacketHandlerFluidTankUpdate implements IMessageHandler<PacketFluidTankUpdate, IMessage>
{
    @Override
    public IMessage onMessage(PacketFluidTankUpdate message, MessageContext ctx)
    {

    }
}

 

 

PacketBuffer class:

Spoiler

import io.netty.buffer.ByteBuf;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;

import javax.annotation.Nullable;

public class PacketBufferMod extends PacketBuffer
{
    public PacketBufferMod(ByteBuf wrapped)
    {
        super(wrapped);
    }

    public void writeFluidStack(@Nullable FluidStack fluidStack)
    {
        if (fluidStack == null) writeVarInt(-1);
        else {
            writeVarInt(fluidStack.amount);
            writeString(fluidStack.getFluid().getName());
        }
    }

    @Nullable
    public FluidStack readFluidStack()
    {
        int amount = readVarInt();
        if (amount > 0)
        {
            String fluidName = readString(1024);
            Fluid fluid = FluidRegistry.getFluid(fluidName);
            if (fluid == null) return null;
            return new FluidStack(fluid, amount);
        }
        return null;
    }
}

 

 

According to the forge documentation I have to create PacketHandler class which implements IMessageHandler, so I created PacketHandlerFluidTankUpdate. I have no idea what I have to do so that the GUI in my TileEntity updates with the right fluid (amount).

Link to comment
Share on other sites

Brief summary: I'm trying to create a packet for sending a FluidStack from the server to the client, so that the GUI of my TileEntity can be updated on the client.

 

I have tried some things and this is what I currently have:

 

The packet & the handler for the packet:

Spoiler

public class PacketFluidTankUpdate implements IMessage
{
    private BlockPos pos;
    private FluidStack fluidStack;

    public PacketFluidTankUpdate(TileStockPot tileStockPot, FluidStack fluidStack)
    {
        this.pos = tileStockPot.getPos();
        this.fluidStack = fluidStack;
    }

    @Override
    public void toBytes(ByteBuf buf)
    {
        PacketBufferMod data = new PacketBufferMod(Unpooled.buffer());
        data.writeBlockPos(pos);
        data.writeFluidStack(fluidStack);
        buf.writeBytes(data);
    }

    @Override
    public void fromBytes(ByteBuf buf)
    {
        PacketBufferMod data = (PacketBufferMod) buf.readBytes(buf);
        pos = data.readBlockPos();
        fluidStack = data.readFluidStack();
    }

    @SideOnly(Side.CLIENT)
    public static class PacketHandler implements IMessageHandler<PacketFluidTankUpdate, IMessage>
    {
        @Override
        public IMessage onMessage(PacketFluidTankUpdate message, MessageContext ctx)
        {
            EntityPlayerMP serverPlayer = ctx.getServerHandler().player;
            BlockPos pos = message.pos;
            FluidStack fluidStack = message.fluidStack;
            TileEntity tileEntity = serverPlayer.world.getTileEntity(pos);

            if (tileEntity != null)
            {
                if (tileEntity instanceof TileStockPot)
                {
                    if (serverPlayer.world.isBlockLoaded(pos))
                    {
                        serverPlayer.getServerWorld().addScheduledTask(() -> ((TileStockPot) tileEntity).getFluidTank().setFluid(fluidStack));
                    }
                }
            }
            return null;
        }
    }
}

 

 

SimpleNetworkWrapper object:

Spoiler

public class ModPacketHandler
{
    public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(BoneAppleTea.MODID);
}

 

 

PacketBuffer class (for storing FluidStack & BlockPos):

Spoiler

public class PacketBufferMod extends PacketBuffer
{
    public PacketBufferMod(ByteBuf wrapped)
    {
        super(wrapped);
    }

    public void writeFluidStack(@Nullable FluidStack fluidStack)
    {
        if (fluidStack == null) writeVarInt(-1);
        else {
            writeVarInt(fluidStack.amount);
            writeString(fluidStack.getFluid().getName());
        }
    }

    @Nullable
    public FluidStack readFluidStack()
    {
        int amount = readVarInt();
        if (amount > 0)
        {
            String fluidName = readString(1024);
            Fluid fluid = FluidRegistry.getFluid(fluidName);
            if (fluid == null) return null;
            return new FluidStack(fluid, amount);
        }
        return null;
    }
}

 

 

(the relevant) part of the container class for my TileEntity

Spoiler

@Override
    public void detectAndSendChanges()
    {
        super.detectAndSendChanges();

        for (IContainerListener listener : listeners)
        {
            if (listener instanceof EntityPlayerMP)
            {
                ModPacketHandler.INSTANCE.sendToAll(new PacketFluidTankUpdate(tileEntity, tileEntity.getFluidTank().getFluid()));
            }
        }
    }

 

 

When I open my TileEntity ingame, I get the following error:

Network Disconnect: A fatal error has occurred, this connection is terminated

Spoiler

[18:43:26] [Netty Local Client IO #0/ERROR] [FML]: FMLIndexedMessageCodec exception caught
io.netty.handler.codec.DecoderException: java.lang.InstantiationException: com.tieso2001.boneappletea.network.PacketFluidTankUpdate
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:98) ~[MessageToMessageDecoder.class:4.1.9.Final]
	at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334) [DefaultChannelPipeline$HeadContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926) [DefaultChannelPipeline.class:4.1.9.Final]
	at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:274) [EmbeddedChannel.class:4.1.9.Final]
	at net.minecraftforge.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:108) [FMLProxyPacket.class:?]
	at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:155) [NetworkManager.class:?]
	at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:49) [NetworkManager.class:?]
	at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [SimpleChannelInboundHandler.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.handleClientSideCustomPacket(NetworkDispatcher.java:385) [NetworkDispatcher.class:?]
	at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:271) [NetworkDispatcher.class:?]
	at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:72) [NetworkDispatcher.class:?]
	at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [SimpleChannelInboundHandler.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334) [DefaultChannelPipeline$HeadContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926) [DefaultChannelPipeline.class:4.1.9.Final]
	at io.netty.channel.local.LocalChannel.finishPeerRead0(LocalChannel.java:443) [LocalChannel.class:4.1.9.Final]
	at io.netty.channel.local.LocalChannel.access$500(LocalChannel.java:49) [LocalChannel.class:4.1.9.Final]
	at io.netty.channel.local.LocalChannel$5.run(LocalChannel.java:397) [LocalChannel$5.class:4.1.9.Final]
	at io.netty.channel.DefaultEventLoop.run(DefaultEventLoop.java:54) [DefaultEventLoop.class:4.1.9.Final]
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858) [SingleThreadEventExecutor$5.class:4.1.9.Final]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_192]
Caused by: java.lang.InstantiationException: com.tieso2001.boneappletea.network.PacketFluidTankUpdate
	at java.lang.Class.newInstance(Class.java:427) ~[?:1.8.0_192]
	at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:109) ~[FMLIndexedMessageToMessageCodec.class:?]
	at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:41) ~[FMLIndexedMessageToMessageCodec.class:?]
	at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:4.1.9.Final]
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:88) ~[MessageToMessageDecoder.class:4.1.9.Final]
	... 33 more
Caused by: java.lang.NoSuchMethodException: com.tieso2001.boneappletea.network.PacketFluidTankUpdate.<init>()
	at java.lang.Class.getConstructor0(Class.java:3082) ~[?:1.8.0_192]
	at java.lang.Class.newInstance(Class.java:412) ~[?:1.8.0_192]
	at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:109) ~[FMLIndexedMessageToMessageCodec.class:?]
	at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:41) ~[FMLIndexedMessageToMessageCodec.class:?]
	at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:4.1.9.Final]
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:88) ~[MessageToMessageDecoder.class:4.1.9.Final]
	... 33 more
[18:43:26] [Netty Local Client IO #0/ERROR] [FML]: SimpleChannelHandlerWrapper exception
io.netty.handler.codec.DecoderException: java.lang.InstantiationException: com.tieso2001.boneappletea.network.PacketFluidTankUpdate
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:98) ~[MessageToMessageDecoder.class:4.1.9.Final]
	at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334) [DefaultChannelPipeline$HeadContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926) [DefaultChannelPipeline.class:4.1.9.Final]
	at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:274) [EmbeddedChannel.class:4.1.9.Final]
	at net.minecraftforge.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:108) [FMLProxyPacket.class:?]
	at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:155) [NetworkManager.class:?]
	at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:49) [NetworkManager.class:?]
	at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [SimpleChannelInboundHandler.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.handleClientSideCustomPacket(NetworkDispatcher.java:385) [NetworkDispatcher.class:?]
	at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:271) [NetworkDispatcher.class:?]
	at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:72) [NetworkDispatcher.class:?]
	at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [SimpleChannelInboundHandler.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334) [DefaultChannelPipeline$HeadContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926) [DefaultChannelPipeline.class:4.1.9.Final]
	at io.netty.channel.local.LocalChannel.finishPeerRead0(LocalChannel.java:443) [LocalChannel.class:4.1.9.Final]
	at io.netty.channel.local.LocalChannel.access$500(LocalChannel.java:49) [LocalChannel.class:4.1.9.Final]
	at io.netty.channel.local.LocalChannel$5.run(LocalChannel.java:397) [LocalChannel$5.class:4.1.9.Final]
	at io.netty.channel.DefaultEventLoop.run(DefaultEventLoop.java:54) [DefaultEventLoop.class:4.1.9.Final]
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858) [SingleThreadEventExecutor$5.class:4.1.9.Final]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_192]
Caused by: java.lang.InstantiationException: com.tieso2001.boneappletea.network.PacketFluidTankUpdate
	at java.lang.Class.newInstance(Class.java:427) ~[?:1.8.0_192]
	at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:109) ~[FMLIndexedMessageToMessageCodec.class:?]
	at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:41) ~[FMLIndexedMessageToMessageCodec.class:?]
	at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:4.1.9.Final]
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:88) ~[MessageToMessageDecoder.class:4.1.9.Final]
	... 33 more
Caused by: java.lang.NoSuchMethodException: com.tieso2001.boneappletea.network.PacketFluidTankUpdate.<init>()
	at java.lang.Class.getConstructor0(Class.java:3082) ~[?:1.8.0_192]
	at java.lang.Class.newInstance(Class.java:412) ~[?:1.8.0_192]
	at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:109) ~[FMLIndexedMessageToMessageCodec.class:?]
	at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:41) ~[FMLIndexedMessageToMessageCodec.class:?]
	at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:4.1.9.Final]
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:88) ~[MessageToMessageDecoder.class:4.1.9.Final]
	... 33 more
[18:43:26] [Netty Local Client IO #0/ERROR] [FML]: There was a critical exception handling a packet on channel boneappletea
io.netty.handler.codec.DecoderException: java.lang.InstantiationException: com.tieso2001.boneappletea.network.PacketFluidTankUpdate
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:98) ~[MessageToMessageDecoder.class:4.1.9.Final]
	at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334) ~[DefaultChannelPipeline$HeadContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926) ~[DefaultChannelPipeline.class:4.1.9.Final]
	at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:274) ~[EmbeddedChannel.class:4.1.9.Final]
	at net.minecraftforge.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:108) [FMLProxyPacket.class:?]
	at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:155) [NetworkManager.class:?]
	at net.minecraft.network.NetworkManager.channelRead0(NetworkManager.java:49) [NetworkManager.class:?]
	at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [SimpleChannelInboundHandler.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.handleClientSideCustomPacket(NetworkDispatcher.java:385) [NetworkDispatcher.class:?]
	at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:271) [NetworkDispatcher.class:?]
	at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.channelRead0(NetworkDispatcher.java:72) [NetworkDispatcher.class:?]
	at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [SimpleChannelInboundHandler.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334) [DefaultChannelPipeline$HeadContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [AbstractChannelHandlerContext.class:4.1.9.Final]
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926) [DefaultChannelPipeline.class:4.1.9.Final]
	at io.netty.channel.local.LocalChannel.finishPeerRead0(LocalChannel.java:443) [LocalChannel.class:4.1.9.Final]
	at io.netty.channel.local.LocalChannel.access$500(LocalChannel.java:49) [LocalChannel.class:4.1.9.Final]
	at io.netty.channel.local.LocalChannel$5.run(LocalChannel.java:397) [LocalChannel$5.class:4.1.9.Final]
	at io.netty.channel.DefaultEventLoop.run(DefaultEventLoop.java:54) [DefaultEventLoop.class:4.1.9.Final]
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858) [SingleThreadEventExecutor$5.class:4.1.9.Final]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_192]
Caused by: java.lang.InstantiationException: com.tieso2001.boneappletea.network.PacketFluidTankUpdate
	at java.lang.Class.newInstance(Class.java:427) ~[?:1.8.0_192]
	at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:109) ~[FMLIndexedMessageToMessageCodec.class:?]
	at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:41) ~[FMLIndexedMessageToMessageCodec.class:?]
	at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:4.1.9.Final]
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:88) ~[MessageToMessageDecoder.class:4.1.9.Final]
	... 33 more
Caused by: java.lang.NoSuchMethodException: com.tieso2001.boneappletea.network.PacketFluidTankUpdate.<init>()
	at java.lang.Class.getConstructor0(Class.java:3082) ~[?:1.8.0_192]
	at java.lang.Class.newInstance(Class.java:412) ~[?:1.8.0_192]
	at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:109) ~[FMLIndexedMessageToMessageCodec.class:?]
	at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:41) ~[FMLIndexedMessageToMessageCodec.class:?]
	at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:4.1.9.Final]
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:88) ~[MessageToMessageDecoder.class:4.1.9.Final]
	... 33 more
[18:43:26] [Netty Local Client IO #0/ERROR] [FML]: Network Disconnect: A fatal error has occurred, this connection is terminated

 

 

If somebody could me help out with what is wrong / what isn't working. I would really appreciate that. Thanks in advance.

Link to comment
Share on other sites

1 hour ago, Tieso2001 said:

PacketBufferMod data = new PacketBufferMod(Unpooled.buffer());

What is this? Why are you doing this? I told you what you needed to do

On 5/3/2019 at 4:37 PM, V0idWa1k3r said:

with a fluidstack you would serialize it to a NBTTagCompound and send that over the network

Why did you create a custom PacketBuffer implementation? You don't need it, discatd it and don't do that pretty much ever again.

 

1 hour ago, Tieso2001 said:

I'm trying to create a packet for sending a FluidStack from the server to the client

 

1 hour ago, Tieso2001 said:

EntityPlayerMP serverPlayer = ctx.getServerHandler().player;

Your statement conflicts your implementation. Your implementation works as if the client is sending the fluid stack to the server(don't ever do that either by the way).

 

1 hour ago, Tieso2001 said:

When I open my TileEntity ingame, I get the following error:

 

 

1 hour ago, Tieso2001 said:

Caused by: java.lang.NoSuchMethodException: com.tieso2001.boneappletea.network.PacketFluidTankUpdate.<init>()

An IMessage implementation must have a parameterless constructor. Which the error report is telling you. Learn to read the error report, in 90% of cases the issue is stated right in it.

Link to comment
Share on other sites

@Override
    public void toBytes(ByteBuf buf)
    {
        NBTTagCompound compound = new NBTTagCompound();
        fluidStack.writeToNBT(compound);
    }

    @Override
    public void fromBytes(ByteBuf buf)
    {

    }

 

Okay so I wrote the FluidStack to NBTTagCompound, but now I don't know what to do. I have to write it to buf, but I don't know how exactly. It has to be a byte or an int.

I can convert the compound to byte with compound.getId(), but I don't know how that can be converted back into a fluidstack in fromBytes().

I can also convert it to an int with compound.hashcode(), but I don't that is of any use here.

 

I want to thank you for helping me, this networking stuff is all new to me so I appreciate that you take the effort to help me with this. Let me explain the things I have done and why I did.

 

Custom PacketBuffer implementation:

3 hours ago, V0idWa1k3r said:

What is this? Why are you doing this?

I got confused how write the NBTTagCompound to ByteBuf, so I started searching for other people that use FluidTank's in GUI's. I found the Forestry code on github and there it was done with a custom PacketBuffer implementation, so I thought that I also had to use that.

 

serverPlayer:

3 hours ago, V0idWa1k3r said:

Your statement conflicts your implementation. Your implementation works as if the client is sending the fluid stack to the server(don't ever do that either by the way).

In the forge documentation they get the player by using ctx.getServerHandler().player; I tried to do ctx.getClientHandler() but I can't retrieve the player from that.

 

And also:

3 hours ago, V0idWa1k3r said:

An IMessage implementation must have a parameterless constructor. Which the error report is telling you. Learn to read the error report, in 90% of cases the issue is stated right in it. 

Thank you, I fixed that now.

Link to comment
Share on other sites

12 minutes ago, Tieso2001 said:

Okay so I wrote the FluidStack to NBTTagCompound, but now I don't know what to do. I have to write it to buf, but I don't know how exactly. It has to be a byte or an int.

ByteBufUtils(or ByteBufUtil) is a helper class that allows you to write/read NBT to/from a ByteBuffer.

 

13 minutes ago, Tieso2001 said:

In the forge documentation they get the player by using ctx.getServerHandler().player; I tried to do ctx.getClientHandler() but I can't retrieve the player from that.

Well, there is only one player on the client... (Minecraft.getMinecraft().player)

Link to comment
Share on other sites

Thanks I got that part working now, but now I got this error when I open the TileEntity:

Caused by: java.lang.IndexOutOfBoundsException: readerIndex(0) + length(1) exceeds writerIndex(0): UnpooledSlicedByteBuf(ridx: 0, widx: 0, cap: 0/0, unwrapped: UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf(ridx: 0, widx: 1, cap: 256))
	at io.netty.buffer.AbstractByteBuf.checkReadableBytes0(AbstractByteBuf.java:1396) ~[AbstractByteBuf.class:4.1.9.Final]
	at io.netty.buffer.AbstractByteBuf.readByte(AbstractByteBuf.java:687) ~[AbstractByteBuf.class:4.1.9.Final]
	at net.minecraft.network.PacketBuffer.readByte(PacketBuffer.java:903) ~[PacketBuffer.class:?]
	at net.minecraft.network.PacketBuffer.readCompoundTag(PacketBuffer.java:332) ~[PacketBuffer.class:?]
	at net.minecraftforge.fml.common.network.ByteBufUtils.readTag(ByteBufUtils.java:227) ~[ByteBufUtils.class:?]
	at com.tieso2001.boneappletea.network.PacketFluidTankUpdate.fromBytes(PacketFluidTankUpdate.java:47) ~[PacketFluidTankUpdate.class:?]
	at net.minecraftforge.fml.common.network.simpleimpl.SimpleIndexedCodec.decodeInto(SimpleIndexedCodec.java:36) ~[SimpleIndexedCodec.class:?]
	at net.minecraftforge.fml.common.network.simpleimpl.SimpleIndexedCodec.decodeInto(SimpleIndexedCodec.java:26) ~[SimpleIndexedCodec.class:?]
	at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:111) ~[FMLIndexedMessageToMessageCodec.class:?]
	at net.minecraftforge.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:41) ~[FMLIndexedMessageToMessageCodec.class:?]
	at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:4.1.9.Final]
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:88) ~[MessageToMessageDecoder.class:4.1.9.Final]
	... 33 more
[00:59:09] [Netty Local Client IO #0/ERROR] [FML]: Network Disconnect: A fatal error has occurred, this connection is terminated

 

It says that it caused by the following, but I have no idea how to fix this:

Caused by: java.lang.IndexOutOfBoundsException: readerIndex(0) + length(1) exceeds writerIndex(0): UnpooledSlicedByteBuf(ridx: 0, widx: 0, cap: 0/0, unwrapped: UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf(ridx: 0, widx: 1, cap: 256))

 

This happens in fromBytes():

@Override
    public void toBytes(ByteBuf buf)
    {
        NBTTagCompound compound = new NBTTagCompound();
        fluidStack.writeToNBT(compound);
        ByteBufUtils.writeTag(buf, compound);
    }

@Override
    public void fromBytes(ByteBuf buf)
    {
        NBTTagCompound compound = ByteBufUtils.readTag(buf);
        fluidStack = FluidStack.loadFluidStackFromNBT(compound);
    }

I think the error says that I try to read more bytes than that are written, but this is not the case right?

 

Edited by Tieso2001
Link to comment
Share on other sites

You were right, there was another error with the BlockPos of the tileEntity being null. I didn't realise that because the log was spamming errors so I got that fixed now. Everything seems to work now and the packet works! Thanks a lot, you really helped me.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • This is my code. How can I change it to have "Hello world!" show on the screen? @Mod(Chants2.MODID) public class Chants2 { public static final String MODID = "chants2"; public Chants2(){ final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); final ClientSideOnlyModEventRegistrar clientSideOnlyModEventRegistrar = new ClientSideOnlyModEventRegistrar(modEventBus); registerCommonEvents(modEventBus); DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> clientSideOnlyModEventRegistrar::registerClientOnlyEvents); } public void registerCommonEvents(IEventBus eventBus) { //eventBus.register(GuiHandler.class); } } public class ClientSideOnlyModEventRegistrar { private final IEventBus eventBus; public ClientSideOnlyModEventRegistrar(IEventBus eventBus) { this.eventBus = eventBus; } public void registerClientOnlyEvents() { eventBus.register(GuiHandler.class); } } public class GuiHandler { String text = "Hello world!"; @SubscribeEvent public void onRenderGui(RenderGameOverlayEvent.Post event) { drawString(event.getMatrixStack(), Minecraft.getInstance().font, text, event.getWindow().getWidth() / 2, event.getWindow().getHeight() / 2, Integer.parseInt("33AA66", 16)); } }  
    • why do you need the JDA API in MinecraftForge?
    • you also can look at the StonecutterScreen, but basically you moved the scrolling bar via mouse scroll or mouse drag (you set the y pos where it will render in the screen), after moving you can update the screen on client then send a custom packet to the server and updating the screen there
    • You still capitalizing every word... the name sounds like it will return a ResourceLocation or the mod id, not sure because urbanxx001 didn't say what the method does can you actually explain your exact goal to us, because it can be that there is a easier way to do this
    • I've got capabilities and I was just wondering if there's a way to add a statistic with the value of that capability to the stat menu, so I can make my mod more useable with FTB quests and other similar mods which can take in a statistic to trigger an event
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.