aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api
diff options
context:
space:
mode:
authorJakub <53441451+kuba6000@users.noreply.github.com>2024-09-04 21:45:17 +0200
committerGitHub <noreply@github.com>2024-09-04 19:45:17 +0000
commit5b5311ab6cda52d33d60c23effad8a1f811e2f0f (patch)
tree1ac998acc0d1f4b0ac3a6cb8a5ba94ef964c11c4 /src/main/java/gregtech/api
parentd00d97c5fd41f8c4751249674452425aaad2d5f7 (diff)
downloadGT5-Unofficial-5b5311ab6cda52d33d60c23effad8a1f811e2f0f.tar.gz
GT5-Unofficial-5b5311ab6cda52d33d60c23effad8a1f811e2f0f.tar.bz2
GT5-Unofficial-5b5311ab6cda52d33d60c23effad8a1f811e2f0f.zip
Remove hard dep on mobs-info (#3053)
Co-authored-by: Martin Robertz <dream-master@gmx.net>
Diffstat (limited to 'src/main/java/gregtech/api')
-rw-r--r--src/main/java/gregtech/api/util/GTUtility.java58
1 files changed, 51 insertions, 7 deletions
diff --git a/src/main/java/gregtech/api/util/GTUtility.java b/src/main/java/gregtech/api/util/GTUtility.java
index 08a1711b97..8eeb71753e 100644
--- a/src/main/java/gregtech/api/util/GTUtility.java
+++ b/src/main/java/gregtech/api/util/GTUtility.java
@@ -4741,7 +4741,8 @@ public class GTUtility {
return new AutoValue_GTUtility_ItemId(
Item.getItemById(tag.getShort("item")),
tag.getShort("meta"),
- tag.hasKey("tag", Constants.NBT.TAG_COMPOUND) ? tag.getCompoundTag("tag") : null);
+ tag.hasKey("tag", Constants.NBT.TAG_COMPOUND) ? tag.getCompoundTag("tag") : null,
+ tag.hasKey("stackSize", Constants.NBT.TAG_INT) ? tag.getInteger("stackSize") : null);
}
/**
@@ -4753,7 +4754,23 @@ public class GTUtility {
nbt = (NBTTagCompound) nbt.copy();
}
- return new AutoValue_GTUtility_ItemId(itemStack.getItem(), Items.feather.getDamage(itemStack), nbt);
+ return new AutoValue_GTUtility_ItemId(itemStack.getItem(), Items.feather.getDamage(itemStack), nbt, null);
+ }
+
+ /**
+ * This method copies NBT, as it is mutable.
+ */
+ public static ItemId createWithStackSize(ItemStack itemStack) {
+ NBTTagCompound nbt = itemStack.getTagCompound();
+ if (nbt != null) {
+ nbt = (NBTTagCompound) nbt.copy();
+ }
+
+ return new AutoValue_GTUtility_ItemId(
+ itemStack.getItem(),
+ Items.feather.getDamage(itemStack),
+ nbt,
+ itemStack.stackSize);
}
/**
@@ -4763,21 +4780,32 @@ public class GTUtility {
if (nbt != null) {
nbt = (NBTTagCompound) nbt.copy();
}
- return new AutoValue_GTUtility_ItemId(item, metaData, nbt);
+ return new AutoValue_GTUtility_ItemId(item, metaData, nbt, null);
+ }
+
+ /**
+ * This method copies NBT, as it is mutable.
+ */
+ public static ItemId create(Item item, int metaData, @Nullable NBTTagCompound nbt,
+ @Nullable Integer stackSize) {
+ if (nbt != null) {
+ nbt = (NBTTagCompound) nbt.copy();
+ }
+ return new AutoValue_GTUtility_ItemId(item, metaData, nbt, stackSize);
}
/**
* This method stores metadata as wildcard and NBT as null.
*/
public static ItemId createAsWildcard(ItemStack itemStack) {
- return new AutoValue_GTUtility_ItemId(itemStack.getItem(), W, null);
+ return new AutoValue_GTUtility_ItemId(itemStack.getItem(), W, null, null);
}
/**
* This method stores NBT as null.
*/
public static ItemId createWithoutNBT(ItemStack itemStack) {
- return new AutoValue_GTUtility_ItemId(itemStack.getItem(), Items.feather.getDamage(itemStack), null);
+ return new AutoValue_GTUtility_ItemId(itemStack.getItem(), Items.feather.getDamage(itemStack), null, null);
}
/**
@@ -4787,14 +4815,26 @@ public class GTUtility {
return new AutoValue_GTUtility_ItemId(
itemStack.getItem(),
Items.feather.getDamage(itemStack),
- itemStack.getTagCompound());
+ itemStack.getTagCompound(),
+ null);
+ }
+
+ /**
+ * This method does not copy NBT in order to save time. Make sure not to mutate it!
+ */
+ public static ItemId createNoCopyWithStackSize(ItemStack itemStack) {
+ return new AutoValue_GTUtility_ItemId(
+ itemStack.getItem(),
+ Items.feather.getDamage(itemStack),
+ itemStack.getTagCompound(),
+ itemStack.stackSize);
}
/**
* This method does not copy NBT in order to save time. Make sure not to mutate it!
*/
public static ItemId createNoCopy(Item item, int metaData, @Nullable NBTTagCompound nbt) {
- return new AutoValue_GTUtility_ItemId(item, metaData, nbt);
+ return new AutoValue_GTUtility_ItemId(item, metaData, nbt, null);
}
protected abstract Item item();
@@ -4804,11 +4844,15 @@ public class GTUtility {
@Nullable
protected abstract NBTTagCompound nbt();
+ @Nullable
+ protected abstract Integer stackSize();
+
public NBTTagCompound writeToNBT() {
NBTTagCompound tag = new NBTTagCompound();
tag.setShort("item", (short) Item.getIdFromItem(item()));
tag.setShort("meta", (short) metaData());
if (nbt() != null) tag.setTag("tag", nbt());
+ if (stackSize() != null) tag.setInteger("stackSize", stackSize());
return tag;
}