Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix crash with Forestry integration #2531

Merged
merged 3 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}