Backstage Sigil of Holding (#785)
* Backstage Sigil of Holding All Sigil of Holding features work, just need to add the aesthetics -> TehNut Somebody might want to look at adding LP costs to the Sigil? Also recipes need to be added Added a keybinding system for future usage Standardized some NBT tags Compact classes Fix lang stuff? * Fancify Sigil of Holding GUI Displays the selected sigil in the GUI now Woops * Quick fix * Unused import * Final commit I promise
This commit is contained in:
parent
9aa2f86c88
commit
8d66575530
19 changed files with 922 additions and 6 deletions
|
@ -0,0 +1,194 @@
|
|||
package WayofTime.bloodmagic.item.inventory;
|
||||
|
||||
import WayofTime.bloodmagic.api.iface.ISigil;
|
||||
import WayofTime.bloodmagic.item.sigil.ItemSigilHolding;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
|
||||
public class ContainerHolding extends Container
|
||||
{
|
||||
private final int PLAYER_INVENTORY_ROWS = 3;
|
||||
private final int PLAYER_INVENTORY_COLUMNS = 9;
|
||||
|
||||
private final EntityPlayer player;
|
||||
public final InventoryHolding inventoryHolding;
|
||||
|
||||
public ContainerHolding(EntityPlayer player, InventoryHolding inventoryHolding)
|
||||
{
|
||||
this.player = player;
|
||||
this.inventoryHolding = inventoryHolding;
|
||||
int currentSlotHeldIn = player.inventory.currentItem;
|
||||
|
||||
for (int columnIndex = 0; columnIndex < ItemSigilHolding.inventorySize; ++columnIndex)
|
||||
{
|
||||
this.addSlotToContainer(new SlotHolding(this, inventoryHolding, player, columnIndex, 8 + columnIndex * 36, 17));
|
||||
}
|
||||
|
||||
for (int rowIndex = 0; rowIndex < PLAYER_INVENTORY_ROWS; ++rowIndex)
|
||||
{
|
||||
for (int columnIndex = 0; columnIndex < PLAYER_INVENTORY_COLUMNS; ++columnIndex)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(player.inventory, columnIndex + rowIndex * 9 + 9, 8 + columnIndex * 18, 41 + rowIndex * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for (int actionBarIndex = 0; actionBarIndex < PLAYER_INVENTORY_COLUMNS; ++actionBarIndex)
|
||||
{
|
||||
if (actionBarIndex == currentSlotHeldIn)
|
||||
{
|
||||
this.addSlotToContainer(new SlotDisabled(player.inventory, actionBarIndex, 8 + actionBarIndex * 18, 99));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.addSlotToContainer(new Slot(player.inventory, actionBarIndex, 8 + actionBarIndex * 18, 99));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer entityPlayer)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(EntityPlayer entityPlayer)
|
||||
{
|
||||
super.onContainerClosed(entityPlayer);
|
||||
|
||||
if (!entityPlayer.worldObj.isRemote)
|
||||
{
|
||||
saveInventory(entityPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges()
|
||||
{
|
||||
super.detectAndSendChanges();
|
||||
|
||||
if (!player.worldObj.isRemote)
|
||||
{
|
||||
saveInventory(player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex)
|
||||
{
|
||||
ItemStack stack = null;
|
||||
Slot slotObject = (Slot) inventorySlots.get(slotIndex);
|
||||
int slots = inventorySlots.size();
|
||||
|
||||
if (slotObject != null && slotObject.getHasStack())
|
||||
{
|
||||
ItemStack stackInSlot = slotObject.getStack();
|
||||
stack = stackInSlot.copy();
|
||||
|
||||
if (stack.getItem() instanceof ISigil)
|
||||
{
|
||||
if (slotIndex < ItemSigilHolding.inventorySize)
|
||||
{
|
||||
if (!this.mergeItemStack(stackInSlot, ItemSigilHolding.inventorySize, slots, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (!this.mergeItemStack(stackInSlot, 0, ItemSigilHolding.inventorySize, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (stack.getItem() instanceof ItemSigilHolding)
|
||||
{
|
||||
if (slotIndex < ItemSigilHolding.inventorySize + (PLAYER_INVENTORY_ROWS * PLAYER_INVENTORY_COLUMNS))
|
||||
{
|
||||
if (!this.mergeItemStack(stackInSlot, ItemSigilHolding.inventorySize + (PLAYER_INVENTORY_ROWS * PLAYER_INVENTORY_COLUMNS), inventorySlots.size(), false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (!this.mergeItemStack(stackInSlot, ItemSigilHolding.inventorySize, ItemSigilHolding.inventorySize + (PLAYER_INVENTORY_ROWS * PLAYER_INVENTORY_COLUMNS), false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (stackInSlot.stackSize == 0)
|
||||
{
|
||||
slotObject.putStack(null);
|
||||
} else
|
||||
{
|
||||
slotObject.onSlotChanged();
|
||||
}
|
||||
|
||||
if (stackInSlot.stackSize == stack.stackSize)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
slotObject.onPickupFromSlot(player, stackInSlot);
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
public void saveInventory(EntityPlayer entityPlayer)
|
||||
{
|
||||
inventoryHolding.onGuiSaved(entityPlayer);
|
||||
}
|
||||
|
||||
private class SlotHolding extends Slot
|
||||
{
|
||||
private final EntityPlayer player;
|
||||
private ContainerHolding containerHolding;
|
||||
|
||||
public SlotHolding(ContainerHolding containerHolding, IInventory inventory, EntityPlayer player, int slotIndex, int x, int y)
|
||||
{
|
||||
super(inventory, slotIndex, x, y);
|
||||
this.player = player;
|
||||
this.containerHolding = containerHolding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlotChanged()
|
||||
{
|
||||
super.onSlotChanged();
|
||||
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isServer())
|
||||
{
|
||||
containerHolding.saveInventory(player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack itemStack)
|
||||
{
|
||||
return itemStack.getItem() instanceof ISigil && !(itemStack.getItem() instanceof ItemSigilHolding);
|
||||
}
|
||||
}
|
||||
|
||||
private class SlotDisabled extends Slot
|
||||
{
|
||||
public SlotDisabled(IInventory inventory, int slotIndex, int x, int y)
|
||||
{
|
||||
super(inventory, slotIndex, x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack itemStack)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeStack(EntityPlayer player)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
package WayofTime.bloodmagic.item.inventory;
|
||||
|
||||
import WayofTime.bloodmagic.api.Constants;
|
||||
import WayofTime.bloodmagic.api.iface.ISigil;
|
||||
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
|
||||
import WayofTime.bloodmagic.item.sigil.ItemSigilHolding;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class InventoryHolding extends ItemInventory
|
||||
{
|
||||
protected ItemStack[] inventory;
|
||||
|
||||
public InventoryHolding(ItemStack itemStack)
|
||||
{
|
||||
super(itemStack, ItemSigilHolding.inventorySize, "SigilOfHolding");
|
||||
|
||||
// readFromNBT(itemStack.getTagCompound());
|
||||
}
|
||||
|
||||
public void onGuiSaved(EntityPlayer entityPlayer)
|
||||
{
|
||||
masterStack = findParentStack(entityPlayer);
|
||||
|
||||
if (masterStack != null)
|
||||
{
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack findParentStack(EntityPlayer entityPlayer)
|
||||
{
|
||||
if (hasUUID(masterStack))
|
||||
{
|
||||
UUID parentStackUUID = new UUID(masterStack.getTagCompound().getLong(Constants.NBT.MOST_SIG), masterStack.getTagCompound().getLong(Constants.NBT.LEAST_SIG));
|
||||
for (int i = 0; i < entityPlayer.inventory.getSizeInventory(); i++)
|
||||
{
|
||||
ItemStack itemStack = entityPlayer.inventory.getStackInSlot(i);
|
||||
|
||||
if (hasUUID(itemStack))
|
||||
{
|
||||
if (itemStack.getTagCompound().getLong(Constants.NBT.MOST_SIG) == parentStackUUID.getMostSignificantBits() && itemStack.getTagCompound().getLong(Constants.NBT.LEAST_SIG) == parentStackUUID.getLeastSignificantBits())
|
||||
{
|
||||
return itemStack;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void save()
|
||||
{
|
||||
NBTTagCompound nbtTagCompound = masterStack.getTagCompound();
|
||||
|
||||
if (nbtTagCompound == null)
|
||||
{
|
||||
nbtTagCompound = new NBTTagCompound();
|
||||
|
||||
UUID uuid = UUID.randomUUID();
|
||||
nbtTagCompound.setLong(Constants.NBT.MOST_SIG, uuid.getMostSignificantBits());
|
||||
nbtTagCompound.setLong(Constants.NBT.LEAST_SIG, uuid.getLeastSignificantBits());
|
||||
}
|
||||
|
||||
writeToNBT(nbtTagCompound);
|
||||
masterStack.setTagCompound(nbtTagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack)
|
||||
{
|
||||
return itemStack.getItem() instanceof ISigil && !(itemStack.getItem() instanceof ItemSigilHolding);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static boolean hasUUID(ItemStack itemStack)
|
||||
{
|
||||
return itemStack.getTagCompound().hasKey(Constants.NBT.MOST_SIG) && itemStack.getTagCompound().hasKey(Constants.NBT.LEAST_SIG);
|
||||
}
|
||||
|
||||
public static void setUUID(ItemStack itemStack)
|
||||
{
|
||||
itemStack = NBTHelper.checkNBT(itemStack);
|
||||
|
||||
if (!itemStack.getTagCompound().hasKey(Constants.NBT.MOST_SIG) && !itemStack.getTagCompound().hasKey(Constants.NBT.LEAST_SIG))
|
||||
{
|
||||
UUID itemUUID = UUID.randomUUID();
|
||||
itemStack.getTagCompound().setLong(Constants.NBT.MOST_SIG, itemUUID.getMostSignificantBits());
|
||||
itemStack.getTagCompound().setLong(Constants.NBT.LEAST_SIG, itemUUID.getLeastSignificantBits());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -50,7 +50,7 @@ public class ItemInventory implements IInventory
|
|||
|
||||
public void readFromNBT(NBTTagCompound tagCompound)
|
||||
{
|
||||
NBTTagList tags = tagCompound.getTagList("Items", 10);
|
||||
NBTTagList tags = tagCompound.getTagList(Constants.NBT.ITEMS, 10);
|
||||
inventory = new ItemStack[getSizeInventory()];
|
||||
|
||||
for (int i = 0; i < tags.tagCount(); i++)
|
||||
|
@ -58,7 +58,7 @@ public class ItemInventory implements IInventory
|
|||
if (!isSyncedSlot(i))
|
||||
{
|
||||
NBTTagCompound data = tags.getCompoundTagAt(i);
|
||||
byte j = data.getByte("Slot");
|
||||
byte j = data.getByte(Constants.NBT.SLOT);
|
||||
|
||||
if (j >= 0 && j < inventory.length)
|
||||
{
|
||||
|
@ -77,13 +77,13 @@ public class ItemInventory implements IInventory
|
|||
if ((inventory[i] != null) && !isSyncedSlot(i))
|
||||
{
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setByte("Slot", (byte) i);
|
||||
data.setByte(Constants.NBT.SLOT, (byte) i);
|
||||
inventory[i].writeToNBT(data);
|
||||
tags.appendTag(data);
|
||||
}
|
||||
}
|
||||
|
||||
tagCompound.setTag("Items", tags);
|
||||
tagCompound.setTag(Constants.NBT.ITEMS, tags);
|
||||
}
|
||||
|
||||
public void readFromStack(ItemStack masterStack)
|
||||
|
|
|
@ -0,0 +1,305 @@
|
|||
package WayofTime.bloodmagic.item.sigil;
|
||||
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import WayofTime.bloodmagic.api.Constants;
|
||||
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
|
||||
import WayofTime.bloodmagic.item.inventory.InventoryHolding;
|
||||
import WayofTime.bloodmagic.util.handler.BMKeyBinding;
|
||||
import WayofTime.bloodmagic.util.handler.IKeybindable;
|
||||
import WayofTime.bloodmagic.util.helper.TextHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ItemSigilHolding extends ItemSigilBase implements IKeybindable
|
||||
{
|
||||
public static int inventorySize;
|
||||
|
||||
public ItemSigilHolding()
|
||||
{
|
||||
super("holding");
|
||||
|
||||
inventorySize = 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyPressed(ItemStack stack, EntityPlayer player, BMKeyBinding.Key key, boolean showInChat)
|
||||
{
|
||||
if (stack == player.getHeldItemMainhand() && stack.getItem() instanceof ItemSigilHolding && key.equals(BMKeyBinding.Key.OPEN_SIGIL_HOLDING))
|
||||
{
|
||||
InventoryHolding.setUUID(stack);
|
||||
player.openGui(BloodMagic.instance, Constants.Gui.SIGIL_HOLDING_GUI, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHighlightTip(ItemStack stack, String displayName)
|
||||
{
|
||||
ItemStack[] inv = getInternalInventory(stack);
|
||||
|
||||
if (inv == null)
|
||||
return displayName;
|
||||
|
||||
int currentSlot = getCurrentItemOrdinal(stack);
|
||||
ItemStack item = inv[currentSlot];
|
||||
|
||||
if (item == null)
|
||||
return displayName;
|
||||
else
|
||||
return TextHelper.localizeEffect("item.BloodMagic.sigil.holding.display", displayName, item.getDisplayName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced)
|
||||
{
|
||||
super.addInformation(stack, player, tooltip, advanced);
|
||||
|
||||
ItemStack[] inv = getInternalInventory(stack);
|
||||
|
||||
if (inv == null)
|
||||
return;
|
||||
|
||||
int currentSlot = getCurrentItemOrdinal(stack);
|
||||
ItemStack item = inv[currentSlot];
|
||||
|
||||
for (int i = 0; i < inventorySize; i++)
|
||||
{
|
||||
if (inv[i] != null)
|
||||
if (item != null && inv[i] == item)
|
||||
tooltip.add(TextHelper.localizeEffect("tooltip.BloodMagic.sigil.holding.sigilInSlot", i + 1, "&l&n" + inv[i].getDisplayName() + "&r"));
|
||||
else
|
||||
tooltip.add(TextHelper.localizeEffect("tooltip.BloodMagic.sigil.holding.sigilInSlot", i + 1, inv[i].getDisplayName()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand)
|
||||
{
|
||||
int currentSlot = getCurrentItemOrdinal(stack);
|
||||
ItemStack[] inv = getInternalInventory(stack);
|
||||
|
||||
if (inv == null)
|
||||
return EnumActionResult.PASS;
|
||||
|
||||
ItemStack itemUsing = inv[currentSlot];
|
||||
|
||||
if (itemUsing == null)
|
||||
return EnumActionResult.PASS;
|
||||
|
||||
EnumActionResult result = itemUsing.getItem().onItemUseFirst(itemUsing, player, world, pos, side, hitX, hitY, hitZ, hand);
|
||||
saveInventory(stack, inv);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
int currentSlot = getCurrentItemOrdinal(stack);
|
||||
ItemStack[] inv = getInternalInventory(stack);
|
||||
|
||||
if (inv == null)
|
||||
return EnumActionResult.PASS;
|
||||
|
||||
ItemStack itemUsing = inv[currentSlot];
|
||||
|
||||
if (itemUsing == null)
|
||||
return EnumActionResult.PASS;
|
||||
|
||||
EnumActionResult result = itemUsing.getItem().onItemUse(itemUsing, playerIn, worldIn, pos, hand, facing, hitX, hitY, hitZ);
|
||||
saveInventory(stack, inv);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand)
|
||||
{
|
||||
int currentSlot = getCurrentItemOrdinal(stack);
|
||||
ItemStack[] inv = getInternalInventory(stack);
|
||||
|
||||
if (inv == null)
|
||||
return ActionResult.newResult(EnumActionResult.PASS, stack);
|
||||
|
||||
ItemStack itemUsing = inv[currentSlot];
|
||||
|
||||
if (itemUsing == null)
|
||||
return ActionResult.newResult(EnumActionResult.PASS, stack);
|
||||
|
||||
itemUsing.getItem().onItemRightClick(itemUsing, world, player, hand);
|
||||
|
||||
saveInventory(stack, inv);
|
||||
|
||||
return ActionResult.newResult(EnumActionResult.PASS, stack);
|
||||
}
|
||||
|
||||
public void saveInventory(ItemStack itemStack, ItemStack[] inventory)
|
||||
{
|
||||
NBTTagCompound itemTag = itemStack.getTagCompound();
|
||||
|
||||
if (itemTag == null)
|
||||
{
|
||||
itemStack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
||||
NBTTagList itemList = new NBTTagList();
|
||||
|
||||
for (int i = 0; i < inventorySize; i++)
|
||||
{
|
||||
if (inventory[i] != null)
|
||||
{
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setByte(Constants.NBT.SLOT, (byte) i);
|
||||
inventory[i].writeToNBT(tag);
|
||||
itemList.appendTag(tag);
|
||||
}
|
||||
}
|
||||
|
||||
itemTag.setTag(Constants.NBT.ITEMS, itemList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack itemStack, World world, Entity entity, int itemSlot, boolean isSelected)
|
||||
{
|
||||
if (itemStack.getTagCompound() != null)
|
||||
{
|
||||
this.tickInternalInventory(itemStack, world, entity, itemSlot, isSelected);
|
||||
}
|
||||
}
|
||||
|
||||
public void tickInternalInventory(ItemStack itemStack, World world, Entity entity, int itemSlot, boolean isSelected)
|
||||
{
|
||||
ItemStack[] inv = getInternalInventory(itemStack);
|
||||
|
||||
if (inv == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < inventorySize; i++)
|
||||
{
|
||||
if (inv[i] == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
inv[i].getItem().onUpdate(inv[i], world, entity, itemSlot, isSelected);
|
||||
}
|
||||
}
|
||||
|
||||
public static int next(int mode)
|
||||
{
|
||||
int index = mode + 1;
|
||||
|
||||
if (index >= inventorySize)
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
public static int prev(int mode)
|
||||
{
|
||||
int index = mode - 1;
|
||||
|
||||
if (index < 0)
|
||||
{
|
||||
index = inventorySize;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
private static void initModeTag(ItemStack itemStack)
|
||||
{
|
||||
if (itemStack.getTagCompound() == null)
|
||||
{
|
||||
itemStack = NBTHelper.checkNBT(itemStack);
|
||||
itemStack.getTagCompound().setInteger(Constants.NBT.CURRENT_SIGIL, inventorySize);
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack getCurrentSigil(ItemStack itemStack)
|
||||
{
|
||||
if (itemStack.getItem() instanceof ItemSigilHolding)
|
||||
{
|
||||
ItemStack[] itemStacks = getInternalInventory(itemStack);
|
||||
if (itemStacks != null)
|
||||
{
|
||||
return itemStacks[getCurrentItemOrdinal(itemStack)];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getCurrentItemOrdinal(ItemStack itemStack)
|
||||
{
|
||||
if (itemStack.getItem() instanceof ItemSigilHolding)
|
||||
{
|
||||
initModeTag(itemStack);
|
||||
int currentSigil = itemStack.getTagCompound().getInteger(Constants.NBT.CURRENT_SIGIL);
|
||||
currentSigil = MathHelper.clamp_int(currentSigil, 0, inventorySize - 1);
|
||||
return currentSigil;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static ItemStack[] getInternalInventory(ItemStack itemStack)
|
||||
{
|
||||
initModeTag(itemStack);
|
||||
NBTTagCompound tagCompound = itemStack.getTagCompound();
|
||||
|
||||
if (tagCompound == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
NBTTagList tagList = tagCompound.getTagList(Constants.NBT.ITEMS, 10);
|
||||
|
||||
if (tagList == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
ItemStack[] inv = new ItemStack[inventorySize];
|
||||
|
||||
for (int i = 0; i < tagList.tagCount(); i++)
|
||||
{
|
||||
NBTTagCompound data = tagList.getCompoundTagAt(i);
|
||||
byte j = data.getByte(Constants.NBT.SLOT);
|
||||
|
||||
if (j >= 0 && j < inv.length)
|
||||
{
|
||||
inv[j] = ItemStack.loadItemStackFromNBT(data);
|
||||
}
|
||||
}
|
||||
|
||||
return inv;
|
||||
}
|
||||
|
||||
public static void cycleSigil(ItemStack itemStack, int mode)
|
||||
{
|
||||
if (itemStack.getItem() instanceof ItemSigilHolding)
|
||||
{
|
||||
initModeTag(itemStack);
|
||||
itemStack.getTagCompound().setInteger(Constants.NBT.CURRENT_SIGIL, mode);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue