Skip to content

Commit

Permalink
Fix biome extract crash on pack reload
Browse files Browse the repository at this point in the history
Closes #1016
  • Loading branch information
rubensworks committed Dec 7, 2023
1 parent bb17e0b commit cee36cb
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/main/java/org/cyclops/evilcraft/item/ItemBiomeExtract.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.cyclops.evilcraft.RegistryEntries;
import org.cyclops.evilcraft.entity.item.EntityBiomeExtract;

import javax.annotation.Nullable;
import java.util.List;
import java.util.function.Function;

Expand All @@ -49,13 +50,19 @@ public ItemBiomeExtract(Properties properties) {
super(properties);
}

@Nullable
public static Registry<Biome> getBiomeRegistry() {
return WorldHelpers.getActiveLevel().registryAccess().registryOrThrow(Registries.BIOME);
Level level = WorldHelpers.getActiveLevel();
if (level == null) { // Can be null at startup time
return null;
}
return level.registryAccess().registryOrThrow(Registries.BIOME);
}

@Override
public String getDescriptionId(ItemStack itemStack) {
return super.getDescriptionId(itemStack) + (getBiome(getBiomeRegistry(), itemStack) == null ? ".empty" : "");
Registry<Biome> biomeRegistry = getBiomeRegistry();
return super.getDescriptionId(itemStack) + (biomeRegistry == null || getBiome(biomeRegistry, itemStack) == null ? ".empty" : "");
}

@Override
Expand Down Expand Up @@ -85,12 +92,14 @@ public InteractionResultHolder<ItemStack> use(Level world, Player player, Intera
public void appendHoverText(ItemStack itemStack, Level world, List<Component> list, TooltipFlag flag) {
super.appendHoverText(itemStack, world, list, flag);
Registry<Biome> registry = getBiomeRegistry();
Biome biome = getBiome(registry, itemStack);
if(biome != null) {
// Biome name generation based on CreateBuffetWorldScreen
ResourceLocation key = registry.getKey(biome);
list.add(Component.translatable(getDescriptionId() + ".info.content",
Component.translatable("biome." + key.getNamespace() + "." + key.getPath())));
if (registry != null) {
Biome biome = getBiome(registry, itemStack);
if (biome != null) {
// Biome name generation based on CreateBuffetWorldScreen
ResourceLocation key = registry.getKey(biome);
list.add(Component.translatable(getDescriptionId() + ".info.content",
Component.translatable("biome." + key.getNamespace() + "." + key.getPath())));
}
}
}

Expand Down Expand Up @@ -139,7 +148,8 @@ public ItemStack createItemStack(Function<Biome, ResourceLocation> biomeKeyFunct

@Override
public Rarity getRarity(ItemStack itemStack) {
Biome biome = getBiome(getBiomeRegistry(), itemStack);
Registry<Biome> biomeRegistry = getBiomeRegistry();
Biome biome = biomeRegistry != null ? getBiome(biomeRegistry, itemStack) : null;
if(biome == null) {
return Rarity.COMMON;
} else {
Expand All @@ -154,7 +164,8 @@ public static class ItemColor implements net.minecraft.client.color.item.ItemCol
@Override
public int getColor(ItemStack itemStack, int renderPass) {
if(renderPass == 0) {
Biome biome = RegistryEntries.ITEM_BIOME_EXTRACT.getBiome(getBiomeRegistry(), itemStack);
Registry<Biome> biomeRegistry = getBiomeRegistry();
Biome biome = biomeRegistry != null ? RegistryEntries.ITEM_BIOME_EXTRACT.getBiome(biomeRegistry, itemStack) : null;
if(biome != null) {
return biome.getFoliageColor();
} else {
Expand Down

0 comments on commit cee36cb

Please sign in to comment.