Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package coap.cultfaerie.container;
- import coap.cultfaerie.client.gui.GuiFaerieJournal;
- import coap.cultfaerie.common.items.ItemJournal;
- import coap.cultfaerie.container.slot.SlotHiveInput;
- import coap.cultfaerie.inventory.InventoryItem;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.entity.player.InventoryPlayer;
- import net.minecraft.inventory.Container;
- import net.minecraft.inventory.InventoryBasic;
- import net.minecraft.inventory.Slot;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- public class ContainerJournal extends Container {
- InventoryPlayer player_inv;
- InventoryItem journal_inv;
- ItemStack journal;
- int journal_slot;
- public ContainerJournal(InventoryPlayer playerinv) {
- //Make temporary inventory
- this.journal = null;
- this.player_inv = playerinv;
- journal_inv = new InventoryItem("Journal", false, 1);
- //Journal [0]
- addSlotToContainer(new Slot(journal_inv, 0, 165, 29));
- for(int i = 0; i < 9; i++)
- {
- ItemStack item = playerinv.mainInventory[i];
- if(item != null && item.getItem() instanceof ItemJournal)
- {
- if(item.hasTagCompound())
- {
- boolean activated = item.getTagCompound().getBoolean("b_activated");
- if(activated)
- {
- item.getTagCompound().setBoolean("b_activated", false);
- journal = item;
- journal_slot = i;
- break;
- }
- }
- }
- }
- //Add the one and only slot.
- if(journal != null)
- {
- //Fill it with the item. (If any)
- NBTTagCompound nbt = journal.getTagCompound();
- if(nbt != null && nbt.hasKey("item"))
- {
- System.out.println("Has key.");
- NBTTagCompound item_nbt = (NBTTagCompound) nbt.getTag("item");
- ItemStack itemstack = ItemStack.loadItemStackFromNBT(item_nbt);
- journal_inv.setInventorySlotContents(0, itemstack);
- journal_inv.markDirty();
- }
- }
- //Bind inventory
- bindPlayerInventory(playerinv);
- }
- @Override
- public boolean canInteractWith(EntityPlayer player) {
- return journal != null;
- }
- @Override
- public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
- ItemStack stack = null;
- Slot slotObject = (Slot) inventorySlots.get(slot);
- System.out.println("Stack in slot probs");
- if(slotObject != null && slotObject.getHasStack())
- {
- ItemStack stackInSlot = slotObject.getStack();
- stack = stackInSlot;
- if(slot == 0)
- {
- //To player
- }else{
- //From player
- }
- }
- return stack;
- }
- protected void bindPlayerInventory(InventoryPlayer invPlayer) {
- // Render inventory
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 9; j++) {
- addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 140 + i * 18));
- }
- }
- // Render hotbar
- for (int j = 0; j < 9; j++) {
- addSlotToContainer(new Slot(invPlayer, j, 8 + j * 18, 198));
- }
- }
- @Override
- public void onContainerClosed(EntityPlayer player) {
- //System.out.println("journal: " + journal + ": isRemote: " + player.worldObj.isRemote);
- //Save data to item.
- if(journal != null)
- {
- NBTTagCompound nbt = journal.getTagCompound();
- ItemStack itemstack = journal_inv.getStackInSlot(0);
- NBTTagCompound item_nbt = new NBTTagCompound();
- if(itemstack != null)
- itemstack.writeToNBT(item_nbt);
- System.out.println(player.worldObj.isRemote ? "Client" : "Server" + " writing NBT. Status=" + (itemstack != null) );
- nbt.setTag("item", item_nbt);
- journal.setTagCompound(nbt);
- player.inventory.setInventorySlotContents(journal_slot, journal);
- }
- //Do player stuff
- super.onContainerClosed(player);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement