Skip to content

Commit 8f485c1

Browse files
committed
fix crash with Forestry integration (#2531)
(cherry picked from commit 7799009)
1 parent 950fcd8 commit 8f485c1

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/main/java/gregtech/api/unification/OreDictUnifier.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,13 @@ public static boolean hasOreDictionary(@NotNull ItemStack itemStack, @NotNull St
217217
return wildcardNames != null && wildcardNames != names && wildcardNames.contains(oreDictName);
218218
}
219219

220-
public static List<ItemStack> getAllWithOreDictionaryName(String oreDictionaryName) {
221-
return oreDictNameStacks.get(oreDictionaryName).stream()
220+
public static @NotNull List<@NotNull ItemStack> getAllWithOreDictionaryName(@NotNull String oreDictionaryName) {
221+
var stacks = oreDictNameStacks.get(oreDictionaryName);
222+
if (stacks == null) {
223+
return Collections.emptyList();
224+
}
225+
226+
return stacks.stream()
222227
.map(ItemStack::copy)
223228
.collect(Collectors.toList());
224229
}

src/main/java/gregtech/integration/forestry/mutation/MaterialMutationCondition.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import gregtech.api.unification.OreDictUnifier;
44
import gregtech.api.unification.material.Material;
5+
import gregtech.api.unification.ore.OrePrefix;
6+
import gregtech.api.unification.stack.UnificationEntry;
57
import gregtech.api.util.LocalizationUtils;
68

79
import net.minecraft.block.Block;
@@ -19,22 +21,21 @@
1921
import forestry.api.genetics.IGenome;
2022
import forestry.api.genetics.IMutationCondition;
2123
import forestry.core.tiles.TileUtil;
24+
import org.jetbrains.annotations.NotNull;
2225

2326
import java.util.HashSet;
2427
import java.util.Set;
2528

26-
import static org.apache.commons.lang3.StringUtils.capitalize;
27-
2829
public class MaterialMutationCondition implements IMutationCondition {
2930

30-
private final Set<IBlockState> acceptedBlocks = new HashSet();
31+
private final Set<IBlockState> acceptedBlocks = new HashSet<>();
3132
private final String displayName;
3233

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

37-
for (ItemStack ore : OreDictUnifier.getAllWithOreDictionaryName(oredictName)) {
38+
for (ItemStack ore : OreDictUnifier.getAllWithOreDictionaryName(oreDictName)) {
3839
if (!ore.isEmpty()) {
3940
Item oreItem = ore.getItem();
4041
Block oreBlock = Block.getBlockFromItem(oreItem);
@@ -45,8 +46,10 @@ public MaterialMutationCondition(Material material) {
4546
}
4647
}
4748

48-
public float getChance(World world, BlockPos pos, IAllele allele0, IAllele allele1, IGenome genome0,
49-
IGenome genome1, IClimateProvider climate) {
49+
@Override
50+
public float getChance(@NotNull World world, @NotNull BlockPos pos, @NotNull IAllele allele0,
51+
@NotNull IAllele allele1, @NotNull IGenome genome0,
52+
@NotNull IGenome genome1, @NotNull IClimateProvider climate) {
5053
TileEntity tile;
5154
do {
5255
pos = pos.down();
@@ -57,7 +60,8 @@ public float getChance(World world, BlockPos pos, IAllele allele0, IAllele allel
5760
return this.acceptedBlocks.contains(blockState) ? 1.0F : 0.0F;
5861
}
5962

60-
public String getDescription() {
63+
@Override
64+
public @NotNull String getDescription() {
6165
return LocalizationUtils.format("for.mutation.condition.resource", this.displayName);
6266
}
6367
}

0 commit comments

Comments
 (0)