some methods belong in the item class itself
This commit is contained in:
@@ -6,6 +6,8 @@ import net.minecraft.creativetab.CreativeTabs;
|
|||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagList;
|
||||||
import net.minecraft.util.IIcon;
|
import net.minecraft.util.IIcon;
|
||||||
import net.minecraft.util.StatCollector;
|
import net.minecraft.util.StatCollector;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
@@ -25,16 +27,16 @@ public class ItemStorageCell extends ItemSC {
|
|||||||
@Override
|
@Override
|
||||||
public void getSubItems(Item item, CreativeTabs tab, List list) {
|
public void getSubItems(Item item, CreativeTabs tab, List list) {
|
||||||
for (int i = 0; i < 5; ++i) {
|
for (int i = 0; i < 5; ++i) {
|
||||||
list.add(CellStorage.init(new ItemStack(item, 1, i)));
|
list.add(initNBT(new ItemStack(item, 1, i)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addInformation(ItemStack cell, EntityPlayer player, List list, boolean b) {
|
public void addInformation(ItemStack cell, EntityPlayer player, List list, boolean b) {
|
||||||
if (CellStorage.getCapacity(cell) == -1) {
|
if (getCapacity(cell) == -1) {
|
||||||
list.add(String.format(StatCollector.translateToLocal("misc.storagecraft:storageCellStored"), CellStorage.getStored(cell)));
|
list.add(String.format(StatCollector.translateToLocal("misc.storagecraft:storageCellStored"), getStored(cell)));
|
||||||
} else {
|
} else {
|
||||||
list.add(String.format(StatCollector.translateToLocal("misc.storagecraft:storageCellStoredWithCapacity"), CellStorage.getStored(cell), CellStorage.getCapacity(cell)));
|
list.add(String.format(StatCollector.translateToLocal("misc.storagecraft:storageCellStoredWithCapacity"), getStored(cell), getCapacity(cell)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +44,7 @@ public class ItemStorageCell extends ItemSC {
|
|||||||
public void onCreated(ItemStack stack, World world, EntityPlayer player) {
|
public void onCreated(ItemStack stack, World world, EntityPlayer player) {
|
||||||
super.onCreated(stack, world, player);
|
super.onCreated(stack, world, player);
|
||||||
|
|
||||||
CellStorage.init(stack);
|
initNBT(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -56,4 +58,33 @@ public class ItemStorageCell extends ItemSC {
|
|||||||
public IIcon getIconFromDamage(int damage) {
|
public IIcon getIconFromDamage(int damage) {
|
||||||
return icons[damage];
|
return icons[damage];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ItemStack initNBT(ItemStack cell) {
|
||||||
|
cell.stackTagCompound = new NBTTagCompound();
|
||||||
|
cell.stackTagCompound.setTag(CellStorage.NBT_ITEMS, new NBTTagList());
|
||||||
|
cell.stackTagCompound.setInteger(CellStorage.NBT_STORED, 0);
|
||||||
|
|
||||||
|
return cell;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getStored(ItemStack cell) {
|
||||||
|
return cell.stackTagCompound.getInteger(CellStorage.NBT_STORED);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getCapacity(ItemStack cell) {
|
||||||
|
switch (cell.getItemDamage()) {
|
||||||
|
case 0:
|
||||||
|
return 1000;
|
||||||
|
case 1:
|
||||||
|
return 4000;
|
||||||
|
case 2:
|
||||||
|
return 16000;
|
||||||
|
case 3:
|
||||||
|
return 64000;
|
||||||
|
case 4:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import net.minecraft.item.Item;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import storagecraft.item.ItemStorageCell;
|
||||||
|
|
||||||
public class CellStorage implements IStorage {
|
public class CellStorage implements IStorage {
|
||||||
public static final String NBT_ITEMS = "Items";
|
public static final String NBT_ITEMS = "Items";
|
||||||
@@ -21,10 +22,6 @@ public class CellStorage implements IStorage {
|
|||||||
this.cell = cell;
|
this.cell = cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
private StorageItem createItemFromNBT(NBTTagCompound tag) {
|
|
||||||
return new StorageItem(Item.getItemById(tag.getInteger(NBT_ITEM_TYPE)), tag.getInteger(NBT_ITEM_QUANTITY), tag.getInteger(NBT_ITEM_DAMAGE), tag.hasKey(NBT_ITEM_NBT) ? ((NBTTagCompound) tag.getTag(NBT_ITEM_NBT)) : null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addItems(List<StorageItem> items) {
|
public void addItems(List<StorageItem> items) {
|
||||||
NBTTagList list = (NBTTagList) cell.stackTagCompound.getTag(NBT_ITEMS);
|
NBTTagList list = (NBTTagList) cell.stackTagCompound.getTag(NBT_ITEMS);
|
||||||
@@ -38,7 +35,7 @@ public class CellStorage implements IStorage {
|
|||||||
public void push(ItemStack stack) {
|
public void push(ItemStack stack) {
|
||||||
NBTTagList list = (NBTTagList) cell.stackTagCompound.getTag(NBT_ITEMS);
|
NBTTagList list = (NBTTagList) cell.stackTagCompound.getTag(NBT_ITEMS);
|
||||||
|
|
||||||
cell.stackTagCompound.setInteger(NBT_STORED, getStored(cell) + stack.stackSize);
|
cell.stackTagCompound.setInteger(NBT_STORED, ItemStorageCell.getStored(cell) + stack.stackSize);
|
||||||
|
|
||||||
for (int i = 0; i < list.tagCount(); ++i) {
|
for (int i = 0; i < list.tagCount(); ++i) {
|
||||||
NBTTagCompound tag = list.getCompoundTagAt(i);
|
NBTTagCompound tag = list.getCompoundTagAt(i);
|
||||||
@@ -87,7 +84,7 @@ public class CellStorage implements IStorage {
|
|||||||
list.removeTag(i);
|
list.removeTag(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
cell.stackTagCompound.setInteger(NBT_STORED, getStored(cell) - quantity);
|
cell.stackTagCompound.setInteger(NBT_STORED, ItemStorageCell.getStored(cell) - quantity);
|
||||||
|
|
||||||
return quantity;
|
return quantity;
|
||||||
}
|
}
|
||||||
@@ -98,39 +95,14 @@ public class CellStorage implements IStorage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canPush(ItemStack stack) {
|
public boolean canPush(ItemStack stack) {
|
||||||
if (getCapacity(cell) == -1) {
|
if (ItemStorageCell.getCapacity(cell) == -1) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (getStored(cell) + stack.stackSize) <= getCapacity(cell);
|
return (ItemStorageCell.getStored(cell) + stack.stackSize) <= ItemStorageCell.getCapacity(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getStored(ItemStack cell) {
|
private StorageItem createItemFromNBT(NBTTagCompound tag) {
|
||||||
return cell.stackTagCompound.getInteger(CellStorage.NBT_STORED);
|
return new StorageItem(Item.getItemById(tag.getInteger(NBT_ITEM_TYPE)), tag.getInteger(NBT_ITEM_QUANTITY), tag.getInteger(NBT_ITEM_DAMAGE), tag.hasKey(NBT_ITEM_NBT) ? ((NBTTagCompound) tag.getTag(NBT_ITEM_NBT)) : null);
|
||||||
}
|
|
||||||
|
|
||||||
public static int getCapacity(ItemStack cell) {
|
|
||||||
switch (cell.getItemDamage()) {
|
|
||||||
case 0:
|
|
||||||
return 1000;
|
|
||||||
case 1:
|
|
||||||
return 4000;
|
|
||||||
case 2:
|
|
||||||
return 16000;
|
|
||||||
case 3:
|
|
||||||
return 64000;
|
|
||||||
case 4:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ItemStack init(ItemStack cell) {
|
|
||||||
cell.stackTagCompound = new NBTTagCompound();
|
|
||||||
cell.stackTagCompound.setTag(CellStorage.NBT_ITEMS, new NBTTagList());
|
|
||||||
cell.stackTagCompound.setInteger(CellStorage.NBT_STORED, 0);
|
|
||||||
|
|
||||||
return cell;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user