Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package iitest.capability;
- 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.text.ITextComponent;
- import net.minecraftforge.common.util.Constants;
- import java.util.List;
- public class ITestImpl implements ITest {
- private int value = 0;
- private ItemStack[] slot = new ItemStack[1];
- public int getValue() {
- return value;
- }
- public void setValue(int v) {
- value = v;
- }
- public void readNBT(NBTTagCompound nbt) {
- NBTTagList slots = nbt.getTagList("__slots__", Constants.NBT.TAG_COMPOUND);
- for (byte i = 0; i < slots.tagCount(); i++) {
- NBTTagCompound item = slots.getCompoundTagAt(i);
- int s = item.getByte("__slot__");
- slot[s] = new ItemStack(item);
- }
- value = nbt.getInteger("__value__");
- }
- public NBTTagCompound writeNBT() {
- NBTTagList slots = new NBTTagList();
- // Can resize this v loop for a real inventory.
- for (byte i = 0; i < 1; i++) {
- if (slot[i] != null) {
- // Calls ItemStack.writeNBT(...)
- NBTTagCompound item = slot[i].serializeNBT();
- item.setByte("__slot__", i);
- slots.appendTag(item);
- }
- }
- NBTTagCompound nbt = new NBTTagCompound();
- nbt.setInteger("__value__", value);
- nbt.setTag("__slots__", slots);
- return nbt;
- }
- @Override
- public int getSizeInventory() {
- return 1;
- }
- @Override
- public boolean isEmpty() {
- return slot[0] == null;
- }
- @Override
- public ItemStack getStackInSlot(int index) {
- if (index == 0 && slot[0] != null)
- return slot[0];
- return ItemStack.EMPTY;
- }
- @Override
- public ItemStack decrStackSize(int index, int count) {
- if (index == 0 && count > 0 && slot[0] != null) {
- ItemStack tmp = this.slot[0].splitStack(count);
- if (this.slot[0].getCount() == 0)
- this.slot[0] = null;
- return tmp;
- }
- return ItemStack.EMPTY;
- }
- @Override
- public ItemStack removeStackFromSlot(int index) {
- if (index == 0 && slot[0] != null) {
- ItemStack tmp = slot[0];
- slot[0] = null;
- return (tmp);
- }
- return ItemStack.EMPTY;
- }
- @Override
- public void setInventorySlotContents(int index, ItemStack stack) {
- if (index == 0)
- this.slot[0] = stack;
- }
- @Override
- public int getInventoryStackLimit() {
- return 64;
- }
- @Override
- public void markDirty() {
- // ???
- }
- @Override
- public boolean isUsableByPlayer(EntityPlayer player) {
- return true;
- }
- @Override
- public void openInventory(EntityPlayer player) {
- // ???
- }
- @Override
- public void closeInventory(EntityPlayer player) {
- // ???
- }
- @Override
- public boolean isItemValidForSlot(int index, ItemStack stack) {
- return true;
- }
- @Override
- public int getField(int id) {
- return 0;
- }
- @Override
- public void setField(int id, int value) {
- // ???
- }
- @Override
- public int getFieldCount() {
- return 0;
- }
- @Override
- public void clear() {
- slot[0] = null;
- }
- @Override
- public String getName() {
- return null;
- }
- @Override
- public boolean hasCustomName() {
- return false;
- }
- @Override
- public ITextComponent getDisplayName() {
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement