Files
CustomNPC-Plus/src/main/java/noppes/npcs/items/MoneyBagContents.java
T
2025-03-13 17:14:45 -04:00

54 lines
1.7 KiB
Java

package noppes.npcs.items;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class MoneyBagContents {
private EntityPlayer player;
private int[] coinData = new int[]{0, 0, 0, 0, 0, 0, 0};
public MoneyBagContents(EntityPlayer player) {
this.player = player;
}
public void readNBT(NBTTagCompound compound) {
coinData = compound.getIntArray("coins");
}
public NBTTagCompound writeNBT() {
NBTTagCompound compound = new NBTTagCompound();
compound.setIntArray("coins", coinData);
return compound;
}
public enum CoinType {
WOOD, STONE, IRON, GOLD, DIAMOND, BRONZE, EMERALD;
}
//Adds stackSize to coinType
public void AddCurrency(CoinType coinType, byte stackSize, ItemStack theBag) {
coinData[coinType.ordinal()] = coinData[coinType.ordinal()] + stackSize;
theBag.stackTagCompound.setTag("contents", writeNBT());
}
//Creates amount number of coinType in playerInventory and subtracts from the moneyBag.
public void WithdrawCurrencyByVal(CoinType coinType, short amount, ItemStack theBag) {
int amtAdded = 0;
coinData[coinType.ordinal()] = coinData[coinType.ordinal()] - amtAdded;
theBag.stackTagCompound.setTag("contents", writeNBT());
}
//Creates numStacks of coinType in recievingInventory and subtracts from the moneyBag.
public void WithdrawCurrencyByStack(CoinType coinType, byte numStacks, ItemStack theBag) {
int amtAdded = 0;
//check inventory space
coinData[coinType.ordinal()] = coinData[coinType.ordinal()] - amtAdded;
theBag.stackTagCompound.setTag("contents", writeNBT());
}
}