I'm trying to check a player's armor inventory to see if my custom Armor currently has a capability attached to it. If it does in another event I give the player an effect. This works fine in SInglePlayer. However, when I run it in a Dedicated Server, the events are out of sync so the Client Player can see the armor and get the capabilities but the Server Player just returns 0. Is there a better way to get the Player's Armor as an ItemStack? I've tried packets but there's no simple way to return them and putting the information in the Player's Persistent Data causes worse desync problems. I know that player.inventory.armorItemInSlot() can only be run on Client but when I use player.inventory.armorInventory.get() or player.inventory.getStackInSlot() instead it doesn't work on Server.
public double getPlayerGemStrength(PlayerEntity player, String attribute) {
double fullStrength = 0;
for (int i = 0; i < 4; i++) {
ItemStack armor;
armor = player.inventory.armorItemInSlot(3 - i);
LazyOptional<ISlottedArmor> armorCapability = armor.getCapability(SlottedArmorProvider.ARMOR_CAPABILITY);
ISlottedArmor armorInstance = armorCapability.orElse(new SlottedArmorInstance());
ItemStack gem = armorInstance.getGem();
if (gem != null) {
LazyOptional<IGem> gemCapability = gem.getCapability(GemProvider.GEM_CAPABILITY);
IGem gemInstance = gemCapability.orElse(new GemInstance());
String gemAttribute = gemInstance.getAttribute();
double strength = gemInstance.getStrength();
if (gemAttribute != null && !gemAttribute.equals("")) {
if (gemAttribute.equals(attribute)) {
fullStrength += strength;
}
}
}
}
return fullStrength;
}
Here is an example effect:
@SubscribeEvent
public void giveEffects(PlayerEvent event) {
if (event.getPlayer() != null) {
PlayerEntity player = event.getPlayer();
double fullStrength = getPlayerGemStrength(player, "HP Up");
if (fullStrength > 0) {
MaxHealthHandler.updateHealthModifier(player, fullStrength);
} else {
MaxHealthHandler.updateHealthModifier(player, 0);
}
}
}