Separate metadata of a itemgroup from the itemgroup
This commit is contained in:
@@ -92,7 +92,7 @@ public class GuiGrid extends GuiBase {
|
|||||||
while (t.hasNext()) {
|
while (t.hasNext()) {
|
||||||
ItemGroup group = t.next();
|
ItemGroup group = t.next();
|
||||||
|
|
||||||
if (!group.toItemStack().getDisplayName().toLowerCase().contains(searchField.getText().toLowerCase())) {
|
if (!group.toStack().getDisplayName().toLowerCase().contains(searchField.getText().toLowerCase())) {
|
||||||
t.remove();
|
t.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -102,9 +102,9 @@ public class GuiGrid extends GuiBase {
|
|||||||
@Override
|
@Override
|
||||||
public int compare(ItemGroup left, ItemGroup right) {
|
public int compare(ItemGroup left, ItemGroup right) {
|
||||||
if (grid.getSortingDirection() == TileGrid.SORTING_DIRECTION_ASCENDING) {
|
if (grid.getSortingDirection() == TileGrid.SORTING_DIRECTION_ASCENDING) {
|
||||||
return right.toItemStack().getDisplayName().compareTo(left.toItemStack().getDisplayName());
|
return right.toStack().getDisplayName().compareTo(left.toStack().getDisplayName());
|
||||||
} else if (grid.getSortingDirection() == TileGrid.SORTING_DIRECTION_DESCENDING) {
|
} else if (grid.getSortingDirection() == TileGrid.SORTING_DIRECTION_DESCENDING) {
|
||||||
return left.toItemStack().getDisplayName().compareTo(right.toItemStack().getDisplayName());
|
return left.toStack().getDisplayName().compareTo(right.toStack().getDisplayName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -251,7 +251,7 @@ public class GuiGrid extends GuiBase {
|
|||||||
text = String.valueOf(qty);
|
text = String.valueOf(qty);
|
||||||
}
|
}
|
||||||
|
|
||||||
drawItem(x, y, items.get(slot).toItemStack(), true, text);
|
drawItem(x, y, items.get(slot).toStack(), true, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inBounds(x, y, 16, 16, mouseX, mouseY) || !grid.isConnected()) {
|
if (inBounds(x, y, 16, 16, mouseX, mouseY) || !grid.isConnected()) {
|
||||||
@@ -279,7 +279,7 @@ public class GuiGrid extends GuiBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isHoveringOverItemInSlot()) {
|
if (isHoveringOverItemInSlot()) {
|
||||||
drawTooltip(mouseX, mouseY, items.get(hoveringSlot).toItemStack());
|
drawTooltip(mouseX, mouseY, items.get(hoveringSlot).toStack());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isHoveringOverClear(mouseX, mouseY)) {
|
if (isHoveringOverClear(mouseX, mouseY)) {
|
||||||
|
|||||||
@@ -3,50 +3,49 @@ package refinedstorage.storage;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
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.minecraftforge.fml.common.network.ByteBufUtils;
|
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||||
import refinedstorage.RefinedStorageUtils;
|
import refinedstorage.RefinedStorageUtils;
|
||||||
|
|
||||||
public class ItemGroup {
|
public class ItemGroup {
|
||||||
private Item type;
|
private ItemGroupMeta meta;
|
||||||
private int quantity;
|
private int quantity;
|
||||||
private int damage;
|
// Used clientside
|
||||||
private NBTTagCompound tag;
|
|
||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
public ItemGroup(ByteBuf buf) {
|
public ItemGroup(ByteBuf buf) {
|
||||||
this.id = buf.readInt();
|
this.id = buf.readInt();
|
||||||
this.type = Item.getItemById(buf.readInt());
|
this.meta = new ItemGroupMeta(
|
||||||
|
Item.getItemById(buf.readInt()),
|
||||||
|
buf.readInt(),
|
||||||
|
buf.readBoolean() ? ByteBufUtils.readTag(buf) : null
|
||||||
|
);
|
||||||
this.quantity = buf.readInt();
|
this.quantity = buf.readInt();
|
||||||
this.damage = buf.readInt();
|
|
||||||
this.tag = buf.readBoolean() ? ByteBufUtils.readTag(buf) : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemGroup(Item type, int quantity, int damage, NBTTagCompound tag) {
|
public ItemGroup(ItemGroupMeta meta, int quantity) {
|
||||||
this.type = type;
|
this.meta = meta;
|
||||||
this.quantity = quantity;
|
this.quantity = quantity;
|
||||||
this.damage = damage;
|
|
||||||
this.tag = tag;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemGroup(ItemStack stack) {
|
public ItemGroup(ItemStack stack) {
|
||||||
this(stack.getItem(), stack.stackSize, stack.getItemDamage(), stack.getTagCompound());
|
this(new ItemGroupMeta(stack), stack.stackSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toBytes(ByteBuf buf, int id) {
|
public void toBytes(ByteBuf buf, int id) {
|
||||||
buf.writeInt(id);
|
buf.writeInt(id);
|
||||||
buf.writeInt(Item.getIdFromItem(type));
|
buf.writeInt(Item.getIdFromItem(meta.getType()));
|
||||||
buf.writeInt(quantity);
|
buf.writeInt(meta.getDamage());
|
||||||
buf.writeInt(damage);
|
buf.writeBoolean(meta.hasTag());
|
||||||
buf.writeBoolean(tag != null);
|
|
||||||
|
|
||||||
if (tag != null) {
|
if (meta.hasTag()) {
|
||||||
ByteBufUtils.writeTag(buf, tag);
|
ByteBufUtils.writeTag(buf, meta.getTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buf.writeInt(quantity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Item getType() {
|
public ItemGroupMeta getMeta() {
|
||||||
return type;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getQuantity() {
|
public int getQuantity() {
|
||||||
@@ -57,22 +56,6 @@ public class ItemGroup {
|
|||||||
this.quantity = 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@@ -82,71 +65,31 @@ public class ItemGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ItemGroup copy(int newQuantity) {
|
public ItemGroup copy(int newQuantity) {
|
||||||
return new ItemGroup(type, newQuantity, damage, tag);
|
return new ItemGroup(meta, newQuantity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack toItemStack() {
|
public ItemStack toStack() {
|
||||||
ItemStack stack = new ItemStack(type, quantity, damage);
|
ItemStack stack = new ItemStack(meta.getType(), quantity, meta.getDamage());
|
||||||
|
|
||||||
stack.setTagCompound(tag);
|
stack.setTagCompound(meta.getTag());
|
||||||
|
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean compare(ItemGroup other, int flags) {
|
public boolean compare(ItemGroup other, int flags) {
|
||||||
if ((flags & RefinedStorageUtils.COMPARE_DAMAGE) == RefinedStorageUtils.COMPARE_DAMAGE) {
|
if ((flags & RefinedStorageUtils.COMPARE_QUANTITY) == RefinedStorageUtils.COMPARE_QUANTITY && other.getQuantity() != quantity) {
|
||||||
if (damage != other.getDamage()) {
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & RefinedStorageUtils.COMPARE_NBT) == RefinedStorageUtils.COMPARE_NBT) {
|
return meta.compare(other.getMeta(), flags);
|
||||||
if ((tag != null && other.getTag() == null) || (tag == null && other.getTag() != null)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tag != null && other.getTag() != null) {
|
|
||||||
if (!tag.equals(other.getTag())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((flags & RefinedStorageUtils.COMPARE_QUANTITY) == RefinedStorageUtils.COMPARE_QUANTITY) {
|
|
||||||
if (quantity != other.getQuantity()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return type == other.getType();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean compare(ItemStack stack, int flags) {
|
public boolean compare(ItemStack stack, int flags) {
|
||||||
if ((flags & RefinedStorageUtils.COMPARE_DAMAGE) == RefinedStorageUtils.COMPARE_DAMAGE) {
|
if ((flags & RefinedStorageUtils.COMPARE_QUANTITY) == RefinedStorageUtils.COMPARE_QUANTITY && stack.stackSize != quantity) {
|
||||||
if (damage != stack.getItemDamage()) {
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & RefinedStorageUtils.COMPARE_NBT) == RefinedStorageUtils.COMPARE_NBT) {
|
return meta.compare(stack, flags);
|
||||||
if ((tag != null && stack.getTagCompound() == null) || (tag == null && stack.getTagCompound() != null)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tag != null && stack.getTagCompound() != null) {
|
|
||||||
if (!tag.equals(stack.getTagCompound())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((flags & RefinedStorageUtils.COMPARE_QUANTITY) == RefinedStorageUtils.COMPARE_QUANTITY) {
|
|
||||||
if (quantity != stack.stackSize) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return type == stack.getItem();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean compareNoQuantity(ItemGroup other) {
|
public boolean compareNoQuantity(ItemGroup other) {
|
||||||
@@ -156,27 +99,4 @@ public class ItemGroup {
|
|||||||
public boolean compareNoQuantity(ItemStack stack) {
|
public boolean compareNoQuantity(ItemStack stack) {
|
||||||
return compare(stack, RefinedStorageUtils.COMPARE_NBT | RefinedStorageUtils.COMPARE_DAMAGE);
|
return compare(stack, RefinedStorageUtils.COMPARE_NBT | RefinedStorageUtils.COMPARE_DAMAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
|
|
||||||
ItemGroup itemGroup = (ItemGroup) o;
|
|
||||||
|
|
||||||
if (quantity != itemGroup.quantity) return false;
|
|
||||||
if (damage != itemGroup.damage) return false;
|
|
||||||
if (!type.equals(itemGroup.type)) return false;
|
|
||||||
return tag != null ? tag.equals(itemGroup.tag) : itemGroup.tag == null;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
int result = type.hashCode();
|
|
||||||
result = 31 * result + quantity;
|
|
||||||
result = 31 * result + damage;
|
|
||||||
result = 31 * result + (tag != null ? tag.hashCode() : 0);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
125
src/main/java/refinedstorage/storage/ItemGroupMeta.java
Executable file
125
src/main/java/refinedstorage/storage/ItemGroupMeta.java
Executable file
@@ -0,0 +1,125 @@
|
|||||||
|
package refinedstorage.storage;
|
||||||
|
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import refinedstorage.RefinedStorageUtils;
|
||||||
|
|
||||||
|
public class ItemGroupMeta {
|
||||||
|
private Item type;
|
||||||
|
private int damage;
|
||||||
|
private NBTTagCompound tag;
|
||||||
|
|
||||||
|
public ItemGroupMeta(Item type, int damage, NBTTagCompound tag) {
|
||||||
|
this.type = type;
|
||||||
|
this.damage = damage;
|
||||||
|
this.tag = tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemGroupMeta(ItemStack stack) {
|
||||||
|
this(stack.getItem(), stack.getItemDamage(), stack.getTagCompound());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Item getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(Item type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDamage() {
|
||||||
|
return damage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDamage(int damage) {
|
||||||
|
this.damage = damage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasTag() {
|
||||||
|
return tag != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NBTTagCompound getTag() {
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTag(NBTTagCompound tag) {
|
||||||
|
this.tag = tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean compare(ItemGroupMeta other, int flags) {
|
||||||
|
if (type != other.getType()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((flags & RefinedStorageUtils.COMPARE_DAMAGE) == RefinedStorageUtils.COMPARE_DAMAGE && damage != other.getDamage()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((flags & RefinedStorageUtils.COMPARE_NBT) == RefinedStorageUtils.COMPARE_NBT) {
|
||||||
|
if ((tag != null && other.getTag() == null) || (tag == null && other.getTag() != null)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag != null && other.getTag() != null) {
|
||||||
|
if (!tag.equals(other.getTag())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean compare(ItemStack stack, int flags) {
|
||||||
|
if (type != stack.getItem()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((flags & RefinedStorageUtils.COMPARE_DAMAGE) == RefinedStorageUtils.COMPARE_DAMAGE && damage != stack.getItemDamage()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((flags & RefinedStorageUtils.COMPARE_NBT) == RefinedStorageUtils.COMPARE_NBT) {
|
||||||
|
if ((tag != null && stack.getTagCompound() == null) || (tag == null && stack.getTagCompound() != null)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag != null && stack.getTagCompound() != null) {
|
||||||
|
if (!tag.equals(stack.getTagCompound())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
if (this == other) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (other == null || getClass() != other.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemGroupMeta meta = (ItemGroupMeta) other;
|
||||||
|
|
||||||
|
if (damage != meta.damage || !type.equals(meta.type)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return tag != null ? tag.equals(meta.tag) : meta.tag == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = type.hashCode();
|
||||||
|
result = 31 * result + damage;
|
||||||
|
result = 31 * result + (tag != null ? tag.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -90,7 +90,7 @@ public class NBTStorage implements IStorage {
|
|||||||
|
|
||||||
nbt.setInteger(NBT_STORED, getStored(nbt) - quantity);
|
nbt.setInteger(NBT_STORED, getStored(nbt) - quantity);
|
||||||
|
|
||||||
ItemStack newItem = group.toItemStack();
|
ItemStack newItem = group.toStack();
|
||||||
|
|
||||||
newItem.stackSize = quantity;
|
newItem.stackSize = quantity;
|
||||||
|
|
||||||
@@ -116,7 +116,13 @@ public class NBTStorage implements IStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ItemGroup createItemGroupFromNBT(NBTTagCompound tag) {
|
private ItemGroup createItemGroupFromNBT(NBTTagCompound tag) {
|
||||||
return new ItemGroup(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);
|
return new ItemGroup(
|
||||||
|
new ItemGroupMeta(
|
||||||
|
Item.getItemById(tag.getInteger(NBT_ITEM_TYPE)),
|
||||||
|
tag.getInteger(NBT_ITEM_DAMAGE),
|
||||||
|
tag.hasKey(NBT_ITEM_NBT) ? ((NBTTagCompound) tag.getTag(NBT_ITEM_NBT)) : null
|
||||||
|
), tag.getInteger(NBT_ITEM_QUANTITY)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getStored(NBTTagCompound tag) {
|
public static int getStored(NBTTagCompound tag) {
|
||||||
|
|||||||
@@ -338,7 +338,7 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the item doesn't exist anymore, remove it from storage to avoid crashes
|
// If the item doesn't exist anymore, remove it from storage to avoid crashes
|
||||||
if (group.getType() == null) {
|
if (group.getMeta().getType() == null) {
|
||||||
combinedGroups.add(i);
|
combinedGroups.add(i);
|
||||||
} else {
|
} else {
|
||||||
for (int j = i + 1; j < itemGroups.size(); ++j) {
|
for (int j = i + 1; j < itemGroups.size(); ++j) {
|
||||||
@@ -679,11 +679,11 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
|||||||
// NO OP, the quantity already set (64) is needed for shift
|
// NO OP, the quantity already set (64) is needed for shift
|
||||||
}
|
}
|
||||||
|
|
||||||
if (quantity > group.getType().getItemStackLimit(group.toItemStack())) {
|
if (quantity > group.getMeta().getType().getItemStackLimit(group.toStack())) {
|
||||||
quantity = group.getType().getItemStackLimit(group.toItemStack());
|
quantity = group.getMeta().getType().getItemStackLimit(group.toStack());
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack took = take(group.copy(quantity).toItemStack());
|
ItemStack took = take(group.copy(quantity).toStack());
|
||||||
|
|
||||||
if (took != null) {
|
if (took != null) {
|
||||||
if (GridPullFlags.isPullingWithShift(flags)) {
|
if (GridPullFlags.isPullingWithShift(flags)) {
|
||||||
@@ -747,7 +747,7 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
|||||||
|
|
||||||
public void onCraftingRequested(int id, int quantity) {
|
public void onCraftingRequested(int id, int quantity) {
|
||||||
if (id >= 0 && id < itemGroups.size() && quantity > 0 && quantity <= MAX_CRAFTING_QUANTITY_PER_REQUEST) {
|
if (id >= 0 && id < itemGroups.size() && quantity > 0 && quantity <= MAX_CRAFTING_QUANTITY_PER_REQUEST) {
|
||||||
ItemStack requested = itemGroups.get(id).toItemStack();
|
ItemStack requested = itemGroups.get(id).toStack();
|
||||||
int quantityPerRequest = 0;
|
int quantityPerRequest = 0;
|
||||||
CraftingPattern pattern = getPattern(requested);
|
CraftingPattern pattern = getPattern(requested);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user