diff --git a/src/main/java/tconstruct/library/weaponry/AmmoItem.java b/src/main/java/tconstruct/library/weaponry/AmmoItem.java index 56857182..e53b7452 100644 --- a/src/main/java/tconstruct/library/weaponry/AmmoItem.java +++ b/src/main/java/tconstruct/library/weaponry/AmmoItem.java @@ -8,6 +8,7 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.server.MinecraftServer; import net.minecraft.util.StatCollector; import net.minecraftforge.event.entity.player.PlayerInteractEvent; @@ -16,6 +17,7 @@ import baubles.api.IBauble; import baubles.api.expanded.BaubleExpandedSlots; import baubles.api.expanded.IBaubleExpanded; import baubles.common.lib.PlayerHandler; +import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Optional; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -63,7 +65,7 @@ public abstract class AmmoItem extends ToolCore implements IBattlegearWeapon, IA NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool"); int oldCount = tags.getInteger("Ammo"); int newCount = Math.min(oldCount + toAdd, getMaxAmmo(stack)); - tags.setInteger("Ammo", newCount); + setAmmo(newCount, stack); return toAdd - (newCount - oldCount); } @@ -73,16 +75,33 @@ public abstract class AmmoItem extends ToolCore implements IBattlegearWeapon, IA NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool"); int oldCount = tags.getInteger("Ammo"); int newCount = Math.max(oldCount - toUse, 0); - tags.setInteger("Ammo", newCount); + setAmmo(newCount, stack); return toUse - (oldCount - newCount); } + private void syncBaubles(ItemStack stack) { + if (LoadedMods.baubles && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) { + var players = MinecraftServer.getServer().getConfigurationManager().playerEntityList; + for (var player : players) { + var baubles = PlayerHandler.getPlayerBaubles(player); + for (int i = 0; i < baubles.stackList.length; i++) { + if (baubles.stackList[i] == stack) { + baubles.syncSlotToClients(i); + return; + } + } + } + } + } + @Override public void setAmmo(int count, ItemStack stack) { if (!stack.hasTagCompound()) return; NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool"); tags.setInteger("Ammo", count); + + syncBaubles(stack); } public float getAmmoModifier() {