Posted October 1, 20214 yr I have a capability which gets attached to the player, and yea it stays the same even when you go to another world Here are all the events todo with refreshing the capability Spoiler @SubscribeEvent public static void playerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) { ServerPlayerEntity player = (ServerPlayerEntity) event.getPlayer(); PacketHandler.INSTANCE.send(PacketDistributor.PLAYER.with(() -> player), new MessageStatus( player.getCapability(StatusProvider.STATUS_CAP, Status.capSide).orElseThrow(ArithmeticException::new))); } @SubscribeEvent public static void playerDeath(LivingDeathEvent event) { if(!event.getEntity().getCommandSenderWorld().isClientSide) { if (event.getEntity() instanceof PlayerEntity) { ServerPlayerEntity player = (ServerPlayerEntity) event.getEntity(); PacketHandler.INSTANCE.send(PacketDistributor.PLAYER.with(() -> player), new MessageStatus( player.getCapability(StatusProvider.STATUS_CAP, Status.capSide).orElseThrow(ArithmeticException::new))); } } } Here are the packets Spoiler public class MessageStatus { public IStatus status; public static void handle(MessageStatus msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> ClientPacketHandler.handleStatus(msg, ctx))); ctx.get().setPacketHandled(true); } public static MessageStatus decode(PacketBuffer buf) { IStatus status = new Status(); status.setFamilia(buf.readUtf()); status.setArray(buf.readVarIntArray()); return new MessageStatus(status); } public static void encode(MessageStatus message, PacketBuffer buf) { buf.writeUtf(message.status.getFamilia()); buf.writeVarIntArray(message.status.getArray()); } public MessageStatus(IStatus status) { this.status = status; } public MessageStatus() { status = new Status(); } } Spoiler public class MessageClientStatus { public IStatus status; public static void handle(MessageClientStatus msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { ServerPlayerEntity sender = ctx.get().getSender(); if(sender == null) return; IStatus status = sender.getCapability(StatusProvider.STATUS_CAP, Status.capSide) .orElseThrow(ArithmeticException::new); if(status.getLevel() != msg.status.getLevel()) sender.awardStat(Stats.LEVEL); status.setArray(msg.status.getArray()); }); ctx.get().setPacketHandled(true); } public static MessageClientStatus decode(PacketBuffer buf) { IStatus status = new Status(); status.setFamilia(buf.readUtf()); status.setArray(buf.readVarIntArray()); return new MessageClientStatus(status); } public static void encode(MessageClientStatus message, PacketBuffer buf) { buf.writeUtf(message.status.getFamilia()); buf.writeVarIntArray(message.status.getArray()); } public MessageClientStatus(IStatus status) { this.status = status; } public MessageClientStatus() { status = new Status(); } } And here's the rest of the source code https://github.com/ImNotJahan/danmachi-mod/tree/master/v1.16.5/src/main/java/imnotjahan/mod/danmachi Edited October 1, 20214 yr by ImNotJahan Removed code that was placed twice
October 2, 20214 yr You need to listen for the PlayerEvent.Clone event, which is fired upon changing dimensions, because entities don't actually move between dimensions. They're destroyed and recreated on the other side. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
October 2, 20214 yr Author 2 hours ago, diesieben07 said: What a strange choice of exception to throw here. Some of the code was made at a time I didn't know how to make exceptions so back then I just used ArithmeticExceptions for capabilities. I do got an exception for that now tho so I should probably change it so thanks for pointing that out. I did fix it and the solution was a large mix of things so I'm not exactly sure what fixed it, but I know a few of the things I needed to do were this: private static final LazyOptional<IStatus> lazyStatus = LazyOptional.of(Status::new); This line in my capability provider was static which was what was causing it to transfer over worlds, making it not static however made it stop saving. To fix that I had to change the parameters in both my readNBT and writeNBT calls from STATUS_CAP, this.instance, Status.capSide, nbt to STATUS_CAP, this.lazyStatus.orElseThrow(MissingStatus::new), Status.capSide, nbt because instance was a variable I for some reason created, which was never used other than in these functions, that was the default value of the capability After that I just had to fix up networking a bunch to get everything completely working, and the only problem there is I had no way to discern the packets being sent at the time, but yea fixing that got them all working correctly
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.