aboutsummaryrefslogtreecommitdiff
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
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>
-rw-r--r--src/main/java/gregtech/api/util/GTUtility.java58
-rw-r--r--src/main/java/kubatech/api/DynamicInventory.java22
-rw-r--r--src/main/java/kubatech/api/EIGDynamicInventory.java8
-rw-r--r--src/main/java/kubatech/api/helpers/GTHelper.java17
-rw-r--r--src/main/java/kubatech/loaders/TCLoader.java11
-rw-r--r--src/main/java/kubatech/tileentity/gregtech/multiblock/MTEMegaIndustrialApiary.java18
6 files changed, 84 insertions, 50 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;
}
diff --git a/src/main/java/kubatech/api/DynamicInventory.java b/src/main/java/kubatech/api/DynamicInventory.java
index ef89c3a341..f718101384 100644
--- a/src/main/java/kubatech/api/DynamicInventory.java
+++ b/src/main/java/kubatech/api/DynamicInventory.java
@@ -34,8 +34,8 @@ import com.gtnewhorizons.modularui.common.widget.ChangeableWidget;
import com.gtnewhorizons.modularui.common.widget.DynamicPositionedRow;
import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget;
import com.gtnewhorizons.modularui.common.widget.Scrollable;
-import com.kuba6000.mobsinfo.api.utils.ItemID;
+import gregtech.api.util.GTUtility.ItemId;
import kubatech.api.helpers.GTHelper;
import kubatech.api.utils.ModUtils;
@@ -117,19 +117,19 @@ public class DynamicInventory<T> {
}
}), builder)
.attachSyncer(new FakeSyncWidget.ListSyncer<>(() -> {
- HashMap<ItemID, Integer> itemMap = new HashMap<>();
- HashMap<ItemID, ItemStack> stackMap = new HashMap<>();
- HashMap<ItemID, ArrayList<Integer>> realSlotMap = new HashMap<>();
+ HashMap<ItemId, Integer> itemMap = new HashMap<>();
+ HashMap<ItemId, ItemStack> stackMap = new HashMap<>();
+ HashMap<ItemId, ArrayList<Integer>> realSlotMap = new HashMap<>();
for (int i = 0, mStorageSize = inventory.size(); i < mStorageSize; i++) {
ItemStack stack = inventoryGetter.get(inventory.get(i));
- ItemID id = ItemID.createNoCopy(stack, false);
+ ItemId id = ItemId.createNoCopyWithStackSize(stack);
itemMap.merge(id, 1, Integer::sum);
stackMap.putIfAbsent(id, stack);
realSlotMap.computeIfAbsent(id, unused -> new ArrayList<>())
.add(i);
}
List<GTHelper.StackableItemSlot> newDrawables = new ArrayList<>();
- for (Map.Entry<ItemID, Integer> entry : itemMap.entrySet()) {
+ for (Map.Entry<ItemId, Integer> entry : itemMap.entrySet()) {
newDrawables.add(
new GTHelper.StackableItemSlot(
entry.getValue(),
@@ -172,19 +172,19 @@ public class DynamicInventory<T> {
ArrayList<Widget> buttons = new ArrayList<>();
if (!ModUtils.isClientThreaded()) {
- HashMap<ItemID, Integer> itemMap = new HashMap<>();
- HashMap<ItemID, ItemStack> stackMap = new HashMap<>();
- HashMap<ItemID, ArrayList<Integer>> realSlotMap = new HashMap<>();
+ HashMap<ItemId, Integer> itemMap = new HashMap<>();
+ HashMap<ItemId, ItemStack> stackMap = new HashMap<>();
+ HashMap<ItemId, ArrayList<Integer>> realSlotMap = new HashMap<>();
for (int i = 0, inventorySize = inventory.size(); i < inventorySize; i++) {
ItemStack stack = inventoryGetter.get(inventory.get(i));
- ItemID id = ItemID.createNoCopy(stack, false);
+ ItemId id = ItemId.createNoCopyWithStackSize(stack);
itemMap.merge(id, 1, Integer::sum);
stackMap.putIfAbsent(id, stack);
realSlotMap.computeIfAbsent(id, unused -> new ArrayList<>())
.add(i);
}
drawables = new ArrayList<>();
- for (Map.Entry<ItemID, Integer> entry : itemMap.entrySet()) {
+ for (Map.Entry<ItemId, Integer> entry : itemMap.entrySet()) {
drawables.add(
new GTHelper.StackableItemSlot(
entry.getValue(),
diff --git a/src/main/java/kubatech/api/EIGDynamicInventory.java b/src/main/java/kubatech/api/EIGDynamicInventory.java
index 1c703fe2fa..1b709a2654 100644
--- a/src/main/java/kubatech/api/EIGDynamicInventory.java
+++ b/src/main/java/kubatech/api/EIGDynamicInventory.java
@@ -3,7 +3,6 @@ package kubatech.api;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
@@ -33,7 +32,6 @@ import com.gtnewhorizons.modularui.common.widget.ChangeableWidget;
import com.gtnewhorizons.modularui.common.widget.DynamicPositionedRow;
import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget;
import com.gtnewhorizons.modularui.common.widget.Scrollable;
-import com.kuba6000.mobsinfo.api.utils.ItemID;
import kubatech.api.gui.AutoScalingStackSizeText;
import kubatech.api.helpers.GTHelper;
@@ -205,9 +203,6 @@ public class EIGDynamicInventory<T> {
ArrayList<Widget> buttons = new ArrayList<>();
if (!ModUtils.isClientThreaded()) {
- HashMap<ItemID, Integer> itemMap = new HashMap<>();
- HashMap<ItemID, ItemStack> stackMap = new HashMap<>();
- HashMap<ItemID, ArrayList<Integer>> realSlotMap = new HashMap<>();
drawables = new ArrayList<>();
for (int i = 0, inventorySize = inventory.size(); i < inventorySize; i++) {
T slot = inventory.get(i);
@@ -215,8 +210,7 @@ public class EIGDynamicInventory<T> {
continue;
}
ItemStack stack = inventoryGetter.get(slot);
- drawables
- .add(new GTHelper.StackableItemSlot(1, stack, new ArrayList<Integer>(Collections.singleton(i))));
+ drawables.add(new GTHelper.StackableItemSlot(1, stack, new ArrayList<>(Collections.singleton(i))));
}
}
diff --git a/src/main/java/kubatech/api/helpers/GTHelper.java b/src/main/java/kubatech/api/helpers/GTHelper.java
index fe6a2a6167..645cd49356 100644
--- a/src/main/java/kubatech/api/helpers/GTHelper.java
+++ b/src/main/java/kubatech/api/helpers/GTHelper.java
@@ -28,16 +28,15 @@ import java.util.ArrayList;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
-import com.kuba6000.mobsinfo.api.utils.ItemID;
-
import gregtech.api.metatileentity.implementations.MTEHatchEnergy;
import gregtech.api.metatileentity.implementations.MTEMultiBlockBase;
+import gregtech.api.util.GTUtility.ItemId;
import kubatech.api.implementations.KubaTechGTMultiBlockBase;
public class GTHelper {
public static long getMaxInputEU(MTEMultiBlockBase mte) {
- if (mte instanceof KubaTechGTMultiBlockBase) return ((KubaTechGTMultiBlockBase<?>) mte).getMaxInputEu();
+ if (mte instanceof KubaTechGTMultiBlockBase) return mte.getMaxInputEu();
long rEU = 0;
for (MTEHatchEnergy tHatch : mte.mEnergyHatches)
if (tHatch.isValid()) rEU += tHatch.maxEUInput() * tHatch.maxAmperesIn();
@@ -65,11 +64,14 @@ public class GTHelper {
public StackableItemSlot(int count, ItemStack stack, ArrayList<Integer> realSlots) {
this.count = count;
this.stack = stack;
+ this.hashcode = ItemId.createNoCopyWithStackSize(stack)
+ .hashCode();
this.realSlots = realSlots;
}
public final int count;
public final ItemStack stack;
+ private final int hashcode;
public final ArrayList<Integer> realSlots;
public void write(PacketBuffer buffer) throws IOException {
@@ -87,13 +89,8 @@ public class GTHelper {
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
- if (!(obj instanceof StackableItemSlot)) return false;
- StackableItemSlot other = (StackableItemSlot) obj;
- return count == other.count && ItemID.createNoCopy(stack, false)
- .hashCode()
- == ItemID.createNoCopy(other.stack, false)
- .hashCode()
- && realSlots.equals(other.realSlots);
+ if (!(obj instanceof StackableItemSlot other)) return false;
+ return count == other.count && hashcode == other.hashcode && realSlots.equals(other.realSlots);
}
}
}
diff --git a/src/main/java/kubatech/loaders/TCLoader.java b/src/main/java/kubatech/loaders/TCLoader.java
index 500dab7f3e..75113eccb8 100644
--- a/src/main/java/kubatech/loaders/TCLoader.java
+++ b/src/main/java/kubatech/loaders/TCLoader.java
@@ -32,9 +32,8 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
-import com.kuba6000.mobsinfo.api.utils.ItemID;
-
import cpw.mods.fml.common.registry.GameRegistry;
+import gregtech.api.util.GTUtility.ItemId;
import kubatech.api.enums.ItemList;
import kubatech.loaders.item.items.ItemTeaUltimate;
import thaumcraft.api.ThaumcraftApi;
@@ -84,8 +83,8 @@ public class TCLoader {
ItemList.MilkTea.get(1), ItemList.OolongTea.get(1), ItemList.PeppermintTea.get(1), ItemList.PuerhTea.get(1),
ItemList.WhiteTea.get(1), ItemList.YellowTea.get(1) };
- final HashSet<ItemID> componentsHashed = Arrays.stream(components)
- .map(stack -> ItemID.createNoCopy(stack, true, false, true))
+ final HashSet<ItemId> componentsHashed = Arrays.stream(components)
+ .map(ItemId::createWithoutNBT)
.collect(Collectors.toCollection(HashSet::new));
// noinspection unchecked
@@ -109,8 +108,8 @@ public class TCLoader {
if (!ThaumcraftApiHelper.isResearchComplete(player.getCommandSenderName(), this.research))
return false;
if (componentsHashed.size() > input.size()) return false;
- HashSet<ItemID> hashedInputs = input.stream()
- .map(stack -> ItemID.createNoCopy(stack, true, false, true))
+ HashSet<ItemId> hashedInputs = input.stream()
+ .map(ItemId::createWithoutNBT)
.collect(Collectors.toCollection(HashSet::new));
return hashedInputs.containsAll(componentsHashed);
}
diff --git a/src/main/java/kubatech/tileentity/gregtech/multiblock/MTEMegaIndustrialApiary.java b/src/main/java/kubatech/tileentity/gregtech/multiblock/MTEMegaIndustrialApiary.java
index 0ea03b9407..6a8f34e2da 100644
--- a/src/main/java/kubatech/tileentity/gregtech/multiblock/MTEMegaIndustrialApiary.java
+++ b/src/main/java/kubatech/tileentity/gregtech/multiblock/MTEMegaIndustrialApiary.java
@@ -92,7 +92,6 @@ import com.gtnewhorizons.modularui.common.widget.DynamicPositionedRow;
import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget;
import com.gtnewhorizons.modularui.common.widget.SlotWidget;
import com.gtnewhorizons.modularui.common.widget.TextWidget;
-import com.kuba6000.mobsinfo.api.utils.ItemID;
import bartworks.API.BorosilicateGlass;
import cpw.mods.fml.relauncher.Side;
@@ -121,6 +120,7 @@ import gregtech.api.recipe.check.CheckRecipeResultRegistry;
import gregtech.api.recipe.check.SimpleCheckRecipeResult;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GTUtility;
+import gregtech.api.util.GTUtility.ItemId;
import gregtech.api.util.MultiblockTooltipBuilder;
import ic2.core.init.BlocksItems;
import ic2.core.init.InternalName;
@@ -927,13 +927,13 @@ public class MTEMegaIndustrialApiary extends KubaTechGTMultiBlockBase<MTEMegaInd
screenElements.widget(new FakeSyncWidget.IntegerSyncer(() -> mSecondaryMode, b -> mSecondaryMode = b));
screenElements.widget(new FakeSyncWidget<>(() -> {
HashMap<ItemStack, Double> ret = new HashMap<>();
- HashMap<ItemID, Double> dropProgress = new HashMap<>();
+ HashMap<ItemId, Double> dropProgress = new HashMap<>();
- for (Map.Entry<ItemID, Double> drop : this.dropProgress.entrySet()) {
+ for (Map.Entry<ItemId, Double> drop : this.dropProgress.entrySet()) {
dropProgress.merge(drop.getKey(), drop.getValue(), Double::sum);
}
- for (Map.Entry<ItemID, Double> drop : dropProgress.entrySet()) {
+ for (Map.Entry<ItemId, Double> drop : dropProgress.entrySet()) {
ret.put(BeeSimulator.dropstacks.get(drop.getKey()), drop.getValue());
}
return ret;
@@ -962,7 +962,7 @@ public class MTEMegaIndustrialApiary extends KubaTechGTMultiBlockBase<MTEMegaInd
super.drawTexts(screenElements, inventorySlot);
}
- final HashMap<ItemID, Double> dropProgress = new HashMap<>();
+ final HashMap<ItemId, Double> dropProgress = new HashMap<>();
private static class BeeSimulator {
@@ -1058,7 +1058,7 @@ public class MTEMegaIndustrialApiary extends KubaTechGTMultiBlockBase<MTEMegaInd
return tag;
}
- static final Map<ItemID, ItemStack> dropstacks = new HashMap<>();
+ static final Map<ItemId, ItemStack> dropstacks = new HashMap<>();
public List<ItemStack> getDrops(final MTEMegaIndustrialApiary MTE, final double timePassed) {
drops.forEach(d -> {
@@ -1103,7 +1103,7 @@ public class MTEMegaIndustrialApiary extends KubaTechGTMultiBlockBase<MTEMegaInd
private static final float MAX_PRODUCTION_MODIFIER_FROM_UPGRADES = 17.19926784f; // 4*1.2^8
final ItemStack stack;
double amount;
- final ItemID id;
+ final ItemId id;
final float chance;
final float beeSpeed;
@@ -1114,7 +1114,7 @@ public class MTEMegaIndustrialApiary extends KubaTechGTMultiBlockBase<MTEMegaInd
this.chance = chance;
this.beeSpeed = beeSpeed;
this.t = t;
- id = ItemID.createNoCopy(this.stack);
+ id = ItemId.createNoCopy(this.stack);
evaluate();
}
@@ -1150,7 +1150,7 @@ public class MTEMegaIndustrialApiary extends KubaTechGTMultiBlockBase<MTEMegaInd
beeSpeed = tag.getFloat("beeSpeed");
t = tag.getFloat("t");
amount = tag.getDouble("amount");
- id = ItemID.createNoCopy(stack);
+ id = ItemId.createNoCopy(stack);
}
public NBTTagCompound toNBTTagCompound() {