Posted May 27, 201411 yr Hello, I am sending a packet and it is returning with an error. I don't really know what is causing it or were to start because the stack trace is leading to forge code resulting in a NullPointerException. Basically I need to send a boolean value along with three other integers to all the player in the server when an event is triggered. So I had setup a LAN world and when the person hosting the LAN world triggered the event, the packet would send and would the tile entity render, this is what I need to syn with the packet, and it would update and sync fine, but when another player triggers the event the player crashes, and they would not crash before I added the packet sending code. I add a try-catch and had it print the stack trace and the packet gets sent and it sync every player, but the stack trace is returning a NullPointerException. I will post my code and the stack trace bellow, but if anyone needs any more code, just ask. All help is appreciated, Thank You! My Code try{ rc_mod.LogFirePacket.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALL); rc_mod.LogFirePacket.get(Side.SERVER).writeOutbound(new PacketLogFire(true, x, y, z)); } catch(NullPointerException e) { e.printStackTrace(); return false; Stack-Trace java.lang.NullPointerException at cpw.mods.fml.common.network.FMLOutboundHandler$OutboundTarget$5.selectNetworks(FMLOutboundHandler.java:129) at cpw.mods.fml.common.network.FMLOutboundHandler.write(FMLOutboundHandler.java:273) at io.netty.channel.DefaultChannelHandlerContext.invokeWrite(DefaultChannelHandlerContext.java:644) at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:698) at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:637) at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:115) at io.netty.handler.codec.MessageToMessageCodec.write(MessageToMessageCodec.java:116) at io.netty.channel.DefaultChannelHandlerContext.invokeWrite(DefaultChannelHandlerContext.java:644) at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:698) at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:637) at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:626) at io.netty.channel.DefaultChannelPipeline.write(DefaultChannelPipeline.java:878) at io.netty.channel.AbstractChannel.write(AbstractChannel.java:229) at io.netty.channel.embedded.EmbeddedChannel.writeOutbound(EmbeddedChannel.java:195) at mod.xtronius.rc_mod.block.misc.BlockLogFire.onBlockActivated(BlockLogFire.java:133) at net.minecraft.client.multiplayer.PlayerControllerMP.onPlayerRightClick(PlayerControllerMP.java:380) at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1498) at net.minecraft.client.Minecraft.runTick(Minecraft.java:2011) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:996) at net.minecraft.client.Minecraft.run(Minecraft.java:912) at net.minecraft.client.main.Main.main(Main.java:112) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:134) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) Edit: BlockLogFire Class package mod.xtronius.rc_mod.block.misc; import java.util.Random; import cpw.mods.fml.common.network.FMLOutboundHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import mod.xtronius.rc_mod.rc_mod; import mod.xtronius.rc_mod.Misc.IDs.MiscIDs; import mod.xtronius.rc_mod.block.Blocks; import mod.xtronius.rc_mod.creativetab.CreativeTab; import mod.xtronius.rc_mod.packetHandling.main.ChannelHandler; import mod.xtronius.rc_mod.packetHandling.packets.generalPackets.PacketLogFire; import mod.xtronius.rc_mod.tileEntity.TileEntityFurnace1; import mod.xtronius.rc_mod.tileEntity.TileEntityLogFire; import mod.xtronius.rc_mod.util.Vec3; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.IIcon; import net.minecraft.world.World; public class BlockLogFire extends BlockContainer { private boolean hasIntitRender = false; private boolean renderLogFire = false; @SideOnly(Side.CLIENT) private IIcon[] iconArray; public BlockLogFire(int id) { super(Material.wood); this.setLightOpacity(0); } public int getRenderBlockPass() { return 0; } public int getRenderType() { if(!hasIntitRender) { if(rc_mod.playerSettings.settings.getPlayerSettingsValues("RenderRCFire", "b").equals(true)) { this.hasIntitRender = true; this.renderLogFire = true; } else this.hasIntitRender = true; } if(this.renderLogFire == true) { this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.3F, 1.0F); return -1; } else { this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); return 0; } } public boolean renderAsNormalBlock() { return false; } public boolean isOpaqueCube() { return false; } @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister par1IconRegister) { this.iconArray = new IIcon[] {par1IconRegister.registerIcon(this.getTextureName() + "_layer_0"), par1IconRegister.registerIcon(this.getTextureName() + "_layer_1")}; } @SideOnly(Side.CLIENT) public IIcon getFireIcon(int par1) { return this.iconArray[par1]; } @SideOnly(Side.CLIENT) public IIcon getIcon(int par1, int par2) { return this.iconArray[0]; } public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4) { return null; } public TileEntity createNewTileEntity(World world, int var1) { return new TileEntityLogFire(world); } public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4) { return super.canPlaceBlockAt(par1World, par2, par3, par4) && par1World.doesBlockHaveSolidTopSurface(par1World, par2, par3 - 1, par4); } public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) { if (!par1World.doesBlockHaveSolidTopSurface(par1World, par2, par3 - 1, par4)) { this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0); par1World.setBlockToAir(par2, par3, par4); } } public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { if(player.inventory != null && player.inventory.getCurrentItem() != null && player.inventory.getCurrentItem().getItem() != null) { if(player.inventory.getCurrentItem().getItem().equals(Item.getItemById(259))) { if(world.getTileEntity(x, y, z) != null && world.getTileEntity(x, y, z) instanceof TileEntityLogFire) { TileEntityLogFire tileEntity = (TileEntityLogFire) world.getTileEntity(x, y, z); if(tileEntity.isLit() != true) { tileEntity.setLit(true); //ChannelHandler.isLit.put(tileEntity, true); try{ rc_mod.LogFirePacket.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALL); rc_mod.LogFirePacket.get(Side.SERVER).writeOutbound(new PacketLogFire(true, x, y, z)); } catch(NullPointerException e) { return false; } return true; } } } } return false; } public void randomDisplayTick(World world, int x, int y, int z, Random rand) { if(world.isRemote) { if(world.getTileEntity(x, y, z) != null) { TileEntityLogFire entity = (TileEntityLogFire)world.getTileEntity(x, y, z); if(entity.isLit()) { for (int i = 0; i < 20; i++) { float f = 0; float f1 = 0; float f2 = 0; f = (float)x + 0.5F + rand.nextFloat() * 1F / 16.0F; f1 = (float)y + 0.175F; f2 = (float)z + 0.5F + rand.nextFloat() * 1F / 16.0F; world.spawnParticle("smoke", (double)(f), (double)f1, (double)(f2), 0.0D, 0.D, 0.0D); } } } } } } Packet Code package mod.xtronius.rc_mod.packetHandling.packets.generalPackets; import mod.xtronius.rc_mod.rc_mod; import mod.xtronius.rc_mod.handlers.BlockBreakHandler; import mod.xtronius.rc_mod.lib.ExtendedPlayer; import mod.xtronius.rc_mod.packetHandling.main.ChannelHandler; import mod.xtronius.rc_mod.packetHandling.main.IPacket; import net.minecraft.entity.player.EntityPlayer; import io.netty.buffer.ByteBuf; public class PacketLogFire implements IPacket{ boolean isLit; int x; int y; int z; public PacketLogFire(){} public PacketLogFire(boolean isLit, int x, int y, int z) { this.isLit = isLit; this.x = x; this.y = y; this.z = z; } public void readBytes(ByteBuf bytes) { this.isLit = bytes.readBoolean(); this.x = bytes.readInt(); this.y = bytes.readInt(); this.z = bytes.readInt(); } public void writeBytes(ByteBuf bytes){ bytes.writeBoolean(isLit); bytes.writeInt(x); bytes.writeInt(y); bytes.writeInt(z); } @Override public void executeClient(EntityPlayer player) { System.out.println("X: " + x + " Y: " + y + " Z: " + z); rc_mod.isLit.put(player.worldObj.getTileEntity(x, y, z), isLit); } @Override public void executeServer(EntityPlayer player) { } } Don't be afraid to ask question when modding, there are no stupid question! Unless you don't know java then all your questions are stupid!
May 27, 201411 yr What is your code for you LogFirePacket and for your BlockLogFire classes? Check out my tutorials here: http://jabelarminecraft.blogspot.com/
May 27, 201411 yr Author I edited my original post, the code should be there. Don't be afraid to ask question when modding, there are no stupid question! Unless you don't know java then all your questions are stupid!
May 27, 201411 yr Do you really need to use a custom packet if you have a TileEntity associated with the block? I thought TileEntities are automatically synced? So I think you should put your custom block properties into fields in the TileEntity instead, when onBlockActivated() happens update them in the TileEntity, and forget about custom packets. Check out my tutorials here: http://jabelarminecraft.blogspot.com/
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.