mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-26 15:03:01 +00:00
Merge remote-tracking branch 'DarkShadow44/ammo_fix' into dev
This commit is contained in:
1 file changed
+21
-2
@@ -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() {
|
||||
|
||||
Reference in new issue
Block a user