Skip to content

Commit e93704c

Browse files
committed
修正复制机JEI的一些错误
1 parent 38a82a2 commit e93704c

File tree

1 file changed

+39
-6
lines changed
  • src/main/java/github/kasuminova/novaeng/client/util

1 file changed

+39
-6
lines changed

src/main/java/github/kasuminova/novaeng/client/util/ExJEI.java

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package github.kasuminova.novaeng.client.util;
22

3+
import com.github.bsideup.jabel.Desugar;
34
import crafttweaker.api.item.IItemStack;
45
import crafttweaker.api.minecraft.CraftTweakerMC;
56
import github.kasuminova.novaeng.NovaEngineeringCore;
@@ -12,13 +13,13 @@
1213
import ink.ikx.rt.impl.mods.jei.impl.core.MCJeiPanel;
1314
import ink.ikx.rt.impl.mods.jei.impl.core.MCJeiRecipe;
1415
import net.minecraft.client.resources.I18n;
16+
import net.minecraft.item.Item;
1517
import net.minecraft.item.ItemStack;
18+
import net.minecraft.nbt.NBTTagCompound;
1619
import net.minecraftforge.fml.relauncher.Side;
1720
import net.minecraftforge.fml.relauncher.SideOnly;
1821

19-
import java.util.Arrays;
20-
import java.util.List;
21-
import java.util.Objects;
22+
import java.util.*;
2223

2324
@SideOnly(Side.CLIENT)
2425
public class ExJEI{
@@ -51,12 +52,44 @@ public static void jeiCreate() {
5152
}
5253

5354
public static void jeiRecipeRegister() {
55+
Map<SimpleItem, ItemStack> uniqueKeys = new HashMap<>();
56+
5457
UuGraph.iterator().forEachRemaining(item -> {
5558
ItemStack stack = item.getKey().copy();
56-
if (item.getValue() != Double.POSITIVE_INFINITY && !blockList.contains(Objects.requireNonNull(stack.getItem().getRegistryName()).getNamespace())) {
57-
double bValue = item.getValue() / 100000;
58-
new MCJeiRecipe("replicator_jei").addInput(CraftTweakerMC.getIItemStack(stack)).addOutput(CraftTweakerMC.getIItemStack(stack)).addElement(IJeiUtils.createFontInfoElement(I18n.format("gui." + NovaEngineeringCore.MOD_ID + ".replicator.tooltips1",Util.toSiString(bValue, 2)), 0, 20, 0x000000, 0, 0)).build();
59+
60+
ItemStack canonicalKey = uniqueKeys.computeIfAbsent(SimpleItem.getInstance(stack), k -> stack);
61+
62+
if (stack == canonicalKey) {
63+
if (item.getValue() != Double.POSITIVE_INFINITY && !blockList.contains(Objects.requireNonNull(stack.getItem().getRegistryName()).getNamespace())) {
64+
double bValue = item.getValue() / 100000;
65+
new MCJeiRecipe("replicator_jei").addInput(CraftTweakerMC.getIItemStack(stack)).addOutput(CraftTweakerMC.getIItemStack(stack)).addElement(IJeiUtils.createFontInfoElement(I18n.format("gui." + NovaEngineeringCore.MOD_ID + ".replicator.tooltips1", Util.toSiString(bValue, 2)), 0, 20, 0x000000, 0, 0)).build();
66+
}
5967
}
6068
});
69+
70+
uniqueKeys.clear();
71+
}
72+
73+
@Desugar
74+
private record SimpleItem(Item item, int meta, NBTTagCompound nbt) {
75+
76+
public static SimpleItem getInstance(ItemStack stack) {
77+
return new SimpleItem(stack.getItem(), stack.getMetadata(), stack.getTagCompound());
78+
}
79+
80+
@Override
81+
public boolean equals(Object o) {
82+
if (o == null || getClass() != o.getClass()) return false;
83+
SimpleItem that = (SimpleItem) o;
84+
return meta == that.meta && Objects.equals(item, that.item) && Objects.equals(nbt, that.nbt);
85+
}
86+
87+
@Override
88+
public int hashCode() {
89+
int result = item.hashCode();
90+
result = 31 * result + meta;
91+
result = 31 * result + (nbt != null ? nbt.hashCode() : 0);
92+
return result;
93+
}
6194
}
6295
}

0 commit comments

Comments
 (0)