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:
Arcaratus 2016-06-07 18:50:41 -04:00 committed by Nick Ignoffo
parent 9aa2f86c88
commit 8d66575530
19 changed files with 922 additions and 6 deletions

View file

@ -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;
}
}
}

View file

@ -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());
}
}
}

View file

@ -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)