Skip to content

Commit

Permalink
fix crash with Forestry integration (GregTechCEu#2531)
Browse files Browse the repository at this point in the history
  • Loading branch information
TechLord22 authored Jul 8, 2024
1 parent 69d4e4a commit 7799009
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
9 changes: 7 additions & 2 deletions src/main/java/gregtech/api/unification/OreDictUnifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,13 @@ public static boolean hasOreDictionary(@NotNull ItemStack itemStack, @NotNull St
return wildcardNames != null && wildcardNames != names && wildcardNames.contains(oreDictName);
}

public static List<ItemStack> getAllWithOreDictionaryName(String oreDictionaryName) {
return oreDictNameStacks.get(oreDictionaryName).stream()
public static @NotNull List<@NotNull ItemStack> getAllWithOreDictionaryName(@NotNull String oreDictionaryName) {
var stacks = oreDictNameStacks.get(oreDictionaryName);
if (stacks == null) {
return Collections.emptyList();
}

return stacks.stream()
.map(ItemStack::copy)
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import gregtech.api.unification.OreDictUnifier;
import gregtech.api.unification.material.Material;
import gregtech.api.unification.ore.OrePrefix;
import gregtech.api.unification.stack.UnificationEntry;
import gregtech.api.util.LocalizationUtils;

import net.minecraft.block.Block;
Expand All @@ -19,22 +21,21 @@
import forestry.api.genetics.IGenome;
import forestry.api.genetics.IMutationCondition;
import forestry.core.tiles.TileUtil;
import org.jetbrains.annotations.NotNull;

import java.util.HashSet;
import java.util.Set;

import static org.apache.commons.lang3.StringUtils.capitalize;

public class MaterialMutationCondition implements IMutationCondition {

private final Set<IBlockState> acceptedBlocks = new HashSet();
private final Set<IBlockState> acceptedBlocks = new HashSet<>();
private final String displayName;

public MaterialMutationCondition(Material material) {
public MaterialMutationCondition(@NotNull Material material) {
this.displayName = LocalizationUtils.format("gregtech.mutation.block_of", material.getLocalizedName());
String oredictName = "block" + capitalize(material.getName());
String oreDictName = new UnificationEntry(OrePrefix.block, material).toString();

for (ItemStack ore : OreDictUnifier.getAllWithOreDictionaryName(oredictName)) {
for (ItemStack ore : OreDictUnifier.getAllWithOreDictionaryName(oreDictName)) {
if (!ore.isEmpty()) {
Item oreItem = ore.getItem();
Block oreBlock = Block.getBlockFromItem(oreItem);
Expand All @@ -45,8 +46,10 @@ public MaterialMutationCondition(Material material) {
}
}

public float getChance(World world, BlockPos pos, IAllele allele0, IAllele allele1, IGenome genome0,
IGenome genome1, IClimateProvider climate) {
@Override
public float getChance(@NotNull World world, @NotNull BlockPos pos, @NotNull IAllele allele0,
@NotNull IAllele allele1, @NotNull IGenome genome0,
@NotNull IGenome genome1, @NotNull IClimateProvider climate) {
TileEntity tile;
do {
pos = pos.down();
Expand All @@ -57,7 +60,8 @@ public float getChance(World world, BlockPos pos, IAllele allele0, IAllele allel
return this.acceptedBlocks.contains(blockState) ? 1.0F : 0.0F;
}

public String getDescription() {
@Override
public @NotNull String getDescription() {
return LocalizationUtils.format("for.mutation.condition.resource", this.displayName);
}
}

0 comments on commit 7799009

Please sign in to comment.