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

I am trying to attach a capability to the player that controls a custom health state. When the

AttachCapabilitiesEvent.Entity

or

AttachCapabilitiesEvent<Entity>

is fired I check for an instance of EntityPlayer and call

event.addCapability(new ResourceLocation(Reference.MOD_ID, "dbno"), new DBNOHandlerProvider((EntityPlayer) event.getObject()));

The constructor then sets a player variable in the capability to the value passed to it in the above statement. The setter for this player variable then sends an update packet to the client for good measure. The player is serialized by writing his UUID to NBT. This causes a NullPointerException:

[19:58:33] [Server thread/ERROR]: SimpleChannelHandlerWrapper exception
java.lang.NullPointerException
	at net.minecraftforge.fml.common.network.FMLOutboundHandler$OutboundTarget$4.selectNetworks(FMLOutboundHandler.java:132) ~[FMLOutboundHandler$OutboundTarget$4.class:?]
	at net.minecraftforge.fml.common.network.FMLOutboundHandler.write(FMLOutboundHandler.java:293) ~[FMLOutboundHandler.class:?]
	at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:658) ~[AbstractChannelHandlerContext.class:4.0.23.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:716) ~[AbstractChannelHandlerContext.class:4.0.23.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:651) ~[AbstractChannelHandlerContext.class:4.0.23.Final]
	at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:112) ~[MessageToMessageEncoder.class:4.0.23.Final]
	at io.netty.handler.codec.MessageToMessageCodec.write(MessageToMessageCodec.java:116) ~[MessageToMessageCodec.class:4.0.23.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:658) ~[AbstractChannelHandlerContext.class:4.0.23.Final]
	at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:716) ~[AbstractChannelHandlerContext.class:4.0.23.Final]
	at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:706) ~[AbstractChannelHandlerContext.class:4.0.23.Final]
	at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:741) ~[AbstractChannelHandlerContext.class:4.0.23.Final]
	at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:895) ~[DefaultChannelPipeline.class:4.0.23.Final]
	at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:240) ~[AbstractChannel.class:4.0.23.Final]
	at net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.sendTo(SimpleNetworkWrapper.java:254) [SimpleNetworkWrapper.class:?]
	at XFactHD.rssmc.RainbowSixSiegeMC$NET.sendMessageToClient(RainbowSixSiegeMC.java:320) [RainbowSixSiegeMC$NET.class:?]
	at XFactHD.rssmc.common.capability.dbnoHandler.DBNOHandler.sendUpdatePacket(DBNOHandler.java:196) [DBNOHandler.class:?]
	at XFactHD.rssmc.common.capability.dbnoHandler.DBNOHandler.setPlayer(DBNOHandler.java:36) [DBNOHandler.class:?]
	at XFactHD.rssmc.common.capability.dbnoHandler.DBNOHandlerProvider.<init>(DBNOHandlerProvider.java:18) [DBNOHandlerProvider.class:?]
	at XFactHD.rssmc.common.capability.dbnoHandler.DBNOEventHandler.attachCapability(DBNOEventHandler.java:141) [DBNOEventHandler.class:?]
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_18_DBNOEventHandler_attachCapability_Entity.invoke(.dynamic) [?:?]
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) [ASMEventHandler.class:?]
	at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:185) [EventBus.class:?]
	at net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(ForgeEventFactory.java:565) [ForgeEventFactory.class:?]
	at net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(ForgeEventFactory.java:550) [ForgeEventFactory.class:?]
	at net.minecraft.entity.Entity.<init>(Entity.java:253) [Entity.class:?]
	at net.minecraft.entity.EntityLivingBase.<init>(EntityLivingBase.java:192) [EntityLivingBase.class:?]
	at net.minecraft.entity.player.EntityPlayer.<init>(EntityPlayer.java:182) [EntityPlayer.class:?]
	at net.minecraft.entity.player.EntityPlayerMP.<init>(EntityPlayerMP.java:166) [EntityPlayerMP.class:?]
	at net.minecraft.server.management.PlayerList.createPlayerForUser(PlayerList.java:527) [PlayerList.class:?]
	at net.minecraft.server.network.NetHandlerLoginServer.tryAcceptPlayer(NetHandlerLoginServer.java:137) [NetHandlerLoginServer.class:?]
	at net.minecraft.server.network.NetHandlerLoginServer.update(NetHandlerLoginServer.java:64) [NetHandlerLoginServer.class:?]
	at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:309) [NetworkManager.class:?]
	at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:197) [NetworkSystem.class:?]
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:807) [MinecraftServer.class:?]
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:688) [MinecraftServer.class:?]
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) [IntegratedServer.class:?]
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:537) [MinecraftServer.class:?]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_131]

This stacktrace is logged and seems to be ignored. I don't know if this causes the capability to be attached. When I then left click one of my items that is completely unrelated to the capability, it causes a crash with the exact same stacktrace. This crash happens even though I am checking on the client if the client player entity already got the capability attached and if not, I queue the NBT data for deserialization until the capability has been attached on the client.

If the item class, the capability class or the event handler class for attaching the capability is needed, I will happily provide them.

Edited by XFactHD

You can't send a packet to the player as that player is being constructed(this is the stage the capabilities are attached at) as at that stage the player's connection field is null and that is used by fml to send the packet. And even if it wouldn't the player's uuid is not properly set from their GameProfileย at that stage either.ย You need to send the packet later.

Yeah, that makes sense, I should have thought a bit more about the fact that the event is fired in the entity's constructor :$. Thanks for your help.

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.