Jump to content

[1.18.2] Crash when adding custom Tree to Biome


Skyriis

Recommended Posts

Hey Guys,

i've created a custom Tree and would love to spawn it in my Biome. But crashes when clicking on the single player button after adding the Tree to the Biome.

My Code:

public class TensuraTreeFeatures {
  public static final Holder<ConfiguredFeature<TreeConfiguration, ?>> SAKURA = FeatureUtils.register("sakura", Feature.TREE,
        basicTree(TensuraBlocks.SAKURA_LOG, TensuraBlocks.SAKURA_LEAVES));

  public static final Holder<PlacedFeature> SAKURA_CHECKED = PlacementUtils.register("sakura_tree", TensuraTreeFeatures.SAKURA,
        PlacementUtils.filteredByBlockSurvival(TensuraBlocks.SAKURA_SAPLING));



  private static TreeConfiguration basicTree(Block logBlock, Block leavesBlock) {
        return createStraightBlobTree(logBlock, leavesBlock, 4, 2, 0, 2).ignoreVines().build();
  }
  
  private static TreeConfiguration.TreeConfigurationBuilder createStraightBlobTree(Block logBlock, Block leavesBlock, int baseHeight, int p_195150_, int p_195151_, int leavesRadius) {
        return new TreeConfiguration.TreeConfigurationBuilder(BlockStateProvider.simple(logBlock),
            new StraightTrunkPlacer(baseHeight, p_195150_, p_195151_), BlockStateProvider.simple(leavesBlock),
            new BlobFoliagePlacer(ConstantInt.of(leavesRadius), ConstantInt.of(0), 3),
            new TwoLayersFeatureSize(1, 0, 1));
  }
}

 

 

Link to comment
Share on other sites

How do i register those?

i've tried to register them like that:

class FeatureRegistry {
    static void register(final DeferredRegister<Feature<?>> registry) { 
        registry.register("sakura_tree", () -> new ConfiguredFeature<>(Feature.TREE, basicTree(TensuraBlocks.SAKURA_LOG, TensuraBlocks.SAKURA_LEAVES)));
    }
  
    private static TreeConfiguration basicTree(Block logBlock, Block leavesBlock) {
        return createStraightBlobTree(logBlock, leavesBlock, 4, 2, 0, 2).ignoreVines().build();
    }

    private static TreeConfiguration.TreeConfigurationBuilder createStraightBlobTree(Block logBlock, Block leavesBlock, int baseHeight, int p_195150_, int p_195151_, int leavesRadius) {
        return new TreeConfiguration.TreeConfigurationBuilder(BlockStateProvider.simple(logBlock),
            new StraightTrunkPlacer(baseHeight, p_195150_, p_195151_), BlockStateProvider.simple(leavesBlock),
            new BlobFoliagePlacer(ConstantInt.of(leavesRadius), ConstantInt.of(0), 3),
            new TwoLayersFeatureSize(1, 0, 1));
    }
}

but ConfiguredFeature isn't a Featue. Do i need to use an other registy instead of ForgeRegistries.FEATURES?

Link to comment
Share on other sites

i'm still running into a small problem with my object holder.

java.lang.IllegalStateException: The ObjectHolder annotation cannot apply to a field that does not map to a registry. Ensure the registry was created during the RegistryEvent.NewRegistry event. (found : net.minecraft.world.level.levelgen.feature.ConfiguredFeature at com.borniuus.tensura.world.gen.TensuraFeatures.SAKURA_FOREST_TREES)
@ObjectHolder(Tensura.MOD_ID)
public class TensuraFeatures {
    @ObjectHolder("sakura_forest_trees")
    public static final ConfiguredFeature<RandomFeatureConfiguration, Feature<RandomFeatureConfiguration>> SAKURA_FOREST_TREES = null;
}

//registered using
registry.register("sakura_forest_trees", () -> new ConfiguredFeature<>(Feature.RANDOM_SELECTOR, new RandomFeatureConfiguration(List.of(
            new WeightedPlacedFeature(Holder.direct(TensuraPlacements.SAKURA_TREE_LARGE_CHECKED), 0.15F)
        ), Holder.direct(TensuraPlacements.SAKURA_TREE_CHECKED))));

 

Link to comment
Share on other sites

ConfiguredFeature:

Spoiler
public class FeatureRegistry {
    private static final BeehiveDecorator BEEHIVE = new BeehiveDecorator(0.05F);
    public static RegistryObject<ConfiguredFeature<?, ?>> SAKURA_TREE, SAKURA_TREE_HIVE, SAKURA_TREE_LARGE, SAKURA_TREE_LARGE_HIVE, SAKURA_FOREST;

    static void register(final DeferredRegister<ConfiguredFeature<?, ?>> registry) {
        SAKURA_TREE = registry.register("sakura_tree", () -> new ConfiguredFeature<>(Feature.TREE, basicTree(TensuraBlocks.SAKURA_LOG, TensuraBlocks.SAKURA_LEAVES)));
        SAKURA_TREE_HIVE = registry.register("sakura_tree_hive", () -> new ConfiguredFeature<>(Feature.TREE, basicTreeWithHive(TensuraBlocks.SAKURA_LOG, TensuraBlocks.SAKURA_LEAVES)));
        SAKURA_TREE_LARGE = registry.register("sakura_tree_large", () -> new ConfiguredFeature<>(Feature.TREE, largeTree(TensuraBlocks.SAKURA_LOG, TensuraBlocks.SAKURA_LEAVES)));
        SAKURA_TREE_LARGE_HIVE = registry.register("sakura_tree_large_hive", () -> new ConfiguredFeature<>(Feature.TREE, largeTreeWithHive(TensuraBlocks.SAKURA_LOG, TensuraBlocks.SAKURA_LEAVES)));

        SAKURA_FOREST = registry.register("sakura_forest_trees", () -> new ConfiguredFeature<>(Feature.RANDOM_SELECTOR, new RandomFeatureConfiguration(List.of(
            new WeightedPlacedFeature(Holder.direct(PlacementRegistry.SAKURA_TREE_LARGE_CHECKED.get()), 0.15F)
        ), Holder.direct(PlacementRegistry.SAKURA_TREE_CHECKED.get()))));
    }

    private static TreeConfiguration largeTree(Block logBlock, Block leavesBlock) {
        return largeTree(logBlock, leavesBlock, 3, 11, 0, 4).build();
    }

    private static TreeConfiguration largeTreeWithHive(Block logBlock, Block leavesBlock) {
        return largeTree(logBlock, leavesBlock, 3, 11, 0, 4).decorators(List.of(BEEHIVE)).build();
    }

    private static TreeConfiguration basicTree(Block logBlock, Block leavesBlock) {
        return createStraightBlobTree(logBlock, leavesBlock, 4, 2, 0, 2).ignoreVines().build();
    }

    private static TreeConfiguration basicTreeWithHive(Block logBlock, Block leavesBlock) {
        return createStraightBlobTree(logBlock, leavesBlock, 4, 2, 0, 2).ignoreVines().decorators(List.of(BEEHIVE)).build();
    }

    private static TreeConfiguration.TreeConfigurationBuilder createStraightBlobTree(Block logBlock, Block leavesBlock, int baseHeight, int p_195150_, int p_195151_, int leavesRadius) {
        return new TreeConfiguration.TreeConfigurationBuilder(BlockStateProvider.simple(logBlock),
            new StraightTrunkPlacer(baseHeight, p_195150_, p_195151_), BlockStateProvider.simple(leavesBlock),
            new BlobFoliagePlacer(ConstantInt.of(leavesRadius), ConstantInt.of(0), 3),
            new TwoLayersFeatureSize(1, 0, 1));
    }

    private static TreeConfiguration.TreeConfigurationBuilder largeTree(Block logBlock, Block leavesBlock, int baseHeight, int p_195150_, int p_195151_, int leavesRadius) {
        return new TreeConfiguration.TreeConfigurationBuilder(BlockStateProvider.simple(logBlock),
            new FancyTrunkPlacer(baseHeight, p_195150_, p_195151_), BlockStateProvider.simple(leavesBlock),
            new FancyFoliagePlacer(ConstantInt.of(leavesRadius), ConstantInt.of(4), 4),
            new TwoLayersFeatureSize(0, 0, 0, OptionalInt.of(4))).ignoreVines();
    }
}

 

PlacedFeatures:

Spoiler
public class PlacementRegistry {
    public static RegistryObject<PlacedFeature> SAKURA_TREE_CHECKED, SAKURA_TREE_LARGE_CHECKED, SAKURA_FOREST_CHECKED;

    static void register(DeferredRegister<PlacedFeature> registry) {
        SAKURA_TREE_CHECKED = registry.register("sakura_tree_checked", () -> new PlacedFeature(Holder.direct(FeatureRegistry.SAKURA_TREE.get()),
            List.of(PlacementUtils.filteredByBlockSurvival(TensuraBlocks.SAKURA_SAPLING))));
        SAKURA_TREE_LARGE_CHECKED = registry.register("sakura_tree_large_checked", () -> new PlacedFeature(Holder.direct(FeatureRegistry.SAKURA_TREE_LARGE.get()),
            List.of(PlacementUtils.filteredByBlockSurvival(TensuraBlocks.SAKURA_SAPLING))));
        SAKURA_FOREST_CHECKED = registry.register("sakura_forest_trees_checked", () -> new PlacedFeature(Holder.direct(FeatureRegistry.SAKURA_TREE_LARGE.get()),
            List.of(CountPlacement.of(16), InSquarePlacement.spread(), TREE_THRESHOLD, PlacementUtils.HEIGHTMAP_OCEAN_FLOOR)));
    }
}

Biome Registry:

Spoiler
class BiomeRegistry {
    static void register(DeferredRegister<Biome> registry) {
        registry.register("sakura_forest", SakuraForestBiome::create).getKey();
    }
}
public class SakuraForestBiome {
    public static Biome create() {
        BiomeGenerationSettingsHelper generationSettingsHelper = new BiomeGenerationSettingsHelper()
            //Add Caves and Canyons
            .addCarver(GenerationStep.Carving.AIR, Carvers.CAVE)
            .addCarver(GenerationStep.Carving.AIR, Carvers.CAVE_EXTRA_UNDERGROUND)
            .addCarver(GenerationStep.Carving.AIR, Carvers.CANYON)
            //Add underground lava lakes
            .addFeature(GenerationStep.Decoration.LAKES, MiscOverworldPlacements.LAKE_LAVA_UNDERGROUND)
            //Add underground crystal formations
            .apply(BiomeDefaultFeatures::addDefaultCrystalFormations)
            //Add Monster Room Structure
            .apply(BiomeDefaultFeatures::addDefaultMonsterRoom)
            //Apply default underground variety
            .apply(BiomeDefaultFeatures::addDefaultUndergroundVariety)
            //Apply default surface freezing
            .apply(BiomeDefaultFeatures::addSurfaceFreezing)
            //Add Trees
            .addFeature(GenerationStep.Decoration.VEGETAL_DECORATION, Holder.direct(PlacementRegistry.SAKURA_FOREST_CHECKED.get()))
            //Apply mossy stones to surface
            .apply(BiomeDefaultFeatures::addMossyStoneBlock)
            //Add flowers to surface
            .apply(BiomeDefaultFeatures::addForestFlowers)
            //Add grass to surface
            .apply(BiomeDefaultFeatures::addForestGrass)
            //Add Mushrooms to surface
            .apply(BiomeDefaultFeatures::addDefaultMushrooms)
            //Add decoration plants to surface
            .apply(BiomeDefaultFeatures::addDefaultExtraVegetation)
            //Add default ores
            .apply(BiomeDefaultFeatures::addDefaultOres, BiomeDefaultFeatures::addDefaultSoftDisks);

        MobSpawnHelper mobSpawnHelper = new MobSpawnHelper()
            //Add default animals
            .apply(BiomeDefaultFeatures::farmAnimals)
            //Add default cave entities and mobs
            .apply(BiomeDefaultFeatures::commonSpawns)
            //Allow wolves to spawn
            .addSpawn(MobCategory.CREATURE, EntityType.WOLF, 5, 4, 4);

        return BiomeBuilder.forest(generationSettingsHelper, mobSpawnHelper).build();
    }
}

 

 

Full crash report: https://pastebin.com/EJaHMYFR

Link to comment
Share on other sites

My DeferredRegister fields are in a seperate class. 

public class TensuraRegistry {
    private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, Tensura.MOD_ID);
    private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, Tensura.MOD_ID);
    private static final DeferredRegister<SoundEvent> SOUND_EVENTS = DeferredRegister.create(ForgeRegistries.SOUND_EVENTS, Tensura.MOD_ID);
    private static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITIES, Tensura.MOD_ID);
    private static final DeferredRegister<Motive> MOTIVE = DeferredRegister.create(ForgeRegistries.PAINTING_TYPES, Tensura.MOD_ID);
    private static final DeferredRegister<Biome> BIOMES = DeferredRegister.create(ForgeRegistries.BIOMES, Tensura.MOD_ID);
    private static final DeferredRegister<ConfiguredFeature<?, ?>> CONFIGURED_FEATURES = DeferredRegister.create(Registry.CONFIGURED_FEATURE_REGISTRY, Tensura.MOD_ID);
    private static final DeferredRegister<PlacedFeature> PLACED_FEATURE = DeferredRegister.create(Registry.PLACED_FEATURE_REGISTRY, Tensura.MOD_ID);

    public static void register(IEventBus modEventBus) {
        BlockRegistry.register(ITEMS, BLOCKS); //Register Blocks with their BlockItems
        ItemRegistry.register(ITEMS); //Register Items to our Registry
        BlockEntityTypeRegistry.register(ITEMS, BLOCKS, BLOCK_ENTITY_TYPES); //Registers Block Entities including their Blocks and Items
        SoundEventRegistry.register(SOUND_EVENTS); //Register Sound Events
        MotiveRegistry.register(MOTIVE); //Register Motives for custom paintings
        ConfiguredFeatureRegistry.register(CONFIGURED_FEATURES);
        PlacedFeatureRegistry.register(PLACED_FEATURE);
        BiomeRegistry.register(BIOMES); //Register Biomes

        // Add our Registries to Forge
        BLOCKS.register(modEventBus);
        ITEMS.register(modEventBus);
        BLOCK_ENTITY_TYPES.register(modEventBus);
        SOUND_EVENTS.register(modEventBus);
        MOTIVE.register(modEventBus);
        BIOMES.register(modEventBus);
        CONFIGURED_FEATURES.register(modEventBus);
        PLACED_FEATURE.register(modEventBus);
    }
}

 

Edited by Skyriis
Link to comment
Share on other sites

 ConfiguredFeature:

Spoiler
public class FeatureRegistry {
    private static final DeferredRegister<ConfiguredFeature<?, ?>> registry = DeferredRegister.create(Registry.CONFIGURED_FEATURE_REGISTRY, Tensura.MOD_ID);
    private static final BeehiveDecorator BEEHIVE = new BeehiveDecorator(0.05F);
    public static RegistryObject<ConfiguredFeature<?, ?>> SAKURA_TREE, SAKURA_TREE_HIVE, SAKURA_TREE_LARGE, SAKURA_TREE_LARGE_HIVE, SAKURA_FOREST;

    static void register(final IEventBus modBus) {
        SAKURA_TREE = registry.register("sakura_tree", () -> new ConfiguredFeature<>(Feature.TREE, basicTree(TensuraBlocks.SAKURA_LOG, TensuraBlocks.SAKURA_LEAVES)));
        SAKURA_TREE_HIVE = registry.register("sakura_tree_hive", () -> new ConfiguredFeature<>(Feature.TREE, basicTreeWithHive(TensuraBlocks.SAKURA_LOG, TensuraBlocks.SAKURA_LEAVES)));
        SAKURA_TREE_LARGE = registry.register("sakura_tree_large", () -> new ConfiguredFeature<>(Feature.TREE, largeTree(TensuraBlocks.SAKURA_LOG, TensuraBlocks.SAKURA_LEAVES)));
        SAKURA_TREE_LARGE_HIVE = registry.register("sakura_tree_large_hive", () -> new ConfiguredFeature<>(Feature.TREE, largeTreeWithHive(TensuraBlocks.SAKURA_LOG, TensuraBlocks.SAKURA_LEAVES)));

        SAKURA_FOREST = registry.register("sakura_forest_trees", () -> new ConfiguredFeature<>(Feature.RANDOM_SELECTOR, new RandomFeatureConfiguration(List.of(
            new WeightedPlacedFeature(Holder.direct(PlacementRegistry.SAKURA_TREE_LARGE_CHECKED.get()), 0.15F)
        ), Holder.direct(PlacementRegistry.SAKURA_TREE_CHECKED.get()))));
      
        registry.register(modBus);
    }

    private static TreeConfiguration largeTree(Block logBlock, Block leavesBlock) {
        return largeTree(logBlock, leavesBlock, 3, 11, 0, 4).build();
    }

    private static TreeConfiguration largeTreeWithHive(Block logBlock, Block leavesBlock) {
        return largeTree(logBlock, leavesBlock, 3, 11, 0, 4).decorators(List.of(BEEHIVE)).build();
    }

    private static TreeConfiguration basicTree(Block logBlock, Block leavesBlock) {
        return createStraightBlobTree(logBlock, leavesBlock, 4, 2, 0, 2).ignoreVines().build();
    }

    private static TreeConfiguration basicTreeWithHive(Block logBlock, Block leavesBlock) {
        return createStraightBlobTree(logBlock, leavesBlock, 4, 2, 0, 2).ignoreVines().decorators(List.of(BEEHIVE)).build();
    }

    private static TreeConfiguration.TreeConfigurationBuilder createStraightBlobTree(Block logBlock, Block leavesBlock, int baseHeight, int p_195150_, int p_195151_, int leavesRadius) {
        return new TreeConfiguration.TreeConfigurationBuilder(BlockStateProvider.simple(logBlock),
            new StraightTrunkPlacer(baseHeight, p_195150_, p_195151_), BlockStateProvider.simple(leavesBlock),
            new BlobFoliagePlacer(ConstantInt.of(leavesRadius), ConstantInt.of(0), 3),
            new TwoLayersFeatureSize(1, 0, 1));
    }

    private static TreeConfiguration.TreeConfigurationBuilder largeTree(Block logBlock, Block leavesBlock, int baseHeight, int p_195150_, int p_195151_, int leavesRadius) {
        return new TreeConfiguration.TreeConfigurationBuilder(BlockStateProvider.simple(logBlock),
            new FancyTrunkPlacer(baseHeight, p_195150_, p_195151_), BlockStateProvider.simple(leavesBlock),
            new FancyFoliagePlacer(ConstantInt.of(leavesRadius), ConstantInt.of(4), 4),
            new TwoLayersFeatureSize(0, 0, 0, OptionalInt.of(4))).ignoreVines();
    }
}

 

PlacedFeatures:

Spoiler
public class PlacementRegistry {
    private static final DeferredRegister<PlacedFeature> registry = DeferredRegister.create(Registry.PLACED_FEATURE_REGISTRY, Tensura.MOD_ID);
    public static RegistryObject<PlacedFeature> SAKURA_TREE_CHECKED, SAKURA_TREE_LARGE_CHECKED, SAKURA_FOREST_CHECKED;

    static void register(final IEventBus modBus) {
        SAKURA_TREE_CHECKED = registry.register("sakura_tree_checked", () -> new PlacedFeature(Holder.direct(FeatureRegistry.SAKURA_TREE.get()),
            List.of(PlacementUtils.filteredByBlockSurvival(TensuraBlocks.SAKURA_SAPLING))));
        SAKURA_TREE_LARGE_CHECKED = registry.register("sakura_tree_large_checked", () -> new PlacedFeature(Holder.direct(FeatureRegistry.SAKURA_TREE_LARGE.get()),
            List.of(PlacementUtils.filteredByBlockSurvival(TensuraBlocks.SAKURA_SAPLING))));
        SAKURA_FOREST_CHECKED = registry.register("sakura_forest_trees_checked", () -> new PlacedFeature(Holder.direct(FeatureRegistry.SAKURA_TREE_LARGE.get()),
            List.of(CountPlacement.of(16), InSquarePlacement.spread(), TREE_THRESHOLD, PlacementUtils.HEIGHTMAP_OCEAN_FLOOR)));
      
        registry.register(modBus);
    }
}

 

Biome Registry:

Spoiler
class BiomeRegistry {
    private static final DeferredRegister<Biome> registry = DeferredRegister.create(ForgeRegistries.BIOMES, Tensura.MOD_ID);
  
    static void register(final IEventBus modBus) {
        registry.register("sakura_forest", SakuraForestBiome::create);
        registry.register(modBus);
    }
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have created a mod which applies x shader to the player after consuming x item for a certain time, but if the player presses f5 to change the camera the shader stops working. The only way I have found to prevent the shader from being deactivated is to load it on all ticks until it is disabled but this greatly reduces the performance of the game. I have also tried to cancel the event of changing the camera but this is not cancelable. Any advice, I've been trying to solve this for several days 😵‍💫  
    • Minecraft 1.20.1 Forge 47.2.0 log and crash report: https://pastebin.com/P7tQymQS ; (crash report) I launch the game and i got this error: Someone could help me please?  
    • EDIT: NVM, the enchantment ID was wrong and that was causing the issue. Not sure why it doesn't let me delete this post Hi, I'm trying to make a "smelting" enchantment Global Loot Modifier, but for some reason the game could not decode its related JSON file, altough is applying the Loot Modifier to every single loot When I join a world I get this error in the console   [01:08:01] [Render thread/WARN] [ne.mi.co.lo.LootModifierManager/]: Could not decode GlobalLootModifier with json id mineworld:enchantments/fiery_touch - error: Not a json array: {"condition":"minecraft:match_tool","predicate":{"enchantments":[{"enchantment":"mineworld:smelting","levels":{"min":1}}]}} The GLM Json file is the following { "type": "mineworld:fiery_touch", "conditions": [ { "condition": "minecraft:match_tool", "predicate": { "enchantments": [ { "enchantment": "mineworld:smelting", "levels": { "min": 1 } } ] } } ] } And this is the LootModifier class   package org.mineworld.loot; import com.google.common.base.Suppliers; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.minecraft.core.RegistryAccess; import net.minecraft.world.Container; import net.minecraft.world.SimpleContainer; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Recipe; import net.minecraft.world.item.crafting.RecipeManager; import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.level.Level; import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; import net.minecraftforge.common.loot.IGlobalLootModifier; import net.minecraftforge.common.loot.LootModifier; import net.minecraftforge.items.ItemHandlerHelper; import org.jetbrains.annotations.NotNull; import org.mineworld.MineWorld; import java.util.List; import java.util.Optional; import java.util.function.Supplier; import java.util.stream.IntStream; /** * {@link MineWorld MineWorld} loot modifier for smelting a drop from a block */ public final class FieryTouchModifier extends LootModifier { /** * {@link Supplier<Codec> The loot codec supplier} */ public static final Supplier<Codec<FieryTouchModifier>> CODEC = Suppliers.memoize(() -> RecordCodecBuilder.create(inst -> codecStart(inst).apply(inst, FieryTouchModifier::new))); /** * Constructor. Set the {@link LootItemCondition loot id conditions} * * @param lootConditions {@index ILootCondition The conditions that need to be matched before the loot is modified} */ public FieryTouchModifier(final LootItemCondition[] lootConditions) { super(lootConditions); } /** * Add the {@link MWLootItem items} to the loot * * @param loot {@link ObjectArrayList<ItemStack> The current loot} * @param context {@link LootContext The loot context} * @return {@link ObjectArrayList<ItemStack> The modified loot} */ @Override protected @NotNull ObjectArrayList<ItemStack> doApply(final ObjectArrayList<ItemStack> loot, final LootContext context) { if(context.hasParam(LootContextParams.BLOCK_STATE)) { final Level level = context.getLevel(); final RecipeManager recipeManager = level.getRecipeManager(); final RegistryAccess registryAccess = level.registryAccess(); IntStream.range(0, loot.size()).forEach(index -> { final ItemStack drop = loot.get(index); final ItemStack smeltedDrop = tryGetSmeltedDrop(recipeManager, RecipeType.SMELTING, level, registryAccess, drop) .orElse(tryGetSmeltedDrop(recipeManager, RecipeType.SMITHING, level, registryAccess, drop) .orElse(tryGetSmeltedDrop(recipeManager, RecipeType.BLASTING, level, registryAccess, drop) .orElse(tryGetSmeltedDrop(recipeManager, RecipeType.SMOKING, level, registryAccess, drop) .orElse(tryGetSmeltedDrop(recipeManager, RecipeType.CAMPFIRE_COOKING, level, registryAccess, drop) .orElse(ItemStack.EMPTY))))); if(!smeltedDrop.isEmpty()) { loot.set(index, smeltedDrop); } }); } return loot; } /** * Get the {@link Codec loot modifier codec} * * @return {@link #CODEC The loot modifier codec} */ @Override public Codec<? extends IGlobalLootModifier> codec() { return CODEC.get(); } /** * Try to set the smelted drop to the {@link List<ItemStack> block drop list} * * @param recipeManager {@link RecipeManager The recipe manager} * @param recipeType {@link RecipeType The recipe type} * @param level {@link Level The level reference} * @param registryAccess {@link RegistryAccess The registry access} * @param drop {@link ItemStack The dropped item} * @return {@link ItemStack The smelted ItemStack} */ private static <C extends Container, T extends Recipe<C>> Optional<ItemStack> tryGetSmeltedDrop(final RecipeManager recipeManager, final RecipeType<T> recipeType, final Level level, final RegistryAccess registryAccess, final ItemStack drop) { return recipeManager.getRecipeFor(recipeType, (C) new SimpleContainer(drop), level) .map(recipe -> recipe.value().getResultItem(registryAccess)) .filter(itemStack -> !itemStack.isEmpty()) .map(itemStack -> ItemHandlerHelper.copyStackWithSize(itemStack, drop.getCount() * itemStack.getCount())); } } I have another GLM that has some entries as well and doesn't have any issues
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.