|
1 | 1 | package github.kasuminova.novaeng.client.util; |
2 | 2 |
|
| 3 | +import com.github.bsideup.jabel.Desugar; |
3 | 4 | import crafttweaker.api.item.IItemStack; |
4 | 5 | import crafttweaker.api.minecraft.CraftTweakerMC; |
5 | 6 | import github.kasuminova.novaeng.NovaEngineeringCore; |
|
12 | 13 | import ink.ikx.rt.impl.mods.jei.impl.core.MCJeiPanel; |
13 | 14 | import ink.ikx.rt.impl.mods.jei.impl.core.MCJeiRecipe; |
14 | 15 | import net.minecraft.client.resources.I18n; |
| 16 | +import net.minecraft.item.Item; |
15 | 17 | import net.minecraft.item.ItemStack; |
| 18 | +import net.minecraft.nbt.NBTTagCompound; |
16 | 19 | import net.minecraftforge.fml.relauncher.Side; |
17 | 20 | import net.minecraftforge.fml.relauncher.SideOnly; |
18 | 21 |
|
19 | | -import java.util.Arrays; |
20 | | -import java.util.List; |
21 | | -import java.util.Objects; |
| 22 | +import java.util.*; |
22 | 23 |
|
23 | 24 | @SideOnly(Side.CLIENT) |
24 | 25 | public class ExJEI{ |
@@ -51,12 +52,44 @@ public static void jeiCreate() { |
51 | 52 | } |
52 | 53 |
|
53 | 54 | public static void jeiRecipeRegister() { |
| 55 | + Map<SimpleItem, ItemStack> uniqueKeys = new HashMap<>(); |
| 56 | + |
54 | 57 | UuGraph.iterator().forEachRemaining(item -> { |
55 | 58 | 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 | + } |
59 | 67 | } |
60 | 68 | }); |
| 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 | + } |
61 | 94 | } |
62 | 95 | } |
0 commit comments