- 47
- 1
Приветствую, ищу способ как перенести nbt умершего player на нового(для того, что бы при смерти nbt переносилось). Я думаю, что
P.S:не ругайтесь на instanceof, я знаю что надо было бы изначально 2 переменные сделать, а потом вызывать их. Это просто прототип
Хотелось бы узнать, есть ли способ покрасивее, и если нет, то помочь с этим кодом либо предложить свой.
ServerPlayerEvents.AfterRespawn
поможет мне с этим, прописал эвент, который не работает:
PlayerSpawnHandler:
public class PlayerSpawnHandler implements ServerPlayerEvents.AfterRespawn {
@Override
public void afterRespawn(ServerPlayerEntity oldPlayer, ServerPlayerEntity newPlayer, boolean alive) {
PacketByteBuf buffer = PacketByteBufs.create();
if (oldPlayer instanceof IEntityDataSaver DatSaverPlayer){
buffer.writeInt(DatSaverPlayer.getPersistentData().getInt("maxmana"));
}
if (newPlayer instanceof IEntityDataSaver DatSaverPlayer){
MAXMANAData.addMaxMana(DatSaverPlayer, buffer.readInt());}
ServerPlayNetworking.send(newPlayer, ModMessages.MAXMANA_SYNC_ID, buffer);
newPlayer.sendMessage(Text.literal("Maxmana sync succ"));
buffer = PacketByteBufs.create();
if (oldPlayer instanceof IEntityDataSaver DatSaverPlayer){
buffer.writeInt(DatSaverPlayer.getPersistentData().getInt("mana"));
}
if (newPlayer instanceof IEntityDataSaver DatSaverPlayer){
ManaData.addMana(DatSaverPlayer, buffer.readInt());
}
ServerPlayNetworking.send(newPlayer, ModMessages.MANA_SYNC_ID, buffer);
newPlayer.sendMessage(Text.literal("Mana sync Succ"));
}
}
MaxmanaSyncS2CPacket:
public class MaxmanaSyncS2CPacket {
public static void receive(MinecraftClient client, ClientPlayNetworkHandler handler,
PacketByteBuf buf, PacketSender responseSender) {
if (client.player instanceof IEntityDataSaver playerDataSaver) {
playerDataSaver.getPersistentData().putInt("maxmana", buf.readInt());
}
}
}
- Краш-лог
-
[13:07:23] [Netty Local Client IO #2/ERROR] (ClientPlayNetworkAddon for Player946) Encountered exception while handling in channel with name "rpserver-fighting:maxmana_sync"
java.lang.IndexOutOfBoundsException: readerIndex(0) + length(4) exceeds writerIndex(0): UnpooledSlicedByteBuf(ridx: 0, widx: 0, cap: 0/0, unwrapped: UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf(ridx: 0, widx: 0, cap: 0))
at io.netty.buffer.AbstractByteBuf.checkReadableBytes0(AbstractByteBuf.java:1442) ~[netty-buffer-4.1.82.Final.jar:?]
at io.netty.buffer.AbstractByteBuf.readInt(AbstractByteBuf.java:809) ~[netty-buffer-4.1.82.Final.jar:?]
at net.minecraft.network.PacketByteBuf.readInt(PacketByteBuf.java:2286) ~[minecraft-merged-a4b002cb63-1.20.1-net.fabricmc.yarn.1_20_1.1.20.1+build.10-v2.jar:?]
at net.lil_requiem.networking.packet.MaxmanaSyncS2CPacket.receive(MaxmanaSyncS2CPacket.java:13) ~[main/:?]
at net.fabricmc.fabric.impl.networking.client.ClientPlayNetworkAddon.receive(ClientPlayNetworkAddon.java:98) ~[fabric-networking-api-v1-1.3.11+1802ada577.jar:?]
at net.fabricmc.fabric.impl.networking.client.ClientPlayNetworkAddon.receive(ClientPlayNetworkAddon.java:40) ~[fabric-networking-api-v1-1.3.11+1802ada577.jar:?]
at net.fabricmc.fabric.impl.networking.AbstractChanneledNetworkAddon.handle(AbstractChanneledNetworkAddon.java:101) ~[fabric-networking-api-v1-1.3.11+1802ada577.jar:?]
at net.fabricmc.fabric.impl.networking.client.ClientPlayNetworkAddon.handle(ClientPlayNetworkAddon.java:90) ~[fabric-networking-api-v1-1.3.11+1802ada577.jar:?]
at net.minecraft.client.network.ClientPlayNetworkHandler.handler$zma000$fabric-networking-api-v1$handleCustomPayload(ClientPlayNetworkHandler.java:3065) ~[minecraft-merged-a4b002cb63-1.20.1-net.fabricmc.yarn.1_20_1.1.20.1+build.10-v2.jar:?]
at net.minecraft.client.network.ClientPlayNetworkHandler.onCustomPayload(ClientPlayNetworkHandler.java) ~[minecraft-merged-a4b002cb63-1.20.1-net.fabricmc.yarn.1_20_1.1.20.1+build.10-v2.jar:?]
at net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket.apply(CustomPayloadS2CPacket.java:60) ~[minecraft-merged-a4b002cb63-1.20.1-net.fabricmc.yarn.1_20_1.1.20.1+build.10-v2.jar:?]
at net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket.apply(CustomPayloadS2CPacket.java:36) ~[minecraft-merged-a4b002cb63-1.20.1-net.fabricmc.yarn.1_20_1.1.20.1+build.10-v2.jar:?]
at net.minecraft.network.ClientConnection.handlePacket(ClientConnection.java:197) ~[minecraft-merged-a4b002cb63-1.20.1-net.fabricmc.yarn.1_20_1.1.20.1+build.10-v2.jar:?]
at net.minecraft.network.ClientConnection.channelRead0(ClientConnection.java:184) ~[minecraft-merged-a4b002cb63-1.20.1-net.fabricmc.yarn.1_20_1.1.20.1+build.10-v2.jar:?]
at net.minecraft.network.ClientConnection.channelRead0(ClientConnection.java:491) ~[minecraft-merged-a4b002cb63-1.20.1-net.fabricmc.yarn.1_20_1.1.20.1+build.10-v2.jar:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.local.LocalChannel.readInbound(LocalChannel.java:299) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.local.LocalChannel.doBeginRead(LocalChannel.java:322) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.AbstractChannel$AbstractUnsafe.beginRead(AbstractChannel.java:834) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.DefaultChannelPipeline$HeadContext.read(DefaultChannelPipeline.java:1362) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeRead(AbstractChannelHandlerContext.java:686) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.AbstractChannelHandlerContext.read(AbstractChannelHandlerContext.java:671) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.DefaultChannelPipeline.read(DefaultChannelPipeline.java:1004) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.AbstractChannel.read(AbstractChannel.java:290) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.DefaultChannelPipeline$HeadContext.readIfIsAutoRead(DefaultChannelPipeline.java:1422) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelReadComplete(DefaultChannelPipeline.java:1417) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(AbstractChannelHandlerContext.java:410) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(AbstractChannelHandlerContext.java:397) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.DefaultChannelPipeline.fireChannelReadComplete(DefaultChannelPipeline.java:925) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.local.LocalChannel.readInbound(LocalChannel.java:302) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.local.LocalChannel.finishPeerRead0(LocalChannel.java:445) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.local.LocalChannel.access$400(LocalChannel.java:50) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.local.LocalChannel$5.run(LocalChannel.java:403) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174) ~[netty-common-4.1.82.Final.jar:?]
at io.netty.channel.DefaultEventLoop.run(DefaultEventLoop.java:54) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.82.Final.jar:?]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.82.Final.jar:?]
at java.lang.Thread.run(Thread.java:1583) ~[?:?]
Краш-лог:
[13:07:23] [Netty Local Client IO #2/ERROR] (ClientPlayNetworkAddon for Player946) Encountered exception while handling in channel with name "rpserver-fighting:maxmana_sync"
java.lang.IndexOutOfBoundsException: readerIndex(0) + length(4) exceeds writerIndex(0): UnpooledSlicedByteBuf(ridx: 0, widx: 0, cap: 0/0, unwrapped: UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf(ridx: 0, widx: 0, cap: 0))
at io.netty.buffer.AbstractByteBuf.checkReadableBytes0(AbstractByteBuf.java:1442) ~[netty-buffer-4.1.82.Final.jar:?]
at io.netty.buffer.AbstractByteBuf.readInt(AbstractByteBuf.java:809) ~[netty-buffer-4.1.82.Final.jar:?]
at net.minecraft.network.PacketByteBuf.readInt(PacketByteBuf.java:2286) ~[minecraft-merged-a4b002cb63-1.20.1-net.fabricmc.yarn.1_20_1.1.20.1+build.10-v2.jar:?]
at net.lil_requiem.networking.packet.MaxmanaSyncS2CPacket.receive(MaxmanaSyncS2CPacket.java:13) ~[main/:?]
at net.fabricmc.fabric.impl.networking.client.ClientPlayNetworkAddon.receive(ClientPlayNetworkAddon.java:98) ~[fabric-networking-api-v1-1.3.11+1802ada577.jar:?]
at net.fabricmc.fabric.impl.networking.client.ClientPlayNetworkAddon.receive(ClientPlayNetworkAddon.java:40) ~[fabric-networking-api-v1-1.3.11+1802ada577.jar:?]
at net.fabricmc.fabric.impl.networking.AbstractChanneledNetworkAddon.handle(AbstractChanneledNetworkAddon.java:101) ~[fabric-networking-api-v1-1.3.11+1802ada577.jar:?]
at net.fabricmc.fabric.impl.networking.client.ClientPlayNetworkAddon.handle(ClientPlayNetworkAddon.java:90) ~[fabric-networking-api-v1-1.3.11+1802ada577.jar:?]
at net.minecraft.client.network.ClientPlayNetworkHandler.handler$zma000$fabric-networking-api-v1$handleCustomPayload(ClientPlayNetworkHandler.java:3065) ~[minecraft-merged-a4b002cb63-1.20.1-net.fabricmc.yarn.1_20_1.1.20.1+build.10-v2.jar:?]
at net.minecraft.client.network.ClientPlayNetworkHandler.onCustomPayload(ClientPlayNetworkHandler.java) ~[minecraft-merged-a4b002cb63-1.20.1-net.fabricmc.yarn.1_20_1.1.20.1+build.10-v2.jar:?]
at net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket.apply(CustomPayloadS2CPacket.java:60) ~[minecraft-merged-a4b002cb63-1.20.1-net.fabricmc.yarn.1_20_1.1.20.1+build.10-v2.jar:?]
at net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket.apply(CustomPayloadS2CPacket.java:36) ~[minecraft-merged-a4b002cb63-1.20.1-net.fabricmc.yarn.1_20_1.1.20.1+build.10-v2.jar:?]
at net.minecraft.network.ClientConnection.handlePacket(ClientConnection.java:197) ~[minecraft-merged-a4b002cb63-1.20.1-net.fabricmc.yarn.1_20_1.1.20.1+build.10-v2.jar:?]
at net.minecraft.network.ClientConnection.channelRead0(ClientConnection.java:184) ~[minecraft-merged-a4b002cb63-1.20.1-net.fabricmc.yarn.1_20_1.1.20.1+build.10-v2.jar:?]
at net.minecraft.network.ClientConnection.channelRead0(ClientConnection.java:491) ~[minecraft-merged-a4b002cb63-1.20.1-net.fabricmc.yarn.1_20_1.1.20.1+build.10-v2.jar:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.local.LocalChannel.readInbound(LocalChannel.java:299) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.local.LocalChannel.doBeginRead(LocalChannel.java:322) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.AbstractChannel$AbstractUnsafe.beginRead(AbstractChannel.java:834) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.DefaultChannelPipeline$HeadContext.read(DefaultChannelPipeline.java:1362) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeRead(AbstractChannelHandlerContext.java:686) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.AbstractChannelHandlerContext.read(AbstractChannelHandlerContext.java:671) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.DefaultChannelPipeline.read(DefaultChannelPipeline.java:1004) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.AbstractChannel.read(AbstractChannel.java:290) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.DefaultChannelPipeline$HeadContext.readIfIsAutoRead(DefaultChannelPipeline.java:1422) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelReadComplete(DefaultChannelPipeline.java:1417) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(AbstractChannelHandlerContext.java:410) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelReadComplete(AbstractChannelHandlerContext.java:397) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.DefaultChannelPipeline.fireChannelReadComplete(DefaultChannelPipeline.java:925) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.local.LocalChannel.readInbound(LocalChannel.java:302) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.local.LocalChannel.finishPeerRead0(LocalChannel.java:445) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.local.LocalChannel.access$400(LocalChannel.java:50) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.channel.local.LocalChannel$5.run(LocalChannel.java:403) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174) ~[netty-common-4.1.82.Final.jar:?]
at io.netty.channel.DefaultEventLoop.run(DefaultEventLoop.java:54) ~[netty-transport-4.1.82.Final.jar:?]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.82.Final.jar:?]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.82.Final.jar:?]
at java.lang.Thread.run(Thread.java:1583) ~[?:?]