diff --git a/src/main/java/ru/bclib/api/LifeCycleAPI.java b/src/main/java/ru/bclib/api/LifeCycleAPI.java index c6afcb20..cf403cd0 100644 --- a/src/main/java/ru/bclib/api/LifeCycleAPI.java +++ b/src/main/java/ru/bclib/api/LifeCycleAPI.java @@ -1,5 +1,6 @@ package ru.bclib.api; +import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; @@ -49,7 +50,7 @@ public class LifeCycleAPI { LevelStorageSource.LevelStorageAccess levelStorageAccess, ServerLevelData serverLevelData, ResourceKey resourceKey, - DimensionType dimensionType, + Holder dimensionType, ChunkProgressListener chunkProgressListener, ChunkGenerator chunkGenerator, boolean bl, @@ -114,7 +115,7 @@ public class LifeCycleAPI { LevelStorageSource.LevelStorageAccess levelStorageAccess, ServerLevelData serverLevelData, ResourceKey resourceKey, - DimensionType dimensionType, + Holder dimensionType, ChunkProgressListener chunkProgressListener, ChunkGenerator chunkGenerator, boolean bl, diff --git a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index 034d2a65..cc01ec0c 100644 --- a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java @@ -2,9 +2,12 @@ package ru.bclib.api.biomes; import net.fabricmc.fabric.api.biome.v1.BiomeModifications; import net.minecraft.core.Holder; +import net.minecraft.core.HolderSet; +import net.minecraft.core.Registry; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.data.BuiltinRegistries; import net.minecraft.data.worldgen.BiomeDefaultFeatures; +import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.Music; import net.minecraft.sounds.SoundEvent; @@ -546,8 +549,8 @@ public class BCLBiomeBuilder { * @param structure {@link ConfiguredStructureFeature} to add. * @return same {@link BCLBiomeBuilder} instance. */ - public BCLBiomeBuilder structure(ConfiguredStructureFeature structure) { - structures.add(structure); + public BCLBiomeBuilder structure(Holder> structure) { + structures.add(structure.value()); return this; } @@ -672,7 +675,7 @@ public class BCLBiomeBuilder { builder.mobSpawnSettings(getSpawns().build()); builder.specialEffects(getEffects().build()); - Map>> defferedFeatures = new HashMap<>(); + Map> defferedFeatures = new HashMap<>(); BiomeGenerationSettingsAccessor acc = BiomeGenerationSettingsAccessor.class.cast(getGeneration().build()); if (acc != null) { builder.generationSettings(new BiomeGenerationSettings.Builder().build()); @@ -700,8 +703,9 @@ public class BCLBiomeBuilder { .setEdge(edge) .setVertical(vertical) .build(); - - final T res = biomeConstructor.apply(biomeID, builder.build(), settings); + + final Biome biome = builder.build(); + final T res = biomeConstructor.apply(biomeID, biome, settings); res.attachStructures(structures); res.setSurface(surfaceRule); res.setFeatures(defferedFeatures); diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index 53fa2988..d0a466e3 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -10,6 +10,7 @@ import net.fabricmc.fabric.impl.biome.TheEndBiomeData; import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; import net.minecraft.core.Holder; +import net.minecraft.core.HolderSet; import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceKey; @@ -74,28 +75,28 @@ public class BiomeAPI { private static final Map ID_MAP = Maps.newHashMap(); private static final Map CLIENT = Maps.newHashMap(); - private static Registry biomeRegistry; + private static Registry> biomeRegistry; private static final Map FEATURE_ORDER = Maps.newHashMap(); private static final MutableInt FEATURE_ORDER_ID = new MutableInt(0); - private static final Map>> MODIFICATIONS = Maps.newHashMap(); + private static final Map>>> MODIFICATIONS = Maps.newHashMap(); private static final Map SURFACE_RULES = Maps.newHashMap(); private static final Set MODIFIED_SURFACE_PROVIDERS = new HashSet<>(8); - public static final BCLBiome NETHER_WASTES_BIOME = registerNetherBiome(getFromRegistry(Biomes.NETHER_WASTES)); - public static final BCLBiome CRIMSON_FOREST_BIOME = registerNetherBiome(getFromRegistry(Biomes.CRIMSON_FOREST)); - public static final BCLBiome WARPED_FOREST_BIOME = registerNetherBiome(getFromRegistry(Biomes.WARPED_FOREST)); - public static final BCLBiome SOUL_SAND_VALLEY_BIOME = registerNetherBiome(getFromRegistry(Biomes.SOUL_SAND_VALLEY)); - public static final BCLBiome BASALT_DELTAS_BIOME = registerNetherBiome(getFromRegistry(Biomes.BASALT_DELTAS)); + public static final BCLBiome NETHER_WASTES_BIOME = registerNetherBiome(getFromRegistry(Biomes.NETHER_WASTES).value()); + public static final BCLBiome CRIMSON_FOREST_BIOME = registerNetherBiome(getFromRegistry(Biomes.CRIMSON_FOREST).value()); + public static final BCLBiome WARPED_FOREST_BIOME = registerNetherBiome(getFromRegistry(Biomes.WARPED_FOREST).value()); + public static final BCLBiome SOUL_SAND_VALLEY_BIOME = registerNetherBiome(getFromRegistry(Biomes.SOUL_SAND_VALLEY).value()); + public static final BCLBiome BASALT_DELTAS_BIOME = registerNetherBiome(getFromRegistry(Biomes.BASALT_DELTAS).value()); - public static final BCLBiome THE_END = registerEndLandBiome(getFromRegistry(Biomes.THE_END)); - public static final BCLBiome END_MIDLANDS = registerSubBiome(THE_END, getFromRegistry(Biomes.END_MIDLANDS), 0.5F); - public static final BCLBiome END_HIGHLANDS = registerSubBiome(THE_END, getFromRegistry(Biomes.END_HIGHLANDS), 0.5F); - - public static final BCLBiome END_BARRENS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("end_barrens"))); - public static final BCLBiome SMALL_END_ISLANDS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("small_end_islands"))); + public static final BCLBiome THE_END = registerEndLandBiome(getFromRegistry(Biomes.THE_END).value()); + public static final BCLBiome END_MIDLANDS = registerSubBiome(THE_END, getFromRegistry(Biomes.END_MIDLANDS).value(), 0.5F); + public static final BCLBiome END_HIGHLANDS = registerSubBiome(THE_END, getFromRegistry(Biomes.END_HIGHLANDS).value(), 0.5F); + public static final BCLBiome END_BARRENS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("end_barrens")).value()); + public static final BCLBiome SMALL_END_ISLANDS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("small_end_islands")).value()); + private static void initFeatureOrder() { if (!FEATURE_ORDER.isEmpty()) { return; @@ -113,7 +114,7 @@ public class BiomeAPI { .map(biome -> (BiomeGenerationSettingsAccessor) biome.getGenerationSettings()) .map(BiomeGenerationSettingsAccessor::bclib_getFeatures) .forEach(stepFeatureSuppliers -> stepFeatureSuppliers.forEach(step -> step.forEach(featureSupplier -> { - PlacedFeature feature = featureSupplier.get(); + PlacedFeature feature = featureSupplier.value(); FEATURE_ORDER.computeIfAbsent(feature, f -> FEATURE_ORDER_ID.getAndIncrement()); }))); } @@ -122,7 +123,7 @@ public class BiomeAPI { * Initialize registry for current server. * @param biomeRegistry - {@link Registry} for {@link Biome}. */ - public static void initRegistry(Registry biomeRegistry) { + public static void initRegistry(Registry> biomeRegistry) { if (biomeRegistry != BiomeAPI.biomeRegistry) { BiomeAPI.biomeRegistry = biomeRegistry; CLIENT.clear(); @@ -185,7 +186,7 @@ public class BiomeAPI { MHelper.randRange(-1.5F, 1.5F, random), random.nextFloat() ); - ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).orElseThrow(); + ResourceKey key = BiomeAPI.getBiomeKeyOrThrow(biome.getBiomeHolder()); NetherBiomeData.addNetherBiome(key, parameters); return biome; } @@ -215,7 +216,7 @@ public class BiomeAPI { END_LAND_BIOME_PICKER.addBiome(biome); float weight = biome.getGenChance(); - ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).orElseThrow(); + ResourceKey key = BiomeAPI.getBiomeKey(biome.getBiome()); TheEndBiomeData.addEndBiomeReplacement(Biomes.END_HIGHLANDS, key, weight); TheEndBiomeData.addEndBiomeReplacement(Biomes.END_MIDLANDS, key, weight); return biome; @@ -261,7 +262,7 @@ public class BiomeAPI { END_VOID_BIOME_PICKER.addBiome(biome); float weight = biome.getGenChance(); - ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).orElseThrow(); + ResourceKey key = BiomeAPI.getBiomeKeyOrThrow(biome.getBiomeHolder()); TheEndBiomeData.addEndBiomeReplacement(Biomes.SMALL_END_ISLANDS, key, weight); return biome; } @@ -300,7 +301,7 @@ public class BiomeAPI { * @param biome - {@link Biome} from world. * @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}. */ - public static BCLBiome getFromBiome(Biome biome) { + public static BCLBiome getFromBiome(Holder biome) { if (biomeRegistry == null) { return EMPTY_BIOME; } @@ -333,7 +334,7 @@ public class BiomeAPI { public static ResourceKey getBiomeKey(Biome biome) { return BuiltinRegistries.BIOME .getResourceKey(biome) - .orElseGet(() -> biomeRegistry != null ? biomeRegistry.getResourceKey(biome).orElse(null) : null); + .orElse(null); } /** @@ -343,9 +344,9 @@ public class BiomeAPI { */ public static ResourceLocation getBiomeID(Biome biome) { ResourceLocation id = BuiltinRegistries.BIOME.getKey(biome); - if (id == null && biomeRegistry != null) { - id = biomeRegistry.getKey(biome); - } + // if (id == null && biomeRegistry != null) { + // id = biomeRegistry.getKey(biome); + //} return id == null ? EMPTY_BIOME.getID() : id; } @@ -361,6 +362,14 @@ public class BiomeAPI { } return null; } + + public static ResourceKey getBiomeKey(Holder biome) { + return biome.unwrapKey().orElse(null); + } + + public static ResourceKey getBiomeKeyOrThrow(Holder biome) { + return biome.unwrapKey().orElseThrow(); + } /** * Get {@link BCLBiome} from given {@link ResourceLocation}. @@ -404,31 +413,31 @@ public class BiomeAPI { public static void loadFabricAPIBiomes() { FabricBiomesData.NETHER_BIOMES.forEach((key) -> { if (!hasBiome(key.location())) { - registerNetherBiome(BuiltinRegistries.BIOME.get(key.location())); + registerNetherBiome(BuiltinRegistries.BIOME.get(key)); } }); FabricBiomesData.END_LAND_BIOMES.forEach((key, weight) -> { if (!hasBiome(key.location())) { - registerEndLandBiome(BuiltinRegistries.BIOME.get(key.location()), weight); + registerEndLandBiome(BuiltinRegistries.BIOME.get(key), weight); } }); FabricBiomesData.END_VOID_BIOMES.forEach((key, weight) -> { if (!hasBiome(key.location())) { - registerEndVoidBiome(BuiltinRegistries.BIOME.get(key.location()), weight); + registerEndVoidBiome(BuiltinRegistries.BIOME.get(key), weight); } }); } @Nullable - public static Biome getFromRegistry(ResourceLocation key) { - return BuiltinRegistries.BIOME.get(key); + public static Holder getFromRegistry(ResourceLocation key) { + return BuiltinRegistries.BIOME.getHolder(ResourceKey.create(Registry.BIOME_REGISTRY, key)).orElseThrow(); } @Nullable - public static Biome getFromRegistry(ResourceKey key) { - return BuiltinRegistries.BIOME.get(key); + public static Holder getFromRegistry(ResourceKey key) { + return BuiltinRegistries.BIOME.getOrCreateHolder(key); } public static boolean isDatapackBiome(ResourceLocation biomeID) { @@ -452,8 +461,8 @@ public class BiomeAPI { * @param dimensionID {@link ResourceLocation} dimension ID, example: Level.OVERWORLD or "minecraft:overworld". * @param modification {@link BiConsumer} with {@link ResourceKey} biome ID and {@link Biome} parameters. */ - public static void registerBiomeModification(ResourceKey dimensionID, BiConsumer modification) { - List> modifications = MODIFICATIONS.computeIfAbsent(dimensionID, k -> Lists.newArrayList()); + public static void registerBiomeModification(ResourceKey dimensionID, BiConsumer> modification) { + List>> modifications = MODIFICATIONS.computeIfAbsent(dimensionID, k -> Lists.newArrayList()); modifications.add(modification); } @@ -461,7 +470,7 @@ public class BiomeAPI { * Registers new biome modification for the Overworld. Will work both for mod and datapack biomes. * @param modification {@link BiConsumer} with {@link ResourceLocation} biome ID and {@link Biome} parameters. */ - public static void registerOverworldBiomeModification(BiConsumer modification) { + public static void registerOverworldBiomeModification(BiConsumer> modification) { registerBiomeModification(Level.OVERWORLD, modification); } @@ -469,7 +478,7 @@ public class BiomeAPI { * Registers new biome modification for the Nether. Will work both for mod and datapack biomes. * @param modification {@link BiConsumer} with {@link ResourceLocation} biome ID and {@link Biome} parameters. */ - public static void registerNetherBiomeModification(BiConsumer modification) { + public static void registerNetherBiomeModification(BiConsumer> modification) { registerBiomeModification(Level.NETHER, modification); } @@ -477,7 +486,7 @@ public class BiomeAPI { * Registers new biome modification for the End. Will work both for mod and datapack biomes. * @param modification {@link BiConsumer} with {@link ResourceLocation} biome ID and {@link Biome} parameters. */ - public static void registerEndBiomeModification(BiConsumer modification) { + public static void registerEndBiomeModification(BiConsumer> modification) { registerBiomeModification(Level.END, modification); } @@ -524,10 +533,10 @@ public class BiomeAPI { } } - List> modifications = MODIFICATIONS.get(level.dimension()); + List>> modifications = MODIFICATIONS.get(level.dimension()); for (Holder biomeHolder : biomes) { if (biomeHolder.isBound()) { - applyModificationsAndUpdateFeatures(modifications, biomeHolder.value()); + applyModificationsAndUpdateFeatures(modifications, biomeHolder); } } @@ -547,7 +556,7 @@ public class BiomeAPI { ((BiomeSourceAccessor) source).bclRebuildFeatures(); } - private static void applyModificationsAndUpdateFeatures(List> modifications, Biome biome) { + private static void applyModificationsAndUpdateFeatures(List>> modifications, Holder biome) { ResourceLocation biomeID = getBiomeID(biome); if (modifications!=null) { modifications.forEach(consumer -> { @@ -567,8 +576,8 @@ public class BiomeAPI { * Create a unique sort order for all Features of the Biome * @param biome The {@link Biome} to sort the features for */ - public static void sortBiomeFeatures(Biome biome) { - BiomeGenerationSettings settings = biome.getGenerationSettings(); + public static void sortBiomeFeatures(Holder biome) { + BiomeGenerationSettings settings = biome.value().getGenerationSettings(); BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) settings; List>> featureList = CollectionsUtil.getMutable(accessor.bclib_getFeatures()); final int size = featureList.size(); @@ -623,7 +632,7 @@ public class BiomeAPI { * @param feature {@link ConfiguredFeature} to add. * */ - public static void addBiomeFeature(Biome biome, BCLFeature feature) { + public static void addBiomeFeature(Holder biome, BCLFeature feature) { addBiomeFeature(biome, feature.getDecoration(), feature.getPlacedFeature()); } @@ -633,7 +642,7 @@ public class BiomeAPI { * @param step a {@link Decoration} step for the feature. * @param featureList {@link ConfiguredFeature} to add. */ - public static void addBiomeFeature(Biome biome, Decoration step, PlacedFeature... featureList) { + public static void addBiomeFeature(Holder biome, Decoration step, Holder... featureList) { addBiomeFeature(biome, step, List.of(featureList)); } @@ -643,12 +652,13 @@ public class BiomeAPI { * @param step a {@link Decoration} step for the feature. * @param featureList List of {@link ConfiguredFeature} to add. */ - private static void addBiomeFeature(Biome biome, Decoration step, List featureList) { - BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings(); - List>> allFeatures = CollectionsUtil.getMutable(accessor.bclib_getFeatures()); + private static void addBiomeFeature(Holder biome, Decoration step, List> featureList) { + BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.value().getGenerationSettings(); + List> allFeatures = CollectionsUtil.getMutable(accessor.bclib_getFeatures()); Set set = CollectionsUtil.getMutable(accessor.bclib_getFeatureSet().get()); - List> features = getFeaturesList(allFeatures, step); + HolderSet features = getFeaturesList(allFeatures, step); for (var feature : featureList) { + features. features.add(() -> feature); set.add(feature); } @@ -659,13 +669,13 @@ public class BiomeAPI { /** * For internal use only! * - * Adds new features to existing biome. Called from {@link #applyModificationsAndUpdateFeatures(List, Biome)} when the Biome is + * Adds new features to existing biome. Called from {@link #applyModificationsAndUpdateFeatures(List, Holder)}} when the Biome is * present in any {@link BiomeSource} * @param biome {@link Biome} to add features in. * @param featureMap Map of {@link ConfiguredFeature} to add. */ - private static void addStepFeaturesToBiome(Biome biome, Map>> featureMap) { - BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings(); + private static void addStepFeaturesToBiome(Holder biome, Map>> featureMap) { + BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.value().getGenerationSettings(); List>> allFeatures = CollectionsUtil.getMutable(accessor.bclib_getFeatures()); Set set = CollectionsUtil.getMutable(accessor.bclib_getFeatureSet().get()); @@ -690,8 +700,8 @@ public class BiomeAPI { */ public static void addBiomeCarver(Biome biome, ConfiguredWorldCarver carver, Carving stage) { BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings(); - Map>>> carvers = CollectionsUtil.getMutable(accessor.bclib_getCarvers()); - List>> carverList = CollectionsUtil.getMutable(carvers.getOrDefault(stage, new ArrayList<>())); + Map>> carvers = CollectionsUtil.getMutable(accessor.bclib_getCarvers()); + HolderSet> carverList = CollectionsUtil.getMutable(carvers.getOrDefault(stage, new ArrayList<>())); carvers.put(stage, carverList); carverList.add(() -> carver); accessor.bclib_setCarvers(carvers); @@ -769,6 +779,10 @@ public class BiomeAPI { return findTopMaterial(getBiome(world.getBiome(pos))); } + public static Optional findTopMaterial(Holder biome){ + return findTopMaterial(getBiome(biome.value())); + } + public static Optional findTopMaterial(Biome biome){ return findTopMaterial(getBiome(biome)); } @@ -784,6 +798,10 @@ public class BiomeAPI { return findUnderMaterial(getBiome(world.getBiome(pos))); } + public static Optional findUnderMaterial(Holder biome){ + return findUnderMaterial(getBiome(biome.value())); + } + public static Optional findUnderMaterial(Biome biome){ return findUnderMaterial(getBiome(biome)); } @@ -887,12 +905,12 @@ public class BiomeAPI { return list; } - private static List> getFeaturesList(List>> features, Decoration step) { + private static HolderSet getFeaturesList(List> features, Decoration step) { int index = step.ordinal(); while (features.size() <= index) { - features.add(Lists.newArrayList()); + features.add(HolderSet.direct(Lists.newArrayList())); } - List> mutable = CollectionsUtil.getMutable(features.get(index)); + HolderSet mutable = features.get(index); features.set(index, mutable); return mutable; } diff --git a/src/main/java/ru/bclib/api/surface/SurfaceRuleBuilder.java b/src/main/java/ru/bclib/api/surface/SurfaceRuleBuilder.java index bd88f2c1..2e6a14c5 100644 --- a/src/main/java/ru/bclib/api/surface/SurfaceRuleBuilder.java +++ b/src/main/java/ru/bclib/api/surface/SurfaceRuleBuilder.java @@ -75,7 +75,7 @@ public class SurfaceRuleBuilder { public SurfaceRuleBuilder subsurface(BlockState state, int depth) { entryInstance = getFromCache("subsurface_" + depth + "_" + state.toString(), () -> { RuleSource rule = SurfaceRules.state(state); - rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(depth, false, false, CaveSurface.FLOOR), rule); + rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(depth, false, CaveSurface.FLOOR), rule); return new SurfaceRuleEntry(3, rule); }); rules.add(entryInstance); @@ -117,7 +117,7 @@ public class SurfaceRuleBuilder { public SurfaceRuleBuilder belowFloor(BlockState state, int height, NoiseCondition noise) { entryInstance = getFromCache("below_floor_" + height + "_" + state.toString() + "_" + noise.getClass().getSimpleName(), () -> { RuleSource rule = SurfaceRules.state(state); - rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(height, false, false, CaveSurface.FLOOR), SurfaceRules.ifTrue(noise, rule)); + rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(height, false, CaveSurface.FLOOR), SurfaceRules.ifTrue(noise, rule)); return new SurfaceRuleEntry(3, rule); }); rules.add(entryInstance); @@ -133,7 +133,7 @@ public class SurfaceRuleBuilder { public SurfaceRuleBuilder belowFloor(BlockState state, int height) { entryInstance = getFromCache("below_floor_" + height + "_" + state.toString(), () -> { RuleSource rule = SurfaceRules.state(state); - rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(height, false, false, CaveSurface.FLOOR), rule); + rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(height, false, CaveSurface.FLOOR), rule); return new SurfaceRuleEntry(3, rule); }); rules.add(entryInstance); @@ -163,7 +163,7 @@ public class SurfaceRuleBuilder { public SurfaceRuleBuilder aboveCeil(BlockState state, int height) { entryInstance = getFromCache("above_ceil_" + height + "_" + state.toString(), () -> { RuleSource rule = SurfaceRules.state(state); - rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(height, false, false, CaveSurface.CEILING), rule); + rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(height, false, CaveSurface.CEILING), rule); return new SurfaceRuleEntry(3, rule); }); rules.add(entryInstance); @@ -179,7 +179,7 @@ public class SurfaceRuleBuilder { public SurfaceRuleBuilder steep(BlockState state, int depth) { entryInstance = getFromCache("steep_" + depth + "_" + state.toString(), () -> { RuleSource rule = SurfaceRules.state(state); - rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(depth, false, false, CaveSurface.FLOOR), rule); + rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(depth, false, CaveSurface.FLOOR), rule); rule = SurfaceRules.ifTrue(SurfaceRules.steep(), rule); int priority = depth < 1 ? 0 : 1; return new SurfaceRuleEntry(priority, rule); diff --git a/src/main/java/ru/bclib/blocks/BaseCropBlock.java b/src/main/java/ru/bclib/blocks/BaseCropBlock.java index 72f7f20a..007db2b3 100644 --- a/src/main/java/ru/bclib/blocks/BaseCropBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseCropBlock.java @@ -39,7 +39,8 @@ public class BaseCropBlock extends BasePlantBlock { public BaseCropBlock(Item drop, Block... terrain) { this( FabricBlockSettings.of(Material.PLANT) - .breakByHand(true) + //TODO: 1.18.2 Check if this is still ok + //.breakByHand(true) .sound(SoundType.GRASS) .randomTicks() .noCollission(), diff --git a/src/main/java/ru/bclib/blocks/BaseDoublePlantBlock.java b/src/main/java/ru/bclib/blocks/BaseDoublePlantBlock.java index 02ae6b35..49b2e34b 100644 --- a/src/main/java/ru/bclib/blocks/BaseDoublePlantBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseDoublePlantBlock.java @@ -31,6 +31,7 @@ import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.RenderLayerProvider; +import ru.bclib.items.tool.BaseShearsItem; import ru.bclib.util.BlocksHelper; import java.util.List; @@ -54,7 +55,8 @@ public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements R public BaseDoublePlantBlock(int light) { this( FabricBlockSettings.of(Material.PLANT) - .breakByHand(true) + //TODO: 1.18.2 Check if this is still ok + //.breakByHand(true) .sound(SoundType.GRASS) .lightLevel((state) -> state.getValue(TOP) ? light : 0) .noCollission() @@ -117,7 +119,8 @@ public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements R } ItemStack tool = builder.getParameter(LootContextParams.TOOL); - if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel( + //TODO: 1.18.2 Test if shearing still works + if (tool != null && BaseShearsItem.isShear(tool) || EnchantmentHelper.getItemEnchantmentLevel( Enchantments.SILK_TOUCH, tool ) > 0) { diff --git a/src/main/java/ru/bclib/blocks/BasePlantBlock.java b/src/main/java/ru/bclib/blocks/BasePlantBlock.java index eaffbcdc..a036fdc1 100644 --- a/src/main/java/ru/bclib/blocks/BasePlantBlock.java +++ b/src/main/java/ru/bclib/blocks/BasePlantBlock.java @@ -39,6 +39,7 @@ import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.RenderLayerProvider; import ru.bclib.interfaces.TagProvider; +import ru.bclib.items.tool.BaseShearsItem; import java.util.List; import java.util.Optional; @@ -70,7 +71,8 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderL this( FabricBlockSettings .of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT) - .breakByHand(true) + //TODO: 1.18.2 Check if this is still ok + //.breakByHand(true) .luminance(light) .sound(SoundType.GRASS) .noCollission() @@ -116,7 +118,8 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderL @Override public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); - if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel( + //TODO: 1.18.2 Test if shearing still works + if (tool != null && BaseShearsItem.isShear(tool) || EnchantmentHelper.getItemEnchantmentLevel( Enchantments.SILK_TOUCH, tool ) > 0) { diff --git a/src/main/java/ru/bclib/blocks/BasePlantWithAgeBlock.java b/src/main/java/ru/bclib/blocks/BasePlantWithAgeBlock.java index 3beb20d8..56f8b375 100644 --- a/src/main/java/ru/bclib/blocks/BasePlantWithAgeBlock.java +++ b/src/main/java/ru/bclib/blocks/BasePlantWithAgeBlock.java @@ -20,7 +20,8 @@ public abstract class BasePlantWithAgeBlock extends BasePlantBlock { public BasePlantWithAgeBlock() { this( FabricBlockSettings.of(Material.PLANT) - .breakByHand(true) + //TODO: 1.18.2 Check if this is still ok + //.breakByHand(true) .sound(SoundType.GRASS) .randomTicks() .noCollission() diff --git a/src/main/java/ru/bclib/blocks/BaseUnderwaterWallPlantBlock.java b/src/main/java/ru/bclib/blocks/BaseUnderwaterWallPlantBlock.java index e8fc1233..d45fb308 100644 --- a/src/main/java/ru/bclib/blocks/BaseUnderwaterWallPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseUnderwaterWallPlantBlock.java @@ -18,7 +18,8 @@ public abstract class BaseUnderwaterWallPlantBlock extends BaseWallPlantBlock im this( FabricBlockSettings .of(Material.WATER_PLANT) - .breakByHand(true) + //TODO: 1.18.2 Check if this is still ok + //.breakByHand(true) .sound(SoundType.WET_GRASS) .noCollission() ); @@ -28,7 +29,8 @@ public abstract class BaseUnderwaterWallPlantBlock extends BaseWallPlantBlock im this( FabricBlockSettings .of(Material.WATER_PLANT) - .breakByHand(true) + //TODO: 1.18.2 Check if this is still ok + //.breakByHand(true) .luminance(light) .sound(SoundType.WET_GRASS) .noCollission() diff --git a/src/main/java/ru/bclib/blocks/BaseVineBlock.java b/src/main/java/ru/bclib/blocks/BaseVineBlock.java index 2b36688c..0f20c3a7 100644 --- a/src/main/java/ru/bclib/blocks/BaseVineBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseVineBlock.java @@ -30,6 +30,7 @@ import net.minecraft.world.phys.shapes.VoxelShape; import ru.bclib.blocks.BlockProperties.TripleShape; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.RenderLayerProvider; +import ru.bclib.items.tool.BaseShearsItem; import ru.bclib.util.BlocksHelper; import java.util.List; @@ -110,7 +111,8 @@ public class BaseVineBlock extends BaseBlockNotFull implements RenderLayerProvid @Override public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); - if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel( + //TODO: Test if shearing still works + if (tool != null && BaseShearsItem.isShear(tool) || EnchantmentHelper.getItemEnchantmentLevel( Enchantments.SILK_TOUCH, tool ) > 0) { diff --git a/src/main/java/ru/bclib/blocks/BaseWallPlantBlock.java b/src/main/java/ru/bclib/blocks/BaseWallPlantBlock.java index 54e8dbd3..7157dd1e 100644 --- a/src/main/java/ru/bclib/blocks/BaseWallPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseWallPlantBlock.java @@ -39,7 +39,8 @@ public abstract class BaseWallPlantBlock extends BasePlantBlock { this( FabricBlockSettings .of(Material.PLANT) - .breakByHand(true) + //TODO: 1.18.2 Check if this is still ok + //.breakByHand(true) .sound(SoundType.GRASS) .noCollission() ); @@ -49,7 +50,8 @@ public abstract class BaseWallPlantBlock extends BasePlantBlock { this( FabricBlockSettings .of(Material.PLANT) - .breakByHand(true) + //TODO: 1.18.2 Check if this is still ok + //.breakByHand(true) .luminance(light) .sound(SoundType.GRASS) .noCollission() diff --git a/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java b/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java index dfee5df8..f8b91d65 100644 --- a/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java +++ b/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java @@ -44,7 +44,8 @@ public class FeatureSaplingBlock extends SaplingBlock implements RenderLayerProv public FeatureSaplingBlock(Function> featureSupplier) { this(FabricBlockSettings.of(Material.PLANT) - .breakByHand(true) + //TODO: 1.18.2 Check if this is still ok + //.breakByHand(true) .collidable(false) .instabreak() .sound(SoundType.GRASS) @@ -55,7 +56,8 @@ public class FeatureSaplingBlock extends SaplingBlock implements RenderLayerProv public FeatureSaplingBlock(int light, Function> featureSupplier) { this(FabricBlockSettings.of(Material.PLANT) - .breakByHand(true) + //TODO: 1.18.2 Check if this is still ok + //.breakByHand(true) .collidable(false) .luminance(light) .instabreak() diff --git a/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java b/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java index 5f71bf5d..746c6470 100644 --- a/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java @@ -35,6 +35,7 @@ import ru.bclib.api.tag.TagAPI.TagLocation; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.RenderLayerProvider; import ru.bclib.interfaces.TagProvider; +import ru.bclib.items.tool.BaseShearsItem; import java.util.List; import java.util.Random; @@ -57,7 +58,8 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements R this( FabricBlockSettings .of(Material.WATER_PLANT) - .breakByHand(true) + //TODO: 1.18.2 Check if this is still ok + //.breakByHand(true) .luminance(light) .sound(SoundType.WET_GRASS) .noCollission() @@ -105,7 +107,8 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements R @Override public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); - if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel( + //TODO: Test is shearing still works + if (tool != null && BaseShearsItem.isShear(tool) || EnchantmentHelper.getItemEnchantmentLevel( Enchantments.SILK_TOUCH, tool ) > 0) { diff --git a/src/main/java/ru/bclib/blocks/UnderwaterPlantWithAgeBlock.java b/src/main/java/ru/bclib/blocks/UnderwaterPlantWithAgeBlock.java index e5ba1b6b..c22473b3 100644 --- a/src/main/java/ru/bclib/blocks/UnderwaterPlantWithAgeBlock.java +++ b/src/main/java/ru/bclib/blocks/UnderwaterPlantWithAgeBlock.java @@ -20,7 +20,8 @@ public abstract class UnderwaterPlantWithAgeBlock extends UnderwaterPlantBlock { super( FabricBlockSettings .of(Material.WATER_PLANT) - .breakByHand(true) + //TODO: 1.18.2 Check if this is still ok + //.breakByHand(true) .sound(SoundType.WET_GRASS) .randomTicks() .noCollission() diff --git a/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java b/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java index 9fdfe7e6..cb60d0a6 100644 --- a/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java @@ -29,6 +29,7 @@ import ru.bclib.api.tag.TagAPI.TagLocation; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.RenderLayerProvider; import ru.bclib.interfaces.TagProvider; +import ru.bclib.items.tool.BaseShearsItem; import java.util.List; @@ -83,7 +84,8 @@ public abstract class UpDownPlantBlock extends BaseBlockNotFull implements Rende @Override public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); - if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel( + //TODO: 1.18.2 Test if shearing still works + if (tool != null && BaseShearsItem.isShear(tool) || EnchantmentHelper.getItemEnchantmentLevel( Enchantments.SILK_TOUCH, tool ) > 0) { diff --git a/src/main/java/ru/bclib/blocks/WallMushroomBlock.java b/src/main/java/ru/bclib/blocks/WallMushroomBlock.java index 6c3379a0..8118b099 100644 --- a/src/main/java/ru/bclib/blocks/WallMushroomBlock.java +++ b/src/main/java/ru/bclib/blocks/WallMushroomBlock.java @@ -19,7 +19,8 @@ public abstract class WallMushroomBlock extends BaseWallPlantBlock { this( FabricBlockSettings .of(Material.PLANT) - .breakByHand(true) + //TODO: 1.18.2 Check if this is still ok + //..breakByHand(true) .luminance(light) .destroyTime(0.2F) .sound(SoundType.GRASS) diff --git a/src/main/java/ru/bclib/client/render/CustomFogRenderer.java b/src/main/java/ru/bclib/client/render/CustomFogRenderer.java index 39291fe9..76a72637 100644 --- a/src/main/java/ru/bclib/client/render/CustomFogRenderer.java +++ b/src/main/java/ru/bclib/client/render/CustomFogRenderer.java @@ -108,12 +108,12 @@ public class CustomFogRenderer { } private static boolean shouldIgnore(Level level, int x, int y, int z) { - Biome biome = level.getBiome(MUT_POS.set(x, y, z)); + Biome biome = level.getBiome(MUT_POS.set(x, y, z)).value(); return BiomeAPI.getRenderBiome(biome) == BiomeAPI.EMPTY_BIOME; } private static float getFogDensityI(Level level, int x, int y, int z) { - Biome biome = level.getBiome(MUT_POS.set(x, y, z)); + Biome biome = level.getBiome(MUT_POS.set(x, y, z)).value(); BCLBiome renderBiome = BiomeAPI.getRenderBiome(biome); return renderBiome.getFogDensity(); } diff --git a/src/main/java/ru/bclib/integration/ModIntegration.java b/src/main/java/ru/bclib/integration/ModIntegration.java index ddfb76a6..8ff8ea63 100644 --- a/src/main/java/ru/bclib/integration/ModIntegration.java +++ b/src/main/java/ru/bclib/integration/ModIntegration.java @@ -1,6 +1,7 @@ package ru.bclib.integration; import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceKey; @@ -37,6 +38,10 @@ public abstract class ModIntegration { public ResourceLocation getID(String name) { return new ResourceLocation(modID, name); } + + public ResourceKey getFeatureKey(String name) { + return ResourceKey.create(Registry.PLACED_FEATURE_REGISTRY, getID(name)); + } public Block getBlock(String name) { return Registry.BLOCK.get(getID(name)); @@ -61,7 +66,7 @@ public abstract class ModIntegration { public BCLFeature getFeature(String featureID, String placedFeatureID, GenerationStep.Decoration featureStep) { ResourceLocation id = getID(featureID); Feature feature = Registry.FEATURE.get(id); - PlacedFeature featureConfigured = BuiltinRegistries.PLACED_FEATURE.get(getID(placedFeatureID)); + Holder featureConfigured = BuiltinRegistries.PLACED_FEATURE.getHolder(getFeatureKey(placedFeatureID)).orElse(null); return new BCLFeature(id, feature, featureStep, featureConfigured); } diff --git a/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java b/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java index 92e3d099..62e0b156 100644 --- a/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java +++ b/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java @@ -1,5 +1,6 @@ package ru.bclib.mixin.common; +import net.minecraft.core.HolderSet; import net.minecraft.world.level.biome.BiomeGenerationSettings; import net.minecraft.world.level.levelgen.GenerationStep; import net.minecraft.world.level.levelgen.GenerationStep.Carving; @@ -17,11 +18,11 @@ import java.util.function.Supplier; @Mixin(BiomeGenerationSettings.class) public interface BiomeGenerationSettingsAccessor { @Accessor("features") - List>> bclib_getFeatures(); + List> bclib_getFeatures(); @Accessor("features") @Mutable - void bclib_setFeatures(List>> value); + void bclib_setFeatures(List> value); @Accessor("featureSet") Supplier> bclib_getFeatureSet(); @@ -30,8 +31,8 @@ public interface BiomeGenerationSettingsAccessor { void bclib_setFeatureSet(Supplier> features); @Accessor("carvers") - Map>>> bclib_getCarvers(); + Map>> bclib_getCarvers(); @Accessor("carvers") - void bclib_setCarvers(Map>>> features); + void bclib_setCarvers(Map>> features); } diff --git a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java index 1bd6050d..15d46beb 100644 --- a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java +++ b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java @@ -1,5 +1,6 @@ package ru.bclib.mixin.common; +import net.minecraft.core.Holder; import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; @@ -9,6 +10,7 @@ import net.minecraft.world.level.CustomSpawner; import net.minecraft.world.level.Level; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.dimension.DimensionType; +import net.minecraft.world.level.storage.LevelStorageSource; import net.minecraft.world.level.storage.LevelStorageSource.LevelStorageAccess; import net.minecraft.world.level.storage.ServerLevelData; import net.minecraft.world.level.storage.WritableLevelData; @@ -28,12 +30,12 @@ import java.util.function.Supplier; public abstract class ServerLevelMixin extends Level { private static String bclib_lastWorld = null; - protected ServerLevelMixin(WritableLevelData writableLevelData, ResourceKey resourceKey, DimensionType dimensionType, Supplier supplier, boolean bl, boolean bl2, long l) { + protected ServerLevelMixin(WritableLevelData writableLevelData, ResourceKey resourceKey, Holder dimensionType, Supplier supplier, boolean bl, boolean bl2, long l) { super(writableLevelData, resourceKey, dimensionType, supplier, bl, bl2, l); } @Inject(method = "*", at = @At("TAIL")) - private void bclib_onServerWorldInit(MinecraftServer server, Executor executor, LevelStorageAccess levelStorageAccess, ServerLevelData serverLevelData, ResourceKey resourceKey, DimensionType dimensionType, ChunkProgressListener chunkProgressListener, ChunkGenerator chunkGenerator, boolean bl, long l, List list, boolean bl2, CallbackInfo info) { + private void bclib_onServerWorldInit(MinecraftServer server, Executor executor, LevelStorageAccess levelStorageAccess, ServerLevelData serverLevelData, ResourceKey resourceKey, Holder dimensionType, ChunkProgressListener chunkProgressListener, ChunkGenerator chunkGenerator, boolean bl, long l, List list, boolean bl2, CallbackInfo ci) { ServerLevel level = ServerLevel.class.cast(this); LifeCycleAPI._runLevelLoad(level, server, executor, levelStorageAccess, serverLevelData, resourceKey, dimensionType, chunkProgressListener, chunkGenerator, bl, l, list, bl2); diff --git a/src/main/java/ru/bclib/recipes/AnvilRecipe.java b/src/main/java/ru/bclib/recipes/AnvilRecipe.java index 28343417..495b95b2 100644 --- a/src/main/java/ru/bclib/recipes/AnvilRecipe.java +++ b/src/main/java/ru/bclib/recipes/AnvilRecipe.java @@ -5,11 +5,13 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.core.NonNullList; +import net.minecraft.core.Registry; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.TagParser; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.Tag; +import net.minecraft.tags.TagKey; import net.minecraft.util.GsonHelper; import net.minecraft.world.Container; import net.minecraft.world.InteractionHand; @@ -116,7 +118,8 @@ public class AnvilRecipe implements Recipe, UnknownReceipBookCategory public boolean matches(Container craftingInventory) { ItemStack hammer = craftingInventory.getItem(1); - if (hammer.isEmpty() || !CommonItemTags.HAMMERS.contains(hammer.getItem())) { + //TODO: 1.18.2 Test if hammer still works + if (hammer.isEmpty() || !hammer.is(CommonItemTags.HAMMERS)) { return false; } ItemStack material = craftingInventory.getItem(0); @@ -209,7 +212,7 @@ public class AnvilRecipe implements Recipe, UnknownReceipBookCategory return this; } - public Builder setInput(Tag inputTag) { + public Builder setInput(TagKey inputTag) { this.setInput(Ingredient.of(inputTag)); return this; } diff --git a/src/main/java/ru/bclib/recipes/GridRecipe.java b/src/main/java/ru/bclib/recipes/GridRecipe.java index 4a1c6155..3af5b4d1 100644 --- a/src/main/java/ru/bclib/recipes/GridRecipe.java +++ b/src/main/java/ru/bclib/recipes/GridRecipe.java @@ -4,6 +4,7 @@ import com.google.common.collect.Maps; import net.minecraft.core.NonNullList; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.Tag; +import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.CraftingRecipe; @@ -74,7 +75,7 @@ public class GridRecipe { return this; } - public GridRecipe addMaterial(char key, Tag value) { + public GridRecipe addMaterial(char key, TagKey value) { return addMaterial(key, Ingredient.of(value)); } diff --git a/src/main/java/ru/bclib/recipes/SmithingTableRecipe.java b/src/main/java/ru/bclib/recipes/SmithingTableRecipe.java index dc9ad9b7..a981d18a 100644 --- a/src/main/java/ru/bclib/recipes/SmithingTableRecipe.java +++ b/src/main/java/ru/bclib/recipes/SmithingTableRecipe.java @@ -2,6 +2,7 @@ package ru.bclib.recipes; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.Tag; +import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; @@ -59,7 +60,7 @@ public class SmithingTableRecipe { return this; } - public SmithingTableRecipe setBase(Tag tag) { + public SmithingTableRecipe setBase(TagKey tag) { this.base = (Ingredient.of(tag)); return this; } @@ -70,7 +71,7 @@ public class SmithingTableRecipe { return this; } - public SmithingTableRecipe setAddition(Tag tag) { + public SmithingTableRecipe setAddition(TagKey tag) { this.addition = (Ingredient.of(tag)); return this; } diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiome.java b/src/main/java/ru/bclib/world/biomes/BCLBiome.java index bbfdafaa..c2bdca7b 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiome.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiome.java @@ -2,6 +2,7 @@ package ru.bclib.world.biomes; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceKey; @@ -31,9 +32,9 @@ public class BCLBiome extends BCLBiomeSettings { private final ResourceLocation biomeID; private final Biome biome; - private Consumer surfaceInit; + private Consumer> surfaceInit; private BCLBiome biomeParent; - private Biome actualBiome; + private Holder actualBiome; /** * Create wrapper for existing biome using its {@link ResourceLocation} identifier. @@ -65,7 +66,7 @@ public class BCLBiome extends BCLBiomeSettings { * @param settings The Settings for this Biome or {@code null} if you want to apply default settings */ public BCLBiome(Biome biome, VanillaBiomeSettings settings) { - this(BuiltinRegistries.BIOME.getKey(biome), biome, settings); + this(BiomeAPI.getBiomeID(biome), biome, settings); } public BCLBiome(ResourceLocation biomeID, Biome biome) { @@ -164,7 +165,10 @@ public class BCLBiome extends BCLBiomeSettings { return biomeID; } - + + public Holder getBiomeHolder() { + return BuiltinRegistries.BIOME.getOrCreateHolder(BiomeAPI.getBiomeKey(biome)); + } /** * Getter for biome from buil-in registry. For datapack biomes will be same as actual biome. * @return {@link Biome}. @@ -177,7 +181,7 @@ public class BCLBiome extends BCLBiomeSettings { * Getter for actual biome (biome from current world registry with same {@link ResourceLocation} id). * @return {@link Biome}. */ - public Biome getActualBiome() { + public Holder getActualBiome() { return this.actualBiome; } @@ -196,7 +200,7 @@ public class BCLBiome extends BCLBiomeSettings { if (edge != null && edge != this) { edge.updateActualBiomes(biomeRegistry); } - this.actualBiome = biomeRegistry.get(biomeID); + this.actualBiome = biomeRegistry.getHolder(ResourceKey.create(Registry.BIOME_REGISTRY, biomeID)).orElse(null); if (actualBiome==null) { BCLib.LOGGER.error("Unable to find actual Biome for " + biomeID); } diff --git a/src/main/java/ru/bclib/world/features/BCLFeature.java b/src/main/java/ru/bclib/world/features/BCLFeature.java index 8c649c43..33e4ef3a 100644 --- a/src/main/java/ru/bclib/world/features/BCLFeature.java +++ b/src/main/java/ru/bclib/world/features/BCLFeature.java @@ -5,32 +5,25 @@ import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.block.Block; import net.minecraft.world.level.levelgen.GenerationStep.Decoration; -import net.minecraft.world.level.levelgen.VerticalAnchor; import net.minecraft.world.level.levelgen.feature.Feature; -import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration; -import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; -import net.minecraft.world.level.levelgen.placement.HeightRangePlacement; import net.minecraft.world.level.levelgen.placement.PlacedFeature; -import net.minecraft.world.level.levelgen.placement.PlacementModifier; -import ru.bclib.api.features.BCLCommonFeatures; import java.util.Map.Entry; import java.util.Optional; public class BCLFeature { - private PlacedFeature placedFeature; + private Holder placedFeature; private Decoration featureStep; private Feature feature; - public BCLFeature(ResourceLocation id, Feature feature, Decoration featureStep, PlacedFeature placedFeature) { + public BCLFeature(ResourceLocation id, Feature feature, Decoration featureStep, Holder placedFeature) { this.placedFeature = placedFeature; this.featureStep = featureStep; this.feature = feature; if (!BuiltinRegistries.PLACED_FEATURE.containsKey(id)) { - Registry.register(BuiltinRegistries.PLACED_FEATURE, id, placedFeature); + Registry.register(BuiltinRegistries.PLACED_FEATURE, id, placedFeature.value()); } if (!Registry.FEATURE.containsKey(id) && !containsObj(Registry.FEATURE, feature)) { Registry.register(Registry.FEATURE, id, feature); @@ -58,7 +51,7 @@ public class BCLFeature { * Get configured feature. * @return {@link PlacedFeature}. */ - public PlacedFeature getPlacedFeature() { + public Holder getPlacedFeature() { return placedFeature; } @@ -69,92 +62,4 @@ public class BCLFeature { public Decoration getDecoration() { return featureStep; } - - /** - * Deprecated, use function from {@link BCLCommonFeatures} instead. - */ - @Deprecated(forRemoval = true) - public static BCLFeature makeVegetationFeature(ResourceLocation id, Feature feature, int density) { - return BCLCommonFeatures.makeVegetationFeature(id, feature, density); - } - - /** - * Deprecated, use function from {@link BCLCommonFeatures} instead. - */ - @Deprecated(forRemoval = true) - public static BCLFeature makeVegetationFeature(ResourceLocation id, Feature feature, int density, boolean allHeight) { - return BCLCommonFeatures.makeVegetationFeature(id, feature, density, allHeight); - } - - /** - * Deprecated, moved to {@link BCLCommonFeatures}. Will be completely removed. - */ - @Deprecated(forRemoval = true) - public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, Block hostBlock, int veins, int veinSize, float airDiscardChance, VerticalAnchor minY, VerticalAnchor maxY, boolean rare) { - return BCLCommonFeatures.makeOreFeature(id, blockOre, hostBlock, veins, veinSize, airDiscardChance, HeightRangePlacement.uniform(minY, maxY), rare); - } - - /** - * Deprecated, moved to {@link BCLCommonFeatures}. Will be completely removed. - */ - @Deprecated(forRemoval = true) - public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, Block hostBlock, int veins, int veinSize, VerticalAnchor minY, VerticalAnchor maxY, boolean rare) { - return BCLCommonFeatures.makeOreFeature(id, blockOre, hostBlock, veins, veinSize, 0.0f, HeightRangePlacement.uniform(minY, maxY), rare); - } - - /** - * Deprecated, use function from {@link BCLCommonFeatures} instead. - */ - @Deprecated(forRemoval = true) - public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, Block hostBlock, int veins, int veinSize, float airDiscardChance, PlacementModifier placement, boolean rare) { - return BCLCommonFeatures.makeOreFeature(id, blockOre, hostBlock, veins, veinSize, airDiscardChance, placement, rare); - } - - /** - * Deprecated, use function from {@link BCLCommonFeatures} instead. - */ - @Deprecated(forRemoval = true) - public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, Block hostBlock, int veins, int veinSize, PlacementModifier placement, boolean rare) { - return BCLCommonFeatures.makeOreFeature(id, blockOre, hostBlock, veins, veinSize, 0.0f, placement, rare); - } - - /** - * Deprecated, use function from {@link BCLCommonFeatures} instead. - */ - @Deprecated(forRemoval = true) - public static BCLFeature makeChunkFeature(ResourceLocation id, Decoration step, Feature feature) { - return BCLCommonFeatures.makeChunkFeature(id, step, feature); - } - - /** - * Deprecated, use function from {@link BCLCommonFeatures} instead. - */ - @Deprecated(forRemoval = true) - public static BCLFeature makeChancedFeature(ResourceLocation id, Decoration step, Feature feature, int chance) { - return BCLCommonFeatures.makeChancedFeature(id, step, feature, chance); - } - - /** - * Deprecated, use function from {@link BCLCommonFeatures} instead. - */ - @Deprecated(forRemoval = true) - public static BCLFeature makeCountFeature(ResourceLocation id, Decoration step, Feature feature, int count) { - return BCLCommonFeatures.makeCountFeature(id, step, feature, count); - } - - /** - * Deprecated, use {@link ru.bclib.api.features.BCLFeatureBuilder} instead. - * - * Creates and configures new BCLib feature. - * @param id {@link ResourceLocation} feature ID. - * @param step {@link Decoration} feature step. - * @param feature {@link Feature} with {@link NoneFeatureConfiguration} config. - * @param placementModifiers array of {@link PlacementModifier} - * @return new BCLFeature instance. - */ - @Deprecated(forRemoval = true) - public static BCLFeature makeFeature(ResourceLocation id, Decoration step, Feature feature, PlacementModifier... placementModifiers) { - PlacedFeature configured = feature.configured(FeatureConfiguration.NONE).placed(placementModifiers); - return new BCLFeature(id, feature, step, configured); - } } diff --git a/src/main/java/ru/bclib/world/features/NBTStructureFeature.java b/src/main/java/ru/bclib/world/features/NBTStructureFeature.java index 77f51198..77f3eb40 100644 --- a/src/main/java/ru/bclib/world/features/NBTStructureFeature.java +++ b/src/main/java/ru/bclib/world/features/NBTStructureFeature.java @@ -3,6 +3,7 @@ package ru.bclib.world.features; import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos.MutableBlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.Holder; import net.minecraft.core.Vec3i; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtIo; @@ -50,7 +51,7 @@ public abstract class NBTStructureFeature extends DefaultFeature { protected abstract void addStructureData(StructurePlaceSettings data); protected BlockPos getGround(WorldGenLevel world, BlockPos center) { - Biome biome = world.getBiome(center); + Holder biome = world.getBiome(center); ResourceLocation id = BiomeAPI.getBiomeID(biome); if (id.getNamespace().contains("moutain") || id.getNamespace().contains("lake")) { int y = getAverageY(world, center); @@ -148,7 +149,7 @@ public abstract class NBTStructureFeature extends DefaultFeature { if (!isTerrain(stateSt)) { if (merge == TerrainMerge.SURFACE) { boolean isTop = mut.getY() == surfMax && state.getMaterial().isSolidBlocking(); - Biome b = world.getBiome(mut); + Holder b = world.getBiome(mut); BlockState top = (isTop ? BiomeAPI.findTopMaterial(b) : BiomeAPI.findUnderMaterial(b)).orElse(defaultBlock); BlocksHelper.setWithoutUpdate(world, mut, top); } @@ -159,7 +160,7 @@ public abstract class NBTStructureFeature extends DefaultFeature { else { if (isTerrain(state) && state.getMaterial().isSolidBlocking()) { if (merge == TerrainMerge.SURFACE) { - Biome b = world.getBiome(mut); + Holder b = world.getBiome(mut); BlockState bottom = BiomeAPI.findUnderMaterial(b).orElse(defaultBlock); BlocksHelper.setWithoutUpdate(world, mut, bottom); } diff --git a/src/main/java/ru/bclib/world/generator/BCLBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLBiomeSource.java index a329a875..cc3c8b74 100644 --- a/src/main/java/ru/bclib/world/generator/BCLBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLBiomeSource.java @@ -1,5 +1,6 @@ package ru.bclib.world.generator; +import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.BiomeSource; @@ -8,15 +9,15 @@ import ru.bclib.api.biomes.BiomeAPI; import java.util.List; public abstract class BCLBiomeSource extends BiomeSource { - protected final Registry biomeRegistry; + protected final Registry> biomeRegistry; protected final long seed; - private static List preInit(Registry biomeRegistry, List biomes){ + private static List> preInit(Registry> biomeRegistry, List> biomes){ biomes.forEach(biome -> BiomeAPI.sortBiomeFeatures(biome)); return biomes; } - protected BCLBiomeSource(Registry biomeRegistry, long seed, List list) { + protected BCLBiomeSource(Registry> biomeRegistry, long seed, List> list) { super(preInit(biomeRegistry, list)); this.seed = seed; diff --git a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java index 61bec9ee..dd2acbae 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java @@ -2,6 +2,7 @@ package ru.bclib.world.generator; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.resources.RegistryOps; import net.minecraft.resources.ResourceLocation; @@ -19,6 +20,7 @@ import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.config.ConfigKeeper.StringArrayEntry; import ru.bclib.config.Configs; import ru.bclib.interfaces.BiomeMap; +import ru.bclib.mixin.common.BiomeAccessor; import ru.bclib.noise.OpenSimplexNoise; import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.generator.map.hex.HexBiomeMap; @@ -29,14 +31,14 @@ import java.util.List; import java.util.function.Function; public class BCLibEndBiomeSource extends BCLBiomeSource { - public static final Codec CODEC = RecordCodecBuilder.create((instance) -> instance.group(RegistryOps + public static Codec CODEC = RecordCodecBuilder.create((instance) -> instance.group(RegistryOps .retrieveRegistry(Registry.BIOME_REGISTRY).forGetter((theEndBiomeSource) -> theEndBiomeSource.biomeRegistry), Codec.LONG.fieldOf("seed").stable().forGetter((theEndBiomeSource) -> theEndBiomeSource.seed)).apply(instance, instance.stable(BCLibEndBiomeSource::new))); private static final OpenSimplexNoise SMALL_NOISE = new OpenSimplexNoise(8324); private Function endLandFunction; private final SimplexNoise noise; - private final Biome centerBiome; - private final Biome barrens; + private final Holder centerBiome; + private final Holder barrens; private BiomeMap mapLand; private BiomeMap mapVoid; private final Point pos; @@ -49,7 +51,7 @@ public class BCLibEndBiomeSource extends BCLBiomeSource { List includeVoid = Configs.BIOMES_CONFIG.getEntry("force_include", "end_void_biomes", StringArrayEntry.class).getValue(); this.possibleBiomes().forEach(biome -> { - ResourceLocation key = biomeRegistry.getKey(biome); + ResourceLocation key = biomeRegistry.getKey(biome.value()); String group = key.getNamespace() + "." + key.getPath(); if (!BiomeAPI.hasBiome(key)) { @@ -94,8 +96,8 @@ public class BCLibEndBiomeSource extends BCLBiomeSource { this.mapVoid = new HexBiomeMap(seed, GeneratorOptions.getBiomeSizeEndVoid(), BiomeAPI.END_VOID_BIOME_PICKER); } - this.centerBiome = biomeRegistry.getOrThrow(Biomes.THE_END); - this.barrens = biomeRegistry.getOrThrow(Biomes.END_BARRENS); + this.centerBiome = biomeRegistry.getHolderOrThrow(Biomes.THE_END); + this.barrens = biomeRegistry.getHolderOrThrow(Biomes.END_BARRENS); WorldgenRandom chunkRandom = new WorldgenRandom(new LegacyRandomSource(seed)); chunkRandom.consumeCount(17292); @@ -115,9 +117,15 @@ public class BCLibEndBiomeSource extends BCLBiomeSource { if (includeLand.contains(key.toString()) || includeVoid.contains(key.toString())) { return true; } - - if (GeneratorOptions.addEndBiomesByCategory() && biome.getBiomeCategory() == BiomeCategory.THEEND) { - return true; + + final boolean isEndBiome; + if ((Object)biome instanceof BiomeAccessor bacc) { + isEndBiome = bacc.bclib_getBiomeCategory() == BiomeCategory.THEEND; + if (GeneratorOptions.addEndBiomesByCategory() && isEndBiome) { + return true; + } + } else { + isEndBiome = false; } BCLBiome bclBiome = BiomeAPI.getBiome(key); @@ -127,12 +135,12 @@ public class BCLibEndBiomeSource extends BCLBiomeSource { } key = bclBiome.getID(); } - return BiomeAPI.END_LAND_BIOME_PICKER.containsImmutable(key) || BiomeAPI.END_VOID_BIOME_PICKER.containsImmutable(key) || (biome.getBiomeCategory() == BiomeCategory.THEEND && BiomeAPI.isDatapackBiome(key)); + return BiomeAPI.END_LAND_BIOME_PICKER.containsImmutable(key) || BiomeAPI.END_VOID_BIOME_PICKER.containsImmutable(key) || (isEndBiome && BiomeAPI.isDatapackBiome(key)); }).toList(); } @Override - public Biome getNoiseBiome(int biomeX, int biomeY, int biomeZ, Climate.Sampler sampler) { + public Holder getNoiseBiome(int biomeX, int biomeY, int biomeZ, Climate.Sampler sampler) { long posX = biomeX << 2; long posZ = biomeZ << 2; long farEndBiomes = GeneratorOptions.getFarEndBiomes(); diff --git a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java index a7509a95..a102e231 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java @@ -71,7 +71,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource { BiomeAPI.NETHER_BIOME_PICKER.clearMutables(); this.possibleBiomes().forEach(biome -> { - ResourceLocation key = biomeRegistry.getKey(biome); + ResourceLocation key = biomeRegistry.getKey(biome.value()); if (!BiomeAPI.hasBiome(key)) { BCLBiome bclBiome = new BCLBiome(key, biome); diff --git a/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java b/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java index 983bd44c..7b021944 100644 --- a/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java +++ b/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java @@ -94,7 +94,7 @@ public class BCLStructureFeature { return structure; } - public ConfiguredStructureFeature getFeatureConfigured() { + public Holder> getFeatureConfigured() { return featureConfigured; }