public class ModPlacedFeatures {
public static final DeferredRegister PLACED_FEATURES =
DeferredRegister.create(Registries.PLACED_FEATURE, BDB.MOD_ID);
code
// Register your PlacedFeature
public static final DeferredHolder<PlacedFeature, PlacedFeature> FLOATING_ISLAND_PLACED =
PLACED_FEATURES.register("floating_island",
() -> new PlacedFeature(
// Get the ConfiguredFeature holder
ModConfiguredFeatures.FLOATING_ISLAND_CONFIGURED.getHolder().orElseThrow(),
// Define placement modifiers (rules for where/how often it generates)
List.of(
// Try to place it on average once every 10 chunks (for testing, adjust as needed)
RarityFilter.onAverageOnceEvery(10),
// Ensure it's placed within a chunk's square area
InSquarePlacement.spread(),
// Place it only if there's air above the height range.
// Modify these values for your desired floating island height.
HeightRangePlacement.uniform(VerticalAnchor.absolute(100), VerticalAnchor.absolute(200)),
// Only place in biomes where it's allowed (e.g., plains, ocean).
// For testing, you might omit this or use a more specific biome.
// BiomeFilter.biome() // This is usually applied later with biome modifiers.
)
));
}
Cannot resolve method 'getHolder' in 'DeferredHolder' Expression expected
Assistant
The error you're encountering is because DeferredHolder does not have a method called getHolder(). Instead, you should directly use the DeferredHolder itself, as it already represents a holder for the configured feature.
Here's the corrected version of your ModPlacedFeatures.java file:
java
// src/main/java/net/mattias/bdb/core/worldgen/ModPlacedFeatures.java
package net.mattias.bdb.core.worldgen;
import net.mattias.bdb.BDB;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.level.levelgen.VerticalAnchor;
import net.minecraft.world.level.levelgen.feature.PlacedFeature;
import net.minecraft.world.level.levelgen.placement.*;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;
import java.util.List;
public class ModPlacedFeatures {
public static final DeferredRegister<PlacedFeature> PLACED_FEATURES =
DeferredRegister.create(Registries.PLACED_FEATURE, BDB.MOD_ID);
// Register your PlacedFeature
public static final DeferredHolder<PlacedFeature, PlacedFeature> FLOATING_ISLAND_PLACED =
PLACED_FEATURES.register("floating_island",
() -> new PlacedFeature(
// Use the DeferredHolder directly
ModConfiguredFeatures.FLOATING_ISLAND_CONFIGURED,
// Define placement modifiers (rules for where/how often it generates)
List.of(
// Try to place it on average once every 10 chunks (for testing, adjust as needed)
RarityFilter.onAverageOnceEvery(10),
// Ensure it's placed within a chunk's square area
InSquarePlacement.spread(),
// Place it only if there's air above the height range.
// Modify these values for your desired floating island height.
HeightRangePlacement.uniform(VerticalAnchor.absolute(100), VerticalAnchor.absolute(200))
)
));
}
In this corrected version, we directly use ModConfiguredFeatures.FLOATING_ISLAND_CONFIGURED instead of trying to call getHolder() on it. The DeferredHolder itself is already a holder for the configured feature, so it can be used directly in the PlacedFeature constructor.
This should resolve the compilation error and allow your feature to be placed correctly.