initial 1.8 port

This commit is contained in:
Raoul Van den Berge
2015-12-25 18:51:58 +01:00
parent 8acd72fffc
commit 6c3c113521
74 changed files with 6796 additions and 7094 deletions

View File

@@ -1,128 +1,128 @@
package storagecraft.storage;
import java.util.List;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import storagecraft.item.ItemStorageCell;
public class CellStorage implements IStorage
{
public static final String NBT_ITEMS = "Items";
public static final String NBT_STORED = "Stored";
public static final String NBT_ITEM_TYPE = "Type";
public static final String NBT_ITEM_QUANTITY = "Quantity";
public static final String NBT_ITEM_DAMAGE = "Damage";
public static final String NBT_ITEM_NBT = "NBT";
private ItemStack cell;
public CellStorage(ItemStack cell)
{
this.cell = cell;
}
@Override
public void addItems(List<StorageItem> items)
{
NBTTagList list = (NBTTagList) cell.stackTagCompound.getTag(NBT_ITEMS);
for (int i = 0; i < list.tagCount(); ++i)
{
items.add(createItemFromNBT(list.getCompoundTagAt(i)));
}
}
@Override
public void push(ItemStack stack)
{
NBTTagList list = (NBTTagList) cell.stackTagCompound.getTag(NBT_ITEMS);
cell.stackTagCompound.setInteger(NBT_STORED, ItemStorageCell.getStored(cell) + stack.stackSize);
for (int i = 0; i < list.tagCount(); ++i)
{
NBTTagCompound tag = list.getCompoundTagAt(i);
StorageItem item = createItemFromNBT(tag);
if (item.compareNoQuantity(stack))
{
tag.setInteger(NBT_ITEM_QUANTITY, item.getQuantity() + stack.stackSize);
return;
}
}
NBTTagCompound tag = new NBTTagCompound();
tag.setInteger(NBT_ITEM_TYPE, Item.getIdFromItem(stack.getItem()));
tag.setInteger(NBT_ITEM_QUANTITY, stack.stackSize);
tag.setInteger(NBT_ITEM_DAMAGE, stack.getItemDamage());
if (stack.stackTagCompound != null)
{
tag.setTag(NBT_ITEM_NBT, stack.stackTagCompound);
}
list.appendTag(tag);
}
@Override
public ItemStack take(ItemStack stack, int flags)
{
int quantity = stack.stackSize;
NBTTagList list = (NBTTagList) cell.stackTagCompound.getTag(NBT_ITEMS);
for (int i = 0; i < list.tagCount(); ++i)
{
NBTTagCompound tag = list.getCompoundTagAt(i);
StorageItem item = createItemFromNBT(tag);
if (item.compare(stack, flags))
{
if (quantity > item.getQuantity())
{
quantity = item.getQuantity();
}
tag.setInteger(NBT_ITEM_QUANTITY, item.getQuantity() - quantity);
if (item.getQuantity() - quantity == 0)
{
list.removeTag(i);
}
cell.stackTagCompound.setInteger(NBT_STORED, ItemStorageCell.getStored(cell) - quantity);
ItemStack newItem = item.toItemStack();
newItem.stackSize = quantity;
return newItem;
}
}
return null;
}
@Override
public boolean canPush(ItemStack stack)
{
if (ItemStorageCell.getCapacity(cell) == -1)
{
return true;
}
return (ItemStorageCell.getStored(cell) + stack.stackSize) <= ItemStorageCell.getCapacity(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);
}
}
package storagecraft.storage;
import java.util.List;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import storagecraft.item.ItemStorageCell;
public class CellStorage implements IStorage
{
public static final String NBT_ITEMS = "Items";
public static final String NBT_STORED = "Stored";
public static final String NBT_ITEM_TYPE = "Type";
public static final String NBT_ITEM_QUANTITY = "Quantity";
public static final String NBT_ITEM_DAMAGE = "Damage";
public static final String NBT_ITEM_NBT = "NBT";
private ItemStack cell;
public CellStorage(ItemStack cell)
{
this.cell = cell;
}
@Override
public void addItems(List<StorageItem> items)
{
NBTTagList list = (NBTTagList) cell.getTagCompound().getTag(NBT_ITEMS);
for (int i = 0; i < list.tagCount(); ++i)
{
items.add(createItemFromNBT(list.getCompoundTagAt(i)));
}
}
@Override
public void push(ItemStack stack)
{
NBTTagList list = (NBTTagList) cell.getTagCompound().getTag(NBT_ITEMS);
cell.getTagCompound().setInteger(NBT_STORED, ItemStorageCell.getStored(cell) + stack.stackSize);
for (int i = 0; i < list.tagCount(); ++i)
{
NBTTagCompound tag = list.getCompoundTagAt(i);
StorageItem item = createItemFromNBT(tag);
if (item.compareNoQuantity(stack))
{
tag.setInteger(NBT_ITEM_QUANTITY, item.getQuantity() + stack.stackSize);
return;
}
}
NBTTagCompound tag = new NBTTagCompound();
tag.setInteger(NBT_ITEM_TYPE, Item.getIdFromItem(stack.getItem()));
tag.setInteger(NBT_ITEM_QUANTITY, stack.stackSize);
tag.setInteger(NBT_ITEM_DAMAGE, stack.getItemDamage());
if (stack.hasTagCompound())
{
tag.setTag(NBT_ITEM_NBT, stack.getTagCompound());
}
list.appendTag(tag);
}
@Override
public ItemStack take(ItemStack stack, int flags)
{
int quantity = stack.stackSize;
NBTTagList list = (NBTTagList) cell.getTagCompound().getTag(NBT_ITEMS);
for (int i = 0; i < list.tagCount(); ++i)
{
NBTTagCompound tag = list.getCompoundTagAt(i);
StorageItem item = createItemFromNBT(tag);
if (item.compare(stack, flags))
{
if (quantity > item.getQuantity())
{
quantity = item.getQuantity();
}
tag.setInteger(NBT_ITEM_QUANTITY, item.getQuantity() - quantity);
if (item.getQuantity() - quantity == 0)
{
list.removeTag(i);
}
cell.getTagCompound().setInteger(NBT_STORED, ItemStorageCell.getStored(cell) - quantity);
ItemStack newItem = item.toItemStack();
newItem.stackSize = quantity;
return newItem;
}
}
return null;
}
@Override
public boolean canPush(ItemStack stack)
{
if (ItemStorageCell.getCapacity(cell) == -1)
{
return true;
}
return (ItemStorageCell.getStored(cell) + stack.stackSize) <= ItemStorageCell.getCapacity(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);
}
}

View File

@@ -1,191 +1,191 @@
package storagecraft.storage;
import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import storagecraft.util.InventoryUtils;
public class StorageItem
{
private Item type;
private int quantity;
private int damage;
private NBTTagCompound tag;
@SideOnly(Side.CLIENT)
private int id;
public StorageItem(ByteBuf buf)
{
this.id = buf.readInt();
this.type = Item.getItemById(buf.readInt());
this.quantity = buf.readInt();
this.damage = buf.readInt();
this.tag = buf.readBoolean() ? ByteBufUtils.readTag(buf) : null;
}
public StorageItem(Item type, int quantity, int damage, NBTTagCompound tag)
{
this.type = type;
this.quantity = quantity;
this.damage = damage;
this.tag = tag;
}
public StorageItem(Item type, int quantity, int damage, NBTTagCompound tag, int id)
{
this(type, quantity, damage, tag);
this.id = id;
}
public StorageItem(ItemStack stack)
{
this(stack.getItem(), stack.stackSize, stack.getItemDamage(), stack.stackTagCompound);
}
public void toBytes(ByteBuf buf, int id)
{
buf.writeInt(id);
buf.writeInt(Item.getIdFromItem(type));
buf.writeInt(quantity);
buf.writeInt(damage);
buf.writeBoolean(tag != null);
if (tag != null)
{
ByteBufUtils.writeTag(buf, tag);
}
}
public Item getType()
{
return type;
}
public int getQuantity()
{
return quantity;
}
public void setQuantity(int quantity)
{
this.quantity = quantity;
}
public int getDamage()
{
return damage;
}
public void setDamage(int damage)
{
this.damage = damage;
}
public NBTTagCompound getTag()
{
return tag;
}
public void setTag(NBTTagCompound tag)
{
this.tag = tag;
}
@SideOnly(Side.CLIENT)
public int getId()
{
return id;
}
public StorageItem copy()
{
return copy(quantity);
}
public StorageItem copy(int newQuantity)
{
return new StorageItem(type, newQuantity, damage, tag);
}
public ItemStack toItemStack()
{
ItemStack stack = new ItemStack(type, quantity, damage);
stack.stackTagCompound = tag;
return stack;
}
public boolean compare(StorageItem other, int flags)
{
if ((flags & InventoryUtils.COMPARE_DAMAGE) == InventoryUtils.COMPARE_DAMAGE)
{
if (damage != other.getDamage())
{
return false;
}
}
if ((flags & InventoryUtils.COMPARE_NBT) == InventoryUtils.COMPARE_NBT)
{
if (tag != null && !tag.equals(other.getTag()))
{
return false;
}
}
if ((flags & InventoryUtils.COMPARE_QUANTITY) == InventoryUtils.COMPARE_QUANTITY)
{
if (quantity != other.getQuantity())
{
return false;
}
}
return type == other.getType();
}
public boolean compare(ItemStack stack, int flags)
{
if ((flags & InventoryUtils.COMPARE_DAMAGE) == InventoryUtils.COMPARE_DAMAGE)
{
if (damage != stack.getItemDamage())
{
return false;
}
}
if ((flags & InventoryUtils.COMPARE_NBT) == InventoryUtils.COMPARE_NBT)
{
if (tag != null && !tag.equals(stack.stackTagCompound))
{
return false;
}
}
if ((flags & InventoryUtils.COMPARE_QUANTITY) == InventoryUtils.COMPARE_QUANTITY)
{
if (quantity != stack.stackSize)
{
return false;
}
}
return type == stack.getItem();
}
public boolean compareNoQuantity(StorageItem other)
{
return compare(other, InventoryUtils.COMPARE_NBT | InventoryUtils.COMPARE_DAMAGE);
}
public boolean compareNoQuantity(ItemStack stack)
{
return compare(stack, InventoryUtils.COMPARE_NBT | InventoryUtils.COMPARE_DAMAGE);
}
}
package storagecraft.storage;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import storagecraft.util.InventoryUtils;
public class StorageItem
{
private Item type;
private int quantity;
private int damage;
private NBTTagCompound tag;
@SideOnly(Side.CLIENT)
private int id;
public StorageItem(ByteBuf buf)
{
this.id = buf.readInt();
this.type = Item.getItemById(buf.readInt());
this.quantity = buf.readInt();
this.damage = buf.readInt();
this.tag = buf.readBoolean() ? ByteBufUtils.readTag(buf) : null;
}
public StorageItem(Item type, int quantity, int damage, NBTTagCompound tag)
{
this.type = type;
this.quantity = quantity;
this.damage = damage;
this.tag = tag;
}
public StorageItem(Item type, int quantity, int damage, NBTTagCompound tag, int id)
{
this(type, quantity, damage, tag);
this.id = id;
}
public StorageItem(ItemStack stack)
{
this(stack.getItem(), stack.stackSize, stack.getItemDamage(), stack.getTagCompound());
}
public void toBytes(ByteBuf buf, int id)
{
buf.writeInt(id);
buf.writeInt(Item.getIdFromItem(type));
buf.writeInt(quantity);
buf.writeInt(damage);
buf.writeBoolean(tag != null);
if (tag != null)
{
ByteBufUtils.writeTag(buf, tag);
}
}
public Item getType()
{
return type;
}
public int getQuantity()
{
return quantity;
}
public void setQuantity(int quantity)
{
this.quantity = quantity;
}
public int getDamage()
{
return damage;
}
public void setDamage(int damage)
{
this.damage = damage;
}
public NBTTagCompound getTag()
{
return tag;
}
public void setTag(NBTTagCompound tag)
{
this.tag = tag;
}
@SideOnly(Side.CLIENT)
public int getId()
{
return id;
}
public StorageItem copy()
{
return copy(quantity);
}
public StorageItem copy(int newQuantity)
{
return new StorageItem(type, newQuantity, damage, tag);
}
public ItemStack toItemStack()
{
ItemStack stack = new ItemStack(type, quantity, damage);
stack.setTagCompound(tag);
return stack;
}
public boolean compare(StorageItem other, int flags)
{
if ((flags & InventoryUtils.COMPARE_DAMAGE) == InventoryUtils.COMPARE_DAMAGE)
{
if (damage != other.getDamage())
{
return false;
}
}
if ((flags & InventoryUtils.COMPARE_NBT) == InventoryUtils.COMPARE_NBT)
{
if (tag != null && !tag.equals(other.getTag()))
{
return false;
}
}
if ((flags & InventoryUtils.COMPARE_QUANTITY) == InventoryUtils.COMPARE_QUANTITY)
{
if (quantity != other.getQuantity())
{
return false;
}
}
return type == other.getType();
}
public boolean compare(ItemStack stack, int flags)
{
if ((flags & InventoryUtils.COMPARE_DAMAGE) == InventoryUtils.COMPARE_DAMAGE)
{
if (damage != stack.getItemDamage())
{
return false;
}
}
if ((flags & InventoryUtils.COMPARE_NBT) == InventoryUtils.COMPARE_NBT)
{
if (tag != null && !tag.equals(stack.getTagCompound()))
{
return false;
}
}
if ((flags & InventoryUtils.COMPARE_QUANTITY) == InventoryUtils.COMPARE_QUANTITY)
{
if (quantity != stack.stackSize)
{
return false;
}
}
return type == stack.getItem();
}
public boolean compareNoQuantity(StorageItem other)
{
return compare(other, InventoryUtils.COMPARE_NBT | InventoryUtils.COMPARE_DAMAGE);
}
public boolean compareNoQuantity(ItemStack stack)
{
return compare(stack, InventoryUtils.COMPARE_NBT | InventoryUtils.COMPARE_DAMAGE);
}
}