Jump to content

Recommended Posts

Posted

In my mod, I setup a packet to handle fluids before and it worked just fine.  However, now that I added energy along with BuildCraft support, the world crashes when it loads if pipes from BuildCraft are next to the block.  Here is my crash log.

 

[18:40:16] [Client thread/ERROR] [FML]: SimpleChannelHandlerWrapper exception

java.lang.NullPointerException

at com.kenoba10.electricfactory.network.packet.PowerFactoryPacket.onMessage(PowerFactoryPacket.java:69) ~[PowerFactoryPacket.class:?]

at com.kenoba10.electricfactory.network.packet.PowerFactoryPacket.onMessage(PowerFactoryPacket.java:11) ~[PowerFactoryPacket.class:?]

at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:34) ~[simpleChannelHandlerWrapper.class:?]

at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:14) ~[simpleChannelHandlerWrapper.class:?]

at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[simpleChannelInboundHandler.class:?]

at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?]

at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?]

at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) [MessageToMessageDecoder.class:?]

at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) [MessageToMessageCodec.class:?]

at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?]

at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?]

at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:?]

at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:?]

at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?]

at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:247) [NetworkManager.class:?]

at net.minecraft.client.multiplayer.PlayerControllerMP.updateController(PlayerControllerMP.java:321) [PlayerControllerMP.class:?]

at net.minecraft.client.Minecraft.runTick(Minecraft.java:1693) [Minecraft.class:?]

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039) [Minecraft.class:?]

at net.minecraft.client.Minecraft.run(Minecraft.java:961) [Minecraft.class:?]

at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_60]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_60]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_60]

at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_60]

at net.minecraft.launchwrapper.Launch.launch(Launch.java:134) [launchwrapper-1.9.jar:?]

at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.9.jar:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_60]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_60]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_60]

at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_60]

at GradleStart.bounce(GradleStart.java:108) [start/:?]

at GradleStart.startClient(GradleStart.java:101) [start/:?]

at GradleStart.main(GradleStart.java:66) [start/:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_60]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_60]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_60]

at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_60]

at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) [idea_rt.jar:?]

 

My packet code is:

 

public class PowerFactoryPacket implements IMessage, IMessageHandler<PowerFactoryPacket, IMessage> {

    public int x;
    public int y;
    public int z;

    public int amountWater;
    public int amountLava;

    public int energy;

    public PowerFactoryPacket() {

    }

    public PowerFactoryPacket(PowerFactoryTileEntity tileentity) {

        x = tileentity.xCoord;
        y = tileentity.yCoord;
        z = tileentity.zCoord;

        amountWater = tileentity.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid.amount;
        amountLava = tileentity.getTankInfo(ForgeDirection.UNKNOWN)[1].fluid.amount;

        energy = tileentity.getEnergy();

    }

    public void fromBytes(ByteBuf buf) {

        x = buf.readInt();
        y = buf.readInt();
        z = buf.readInt();

        amountWater = buf.readInt();
        amountLava = buf.readInt();

        energy = buf.readInt();

    }

    public void toBytes(ByteBuf buf) {

        buf.writeInt(x);
        buf.writeInt(y);
        buf.writeInt(z);

        buf.writeInt(amountWater);
        buf.writeInt(amountLava);

        buf.writeInt(energy);

    }

    public IMessage onMessage(PowerFactoryPacket message, MessageContext context) {

        PowerFactoryTileEntity tileentity = (PowerFactoryTileEntity)FMLClientHandler.instance().getClient().theWorld.getTileEntity(message.x, message.y, message.z);

        tileentity.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid.amount = message.amountWater;
        tileentity.getTankInfo(ForgeDirection.UNKNOWN)[1].fluid.amount = message.amountLava;

        tileentity.setEnergy(message.energy);

        return null;

    }

}

Posted

Hi

 

My guess is the error is here

tileentity.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid.

 

-> probably your tileentity hasn't initialised itself correctly, so that getTankInfo returns a null or the array it returns has null fluid entries

 

Show your TileEntity class?

 

-TGG

Posted

That is most likely not the issue because it only happens when buildcraft energy pipes are connected to it.  Here is my tile entity code though:

 

public class PowerFactoryTileEntity extends TileEntity implements IInventory, IFluidHandler {

    private ItemStack[] itemInventory;

    private FluidTank tankWater;
    private FluidTank tankLava;

    private int energy = 0;

    public PowerFactoryTileEntity() {

        itemInventory = new ItemStack[8];

        tankWater = new FluidTank(FluidRegistry.WATER, 0, FluidContainerRegistry.BUCKET_VOLUME * 4);
        tankLava = new FluidTank(FluidRegistry.LAVA, 0, FluidContainerRegistry.BUCKET_VOLUME * 4);

    }

    public String getInventoryName() {

        return "container.electricfactory:factoryPower";

    }

    public boolean hasCustomInventoryName() {

        return false;

    }

    public int getSizeInventory() {

        return itemInventory.length;

    }

    public int getInventoryStackLimit() {

        return 64;

    }

    public boolean isUseableByPlayer(EntityPlayer player) {

        return true;

    }

    public void openInventory() {

    }

    public void closeInventory() {

    }

    public boolean isItemValidForSlot(int index, ItemStack stack) {

        return true;

    }

    public ItemStack getStackInSlot(int index) {

        return itemInventory[index];

    }

    public ItemStack getStackInSlotOnClosing(int index) {

        if(itemInventory[index] != null) {

            itemInventory[index] = null;

            return itemInventory[index];

        }

        return null;

    }

    public ItemStack decrStackSize(int index, int amount) {

        ItemStack stack = getStackInSlot(index);

        if(stack != null) {

            if(stack.stackSize <= amount) {

                setInventorySlotContents(index, null);

            }
            else {

                stack = stack.splitStack(amount);

                if(stack.stackSize == 0)
                    setInventorySlotContents(index, null);

            }

        }

        return stack;

    }

    public void setInventorySlotContents(int index, ItemStack stack) {

        itemInventory[index] = stack;

        if(stack != null && stack.stackSize > getInventoryStackLimit())
            stack.stackSize = getInventoryStackLimit();

        markDirty();

    }

    public int fill(ForgeDirection side, FluidStack stack, boolean fill) {

        int filled;

        if(stack.getFluid() == FluidRegistry.WATER)
            filled = tankWater.fill(stack, fill);
        else if(stack.getFluid() == FluidRegistry.LAVA)
            filled = tankLava.fill(stack, fill);
        else
            filled = 0;

        if(!worldObj.isRemote)
            Packets.INSTANCE.sendToAll(new PowerFactoryPacket(this));

        return filled;

    }

    public FluidStack drain(ForgeDirection side, FluidStack stack, boolean drain) {

        return null;

    }

    public FluidStack drain(ForgeDirection side, int max, boolean drain) {

        return null;

    }

    public boolean canFill(ForgeDirection side, Fluid fluid) {

        return fluid == FluidRegistry.WATER || fluid == FluidRegistry.LAVA;

    }

    public boolean canDrain(ForgeDirection side, Fluid fluid) {

        return false;

    }

    public FluidTankInfo[] getTankInfo(ForgeDirection side) {

        return new FluidTankInfo[] {tankWater.getInfo(), tankLava.getInfo()};

    }

    public Packet getDescriptionPacket() {

        return Packets.INSTANCE.getPacketFrom(new PowerFactoryPacket(this));

    }

    public void updateEntity() {

        super.updateEntity();

    }

    public void readFromNBT(NBTTagCompound tagCompound) {

        super.readFromNBT(tagCompound);

        NBTTagList tags = tagCompound.getTagList("items", 10);

        for(int i = 0; i < tags.tagCount(); i++) {

            NBTTagCompound tag = tags.getCompoundTagAt(i);

            byte index = tag.getByte("slot");

            if(index >= 0 && index < itemInventory.length)
                itemInventory[index] = ItemStack.loadItemStackFromNBT(tag);

        }

        NBTTagCompound tagWater = tagCompound.getCompoundTag("water");
        NBTTagCompound tagLava = tagCompound.getCompoundTag("lava");

        tankWater.readFromNBT(tagWater);
        tankLava.readFromNBT(tagLava);

        energy = tagCompound.getInteger("energy");

    }

    public void writeToNBT(NBTTagCompound tagCompound) {

        super.writeToNBT(tagCompound);

        NBTTagList tags = new NBTTagList();

        for(int i = 0; i < itemInventory.length; i++) {

            if(itemInventory[i] != null) {

                NBTTagCompound tag = new NBTTagCompound();

                tag.setByte("slot", (byte)i);

                itemInventory[i].writeToNBT(tag);

                tags.appendTag(tag);

            }

        }

        tagCompound.setTag("items", tags);

        NBTTagCompound tagWater = new NBTTagCompound();
        NBTTagCompound tagLava = new NBTTagCompound();

        tankWater.writeToNBT(tagWater);
        tankLava.writeToNBT(tagLava);

        tagCompound.setTag("water", tagWater);
        tagCompound.setTag("lava", tagLava);

        tagCompound.setInteger("energy", energy);

    }

    public int getEnergy() {

        return energy;

    }

    public void setEnergy(int energy) {

        if(energy > PowerFactoryMultiBlock.getPowerCells(worldObj, xCoord, yCoord, zCoord) * 200000)
            return;

        this.energy = energy;

        if(!worldObj.isRemote)
            Packets.INSTANCE.sendToAll(new PowerFactoryPacket(this));

    }

    public void addEnergy(int energy) {

        if(this.energy + energy > PowerFactoryMultiBlock.getPowerCells(worldObj, xCoord, yCoord, zCoord) * 200000)
            return;

        this.energy += energy;

        if(!worldObj.isRemote)
            Packets.INSTANCE.sendToAll(new PowerFactoryPacket(this));

    }

    public void removeEnergy(int energy) {

        if(this.energy - energy > PowerFactoryMultiBlock.getPowerCells(worldObj, xCoord, yCoord, zCoord) * 200000)
            return;

        this.energy -= energy;

        if(!worldObj.isRemote)
            Packets.INSTANCE.sendToAll(new PowerFactoryPacket(this));

    }

}

Posted

Hmmm

 

In that case, perhaps there is something wrong in FluidTank.getInfo(), or perhaps there is no tileEntity at the location in the message, so that tileentity is null.

 

I'd suggest adding a System.out.println("TileEntity at [" + x + ", " + y + ", " + z + "]:" + tileentity); just before the line which crashes.  Or alternatively, set a breakpoint on NPE in  your debugger and have a look directly.

 

Not sure why the tileEntity might be missing - or rather, why you might be getting a message for that location before the tileEntity has been created on the client.

 

-TGG

Posted

This is strange.  I tried what you said and it actually loaded up correctly.  Then I loaded up the world again and it crashed saying that the tile entity was null.  Also, I have done this on separate worlds and they all do this.

Posted

I may have figured it out but the fix is a bit weird.  I have another block that on every update edits the internal power and if I wait to manipulate the variables until the end of the method, it works more often.  I think I should be able to get it working now though.

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...

×   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.

Announcements



×
×
  • Create New...

Important Information

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