Jump to content

Recommended Posts

Posted

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!

Posted

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!

Posted

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.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Im trying to build my mod using shade since i use the luaj library however i keep getting this error Reason: Task ':reobfJar' uses this output of task ':shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. So i try adding reobfJar.dependsOn shadowJar  Could not get unknown property 'reobfJar' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. my gradle file plugins { id 'eclipse' id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'org.spongepowered.mixin' version '0.7.+' } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' apply plugin: 'com.github.johnrengelman.shadow' version = mod_version group = mod_group_id base { archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) //jarJar.enable() println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' arg "-mixin.config=derp.mixin.json" mods { "${mod_id}" { source sourceSets.main } } } client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id } server { property 'forge.enabledGameTestNamespaces', mod_id args '--nogui' } gameTestServer { property 'forge.enabledGameTestNamespaces', mod_id } data { workingDirectory project.file('run-data') args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { flatDir { dirs './libs' } maven { url = "https://jitpack.io" } } configurations { shade implementation.extendsFrom shade } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'org.luaj:luaj-jse-3.0.2' implementation fg.deobf("com.github.Virtuoel:Pehkui:${pehkui_version}") annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' minecraftLibrary 'luaj:luaj-jse:3.0.2' shade 'luaj:luaj-jse:3.0.2' } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, 'Specification-Version' : '1', // We are version 1 of ourselves 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", "TweakOrder" : 0, "MixinConfigs" : "derp.mixin.json" ]) } rename 'mixin.refmap.json', 'derp.mixin-refmap.json' } shadowJar { archiveClassifier = '' configurations = [project.configurations.shade] finalizedBy 'reobfShadowJar' } assemble.dependsOn shadowJar reobf { re shadowJar {} } publishing { publications { mavenJava(MavenPublication) { artifact jar } } repositories { maven { url "file://${project.projectDir}/mcmodsrepo" } } }  
    • All versions of Minecraft Forge suddenly black screen even without mods (tried reinstalling original Minecraft, Java, updating drivers doesn't work)
    • When i join minecraft all ok, when i join world all working fine, but when i open indentity menu, i get this The game crashed whilst unexpected error Error: java.lang.NullPointerException: Cannot invoke "top.ribs.scguns.common.Gun$Projectile.getDamage()" because "this.projectile" is null crash report here https://paste.ee/p/0vKaf
  • Topics

×
×
  • Create New...

Important Information

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