Skip to content

Commit

Permalink
Use singleton EmptyMapMarkerEntry instead of null in ITEM_UNIFICATION…
Browse files Browse the repository at this point in the history
…_ENTRY_COLLECTED (#966)

Co-authored-by: sirjoekcb <[email protected]>
  • Loading branch information
2 people authored and mikerooni committed Mar 23, 2024
1 parent b2c6a2b commit bee4553
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static MaterialStack getMaterial(UnificationEntry entry) {
@Nullable
public static MaterialStack getMaterial(ItemLike itemLike) {
var entry = getUnificationEntry(itemLike);
if (entry != null) {
if (entry != null && entry != UnificationEntry.EmptyMapMarkerEntry) {
Material entryMaterial = entry.material;
if (entryMaterial != null) {
return new MaterialStack(entryMaterial, entry.tagPrefix.getMaterialAmount(entryMaterial));
Expand Down Expand Up @@ -165,7 +165,7 @@ public static Material getMaterial(Fluid fluid) {
public static TagPrefix getPrefix(ItemLike itemLike) {
if (itemLike == null) return null;
UnificationEntry entry = getUnificationEntry(itemLike);
if (entry != null) return entry.tagPrefix;
if (entry != null && entry != UnificationEntry.EmptyMapMarkerEntry) return entry.tagPrefix;
return null;
}

Expand Down Expand Up @@ -228,7 +228,7 @@ public static UnificationEntry getUnificationEntry(ItemLike itemLike) {
return entry.getValue();
}
}
return null;
return UnificationEntry.EmptyMapMarkerEntry;
});
}

Expand All @@ -241,7 +241,7 @@ public static UnificationEntry getUnificationEntry(TagKey<Item> tag) {
}
}
}
return new UnificationEntry.EmptyMapMarkerEntry();
return UnificationEntry.EmptyMapMarkerEntry;
});
}

Expand All @@ -251,7 +251,7 @@ public static UnificationEntry getOrComputeUnificationEntry(ItemLike itemLike) {
return ITEM_UNIFICATION_ENTRY_COLLECTED.computeIfAbsent(itemLike, item -> {
Holder<Item> holder = Registry.ITEM.getOrCreateHolderOrThrow(Registry.ITEM.getResourceKey(item.asItem()).orElseThrow());
return holder.tags().map(ChemicalHelper::getUnificationEntry).filter(Objects::nonNull)
.filter(entry -> !(entry instanceof UnificationEntry.EmptyMapMarkerEntry)).findFirst().orElse(null);
.filter(entry -> !(entry == UnificationEntry.EmptyMapMarkerEntry)).findFirst().orElse(null);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ public String toString() {
return tagPrefix.name + (material != null ? material.toCamelCaseString() : "");
}

public static class EmptyMapMarkerEntry extends UnificationEntry {

public EmptyMapMarkerEntry() {
super(null);
}

public static final UnificationEntry EmptyMapMarkerEntry = new UnificationEntry(null) {
@Override
public boolean equals(Object o) {
return this == o;
Expand All @@ -65,5 +60,6 @@ public int hashCode() {
public String toString() {
return "EMPTY UNIFICATION ENTRY";
}
}
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public boolean matches(CraftingContainer inv, @NotNull Level level) {
} else return false;

if (!tool.isElectric()) return false;
if (toolHead == null) return false;
if (toolHead == null || toolHead == UnificationEntry.EmptyMapMarkerEntry) return false;
GTToolType[] output = TOOL_HEAD_TO_TOOL_MAP.get(toolHead.tagPrefix);
return output != null && output[tool.getElectricTier()] != null;
}
Expand Down Expand Up @@ -105,7 +105,7 @@ public ItemStack assemble(CraftingContainer inv) {
} else return ItemStack.EMPTY;
if (!tool.isElectric()) return ItemStack.EMPTY;
IElectricItem powerUnit = GTCapabilityHelper.getElectricItem(realTool);
if (toolHead == null) return ItemStack.EMPTY;
if (toolHead == null || toolHead == UnificationEntry.EmptyMapMarkerEntry) return ItemStack.EMPTY;
GTToolType[] toolArray = TOOL_HEAD_TO_TOOL_MAP.get(toolHead.tagPrefix);
ItemStack newTool = GTItems.TOOL_ITEMS.get(toolHead.material, toolArray[tool.getElectricTier()])
.get().get(powerUnit.getCharge(), powerUnit.getMaxCharge());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private static void registerMaceratorRecycling(Consumer<FinishedRecipe> provider

UnificationEntry entry = ChemicalHelper.getUnificationEntry(input.getItem());
TagKey<Item> inputTag = null;
if (entry != null) {
if (entry != null && entry != UnificationEntry.EmptyMapMarkerEntry) {
inputTag = ChemicalHelper.getTag(entry.tagPrefix, entry.material);
}

Expand All @@ -134,7 +134,7 @@ private static void registerExtractorRecycling(Consumer<FinishedRecipe> provider

UnificationEntry entry = ChemicalHelper.getUnificationEntry(input.getItem());
TagKey<Item> inputTag = null;
if (entry != null) {
if (entry != null && entry != UnificationEntry.EmptyMapMarkerEntry) {
inputTag = ChemicalHelper.getTag(entry.tagPrefix, entry.material);
}

Expand Down Expand Up @@ -217,7 +217,7 @@ private static void registerExtractorRecycling(Consumer<FinishedRecipe> provider
private static void registerArcRecycling(Consumer<FinishedRecipe> provider, ItemStack input, List<MaterialStack> materials, @Nullable TagPrefix prefix) {
UnificationEntry entry = ChemicalHelper.getUnificationEntry(input.getItem());
TagKey<Item> inputTag = null;
if (entry != null) {
if (entry != null && entry != UnificationEntry.EmptyMapMarkerEntry) {
inputTag = ChemicalHelper.getTag(entry.tagPrefix, entry.material);
}

Expand Down Expand Up @@ -407,7 +407,7 @@ private static List<ItemStack> finalizeOutputs(List<MaterialStack> materials, in
if (stack == ItemStack.EMPTY) continue;
if (stack.getCount() > 64) {
UnificationEntry entry = ChemicalHelper.getUnificationEntry(stack.getItem());
if (entry != null) { // should always be true
if (entry != null && entry != UnificationEntry.EmptyMapMarkerEntry) { // should always be true
TagPrefix prefix = entry.tagPrefix;

// These are the highest forms that a Material can have (for Ingot and Dust, respectively),
Expand Down

0 comments on commit bee4553

Please sign in to comment.