Advertisement
Fatcatgaming3603

Untitled

Jun 5th, 2020
2,839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.39 KB | None | 0 0
  1. package micdoodle8.mods.galacticraft.core.inventory;
  2.  
  3. import micdoodle8.mods.galacticraft.api.inventory.IInventoryGC;
  4. import net.minecraft.entity.player.EntityPlayer;
  5. import net.minecraft.inventory.ItemStackHelper;
  6. import net.minecraft.item.ItemStack;
  7. import net.minecraft.nbt.NBTTagCompound;
  8. import net.minecraft.nbt.NBTTagList;
  9. import net.minecraft.util.NonNullList;
  10. import net.minecraft.util.text.ITextComponent;
  11.  
  12. import javax.annotation.Nonnull;
  13.  
  14. public class InventoryExtended implements IInventoryGC
  15. {
  16.     public NonNullList<ItemStack> stacks = NonNullList.withSize(11, ItemStack.EMPTY);
  17.  
  18.     @Override
  19.     public boolean isEmpty()
  20.     {
  21.         for (ItemStack itemstack : this.stacks)
  22.         {
  23.             if (!itemstack.isEmpty())
  24.             {
  25.                 return false;
  26.             }
  27.         }
  28.  
  29.         return true;
  30.     }
  31.  
  32.     @Override
  33.     public int getSizeInventory()
  34.     {
  35.         return this.stacks.size();
  36.     }
  37.  
  38.     @Override
  39.     @Nonnull
  40.     public ItemStack getStackInSlot(int index)
  41.     {
  42.         return this.stacks.get(index);
  43.     }
  44.  
  45.     @Override
  46.     public ItemStack decrStackSize(int index, int count)
  47.     {
  48.         ItemStack itemstack = ItemStackHelper.getAndSplit(this.stacks, index, count);
  49.  
  50.         if (!itemstack.isEmpty())
  51.         {
  52.             this.markDirty();
  53.         }
  54.  
  55.         return itemstack;
  56.     }
  57.  
  58.     @Override
  59.     public ItemStack removeStackFromSlot(int index)
  60.     {
  61.         return ItemStackHelper.getAndRemove(this.stacks, index);
  62.     }
  63.  
  64.     @Override
  65.     public void setInventorySlotContents(int index, ItemStack stack)
  66.     {
  67.         this.stacks.set(index, stack);
  68.  
  69.         if (stack.getCount() > this.getInventoryStackLimit())
  70.         {
  71.             stack.setCount(this.getInventoryStackLimit());
  72.         }
  73.  
  74.         this.markDirty();
  75.     }
  76.  
  77.     @Override
  78.     public String getName()
  79.     {
  80.         return "Galacticraft Player Inventory";
  81.     }
  82.  
  83.     @Override
  84.     public boolean hasCustomName()
  85.     {
  86.         return true;
  87.     }
  88.  
  89.     @Override
  90.     public int getInventoryStackLimit()
  91.     {
  92.         return 64;
  93.     }
  94.  
  95.     @Override
  96.     public void markDirty()
  97.     {
  98.  
  99.     }
  100.  
  101.     @Override
  102.     public boolean isUsableByPlayer(EntityPlayer entityplayer)
  103.     {
  104.         return true;
  105.     }
  106.  
  107.     @Override
  108.     public void openInventory(EntityPlayer player)
  109.     {
  110.  
  111.     }
  112.  
  113.     @Override
  114.     public void closeInventory(EntityPlayer player)
  115.     {
  116.  
  117.     }
  118.  
  119.     @Override
  120.     public boolean isItemValidForSlot(int i, ItemStack itemstack)
  121.     {
  122.         return false;
  123.     }
  124.  
  125.     @Override
  126.     public void dropExtendedItems(EntityPlayer player)
  127.     {
  128.         for (int i = 0; i < this.stacks.size(); i++)
  129.         {
  130.             ItemStack stack = this.stacks.get(i);
  131.  
  132.             if (!stack.isEmpty())
  133.             {
  134.                 player.dropItem(stack, true);
  135.             }
  136.  
  137.             this.stacks.set(i, ItemStack.EMPTY);
  138.         }
  139.     }
  140.  
  141.     // Backwards compatibility for old inventory
  142.     public void readFromNBTOld(NBTTagList par1NBTTagList)
  143.     {
  144.         this.stacks = NonNullList.withSize(11, ItemStack.EMPTY);
  145.  
  146.         for (int i = 0; i < par1NBTTagList.tagCount(); ++i)
  147.         {
  148.             final NBTTagCompound nbttagcompound = par1NBTTagList.getCompoundTagAt(i);
  149.             final int j = nbttagcompound.getByte("Slot") & 255;
  150.             final ItemStack itemstack = new ItemStack(nbttagcompound);
  151.  
  152.             if (!itemstack.isEmpty())
  153.             {
  154.                 if (j >= 200 && j < this.stacks.size() + 200 - 1)
  155.                 {
  156.                     this.stacks.set(j - 200, itemstack);
  157.                 }
  158.             }
  159.         }
  160.     }
  161.  
  162.     public void readFromNBT(NBTTagList tagList)
  163.     {
  164.         this.stacks = NonNullList.withSize(11, ItemStack.EMPTY);
  165.  
  166.         for (int i = 0; i < tagList.tagCount(); ++i)
  167.         {
  168.             final NBTTagCompound nbttagcompound = tagList.getCompoundTagAt(i);
  169.             final int j = nbttagcompound.getByte("Slot") & 255;
  170.             final ItemStack itemstack = new ItemStack(nbttagcompound);
  171.  
  172.             if (!itemstack.isEmpty())
  173.             {
  174.                 this.stacks.set(j, itemstack);
  175.             }
  176.         }
  177.     }
  178.  
  179.     public NBTTagList writeToNBT(NBTTagList tagList)
  180.     {
  181.         NBTTagCompound nbttagcompound;
  182.  
  183.         for (int i = 0; i < this.stacks.size(); ++i)
  184.         {
  185.             if (!this.stacks.get(i).isEmpty())
  186.             {
  187.                 nbttagcompound = new NBTTagCompound();
  188.                 nbttagcompound.setByte("Slot", (byte) i);
  189.                 this.stacks.get(i).writeToNBT(nbttagcompound);
  190.                 tagList.appendTag(nbttagcompound);
  191.             }
  192.         }
  193.  
  194.         return tagList;
  195.     }
  196.  
  197.     @Override
  198.     public void copyInventory(IInventoryGC par1InventoryPlayer)
  199.     {
  200.         InventoryExtended toCopy = (InventoryExtended) par1InventoryPlayer;
  201.         for (int i = 0; i < this.stacks.size(); ++i)
  202.         {
  203.             this.stacks.set(i, toCopy.stacks.get(i).copy());
  204.         }
  205.     }
  206.  
  207.     @Override
  208.     public int getField(int id)
  209.     {
  210.         return 0;
  211.     }
  212.  
  213.     @Override
  214.     public void setField(int id, int value)
  215.     {
  216.  
  217.     }
  218.  
  219.     @Override
  220.     public int getFieldCount()
  221.     {
  222.         return 0;
  223.     }
  224.  
  225.     @Override
  226.     public void clear()
  227.     {
  228.  
  229.     }
  230.  
  231.     @Override
  232.     public ITextComponent getDisplayName()
  233.     {
  234.         return null;
  235.     }
  236. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement