From c9a1cdb14cceef41bd62296e716f80edca044aae Mon Sep 17 00:00:00 2001 From: Lovely_xianxian Date: Mon, 8 Feb 2021 10:21:46 +0800 Subject: [PATCH] Fix Living Armor Desync --- .../bloodmagic/item/armour/ItemLivingArmour.java | 5 ++++- .../java/WayofTime/bloodmagic/proxy/ClientProxy.java | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/WayofTime/bloodmagic/item/armour/ItemLivingArmour.java b/src/main/java/WayofTime/bloodmagic/item/armour/ItemLivingArmour.java index 2d7ab2881a..fced20da0f 100644 --- a/src/main/java/WayofTime/bloodmagic/item/armour/ItemLivingArmour.java +++ b/src/main/java/WayofTime/bloodmagic/item/armour/ItemLivingArmour.java @@ -281,6 +281,8 @@ public void onArmorTick(World world, EntityPlayer player, ItemStack stack) { super.onArmorTick(world, player, stack); if (world.isRemote && this == RegistrarBloodMagicItems.LIVING_ARMOUR_CHEST) { + setLivingArmour(stack, getLivingArmourFromStack(stack)); // updates the living armor + if (player instanceof EntityPlayerSP) //Sanity check { EntityPlayerSP spPlayer = (EntityPlayerSP) player; @@ -328,7 +330,8 @@ public void onArmorTick(World world, EntityPlayer player, ItemStack stack) { armour.onTick(world, player); } - setLivingArmour(stack, armour, false); + if (!world.isRemote) // client shouldn't change the nbt data + setLivingArmour(stack, armour, false); } } diff --git a/src/main/java/WayofTime/bloodmagic/proxy/ClientProxy.java b/src/main/java/WayofTime/bloodmagic/proxy/ClientProxy.java index 204d1db466..5928e55603 100644 --- a/src/main/java/WayofTime/bloodmagic/proxy/ClientProxy.java +++ b/src/main/java/WayofTime/bloodmagic/proxy/ClientProxy.java @@ -13,6 +13,7 @@ import WayofTime.bloodmagic.entity.projectile.EntityMeteor; import WayofTime.bloodmagic.entity.projectile.EntitySentientArrow; import WayofTime.bloodmagic.entity.projectile.EntitySoulSnare; +import WayofTime.bloodmagic.item.armour.ItemLivingArmour; import WayofTime.bloodmagic.item.types.AlchemicVialType; import WayofTime.bloodmagic.soul.DemonWillHolder; import WayofTime.bloodmagic.tile.*; @@ -30,12 +31,15 @@ import net.minecraftforge.client.model.ModelLoaderRegistry; import net.minecraftforge.client.model.animation.AnimationTESR; import net.minecraftforge.client.model.obj.OBJLoader; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.animation.Event; import net.minecraftforge.common.animation.ITimeValue; import net.minecraftforge.common.model.animation.IAnimationStateMachine; import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.client.registry.RenderingRegistry; import net.minecraftforge.fml.common.ObfuscationReflectionHelper; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.network.FMLNetworkEvent; import java.awt.Color; import java.util.Map; @@ -66,6 +70,8 @@ public void handleEvents(TileInversionPillar chest, float time, Iterable // Initialize key-binds during startup so they load correctly for (KeyBindings key : KeyBindings.values()) key.getKey(); + + MinecraftForge.EVENT_BUS.register(this); } @Override @@ -142,4 +148,10 @@ private void addElytraLayer() { public IAnimationStateMachine load(ResourceLocation location, ImmutableMap parameters) { return ModelLoaderRegistry.loadASM(location, parameters); } + + @SubscribeEvent + public void onClientDisconnected(FMLNetworkEvent.ClientDisconnectionFromServerEvent event) { + // clean up the living armour's cache + ItemLivingArmour.armourMap.clear(); + } }