Advertisement
Guest User

ITestImpl (2)

a guest
Jul 1st, 2017
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.80 KB | None | 0 0
  1. package iitest.capability;
  2.  
  3. import net.minecraft.entity.player.EntityPlayer;
  4. import net.minecraft.item.ItemStack;
  5. import net.minecraft.nbt.NBTTagCompound;
  6. import net.minecraft.nbt.NBTTagList;
  7. import net.minecraft.util.text.ITextComponent;
  8. import net.minecraftforge.common.util.Constants;
  9.  
  10. import java.util.List;
  11.  
  12. public class ITestImpl implements ITest {
  13.     private int       value = 0;
  14.  
  15.     private ItemStack[] slot = new ItemStack[1];
  16.  
  17.  
  18.     public int getValue() {
  19.         return value;
  20.     }
  21.  
  22.     public void setValue(int v) {
  23.         value = v;
  24.     }
  25.  
  26.  
  27.     public void readNBT(NBTTagCompound nbt) {
  28.         NBTTagList slots = nbt.getTagList("__slots__", Constants.NBT.TAG_COMPOUND);
  29.  
  30.         for (byte i = 0; i < slots.tagCount(); i++) {
  31.             NBTTagCompound item = slots.getCompoundTagAt(i);
  32.             int s = item.getByte("__slot__");
  33.             slot[s] = new ItemStack(item);
  34.         }
  35.  
  36.         value = nbt.getInteger("__value__");
  37.     }
  38.  
  39.     public NBTTagCompound writeNBT() {
  40.         NBTTagList slots = new NBTTagList();
  41.  
  42.         // Can resize this   v  loop for a real inventory.
  43.         for (byte i = 0; i < 1; i++) {
  44.             if (slot[i] != null) {
  45.                 // Calls ItemStack.writeNBT(...)
  46.                 NBTTagCompound item = slot[i].serializeNBT();
  47.                 item.setByte("__slot__", i);
  48.                 slots.appendTag(item);
  49.             }
  50.         }
  51.  
  52.         NBTTagCompound nbt = new NBTTagCompound();
  53.  
  54.         nbt.setInteger("__value__", value);
  55.         nbt.setTag("__slots__", slots);
  56.  
  57.         return nbt;
  58.     }
  59.  
  60.  
  61.     @Override
  62.     public int getSizeInventory() {
  63.         return 1;
  64.     }
  65.  
  66.     @Override
  67.     public boolean isEmpty() {
  68.         return slot[0] == null;
  69.     }
  70.  
  71.     @Override
  72.     public ItemStack getStackInSlot(int index) {
  73.         if (index == 0 && slot[0] != null)
  74.             return slot[0];
  75.         return ItemStack.EMPTY;
  76.     }
  77.  
  78.     @Override
  79.     public ItemStack decrStackSize(int index, int count) {
  80.         if (index == 0 && count > 0 && slot[0] != null) {
  81.             ItemStack tmp = this.slot[0].splitStack(count);
  82.  
  83.             if (this.slot[0].getCount() == 0)
  84.                 this.slot[0] = null;
  85.  
  86.             return tmp;
  87.         }
  88.         return ItemStack.EMPTY;
  89.     }
  90.  
  91.     @Override
  92.     public ItemStack removeStackFromSlot(int index) {
  93.         if (index == 0 && slot[0] != null) {
  94.             ItemStack tmp = slot[0];
  95.             slot[0] = null;
  96.             return (tmp);
  97.         }
  98.         return ItemStack.EMPTY;
  99.     }
  100.  
  101.     @Override
  102.     public void setInventorySlotContents(int index, ItemStack stack) {
  103.         if (index == 0)
  104.             this.slot[0] = stack;
  105.     }
  106.  
  107.     @Override
  108.     public int getInventoryStackLimit() {
  109.         return 64;
  110.     }
  111.  
  112.     @Override
  113.     public void markDirty() {
  114.         // ???
  115.     }
  116.  
  117.     @Override
  118.     public boolean isUsableByPlayer(EntityPlayer player) {
  119.         return true;
  120.     }
  121.  
  122.     @Override
  123.     public void openInventory(EntityPlayer player) {
  124.         // ???
  125.     }
  126.  
  127.     @Override
  128.     public void closeInventory(EntityPlayer player) {
  129.         // ???
  130.     }
  131.  
  132.     @Override
  133.     public boolean isItemValidForSlot(int index, ItemStack stack) {
  134.         return true;
  135.     }
  136.  
  137.     @Override
  138.     public int getField(int id) {
  139.         return 0;
  140.     }
  141.  
  142.     @Override
  143.     public void setField(int id, int value) {
  144.         // ???
  145.     }
  146.  
  147.     @Override
  148.     public int getFieldCount() {
  149.         return 0;
  150.     }
  151.  
  152.     @Override
  153.     public void clear() {
  154.         slot[0] = null;
  155.     }
  156.  
  157.  
  158.     @Override
  159.     public String getName() {
  160.         return null;
  161.     }
  162.  
  163.     @Override
  164.     public boolean hasCustomName() {
  165.         return false;
  166.     }
  167.  
  168.     @Override
  169.     public ITextComponent getDisplayName() {
  170.         return null;
  171.     }
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement