From 66e3bf483be89a9a3d84b507029509d3e363e070 Mon Sep 17 00:00:00 2001 From: Frank Date: Sun, 19 Sep 2021 16:51:54 +0200 Subject: [PATCH 01/96] Using Loom 0.9 --- bclib.gradle | 4 ++-- gradle.properties | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bclib.gradle b/bclib.gradle index a65ff5d4..1beb0887 100644 --- a/bclib.gradle +++ b/bclib.gradle @@ -23,8 +23,8 @@ repositories { maven { url 'https://jitpack.io' } } -minecraft { - accessWidener = file("src/main/resources/bclib.accesswidener") +loom { + accessWidenerPath = file("src/main/resources/bclib.accesswidener") } dependencies { diff --git a/gradle.properties b/gradle.properties index c44ce364..2cb7cc32 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx2G #Loom -loom_version=0.8-SNAPSHOT +loom_version=0.9-SNAPSHOT # Fabric Properties # check these on https://fabricmc.net/versions.html From 791db59c18657def16e69d3a8c7c93f7fbb16ca7 Mon Sep 17 00:00:00 2001 From: Frank Date: Sun, 19 Sep 2021 16:57:08 +0200 Subject: [PATCH 02/96] Snapshot versions --- gradle.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 2cb7cc32..2d32f978 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,9 +6,9 @@ loom_version=0.9-SNAPSHOT # Fabric Properties # check these on https://fabricmc.net/versions.html -minecraft_version= 1.17.1 -loader_version= 0.11.6 -fabric_version = 0.39.1+1.17 +minecraft_version= 21w37a +loader_version= 0.11.7 +fabric_version = 0.40.1+1.17 # Mod Properties mod_version = 0.4.1 From 8abcab32ecc7ee2354f57487e3399eaa7e905906 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 23 Sep 2021 15:20:03 +0200 Subject: [PATCH 03/96] Fixed some fabric warnings --- src/main/java/ru/bclib/api/TagAPI.java | 9 ++++++--- .../ru/bclib/blockentities/BaseBarrelBlockEntity.java | 9 +++++---- src/main/java/ru/bclib/blocks/BaseLeavesBlock.java | 2 +- src/main/java/ru/bclib/integration/ModIntegration.java | 9 ++++++--- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/main/java/ru/bclib/api/TagAPI.java b/src/main/java/ru/bclib/api/TagAPI.java index c3b04638..353acd4a 100644 --- a/src/main/java/ru/bclib/api/TagAPI.java +++ b/src/main/java/ru/bclib/api/TagAPI.java @@ -2,7 +2,8 @@ package ru.bclib.api; import com.google.common.collect.Maps; import com.google.common.collect.Sets; -import net.fabricmc.fabric.api.tag.TagRegistry; +import net.fabricmc.fabric.api.tag.TagFactory; +import net.fabricmc.fabric.impl.tag.extension.TagDelegate; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.resources.ResourceManager; @@ -60,7 +61,8 @@ public class TagAPI { */ public static Tag.Named makeTag(Supplier> containerSupplier, ResourceLocation id) { Tag tag = containerSupplier.get().getTag(id); - return tag == null ? TagRegistry.create(id, containerSupplier) : (Named) tag; + //return tag == null ? TagRegistry.create(id, containerSupplier) : (Named) tag; + return tag == null ? new TagDelegate<>(id, containerSupplier) : (Named) tag; } /** @@ -116,7 +118,8 @@ public class TagAPI { public static Tag.Named getMCBlockTag(String name) { ResourceLocation id = new ResourceLocation(name); Tag tag = BlockTags.getAllTags().getTag(id); - return tag == null ? (Named) TagRegistry.block(id) : (Named) tag; + //return tag == null ? (Named) TagRegistry.block(id) : (Named) tag; + return tag == null ? (Named) TagFactory.BLOCK.create(id): (Named) tag; } /** diff --git a/src/main/java/ru/bclib/blockentities/BaseBarrelBlockEntity.java b/src/main/java/ru/bclib/blockentities/BaseBarrelBlockEntity.java index 314503d4..f517d01b 100644 --- a/src/main/java/ru/bclib/blockentities/BaseBarrelBlockEntity.java +++ b/src/main/java/ru/bclib/blockentities/BaseBarrelBlockEntity.java @@ -35,14 +35,15 @@ public class BaseBarrelBlockEntity extends RandomizableContainerBlockEntity { public BaseBarrelBlockEntity(BlockPos blockPos, BlockState blockState) { this(BaseBlockEntities.BARREL, blockPos, blockState); } - - public CompoundTag save(CompoundTag tag) { - super.save(tag); + + @Override + public void saveAdditional(CompoundTag tag) { + super.saveAdditional(tag); if (!this.trySaveLootTable(tag)) { ContainerHelper.saveAllItems(tag, this.inventory); } - return tag; + //return tag; } public void load(CompoundTag tag) { diff --git a/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java b/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java index 4c6861bf..f414b269 100644 --- a/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java @@ -54,7 +54,7 @@ public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, } public BaseLeavesBlock(Block sapling, MaterialColor color, int light) { - super(makeLeaves(color).lightLevel(light)); + super(makeLeaves(color).luminance(light)); this.sapling = sapling; } diff --git a/src/main/java/ru/bclib/integration/ModIntegration.java b/src/main/java/ru/bclib/integration/ModIntegration.java index 869edc61..8597971f 100644 --- a/src/main/java/ru/bclib/integration/ModIntegration.java +++ b/src/main/java/ru/bclib/integration/ModIntegration.java @@ -1,6 +1,6 @@ package ru.bclib.integration; -import net.fabricmc.fabric.api.tag.TagRegistry; +import net.fabricmc.fabric.api.tag.TagFactory; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; @@ -198,12 +198,15 @@ public abstract class ModIntegration { public Tag.Named getItemTag(String name) { ResourceLocation id = getID(name); Tag tag = ItemTags.getAllTags().getTag(id); - return tag == null ? (Named) TagRegistry.item(id) : (Named) tag; + + //return tag == null ? (Named) TagRegistry.item(id) : (Named) tag; + return tag == null ? (Named) TagFactory.ITEM.create(id) : (Named) tag; } public Tag.Named getBlockTag(String name) { ResourceLocation id = getID(name); Tag tag = BlockTags.getAllTags().getTag(id); - return tag == null ? (Named) TagRegistry.block(id) : (Named) tag; + //return tag == null ? (Named) TagRegistry.block(id) : (Named) tag; + return tag == null ? (Named) TagFactory.BLOCK.create(id) : (Named) tag; } } From 23bcbe1977ccb5bce6917b0c6afcd0552adb5b3e Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 23 Sep 2021 16:19:30 +0200 Subject: [PATCH 04/96] Some simple Biome related changes --- src/main/java/ru/bclib/api/BiomeAPI.java | 7 +++++-- .../ru/bclib/complexmaterials/WoodenComplexMaterial.java | 2 +- .../java/ru/bclib/mixin/common/InternalBiomeDataMixin.java | 3 ++- src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java | 4 ++-- .../java/ru/bclib/world/generator/BCLibEndBiomeSource.java | 5 +++-- .../ru/bclib/world/generator/BCLibNetherBiomeSource.java | 5 +++-- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main/java/ru/bclib/api/BiomeAPI.java b/src/main/java/ru/bclib/api/BiomeAPI.java index eb4ff13e..9aef32e0 100644 --- a/src/main/java/ru/bclib/api/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/BiomeAPI.java @@ -11,7 +11,7 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.Biome.ClimateParameters; +import net.minecraft.world.level.biome.Climate; import net.minecraft.world.level.biome.Biomes; import org.jetbrains.annotations.Nullable; import ru.bclib.util.MHelper; @@ -95,11 +95,14 @@ public class BiomeAPI { registerBiome(biome); NETHER_BIOME_PICKER.addBiome(biome); Random random = new Random(biome.getID().hashCode()); - ClimateParameters parameters = new ClimateParameters( + //TODO: did they add depth and scale as two new params here??? + Climate.ParameterPoint parameters = Climate.parameters( MHelper.randRange(-1.5F, 1.5F, random), MHelper.randRange(-1.5F, 1.5F, random), MHelper.randRange(-1.5F, 1.5F, random), MHelper.randRange(-1.5F, 1.5F, random), + 0.0f, + 0.0f, random.nextFloat() ); ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get(); diff --git a/src/main/java/ru/bclib/complexmaterials/WoodenComplexMaterial.java b/src/main/java/ru/bclib/complexmaterials/WoodenComplexMaterial.java index 97a54004..4940f6c1 100644 --- a/src/main/java/ru/bclib/complexmaterials/WoodenComplexMaterial.java +++ b/src/main/java/ru/bclib/complexmaterials/WoodenComplexMaterial.java @@ -75,7 +75,7 @@ public class WoodenComplexMaterial extends ComplexMaterial { @Override protected FabricBlockSettings getBlockSettings() { - return FabricBlockSettings.copyOf(Blocks.OAK_PLANKS).materialColor(planksColor); + return FabricBlockSettings.copyOf(Blocks.OAK_PLANKS).mapColor(planksColor); } @Override diff --git a/src/main/java/ru/bclib/mixin/common/InternalBiomeDataMixin.java b/src/main/java/ru/bclib/mixin/common/InternalBiomeDataMixin.java index 3f0e7c37..ac8d41b4 100644 --- a/src/main/java/ru/bclib/mixin/common/InternalBiomeDataMixin.java +++ b/src/main/java/ru/bclib/mixin/common/InternalBiomeDataMixin.java @@ -4,6 +4,7 @@ import net.fabricmc.fabric.impl.biome.InternalBiomeData; import net.minecraft.resources.ResourceKey; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biomes; +import net.minecraft.world.level.biome.Climate; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -34,7 +35,7 @@ public class InternalBiomeDataMixin { } @Inject(method = "addNetherBiome", at = @At(value = "HEAD")) - private static void bclib_addNetherBiome(ResourceKey biome, Biome.ClimateParameters spawnNoisePoint, CallbackInfo info) { + private static void bclib_addNetherBiome(ResourceKey biome, Climate.ParameterPoint spawnNoisePoint, CallbackInfo info) { FabricBiomesData.NETHER_BIOMES.add(biome); } } diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java index bd661334..af2fd15a 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java @@ -341,8 +341,8 @@ public class BCLBiomeDef { return new Biome.BiomeBuilder().precipitation(precipitation) .biomeCategory(category) - .depth(depth) - .scale(0.2F) + //.depth(depth) //TODO: No longer available in 1.18 + //.scale(0.2F) .temperature(temperature) .downfall(downfall) .specialEffects(effects.build()) diff --git a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java index d5dd9827..6f442b0f 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java @@ -9,6 +9,7 @@ import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome.BiomeCategory; import net.minecraft.world.level.biome.BiomeSource; import net.minecraft.world.level.biome.Biomes; +import net.minecraft.world.level.biome.Climate; import net.minecraft.world.level.biome.TheEndBiomeSource; import net.minecraft.world.level.levelgen.WorldgenRandom; import net.minecraft.world.level.levelgen.synth.SimplexNoise; @@ -46,7 +47,7 @@ public class BCLibEndBiomeSource extends BiomeSource { BiomeAPI.END_LAND_BIOME_PICKER.clearMutables(); BiomeAPI.END_VOID_BIOME_PICKER.clearMutables(); - this.possibleBiomes.forEach(biome -> { + this.possibleBiomes().forEach(biome -> { ResourceLocation key = biomeRegistry.getKey(biome); if (!BiomeAPI.hasBiome(key)) { BCLBiome bclBiome = new BCLBiome(key, biome, 1, 1); @@ -98,7 +99,7 @@ public class BCLibEndBiomeSource extends BiomeSource { } @Override - public Biome getNoiseBiome(int biomeX, int biomeY, int biomeZ) { + public Biome getNoiseBiome(int biomeX, int biomeY, int biomeZ, Climate.Sampler sampler) { long i = (long) biomeX * (long) biomeX; long j = (long) biomeZ * (long) biomeZ; long check = GeneratorOptions.isFarEndBiomes() ? 65536L : 625L; diff --git a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java index 9fdbfbe5..be2e7f8c 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java @@ -8,6 +8,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome.BiomeCategory; import net.minecraft.world.level.biome.BiomeSource; +import net.minecraft.world.level.biome.Climate; import ru.bclib.BCLib; import ru.bclib.api.BiomeAPI; import ru.bclib.world.biomes.BCLBiome; @@ -35,7 +36,7 @@ public class BCLibNetherBiomeSource extends BiomeSource { BiomeAPI.NETHER_BIOME_PICKER.clearMutables(); - this.possibleBiomes.forEach(biome -> { + this.possibleBiomes().forEach(biome -> { ResourceLocation key = biomeRegistry.getKey(biome); if (!BiomeAPI.hasBiome(key)) { BCLBiome bclBiome = new BCLBiome(key, biome, 1, 1); @@ -76,7 +77,7 @@ public class BCLibNetherBiomeSource extends BiomeSource { } @Override - public Biome getNoiseBiome(int biomeX, int biomeY, int biomeZ) { + public Biome getNoiseBiome(int biomeX, int biomeY, int biomeZ, Climate.Sampler sampler) { if ((biomeX & 63) == 0 && (biomeZ & 63) == 0) { biomeMap.clearCache(); } From e2ab77658b8ccfd45daf590dd58c477417596386 Mon Sep 17 00:00:00 2001 From: Frank Date: Sat, 25 Sep 2021 11:36:26 +0200 Subject: [PATCH 05/96] Adapted to soem Fabric API changes --- gradle.properties | 4 +- src/main/java/ru/bclib/api/BiomeAPI.java | 14 +++-- .../ru/bclib/blocks/FeatureSaplingBlock.java | 1 + .../blocks/properties/StringProperty.java | 61 ------------------- .../mixin/common/InternalBiomeDataMixin.java | 41 ------------- .../mixin/common/NetherBiomeDataMixin.java | 19 ++++++ .../mixin/common/TheEndBiomeDataMixin.java | 35 +++++++++++ .../ru/bclib/world/biomes/BCLBiomeDef.java | 1 + .../world/structures/BCLStructureFeature.java | 2 +- .../surface/DoubleBlockSurfaceBuilder.java | 8 +-- src/main/resources/bclib.mixins.common.json | 5 +- 11 files changed, 74 insertions(+), 117 deletions(-) delete mode 100644 src/main/java/ru/bclib/blocks/properties/StringProperty.java delete mode 100644 src/main/java/ru/bclib/mixin/common/InternalBiomeDataMixin.java create mode 100644 src/main/java/ru/bclib/mixin/common/NetherBiomeDataMixin.java create mode 100644 src/main/java/ru/bclib/mixin/common/TheEndBiomeDataMixin.java diff --git a/gradle.properties b/gradle.properties index 2d32f978..58d5cdbe 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,9 +6,9 @@ loom_version=0.9-SNAPSHOT # Fabric Properties # check these on https://fabricmc.net/versions.html -minecraft_version= 21w37a +minecraft_version= 21w38a loader_version= 0.11.7 -fabric_version = 0.40.1+1.17 +fabric_version = 0.40.4+1.18 # Mod Properties mod_version = 0.4.1 diff --git a/src/main/java/ru/bclib/api/BiomeAPI.java b/src/main/java/ru/bclib/api/BiomeAPI.java index 9aef32e0..8639d99c 100644 --- a/src/main/java/ru/bclib/api/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/BiomeAPI.java @@ -3,7 +3,9 @@ package ru.bclib.api; import com.google.common.collect.Maps; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.fabricmc.fabric.impl.biome.InternalBiomeData; +import net.fabricmc.fabric.api.biome.v1.NetherBiomes; +import net.fabricmc.fabric.impl.biome.NetherBiomeData; +import net.fabricmc.fabric.impl.biome.TheEndBiomeData; import net.minecraft.client.Minecraft; import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; @@ -11,8 +13,8 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.Climate; import net.minecraft.world.level.biome.Biomes; +import net.minecraft.world.level.biome.Climate; import org.jetbrains.annotations.Nullable; import ru.bclib.util.MHelper; import ru.bclib.world.biomes.BCLBiome; @@ -106,7 +108,7 @@ public class BiomeAPI { random.nextFloat() ); ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get(); - InternalBiomeData.addNetherBiome(key, parameters); + NetherBiomeData.addNetherBiome(key, parameters); return biome; } @@ -135,8 +137,8 @@ public class BiomeAPI { END_LAND_BIOME_PICKER.addBiome(biome); float weight = biome.getGenChance(); ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get(); - InternalBiomeData.addEndBiomeReplacement(Biomes.END_HIGHLANDS, key, weight); - InternalBiomeData.addEndBiomeReplacement(Biomes.END_MIDLANDS, key, weight); + TheEndBiomeData.addEndBiomeReplacement(Biomes.END_HIGHLANDS, key, weight); + TheEndBiomeData.addEndBiomeReplacement(Biomes.END_MIDLANDS, key, weight); return biome; } @@ -180,7 +182,7 @@ public class BiomeAPI { END_VOID_BIOME_PICKER.addBiome(biome); float weight = biome.getGenChance(); ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get(); - InternalBiomeData.addEndBiomeReplacement(Biomes.SMALL_END_ISLANDS, key, weight); + TheEndBiomeData.addEndBiomeReplacement(Biomes.SMALL_END_ISLANDS, key, weight); return biome; } diff --git a/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java b/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java index 40ea6e02..00805a68 100644 --- a/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java +++ b/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java @@ -91,6 +91,7 @@ public abstract class FeatureSaplingBlock extends SaplingBlock implements Render @Override public void advanceTree(ServerLevel world, BlockPos pos, BlockState blockState, Random random) { FeaturePlaceContext context = new FeaturePlaceContext( + Optional.empty(), world, world.getChunkSource().getGenerator(), random, diff --git a/src/main/java/ru/bclib/blocks/properties/StringProperty.java b/src/main/java/ru/bclib/blocks/properties/StringProperty.java deleted file mode 100644 index 8aaff298..00000000 --- a/src/main/java/ru/bclib/blocks/properties/StringProperty.java +++ /dev/null @@ -1,61 +0,0 @@ -package ru.bclib.blocks.properties; - -import com.google.common.collect.Sets; -import net.minecraft.world.level.block.state.properties.Property; - -import java.util.Collection; -import java.util.Collections; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; - -@Deprecated -public class StringProperty extends Property { - private final Set values; - - public static StringProperty create(String name, String... values) { - return new StringProperty(name, values); - } - - protected StringProperty(String string, String... values) { - super(string, String.class); - this.values = Sets.newHashSet(values); - } - - public void addValue(String name) { - values.add(name); - } - - @Override - public Collection getPossibleValues() { - return Collections.unmodifiableSet(values); - } - - @Override - public String getName(String comparable) { - return comparable; - } - - @Override - public Optional getValue(String string) { - if (values.contains(string)) { - return Optional.of(string); - } - else { - return Optional.empty(); - } - } - - @Override - public int generateHashCode() { - return super.generateHashCode() + Objects.hashCode(values); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof StringProperty that)) return false; - if (!super.equals(o)) return false; - return values.equals(that.values); - } -} diff --git a/src/main/java/ru/bclib/mixin/common/InternalBiomeDataMixin.java b/src/main/java/ru/bclib/mixin/common/InternalBiomeDataMixin.java deleted file mode 100644 index ac8d41b4..00000000 --- a/src/main/java/ru/bclib/mixin/common/InternalBiomeDataMixin.java +++ /dev/null @@ -1,41 +0,0 @@ -package ru.bclib.mixin.common; - -import net.fabricmc.fabric.impl.biome.InternalBiomeData; -import net.minecraft.resources.ResourceKey; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.Biomes; -import net.minecraft.world.level.biome.Climate; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import ru.bclib.world.biomes.FabricBiomesData; - -@Mixin(value = InternalBiomeData.class, remap = false) -public class InternalBiomeDataMixin { - @Inject(method = "addEndBiomeReplacement", at = @At(value = "HEAD")) - private static void bclib_addEndBiomeReplacement(ResourceKey replaced, ResourceKey variant, double weight, CallbackInfo info) { - if (replaced == Biomes.END_BARRENS || replaced == Biomes.SMALL_END_ISLANDS) { - FabricBiomesData.END_VOID_BIOMES.put(variant, (float) weight); - } - else { - FabricBiomesData.END_LAND_BIOMES.put(variant, (float) weight); - } - } - - @Inject(method = "addEndMidlandsReplacement", at = @At(value = "HEAD")) - private static void bclib_addEndMidlandsReplacement(ResourceKey highlands, ResourceKey midlands, double weight, CallbackInfo info) { - FabricBiomesData.END_LAND_BIOMES.put(midlands, (float) weight); - } - - @Inject(method = "addEndBarrensReplacement", at = @At(value = "HEAD")) - private static void bclib_addEndBarrensReplacement(ResourceKey highlands, ResourceKey barrens, double weight, CallbackInfo info) { - FabricBiomesData.END_LAND_BIOMES.put(barrens, (float) weight); - FabricBiomesData.END_VOID_BIOMES.put(barrens, (float) weight); - } - - @Inject(method = "addNetherBiome", at = @At(value = "HEAD")) - private static void bclib_addNetherBiome(ResourceKey biome, Climate.ParameterPoint spawnNoisePoint, CallbackInfo info) { - FabricBiomesData.NETHER_BIOMES.add(biome); - } -} diff --git a/src/main/java/ru/bclib/mixin/common/NetherBiomeDataMixin.java b/src/main/java/ru/bclib/mixin/common/NetherBiomeDataMixin.java new file mode 100644 index 00000000..1a941711 --- /dev/null +++ b/src/main/java/ru/bclib/mixin/common/NetherBiomeDataMixin.java @@ -0,0 +1,19 @@ +package ru.bclib.mixin.common; + +import net.fabricmc.fabric.impl.biome.NetherBiomeData; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.Climate; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import ru.bclib.world.biomes.FabricBiomesData; + +@Mixin(value = NetherBiomeData.class, remap = false) +public class NetherBiomeDataMixin { + @Inject(method = "addNetherBiome", at = @At(value = "HEAD")) + private static void bclib_addNetherBiome(ResourceKey biome, Climate.ParameterPoint spawnNoisePoint, CallbackInfo info) { + FabricBiomesData.NETHER_BIOMES.add(biome); + } +} diff --git a/src/main/java/ru/bclib/mixin/common/TheEndBiomeDataMixin.java b/src/main/java/ru/bclib/mixin/common/TheEndBiomeDataMixin.java new file mode 100644 index 00000000..93bca16f --- /dev/null +++ b/src/main/java/ru/bclib/mixin/common/TheEndBiomeDataMixin.java @@ -0,0 +1,35 @@ +package ru.bclib.mixin.common; + +import net.fabricmc.fabric.impl.biome.TheEndBiomeData; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.Biomes; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import ru.bclib.world.biomes.FabricBiomesData; + +@Mixin(value = TheEndBiomeData.class, remap = false) +public class TheEndBiomeDataMixin { + @Inject(method = "addEndBiomeReplacement", at = @At(value = "HEAD")) + private static void bclib_addEndBiomeReplacement(ResourceKey replaced, ResourceKey variant, double weight, CallbackInfo info) { + if (replaced == Biomes.END_BARRENS || replaced == Biomes.SMALL_END_ISLANDS) { + FabricBiomesData.END_VOID_BIOMES.put(variant, (float) weight); + } + else { + FabricBiomesData.END_LAND_BIOMES.put(variant, (float) weight); + } + } + + @Inject(method = "addEndMidlandsReplacement", at = @At(value = "HEAD")) + private static void bclib_addEndMidlandsReplacement(ResourceKey highlands, ResourceKey midlands, double weight, CallbackInfo info) { + FabricBiomesData.END_LAND_BIOMES.put(midlands, (float) weight); + } + + @Inject(method = "addEndBarrensReplacement", at = @At(value = "HEAD")) + private static void bclib_addEndBarrensReplacement(ResourceKey highlands, ResourceKey barrens, double weight, CallbackInfo info) { + FabricBiomesData.END_LAND_BIOMES.put(barrens, (float) weight); + FabricBiomesData.END_VOID_BIOMES.put(barrens, (float) weight); + } +} diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java index af2fd15a..67247cc2 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java @@ -321,6 +321,7 @@ public class BCLBiomeDef { }); generationSettings.surfaceBuilder(surface == null ? net.minecraft.data.worldgen.SurfaceBuilders.END : surface); + //TODO: Removed now. Seems to part of a registry step per biome now structures.forEach((structure) -> generationSettings.addStructureStart(structure)); features.forEach((info) -> generationSettings.addFeature(info.featureStep, info.feature)); carvers.forEach((info) -> generationSettings.addCarver(info.carverStep, info.carver)); diff --git a/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java b/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java index 4497bfc7..d1fff1d1 100644 --- a/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java +++ b/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java @@ -25,7 +25,7 @@ public class BCLStructureFeature { .register(); this.featureConfigured = this.structure.configured(NoneFeatureConfiguration.NONE); BuiltinRegistries.register(BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE, id, this.featureConfigured); - FlatChunkGeneratorConfigAccessor.getStructureToFeatures().put(this.structure, this.featureConfigured); + FlatLevelGeneratorSettings.getStructureToFeatures().put(this.structure, this.featureConfigured); } public StructureFeature getStructure() { diff --git a/src/main/java/ru/bclib/world/surface/DoubleBlockSurfaceBuilder.java b/src/main/java/ru/bclib/world/surface/DoubleBlockSurfaceBuilder.java index 434b1a39..3a2b1b6d 100644 --- a/src/main/java/ru/bclib/world/surface/DoubleBlockSurfaceBuilder.java +++ b/src/main/java/ru/bclib/world/surface/DoubleBlockSurfaceBuilder.java @@ -5,7 +5,7 @@ import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.chunk.ChunkAccess; +import net.minecraft.world.level.chunk.BlockColumn; import net.minecraft.world.level.levelgen.surfacebuilders.ConfiguredSurfaceBuilder; import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilder; import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderBaseConfiguration; @@ -43,13 +43,13 @@ public class DoubleBlockSurfaceBuilder extends SurfaceBuilder Date: Sat, 25 Sep 2021 13:18:32 +0200 Subject: [PATCH 06/96] Fixed compiler and Startup Errors --- src/main/java/ru/bclib/api/BiomeAPI.java | 2 +- src/main/java/ru/bclib/blocks/BaseSignBlock.java | 2 -- .../ru/bclib/mixin/common/BoneMealItemMixin.java | 2 +- .../{BiomeMixin.java => ChunkGeneratorMixin.java} | 12 +++++++----- src/main/java/ru/bclib/mixin/common/MainMixin.java | 2 +- .../ru/bclib/mixin/common/MinecraftServerMixin.java | 9 --------- src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java | 4 ++-- .../bclib/world/structures/BCLStructureFeature.java | 5 +++-- src/main/resources/bclib.mixins.common.json | 2 +- 9 files changed, 16 insertions(+), 24 deletions(-) rename src/main/java/ru/bclib/mixin/common/{BiomeMixin.java => ChunkGeneratorMixin.java} (61%) diff --git a/src/main/java/ru/bclib/api/BiomeAPI.java b/src/main/java/ru/bclib/api/BiomeAPI.java index 8639d99c..6d8e9536 100644 --- a/src/main/java/ru/bclib/api/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/BiomeAPI.java @@ -97,7 +97,7 @@ public class BiomeAPI { registerBiome(biome); NETHER_BIOME_PICKER.addBiome(biome); Random random = new Random(biome.getID().hashCode()); - //TODO: did they add depth and scale as two new params here??? + //TODO: (1.18) did they add depth and scale as two new params here??? Climate.ParameterPoint parameters = Climate.parameters( MHelper.randRange(-1.5F, 1.5F, random), MHelper.randRange(-1.5F, 1.5F, random), diff --git a/src/main/java/ru/bclib/blocks/BaseSignBlock.java b/src/main/java/ru/bclib/blocks/BaseSignBlock.java index 655dff5a..07a479ad 100644 --- a/src/main/java/ru/bclib/blocks/BaseSignBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseSignBlock.java @@ -181,13 +181,11 @@ public class BaseSignBlock extends SignBlock implements BlockModelProvider, Cust @Override public boolean canPlaceLiquid(BlockGetter world, BlockPos pos, BlockState state, Fluid fluid) { - // TODO Auto-generated method stub return super.canPlaceLiquid(world, pos, state, fluid); } @Override public boolean placeLiquid(LevelAccessor world, BlockPos pos, BlockState state, FluidState fluidState) { - // TODO Auto-generated method stub return super.placeLiquid(world, pos, state, fluidState); } diff --git a/src/main/java/ru/bclib/mixin/common/BoneMealItemMixin.java b/src/main/java/ru/bclib/mixin/common/BoneMealItemMixin.java index 52357c1a..432345f1 100644 --- a/src/main/java/ru/bclib/mixin/common/BoneMealItemMixin.java +++ b/src/main/java/ru/bclib/mixin/common/BoneMealItemMixin.java @@ -29,7 +29,7 @@ public class BoneMealItemMixin { Level world = context.getLevel(); BlockPos blockPos = context.getClickedPos(); if (!world.isClientSide) { - BlockPos offseted = blockPos.relative(context.getClickedFace()); + //BlockPos offset = blockPos.relative(context.getClickedFace()); if (BonemealAPI.isTerrain(world.getBlockState(blockPos).getBlock())) { boolean consume = false; if (BonemealAPI.isSpreadableTerrain(world.getBlockState(blockPos).getBlock())) { diff --git a/src/main/java/ru/bclib/mixin/common/BiomeMixin.java b/src/main/java/ru/bclib/mixin/common/ChunkGeneratorMixin.java similarity index 61% rename from src/main/java/ru/bclib/mixin/common/BiomeMixin.java rename to src/main/java/ru/bclib/mixin/common/ChunkGeneratorMixin.java index 26f16bcb..a18fbe2a 100644 --- a/src/main/java/ru/bclib/mixin/common/BiomeMixin.java +++ b/src/main/java/ru/bclib/mixin/common/ChunkGeneratorMixin.java @@ -2,7 +2,9 @@ package ru.bclib.mixin.common; import net.minecraft.core.BlockPos; import net.minecraft.server.level.WorldGenRegion; +import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.StructureFeatureManager; +import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.WorldgenRandom; @@ -12,17 +14,17 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(Biome.class) -public class BiomeMixin { +@Mixin(ChunkGenerator.class) +public class ChunkGeneratorMixin { private int bclib_featureIteratorSeed; - @ModifyArg(method = "generate", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/levelgen/WorldgenRandom;setFeatureSeed(JII)J")) + @ModifyArg(method = "applyBiomeDecoration", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/levelgen/WorldgenRandom;setFeatureSeed(JII)V")) private long bclib_updateFeatureSeed(long seed) { return Long.rotateRight(seed, bclib_featureIteratorSeed++); } - @Inject(method = "generate", at = @At("HEAD")) - private void bclib_obBiomeGenerate(StructureFeatureManager structureFeatureManager, ChunkGenerator chunkGenerator, WorldGenRegion worldGenRegion, long l, WorldgenRandom worldgenRandom, BlockPos blockPos, CallbackInfo info) { + @Inject(method = "applyBiomeDecoration", at = @At("HEAD")) + private void bclib_obBiomeGenerate(WorldGenLevel level, ChunkPos pos, StructureFeatureManager manager, CallbackInfo ci) { bclib_featureIteratorSeed = 0; } } diff --git a/src/main/java/ru/bclib/mixin/common/MainMixin.java b/src/main/java/ru/bclib/mixin/common/MainMixin.java index 142aada1..72f17ecf 100644 --- a/src/main/java/ru/bclib/mixin/common/MainMixin.java +++ b/src/main/java/ru/bclib/mixin/common/MainMixin.java @@ -9,7 +9,7 @@ import ru.bclib.api.datafixer.DataFixerAPI; @Mixin(Main.class) abstract public class MainMixin { - @ModifyArg(method="main", at=@At(value="INVOKE", target="Lnet/minecraft/server/MinecraftServer;convertFromRegionFormatIfNeeded(Lnet/minecraft/world/level/storage/LevelStorageSource$LevelStorageAccess;)V")) + @ModifyArg(method="main", at=@At(value="INVOKE_ASSIGN", target="Lnet/minecraft/world/level/storage/LevelStorageSource$LevelStorageAccess;getSummary()Lnet/minecraft/world/level/storage/LevelSummary;")) private static LevelStorageSource.LevelStorageAccess bclib_callServerFix(LevelStorageSource.LevelStorageAccess session){ DataFixerAPI.fixData(session, false, (didFix)->{/* not called when showUI==false */}); return session; diff --git a/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java b/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java index e494a05f..b19e285b 100644 --- a/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java +++ b/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java @@ -49,15 +49,6 @@ public class MinecraftServerMixin { DataExchangeAPI.prepareServerside(); } - @Inject(method = "convertFromRegionFormatIfNeeded", at = @At("HEAD")) - private static void bclib_applyPatches(LevelStorageSource.LevelStorageAccess session, CallbackInfo ci) { - - /*File levelPath = session.getLevelPath(LevelResource.ROOT).toFile(); - WorldDataAPI.load(new File(levelPath, "data")); - DataFixerAPI.fixData(levelPath, session.getLevelId());*/ - } - - @Inject(method = "reloadResources", at = @At(value = "RETURN"), cancellable = true) private void bclib_reloadResources(Collection collection, CallbackInfoReturnable> info) { bclib_injectRecipes(); diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java index 67247cc2..2b3f7faf 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java @@ -321,8 +321,8 @@ public class BCLBiomeDef { }); generationSettings.surfaceBuilder(surface == null ? net.minecraft.data.worldgen.SurfaceBuilders.END : surface); - //TODO: Removed now. Seems to part of a registry step per biome now - structures.forEach((structure) -> generationSettings.addStructureStart(structure)); + //TODO: (1.18) Removed now. Seems to part of a registry step per biome now + //structures.forEach((structure) -> generationSettings.addStructureStart(structure)); features.forEach((info) -> generationSettings.addFeature(info.featureStep, info.feature)); carvers.forEach((info) -> generationSettings.addCarver(info.carverStep, info.carver)); diff --git a/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java b/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java index d1fff1d1..bef51070 100644 --- a/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java +++ b/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java @@ -1,7 +1,6 @@ package ru.bclib.world.structures; import net.fabricmc.fabric.api.structure.v1.FabricStructureBuilder; -import net.fabricmc.fabric.mixin.structure.FlatChunkGeneratorConfigAccessor; import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.levelgen.GenerationStep; @@ -25,7 +24,9 @@ public class BCLStructureFeature { .register(); this.featureConfigured = this.structure.configured(NoneFeatureConfiguration.NONE); BuiltinRegistries.register(BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE, id, this.featureConfigured); - FlatLevelGeneratorSettings.getStructureToFeatures().put(this.structure, this.featureConfigured); + // TODO: (1.18) Find Alternative for this mapping + //FlatLevelGeneratorSettings.getStructureToFeatures().put(this.structure, this.featureConfigured); + } public StructureFeature getStructure() { diff --git a/src/main/resources/bclib.mixins.common.json b/src/main/resources/bclib.mixins.common.json index c6dfa3cc..fca5fd56 100644 --- a/src/main/resources/bclib.mixins.common.json +++ b/src/main/resources/bclib.mixins.common.json @@ -18,7 +18,7 @@ "AnvilBlockMixin", "AnvilMenuMixin", "TagLoaderMixin", - "BiomeMixin", + "ChunkGeneratorMixin", "MainMixin", "TheEndBiomeDataMixin", "NetherBiomeDataMixin" From 74533e2e66d0e2f2d9a154d65eb6369f30535b06 Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 12 Oct 2021 14:53:14 +0200 Subject: [PATCH 07/96] fixes for 21w40a --- gradle.properties | 8 ++++---- .../ru/bclib/api/datafixer/MigrationProfile.java | 1 - src/main/java/ru/bclib/util/ModUtil.java | 15 ++++++++++----- .../world/generator/BCLibEndBiomeSource.java | 3 ++- .../java/ru/bclib/world/generator/BiomeMap.java | 5 +++-- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/gradle.properties b/gradle.properties index 58d5cdbe..c65e4e44 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,13 +2,13 @@ org.gradle.jvmargs=-Xmx2G #Loom -loom_version=0.9-SNAPSHOT +loom_version=0.10-SNAPSHOT # Fabric Properties # check these on https://fabricmc.net/versions.html -minecraft_version= 21w38a -loader_version= 0.11.7 -fabric_version = 0.40.4+1.18 +minecraft_version= 21w40a +loader_version= 0.12.1 +fabric_version = 0.40.8+1.18 # Mod Properties mod_version = 0.4.1 diff --git a/src/main/java/ru/bclib/api/datafixer/MigrationProfile.java b/src/main/java/ru/bclib/api/datafixer/MigrationProfile.java index 24e5e8ad..10b8a593 100644 --- a/src/main/java/ru/bclib/api/datafixer/MigrationProfile.java +++ b/src/main/java/ru/bclib/api/datafixer/MigrationProfile.java @@ -1,6 +1,5 @@ package ru.bclib.api.datafixer; -import net.fabricmc.loom.util.ModUtils; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.NbtIo; diff --git a/src/main/java/ru/bclib/util/ModUtil.java b/src/main/java/ru/bclib/util/ModUtil.java index db873bc5..2f3e9978 100644 --- a/src/main/java/ru/bclib/util/ModUtil.java +++ b/src/main/java/ru/bclib/util/ModUtil.java @@ -5,21 +5,23 @@ import net.fabricmc.loader.api.ModContainer; import net.fabricmc.loader.api.SemanticVersion; import net.fabricmc.loader.api.Version; import net.fabricmc.loader.api.metadata.ModMetadata; -import net.fabricmc.loader.metadata.ModMetadataParser; -import net.fabricmc.loader.metadata.ParseMetadataException; +import net.fabricmc.loader.impl.metadata.ModMetadataParser; +import net.fabricmc.loader.impl.metadata.ParseMetadataException; import org.apache.logging.log4j.LogManager; import ru.bclib.BCLib; import java.io.IOException; +import java.io.InputStream; import java.net.URI; import java.nio.file.FileSystem; import java.nio.file.FileSystems; +import java.nio.file.Files; import java.nio.file.Path; import java.util.HashMap; +import java.util.LinkedList; import java.util.Locale; import java.util.Map; import java.util.Optional; -import java.util.jar.JarFile; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -56,8 +58,11 @@ public class ModUtil { try { Path modMetaFile = fs.getPath("fabric.mod.json"); if (modMetaFile != null) { - ModMetadata mc = ModMetadataParser.parseMetadata(logger, modMetaFile); - mods.put(mc.getId(), new ModInfo(mc, file)); + try (InputStream is = Files.newInputStream(modMetaFile)) { + ModMetadata mc = ModMetadataParser.parseMetadata(is, uri.toString(), new LinkedList()); + mods.put(mc.getId(), new ModInfo(mc, file)); + } + } } catch (ParseMetadataException e) { BCLib.LOGGER.error(e.getMessage()); diff --git a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java index 6f442b0f..7e236521 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java @@ -11,6 +11,7 @@ import net.minecraft.world.level.biome.BiomeSource; import net.minecraft.world.level.biome.Biomes; import net.minecraft.world.level.biome.Climate; import net.minecraft.world.level.biome.TheEndBiomeSource; +import net.minecraft.world.level.levelgen.LegacyRandomSource; import net.minecraft.world.level.levelgen.WorldgenRandom; import net.minecraft.world.level.levelgen.synth.SimplexNoise; import ru.bclib.BCLib; @@ -76,7 +77,7 @@ public class BCLibEndBiomeSource extends BiomeSource { this.biomeRegistry = biomeRegistry; this.seed = seed; - WorldgenRandom chunkRandom = new WorldgenRandom(seed); + WorldgenRandom chunkRandom = new WorldgenRandom(new LegacyRandomSource(seed)); chunkRandom.consumeCount(17292); this.noise = new SimplexNoise(chunkRandom); diff --git a/src/main/java/ru/bclib/world/generator/BiomeMap.java b/src/main/java/ru/bclib/world/generator/BiomeMap.java index 9de76325..43614a3d 100644 --- a/src/main/java/ru/bclib/world/generator/BiomeMap.java +++ b/src/main/java/ru/bclib/world/generator/BiomeMap.java @@ -2,6 +2,7 @@ package ru.bclib.world.generator; import com.google.common.collect.Maps; import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.levelgen.LegacyRandomSource; import net.minecraft.world.level.levelgen.WorldgenRandom; import ru.bclib.noise.OpenSimplexNoise; import ru.bclib.util.MHelper; @@ -10,7 +11,7 @@ import ru.bclib.world.biomes.BCLBiome; import java.util.Map; public class BiomeMap { - private static final WorldgenRandom RANDOM = new WorldgenRandom(); + private final WorldgenRandom RANDOM; private final Map maps = Maps.newHashMap(); private final int size; @@ -23,7 +24,7 @@ public class BiomeMap { public BiomeMap(long seed, int size, BiomePicker picker) { maps.clear(); - RANDOM.setSeed(seed); + RANDOM = new WorldgenRandom(new LegacyRandomSource(seed)); noiseX = new OpenSimplexNoise(RANDOM.nextLong()); noiseZ = new OpenSimplexNoise(RANDOM.nextLong()); this.sizeXZ = size; From 40851c38cd7e1fcc81a4c16a970cb5eab0e97fb9 Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 12 Oct 2021 16:27:12 +0200 Subject: [PATCH 08/96] Changed Structure handling (Untested yet) --- .../mixin/client/IStructureFeatures.java | 12 ++++++++ .../mixin/client/StructureFeaturesMixin.java | 29 +++++++++++++++++++ .../ru/bclib/world/biomes/BCLBiomeDef.java | 21 ++++++++++++-- 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 src/main/java/ru/bclib/mixin/client/IStructureFeatures.java create mode 100644 src/main/java/ru/bclib/mixin/client/StructureFeaturesMixin.java diff --git a/src/main/java/ru/bclib/mixin/client/IStructureFeatures.java b/src/main/java/ru/bclib/mixin/client/IStructureFeatures.java new file mode 100644 index 00000000..85e92535 --- /dev/null +++ b/src/main/java/ru/bclib/mixin/client/IStructureFeatures.java @@ -0,0 +1,12 @@ +package ru.bclib.mixin.client; + +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; + +import java.util.function.BiConsumer; +import java.util.function.Consumer; + +public interface IStructureFeatures { + public void bclib_registerStructure(Consumer, ResourceKey>> callback); +} diff --git a/src/main/java/ru/bclib/mixin/client/StructureFeaturesMixin.java b/src/main/java/ru/bclib/mixin/client/StructureFeaturesMixin.java new file mode 100644 index 00000000..b6d1064a --- /dev/null +++ b/src/main/java/ru/bclib/mixin/client/StructureFeaturesMixin.java @@ -0,0 +1,29 @@ +package ru.bclib.mixin.client; + +import net.minecraft.data.worldgen.StructureFeatures; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.LinkedList; +import java.util.List; +import java.util.function.BiConsumer; +import java.util.function.Consumer; + +@Mixin(StructureFeatures.class) +public abstract class StructureFeaturesMixin implements IStructureFeatures{ + @Inject(method="registerStructures", at=@At("TAIL")) + static void bclib_registerStructures(BiConsumer, ResourceKey> biConsumer, CallbackInfo ci){ + bclib_callbacks.forEach(consumer -> consumer.accept(biConsumer)); + bclib_callbacks.clear(); + } + + private static List, ResourceKey>> > bclib_callbacks = new LinkedList<>(); + public void bclib_registerStructure(Consumer, ResourceKey>> callback){ + bclib_callbacks.add(callback); + } +} diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java index 2b3f7faf..cbd7ac45 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java @@ -2,8 +2,11 @@ package ru.bclib.world.biomes; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import net.fabricmc.fabric.api.biome.v1.BiomeModifications; import net.minecraft.core.Registry; import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.data.BuiltinRegistries; +import net.minecraft.data.worldgen.StructureFeatures; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.Music; import net.minecraft.sounds.Musics; @@ -31,7 +34,9 @@ import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import net.minecraft.world.level.levelgen.surfacebuilders.ConfiguredSurfaceBuilder; import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilder; import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderBaseConfiguration; +import net.minecraft.resources.ResourceKey; import ru.bclib.config.IdConfig; +import ru.bclib.mixin.client.IStructureFeatures; import ru.bclib.util.ColorUtil; import ru.bclib.world.features.BCLFeature; import ru.bclib.world.structures.BCLStructureFeature; @@ -44,7 +49,8 @@ public class BCLBiomeDef { public static final int DEF_FOLIAGE_OVERWORLD = ColorUtil.color(110, 143, 64); public static final int DEF_FOLIAGE_NETHER = ColorUtil.color(117, 10, 10); public static final int DEF_FOLIAGE_END = ColorUtil.color(197, 210, 112); - + + private final IStructureFeatures structureFeatures = (IStructureFeatures)new StructureFeatures(); private final List> structures = Lists.newArrayList(); private final List features = Lists.newArrayList(); private final List carvers = Lists.newArrayList(); @@ -340,7 +346,7 @@ public class BCLBiomeDef { if (particleConfig != null) effects.ambientParticle(particleConfig); effects.backgroundMusic(music != null ? new Music(music, 600, 2400, true) : Musics.END); - return new Biome.BiomeBuilder().precipitation(precipitation) + Biome biome = new Biome.BiomeBuilder().precipitation(precipitation) .biomeCategory(category) //.depth(depth) //TODO: No longer available in 1.18 //.scale(0.2F) @@ -350,6 +356,17 @@ public class BCLBiomeDef { .mobSpawnSettings(spawnSettings.build()) .generationSettings(generationSettings.build()) .build(); + + structureFeatures.bclib_registerStructure(biConsumer -> { + ResourceKey biomeKey = ResourceKey.create(Registry.BIOME_REGISTRY, BuiltinRegistries.BIOME.getKey(biome)); + System.out.println("Biome:" + biomeKey); + structures.forEach((structure) -> { + biConsumer.accept(structure, biomeKey); + }); + + }); + + return biome; } private static final class SpawnInfo { From c8d1b61006f35de6096c45d42434a31d5c05d631 Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 12 Oct 2021 17:45:59 +0200 Subject: [PATCH 09/96] Added mixin --- src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java | 2 +- src/main/resources/bclib.mixins.client.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java index cbd7ac45..e478e73f 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java @@ -50,7 +50,7 @@ public class BCLBiomeDef { public static final int DEF_FOLIAGE_NETHER = ColorUtil.color(117, 10, 10); public static final int DEF_FOLIAGE_END = ColorUtil.color(197, 210, 112); - private final IStructureFeatures structureFeatures = (IStructureFeatures)new StructureFeatures(); + protected final IStructureFeatures structureFeatures = (IStructureFeatures)new StructureFeatures(); private final List> structures = Lists.newArrayList(); private final List features = Lists.newArrayList(); private final List carvers = Lists.newArrayList(); diff --git a/src/main/resources/bclib.mixins.client.json b/src/main/resources/bclib.mixins.client.json index 83b869c2..5d05d731 100644 --- a/src/main/resources/bclib.mixins.client.json +++ b/src/main/resources/bclib.mixins.client.json @@ -11,7 +11,8 @@ "TextureAtlasMixin", "ModelBakeryMixin", "MinecraftMixin", - "GameMixin" + "GameMixin", + "StructureFeaturesMixin" ], "injectors": { "defaultRequire": 1 From 7d23a162ee2206f6de16a63e4ae25fe27c04d12c Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 12 Oct 2021 19:20:36 +0200 Subject: [PATCH 10/96] Some refactoring --- .../{mixin/client => interfaces}/IStructureFeatures.java | 2 +- .../java/ru/bclib/mixin/client/StructureFeaturesMixin.java | 5 +++-- src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java | 3 +-- 3 files changed, 5 insertions(+), 5 deletions(-) rename src/main/java/ru/bclib/{mixin/client => interfaces}/IStructureFeatures.java (92%) diff --git a/src/main/java/ru/bclib/mixin/client/IStructureFeatures.java b/src/main/java/ru/bclib/interfaces/IStructureFeatures.java similarity index 92% rename from src/main/java/ru/bclib/mixin/client/IStructureFeatures.java rename to src/main/java/ru/bclib/interfaces/IStructureFeatures.java index 85e92535..11ac69be 100644 --- a/src/main/java/ru/bclib/mixin/client/IStructureFeatures.java +++ b/src/main/java/ru/bclib/interfaces/IStructureFeatures.java @@ -1,4 +1,4 @@ -package ru.bclib.mixin.client; +package ru.bclib.interfaces; import net.minecraft.resources.ResourceKey; import net.minecraft.world.level.biome.Biome; diff --git a/src/main/java/ru/bclib/mixin/client/StructureFeaturesMixin.java b/src/main/java/ru/bclib/mixin/client/StructureFeaturesMixin.java index b6d1064a..b37a0d77 100644 --- a/src/main/java/ru/bclib/mixin/client/StructureFeaturesMixin.java +++ b/src/main/java/ru/bclib/mixin/client/StructureFeaturesMixin.java @@ -8,6 +8,7 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import ru.bclib.interfaces.IStructureFeatures; import java.util.LinkedList; import java.util.List; @@ -15,9 +16,9 @@ import java.util.function.BiConsumer; import java.util.function.Consumer; @Mixin(StructureFeatures.class) -public abstract class StructureFeaturesMixin implements IStructureFeatures{ +public abstract class StructureFeaturesMixin implements IStructureFeatures { @Inject(method="registerStructures", at=@At("TAIL")) - static void bclib_registerStructures(BiConsumer, ResourceKey> biConsumer, CallbackInfo ci){ + private static void bclib_registerStructures(BiConsumer, ResourceKey> biConsumer, CallbackInfo ci){ bclib_callbacks.forEach(consumer -> consumer.accept(biConsumer)); bclib_callbacks.clear(); } diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java index e478e73f..7829322c 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java @@ -2,7 +2,6 @@ package ru.bclib.world.biomes; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import net.fabricmc.fabric.api.biome.v1.BiomeModifications; import net.minecraft.core.Registry; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.data.BuiltinRegistries; @@ -36,7 +35,7 @@ import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilder; import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderBaseConfiguration; import net.minecraft.resources.ResourceKey; import ru.bclib.config.IdConfig; -import ru.bclib.mixin.client.IStructureFeatures; +import ru.bclib.interfaces.IStructureFeatures; import ru.bclib.util.ColorUtil; import ru.bclib.world.features.BCLFeature; import ru.bclib.world.structures.BCLStructureFeature; From 5a1bd5e31b7cc9cc3d4c4cd86e811176b62c3baf Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 12 Oct 2021 20:08:10 +0200 Subject: [PATCH 11/96] Downgraded loom version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index c65e4e44..c3f11f2c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx2G #Loom -loom_version=0.10-SNAPSHOT +loom_version=0.9-SNAPSHOT # Fabric Properties # check these on https://fabricmc.net/versions.html From 18a64c267dad24f5afa6cea124c45fb310487ca9 Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 12 Oct 2021 22:04:45 +0200 Subject: [PATCH 12/96] replaced accesswidener with simple reflection --- bclib.gradle | 4 -- gradle.properties | 2 +- src/main/java/ru/bclib/BCLib.java | 3 ++ .../ru/bclib/mixin/client/MinecraftMixin.java | 52 ++++++++++++++++--- src/main/resources/bclib.accesswidener | 4 -- src/main/resources/fabric.mod.json | 3 +- 6 files changed, 51 insertions(+), 17 deletions(-) delete mode 100644 src/main/resources/bclib.accesswidener diff --git a/bclib.gradle b/bclib.gradle index 1beb0887..0ba6ce46 100644 --- a/bclib.gradle +++ b/bclib.gradle @@ -23,10 +23,6 @@ repositories { maven { url 'https://jitpack.io' } } -loom { - accessWidenerPath = file("src/main/resources/bclib.accesswidener") -} - dependencies { minecraft "com.mojang:minecraft:${project.minecraft_version}" mappings minecraft.officialMojangMappings() diff --git a/gradle.properties b/gradle.properties index c3f11f2c..c65e4e44 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx2G #Loom -loom_version=0.9-SNAPSHOT +loom_version=0.10-SNAPSHOT # Fabric Properties # check these on https://fabricmc.net/versions.html diff --git a/src/main/java/ru/bclib/BCLib.java b/src/main/java/ru/bclib/BCLib.java index f5f6eb3c..73dce098 100644 --- a/src/main/java/ru/bclib/BCLib.java +++ b/src/main/java/ru/bclib/BCLib.java @@ -3,6 +3,7 @@ package ru.bclib; import net.fabricmc.api.EnvType; import net.fabricmc.api.ModInitializer; import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; import ru.bclib.api.TagAPI; import ru.bclib.api.WorldDataAPI; @@ -23,6 +24,8 @@ import ru.bclib.world.generator.BCLibNetherBiomeSource; import ru.bclib.world.generator.GeneratorOptions; import ru.bclib.world.surface.BCLSurfaceBuilders; +import java.lang.reflect.Array; +import java.lang.reflect.Field; import java.util.List; public class BCLib implements ModInitializer { diff --git a/src/main/java/ru/bclib/mixin/client/MinecraftMixin.java b/src/main/java/ru/bclib/mixin/client/MinecraftMixin.java index 76d00a4d..3499016a 100644 --- a/src/main/java/ru/bclib/mixin/client/MinecraftMixin.java +++ b/src/main/java/ru/bclib/mixin/client/MinecraftMixin.java @@ -2,7 +2,6 @@ package ru.bclib.mixin.client; import com.mojang.datafixers.util.Function4; import net.minecraft.client.Minecraft; -import net.minecraft.client.Minecraft.ExperimentalDialogType; import net.minecraft.client.color.block.BlockColors; import net.minecraft.client.color.item.ItemColors; import net.minecraft.client.main.GameConfig; @@ -26,6 +25,11 @@ import ru.bclib.api.dataexchange.DataExchangeAPI; import ru.bclib.api.datafixer.DataFixerAPI; import ru.bclib.interfaces.CustomColorProvider; +import java.lang.reflect.Array; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Arrays; import java.util.function.Function; @Mixin(Minecraft.class) @@ -49,19 +53,55 @@ public abstract class MinecraftMixin { }); } - @Shadow - protected abstract void doLoadLevel(String string, RegistryHolder registryHolder, Function function, Function4 function4, boolean bl, ExperimentalDialogType experimentalDialogType); - +// @Shadow +// protected abstract void doLoadLevel(String string, RegistryHolder registryHolder, Function function, Function4 function4, boolean bl, ExperimentalDialogType experimentalDialogType); +// @Shadow @Final private LevelStorageSource levelSource; - + Method doLoadLevel = null; + Object experimentalDialogType_BACKUP = null; + + private void bclib_doLoadLevel_BACKUP(String levelID, RegistryHolder registryHolder, Function function, Function4 function4, boolean bl){ + if (experimentalDialogType_BACKUP==null) { + try { + Class experimentalDialogType = Class.forName("net.minecraft.client.Minecraft$ExperimentalDialogType"); + Field f = experimentalDialogType.getDeclaredField("$VALUES"); + f.setAccessible(true); + experimentalDialogType_BACKUP = Array.get(f.get(null), 2); + } catch (ClassNotFoundException | IllegalAccessException | NoSuchFieldException e) { + e.printStackTrace(); + } + } + + if (doLoadLevel==null) { + for (Method m : Minecraft.class.getDeclaredMethods()) { + if (m.getName().equals("doLoadLevel")) { + doLoadLevel = m; + break; + } + } + } + + if (doLoadLevel!=null && experimentalDialogType_BACKUP!=null){ + doLoadLevel.setAccessible(true); + try { + doLoadLevel.invoke(this, new Object[]{levelID, registryHolder, function, function4, bl, experimentalDialogType_BACKUP}); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + } + } + @Inject(method = "loadLevel", cancellable = true, at = @At("HEAD")) private void bclib_callFixerOnLoad(String levelID, CallbackInfo ci) { DataExchangeAPI.prepareServerside(); if (DataFixerAPI.fixData(this.levelSource, levelID, true, (appliedFixes) -> { - this.doLoadLevel(levelID, RegistryAccess.builtin(), Minecraft::loadDataPacks, Minecraft::loadWorldData, false, Minecraft.ExperimentalDialogType.BACKUP); + bclib_doLoadLevel_BACKUP(levelID, RegistryAccess.builtin(), Minecraft::loadDataPacks, Minecraft::loadWorldData, false); + //this.doLoadLevel(levelID, RegistryAccess.builtin(), Minecraft::loadDataPacks, Minecraft::loadWorldData, false, Minecraft.ExperimentalDialogType.BACKUP); })) { ci.cancel(); } diff --git a/src/main/resources/bclib.accesswidener b/src/main/resources/bclib.accesswidener deleted file mode 100644 index 3efe4455..00000000 --- a/src/main/resources/bclib.accesswidener +++ /dev/null @@ -1,4 +0,0 @@ -accessWidener v1 named - -# Classes -accessible class net/minecraft/client/Minecraft$ExperimentalDialogType \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 9ec07e33..f7563925 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -28,8 +28,7 @@ ], "modmenu": [ "ru.bclib.gui.modmenu.EntryPoint::entrypointObject" ] }, - "accessWidener" : "bclib.accesswidener", - "mixins": [ + "mixins": [ "bclib.mixins.common.json", "bclib.mixins.client.json" ], From 87858fc6d51c1b460461c53904bf28829d1606e7 Mon Sep 17 00:00:00 2001 From: Frank Date: Sat, 13 Nov 2021 20:42:27 +0100 Subject: [PATCH 13/96] Sync with current master --- .../mixin/common/InternalBiomeDataMixin.java | 40 +++++++++++++++++++ .../mixin/common/NetherBiomeDataMixin.java | 19 --------- .../mixin/common/TheEndBiomeDataMixin.java | 35 ---------------- 3 files changed, 40 insertions(+), 54 deletions(-) create mode 100644 src/main/java/ru/bclib/mixin/common/InternalBiomeDataMixin.java delete mode 100644 src/main/java/ru/bclib/mixin/common/NetherBiomeDataMixin.java delete mode 100644 src/main/java/ru/bclib/mixin/common/TheEndBiomeDataMixin.java diff --git a/src/main/java/ru/bclib/mixin/common/InternalBiomeDataMixin.java b/src/main/java/ru/bclib/mixin/common/InternalBiomeDataMixin.java new file mode 100644 index 00000000..3f0e7c37 --- /dev/null +++ b/src/main/java/ru/bclib/mixin/common/InternalBiomeDataMixin.java @@ -0,0 +1,40 @@ +package ru.bclib.mixin.common; + +import net.fabricmc.fabric.impl.biome.InternalBiomeData; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.Biomes; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import ru.bclib.world.biomes.FabricBiomesData; + +@Mixin(value = InternalBiomeData.class, remap = false) +public class InternalBiomeDataMixin { + @Inject(method = "addEndBiomeReplacement", at = @At(value = "HEAD")) + private static void bclib_addEndBiomeReplacement(ResourceKey replaced, ResourceKey variant, double weight, CallbackInfo info) { + if (replaced == Biomes.END_BARRENS || replaced == Biomes.SMALL_END_ISLANDS) { + FabricBiomesData.END_VOID_BIOMES.put(variant, (float) weight); + } + else { + FabricBiomesData.END_LAND_BIOMES.put(variant, (float) weight); + } + } + + @Inject(method = "addEndMidlandsReplacement", at = @At(value = "HEAD")) + private static void bclib_addEndMidlandsReplacement(ResourceKey highlands, ResourceKey midlands, double weight, CallbackInfo info) { + FabricBiomesData.END_LAND_BIOMES.put(midlands, (float) weight); + } + + @Inject(method = "addEndBarrensReplacement", at = @At(value = "HEAD")) + private static void bclib_addEndBarrensReplacement(ResourceKey highlands, ResourceKey barrens, double weight, CallbackInfo info) { + FabricBiomesData.END_LAND_BIOMES.put(barrens, (float) weight); + FabricBiomesData.END_VOID_BIOMES.put(barrens, (float) weight); + } + + @Inject(method = "addNetherBiome", at = @At(value = "HEAD")) + private static void bclib_addNetherBiome(ResourceKey biome, Biome.ClimateParameters spawnNoisePoint, CallbackInfo info) { + FabricBiomesData.NETHER_BIOMES.add(biome); + } +} diff --git a/src/main/java/ru/bclib/mixin/common/NetherBiomeDataMixin.java b/src/main/java/ru/bclib/mixin/common/NetherBiomeDataMixin.java deleted file mode 100644 index 1a941711..00000000 --- a/src/main/java/ru/bclib/mixin/common/NetherBiomeDataMixin.java +++ /dev/null @@ -1,19 +0,0 @@ -package ru.bclib.mixin.common; - -import net.fabricmc.fabric.impl.biome.NetherBiomeData; -import net.minecraft.resources.ResourceKey; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.Climate; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import ru.bclib.world.biomes.FabricBiomesData; - -@Mixin(value = NetherBiomeData.class, remap = false) -public class NetherBiomeDataMixin { - @Inject(method = "addNetherBiome", at = @At(value = "HEAD")) - private static void bclib_addNetherBiome(ResourceKey biome, Climate.ParameterPoint spawnNoisePoint, CallbackInfo info) { - FabricBiomesData.NETHER_BIOMES.add(biome); - } -} diff --git a/src/main/java/ru/bclib/mixin/common/TheEndBiomeDataMixin.java b/src/main/java/ru/bclib/mixin/common/TheEndBiomeDataMixin.java deleted file mode 100644 index 93bca16f..00000000 --- a/src/main/java/ru/bclib/mixin/common/TheEndBiomeDataMixin.java +++ /dev/null @@ -1,35 +0,0 @@ -package ru.bclib.mixin.common; - -import net.fabricmc.fabric.impl.biome.TheEndBiomeData; -import net.minecraft.resources.ResourceKey; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.Biomes; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import ru.bclib.world.biomes.FabricBiomesData; - -@Mixin(value = TheEndBiomeData.class, remap = false) -public class TheEndBiomeDataMixin { - @Inject(method = "addEndBiomeReplacement", at = @At(value = "HEAD")) - private static void bclib_addEndBiomeReplacement(ResourceKey replaced, ResourceKey variant, double weight, CallbackInfo info) { - if (replaced == Biomes.END_BARRENS || replaced == Biomes.SMALL_END_ISLANDS) { - FabricBiomesData.END_VOID_BIOMES.put(variant, (float) weight); - } - else { - FabricBiomesData.END_LAND_BIOMES.put(variant, (float) weight); - } - } - - @Inject(method = "addEndMidlandsReplacement", at = @At(value = "HEAD")) - private static void bclib_addEndMidlandsReplacement(ResourceKey highlands, ResourceKey midlands, double weight, CallbackInfo info) { - FabricBiomesData.END_LAND_BIOMES.put(midlands, (float) weight); - } - - @Inject(method = "addEndBarrensReplacement", at = @At(value = "HEAD")) - private static void bclib_addEndBarrensReplacement(ResourceKey highlands, ResourceKey barrens, double weight, CallbackInfo info) { - FabricBiomesData.END_LAND_BIOMES.put(barrens, (float) weight); - FabricBiomesData.END_VOID_BIOMES.put(barrens, (float) weight); - } -} From 8b314577ef4232ae6d8e9a869a5ec15aa848e8e6 Mon Sep 17 00:00:00 2001 From: Frank Date: Sat, 13 Nov 2021 21:06:40 +0100 Subject: [PATCH 14/96] Minor build fixes --- src/main/java/ru/bclib/mixin/common/WorldGenRegionMixin.java | 3 ++- src/main/java/ru/bclib/world/features/NBTStructureFeature.java | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/bclib/mixin/common/WorldGenRegionMixin.java b/src/main/java/ru/bclib/mixin/common/WorldGenRegionMixin.java index a8866f3e..398e2d7e 100644 --- a/src/main/java/ru/bclib/mixin/common/WorldGenRegionMixin.java +++ b/src/main/java/ru/bclib/mixin/common/WorldGenRegionMixin.java @@ -3,6 +3,7 @@ package ru.bclib.mixin.common; import net.minecraft.core.BlockPos; import net.minecraft.server.level.WorldGenRegion; import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.chunk.ChunkAccess; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -14,7 +15,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; public class WorldGenRegionMixin { @Final @Shadow - private ChunkPos center; + private ChunkAccess center; @Inject(method = "ensureCanWrite", at = @At("HEAD"), cancellable = true) private void be_alterBlockCheck(BlockPos blockPos, CallbackInfoReturnable info) { diff --git a/src/main/java/ru/bclib/world/features/NBTStructureFeature.java b/src/main/java/ru/bclib/world/features/NBTStructureFeature.java index 37aa0050..acaed3ec 100644 --- a/src/main/java/ru/bclib/world/features/NBTStructureFeature.java +++ b/src/main/java/ru/bclib/world/features/NBTStructureFeature.java @@ -18,7 +18,6 @@ import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConf import net.minecraft.world.level.levelgen.structure.BoundingBox; import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings; import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; -import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderConfiguration; import ru.bclib.api.BiomeAPI; import ru.bclib.api.TagAPI; import ru.bclib.util.BlocksHelper; From a6e538b004f8d3035b5db1ce61fe2437a94e94f6 Mon Sep 17 00:00:00 2001 From: Frank Date: Sun, 14 Nov 2021 11:38:14 +0100 Subject: [PATCH 15/96] Fixed `DimensionType` Mixin --- .../mixin/common/DimensionTypeMixin.java | 61 +++++++++++++------ 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/src/main/java/ru/bclib/mixin/common/DimensionTypeMixin.java b/src/main/java/ru/bclib/mixin/common/DimensionTypeMixin.java index 2826a052..5e589aeb 100644 --- a/src/main/java/ru/bclib/mixin/common/DimensionTypeMixin.java +++ b/src/main/java/ru/bclib/mixin/common/DimensionTypeMixin.java @@ -1,11 +1,18 @@ package ru.bclib.mixin.common; +import com.mojang.serialization.Lifecycle; +import net.minecraft.core.MappedRegistry; import net.minecraft.core.Registry; +import net.minecraft.core.RegistryAccess; import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.MultiNoiseBiomeSource; +import net.minecraft.world.level.biome.TheEndBiomeSource; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.dimension.DimensionType; +import net.minecraft.world.level.dimension.LevelStem; import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator; import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; +import net.minecraft.world.level.levelgen.synth.NormalNoise; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -16,25 +23,45 @@ import ru.bclib.world.generator.GeneratorOptions; @Mixin(value = DimensionType.class, priority = 100) public class DimensionTypeMixin { - @Inject(method = "defaultNetherGenerator", at = @At("HEAD"), cancellable = true) - private static void be_replaceNetherBiomeSource(Registry biomeRegistry, Registry chunkGeneratorSettingsRegistry, long seed, CallbackInfoReturnable info) { - if (GeneratorOptions.customNetherBiomeSource()) { - info.setReturnValue(new NoiseBasedChunkGenerator( - new BCLibNetherBiomeSource(biomeRegistry, seed), - seed, - () -> chunkGeneratorSettingsRegistry.getOrThrow(NoiseGeneratorSettings.NETHER) - )); - } + @Inject(method="defaultDimensions(Lnet/minecraft/core/RegistryAccess;JZ)Lnet/minecraft/core/MappedRegistry;", at=@At("HEAD"), cancellable = true) + static void bclib_defaultDimensions(RegistryAccess registryAccess, long l, boolean bl, CallbackInfoReturnable> cir){ + MappedRegistry mappedRegistry = new MappedRegistry<>(Registry.LEVEL_STEM_REGISTRY, Lifecycle.experimental()); + Registry registry = registryAccess.registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY); + Registry registry2 = registryAccess.registryOrThrow(Registry.BIOME_REGISTRY); + Registry registry3 = registryAccess.registryOrThrow(Registry.NOISE_GENERATOR_SETTINGS_REGISTRY); + Registry registry4 = registryAccess.registryOrThrow(Registry.NOISE_REGISTRY); + + mappedRegistry.register(LevelStem.NETHER, new LevelStem( + () -> registry.getOrThrow(DimensionType.NETHER_LOCATION), + bclib_replaceNetherBiomeSource(registry2, registry3, registry4, l, bl) + ), Lifecycle.stable()); + + mappedRegistry.register(LevelStem.END, new LevelStem( + () -> registry.getOrThrow(DimensionType.END_LOCATION), + bclib_replaceEndBiomeSource(registry2, registry3, registry4, l) + ), Lifecycle.stable()); + cir.setReturnValue(mappedRegistry); } - @Inject(method = "defaultEndGenerator", at = @At("HEAD"), cancellable = true) - private static void be_replaceEndBiomeSource(Registry biomeRegistry, Registry chunkGeneratorSettingsRegistry, long seed, CallbackInfoReturnable info) { - if (GeneratorOptions.customEndBiomeSource()) { - info.setReturnValue(new NoiseBasedChunkGenerator( - new BCLibEndBiomeSource(biomeRegistry, seed), + private static ChunkGenerator bclib_replaceNetherBiomeSource(Registry biomeRegistry, Registry chunkGeneratorSettingsRegistry, Registry noiseRegistry , long seed, boolean bl) { + return new NoiseBasedChunkGenerator( + noiseRegistry, + GeneratorOptions.customNetherBiomeSource() + ? new BCLibNetherBiomeSource(biomeRegistry, seed) + : MultiNoiseBiomeSource.Preset.NETHER.biomeSource(biomeRegistry, bl), seed, - () -> chunkGeneratorSettingsRegistry.getOrThrow(NoiseGeneratorSettings.END) - )); - } + () -> chunkGeneratorSettingsRegistry.getOrThrow(NoiseGeneratorSettings.NETHER) + ); + } + + private static ChunkGenerator bclib_replaceEndBiomeSource(Registry biomeRegistry, Registry chunkGeneratorSettingsRegistry, Registry noiseRegistry , long seed) { + return new NoiseBasedChunkGenerator( + noiseRegistry, + GeneratorOptions.customEndBiomeSource() + ? new BCLibEndBiomeSource(biomeRegistry, seed) + : new TheEndBiomeSource(biomeRegistry, seed), + seed, + () -> chunkGeneratorSettingsRegistry.getOrThrow(NoiseGeneratorSettings.END) + ); } } \ No newline at end of file From 91832933291c542ed8c6aa4de6dd1c7e0fba30f5 Mon Sep 17 00:00:00 2001 From: Frank Date: Sun, 14 Nov 2021 11:44:47 +0100 Subject: [PATCH 16/96] Revert "Sync with current master" This reverts commit 87858fc6d51c1b460461c53904bf28829d1606e7. --- .../mixin/common/InternalBiomeDataMixin.java | 40 ------------------- .../mixin/common/NetherBiomeDataMixin.java | 19 +++++++++ .../mixin/common/TheEndBiomeDataMixin.java | 35 ++++++++++++++++ 3 files changed, 54 insertions(+), 40 deletions(-) delete mode 100644 src/main/java/ru/bclib/mixin/common/InternalBiomeDataMixin.java create mode 100644 src/main/java/ru/bclib/mixin/common/NetherBiomeDataMixin.java create mode 100644 src/main/java/ru/bclib/mixin/common/TheEndBiomeDataMixin.java diff --git a/src/main/java/ru/bclib/mixin/common/InternalBiomeDataMixin.java b/src/main/java/ru/bclib/mixin/common/InternalBiomeDataMixin.java deleted file mode 100644 index 3f0e7c37..00000000 --- a/src/main/java/ru/bclib/mixin/common/InternalBiomeDataMixin.java +++ /dev/null @@ -1,40 +0,0 @@ -package ru.bclib.mixin.common; - -import net.fabricmc.fabric.impl.biome.InternalBiomeData; -import net.minecraft.resources.ResourceKey; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.Biomes; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import ru.bclib.world.biomes.FabricBiomesData; - -@Mixin(value = InternalBiomeData.class, remap = false) -public class InternalBiomeDataMixin { - @Inject(method = "addEndBiomeReplacement", at = @At(value = "HEAD")) - private static void bclib_addEndBiomeReplacement(ResourceKey replaced, ResourceKey variant, double weight, CallbackInfo info) { - if (replaced == Biomes.END_BARRENS || replaced == Biomes.SMALL_END_ISLANDS) { - FabricBiomesData.END_VOID_BIOMES.put(variant, (float) weight); - } - else { - FabricBiomesData.END_LAND_BIOMES.put(variant, (float) weight); - } - } - - @Inject(method = "addEndMidlandsReplacement", at = @At(value = "HEAD")) - private static void bclib_addEndMidlandsReplacement(ResourceKey highlands, ResourceKey midlands, double weight, CallbackInfo info) { - FabricBiomesData.END_LAND_BIOMES.put(midlands, (float) weight); - } - - @Inject(method = "addEndBarrensReplacement", at = @At(value = "HEAD")) - private static void bclib_addEndBarrensReplacement(ResourceKey highlands, ResourceKey barrens, double weight, CallbackInfo info) { - FabricBiomesData.END_LAND_BIOMES.put(barrens, (float) weight); - FabricBiomesData.END_VOID_BIOMES.put(barrens, (float) weight); - } - - @Inject(method = "addNetherBiome", at = @At(value = "HEAD")) - private static void bclib_addNetherBiome(ResourceKey biome, Biome.ClimateParameters spawnNoisePoint, CallbackInfo info) { - FabricBiomesData.NETHER_BIOMES.add(biome); - } -} diff --git a/src/main/java/ru/bclib/mixin/common/NetherBiomeDataMixin.java b/src/main/java/ru/bclib/mixin/common/NetherBiomeDataMixin.java new file mode 100644 index 00000000..1a941711 --- /dev/null +++ b/src/main/java/ru/bclib/mixin/common/NetherBiomeDataMixin.java @@ -0,0 +1,19 @@ +package ru.bclib.mixin.common; + +import net.fabricmc.fabric.impl.biome.NetherBiomeData; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.Climate; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import ru.bclib.world.biomes.FabricBiomesData; + +@Mixin(value = NetherBiomeData.class, remap = false) +public class NetherBiomeDataMixin { + @Inject(method = "addNetherBiome", at = @At(value = "HEAD")) + private static void bclib_addNetherBiome(ResourceKey biome, Climate.ParameterPoint spawnNoisePoint, CallbackInfo info) { + FabricBiomesData.NETHER_BIOMES.add(biome); + } +} diff --git a/src/main/java/ru/bclib/mixin/common/TheEndBiomeDataMixin.java b/src/main/java/ru/bclib/mixin/common/TheEndBiomeDataMixin.java new file mode 100644 index 00000000..93bca16f --- /dev/null +++ b/src/main/java/ru/bclib/mixin/common/TheEndBiomeDataMixin.java @@ -0,0 +1,35 @@ +package ru.bclib.mixin.common; + +import net.fabricmc.fabric.impl.biome.TheEndBiomeData; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.Biomes; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import ru.bclib.world.biomes.FabricBiomesData; + +@Mixin(value = TheEndBiomeData.class, remap = false) +public class TheEndBiomeDataMixin { + @Inject(method = "addEndBiomeReplacement", at = @At(value = "HEAD")) + private static void bclib_addEndBiomeReplacement(ResourceKey replaced, ResourceKey variant, double weight, CallbackInfo info) { + if (replaced == Biomes.END_BARRENS || replaced == Biomes.SMALL_END_ISLANDS) { + FabricBiomesData.END_VOID_BIOMES.put(variant, (float) weight); + } + else { + FabricBiomesData.END_LAND_BIOMES.put(variant, (float) weight); + } + } + + @Inject(method = "addEndMidlandsReplacement", at = @At(value = "HEAD")) + private static void bclib_addEndMidlandsReplacement(ResourceKey highlands, ResourceKey midlands, double weight, CallbackInfo info) { + FabricBiomesData.END_LAND_BIOMES.put(midlands, (float) weight); + } + + @Inject(method = "addEndBarrensReplacement", at = @At(value = "HEAD")) + private static void bclib_addEndBarrensReplacement(ResourceKey highlands, ResourceKey barrens, double weight, CallbackInfo info) { + FabricBiomesData.END_LAND_BIOMES.put(barrens, (float) weight); + FabricBiomesData.END_VOID_BIOMES.put(barrens, (float) weight); + } +} From 53911dfe91fd2069ac5a0c491e85db05e81d9748 Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 30 Nov 2021 21:15:10 +0100 Subject: [PATCH 17/96] Backportat latest changes from master --- bclib.gradle | 4 +- gradle.properties | 8 +- src/main/java/ru/bclib/BCLib.java | 3 - src/main/java/ru/bclib/BCLibPatch.java | 2 +- src/main/java/ru/bclib/api/BiomeAPI.java | 89 +++-- src/main/java/ru/bclib/api/ComposterAPI.java | 22 ++ src/main/java/ru/bclib/api/LifeCycleAPI.java | 120 +++++++ .../ru/bclib/api/datafixer/DataFixerAPI.java | 6 +- .../bclib/api/datafixer/ForcedLevelPatch.java | 2 + .../bclib/api/datafixer/MigrationProfile.java | 2 + .../java/ru/bclib/api/datafixer/Patch.java | 2 + .../bclib/api/spawning/SpawnRuleBuilder.java | 308 ++++++++++++++++++ .../ru/bclib/api/spawning/SpawnRuleEntry.java | 30 ++ .../blockentities/BaseBarrelBlockEntity.java | 2 +- .../java/ru/bclib/blocks/BaseAnvilBlock.java | 2 +- .../java/ru/bclib/blocks/BaseChainBlock.java | 2 +- .../ru/bclib/blocks/BaseFurnaceBlock.java | 2 +- .../java/ru/bclib/blocks/BaseLeavesBlock.java | 10 +- .../java/ru/bclib/blocks/BaseOreBlock.java | 4 +- .../java/ru/bclib/blocks/BaseSignBlock.java | 4 +- .../java/ru/bclib/blocks/BaseSlabBlock.java | 3 +- .../bclib/blocks/BaseStripableLogBlock.java | 2 +- .../ru/bclib/blocks/SimpleLeavesBlock.java | 4 +- .../ru/bclib/blocks/StripableBarkBlock.java | 2 +- .../ru/bclib/blocks/WallMushroomBlock.java | 2 +- .../blocks/properties/StringProperty.java | 61 ++++ src/main/java/ru/bclib/config/Config.java | 6 +- .../java/ru/bclib/config/ConfigKeeper.java | 21 +- src/main/java/ru/bclib/config/Configs.java | 15 +- src/main/java/ru/bclib/config/PathConfig.java | 1 - .../ru/bclib/entity/DespawnableAnimal.java | 16 + .../ru/bclib/gui/gridlayout/GridScreen.java | 1 + .../bclib/interfaces/IStructureFeatures.java | 12 - .../PatchBiFunction.java | 5 +- .../PatchFunction.java | 5 +- .../java/ru/bclib/interfaces/SpawnRule.java | 14 + .../ru/bclib/mixin/client/MinecraftMixin.java | 49 +-- .../mixin/client/StructureFeaturesMixin.java | 30 -- ...unkGeneratorMixin.java => BiomeMixin.java} | 12 +- .../bclib/mixin/common/BoneMealItemMixin.java | 2 +- .../common/ChunkBiomeContainerMixin.java | 12 +- .../mixin/common/DimensionTypeMixin.java | 67 ---- .../common/LayerLightSectionStorageMixin.java | 35 ++ .../mixin/common/MinecraftServerMixin.java | 1 - .../bclib/mixin/common/ServerLevelMixin.java | 14 +- .../SimpleReloadableResourceManagerMixin.java | 2 +- .../mixin/common/WorldGenRegionMixin.java | 3 +- .../java/ru/bclib/recipes/AnvilRecipe.java | 13 +- .../java/ru/bclib/recipes/FurnaceRecipe.java | 2 +- .../java/ru/bclib/recipes/GridRecipe.java | 2 +- .../ru/bclib/recipes/SmithingTableRecipe.java | 2 +- src/main/java/ru/bclib/util/ModUtil.java | 1 - .../java/ru/bclib/world/biomes/BCLBiome.java | 14 +- .../ru/bclib/world/biomes/BCLBiomeDef.java | 58 ++-- .../ru/bclib/world/features/BCLFeature.java | 169 +++++++--- .../world/features/NBTStructureFeature.java | 1 + .../world/generator/BCLibEndBiomeSource.java | 21 +- .../generator/BCLibNetherBiomeSource.java | 19 +- .../ru/bclib/world/generator/BiomeMap.java | 1 - .../world/generator/GeneratorOptions.java | 12 + .../world/structures/BCLStructureFeature.java | 5 +- .../surface/DoubleBlockSurfaceBuilder.java | 8 +- src/main/resources/bclib.mixins.common.json | 4 +- 63 files changed, 1002 insertions(+), 351 deletions(-) create mode 100644 src/main/java/ru/bclib/api/ComposterAPI.java create mode 100644 src/main/java/ru/bclib/api/LifeCycleAPI.java create mode 100644 src/main/java/ru/bclib/api/spawning/SpawnRuleBuilder.java create mode 100644 src/main/java/ru/bclib/api/spawning/SpawnRuleEntry.java create mode 100644 src/main/java/ru/bclib/blocks/properties/StringProperty.java create mode 100644 src/main/java/ru/bclib/entity/DespawnableAnimal.java delete mode 100644 src/main/java/ru/bclib/interfaces/IStructureFeatures.java rename src/main/java/ru/bclib/{api/datafixer => interfaces}/PatchBiFunction.java (52%) rename src/main/java/ru/bclib/{api/datafixer => interfaces}/PatchFunction.java (50%) create mode 100644 src/main/java/ru/bclib/interfaces/SpawnRule.java delete mode 100644 src/main/java/ru/bclib/mixin/client/StructureFeaturesMixin.java rename src/main/java/ru/bclib/mixin/common/{ChunkGeneratorMixin.java => BiomeMixin.java} (61%) delete mode 100644 src/main/java/ru/bclib/mixin/common/DimensionTypeMixin.java create mode 100644 src/main/java/ru/bclib/mixin/common/LayerLightSectionStorageMixin.java diff --git a/bclib.gradle b/bclib.gradle index 3ff8796e..ec8dbbaf 100644 --- a/bclib.gradle +++ b/bclib.gradle @@ -7,8 +7,8 @@ buildscript { gradlePluginPortal() } } -sourceCompatibility = JavaVersion.VERSION_16 -targetCompatibility = JavaVersion.VERSION_16 +sourceCompatibility = JavaVersion.VERSION_17 +targetCompatibility = JavaVersion.VERSION_17 archivesBaseName = project.archives_base_name version = project.mod_version diff --git a/gradle.properties b/gradle.properties index 5b8a020f..47e71b78 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,12 +6,12 @@ loom_version=0.10-SNAPSHOT # Fabric Properties # check these on https://fabricmc.net/versions.html -minecraft_version= 1.18-pre1 -loader_version= 0.12.5 -fabric_version = 0.42.2+1.18 +minecraft_version= 1.18 +loader_version= 0.12.6 +fabric_version = 0.43.1+1.18 # Mod Properties -mod_version = 0.5.1 +mod_version = 0.5.5 maven_group = ru.bclib archives_base_name = bclib diff --git a/src/main/java/ru/bclib/BCLib.java b/src/main/java/ru/bclib/BCLib.java index 18e94261..1e450f96 100644 --- a/src/main/java/ru/bclib/BCLib.java +++ b/src/main/java/ru/bclib/BCLib.java @@ -3,7 +3,6 @@ package ru.bclib; import net.fabricmc.api.EnvType; import net.fabricmc.api.ModInitializer; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; import ru.bclib.api.TagAPI; import ru.bclib.api.WorldDataAPI; @@ -23,8 +22,6 @@ import ru.bclib.world.generator.BCLibNetherBiomeSource; import ru.bclib.world.generator.GeneratorOptions; import ru.bclib.world.surface.BCLSurfaceBuilders; -import java.lang.reflect.Array; -import java.lang.reflect.Field; import java.util.List; public class BCLib implements ModInitializer { diff --git a/src/main/java/ru/bclib/BCLibPatch.java b/src/main/java/ru/bclib/BCLibPatch.java index d7db7d40..44e4bc51 100644 --- a/src/main/java/ru/bclib/BCLibPatch.java +++ b/src/main/java/ru/bclib/BCLibPatch.java @@ -3,7 +3,7 @@ package ru.bclib; import net.minecraft.nbt.CompoundTag; import ru.bclib.api.datafixer.DataFixerAPI; import ru.bclib.api.datafixer.Patch; -import ru.bclib.api.datafixer.PatchFunction; +import ru.bclib.interfaces.PatchFunction; diff --git a/src/main/java/ru/bclib/api/BiomeAPI.java b/src/main/java/ru/bclib/api/BiomeAPI.java index 50260684..4cd48391 100644 --- a/src/main/java/ru/bclib/api/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/BiomeAPI.java @@ -1,13 +1,17 @@ package ru.bclib.api; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.impl.biome.InternalBiomeData; +import net.fabricmc.fabric.impl.biome.NetherBiomeData; +import net.fabricmc.fabric.impl.biome.TheEndBiomeData; import net.fabricmc.fabric.mixin.biome.modification.GenerationSettingsAccessor; +import net.fabricmc.fabric.mixin.biome.modification.SpawnSettingsAccessor; import net.minecraft.client.Minecraft; import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; @@ -15,11 +19,16 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.random.WeightedRandomList; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.MobCategory; import net.minecraft.world.level.Level; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.Biome.ClimateParameters; +import net.minecraft.world.biome.Biome.ClimateParameters; import net.minecraft.world.level.biome.BiomeSource; import net.minecraft.world.level.biome.Biomes; +import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; import net.minecraft.world.level.levelgen.GenerationStep.Decoration; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; @@ -31,6 +40,8 @@ import ru.bclib.world.features.BCLFeature; import ru.bclib.world.generator.BiomePicker; import ru.bclib.world.structures.BCLStructureFeature; +import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Random; @@ -114,8 +125,8 @@ public class BiomeAPI { registerBiome(biome); NETHER_BIOME_PICKER.addBiome(biome); Random random = new Random(biome.getID().hashCode()); - //TODO: (1.18) did they add depth and scale as two new params here??? - Climate.ParameterPoint parameters = Climate.parameters( + //TODO: (1.18) did they add depth and scale as two new params here??? + ClimateParameters parameters = new ClimateParameters( MHelper.randRange(-1.5F, 1.5F, random), MHelper.randRange(-1.5F, 1.5F, random), MHelper.randRange(-1.5F, 1.5F, random), @@ -396,7 +407,10 @@ public class BiomeAPI { biomes.forEach(biome -> { ResourceLocation biomeID = getBiomeID(biome); boolean modify = isDatapackBiome(biomeID); - if (!modify && !MODIFIED_BIOMES.contains(biomeID)) { + if (biome != BuiltinRegistries.BIOME.get(biomeID)) { + modify = true; + } + else if (!modify && !MODIFIED_BIOMES.contains(biomeID)) { MODIFIED_BIOMES.add(biomeID); modify = true; } @@ -417,13 +431,7 @@ public class BiomeAPI { public static void addBiomeFeature(Biome biome, ConfiguredFeature feature, Decoration step) { GenerationSettingsAccessor accessor = (GenerationSettingsAccessor) biome.getGenerationSettings(); List>>> biomeFeatures = getMutableList(accessor.fabric_getFeatures()); - int index = step.ordinal(); - if (biomeFeatures.size() < index) { - for (int i = biomeFeatures.size(); i <= index; i++) { - biomeFeatures.add(Lists.newArrayList()); - } - } - List>> list = getMutableList(biomeFeatures.get(index)); + List>> list = getList(step, biomeFeatures); list.add(() -> feature); accessor.fabric_setFeatures(biomeFeatures); } @@ -437,18 +445,30 @@ public class BiomeAPI { GenerationSettingsAccessor accessor = (GenerationSettingsAccessor) biome.getGenerationSettings(); List>>> biomeFeatures = getMutableList(accessor.fabric_getFeatures()); for (BCLFeature feature: features) { - int index = feature.getFeatureStep().ordinal(); - if (biomeFeatures.size() < index) { - for (int i = biomeFeatures.size(); i <= index; i++) { - biomeFeatures.add(Lists.newArrayList()); - } - } - List>> list = getMutableList(biomeFeatures.get(index)); + List>> list = getList(feature.getFeatureStep(), biomeFeatures); list.add(feature::getFeatureConfigured); } accessor.fabric_setFeatures(biomeFeatures); } + /** + * Getter for correct feature list from all biome feature list of lists. + * @param step feature {@link Decoration} step. + * @param lists biome accessor lists. + * @return mutable {@link ConfiguredFeature} list. + */ + private static List>> getList(Decoration step, List>>> lists) { + int index = step.ordinal(); + if (lists.size() <= index) { + for (int i = lists.size(); i <= index; i++) { + lists.add(Lists.newArrayList()); + } + } + List>> list = getMutableList(lists.get(index)); + lists.set(index, list); + return list; + } + /** * Adds new structure feature to existing biome. * @param biome {@link Biome} to add structure feature in. @@ -475,10 +495,41 @@ public class BiomeAPI { accessor.fabric_setStructureFeatures(biomeStructures); } + /** + * Adds mob spawning to specified biome. + * @param biome {@link Biome} to add mob spawning. + * @param entityType {@link EntityType} mob type. + * @param weight spawn weight. + * @param minGroupCount minimum mobs in group. + * @param maxGroupCount maximum mobs in group. + */ + public static void addBiomeMobSpawn(Biome biome, EntityType entityType, int weight, int minGroupCount, int maxGroupCount) { + MobCategory category = entityType.getCategory(); + SpawnSettingsAccessor accessor = (SpawnSettingsAccessor) biome.getMobSettings(); + Map> spawners = getMutableMap(accessor.fabric_getSpawners()); + List mobs = spawners.containsKey(category) ? getMutableList(spawners.get(category).unwrap()) : Lists.newArrayList(); + mobs.add(new SpawnerData(entityType, weight, minGroupCount, maxGroupCount)); + spawners.put(category, WeightedRandomList.create(mobs)); + accessor.fabric_setSpawners(spawners); + } + private static List getMutableList(List input) { - if (input instanceof ImmutableList) { + if (input!=null) { + System.out.println("getMutableList: " + input.getClass().getName()); + for (Class cl : input.getClass().getInterfaces()){ + System.out.println(" - " + cl.getName()); + } + } + if (/*input instanceof ImmutableList ||*/ !(input instanceof ArrayList || input instanceof LinkedList)) { return Lists.newArrayList(input); } return input; } + + private static Map getMutableMap(Map input) { + if (input instanceof ImmutableMap) { + return Maps.newHashMap(input); + } + return input; + } } diff --git a/src/main/java/ru/bclib/api/ComposterAPI.java b/src/main/java/ru/bclib/api/ComposterAPI.java new file mode 100644 index 00000000..ae9eda80 --- /dev/null +++ b/src/main/java/ru/bclib/api/ComposterAPI.java @@ -0,0 +1,22 @@ +package ru.bclib.api; + +import net.minecraft.world.item.Item; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.block.Block; +import ru.bclib.mixin.common.ComposterBlockAccessor; + +public class ComposterAPI { + public static Block allowCompost(float chance, Block block){ + if (block != null) { + allowCompost(chance, block.asItem()); + } + return block; + } + + public static Item allowCompost(float chance, Item item){ + if (item != null && item != Items.AIR) { + ComposterBlockAccessor.callAdd(chance, item); + } + return item; + } +} diff --git a/src/main/java/ru/bclib/api/LifeCycleAPI.java b/src/main/java/ru/bclib/api/LifeCycleAPI.java new file mode 100644 index 00000000..c50b83b9 --- /dev/null +++ b/src/main/java/ru/bclib/api/LifeCycleAPI.java @@ -0,0 +1,120 @@ +package ru.bclib.api; + +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceKey; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.progress.ChunkProgressListener; +import net.minecraft.world.level.CustomSpawner; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.biome.Biome; +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.ServerLevelData; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Executor; + +/** + * provides some lifetime hooks for a Minecraft instance + */ +public class LifeCycleAPI { + private final static List onLoadLevelBiomes = new ArrayList<>(2); + private final static List onLoadLevel = new ArrayList<>(2); + + /** + * A callback function that is used for each new ServerLevel instance + */ + public interface LevelLoadBiomesCall { + void onLoad(ServerLevel world, long seed, Registry registry); + } + + /** + * A callback function that is used for each new ServerLevel instance + */ + public interface LevelLoadCall { + void onLoad( + ServerLevel world, + MinecraftServer minecraftServer, + Executor executor, + LevelStorageSource.LevelStorageAccess levelStorageAccess, + ServerLevelData serverLevelData, + ResourceKey resourceKey, + DimensionType dimensionType, + ChunkProgressListener chunkProgressListener, + ChunkGenerator chunkGenerator, + boolean bl, + long l, + List list, + boolean bl2); + } + + /** + * Register a callback that is called when a new {@code ServerLevel is instantiated}. + * This callback will receive the world seed as well as it's biome registry. + * @param call The calbback Method + */ + public static void onLevelLoad(LevelLoadBiomesCall call){ + onLoadLevelBiomes.add(call); + } + + /** + * Register a callback that is called when a new {@code ServerLevel is instantiated}. + * This callbacl will receiv all parameters that were passed to the ServerLevel's constructor + * @param call The calbback Method + */ + public static void onLevelLoad(LevelLoadCall call){ + onLoadLevel.add(call); + } + + /** + * For internal use, You should not call this method! + * @param minecraftServer + * @param executor + * @param levelStorageAccess + * @param serverLevelData + * @param resourceKey + * @param dimensionType + * @param chunkProgressListener + * @param chunkGenerator + * @param bl + * @param l + * @param list + * @param bl2 + */ + public static void _runLevelLoad(ServerLevel world, + MinecraftServer minecraftServer, + Executor executor, + LevelStorageSource.LevelStorageAccess levelStorageAccess, + ServerLevelData serverLevelData, + ResourceKey resourceKey, + DimensionType dimensionType, + ChunkProgressListener chunkProgressListener, + ChunkGenerator chunkGenerator, + boolean bl, + long l, + List list, + boolean bl2){ + onLoadLevel.forEach(c -> c.onLoad( + world, + minecraftServer, + executor, + levelStorageAccess, + serverLevelData, + resourceKey, + dimensionType, + chunkProgressListener, + chunkGenerator, + bl, + l, + list, + bl2) + ); + + final long seed = world.getSeed(); + final Registry biomeRegistry = world.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY); + onLoadLevelBiomes.forEach(c -> c.onLoad(world, seed, biomeRegistry)); + } +} diff --git a/src/main/java/ru/bclib/api/datafixer/DataFixerAPI.java b/src/main/java/ru/bclib/api/datafixer/DataFixerAPI.java index b63505c9..1a832f6f 100644 --- a/src/main/java/ru/bclib/api/datafixer/DataFixerAPI.java +++ b/src/main/java/ru/bclib/api/datafixer/DataFixerAPI.java @@ -32,6 +32,7 @@ import ru.bclib.util.Logger; import java.io.DataInputStream; import java.io.DataOutputStream; +import java.io.EOFException; import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -570,6 +571,9 @@ public class DataFixerAPI { private static List getAllPlayers(File dir) { List list = new ArrayList<>(); dir = new File(dir, "playerdata"); + if (!dir.exists() || !dir.isDirectory()) { + return list; + } for (File file : dir.listFiles()) { if (file.isFile() && file.getName().endsWith(".dat")) { list.add(file); @@ -604,7 +608,7 @@ public class DataFixerAPI { private static CompoundTag readNbt(File file) throws IOException { try { return NbtIo.readCompressed(file); - } catch (ZipException e){ + } catch (ZipException | EOFException e){ return NbtIo.read(file); } } diff --git a/src/main/java/ru/bclib/api/datafixer/ForcedLevelPatch.java b/src/main/java/ru/bclib/api/datafixer/ForcedLevelPatch.java index 34951454..333d473b 100644 --- a/src/main/java/ru/bclib/api/datafixer/ForcedLevelPatch.java +++ b/src/main/java/ru/bclib/api/datafixer/ForcedLevelPatch.java @@ -3,6 +3,8 @@ package ru.bclib.api.datafixer; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import org.jetbrains.annotations.NotNull; +import ru.bclib.interfaces.PatchBiFunction; +import ru.bclib.interfaces.PatchFunction; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/ru/bclib/api/datafixer/MigrationProfile.java b/src/main/java/ru/bclib/api/datafixer/MigrationProfile.java index 26065093..831470ff 100644 --- a/src/main/java/ru/bclib/api/datafixer/MigrationProfile.java +++ b/src/main/java/ru/bclib/api/datafixer/MigrationProfile.java @@ -7,6 +7,8 @@ import net.minecraft.nbt.Tag; import org.jetbrains.annotations.NotNull; import ru.bclib.BCLib; import ru.bclib.api.WorldDataAPI; +import ru.bclib.interfaces.PatchBiFunction; +import ru.bclib.interfaces.PatchFunction; import ru.bclib.util.ModUtil; import java.io.File; diff --git a/src/main/java/ru/bclib/api/datafixer/Patch.java b/src/main/java/ru/bclib/api/datafixer/Patch.java index bc64e3c5..30a26ce7 100644 --- a/src/main/java/ru/bclib/api/datafixer/Patch.java +++ b/src/main/java/ru/bclib/api/datafixer/Patch.java @@ -3,6 +3,8 @@ package ru.bclib.api.datafixer; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import org.jetbrains.annotations.NotNull; +import ru.bclib.interfaces.PatchBiFunction; +import ru.bclib.interfaces.PatchFunction; import ru.bclib.util.ModUtil; import java.util.ArrayList; diff --git a/src/main/java/ru/bclib/api/spawning/SpawnRuleBuilder.java b/src/main/java/ru/bclib/api/spawning/SpawnRuleBuilder.java new file mode 100644 index 00000000..02ca1ccd --- /dev/null +++ b/src/main/java/ru/bclib/api/spawning/SpawnRuleBuilder.java @@ -0,0 +1,308 @@ +package ru.bclib.api.spawning; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import net.fabricmc.fabric.mixin.object.builder.SpawnRestrictionAccessor; +import net.minecraft.core.BlockPos; +import net.minecraft.world.Difficulty; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.SpawnPlacements.SpawnPredicate; +import net.minecraft.world.entity.SpawnPlacements.Type; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.levelgen.Heightmap.Types; +import net.minecraft.world.phys.AABB; +import ru.bclib.interfaces.SpawnRule; + +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.function.Supplier; + +public class SpawnRuleBuilder { + private static final Map RULES_CACHE = Maps.newHashMap(); + private static final SpawnRuleBuilder INSTANCE = new SpawnRuleBuilder(); + private List rules = Lists.newArrayList(); + private SpawnRuleEntry entryInstance; + private EntityType entityType; + + private SpawnRuleBuilder() {} + + /** + * Starts new rule building process. + * @return prepared {@link SpawnRuleBuilder} instance. + */ + public static SpawnRuleBuilder start(EntityType entityType) { + INSTANCE.entityType = entityType; + INSTANCE.rules.clear(); + return INSTANCE; + } + + /** + * Stop entity spawn on peaceful {@link Difficulty} + * @return same {@link SpawnRuleBuilder} instance. + */ + public SpawnRuleBuilder notPeaceful() { + entryInstance = getFromCache("not_peaceful", () -> { + return new SpawnRuleEntry(0, (type, world, spawnReason, pos, random) -> world.getDifficulty() != Difficulty.PEACEFUL); + }); + rules.add(entryInstance); + return this; + } + + /** + * Restricts entity spawn above world surface (flying mobs). + * @param minHeight minimal spawn height. + * @return same {@link SpawnRuleBuilder} instance. + */ + public SpawnRuleBuilder aboveGround(int minHeight) { + entryInstance = getFromCache("above_ground", () -> { + return new SpawnRuleEntry(0, (type, world, spawnReason, pos, random) -> { + if (pos.getY() < world.getMinBuildHeight() + 2) { + return false; + } + return pos.getY() > world.getHeight(Types.WORLD_SURFACE, pos.getX(), pos.getZ()) + minHeight; + }); + }); + rules.add(entryInstance); + return this; + } + + /** + * Restricts entity spawn below world logical height (useful for Nether mobs). + * @return same {@link SpawnRuleBuilder} instance. + */ + public SpawnRuleBuilder belowMaxHeight() { + entryInstance = getFromCache("below_max_height", () -> { + return new SpawnRuleEntry(0, (type, world, spawnReason, pos, random) -> pos.getY() < world.dimensionType().logicalHeight()); + }); + rules.add(entryInstance); + return this; + } + + /** + * Restricts spawning only to vanilla valid blocks. + * @return same {@link SpawnRuleBuilder} instance. + */ + public SpawnRuleBuilder onlyOnValidBlocks() { + entryInstance = getFromCache("only_on_valid_blocks", () -> { + return new SpawnRuleEntry(0, (type, world, spawnReason, pos, random) -> { + BlockPos below = pos.below(); + return world.getBlockState(below).isValidSpawn(world, below, type); + }); + }); + rules.add(entryInstance); + return this; + } + + /** + * Restricts spawning only to specified blocks. + * @return same {@link SpawnRuleBuilder} instance. + */ + public SpawnRuleBuilder onlyOnBlocks(Block... blocks) { + final Block[] floorBlocks = blocks; + Arrays.sort(floorBlocks, Comparator.comparing(Block::getDescriptionId)); + + StringBuilder builder = new StringBuilder("only_on_blocks"); + for (Block block : floorBlocks) { + builder.append('_'); + builder.append(block.getDescriptionId()); + } + + entryInstance = getFromCache(builder.toString(), () -> { + return new SpawnRuleEntry(0, (type, world, spawnReason, pos, random) -> { + Block below = world.getBlockState(pos.below()).getBlock(); + for (Block floor: floorBlocks) { + if (floor == below) { + return true; + } + } + return false; + }); + }); + + rules.add(entryInstance); + return this; + } + + /** + * Will spawn entity with 1 / chance probability (randomly). + * @param chance probability limit. + * @return same {@link SpawnRuleBuilder} instance. + */ + public SpawnRuleBuilder withChance(int chance) { + entryInstance = getFromCache("with_chance_" + chance, () -> { + return new SpawnRuleEntry(1, (type, world, spawnReason, pos, random) -> random.nextInt(chance) == 0); + }); + rules.add(entryInstance); + return this; + } + + /** + * Will spawn entity only below specified brightness value. + * @param lightLevel light level upper limit. + * @return same {@link SpawnRuleBuilder} instance. + */ + public SpawnRuleBuilder belowBrightness(int lightLevel) { + entryInstance = getFromCache("below_brightness_" + lightLevel, () -> { + return new SpawnRuleEntry(2, (type, world, spawnReason, pos, random) -> world.getMaxLocalRawBrightness(pos) <= lightLevel); + }); + rules.add(entryInstance); + return this; + } + + /** + * Will spawn entity only above specified brightness value. + * @param lightLevel light level lower limit. + * @return same {@link SpawnRuleBuilder} instance. + */ + public SpawnRuleBuilder aboveBrightness(int lightLevel) { + entryInstance = getFromCache("above_brightness_" + lightLevel, () -> { + return new SpawnRuleEntry(2, (type, world, spawnReason, pos, random) -> world.getMaxLocalRawBrightness(pos) >= lightLevel); + }); + rules.add(entryInstance); + return this; + } + + /** + * Entity spawn will follow common vanilla spawn rules - spawn in darkness and not on peaceful level. + * @param lightLevel light level upper limit. + * @return same {@link SpawnRuleBuilder} instance. + */ + public SpawnRuleBuilder hostile(int lightLevel) { + return notPeaceful().belowBrightness(lightLevel); + } + + /** + * Entity spawn will follow common vanilla spawn rules - spawn in darkness (below light level 7) and not on peaceful level. + * @return same {@link SpawnRuleBuilder} instance. + */ + public SpawnRuleBuilder vanillaHostile() { + return hostile(7); + } + + /** + * Will spawn entity only if count of nearby entities will be lower than specified. + * @param selectorType selector {@link EntityType} to search. + * @param count max entity count. + * @param side side of box to search in. + * @return same {@link SpawnRuleBuilder} instance. + */ + public SpawnRuleBuilder maxNearby(EntityType selectorType, int count, int side) { + final Class baseClass = selectorType.getBaseClass(); + entryInstance = getFromCache("max_nearby_" + selectorType.getDescriptionId()+"_"+count+"_"+side, () -> { + return new SpawnRuleEntry(3, (type, world, spawnReason, pos, random) -> { + try { + final AABB box = new AABB(pos).inflate(side, world.getHeight(), side); + final List list = world.getEntitiesOfClass(baseClass, box, (entity) -> true); + return list.size() < count; + } + catch (Exception e) { + return true; + } + }); + }); + rules.add(entryInstance); + return this; + } + + /** + * Will spawn entity only if count of nearby entities with same type will be lower than specified. + * @param count max entity count. + * @param side side of box to search in. + * @return same {@link SpawnRuleBuilder} instance. + */ + public SpawnRuleBuilder maxNearby(int count, int side) { + return maxNearby(entityType, count, side); + } + + /** + * Will spawn entity only if count of nearby entities with same type will be lower than specified. + * @param count max entity count. + * @return same {@link SpawnRuleBuilder} instance. + */ + public SpawnRuleBuilder maxNearby(int count) { + return maxNearby(entityType, count, 256); + } + + /** + * Allows to add custom spawning rule for specific entities. + * @param rule {@link SpawnRule} rule, can be a lambda expression. + * @return same {@link SpawnRuleBuilder} instance. + */ + public SpawnRuleBuilder customRule(SpawnRule rule) { + rules.add(new SpawnRuleEntry(7, rule)); + return this; + } + + /** + * Finalize spawning rule creation. + * @param spawnType {@link Type} of spawn. + * @param heightmapType {@link Types} heightmap type. + */ + public void build(Type spawnType, Types heightmapType) { + final List rulesCopy = Lists.newArrayList(this.rules); + Collections.sort(rulesCopy); + + SpawnPredicate predicate = (entityType, serverLevelAccessor, mobSpawnType, blockPos, random) -> { + for (SpawnRuleEntry rule: rulesCopy) { + if (!rule.canSpawn(entityType, serverLevelAccessor, mobSpawnType, blockPos, random)) { + return false; + } + } + return true; + }; + + SpawnRestrictionAccessor.callRegister(entityType, spawnType, heightmapType, predicate); + } + + /** + * Finalize spawning rule creation with No Restrictions spawn type, useful for flying entities. + * @param heightmapType {@link Types} heightmap type. + */ + public void buildNoRestrictions(Types heightmapType) { + build(Type.NO_RESTRICTIONS, heightmapType); + } + + /** + * Finalize spawning rule creation with On Ground spawn type, useful for common entities. + * @param heightmapType {@link Types} heightmap type. + */ + public void buildOnGround(Types heightmapType) { + build(Type.ON_GROUND, heightmapType); + } + + /** + * Finalize spawning rule creation with In Water spawn type, useful for water entities. + * @param heightmapType {@link Types} heightmap type. + */ + public void buildInWater(Types heightmapType) { + build(Type.IN_WATER, heightmapType); + } + + /** + * Finalize spawning rule creation with In Lava spawn type, useful for lava entities. + * @param heightmapType {@link Types} heightmap type. + */ + public void buildInLava(Types heightmapType) { + build(Type.IN_LAVA, heightmapType); + } + + /** + * Internal function, will take entry from cache or create it if necessary. + * @param name {@link String} entry internal name. + * @param supplier {@link Supplier} for {@link SpawnRuleEntry}. + * @return new or existing {@link SpawnRuleEntry}. + */ + private static SpawnRuleEntry getFromCache(String name, Supplier supplier) { + SpawnRuleEntry entry = RULES_CACHE.get(name); + if (entry == null) { + entry = supplier.get(); + RULES_CACHE.put(name, entry); + } + return entry; + } +} diff --git a/src/main/java/ru/bclib/api/spawning/SpawnRuleEntry.java b/src/main/java/ru/bclib/api/spawning/SpawnRuleEntry.java new file mode 100644 index 00000000..710860c6 --- /dev/null +++ b/src/main/java/ru/bclib/api/spawning/SpawnRuleEntry.java @@ -0,0 +1,30 @@ +package ru.bclib.api.spawning; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.MobSpawnType; +import net.minecraft.world.level.LevelAccessor; +import org.jetbrains.annotations.NotNull; +import ru.bclib.interfaces.SpawnRule; + +import java.util.Random; + +public class SpawnRuleEntry implements Comparable { + private final SpawnRule rule; + private final byte priority; + + public SpawnRuleEntry(int priority, SpawnRule rule) { + this.priority = (byte) priority; + this.rule = rule; + } + + boolean canSpawn(EntityType type, LevelAccessor world, MobSpawnType spawnReason, BlockPos pos, Random random) { + return rule.canSpawn(type, world, spawnReason, pos, random); + } + + @Override + public int compareTo(@NotNull SpawnRuleEntry entry) { + return Integer.compare(priority, entry.priority); + } +} diff --git a/src/main/java/ru/bclib/blockentities/BaseBarrelBlockEntity.java b/src/main/java/ru/bclib/blockentities/BaseBarrelBlockEntity.java index f517d01b..9965baf5 100644 --- a/src/main/java/ru/bclib/blockentities/BaseBarrelBlockEntity.java +++ b/src/main/java/ru/bclib/blockentities/BaseBarrelBlockEntity.java @@ -94,7 +94,7 @@ public class BaseBarrelBlockEntity extends RandomizableContainerBlockEntity { } private void scheduleUpdate() { - level.getBlockTicks().scheduleTick(getBlockPos(), getBlockState().getBlock(), 5); + level.getBlockTicks().schedule(getBlockPos(), getBlockState().getBlock(), 5); } public void tick() { diff --git a/src/main/java/ru/bclib/blocks/BaseAnvilBlock.java b/src/main/java/ru/bclib/blocks/BaseAnvilBlock.java index 9aca2c1d..dc5826af 100644 --- a/src/main/java/ru/bclib/blocks/BaseAnvilBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseAnvilBlock.java @@ -40,7 +40,7 @@ public abstract class BaseAnvilBlock extends AnvilBlock implements BlockModelPro public IntegerProperty durability; public BaseAnvilBlock(MaterialColor color) { - super(FabricBlockSettings.copyOf(Blocks.ANVIL).mapColor(color)); + super(FabricBlockSettings.copyOf(Blocks.ANVIL).color(color)); } @Override diff --git a/src/main/java/ru/bclib/blocks/BaseChainBlock.java b/src/main/java/ru/bclib/blocks/BaseChainBlock.java index 9abdb58e..a0c5863c 100644 --- a/src/main/java/ru/bclib/blocks/BaseChainBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseChainBlock.java @@ -28,7 +28,7 @@ import java.util.Optional; public class BaseChainBlock extends ChainBlock implements BlockModelProvider, RenderLayerProvider { public BaseChainBlock(MaterialColor color) { - super(FabricBlockSettings.copyOf(Blocks.CHAIN).mapColor(color)); + super(FabricBlockSettings.copyOf(Blocks.CHAIN).color(color)); } @Override diff --git a/src/main/java/ru/bclib/blocks/BaseFurnaceBlock.java b/src/main/java/ru/bclib/blocks/BaseFurnaceBlock.java index 09958ec8..ef5c0557 100644 --- a/src/main/java/ru/bclib/blocks/BaseFurnaceBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseFurnaceBlock.java @@ -39,7 +39,7 @@ import java.util.Optional; public class BaseFurnaceBlock extends FurnaceBlock implements BlockModelProvider, RenderLayerProvider { public BaseFurnaceBlock(Block source) { - super(FabricBlockSettings.copyOf(source).luminance(state -> state.getValue(LIT) ? 13 : 0)); + super(FabricBlockSettings.copyOf(source).lightLevel(state -> state.getValue(LIT) ? 13 : 0)); } @Override diff --git a/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java b/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java index 63b000ec..e0a72abf 100644 --- a/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java @@ -29,13 +29,13 @@ public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, private static FabricBlockSettings makeLeaves(MaterialColor color) { return FabricBlockSettings.copyOf(Blocks.OAK_LEAVES) - .mapColor(color) + .color(color) .breakByTool(FabricToolTags.HOES) .breakByTool(FabricToolTags.SHEARS) .breakByHand(true) - .allowsSpawning((state, world, pos, type) -> false) - .suffocates((state, world, pos) -> false) - .blockVision((state, world, pos) -> false); + .isValidSpawn((state, world, pos, type) -> false) + .isSuffocating((state, world, pos) -> false) + .isViewBlocking((state, world, pos) -> false); } public BaseLeavesBlock(Block sapling, MaterialColor color, Consumer customizeProperties) { @@ -54,7 +54,7 @@ public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, } public BaseLeavesBlock(Block sapling, MaterialColor color, int light) { - super(makeLeaves(color).luminance(light)); + super(makeLeaves(color).lightLevel(light)); this.sapling = sapling; } diff --git a/src/main/java/ru/bclib/blocks/BaseOreBlock.java b/src/main/java/ru/bclib/blocks/BaseOreBlock.java index f529c082..31963438 100644 --- a/src/main/java/ru/bclib/blocks/BaseOreBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseOreBlock.java @@ -30,8 +30,8 @@ public class BaseOreBlock extends OreBlock implements BlockModelProvider { public BaseOreBlock(Item drop, int minCount, int maxCount, int experience) { this(drop, minCount, maxCount, experience, FabricBlockSettings.of(Material.STONE, MaterialColor.SAND) - .hardness(3F) - .resistance(9F) + .destroyTime(3F) + .explosionResistance(9F) .requiresCorrectToolForDrops() .sound(SoundType.STONE)); diff --git a/src/main/java/ru/bclib/blocks/BaseSignBlock.java b/src/main/java/ru/bclib/blocks/BaseSignBlock.java index 07a479ad..2d5cdffe 100644 --- a/src/main/java/ru/bclib/blocks/BaseSignBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseSignBlock.java @@ -105,7 +105,7 @@ public class BaseSignBlock extends SignBlock implements BlockModelProvider, Cust @Override public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { if (state.getValue(WATERLOGGED)) { - world.getLiquidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world)); + world.getFluidTicks().schedule(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world)); } if (!canSurvive(state, world, pos)) { return state.getValue(WATERLOGGED) ? state.getFluidState() @@ -191,6 +191,6 @@ public class BaseSignBlock extends SignBlock implements BlockModelProvider, Cust @Override public BlockItem getCustomItem(ResourceLocation blockID, FabricItemSettings settings) { - return new BlockItem(this, settings.maxCount(16)); + return new BlockItem(this, settings.stacksTo(16)); } } \ No newline at end of file diff --git a/src/main/java/ru/bclib/blocks/BaseSlabBlock.java b/src/main/java/ru/bclib/blocks/BaseSlabBlock.java index 80550b77..ed9a6004 100644 --- a/src/main/java/ru/bclib/blocks/BaseSlabBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseSlabBlock.java @@ -36,7 +36,8 @@ public class BaseSlabBlock extends SlabBlock implements BlockModelProvider { @Override @SuppressWarnings("deprecation") public List getDrops(BlockState state, LootContext.Builder builder) { - return Collections.singletonList(new ItemStack(this)); + int count = state.getValue(TYPE) == SlabType.DOUBLE ? 2 : 1; + return Collections.singletonList(new ItemStack(this, count)); } @Override diff --git a/src/main/java/ru/bclib/blocks/BaseStripableLogBlock.java b/src/main/java/ru/bclib/blocks/BaseStripableLogBlock.java index eb82ebbe..28127de4 100644 --- a/src/main/java/ru/bclib/blocks/BaseStripableLogBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseStripableLogBlock.java @@ -20,7 +20,7 @@ public class BaseStripableLogBlock extends BaseRotatedPillarBlock { private final Block striped; public BaseStripableLogBlock(MaterialColor color, Block striped) { - super(FabricBlockSettings.copyOf(striped).mapColor(color)); + super(FabricBlockSettings.copyOf(striped).color(color)); this.striped = striped; } diff --git a/src/main/java/ru/bclib/blocks/SimpleLeavesBlock.java b/src/main/java/ru/bclib/blocks/SimpleLeavesBlock.java index 4f4d1128..51d6bf29 100644 --- a/src/main/java/ru/bclib/blocks/SimpleLeavesBlock.java +++ b/src/main/java/ru/bclib/blocks/SimpleLeavesBlock.java @@ -12,7 +12,7 @@ public class SimpleLeavesBlock extends BaseBlockNotFull implements RenderLayerPr public SimpleLeavesBlock(MaterialColor color) { super(FabricBlockSettings.of(Material.LEAVES) .strength(0.2F) - .mapColor(color) + .color(color) .sound(SoundType.GRASS) .noOcclusion() .isValidSpawn((state, world, pos, type) -> false) @@ -25,7 +25,7 @@ public class SimpleLeavesBlock extends BaseBlockNotFull implements RenderLayerPr public SimpleLeavesBlock(MaterialColor color, int light) { super(FabricBlockSettings.of(Material.LEAVES) .luminance(light) - .mapColor(color) + .color(color) .strength(0.2F) .sound(SoundType.GRASS) .noOcclusion() diff --git a/src/main/java/ru/bclib/blocks/StripableBarkBlock.java b/src/main/java/ru/bclib/blocks/StripableBarkBlock.java index d87f973a..328c6f1d 100644 --- a/src/main/java/ru/bclib/blocks/StripableBarkBlock.java +++ b/src/main/java/ru/bclib/blocks/StripableBarkBlock.java @@ -20,7 +20,7 @@ public class StripableBarkBlock extends BaseBarkBlock { private final Block striped; public StripableBarkBlock(MaterialColor color, Block striped) { - super(FabricBlockSettings.copyOf(striped).mapColor(color)); + super(FabricBlockSettings.copyOf(striped).color(color)); this.striped = striped; } diff --git a/src/main/java/ru/bclib/blocks/WallMushroomBlock.java b/src/main/java/ru/bclib/blocks/WallMushroomBlock.java index a4aabaf3..f03999e7 100644 --- a/src/main/java/ru/bclib/blocks/WallMushroomBlock.java +++ b/src/main/java/ru/bclib/blocks/WallMushroomBlock.java @@ -20,7 +20,7 @@ public abstract class WallMushroomBlock extends BaseWallPlantBlock { .breakByTool(FabricToolTags.AXES) .breakByHand(true) .luminance(light) - .hardness(0.2F) + .destroyTime(0.2F) .sound(SoundType.GRASS) .sound(SoundType.WOOD) .noCollission()); diff --git a/src/main/java/ru/bclib/blocks/properties/StringProperty.java b/src/main/java/ru/bclib/blocks/properties/StringProperty.java new file mode 100644 index 00000000..8aaff298 --- /dev/null +++ b/src/main/java/ru/bclib/blocks/properties/StringProperty.java @@ -0,0 +1,61 @@ +package ru.bclib.blocks.properties; + +import com.google.common.collect.Sets; +import net.minecraft.world.level.block.state.properties.Property; + +import java.util.Collection; +import java.util.Collections; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +@Deprecated +public class StringProperty extends Property { + private final Set values; + + public static StringProperty create(String name, String... values) { + return new StringProperty(name, values); + } + + protected StringProperty(String string, String... values) { + super(string, String.class); + this.values = Sets.newHashSet(values); + } + + public void addValue(String name) { + values.add(name); + } + + @Override + public Collection getPossibleValues() { + return Collections.unmodifiableSet(values); + } + + @Override + public String getName(String comparable) { + return comparable; + } + + @Override + public Optional getValue(String string) { + if (values.contains(string)) { + return Optional.of(string); + } + else { + return Optional.empty(); + } + } + + @Override + public int generateHashCode() { + return super.generateHashCode() + Objects.hashCode(values); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof StringProperty that)) return false; + if (!super.equals(o)) return false; + return values.equals(that.values); + } +} diff --git a/src/main/java/ru/bclib/config/Config.java b/src/main/java/ru/bclib/config/Config.java index ba2c8afb..a883116e 100644 --- a/src/main/java/ru/bclib/config/Config.java +++ b/src/main/java/ru/bclib/config/Config.java @@ -21,8 +21,8 @@ import java.util.List; import java.util.Map; public abstract class Config { + protected final static Map AUTO_SYNC_CONFIGS = new HashMap<>(); public static final String CONFIG_SYNC_PREFIX = "CONFIG_"; - protected final static Map autoSyncConfigs = new HashMap<>(); protected final ConfigKeeper keeper; protected final boolean autoSync; public final String configID; @@ -51,7 +51,7 @@ public abstract class Config { else DataExchangeAPI.addAutoSyncFile(aid.modID, aid.uniqueID, keeper.getConfigFile()); - autoSyncConfigs.put(aid, this); + AUTO_SYNC_CONFIGS.put(aid, this); BCLib.LOGGER.info("Added Config " + configID + " to auto sync (" + (diffContent?"content diff":"file hash") + ")"); } } @@ -70,7 +70,7 @@ public abstract class Config { } public static void reloadSyncedConfig(AutoSyncID aid, File file) { - Config cfg = autoSyncConfigs.get(aid); + Config cfg = AUTO_SYNC_CONFIGS.get(aid); if (cfg != null) { cfg.reload(); } diff --git a/src/main/java/ru/bclib/config/ConfigKeeper.java b/src/main/java/ru/bclib/config/ConfigKeeper.java index f3e6263e..e3711670 100644 --- a/src/main/java/ru/bclib/config/ConfigKeeper.java +++ b/src/main/java/ru/bclib/config/ConfigKeeper.java @@ -23,9 +23,9 @@ import java.util.function.Supplier; public final class ConfigKeeper { private final Map> configEntries = Maps.newHashMap(); - private JsonObject configObject; private final ConfigWriter writer; + private JsonObject configObject; private boolean changed = false; public ConfigKeeper(String modID, String group) { @@ -33,7 +33,7 @@ public final class ConfigKeeper { this.configObject = writer.load(); } - File getConfigFile() { + public File getConfigFile() { return this.writer.getConfigFile(); } @@ -141,7 +141,9 @@ public final class ConfigKeeper { } String paramKey = key.getEntry(); - paramKey += " [default: " + entry.getDefault() + "]"; + if (entry.hasDefaultInName()) { + paramKey += " [default: " + entry.getDefault() + "]"; + } this.changed |= entry.setLocation(obj, paramKey); } @@ -328,7 +330,6 @@ public final class ConfigKeeper { } public static class StringArrayEntry extends ArrayEntry { - public StringArrayEntry(List defaultValue) { super(defaultValue); } @@ -341,10 +342,14 @@ public final class ConfigKeeper { protected void add(JsonArray array, String el){ array.add(el); } + + @Override + protected boolean hasDefaultInName() { + return false; + } } public static class EnumEntry> extends Entry { - private final Type type; public EnumEntry(T defaultValue) { @@ -372,7 +377,6 @@ public final class ConfigKeeper { } public static abstract class RangeEntry> extends Entry { - private final T min, max; public RangeEntry(T defaultValue, T minVal, T maxVal) { @@ -396,7 +400,6 @@ public final class ConfigKeeper { } public static abstract class Entry { - protected final T defaultValue; protected Consumer writer; protected Supplier reader; @@ -448,5 +451,9 @@ public final class ConfigKeeper { public void setDefault() { this.setValue(defaultValue); } + + protected boolean hasDefaultInName() { + return true; + } } } diff --git a/src/main/java/ru/bclib/config/Configs.java b/src/main/java/ru/bclib/config/Configs.java index 2926b235..deac17d2 100644 --- a/src/main/java/ru/bclib/config/Configs.java +++ b/src/main/java/ru/bclib/config/Configs.java @@ -3,6 +3,9 @@ package ru.bclib.config; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import ru.bclib.BCLib; +import ru.bclib.config.ConfigKeeper.StringArrayEntry; + +import java.util.Collections; public class Configs { // Client and Server-Config must be the first entries. They are not part of the Auto-Sync process @@ -11,18 +14,24 @@ public class Configs { public static final ClientConfig CLIENT_CONFIG = new ClientConfig(); public static final ServerConfig SERVER_CONFIG = new ServerConfig(); - public static final PathConfig GENERATOR_CONFIG = new PathConfig(BCLib.MOD_ID, "generator", false); public static final PathConfig MAIN_CONFIG = new PathConfig(BCLib.MOD_ID, "main", true, true); - public static final String MAIN_PATCH_CATEGORY = "patches"; public static final PathConfig RECIPE_CONFIG = new PathConfig(BCLib.MOD_ID, "recipes"); - + public static final PathConfig BIOMES_CONFIG = new PathConfig(BCLib.MOD_ID, "biomes", false); + public static final String MAIN_PATCH_CATEGORY = "patches"; public static void save() { MAIN_CONFIG.saveChanges(); RECIPE_CONFIG.saveChanges(); GENERATOR_CONFIG.saveChanges(); + initForcedConfig(); + } + + private static void initForcedConfig() { + BIOMES_CONFIG.keeper.registerEntry(new ConfigKey("end_biomes", "force_include"), new StringArrayEntry(Collections.EMPTY_LIST)); + BIOMES_CONFIG.keeper.registerEntry(new ConfigKey("nether_biomes", "force_include"), new StringArrayEntry(Collections.EMPTY_LIST)); + BIOMES_CONFIG.saveChanges(); } } diff --git a/src/main/java/ru/bclib/config/PathConfig.java b/src/main/java/ru/bclib/config/PathConfig.java index 062e60ec..0bf8d1d3 100644 --- a/src/main/java/ru/bclib/config/PathConfig.java +++ b/src/main/java/ru/bclib/config/PathConfig.java @@ -6,7 +6,6 @@ import ru.bclib.config.ConfigKeeper.FloatRange; import ru.bclib.config.ConfigKeeper.IntegerRange; public class PathConfig extends Config { - public PathConfig(String modID, String group, boolean autoSync, boolean diffContent) { super(modID, group, autoSync, diffContent); } diff --git a/src/main/java/ru/bclib/entity/DespawnableAnimal.java b/src/main/java/ru/bclib/entity/DespawnableAnimal.java new file mode 100644 index 00000000..197673a1 --- /dev/null +++ b/src/main/java/ru/bclib/entity/DespawnableAnimal.java @@ -0,0 +1,16 @@ +package ru.bclib.entity; + +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.animal.Animal; +import net.minecraft.world.level.Level; + +public abstract class DespawnableAnimal extends Animal { + protected DespawnableAnimal(EntityType entityType, Level level) { + super(entityType, level); + } + + @Override + public boolean removeWhenFarAway(double d) { + return !this.hasCustomName(); + } +} diff --git a/src/main/java/ru/bclib/gui/gridlayout/GridScreen.java b/src/main/java/ru/bclib/gui/gridlayout/GridScreen.java index 663ca0dd..3d21990e 100644 --- a/src/main/java/ru/bclib/gui/gridlayout/GridScreen.java +++ b/src/main/java/ru/bclib/gui/gridlayout/GridScreen.java @@ -18,6 +18,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.util.Mth; import org.jetbrains.annotations.Nullable; import ru.bclib.gui.gridlayout.GridLayout.Alignment; +import ru.bclib.util.Pair; @Environment(EnvType.CLIENT) diff --git a/src/main/java/ru/bclib/interfaces/IStructureFeatures.java b/src/main/java/ru/bclib/interfaces/IStructureFeatures.java deleted file mode 100644 index 11ac69be..00000000 --- a/src/main/java/ru/bclib/interfaces/IStructureFeatures.java +++ /dev/null @@ -1,12 +0,0 @@ -package ru.bclib.interfaces; - -import net.minecraft.resources.ResourceKey; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; - -import java.util.function.BiConsumer; -import java.util.function.Consumer; - -public interface IStructureFeatures { - public void bclib_registerStructure(Consumer, ResourceKey>> callback); -} diff --git a/src/main/java/ru/bclib/api/datafixer/PatchBiFunction.java b/src/main/java/ru/bclib/interfaces/PatchBiFunction.java similarity index 52% rename from src/main/java/ru/bclib/api/datafixer/PatchBiFunction.java rename to src/main/java/ru/bclib/interfaces/PatchBiFunction.java index 6bd8da12..4bb345af 100644 --- a/src/main/java/ru/bclib/api/datafixer/PatchBiFunction.java +++ b/src/main/java/ru/bclib/interfaces/PatchBiFunction.java @@ -1,4 +1,7 @@ -package ru.bclib.api.datafixer; +package ru.bclib.interfaces; + +import ru.bclib.api.datafixer.MigrationProfile; +import ru.bclib.api.datafixer.PatchDidiFailException; @FunctionalInterface public interface PatchBiFunction { diff --git a/src/main/java/ru/bclib/api/datafixer/PatchFunction.java b/src/main/java/ru/bclib/interfaces/PatchFunction.java similarity index 50% rename from src/main/java/ru/bclib/api/datafixer/PatchFunction.java rename to src/main/java/ru/bclib/interfaces/PatchFunction.java index 7d429d68..809d55e0 100644 --- a/src/main/java/ru/bclib/api/datafixer/PatchFunction.java +++ b/src/main/java/ru/bclib/interfaces/PatchFunction.java @@ -1,4 +1,7 @@ -package ru.bclib.api.datafixer; +package ru.bclib.interfaces; + +import ru.bclib.api.datafixer.MigrationProfile; +import ru.bclib.api.datafixer.PatchDidiFailException; @FunctionalInterface public interface PatchFunction { diff --git a/src/main/java/ru/bclib/interfaces/SpawnRule.java b/src/main/java/ru/bclib/interfaces/SpawnRule.java new file mode 100644 index 00000000..8dffc463 --- /dev/null +++ b/src/main/java/ru/bclib/interfaces/SpawnRule.java @@ -0,0 +1,14 @@ +package ru.bclib.interfaces; + +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.MobSpawnType; +import net.minecraft.world.level.LevelAccessor; + +import java.util.Random; + +@FunctionalInterface +public interface SpawnRule { + boolean canSpawn(EntityType type, LevelAccessor world, MobSpawnType spawnReason, BlockPos pos, Random random); +} diff --git a/src/main/java/ru/bclib/mixin/client/MinecraftMixin.java b/src/main/java/ru/bclib/mixin/client/MinecraftMixin.java index aba7f73b..f1cb2523 100644 --- a/src/main/java/ru/bclib/mixin/client/MinecraftMixin.java +++ b/src/main/java/ru/bclib/mixin/client/MinecraftMixin.java @@ -2,6 +2,7 @@ package ru.bclib.mixin.client; import com.mojang.datafixers.util.Function4; import net.minecraft.client.Minecraft; +import net.minecraft.client.Minecraft.ExperimentalDialogType; import net.minecraft.client.color.block.BlockColors; import net.minecraft.client.color.item.ItemColors; import net.minecraft.client.main.GameConfig; @@ -25,11 +26,6 @@ import ru.bclib.api.dataexchange.DataExchangeAPI; import ru.bclib.api.datafixer.DataFixerAPI; import ru.bclib.interfaces.CustomColorProvider; -import java.lang.reflect.Array; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Arrays; import java.util.function.Function; @Mixin(Minecraft.class) @@ -53,48 +49,13 @@ public abstract class MinecraftMixin { }); } -// @Shadow -// protected abstract void doLoadLevel(String string, RegistryHolder registryHolder, Function function, Function4 function4, boolean bl, ExperimentalDialogType experimentalDialogType); -// + @Shadow + protected abstract void doLoadLevel(String string, RegistryHolder registryHolder, Function function, Function4 function4, boolean bl, ExperimentalDialogType experimentalDialogType); + @Shadow @Final private LevelStorageSource levelSource; - Method doLoadLevel = null; - Object experimentalDialogType_BACKUP = null; - - private void bclib_doLoadLevel_BACKUP(String levelID, RegistryHolder registryHolder, Function function, Function4 function4, boolean bl){ - if (experimentalDialogType_BACKUP==null) { - try { - Class experimentalDialogType = Class.forName("net.minecraft.client.Minecraft$ExperimentalDialogType"); - Field f = experimentalDialogType.getDeclaredField("$VALUES"); - f.setAccessible(true); - experimentalDialogType_BACKUP = Array.get(f.get(null), 2); - } catch (ClassNotFoundException | IllegalAccessException | NoSuchFieldException e) { - e.printStackTrace(); - } - } - - if (doLoadLevel==null) { - for (Method m : Minecraft.class.getDeclaredMethods()) { - if (m.getName().equals("doLoadLevel")) { - doLoadLevel = m; - break; - } - } - } - - if (doLoadLevel!=null && experimentalDialogType_BACKUP!=null){ - doLoadLevel.setAccessible(true); - try { - doLoadLevel.invoke(this, new Object[]{levelID, registryHolder, function, function4, bl, experimentalDialogType_BACKUP}); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); - } - } - } - + @Inject(method = "loadLevel", cancellable = true, at = @At("HEAD")) private void bclib_callFixerOnLoad(String levelID, CallbackInfo ci) { DataExchangeAPI.prepareServerside(); diff --git a/src/main/java/ru/bclib/mixin/client/StructureFeaturesMixin.java b/src/main/java/ru/bclib/mixin/client/StructureFeaturesMixin.java deleted file mode 100644 index b37a0d77..00000000 --- a/src/main/java/ru/bclib/mixin/client/StructureFeaturesMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package ru.bclib.mixin.client; - -import net.minecraft.data.worldgen.StructureFeatures; -import net.minecraft.resources.ResourceKey; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import ru.bclib.interfaces.IStructureFeatures; - -import java.util.LinkedList; -import java.util.List; -import java.util.function.BiConsumer; -import java.util.function.Consumer; - -@Mixin(StructureFeatures.class) -public abstract class StructureFeaturesMixin implements IStructureFeatures { - @Inject(method="registerStructures", at=@At("TAIL")) - private static void bclib_registerStructures(BiConsumer, ResourceKey> biConsumer, CallbackInfo ci){ - bclib_callbacks.forEach(consumer -> consumer.accept(biConsumer)); - bclib_callbacks.clear(); - } - - private static List, ResourceKey>> > bclib_callbacks = new LinkedList<>(); - public void bclib_registerStructure(Consumer, ResourceKey>> callback){ - bclib_callbacks.add(callback); - } -} diff --git a/src/main/java/ru/bclib/mixin/common/ChunkGeneratorMixin.java b/src/main/java/ru/bclib/mixin/common/BiomeMixin.java similarity index 61% rename from src/main/java/ru/bclib/mixin/common/ChunkGeneratorMixin.java rename to src/main/java/ru/bclib/mixin/common/BiomeMixin.java index a18fbe2a..26f16bcb 100644 --- a/src/main/java/ru/bclib/mixin/common/ChunkGeneratorMixin.java +++ b/src/main/java/ru/bclib/mixin/common/BiomeMixin.java @@ -2,9 +2,7 @@ package ru.bclib.mixin.common; import net.minecraft.core.BlockPos; import net.minecraft.server.level.WorldGenRegion; -import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.StructureFeatureManager; -import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.WorldgenRandom; @@ -14,17 +12,17 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(ChunkGenerator.class) -public class ChunkGeneratorMixin { +@Mixin(Biome.class) +public class BiomeMixin { private int bclib_featureIteratorSeed; - @ModifyArg(method = "applyBiomeDecoration", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/levelgen/WorldgenRandom;setFeatureSeed(JII)V")) + @ModifyArg(method = "generate", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/levelgen/WorldgenRandom;setFeatureSeed(JII)J")) private long bclib_updateFeatureSeed(long seed) { return Long.rotateRight(seed, bclib_featureIteratorSeed++); } - @Inject(method = "applyBiomeDecoration", at = @At("HEAD")) - private void bclib_obBiomeGenerate(WorldGenLevel level, ChunkPos pos, StructureFeatureManager manager, CallbackInfo ci) { + @Inject(method = "generate", at = @At("HEAD")) + private void bclib_obBiomeGenerate(StructureFeatureManager structureFeatureManager, ChunkGenerator chunkGenerator, WorldGenRegion worldGenRegion, long l, WorldgenRandom worldgenRandom, BlockPos blockPos, CallbackInfo info) { bclib_featureIteratorSeed = 0; } } diff --git a/src/main/java/ru/bclib/mixin/common/BoneMealItemMixin.java b/src/main/java/ru/bclib/mixin/common/BoneMealItemMixin.java index 432345f1..52357c1a 100644 --- a/src/main/java/ru/bclib/mixin/common/BoneMealItemMixin.java +++ b/src/main/java/ru/bclib/mixin/common/BoneMealItemMixin.java @@ -29,7 +29,7 @@ public class BoneMealItemMixin { Level world = context.getLevel(); BlockPos blockPos = context.getClickedPos(); if (!world.isClientSide) { - //BlockPos offset = blockPos.relative(context.getClickedFace()); + BlockPos offseted = blockPos.relative(context.getClickedFace()); if (BonemealAPI.isTerrain(world.getBlockState(blockPos).getBlock())) { boolean consume = false; if (BonemealAPI.isSpreadableTerrain(world.getBlockState(blockPos).getBlock())) { diff --git a/src/main/java/ru/bclib/mixin/common/ChunkBiomeContainerMixin.java b/src/main/java/ru/bclib/mixin/common/ChunkBiomeContainerMixin.java index 3ad2c2a8..5518fd1f 100644 --- a/src/main/java/ru/bclib/mixin/common/ChunkBiomeContainerMixin.java +++ b/src/main/java/ru/bclib/mixin/common/ChunkBiomeContainerMixin.java @@ -2,8 +2,8 @@ package ru.bclib.mixin.common; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.core.BlockPos; -import net.minecraft.util.BitStorage; import net.minecraft.util.Mth; +import net.minecraft.util.SimpleBitStorage; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.chunk.ChunkBiomeContainer; import org.spongepowered.asm.mixin.Final; @@ -40,7 +40,7 @@ public class ChunkBiomeContainerMixin implements BiomeSetter { if (bclib_hasHydrogen && be_shouldWriteToHydrogen()) { try { ChunkBiomeContainer self = (ChunkBiomeContainer) (Object) this; - BitStorage storage = be_getHydrogenStorage(self); + SimpleBitStorage storage = be_getHydrogenStorage(self); Biome[] palette = be_getHydrogenPalette(self); int paletteIndex = be_getHydrogenPaletteIndex(biome, palette); if (paletteIndex == -1) { @@ -57,7 +57,7 @@ public class ChunkBiomeContainerMixin implements BiomeSetter { catch (Exception e) { int size = storage.getSize(); int bits = Mth.ceillog2(palette.length); - BitStorage newStorage = new BitStorage(bits, size); + SimpleBitStorage newStorage = new SimpleBitStorage(bits, size); for (int i = 0; i < size; i++) { newStorage.set(i, storage.get(i)); } @@ -105,8 +105,8 @@ public class ChunkBiomeContainerMixin implements BiomeSetter { return field; } - private BitStorage be_getHydrogenStorage(ChunkBiomeContainer container) throws Exception { - return (BitStorage) be_getField("intArray").get(container); + private SimpleBitStorage be_getHydrogenStorage(ChunkBiomeContainer container) throws Exception { + return (SimpleBitStorage) be_getField("intArray").get(container); } private Biome[] be_getHydrogenPalette(ChunkBiomeContainer container) throws Exception { @@ -128,7 +128,7 @@ public class ChunkBiomeContainerMixin implements BiomeSetter { be_getField("palette").set(container, palette); } - private void be_setHydrogenStorage(ChunkBiomeContainer container, BitStorage storage) throws Exception { + private void be_setHydrogenStorage(ChunkBiomeContainer container, SimpleBitStorage storage) throws Exception { be_getField("intArray").set(container, storage); } } diff --git a/src/main/java/ru/bclib/mixin/common/DimensionTypeMixin.java b/src/main/java/ru/bclib/mixin/common/DimensionTypeMixin.java deleted file mode 100644 index 5e589aeb..00000000 --- a/src/main/java/ru/bclib/mixin/common/DimensionTypeMixin.java +++ /dev/null @@ -1,67 +0,0 @@ -package ru.bclib.mixin.common; - -import com.mojang.serialization.Lifecycle; -import net.minecraft.core.MappedRegistry; -import net.minecraft.core.Registry; -import net.minecraft.core.RegistryAccess; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.MultiNoiseBiomeSource; -import net.minecraft.world.level.biome.TheEndBiomeSource; -import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.dimension.DimensionType; -import net.minecraft.world.level.dimension.LevelStem; -import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator; -import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; -import net.minecraft.world.level.levelgen.synth.NormalNoise; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import ru.bclib.world.generator.BCLibEndBiomeSource; -import ru.bclib.world.generator.BCLibNetherBiomeSource; -import ru.bclib.world.generator.GeneratorOptions; - -@Mixin(value = DimensionType.class, priority = 100) -public class DimensionTypeMixin { - @Inject(method="defaultDimensions(Lnet/minecraft/core/RegistryAccess;JZ)Lnet/minecraft/core/MappedRegistry;", at=@At("HEAD"), cancellable = true) - static void bclib_defaultDimensions(RegistryAccess registryAccess, long l, boolean bl, CallbackInfoReturnable> cir){ - MappedRegistry mappedRegistry = new MappedRegistry<>(Registry.LEVEL_STEM_REGISTRY, Lifecycle.experimental()); - Registry registry = registryAccess.registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY); - Registry registry2 = registryAccess.registryOrThrow(Registry.BIOME_REGISTRY); - Registry registry3 = registryAccess.registryOrThrow(Registry.NOISE_GENERATOR_SETTINGS_REGISTRY); - Registry registry4 = registryAccess.registryOrThrow(Registry.NOISE_REGISTRY); - - mappedRegistry.register(LevelStem.NETHER, new LevelStem( - () -> registry.getOrThrow(DimensionType.NETHER_LOCATION), - bclib_replaceNetherBiomeSource(registry2, registry3, registry4, l, bl) - ), Lifecycle.stable()); - - mappedRegistry.register(LevelStem.END, new LevelStem( - () -> registry.getOrThrow(DimensionType.END_LOCATION), - bclib_replaceEndBiomeSource(registry2, registry3, registry4, l) - ), Lifecycle.stable()); - cir.setReturnValue(mappedRegistry); - } - - private static ChunkGenerator bclib_replaceNetherBiomeSource(Registry biomeRegistry, Registry chunkGeneratorSettingsRegistry, Registry noiseRegistry , long seed, boolean bl) { - return new NoiseBasedChunkGenerator( - noiseRegistry, - GeneratorOptions.customNetherBiomeSource() - ? new BCLibNetherBiomeSource(biomeRegistry, seed) - : MultiNoiseBiomeSource.Preset.NETHER.biomeSource(biomeRegistry, bl), - seed, - () -> chunkGeneratorSettingsRegistry.getOrThrow(NoiseGeneratorSettings.NETHER) - ); - } - - private static ChunkGenerator bclib_replaceEndBiomeSource(Registry biomeRegistry, Registry chunkGeneratorSettingsRegistry, Registry noiseRegistry , long seed) { - return new NoiseBasedChunkGenerator( - noiseRegistry, - GeneratorOptions.customEndBiomeSource() - ? new BCLibEndBiomeSource(biomeRegistry, seed) - : new TheEndBiomeSource(biomeRegistry, seed), - seed, - () -> chunkGeneratorSettingsRegistry.getOrThrow(NoiseGeneratorSettings.END) - ); - } -} \ No newline at end of file diff --git a/src/main/java/ru/bclib/mixin/common/LayerLightSectionStorageMixin.java b/src/main/java/ru/bclib/mixin/common/LayerLightSectionStorageMixin.java new file mode 100644 index 00000000..a222afef --- /dev/null +++ b/src/main/java/ru/bclib/mixin/common/LayerLightSectionStorageMixin.java @@ -0,0 +1,35 @@ +package ru.bclib.mixin.common; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.SectionPos; +import net.minecraft.world.level.chunk.DataLayer; +import net.minecraft.world.level.lighting.LayerLightSectionStorage; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(LayerLightSectionStorage.class) +public class LayerLightSectionStorageMixin { + @Shadow + protected DataLayer getDataLayer(long sectionPos, boolean cached) { + return null; + } + + @Inject(method = "getStoredLevel", at = @At(value = "HEAD"), cancellable = true) + private void bclib_lightFix(long blockPos, CallbackInfoReturnable info) { + try { + long pos = SectionPos.blockToSection(blockPos); + DataLayer dataLayer = this.getDataLayer(pos, true); + info.setReturnValue(dataLayer.get( + SectionPos.sectionRelative(BlockPos.getX(blockPos)), + SectionPos.sectionRelative(BlockPos.getY(blockPos)), + SectionPos.sectionRelative(BlockPos.getZ(blockPos)) + )); + } + catch (Exception e) { + info.setReturnValue(0); + } + } +} diff --git a/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java b/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java index b19e285b..0b7cfc6a 100644 --- a/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java +++ b/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java @@ -12,7 +12,6 @@ import net.minecraft.server.level.progress.ChunkProgressListenerFactory; import net.minecraft.server.packs.repository.PackRepository; import net.minecraft.server.players.GameProfileCache; import net.minecraft.world.level.Level; -import net.minecraft.world.level.storage.LevelStorageSource; import net.minecraft.world.level.storage.LevelStorageSource.LevelStorageAccess; import net.minecraft.world.level.storage.WorldData; import org.spongepowered.asm.mixin.Final; diff --git a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java index 8de68864..91c2c4d2 100644 --- a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java +++ b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java @@ -1,5 +1,9 @@ package ru.bclib.mixin.common; +import java.util.List; +import java.util.concurrent.Executor; +import java.util.function.Supplier; + import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; @@ -17,10 +21,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import ru.bclib.api.BiomeAPI; - -import java.util.List; -import java.util.concurrent.Executor; -import java.util.function.Supplier; +import ru.bclib.api.LifeCycleAPI; @Mixin(ServerLevel.class) public abstract class ServerLevelMixin extends Level { @@ -32,6 +33,9 @@ public abstract class ServerLevelMixin extends Level { @Inject(method = "*", at = @At("TAIL")) private void bclib_onServerWorldInit(MinecraftServer server, Executor workerExecutor, LevelStorageSource.LevelStorageAccess session, ServerLevelData properties, ResourceKey registryKey, DimensionType dimensionType, ChunkProgressListener worldGenerationProgressListener, ChunkGenerator chunkGenerator, boolean debugWorld, long l, List list, boolean bl, CallbackInfo info) { + ServerLevel world = ServerLevel.class.cast(this); + LifeCycleAPI._runLevelLoad(world, server, workerExecutor, session, properties, registryKey, dimensionType, worldGenerationProgressListener, chunkGenerator, debugWorld, l, list, bl); + BiomeAPI.initRegistry(server); BiomeAPI.applyModifications(ServerLevel.class.cast(this)); @@ -40,5 +44,7 @@ public abstract class ServerLevelMixin extends Level { } bclib_lastWorld = session.getLevelId(); + + } } diff --git a/src/main/java/ru/bclib/mixin/common/SimpleReloadableResourceManagerMixin.java b/src/main/java/ru/bclib/mixin/common/SimpleReloadableResourceManagerMixin.java index 94f5ea2d..d2ff94df 100644 --- a/src/main/java/ru/bclib/mixin/common/SimpleReloadableResourceManagerMixin.java +++ b/src/main/java/ru/bclib/mixin/common/SimpleReloadableResourceManagerMixin.java @@ -26,7 +26,7 @@ public class SimpleReloadableResourceManagerMixin { }; @Inject(method = "hasResource", at = @At("HEAD"), cancellable = true) - private void hasResource(ResourceLocation resourceLocation, CallbackInfoReturnable info) { + private void bclib_hasResource(ResourceLocation resourceLocation, CallbackInfoReturnable info) { if (resourceLocation.getNamespace().equals("minecraft")) { for (String key: BCLIB_MISSING_RESOURCES) { if (resourceLocation.getPath().equals(key)) { diff --git a/src/main/java/ru/bclib/mixin/common/WorldGenRegionMixin.java b/src/main/java/ru/bclib/mixin/common/WorldGenRegionMixin.java index 398e2d7e..a8866f3e 100644 --- a/src/main/java/ru/bclib/mixin/common/WorldGenRegionMixin.java +++ b/src/main/java/ru/bclib/mixin/common/WorldGenRegionMixin.java @@ -3,7 +3,6 @@ package ru.bclib.mixin.common; import net.minecraft.core.BlockPos; import net.minecraft.server.level.WorldGenRegion; import net.minecraft.world.level.ChunkPos; -import net.minecraft.world.level.chunk.ChunkAccess; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -15,7 +14,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; public class WorldGenRegionMixin { @Final @Shadow - private ChunkAccess center; + private ChunkPos center; @Inject(method = "ensureCanWrite", at = @At("HEAD"), cancellable = true) private void be_alterBlockCheck(BlockPos blockPos, CallbackInfoReturnable info) { diff --git a/src/main/java/ru/bclib/recipes/AnvilRecipe.java b/src/main/java/ru/bclib/recipes/AnvilRecipe.java index 378a7fd9..4d8eab82 100644 --- a/src/main/java/ru/bclib/recipes/AnvilRecipe.java +++ b/src/main/java/ru/bclib/recipes/AnvilRecipe.java @@ -140,13 +140,12 @@ public class AnvilRecipe implements Recipe, UnknownReceipBookCategory @Override public NonNullList getIngredients() { NonNullList defaultedList = NonNullList.create(); - defaultedList.add(Ingredient.of(TagAPI.ITEM_HAMMERS.getValues() - .stream() - .filter(hammer -> ((TieredItem) hammer).getTier() - .getLevel() >= toolLevel) - .map(ItemStack::new))); + defaultedList.add(Ingredient.of(TagAPI.ITEM_HAMMERS + .getValues() + .stream() + .filter(hammer -> ((TieredItem) hammer).getTier().getLevel() >= toolLevel) + .map(ItemStack::new))); defaultedList.add(input); - return defaultedList; } @@ -252,7 +251,7 @@ public class AnvilRecipe implements Recipe, UnknownReceipBookCategory } public Builder checkConfig(PathConfig config) { - exist |= config.getBoolean("anvil", id.getPath(), true); + exist &= config.getBoolean("anvil", id.getPath(), true); return this; } diff --git a/src/main/java/ru/bclib/recipes/FurnaceRecipe.java b/src/main/java/ru/bclib/recipes/FurnaceRecipe.java index fbdd57ea..a1986232 100644 --- a/src/main/java/ru/bclib/recipes/FurnaceRecipe.java +++ b/src/main/java/ru/bclib/recipes/FurnaceRecipe.java @@ -39,7 +39,7 @@ public class FurnaceRecipe { } public FurnaceRecipe checkConfig(PathConfig config) { - exist |= config.getBoolean("furnace", id.getPath(), true); + exist &= config.getBoolean("furnace", id.getPath(), true); return this; } diff --git a/src/main/java/ru/bclib/recipes/GridRecipe.java b/src/main/java/ru/bclib/recipes/GridRecipe.java index 71a6bbc9..95d68cfb 100644 --- a/src/main/java/ru/bclib/recipes/GridRecipe.java +++ b/src/main/java/ru/bclib/recipes/GridRecipe.java @@ -55,7 +55,7 @@ public class GridRecipe { } public GridRecipe checkConfig(PathConfig config) { - exist |= config.getBoolean("grid", id.getPath(), true); + exist &= config.getBoolean("grid", id.getPath(), true); return this; } diff --git a/src/main/java/ru/bclib/recipes/SmithingTableRecipe.java b/src/main/java/ru/bclib/recipes/SmithingTableRecipe.java index a74c6184..464ed15d 100644 --- a/src/main/java/ru/bclib/recipes/SmithingTableRecipe.java +++ b/src/main/java/ru/bclib/recipes/SmithingTableRecipe.java @@ -40,7 +40,7 @@ public class SmithingTableRecipe { private SmithingTableRecipe() {} public SmithingTableRecipe checkConfig(PathConfig config) { - exist |= config.getBoolean("smithing", id.getPath(), true); + exist &= config.getBoolean("smithing", id.getPath(), true); return this; } diff --git a/src/main/java/ru/bclib/util/ModUtil.java b/src/main/java/ru/bclib/util/ModUtil.java index cf3019ee..8f4b973a 100644 --- a/src/main/java/ru/bclib/util/ModUtil.java +++ b/src/main/java/ru/bclib/util/ModUtil.java @@ -31,7 +31,6 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.LinkedList; import java.util.Locale; import java.util.Map; import java.util.Optional; diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiome.java b/src/main/java/ru/bclib/world/biomes/BCLBiome.java index 0cf21cbb..ebdf2a73 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiome.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiome.java @@ -7,6 +7,8 @@ import com.google.gson.JsonObject; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.Biomes; +import ru.bclib.config.Configs; import ru.bclib.util.JsonFactory; import ru.bclib.util.StructureHelper; import ru.bclib.util.WeightedList; @@ -38,6 +40,7 @@ public class BCLBiome { private Biome actualBiome; public BCLBiome(BCLBiomeDef definition) { + definition.loadConfigValues(Configs.BIOMES_CONFIG); this.mcID = definition.getID(); this.readStructureList(); if (structuresFeature != null) { @@ -53,8 +56,15 @@ public class BCLBiome { public BCLBiome(ResourceLocation id, Biome biome, float fogDensity, float genChance) { this.mcID = id; this.biome = biome; - this.genChance = genChance; - this.fogDensity = fogDensity; + if (id.equals(Biomes.THE_VOID.location())) { + this.genChance = fogDensity; + this.fogDensity = genChance; + } + else { + String biomePath = id.getNamespace() + "." + id.getPath(); + this.genChance = Configs.BIOMES_CONFIG.getFloat(biomePath, "generation_chance", genChance); + this.fogDensity = Configs.BIOMES_CONFIG.getFloat(biomePath, "fog_density", fogDensity); + } this.readStructureList(); this.customData = Maps.newHashMap(); subbiomes.add(this, 1); diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java index 389e350d..8d91066f 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java @@ -4,8 +4,6 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import net.minecraft.core.Registry; import net.minecraft.core.particles.ParticleOptions; -import net.minecraft.data.BuiltinRegistries; -import net.minecraft.data.worldgen.StructureFeatures; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.Music; import net.minecraft.sounds.Musics; @@ -33,9 +31,8 @@ import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import net.minecraft.world.level.levelgen.surfacebuilders.ConfiguredSurfaceBuilder; import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilder; import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderBaseConfiguration; -import net.minecraft.resources.ResourceKey; import ru.bclib.config.IdConfig; -import ru.bclib.interfaces.IStructureFeatures; +import ru.bclib.config.PathConfig; import ru.bclib.util.ColorUtil; import ru.bclib.world.features.BCLFeature; import ru.bclib.world.structures.BCLStructureFeature; @@ -48,8 +45,7 @@ public class BCLBiomeDef { public static final int DEF_FOLIAGE_OVERWORLD = ColorUtil.color(110, 143, 64); public static final int DEF_FOLIAGE_NETHER = ColorUtil.color(117, 10, 10); public static final int DEF_FOLIAGE_END = ColorUtil.color(197, 210, 112); - - protected final IStructureFeatures structureFeatures = (IStructureFeatures)new StructureFeatures(); + private final List> structures = Lists.newArrayList(); private final List features = Lists.newArrayList(); private final List carvers = Lists.newArrayList(); @@ -118,7 +114,6 @@ public class BCLBiomeDef { /** * Used to load biome settings from config. - * * @param config - {@link IdConfig}. * @return this {@link BCLBiomeDef}. */ @@ -129,9 +124,21 @@ public class BCLBiomeDef { return this; } + /** + * Used to load biome settings from config. + * @param config - {@link PathConfig}. + * @return this {@link BCLBiomeDef}. + */ + public BCLBiomeDef loadConfigValues(PathConfig config) { + String biomePath = id.getNamespace() + "." + id.getPath(); + this.fogDensity = config.getFloat(biomePath, "fog_density", this.fogDensity); + this.genChance = config.getFloat(biomePath, "generation_chance", this.genChance); + this.edgeSize = config.getInt(biomePath, "edge_size", this.edgeSize); + return this; + } + /** * Set category of the biome. - * * @param category - {@link BiomeCategory}. * @return this {@link BCLBiomeDef}. */ @@ -340,8 +347,7 @@ public class BCLBiomeDef { }); generationSettings.surfaceBuilder(surface == null ? net.minecraft.data.worldgen.SurfaceBuilders.END : surface); - //TODO: (1.18) Removed now. Seems to part of a registry step per biome now - //structures.forEach((structure) -> generationSettings.addStructureStart(structure)); + structures.forEach((structure) -> generationSettings.addStructureStart(structure)); features.forEach((info) -> generationSettings.addFeature(info.featureStep, info.feature)); carvers.forEach((info) -> generationSettings.addCarver(info.carverStep, info.carver)); @@ -359,27 +365,17 @@ public class BCLBiomeDef { if (particleConfig != null) effects.ambientParticle(particleConfig); effects.backgroundMusic(music != null ? new Music(music, 600, 2400, true) : Musics.END); - Biome biome = new Biome.BiomeBuilder().precipitation(precipitation) - .biomeCategory(category) - //.depth(depth) //TODO: No longer available in 1.18 - //.scale(0.2F) - .temperature(temperature) - .downfall(downfall) - .specialEffects(effects.build()) - .mobSpawnSettings(spawnSettings.build()) - .generationSettings(generationSettings.build()) - .build(); - - structureFeatures.bclib_registerStructure(biConsumer -> { - ResourceKey biomeKey = ResourceKey.create(Registry.BIOME_REGISTRY, BuiltinRegistries.BIOME.getKey(biome)); - System.out.println("Biome:" + biomeKey); - structures.forEach((structure) -> { - biConsumer.accept(structure, biomeKey); - }); - - }); - - return biome; + return new Biome.BiomeBuilder() + .precipitation(precipitation) + .biomeCategory(category) + .depth(depth) + .scale(0.2F) + .temperature(temperature) + .downfall(downfall) + .effects(effects.build()) + .spawnSettings(spawnSettings.build()) + .generationSettings(generationSettings.build()) + .build(); } private static final class SpawnInfo { diff --git a/src/main/java/ru/bclib/world/features/BCLFeature.java b/src/main/java/ru/bclib/world/features/BCLFeature.java index b7b898d0..c4a8e4bb 100644 --- a/src/main/java/ru/bclib/world/features/BCLFeature.java +++ b/src/main/java/ru/bclib/world/features/BCLFeature.java @@ -4,11 +4,9 @@ import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.levelgen.GenerationStep; +import net.minecraft.world.level.levelgen.GenerationStep.Decoration; import net.minecraft.world.level.levelgen.VerticalAnchor; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; -import net.minecraft.world.level.levelgen.feature.Feature; import net.minecraft.world.level.levelgen.feature.configurations.CountConfiguration; import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; @@ -16,59 +14,81 @@ import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguratio import net.minecraft.world.level.levelgen.placement.ChanceDecoratorConfiguration; import net.minecraft.world.level.levelgen.placement.FeatureDecorator; import net.minecraft.world.level.levelgen.structure.templatesystem.BlockMatchTest; -import net.minecraft.world.level.levelgen.structure.templatesystem.RuleTest; -import net.minecraft.world.level.levelgen.structure.templatesystem.TagMatchTest; -import ru.bclib.api.TagAPI; public class BCLFeature { - private static final RuleTest ANY_TERRAIN = new TagMatchTest(TagAPI.BLOCK_GEN_TERRAIN); private ConfiguredFeature featureConfigured; - private GenerationStep.Decoration featureStep; - private Feature feature; + private Decoration featureStep; + private net.minecraft.world.level.levelgen.feature.Feature feature; - public BCLFeature(Feature feature, ConfiguredFeature configuredFeature, GenerationStep.Decoration featureStep) { + public BCLFeature(net.minecraft.world.level.levelgen.feature.Feature feature, ConfiguredFeature configuredFeature, Decoration featureStep) { this.featureConfigured = configuredFeature; this.featureStep = featureStep; this.feature = feature; } - public BCLFeature(ResourceLocation id, Feature feature, GenerationStep.Decoration featureStep, ConfiguredFeature configuredFeature) { + public BCLFeature(ResourceLocation id, net.minecraft.world.level.levelgen.feature.Feature feature, Decoration featureStep, ConfiguredFeature configuredFeature) { this.featureConfigured = Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, id, configuredFeature); this.feature = Registry.register(Registry.FEATURE, id, feature); this.featureStep = featureStep; } - public static BCLFeature makeVegetationFeature(ResourceLocation id, Feature feature, int density) { + /** + * Get raw feature. + * @return {@link net.minecraft.world.level.levelgen.feature.Feature}. + */ + public net.minecraft.world.level.levelgen.feature.Feature getFeature() { + return feature; + } + + /** + * Get configured feature. + * @return {@link ConfiguredFeature}. + */ + public ConfiguredFeature getFeatureConfigured() { + return featureConfigured; + } + + /** + * Get feature decoration step. + * @return {@link Decoration}. + */ + public Decoration getFeatureStep() { + return featureStep; + } + + /** + * Will create a basic plant feature. + * @param id {@link ResourceLocation} feature ID. + * @param feature {@link net.minecraft.world.level.levelgen.feature.Feature} with {@link NoneFeatureConfiguration} config. + * @param density iterations per chunk. + * @return new BCLFeature instance. + */ + public static BCLFeature makeVegetationFeature(ResourceLocation id, net.minecraft.world.level.levelgen.feature.Feature feature, int density) { ConfiguredFeature configured = feature .configured(FeatureConfiguration.NONE) .decorated(BCLDecorators.HEIGHTMAP_SQUARE) .countRandom(density); - return new BCLFeature(id, feature, GenerationStep.Decoration.VEGETAL_DECORATION, configured); + return new BCLFeature(id, feature, Decoration.VEGETAL_DECORATION, configured); } - public static BCLFeature makeRawGenFeature(ResourceLocation id, Feature feature, int chance) { - ConfiguredFeature configured = feature - .configured(FeatureConfiguration.NONE) - .decorated(FeatureDecorator.CHANCE.configured(new ChanceDecoratorConfiguration(chance))); - return new BCLFeature(id, feature, GenerationStep.Decoration.RAW_GENERATION, configured); - } - - @Deprecated - public static BCLFeature makeLakeFeature(ResourceLocation id, Feature feature, int chance) { - ConfiguredFeature configured = feature - .configured(FeatureConfiguration.NONE) - .decorated(FeatureDecorator.LAVA_LAKE.configured(new ChanceDecoratorConfiguration(chance))); - return new BCLFeature(id, feature, GenerationStep.Decoration.LAKES, configured); - } - - public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, int veins, int veinSize, int offset, int minY, int maxY) { + /** + * Will create a basic ore feature. + * @param id {@link ResourceLocation} feature ID. + * @param blockOre {@link Decoration} feature step. + * @param hostBlock {@link Block} to generate feature in. + * @param veins iterations per chunk. + * @param veinSize size of ore vein. + * @param minY minimum height. + * @param maxY maximum height. + * @return new BCLFeature instance. + */ + public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, Block hostBlock, int veins, int veinSize, int minY, int maxY) { OreConfiguration featureConfig = new OreConfiguration( - new BlockMatchTest(Blocks.END_STONE), + new BlockMatchTest(hostBlock), blockOre.defaultBlockState(), veinSize ); - OreConfiguration config = new OreConfiguration(ANY_TERRAIN, blockOre.defaultBlockState(), 33); - ConfiguredFeature oreFeature = Feature.ORE + ConfiguredFeature oreFeature = net.minecraft.world.level.levelgen.feature.Feature.ORE .configured(featureConfig) .rangeUniform( VerticalAnchor.absolute(minY), @@ -77,46 +97,95 @@ public class BCLFeature { .squared() .count(veins); return new BCLFeature( - Feature.ORE, + net.minecraft.world.level.levelgen.feature.Feature.ORE, Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, id, oreFeature), - GenerationStep.Decoration.UNDERGROUND_ORES + Decoration.UNDERGROUND_ORES ); } - public static BCLFeature makeChunkFeature(ResourceLocation id, Feature feature) { + /** + * Will create feature which will be generated once in each chunk. + * @param id {@link ResourceLocation} feature ID. + * @param step {@link Decoration} feature step. + * @param feature {@link net.minecraft.world.level.levelgen.feature.Feature} with {@link NoneFeatureConfiguration} config. + * @return new BCLFeature instance. + */ + public static BCLFeature makeChunkFeature(ResourceLocation id, Decoration step, net.minecraft.world.level.levelgen.feature.Feature feature) { ConfiguredFeature configured = feature .configured(FeatureConfiguration.NONE) .decorated(FeatureDecorator.COUNT.configured(new CountConfiguration(1))); - return new BCLFeature(id, feature, GenerationStep.Decoration.LOCAL_MODIFICATIONS, configured); + return new BCLFeature(id, feature, step, configured); } - public static BCLFeature makeChansedFeature(ResourceLocation id, Feature feature, int chance) { + /** + * Will create feature with chanced decoration, chance for feature to generate per chunk is 1 / chance. + * @param id {@link ResourceLocation} feature ID. + * @param step {@link Decoration} feature step. + * @param feature {@link net.minecraft.world.level.levelgen.feature.Feature} with {@link NoneFeatureConfiguration} config. + * @param chance chance for feature to be generated in. + * @return new BCLFeature instance. + */ + public static BCLFeature makeChancedFeature(ResourceLocation id, Decoration step, net.minecraft.world.level.levelgen.feature.Feature feature, int chance) { ConfiguredFeature configured = feature .configured(FeatureConfiguration.NONE) .decorated(FeatureDecorator.CHANCE.configured(new ChanceDecoratorConfiguration(chance))); - return new BCLFeature(id, feature, GenerationStep.Decoration.SURFACE_STRUCTURES, configured); + return new BCLFeature(id, feature, step, configured); } - public static BCLFeature makeCountRawFeature(ResourceLocation id, Feature feature, int chance) { - ConfiguredFeature configured = feature.configured(FeatureConfiguration.NONE) - .decorated(FeatureDecorator.COUNT.configured(new CountConfiguration(chance))); - return new BCLFeature(id, feature, GenerationStep.Decoration.RAW_GENERATION, configured); + /** + * Will create feature with specified generation iterations per chunk. + * @param id {@link ResourceLocation} feature ID. + * @param step {@link Decoration} feature step. + * @param feature {@link net.minecraft.world.level.levelgen.feature.Feature} with {@link NoneFeatureConfiguration} config. + * @param count iterations steps. + * @return new BCLFeature instance. + */ + public static BCLFeature makeCountFeature(ResourceLocation id, Decoration step, net.minecraft.world.level.levelgen.feature.Feature feature, int count) { + ConfiguredFeature configured = feature + .configured(FeatureConfiguration.NONE) + .decorated(FeatureDecorator.COUNT.configured(new CountConfiguration(count))); + return new BCLFeature(id, feature, step, configured); } - public static BCLFeature makeFeatureConfigured(ResourceLocation id, Feature feature) { + /** + * Makes simple configured feature with {@link NoneFeatureConfiguration} set to NONE. + * @param id {@link ResourceLocation} feature ID. + * @param step {@link Decoration} feature step. + * @param feature {@link net.minecraft.world.level.levelgen.feature.Feature} with {@link NoneFeatureConfiguration} config. + * @return new BCLFeature instance. + */ + public static BCLFeature makeFeatureConfigured(ResourceLocation id, Decoration step, net.minecraft.world.level.levelgen.feature.Feature feature) { ConfiguredFeature configured = feature.configured(FeatureConfiguration.NONE); - return new BCLFeature(id, feature, GenerationStep.Decoration.RAW_GENERATION, configured); + return new BCLFeature(id, feature, step, configured); } - public Feature getFeature() { - return feature; + @Deprecated(forRemoval = true) + public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, Block hostBlock, int veins, int veinSize, int offset, int minY, int maxY) { + return makeOreFeature(id, blockOre, hostBlock, veins, veinSize, minY, maxY); } - public ConfiguredFeature getFeatureConfigured() { - return featureConfigured; + @Deprecated(forRemoval = true) + public static BCLFeature makeRawGenFeature(ResourceLocation id, net.minecraft.world.level.levelgen.feature.Feature feature, int chance) { + return makeChancedFeature(id, Decoration.RAW_GENERATION, feature, chance); } - public GenerationStep.Decoration getFeatureStep() { - return featureStep; + @Deprecated(forRemoval = true) + public static BCLFeature makeChunkFeature(ResourceLocation id, net.minecraft.world.level.levelgen.feature.Feature feature) { + return makeChunkFeature(id, Decoration.LOCAL_MODIFICATIONS, feature); + } + + @Deprecated(forRemoval = true) + public static BCLFeature makeChansedFeature(ResourceLocation id, net.minecraft.world.level.levelgen.feature.Feature feature, int chance) { + return makeChancedFeature(id, Decoration.SURFACE_STRUCTURES, feature, chance); + } + + @Deprecated(forRemoval = true) + public static BCLFeature makeCountRawFeature(ResourceLocation id, net.minecraft.world.level.levelgen.feature.Feature feature, int chance) { + return makeCountFeature(id, Decoration.RAW_GENERATION, feature, chance); + } + + @Deprecated(forRemoval = true) + public static BCLFeature makeFeatureConfigured(ResourceLocation id, net.minecraft.world.level.levelgen.feature.Feature feature) { + return makeFeatureConfigured(id, Decoration.RAW_GENERATION, feature); } } diff --git a/src/main/java/ru/bclib/world/features/NBTStructureFeature.java b/src/main/java/ru/bclib/world/features/NBTStructureFeature.java index acaed3ec..37aa0050 100644 --- a/src/main/java/ru/bclib/world/features/NBTStructureFeature.java +++ b/src/main/java/ru/bclib/world/features/NBTStructureFeature.java @@ -18,6 +18,7 @@ import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConf import net.minecraft.world.level.levelgen.structure.BoundingBox; import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings; import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; +import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderConfiguration; import ru.bclib.api.BiomeAPI; import ru.bclib.api.TagAPI; import ru.bclib.util.BlocksHelper; diff --git a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java index 7e236521..97bd8e81 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java @@ -9,13 +9,13 @@ import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome.BiomeCategory; import net.minecraft.world.level.biome.BiomeSource; import net.minecraft.world.level.biome.Biomes; -import net.minecraft.world.level.biome.Climate; import net.minecraft.world.level.biome.TheEndBiomeSource; -import net.minecraft.world.level.levelgen.LegacyRandomSource; import net.minecraft.world.level.levelgen.WorldgenRandom; import net.minecraft.world.level.levelgen.synth.SimplexNoise; import ru.bclib.BCLib; import ru.bclib.api.BiomeAPI; +import ru.bclib.config.ConfigKeeper.StringArrayEntry; +import ru.bclib.config.Configs; import ru.bclib.noise.OpenSimplexNoise; import ru.bclib.world.biomes.BCLBiome; @@ -48,7 +48,7 @@ public class BCLibEndBiomeSource extends BiomeSource { BiomeAPI.END_LAND_BIOME_PICKER.clearMutables(); BiomeAPI.END_VOID_BIOME_PICKER.clearMutables(); - this.possibleBiomes().forEach(biome -> { + this.possibleBiomes.forEach(biome -> { ResourceLocation key = biomeRegistry.getKey(biome); if (!BiomeAPI.hasBiome(key)) { BCLBiome bclBiome = new BCLBiome(key, biome, 1, 1); @@ -64,6 +64,8 @@ public class BCLibEndBiomeSource extends BiomeSource { } }); + Configs.BIOMES_CONFIG.saveChanges(); + BiomeAPI.END_LAND_BIOME_PICKER.getBiomes().forEach(biome -> biome.updateActualBiomes(biomeRegistry)); BiomeAPI.END_VOID_BIOME_PICKER.getBiomes().forEach(biome -> biome.updateActualBiomes(biomeRegistry)); @@ -86,8 +88,19 @@ public class BCLibEndBiomeSource extends BiomeSource { } private static List getBiomes(Registry biomeRegistry) { + List include = Configs.BIOMES_CONFIG.getEntry("force_include", "end_biomes", StringArrayEntry.class).getValue(); + return biomeRegistry.stream().filter(biome -> { ResourceLocation key = biomeRegistry.getKey(biome); + + if (include.contains(key.toString())) { + return true; + } + + if (GeneratorOptions.addEndBiomesByCategory() && biome.getBiomeCategory() == BiomeCategory.THEEND) { + return true; + } + BCLBiome bclBiome = BiomeAPI.getBiome(key); if (bclBiome != BiomeAPI.EMPTY_BIOME) { if (bclBiome.hasParentBiome()) { @@ -100,7 +113,7 @@ public class BCLibEndBiomeSource extends BiomeSource { } @Override - public Biome getNoiseBiome(int biomeX, int biomeY, int biomeZ, Climate.Sampler sampler) { + public Biome getBiomeForNoiseGen(int biomeX, int biomeY, int biomeZ) { long i = (long) biomeX * (long) biomeX; long j = (long) biomeZ * (long) biomeZ; long check = GeneratorOptions.isFarEndBiomes() ? 65536L : 625L; diff --git a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java index e992b5b3..754b8d7d 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java @@ -8,9 +8,10 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome.BiomeCategory; import net.minecraft.world.level.biome.BiomeSource; -import net.minecraft.world.level.biome.Climate; import ru.bclib.BCLib; import ru.bclib.api.BiomeAPI; +import ru.bclib.config.ConfigKeeper.StringArrayEntry; +import ru.bclib.config.Configs; import ru.bclib.world.biomes.BCLBiome; import java.util.LinkedList; @@ -37,7 +38,7 @@ public class BCLibNetherBiomeSource extends BiomeSource { BiomeAPI.NETHER_BIOME_PICKER.clearMutables(); - this.possibleBiomes().forEach(biome -> { + this.possibleBiomes.forEach(biome -> { ResourceLocation key = biomeRegistry.getKey(biome); if (!BiomeAPI.hasBiome(key)) { BCLBiome bclBiome = new BCLBiome(key, biome, 1, 1); @@ -53,6 +54,7 @@ public class BCLibNetherBiomeSource extends BiomeSource { } }); + Configs.BIOMES_CONFIG.saveChanges(); BiomeAPI.NETHER_BIOME_PICKER.getBiomes().forEach(biome -> biome.updateActualBiomes(biomeRegistry)); BiomeAPI.NETHER_BIOME_PICKER.rebuild(); @@ -64,8 +66,19 @@ public class BCLibNetherBiomeSource extends BiomeSource { } private static List getBiomes(Registry biomeRegistry) { + List include = Configs.BIOMES_CONFIG.getEntry("force_include", "nether_biomes", StringArrayEntry.class).getValue(); + return biomeRegistry.stream().filter(biome -> { ResourceLocation key = biomeRegistry.getKey(biome); + + if (include.contains(key.toString())) { + return true; + } + + if (GeneratorOptions.addNetherBiomesByCategory() && biome.getBiomeCategory() == BiomeCategory.NETHER) { + return true; + } + BCLBiome bclBiome = BiomeAPI.getBiome(key); if (bclBiome != BiomeAPI.EMPTY_BIOME) { if (bclBiome.hasParentBiome()) { @@ -78,7 +91,7 @@ public class BCLibNetherBiomeSource extends BiomeSource { } @Override - public Biome getNoiseBiome(int biomeX, int biomeY, int biomeZ, Climate.Sampler sampler) { + public Biome getBiomeForNoiseGen(int biomeX, int biomeY, int biomeZ) { if ((biomeX & 63) == 0 && (biomeZ & 63) == 0) { biomeMap.clearCache(); } diff --git a/src/main/java/ru/bclib/world/generator/BiomeMap.java b/src/main/java/ru/bclib/world/generator/BiomeMap.java index 43614a3d..a244029c 100644 --- a/src/main/java/ru/bclib/world/generator/BiomeMap.java +++ b/src/main/java/ru/bclib/world/generator/BiomeMap.java @@ -2,7 +2,6 @@ package ru.bclib.world.generator; import com.google.common.collect.Maps; import net.minecraft.world.level.ChunkPos; -import net.minecraft.world.level.levelgen.LegacyRandomSource; import net.minecraft.world.level.levelgen.WorldgenRandom; import ru.bclib.noise.OpenSimplexNoise; import ru.bclib.util.MHelper; diff --git a/src/main/java/ru/bclib/world/generator/GeneratorOptions.java b/src/main/java/ru/bclib/world/generator/GeneratorOptions.java index a2b80ad4..af5c084d 100644 --- a/src/main/java/ru/bclib/world/generator/GeneratorOptions.java +++ b/src/main/java/ru/bclib/world/generator/GeneratorOptions.java @@ -14,6 +14,8 @@ public class GeneratorOptions { private static boolean farEndBiomes = true; private static boolean customNetherBiomeSource = true; private static boolean customEndBiomeSource = true; + private static boolean addNetherBiomesByCategory = false; + private static boolean addEndBiomesByCategory = false; public static void init() { biomeSizeNether = Configs.GENERATOR_CONFIG.getInt("nether.biomeMap", "biomeSize", 256); @@ -21,6 +23,8 @@ public class GeneratorOptions { biomeSizeEndVoid = Configs.GENERATOR_CONFIG.getInt("end.biomeMap", "biomeSizeVoid", 256); customNetherBiomeSource = Configs.GENERATOR_CONFIG.getBoolean("options", "customNetherBiomeSource", true); customEndBiomeSource = Configs.GENERATOR_CONFIG.getBoolean("options", "customEndBiomeSource", true); + addNetherBiomesByCategory = Configs.GENERATOR_CONFIG.getBoolean("options", "addNetherBiomesByCategory", false); + addEndBiomesByCategory = Configs.GENERATOR_CONFIG.getBoolean("options", "addEndBiomesByCategory", false); } public static int getBiomeSizeNether() { @@ -58,4 +62,12 @@ public class GeneratorOptions { public static boolean customEndBiomeSource() { return customEndBiomeSource; } + + public static boolean addNetherBiomesByCategory() { + return addNetherBiomesByCategory; + } + + public static boolean addEndBiomesByCategory() { + return addEndBiomesByCategory; + } } diff --git a/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java b/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java index bef51070..4497bfc7 100644 --- a/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java +++ b/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java @@ -1,6 +1,7 @@ package ru.bclib.world.structures; import net.fabricmc.fabric.api.structure.v1.FabricStructureBuilder; +import net.fabricmc.fabric.mixin.structure.FlatChunkGeneratorConfigAccessor; import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.levelgen.GenerationStep; @@ -24,9 +25,7 @@ public class BCLStructureFeature { .register(); this.featureConfigured = this.structure.configured(NoneFeatureConfiguration.NONE); BuiltinRegistries.register(BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE, id, this.featureConfigured); - // TODO: (1.18) Find Alternative for this mapping - //FlatLevelGeneratorSettings.getStructureToFeatures().put(this.structure, this.featureConfigured); - + FlatChunkGeneratorConfigAccessor.getStructureToFeatures().put(this.structure, this.featureConfigured); } public StructureFeature getStructure() { diff --git a/src/main/java/ru/bclib/world/surface/DoubleBlockSurfaceBuilder.java b/src/main/java/ru/bclib/world/surface/DoubleBlockSurfaceBuilder.java index 3a2b1b6d..434b1a39 100644 --- a/src/main/java/ru/bclib/world/surface/DoubleBlockSurfaceBuilder.java +++ b/src/main/java/ru/bclib/world/surface/DoubleBlockSurfaceBuilder.java @@ -5,7 +5,7 @@ import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.chunk.BlockColumn; +import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.levelgen.surfacebuilders.ConfiguredSurfaceBuilder; import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilder; import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderBaseConfiguration; @@ -43,13 +43,13 @@ public class DoubleBlockSurfaceBuilder extends SurfaceBuilder Date: Tue, 30 Nov 2021 21:19:44 +0100 Subject: [PATCH 18/96] Added back AccessWidener --- bclib.gradle | 8 ++++++-- src/main/resources/bclib.accesswidener | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/bclib.accesswidener diff --git a/bclib.gradle b/bclib.gradle index ec8dbbaf..2f8a64ae 100644 --- a/bclib.gradle +++ b/bclib.gradle @@ -7,8 +7,8 @@ buildscript { gradlePluginPortal() } } -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 +sourceCompatibility = JavaVersion.VERSION_16 +targetCompatibility = JavaVersion.VERSION_16 archivesBaseName = project.archives_base_name version = project.mod_version @@ -23,6 +23,10 @@ repositories { maven { url 'https://jitpack.io' } } +minecraft { + accessWidener = file("src/main/resources/bclib.accesswidener") +} + dependencies { minecraft "com.mojang:minecraft:${project.minecraft_version}" mappings minecraft.officialMojangMappings() diff --git a/src/main/resources/bclib.accesswidener b/src/main/resources/bclib.accesswidener new file mode 100644 index 00000000..3efe4455 --- /dev/null +++ b/src/main/resources/bclib.accesswidener @@ -0,0 +1,4 @@ +accessWidener v1 named + +# Classes +accessible class net/minecraft/client/Minecraft$ExperimentalDialogType \ No newline at end of file From ddddfa1492b031e7519c2772d2bb4a8e5457d31b Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 30 Nov 2021 21:55:35 +0100 Subject: [PATCH 19/96] Fixed some mixins --- src/main/java/ru/bclib/api/BiomeAPI.java | 1 - .../ru/bclib/mixin/common/BiomeMixin.java | 28 ------------------- .../mixin/common/ChunkGeneratorMixin.java | 26 +++++++++++++++++ .../mixin/common/WorldGenRegionMixin.java | 4 +-- src/main/resources/bclib.mixins.common.json | 2 +- 5 files changed, 29 insertions(+), 32 deletions(-) delete mode 100644 src/main/java/ru/bclib/mixin/common/BiomeMixin.java create mode 100644 src/main/java/ru/bclib/mixin/common/ChunkGeneratorMixin.java diff --git a/src/main/java/ru/bclib/api/BiomeAPI.java b/src/main/java/ru/bclib/api/BiomeAPI.java index 4cd48391..e6bc49c6 100644 --- a/src/main/java/ru/bclib/api/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/BiomeAPI.java @@ -7,7 +7,6 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.fabricmc.fabric.impl.biome.InternalBiomeData; import net.fabricmc.fabric.impl.biome.NetherBiomeData; import net.fabricmc.fabric.impl.biome.TheEndBiomeData; import net.fabricmc.fabric.mixin.biome.modification.GenerationSettingsAccessor; diff --git a/src/main/java/ru/bclib/mixin/common/BiomeMixin.java b/src/main/java/ru/bclib/mixin/common/BiomeMixin.java deleted file mode 100644 index 26f16bcb..00000000 --- a/src/main/java/ru/bclib/mixin/common/BiomeMixin.java +++ /dev/null @@ -1,28 +0,0 @@ -package ru.bclib.mixin.common; - -import net.minecraft.core.BlockPos; -import net.minecraft.server.level.WorldGenRegion; -import net.minecraft.world.level.StructureFeatureManager; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.chunk.ChunkGenerator; -import net.minecraft.world.level.levelgen.WorldgenRandom; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyArg; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(Biome.class) -public class BiomeMixin { - private int bclib_featureIteratorSeed; - - @ModifyArg(method = "generate", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/levelgen/WorldgenRandom;setFeatureSeed(JII)J")) - private long bclib_updateFeatureSeed(long seed) { - return Long.rotateRight(seed, bclib_featureIteratorSeed++); - } - - @Inject(method = "generate", at = @At("HEAD")) - private void bclib_obBiomeGenerate(StructureFeatureManager structureFeatureManager, ChunkGenerator chunkGenerator, WorldGenRegion worldGenRegion, long l, WorldgenRandom worldgenRandom, BlockPos blockPos, CallbackInfo info) { - bclib_featureIteratorSeed = 0; - } -} diff --git a/src/main/java/ru/bclib/mixin/common/ChunkGeneratorMixin.java b/src/main/java/ru/bclib/mixin/common/ChunkGeneratorMixin.java new file mode 100644 index 00000000..9c6058ac --- /dev/null +++ b/src/main/java/ru/bclib/mixin/common/ChunkGeneratorMixin.java @@ -0,0 +1,26 @@ +package ru.bclib.mixin.common; + +import net.minecraft.world.level.StructureFeatureManager; +import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.chunk.ChunkAccess; +import net.minecraft.world.level.chunk.ChunkGenerator; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyArg; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ChunkGenerator.class) +public class ChunkGeneratorMixin { + private int bclib_featureIteratorSeed; + + @ModifyArg(method = "applyBiomeDecoration", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/levelgen/WorldgenRandom;setFeatureSeed(JII)V")) + private long bclib_updateFeatureSeed(long seed) { + return Long.rotateRight(seed, bclib_featureIteratorSeed++); + } + + @Inject(method = "applyBiomeDecoration", at = @At("HEAD")) + private void bclib_obBiomeGenerate(WorldGenLevel worldGenLevel, ChunkAccess chunkAccess, StructureFeatureManager structureFeatureManager, CallbackInfo ci) { + bclib_featureIteratorSeed = 0; + } +} diff --git a/src/main/java/ru/bclib/mixin/common/WorldGenRegionMixin.java b/src/main/java/ru/bclib/mixin/common/WorldGenRegionMixin.java index a8866f3e..08cde84d 100644 --- a/src/main/java/ru/bclib/mixin/common/WorldGenRegionMixin.java +++ b/src/main/java/ru/bclib/mixin/common/WorldGenRegionMixin.java @@ -2,7 +2,7 @@ package ru.bclib.mixin.common; import net.minecraft.core.BlockPos; import net.minecraft.server.level.WorldGenRegion; -import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.chunk.ChunkAccess; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -14,7 +14,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; public class WorldGenRegionMixin { @Final @Shadow - private ChunkPos center; + private ChunkAccess center; @Inject(method = "ensureCanWrite", at = @At("HEAD"), cancellable = true) private void be_alterBlockCheck(BlockPos blockPos, CallbackInfoReturnable info) { diff --git a/src/main/resources/bclib.mixins.common.json b/src/main/resources/bclib.mixins.common.json index 6ed5ea26..5e03cbe7 100644 --- a/src/main/resources/bclib.mixins.common.json +++ b/src/main/resources/bclib.mixins.common.json @@ -6,7 +6,7 @@ "mixins": [ "AnvilBlockMixin", "AnvilMenuMixin", - "BiomeMixin", + "ChunkGeneratorMixin", "BoneMealItemMixin", "ChunkBiomeContainerMixin", "ComposterBlockAccessor", From 99840b8ee2ae208b805479a6ad34fb9c9cfa8881 Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 30 Nov 2021 22:29:58 +0100 Subject: [PATCH 20/96] Fixed `BCLFeature` --- src/main/java/ru/bclib/api/BiomeAPI.java | 3 +- .../common/FeatureDecoratorsAccessor.java | 6 +- .../ru/bclib/world/biomes/BCLBiomeDef.java | 2 +- .../bclib/world/features/BCLDecorators.java | 10 +- .../ru/bclib/world/features/BCLFeature.java | 104 ++++++++++++------ 5 files changed, 78 insertions(+), 47 deletions(-) diff --git a/src/main/java/ru/bclib/api/BiomeAPI.java b/src/main/java/ru/bclib/api/BiomeAPI.java index e6bc49c6..a096b425 100644 --- a/src/main/java/ru/bclib/api/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/BiomeAPI.java @@ -1,6 +1,5 @@ package ru.bclib.api; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.google.common.collect.Maps; @@ -445,7 +444,7 @@ public class BiomeAPI { List>>> biomeFeatures = getMutableList(accessor.fabric_getFeatures()); for (BCLFeature feature: features) { List>> list = getList(feature.getFeatureStep(), biomeFeatures); - list.add(feature::getFeatureConfigured); + list.add(feature::getPlacedFeature); } accessor.fabric_setFeatures(biomeFeatures); } diff --git a/src/main/java/ru/bclib/mixin/common/FeatureDecoratorsAccessor.java b/src/main/java/ru/bclib/mixin/common/FeatureDecoratorsAccessor.java index 5e6ed7ad..e5bc92f3 100644 --- a/src/main/java/ru/bclib/mixin/common/FeatureDecoratorsAccessor.java +++ b/src/main/java/ru/bclib/mixin/common/FeatureDecoratorsAccessor.java @@ -1,11 +1,9 @@ package ru.bclib.mixin.common; -import net.minecraft.world.level.levelgen.placement.ConfiguredDecorator; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; @Mixin(targets = "net.minecraft.data.worldgen.Features$Decorators") public interface FeatureDecoratorsAccessor { - @Accessor("HEIGHTMAP_SQUARE") - ConfiguredDecorator bclib_getHeightmapSquare(); + /*@Accessor("HEIGHTMAP_SQUARE") + ConfiguredDecorator bclib_getHeightmapSquare();*/ } diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java index 8d91066f..f7f2a315 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java @@ -235,7 +235,7 @@ public class BCLBiomeDef { public BCLBiomeDef addFeature(BCLFeature feature) { FeatureInfo info = new FeatureInfo(); info.featureStep = feature.getFeatureStep(); - info.feature = feature.getFeatureConfigured(); + info.feature = feature.getPlacedFeature(); features.add(info); return this; } diff --git a/src/main/java/ru/bclib/world/features/BCLDecorators.java b/src/main/java/ru/bclib/world/features/BCLDecorators.java index ee5b60b2..ca8f377d 100644 --- a/src/main/java/ru/bclib/world/features/BCLDecorators.java +++ b/src/main/java/ru/bclib/world/features/BCLDecorators.java @@ -1,13 +1,7 @@ package ru.bclib.world.features; -import net.minecraft.data.worldgen.Features; -import net.minecraft.world.level.levelgen.placement.ConfiguredDecorator; -import ru.bclib.BCLib; - -import java.lang.reflect.Field; - public class BCLDecorators { - public static final ConfiguredDecorator HEIGHTMAP_SQUARE; + /*public static final ConfiguredDecorator HEIGHTMAP_SQUARE; private static final ConfiguredDecorator getDecorator(Field[] fields, int index) { try { @@ -23,5 +17,5 @@ public class BCLDecorators { Class[] classes = Features.class.getDeclaredClasses(); Field[] fields = classes[1].getDeclaredFields(); // Decorators class HEIGHTMAP_SQUARE = getDecorator(fields, 17); - } + }*/ } diff --git a/src/main/java/ru/bclib/world/features/BCLFeature.java b/src/main/java/ru/bclib/world/features/BCLFeature.java index e954f22a..52122358 100644 --- a/src/main/java/ru/bclib/world/features/BCLFeature.java +++ b/src/main/java/ru/bclib/world/features/BCLFeature.java @@ -2,33 +2,38 @@ package ru.bclib.world.features; import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; +import net.minecraft.data.worldgen.placement.PlacementUtils; import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.valueproviders.UniformInt; 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.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.Feature; -import net.minecraft.world.level.levelgen.feature.configurations.CountConfiguration; import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration; -import net.minecraft.world.level.levelgen.placement.ChanceDecoratorConfiguration; -import net.minecraft.world.level.levelgen.placement.FeatureDecorator; +import net.minecraft.world.level.levelgen.heightproviders.UniformHeight; +import net.minecraft.world.level.levelgen.placement.BiomeFilter; +import net.minecraft.world.level.levelgen.placement.CountPlacement; +import net.minecraft.world.level.levelgen.placement.HeightRangePlacement; +import net.minecraft.world.level.levelgen.placement.InSquarePlacement; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; +import net.minecraft.world.level.levelgen.placement.RarityFilter; import net.minecraft.world.level.levelgen.structure.templatesystem.BlockMatchTest; public class BCLFeature { - private ConfiguredFeature featureConfigured; + private PlacedFeature placedFeature; private Decoration featureStep; private Feature feature; - public BCLFeature(Feature feature, ConfiguredFeature configuredFeature, Decoration featureStep) { - this.featureConfigured = configuredFeature; + public BCLFeature(Feature feature, PlacedFeature placedFeature, Decoration featureStep) { + this.placedFeature = placedFeature; this.featureStep = featureStep; this.feature = feature; } - public BCLFeature(ResourceLocation id, Feature feature, Decoration featureStep, ConfiguredFeature configuredFeature) { - this.featureConfigured = Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, id, configuredFeature); + public BCLFeature(ResourceLocation id, Feature feature, Decoration featureStep, PlacedFeature placedFeature) { + this.placedFeature = Registry.register(BuiltinRegistries.PLACED_FEATURE, id, placedFeature); this.feature = Registry.register(Registry.FEATURE, id, feature); this.featureStep = featureStep; } @@ -43,10 +48,10 @@ public class BCLFeature { /** * Get configured feature. - * @return {@link ConfiguredFeature}. + * @return {@link PlacedFeature}. */ - public ConfiguredFeature getFeatureConfigured() { - return featureConfigured; + public PlacedFeature getPlacedFeature() { + return placedFeature; } /** @@ -56,7 +61,6 @@ public class BCLFeature { public Decoration getFeatureStep() { return featureStep; } - /** * Will create a basic plant feature. * @param id {@link ResourceLocation} feature ID. @@ -65,13 +69,18 @@ public class BCLFeature { * @return new BCLFeature instance. */ public static BCLFeature makeVegetationFeature(ResourceLocation id, Feature feature, int density) { - ConfiguredFeature configured = feature + PlacedFeature configured = feature .configured(FeatureConfiguration.NONE) - .decorated(BCLDecorators.HEIGHTMAP_SQUARE) - .countRandom(density); + .placed( + CountPlacement.of(UniformInt.of(0, 4)), + InSquarePlacement.spread(), + PlacementUtils.HEIGHTMAP, + BiomeFilter.biome() + ); + //.decorated(BCLDecorators.HEIGHTMAP_SQUARE) + //.countRandom(density); return new BCLFeature(id, feature, Decoration.VEGETAL_DECORATION, configured); } - /** * Will create a basic ore feature. * @param id {@link ResourceLocation} feature ID. @@ -84,22 +93,50 @@ public class BCLFeature { * @return new BCLFeature instance. */ public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, Block hostBlock, int veins, int veinSize, int minY, int maxY) { + return makeOreFeature(id, blockOre, hostBlock, veins, veinSize, minY, maxY, false); + } + + /** + * Will create a basic ore feature. + * + * @param id {@link ResourceLocation} feature ID. + * @param blockOre {@link Decoration} feature step. + * @param hostBlock {@link Block} to generate feature in. + * @param veins iterations per chunk. + * @param veinSize size of ore vein. + * @param minY minimum height. + * @param maxY maximum height. + * @param rare when true, this is placed as a rare resource + * @return new BCLFeature instance. + */ + public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, Block hostBlock, int veins, int veinSize, int minY, int maxY, boolean rare) { OreConfiguration featureConfig = new OreConfiguration( new BlockMatchTest(hostBlock), blockOre.defaultBlockState(), veinSize ); - ConfiguredFeature oreFeature = Feature.ORE + + PlacedFeature oreFeature = Feature.ORE .configured(featureConfig) - .rangeUniform( - VerticalAnchor.absolute(minY), - VerticalAnchor.absolute(maxY) - ) - .squared() - .count(veins); + .placed( + InSquarePlacement.spread(), + rare ? RarityFilter.onAverageOnceEvery(veins) : CountPlacement.of(veins), + HeightRangePlacement.of( + UniformHeight.of( + VerticalAnchor.absolute(minY), + VerticalAnchor.absolute(maxY) + ) + ), + BiomeFilter.biome()); +// .rangeUniform( +// VerticalAnchor.absolute(minY), +// VerticalAnchor.absolute(maxY) +// ) +// .squared() +// .count(veins); return new BCLFeature( net.minecraft.world.level.levelgen.feature.Feature.ORE, - Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, id, oreFeature), + Registry.register(BuiltinRegistries.PLACED_FEATURE, id, oreFeature), Decoration.UNDERGROUND_ORES ); } @@ -112,9 +149,10 @@ public class BCLFeature { * @return new BCLFeature instance. */ public static BCLFeature makeChunkFeature(ResourceLocation id, Decoration step, Feature feature) { - ConfiguredFeature configured = feature + PlacedFeature configured = feature .configured(FeatureConfiguration.NONE) - .decorated(FeatureDecorator.COUNT.configured(new CountConfiguration(1))); + .placed(CountPlacement.of(1)); + //.decorated(FeatureDecorator.COUNT.configured(new CountConfiguration(1))); return new BCLFeature(id, feature, step, configured); } @@ -127,9 +165,10 @@ public class BCLFeature { * @return new BCLFeature instance. */ public static BCLFeature makeChancedFeature(ResourceLocation id, Decoration step, Feature feature, int chance) { - ConfiguredFeature configured = feature + PlacedFeature configured = feature .configured(FeatureConfiguration.NONE) - .decorated(FeatureDecorator.CHANCE.configured(new ChanceDecoratorConfiguration(chance))); + .placed(RarityFilter.onAverageOnceEvery(chance)); + //.decorated(FeatureDecorator.CHANCE.configured(new ChanceDecoratorConfiguration(chance))); return new BCLFeature(id, feature, step, configured); } @@ -142,9 +181,10 @@ public class BCLFeature { * @return new BCLFeature instance. */ public static BCLFeature makeCountFeature(ResourceLocation id, Decoration step, Feature feature, int count) { - ConfiguredFeature configured = feature + PlacedFeature configured = feature .configured(FeatureConfiguration.NONE) - .decorated(FeatureDecorator.COUNT.configured(new CountConfiguration(count))); + .placed(CountPlacement.of(count)); + //.decorated(FeatureDecorator.COUNT.configured(new CountConfiguration(count))); return new BCLFeature(id, feature, step, configured); } @@ -156,7 +196,7 @@ public class BCLFeature { * @return new BCLFeature instance. */ public static BCLFeature makeFeatureConfigured(ResourceLocation id, Decoration step, Feature feature) { - ConfiguredFeature configured = feature.configured(FeatureConfiguration.NONE); + PlacedFeature configured = feature.configured(FeatureConfiguration.NONE).placed(); return new BCLFeature(id, feature, step, configured); } From eb287422aa460dcb594c78740240e3102a71c3b4 Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 30 Nov 2021 23:38:55 +0100 Subject: [PATCH 21/96] Adapted BiomeAPI --- src/main/java/ru/bclib/api/BiomeAPI.java | 76 +++++++++++-------- .../BiomeGenerationSettingsAccessor.java | 20 +++++ .../common/MobSpawnSettingsAccessor.java | 21 +++++ .../ru/bclib/world/features/BCLFeature.java | 1 + 4 files changed, 87 insertions(+), 31 deletions(-) create mode 100644 src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java create mode 100644 src/main/java/ru/bclib/mixin/common/MobSpawnSettingsAccessor.java diff --git a/src/main/java/ru/bclib/api/BiomeAPI.java b/src/main/java/ru/bclib/api/BiomeAPI.java index a096b425..e90d3a85 100644 --- a/src/main/java/ru/bclib/api/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/BiomeAPI.java @@ -6,10 +6,9 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.fabricmc.fabric.api.biome.v1.BiomeModifications; import net.fabricmc.fabric.impl.biome.NetherBiomeData; import net.fabricmc.fabric.impl.biome.TheEndBiomeData; -import net.fabricmc.fabric.mixin.biome.modification.GenerationSettingsAccessor; -import net.fabricmc.fabric.mixin.biome.modification.SpawnSettingsAccessor; import net.minecraft.client.Minecraft; import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; @@ -23,14 +22,17 @@ import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.MobCategory; import net.minecraft.world.level.Level; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.biome.Biome.ClimateParameters; import net.minecraft.world.level.biome.BiomeSource; import net.minecraft.world.level.biome.Biomes; +import net.minecraft.world.level.biome.Climate; import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; import net.minecraft.world.level.levelgen.GenerationStep.Decoration; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; import org.jetbrains.annotations.Nullable; +import ru.bclib.mixin.common.BiomeGenerationSettingsAccessor; +import ru.bclib.mixin.common.MobSpawnSettingsAccessor; import ru.bclib.util.MHelper; import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.biomes.FabricBiomesData; @@ -123,14 +125,16 @@ public class BiomeAPI { registerBiome(biome); NETHER_BIOME_PICKER.addBiome(biome); Random random = new Random(biome.getID().hashCode()); - //TODO: (1.18) did they add depth and scale as two new params here??? - ClimateParameters parameters = new ClimateParameters( + + //TODO: 1.18 Check parameters, depth was previously called altitude + //temperature, humidity, continentalness, erosion, depth, weirdness, offset + Climate.ParameterPoint parameters = Climate.parameters( MHelper.randRange(-1.5F, 1.5F, random), MHelper.randRange(-1.5F, 1.5F, random), + 0.0f, //new in 1.18 + 0.0f, //new in 1.18 MHelper.randRange(-1.5F, 1.5F, random), MHelper.randRange(-1.5F, 1.5F, random), - 0.0f, - 0.0f, random.nextFloat() ); ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get(); @@ -400,7 +404,7 @@ public class BiomeAPI { return; } BiomeSource source = level.getChunkSource().getGenerator().getBiomeSource(); - List biomes = source.possibleBiomes(); + Set biomes = source.possibleBiomes(); biomes.forEach(biome -> { ResourceLocation biomeID = getBiomeID(biome); @@ -426,12 +430,12 @@ public class BiomeAPI { * @param feature {@link ConfiguredFeature} to add. * @param step a {@link Decoration} step for the feature. */ - public static void addBiomeFeature(Biome biome, ConfiguredFeature feature, Decoration step) { - GenerationSettingsAccessor accessor = (GenerationSettingsAccessor) biome.getGenerationSettings(); - List>>> biomeFeatures = getMutableList(accessor.fabric_getFeatures()); - List>> list = getList(step, biomeFeatures); + public static void addBiomeFeature(Biome biome, PlacedFeature feature, Decoration step) { + BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings(); + List>> biomeFeatures = getMutableList(accessor.bcl_getFeatures()); + List> list = getList(step, biomeFeatures); list.add(() -> feature); - accessor.fabric_setFeatures(biomeFeatures); + accessor.bcl_setFeatures(biomeFeatures); } /** @@ -440,13 +444,13 @@ public class BiomeAPI { * @param features array of {@link BCLFeature} to add. */ public static void addBiomeFeatures(Biome biome, BCLFeature... features) { - GenerationSettingsAccessor accessor = (GenerationSettingsAccessor) biome.getGenerationSettings(); - List>>> biomeFeatures = getMutableList(accessor.fabric_getFeatures()); + BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings(); + List>> biomeFeatures = getMutableList(accessor.bcl_getFeatures()); for (BCLFeature feature: features) { - List>> list = getList(feature.getFeatureStep(), biomeFeatures); + List> list = getList(feature.getFeatureStep(), biomeFeatures); list.add(feature::getPlacedFeature); } - accessor.fabric_setFeatures(biomeFeatures); + accessor.bcl_setFeatures(biomeFeatures); } /** @@ -455,42 +459,52 @@ public class BiomeAPI { * @param lists biome accessor lists. * @return mutable {@link ConfiguredFeature} list. */ - private static List>> getList(Decoration step, List>>> lists) { + private static List> getList(Decoration step, List>> lists) { int index = step.ordinal(); if (lists.size() <= index) { for (int i = lists.size(); i <= index; i++) { lists.add(Lists.newArrayList()); } } - List>> list = getMutableList(lists.get(index)); + List> list = getMutableList(lists.get(index)); lists.set(index, list); return list; } + // TODO: 1.18 There are no more StructureFeatures in the Biomes, they are in a separate registry now /** * Adds new structure feature to existing biome. * @param biome {@link Biome} to add structure feature in. * @param structure {@link ConfiguredStructureFeature} to add. */ public static void addBiomeStructure(Biome biome, ConfiguredStructureFeature structure) { - GenerationSettingsAccessor accessor = (GenerationSettingsAccessor) biome.getGenerationSettings(); - List>> biomeStructures = getMutableList(accessor.fabric_getStructureFeatures()); - biomeStructures.add(() -> structure); - accessor.fabric_setStructureFeatures(biomeStructures); + BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE.getResourceKey(structure) + .ifPresent((key)-> + BiomeModifications.addStructure( + (ctx)->ctx.getBiomeKey().equals(BuiltinRegistries.BIOME.getKey(biome)), + key + )); +// BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings(); +// List>> biomeStructures = getMutableList(accessor.fabric_getStructureFeatures()); +// biomeStructures.add(() -> structure); +// accessor.fabric_setStructureFeatures(biomeStructures); } - + /** * Adds new structure features to existing biome. * @param biome {@link Biome} to add structure features in. * @param structures array of {@link BCLStructureFeature} to add. */ public static void addBiomeStructures(Biome biome, BCLStructureFeature... structures) { - GenerationSettingsAccessor accessor = (GenerationSettingsAccessor) biome.getGenerationSettings(); - List>> biomeStructures = getMutableList(accessor.fabric_getStructureFeatures()); for (BCLStructureFeature structure: structures) { - biomeStructures.add(structure::getFeatureConfigured); + addBiomeStructure(biome, structure.getFeatureConfigured()); } - accessor.fabric_setStructureFeatures(biomeStructures); +// GenerationSettingsAccessor accessor = (GenerationSettingsAccessor) biome.getGenerationSettings(); +// List>> biomeStructures = getMutableList(accessor.fabric_getStructureFeatures()); +// for (BCLStructureFeature structure: structures) { +// biomeStructures.add(structure::getFeatureConfigured); +// } +// accessor.fabric_setStructureFeatures(biomeStructures); } /** @@ -503,12 +517,12 @@ public class BiomeAPI { */ public static void addBiomeMobSpawn(Biome biome, EntityType entityType, int weight, int minGroupCount, int maxGroupCount) { MobCategory category = entityType.getCategory(); - SpawnSettingsAccessor accessor = (SpawnSettingsAccessor) biome.getMobSettings(); - Map> spawners = getMutableMap(accessor.fabric_getSpawners()); + MobSpawnSettingsAccessor accessor = (MobSpawnSettingsAccessor) biome.getMobSettings(); + Map> spawners = getMutableMap(accessor.bcl_getSpawners()); List mobs = spawners.containsKey(category) ? getMutableList(spawners.get(category).unwrap()) : Lists.newArrayList(); mobs.add(new SpawnerData(entityType, weight, minGroupCount, maxGroupCount)); spawners.put(category, WeightedRandomList.create(mobs)); - accessor.fabric_setSpawners(spawners); + accessor.bcl_setSpawners(spawners); } private static List getMutableList(List input) { diff --git a/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java b/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java new file mode 100644 index 00000000..9bdcd76c --- /dev/null +++ b/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java @@ -0,0 +1,20 @@ +package ru.bclib.mixin.common; + +import net.minecraft.world.level.biome.BiomeGenerationSettings; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.List; +import java.util.function.Supplier; + +@Mixin(BiomeGenerationSettings.class) +public interface BiomeGenerationSettingsAccessor { + @Accessor("features") + List>> bcl_getFeatures(); + + @Accessor("features") + @Mutable + void bcl_setFeatures(List>> value); +} diff --git a/src/main/java/ru/bclib/mixin/common/MobSpawnSettingsAccessor.java b/src/main/java/ru/bclib/mixin/common/MobSpawnSettingsAccessor.java new file mode 100644 index 00000000..e3491b73 --- /dev/null +++ b/src/main/java/ru/bclib/mixin/common/MobSpawnSettingsAccessor.java @@ -0,0 +1,21 @@ +package ru.bclib.mixin.common; + +import net.minecraft.util.random.WeightedRandomList; +import net.minecraft.world.entity.MobCategory; +import net.minecraft.world.level.biome.MobSpawnSettings; +import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.Map; + +@Mixin(MobSpawnSettings.class) +public interface MobSpawnSettingsAccessor { + @Accessor("spawners") + Map> bcl_getSpawners(); + + @Accessor("spawners") + @Mutable + void bcl_setSpawners(Map> spawners); +} diff --git a/src/main/java/ru/bclib/world/features/BCLFeature.java b/src/main/java/ru/bclib/world/features/BCLFeature.java index 52122358..0987c81a 100644 --- a/src/main/java/ru/bclib/world/features/BCLFeature.java +++ b/src/main/java/ru/bclib/world/features/BCLFeature.java @@ -93,6 +93,7 @@ public class BCLFeature { * @return new BCLFeature instance. */ public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, Block hostBlock, int veins, int veinSize, int minY, int maxY) { + //TODO: 1.18 See if this still works return makeOreFeature(id, blockOre, hostBlock, veins, veinSize, minY, maxY, false); } From 85b11f605c6c4831e103fc4dff569819cf64dac5 Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 30 Nov 2021 23:44:27 +0100 Subject: [PATCH 22/96] Adopting Fabric Biome Modifications --- src/main/java/ru/bclib/api/BiomeAPI.java | 57 +++++++++++++++--------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/src/main/java/ru/bclib/api/BiomeAPI.java b/src/main/java/ru/bclib/api/BiomeAPI.java index e90d3a85..982af38b 100644 --- a/src/main/java/ru/bclib/api/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/BiomeAPI.java @@ -16,23 +16,18 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; -import net.minecraft.util.random.WeightedRandomList; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; -import net.minecraft.world.entity.MobCategory; import net.minecraft.world.level.Level; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.BiomeSource; import net.minecraft.world.level.biome.Biomes; import net.minecraft.world.level.biome.Climate; -import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; import net.minecraft.world.level.levelgen.GenerationStep.Decoration; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import net.minecraft.world.level.levelgen.placement.PlacedFeature; import org.jetbrains.annotations.Nullable; -import ru.bclib.mixin.common.BiomeGenerationSettingsAccessor; -import ru.bclib.mixin.common.MobSpawnSettingsAccessor; import ru.bclib.util.MHelper; import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.biomes.FabricBiomesData; @@ -431,11 +426,18 @@ public class BiomeAPI { * @param step a {@link Decoration} step for the feature. */ public static void addBiomeFeature(Biome biome, PlacedFeature feature, Decoration step) { - BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings(); - List>> biomeFeatures = getMutableList(accessor.bcl_getFeatures()); - List> list = getList(step, biomeFeatures); - list.add(() -> feature); - accessor.bcl_setFeatures(biomeFeatures); + BuiltinRegistries.PLACED_FEATURE.getResourceKey(feature) + .ifPresent((key)-> + BiomeModifications.addFeature( + (ctx)->ctx.getBiomeKey().equals(BuiltinRegistries.BIOME.getKey(biome)), + step, + key + )); +// BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings(); +// List>> biomeFeatures = getMutableList(accessor.bcl_getFeatures()); +// List> list = getList(step, biomeFeatures); +// list.add(() -> feature); +// accessor.bcl_setFeatures(biomeFeatures); } /** @@ -444,13 +446,16 @@ public class BiomeAPI { * @param features array of {@link BCLFeature} to add. */ public static void addBiomeFeatures(Biome biome, BCLFeature... features) { - BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings(); - List>> biomeFeatures = getMutableList(accessor.bcl_getFeatures()); for (BCLFeature feature: features) { - List> list = getList(feature.getFeatureStep(), biomeFeatures); - list.add(feature::getPlacedFeature); + addBiomeFeature(biome, feature.getPlacedFeature(), feature.getFeatureStep()); } - accessor.bcl_setFeatures(biomeFeatures); +// BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings(); +// List>> biomeFeatures = getMutableList(accessor.bcl_getFeatures()); +// for (BCLFeature feature: features) { +// List> list = getList(feature.getFeatureStep(), biomeFeatures); +// list.add(feature::getPlacedFeature); +// } +// accessor.bcl_setFeatures(biomeFeatures); } /** @@ -516,13 +521,21 @@ public class BiomeAPI { * @param maxGroupCount maximum mobs in group. */ public static void addBiomeMobSpawn(Biome biome, EntityType entityType, int weight, int minGroupCount, int maxGroupCount) { - MobCategory category = entityType.getCategory(); - MobSpawnSettingsAccessor accessor = (MobSpawnSettingsAccessor) biome.getMobSettings(); - Map> spawners = getMutableMap(accessor.bcl_getSpawners()); - List mobs = spawners.containsKey(category) ? getMutableList(spawners.get(category).unwrap()) : Lists.newArrayList(); - mobs.add(new SpawnerData(entityType, weight, minGroupCount, maxGroupCount)); - spawners.put(category, WeightedRandomList.create(mobs)); - accessor.bcl_setSpawners(spawners); + BiomeModifications.addSpawn( + (ctx)->ctx.getBiomeKey().equals(BuiltinRegistries.BIOME.getKey(biome)), + entityType.getCategory(), + entityType, + weight, + minGroupCount, + maxGroupCount + ); +// MobCategory category = entityType.getCategory(); +// MobSpawnSettingsAccessor accessor = (MobSpawnSettingsAccessor) biome.getMobSettings(); +// Map> spawners = getMutableMap(accessor.bcl_getSpawners()); +// List mobs = spawners.containsKey(category) ? getMutableList(spawners.get(category).unwrap()) : Lists.newArrayList(); +// mobs.add(new SpawnerData(entityType, weight, minGroupCount, maxGroupCount)); +// spawners.put(category, WeightedRandomList.create(mobs)); +// accessor.bcl_setSpawners(spawners); } private static List getMutableList(List input) { From 79710dead6411b9b2fcda6f83035c53b56048c16 Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 30 Nov 2021 23:57:50 +0100 Subject: [PATCH 23/96] Removed Hydrogen Fix --- .../common/ChunkBiomeContainerMixin.java | 134 ------------------ src/main/resources/bclib.mixins.common.json | 1 - 2 files changed, 135 deletions(-) delete mode 100644 src/main/java/ru/bclib/mixin/common/ChunkBiomeContainerMixin.java diff --git a/src/main/java/ru/bclib/mixin/common/ChunkBiomeContainerMixin.java b/src/main/java/ru/bclib/mixin/common/ChunkBiomeContainerMixin.java deleted file mode 100644 index 5518fd1f..00000000 --- a/src/main/java/ru/bclib/mixin/common/ChunkBiomeContainerMixin.java +++ /dev/null @@ -1,134 +0,0 @@ -package ru.bclib.mixin.common; - -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.core.BlockPos; -import net.minecraft.util.Mth; -import net.minecraft.util.SimpleBitStorage; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.chunk.ChunkBiomeContainer; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import ru.bclib.BCLib; -import ru.bclib.interfaces.BiomeSetter; - -import java.lang.reflect.Field; - -@Mixin(ChunkBiomeContainer.class) -public class ChunkBiomeContainerMixin implements BiomeSetter { - private static boolean bclib_hasHydrogen = FabricLoader.getInstance().isModLoaded("hydrogen"); - - @Final - @Shadow - private Biome[] biomes; - - @Final - @Shadow - private static int WIDTH_BITS; - - @Final - @Shadow - private static int HORIZONTAL_MASK; - - @Override - public void bclib_setBiome(Biome biome, BlockPos pos) { - int biomeX = pos.getX() >> 2; - int biomeY = pos.getY() >> 2; - int biomeZ = pos.getZ() >> 2; - int index = be_getArrayIndex(biomeX, biomeY, biomeZ); - - if (bclib_hasHydrogen && be_shouldWriteToHydrogen()) { - try { - ChunkBiomeContainer self = (ChunkBiomeContainer) (Object) this; - SimpleBitStorage storage = be_getHydrogenStorage(self); - Biome[] palette = be_getHydrogenPalette(self); - int paletteIndex = be_getHydrogenPaletteIndex(biome, palette); - if (paletteIndex == -1) { - Biome[] newPalette = new Biome[palette.length + 1]; - System.arraycopy(palette, 0, newPalette, 0, palette.length); - paletteIndex = palette.length; - palette = newPalette; - palette[paletteIndex] = biome; - be_setHydrogenPalette(self, palette); - } - try { - storage.set(index, paletteIndex); - } - catch (Exception e) { - int size = storage.getSize(); - int bits = Mth.ceillog2(palette.length); - SimpleBitStorage newStorage = new SimpleBitStorage(bits, size); - for (int i = 0; i < size; i++) { - newStorage.set(i, storage.get(i)); - } - storage = newStorage; - storage.set(index, paletteIndex); - be_setHydrogenStorage(self, storage); - } - } - catch (Exception e) { - BCLib.LOGGER.warning(e.getLocalizedMessage()); - } - return; - } - - biomes[index] = biome; - } - - @Shadow - @Final - private int quartMinY; - @Shadow - @Final - private int quartHeight; - - private boolean be_shouldWriteToHydrogen() { - try { - Field field = ChunkBiomeContainer.class.getDeclaredField("intArray"); - return field != null; - } - catch (NoSuchFieldException e) { - return false; - } - } - - private int be_getArrayIndex(int biomeX, int biomeY, int biomeZ) { - int i = biomeX & HORIZONTAL_MASK; - int j = Mth.clamp(biomeY - this.quartMinY, 0, this.quartHeight); - int k = biomeZ & HORIZONTAL_MASK; - return j << WIDTH_BITS + WIDTH_BITS | k << WIDTH_BITS | i; - } - - private Field be_getField(String name) throws Exception { - Field field = ChunkBiomeContainer.class.getDeclaredField(name); - field.setAccessible(true); - return field; - } - - private SimpleBitStorage be_getHydrogenStorage(ChunkBiomeContainer container) throws Exception { - return (SimpleBitStorage) be_getField("intArray").get(container); - } - - private Biome[] be_getHydrogenPalette(ChunkBiomeContainer container) throws Exception { - return (Biome[]) be_getField("palette").get(container); - } - - private int be_getHydrogenPaletteIndex(Biome biome, Biome[] palette) { - int index = -1; - for (int i = 0; i < palette.length; i++) { - if (palette[i] == biome) { - index = i; - break; - } - } - return index; - } - - private void be_setHydrogenPalette(ChunkBiomeContainer container, Biome[] palette) throws Exception { - be_getField("palette").set(container, palette); - } - - private void be_setHydrogenStorage(ChunkBiomeContainer container, SimpleBitStorage storage) throws Exception { - be_getField("intArray").set(container, storage); - } -} diff --git a/src/main/resources/bclib.mixins.common.json b/src/main/resources/bclib.mixins.common.json index 5e03cbe7..b2bdd97c 100644 --- a/src/main/resources/bclib.mixins.common.json +++ b/src/main/resources/bclib.mixins.common.json @@ -8,7 +8,6 @@ "AnvilMenuMixin", "ChunkGeneratorMixin", "BoneMealItemMixin", - "ChunkBiomeContainerMixin", "ComposterBlockAccessor", "PotionBrewingAccessor", "RecipeManagerAccessor", From 09c67e3e4a969360c089683d9457e7571defaab4 Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 1 Dec 2021 00:15:37 +0100 Subject: [PATCH 24/96] Removed StructureToFeatures --- .../java/ru/bclib/world/structures/BCLStructureFeature.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java b/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java index 4497bfc7..f171d945 100644 --- a/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java +++ b/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java @@ -1,7 +1,6 @@ package ru.bclib.world.structures; import net.fabricmc.fabric.api.structure.v1.FabricStructureBuilder; -import net.fabricmc.fabric.mixin.structure.FlatChunkGeneratorConfigAccessor; import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.levelgen.GenerationStep; @@ -25,7 +24,8 @@ public class BCLStructureFeature { .register(); this.featureConfigured = this.structure.configured(NoneFeatureConfiguration.NONE); BuiltinRegistries.register(BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE, id, this.featureConfigured); - FlatChunkGeneratorConfigAccessor.getStructureToFeatures().put(this.structure, this.featureConfigured); + //TODO: 1.18 check if structures are added correctly + //FlatChunkGeneratorConfigAccessor.getStructureToFeatures().put(this.structure, this.featureConfigured); } public StructureFeature getStructure() { From 4c1e8273f6c6323e4532d6e4a63d33143842193e Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 1 Dec 2021 01:12:20 +0100 Subject: [PATCH 25/96] Fixed some more compile issues --- src/main/java/ru/bclib/BCLib.java | 2 - src/main/java/ru/bclib/api/TagAPI.java | 1 + .../ru/bclib/api/datafixer/DataFixerAPI.java | 6 +- .../blockentities/BaseBarrelBlockEntity.java | 2 +- .../java/ru/bclib/blocks/BaseLeavesBlock.java | 8 +-- .../java/ru/bclib/blocks/BaseSignBlock.java | 2 +- .../blocks/FeatureSaplingBlockCommon.java | 1 + .../ru/bclib/integration/ModIntegration.java | 5 +- .../mixin/common/WorldGenRegionMixin.java | 2 +- .../java/ru/bclib/world/biomes/BCLBiome.java | 4 +- .../ru/bclib/world/biomes/BCLBiomeDef.java | 43 ++++-------- .../world/features/NBTStructureFeature.java | 1 - .../world/generator/BCLibEndBiomeSource.java | 4 +- .../generator/BCLibNetherBiomeSource.java | 3 +- .../ru/bclib/world/generator/BiomeMap.java | 3 +- .../world/surface/BCLSurfaceBuilders.java | 20 ------ .../surface/DoubleBlockSurfaceBuilder.java | 66 ------------------- 17 files changed, 39 insertions(+), 134 deletions(-) delete mode 100644 src/main/java/ru/bclib/world/surface/BCLSurfaceBuilders.java delete mode 100644 src/main/java/ru/bclib/world/surface/DoubleBlockSurfaceBuilder.java diff --git a/src/main/java/ru/bclib/BCLib.java b/src/main/java/ru/bclib/BCLib.java index 1e450f96..4478b912 100644 --- a/src/main/java/ru/bclib/BCLib.java +++ b/src/main/java/ru/bclib/BCLib.java @@ -20,7 +20,6 @@ import ru.bclib.util.Logger; import ru.bclib.world.generator.BCLibEndBiomeSource; import ru.bclib.world.generator.BCLibNetherBiomeSource; import ru.bclib.world.generator.GeneratorOptions; -import ru.bclib.world.surface.BCLSurfaceBuilders; import java.util.List; @@ -33,7 +32,6 @@ public class BCLib implements ModInitializer { BaseRegistry.register(); GeneratorOptions.init(); BaseBlockEntities.register(); - BCLSurfaceBuilders.register(); BCLibEndBiomeSource.register(); BCLibNetherBiomeSource.register(); TagAPI.init(); diff --git a/src/main/java/ru/bclib/api/TagAPI.java b/src/main/java/ru/bclib/api/TagAPI.java index f157dbfb..a9948037 100644 --- a/src/main/java/ru/bclib/api/TagAPI.java +++ b/src/main/java/ru/bclib/api/TagAPI.java @@ -3,6 +3,7 @@ package ru.bclib.api; import com.google.common.collect.Maps; import com.google.common.collect.Sets; import net.fabricmc.fabric.api.tag.TagFactory; +import net.fabricmc.fabric.api.tag.TagRegistry; import net.fabricmc.fabric.impl.tag.extension.TagDelegate; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; diff --git a/src/main/java/ru/bclib/api/datafixer/DataFixerAPI.java b/src/main/java/ru/bclib/api/datafixer/DataFixerAPI.java index 1a832f6f..c6f23694 100644 --- a/src/main/java/ru/bclib/api/datafixer/DataFixerAPI.java +++ b/src/main/java/ru/bclib/api/datafixer/DataFixerAPI.java @@ -35,6 +35,7 @@ import java.io.DataOutputStream; import java.io.EOFException; import java.io.File; import java.io.IOException; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; @@ -459,9 +460,10 @@ public class DataFixerAPI { private static void fixRegion(MigrationProfile data, State state, File file) { try { - LOGGER.info("Inspecting " + file); + Path path = file.toPath(); + LOGGER.info("Inspecting " + path); boolean[] changed = new boolean[1]; - RegionFile region = new RegionFile(file, file.getParentFile(), true); + RegionFile region = new RegionFile(path, path.getParent(), true); for (int x = 0; x < 32; x++) { for (int z = 0; z < 32; z++) { diff --git a/src/main/java/ru/bclib/blockentities/BaseBarrelBlockEntity.java b/src/main/java/ru/bclib/blockentities/BaseBarrelBlockEntity.java index 9965baf5..d4badf53 100644 --- a/src/main/java/ru/bclib/blockentities/BaseBarrelBlockEntity.java +++ b/src/main/java/ru/bclib/blockentities/BaseBarrelBlockEntity.java @@ -94,7 +94,7 @@ public class BaseBarrelBlockEntity extends RandomizableContainerBlockEntity { } private void scheduleUpdate() { - level.getBlockTicks().schedule(getBlockPos(), getBlockState().getBlock(), 5); + level.scheduleTick(getBlockPos(), getBlockState().getBlock(), 5); } public void tick() { diff --git a/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java b/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java index e0a72abf..3dd32197 100644 --- a/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java @@ -29,13 +29,13 @@ public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, private static FabricBlockSettings makeLeaves(MaterialColor color) { return FabricBlockSettings.copyOf(Blocks.OAK_LEAVES) - .color(color) + .mapColor(color) .breakByTool(FabricToolTags.HOES) .breakByTool(FabricToolTags.SHEARS) .breakByHand(true) - .isValidSpawn((state, world, pos, type) -> false) - .isSuffocating((state, world, pos) -> false) - .isViewBlocking((state, world, pos) -> false); + .allowsSpawning((state, world, pos, type) -> false) + .suffocates((state, world, pos) -> false) + .blockVision((state, world, pos) -> false); } public BaseLeavesBlock(Block sapling, MaterialColor color, Consumer customizeProperties) { diff --git a/src/main/java/ru/bclib/blocks/BaseSignBlock.java b/src/main/java/ru/bclib/blocks/BaseSignBlock.java index 2d5cdffe..f8f4f9d8 100644 --- a/src/main/java/ru/bclib/blocks/BaseSignBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseSignBlock.java @@ -105,7 +105,7 @@ public class BaseSignBlock extends SignBlock implements BlockModelProvider, Cust @Override public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { if (state.getValue(WATERLOGGED)) { - world.getFluidTicks().schedule(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world)); + world.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world)); } if (!canSurvive(state, world, pos)) { return state.getValue(WATERLOGGED) ? state.getFluidState() diff --git a/src/main/java/ru/bclib/blocks/FeatureSaplingBlockCommon.java b/src/main/java/ru/bclib/blocks/FeatureSaplingBlockCommon.java index fcc7f3af..83d86edf 100644 --- a/src/main/java/ru/bclib/blocks/FeatureSaplingBlockCommon.java +++ b/src/main/java/ru/bclib/blocks/FeatureSaplingBlockCommon.java @@ -87,6 +87,7 @@ abstract class FeatureSaplingBlockCommon extends SaplingBlock implements RenderL @Override public void advanceTree(ServerLevel world, BlockPos pos, BlockState blockState, Random random) { FeaturePlaceContext context = new FeaturePlaceContext( + Optional.empty(), world, world.getChunkSource().getGenerator(), random, diff --git a/src/main/java/ru/bclib/integration/ModIntegration.java b/src/main/java/ru/bclib/integration/ModIntegration.java index 8597971f..1c26e8c7 100644 --- a/src/main/java/ru/bclib/integration/ModIntegration.java +++ b/src/main/java/ru/bclib/integration/ModIntegration.java @@ -17,6 +17,7 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.GenerationStep; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.Feature; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; import ru.bclib.BCLib; import ru.bclib.world.features.BCLFeature; @@ -58,9 +59,9 @@ public abstract class ModIntegration { return FabricLoader.getInstance().isModLoaded(modID); } - public BCLFeature getFeature(String featureID, String configuredFeatureID, GenerationStep.Decoration featureStep) { + public BCLFeature getFeature(String featureID, String placedFeatureID, GenerationStep.Decoration featureStep) { Feature feature = Registry.FEATURE.get(getID(featureID)); - ConfiguredFeature featureConfigured = BuiltinRegistries.CONFIGURED_FEATURE.get(getID(configuredFeatureID)); + PlacedFeature featureConfigured = BuiltinRegistries.PLACED_FEATURE.get(getID(placedFeatureID)); return new BCLFeature(feature, featureConfigured, featureStep); } diff --git a/src/main/java/ru/bclib/mixin/common/WorldGenRegionMixin.java b/src/main/java/ru/bclib/mixin/common/WorldGenRegionMixin.java index 08cde84d..29a130c5 100644 --- a/src/main/java/ru/bclib/mixin/common/WorldGenRegionMixin.java +++ b/src/main/java/ru/bclib/mixin/common/WorldGenRegionMixin.java @@ -21,6 +21,6 @@ public class WorldGenRegionMixin { int x = blockPos.getX() >> 4; int z = blockPos.getZ() >> 4; WorldGenRegion region = (WorldGenRegion) (Object) this; - info.setReturnValue(Math.abs(x - center.x) < 2 && Math.abs(z - center.z) < 2); + info.setReturnValue(Math.abs(x - center.getPos().x) < 2 && Math.abs(z - center.getPos().z) < 2); } } diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiome.java b/src/main/java/ru/bclib/world/biomes/BCLBiome.java index ebdf2a73..bf86b175 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiome.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiome.java @@ -8,6 +8,7 @@ import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biomes; +import net.minecraft.world.level.levelgen.GenerationStep.Decoration; import ru.bclib.config.Configs; import ru.bclib.util.JsonFactory; import ru.bclib.util.StructureHelper; @@ -152,8 +153,9 @@ public class BCLBiome { list.add(new StructureInfo(structure, offsetY, terrainMerge)); }); if (!list.isEmpty()) { - structuresFeature = BCLFeature.makeChansedFeature( + structuresFeature = BCLFeature.makeChancedFeature( new ResourceLocation(ns, nm + "_structures"), + Decoration.SURFACE_STRUCTURES, new ListFeature(list), 10 ); diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java index f7f2a315..ac8731ae 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java @@ -21,22 +21,17 @@ import net.minecraft.world.level.biome.BiomeSpecialEffects.Builder; import net.minecraft.world.level.biome.MobSpawnSettings; import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.levelgen.GenerationStep.Carving; import net.minecraft.world.level.levelgen.GenerationStep.Decoration; import net.minecraft.world.level.levelgen.carver.CarverConfiguration; import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver; -import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; -import net.minecraft.world.level.levelgen.surfacebuilders.ConfiguredSurfaceBuilder; -import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilder; -import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderBaseConfiguration; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; import ru.bclib.config.IdConfig; import ru.bclib.config.PathConfig; import ru.bclib.util.ColorUtil; import ru.bclib.world.features.BCLFeature; import ru.bclib.world.structures.BCLStructureFeature; -import ru.bclib.world.surface.DoubleBlockSurfaceBuilder; import java.util.List; import java.util.Map; @@ -77,8 +72,6 @@ public class BCLBiomeDef { private float downfall = 0F; private int edgeSize = 32; - private ConfiguredSurfaceBuilder surface; - /** * Custom biome definition. Can be extended with new parameters. * @@ -153,24 +146,12 @@ public class BCLBiomeDef { } public BCLBiomeDef setSurface(Block block) { - setSurface(SurfaceBuilder.DEFAULT.configured(new SurfaceBuilderBaseConfiguration( - block.defaultBlockState(), - Blocks.END_STONE.defaultBlockState(), - Blocks.END_STONE.defaultBlockState() - ))); + return this; } public BCLBiomeDef setSurface(Block block1, Block block2) { - setSurface(DoubleBlockSurfaceBuilder.register("bclib_" + id.getPath() + "_surface") - .setBlock1(block1) - .setBlock2(block2) - .configured()); - return this; - } - - public BCLBiomeDef setSurface(ConfiguredSurfaceBuilder builder) { - this.surface = builder; + return this; } @@ -240,7 +221,7 @@ public class BCLBiomeDef { return this; } - public BCLBiomeDef addFeature(Decoration featureStep, ConfiguredFeature feature) { + public BCLBiomeDef addFeature(Decoration featureStep, PlacedFeature feature) { FeatureInfo info = new FeatureInfo(); info.featureStep = featureStep; info.feature = feature; @@ -346,8 +327,10 @@ public class BCLBiomeDef { spawnSettings.addSpawn(entry.type.getCategory(), entry); }); - generationSettings.surfaceBuilder(surface == null ? net.minecraft.data.worldgen.SurfaceBuilders.END : surface); - structures.forEach((structure) -> generationSettings.addStructureStart(structure)); + //generationSettings.surfaceBuilder(surface == null ? net.minecraft.data.worldgen.SurfaceBuilders.END : surface); + + //TODO: 1.18 Done elsewhere now + //structures.forEach((structure) -> generationSettings.addStructureStart(structure)); features.forEach((info) -> generationSettings.addFeature(info.featureStep, info.feature)); carvers.forEach((info) -> generationSettings.addCarver(info.carverStep, info.carver)); @@ -368,12 +351,12 @@ public class BCLBiomeDef { return new Biome.BiomeBuilder() .precipitation(precipitation) .biomeCategory(category) - .depth(depth) - .scale(0.2F) + //.depth(depth) + //.scale(0.2F) .temperature(temperature) .downfall(downfall) - .effects(effects.build()) - .spawnSettings(spawnSettings.build()) + .specialEffects(effects.build()) + .mobSpawnSettings(spawnSettings.build()) .generationSettings(generationSettings.build()) .build(); } @@ -387,7 +370,7 @@ public class BCLBiomeDef { private static final class FeatureInfo { Decoration featureStep; - ConfiguredFeature feature; + PlacedFeature feature; } private static final class CarverInfo { diff --git a/src/main/java/ru/bclib/world/features/NBTStructureFeature.java b/src/main/java/ru/bclib/world/features/NBTStructureFeature.java index 37aa0050..acaed3ec 100644 --- a/src/main/java/ru/bclib/world/features/NBTStructureFeature.java +++ b/src/main/java/ru/bclib/world/features/NBTStructureFeature.java @@ -18,7 +18,6 @@ import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConf import net.minecraft.world.level.levelgen.structure.BoundingBox; import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings; import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; -import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderConfiguration; import ru.bclib.api.BiomeAPI; import ru.bclib.api.TagAPI; import ru.bclib.util.BlocksHelper; diff --git a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java index 97bd8e81..5a8ea37e 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java @@ -9,7 +9,9 @@ import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome.BiomeCategory; import net.minecraft.world.level.biome.BiomeSource; import net.minecraft.world.level.biome.Biomes; +import net.minecraft.world.level.biome.Climate; import net.minecraft.world.level.biome.TheEndBiomeSource; +import net.minecraft.world.level.levelgen.LegacyRandomSource; import net.minecraft.world.level.levelgen.WorldgenRandom; import net.minecraft.world.level.levelgen.synth.SimplexNoise; import ru.bclib.BCLib; @@ -113,7 +115,7 @@ public class BCLibEndBiomeSource extends BiomeSource { } @Override - public Biome getBiomeForNoiseGen(int biomeX, int biomeY, int biomeZ) { + public Biome getNoiseBiome(int biomeX, int biomeY, int biomeZ, Climate.Sampler sampler) { long i = (long) biomeX * (long) biomeX; long j = (long) biomeZ * (long) biomeZ; long check = GeneratorOptions.isFarEndBiomes() ? 65536L : 625L; diff --git a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java index 754b8d7d..a11aa935 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java @@ -8,6 +8,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome.BiomeCategory; import net.minecraft.world.level.biome.BiomeSource; +import net.minecraft.world.level.biome.Climate; import ru.bclib.BCLib; import ru.bclib.api.BiomeAPI; import ru.bclib.config.ConfigKeeper.StringArrayEntry; @@ -91,7 +92,7 @@ public class BCLibNetherBiomeSource extends BiomeSource { } @Override - public Biome getBiomeForNoiseGen(int biomeX, int biomeY, int biomeZ) { + public Biome getNoiseBiome(int biomeX, int biomeY, int biomeZ, Climate.Sampler var4) { if ((biomeX & 63) == 0 && (biomeZ & 63) == 0) { biomeMap.clearCache(); } diff --git a/src/main/java/ru/bclib/world/generator/BiomeMap.java b/src/main/java/ru/bclib/world/generator/BiomeMap.java index a244029c..078bac1f 100644 --- a/src/main/java/ru/bclib/world/generator/BiomeMap.java +++ b/src/main/java/ru/bclib/world/generator/BiomeMap.java @@ -2,6 +2,7 @@ package ru.bclib.world.generator; import com.google.common.collect.Maps; import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.levelgen.LegacyRandomSource; import net.minecraft.world.level.levelgen.WorldgenRandom; import ru.bclib.noise.OpenSimplexNoise; import ru.bclib.util.MHelper; @@ -75,7 +76,7 @@ public class BiomeMap { ChunkPos cpos = new ChunkPos(MHelper.floor(x / BiomeChunk.WIDTH), MHelper.floor(z / BiomeChunk.WIDTH)); BiomeChunk chunk = maps.get(cpos); if (chunk == null) { - RANDOM.setBaseChunkSeed(cpos.x, cpos.z); + RANDOM.setLargeFeatureWithSalt(0, cpos.x, cpos.z, 0); chunk = new BiomeChunk(this, RANDOM, picker); maps.put(cpos, chunk); } diff --git a/src/main/java/ru/bclib/world/surface/BCLSurfaceBuilders.java b/src/main/java/ru/bclib/world/surface/BCLSurfaceBuilders.java deleted file mode 100644 index 641eeace..00000000 --- a/src/main/java/ru/bclib/world/surface/BCLSurfaceBuilders.java +++ /dev/null @@ -1,20 +0,0 @@ -package ru.bclib.world.surface; - -import net.minecraft.core.Registry; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilder; -import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderBaseConfiguration; - -public class BCLSurfaceBuilders { - public static SurfaceBuilder register(String name, SurfaceBuilder builder) { - return Registry.register(Registry.SURFACE_BUILDER, name, builder); - } - - public static SurfaceBuilderBaseConfiguration makeSimpleConfig(Block block) { - BlockState state = block.defaultBlockState(); - return new SurfaceBuilderBaseConfiguration(state, state, state); - } - - public static void register() {} -} diff --git a/src/main/java/ru/bclib/world/surface/DoubleBlockSurfaceBuilder.java b/src/main/java/ru/bclib/world/surface/DoubleBlockSurfaceBuilder.java deleted file mode 100644 index 434b1a39..00000000 --- a/src/main/java/ru/bclib/world/surface/DoubleBlockSurfaceBuilder.java +++ /dev/null @@ -1,66 +0,0 @@ -package ru.bclib.world.surface; - -import net.minecraft.core.Registry; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.chunk.ChunkAccess; -import net.minecraft.world.level.levelgen.surfacebuilders.ConfiguredSurfaceBuilder; -import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilder; -import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderBaseConfiguration; -import ru.bclib.noise.OpenSimplexNoise; -import ru.bclib.util.MHelper; - -import java.util.Random; - -public class DoubleBlockSurfaceBuilder extends SurfaceBuilder { - private static final OpenSimplexNoise NOISE = new OpenSimplexNoise(4141); - private SurfaceBuilderBaseConfiguration config1; - private SurfaceBuilderBaseConfiguration config2; - - private DoubleBlockSurfaceBuilder() { - super(SurfaceBuilderBaseConfiguration.CODEC); - } - - public DoubleBlockSurfaceBuilder setBlock1(Block block) { - BlockState stone = Blocks.END_STONE.defaultBlockState(); - config1 = new SurfaceBuilderBaseConfiguration(block.defaultBlockState(), stone, stone); - return this; - } - - public DoubleBlockSurfaceBuilder setBlock2(Block block) { - BlockState stone = Blocks.END_STONE.defaultBlockState(); - config2 = new SurfaceBuilderBaseConfiguration(block.defaultBlockState(), stone, stone); - return this; - } - - public static DoubleBlockSurfaceBuilder register(String name) { - return Registry.register(Registry.SURFACE_BUILDER, name, new DoubleBlockSurfaceBuilder()); - } - - public ConfiguredSurfaceBuilder configured() { - BlockState stone = Blocks.END_STONE.defaultBlockState(); - return this.configured(new SurfaceBuilderBaseConfiguration(config1.getTopMaterial(), stone, stone)); - } - - @Override - public void apply(Random random, ChunkAccess chunkAccess, Biome biome, int x, int z, int height, double noise, BlockState defaultBlock, BlockState defaultFluid, int l, int m, long seed, SurfaceBuilderBaseConfiguration surfaceBuilderConfiguration) { - noise = NOISE.eval(x * 0.1, z * 0.1) + MHelper.randRange(-0.4, 0.4, random); - SurfaceBuilder.DEFAULT.apply( - random, - chunkAccess, - biome, - x, - z, - height, - noise, - defaultBlock, - defaultFluid, - l, - m, - seed, - noise > 0 ? config1 : config2 - ); - } -} \ No newline at end of file From 54f13847b550e2138e7f2003982b48c8cc84214a Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 1 Dec 2021 01:33:24 +0100 Subject: [PATCH 26/96] First running version of BCLib --- bclib.gradle | 2 +- .../java/ru/bclib/util/StructureHelper.java | 4 +++- .../world/features/NBTStructureFeature.java | 23 ++++++++++++------- .../world/generator/BCLibEndBiomeSource.java | 2 +- .../generator/BCLibNetherBiomeSource.java | 2 +- .../processors/TerrainStructureProcessor.java | 10 ++++---- src/main/resources/bclib.mixins.client.json | 1 - 7 files changed, 27 insertions(+), 17 deletions(-) diff --git a/bclib.gradle b/bclib.gradle index 1d44570a..540c5ae0 100644 --- a/bclib.gradle +++ b/bclib.gradle @@ -89,7 +89,7 @@ processResources { // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html tasks.withType(JavaCompile) { options.encoding = "UTF-8" - it.options.release = 16 + it.options.release = 17 } javadoc { diff --git a/src/main/java/ru/bclib/util/StructureHelper.java b/src/main/java/ru/bclib/util/StructureHelper.java index 28494f48..0b0f3df2 100644 --- a/src/main/java/ru/bclib/util/StructureHelper.java +++ b/src/main/java/ru/bclib/util/StructureHelper.java @@ -378,7 +378,9 @@ public class StructureHelper { mut.setX(x); for (int z = bounds.minZ(); z <= bounds.maxZ(); z++) { mut.setZ(z); - BlockState top = world.getBiome(mut).getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial(); + BlockState top = Blocks.PURPLE_CONCRETE.defaultBlockState(); + //TODO: 1.18 find another way to get the Top Materiel + //world.getBiome(mut).getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial(); for (int y = bounds.maxY(); y >= bounds.minY(); y--) { mut.setY(y); BlockState state = world.getBlockState(mut); diff --git a/src/main/java/ru/bclib/world/features/NBTStructureFeature.java b/src/main/java/ru/bclib/world/features/NBTStructureFeature.java index acaed3ec..63a37fdd 100644 --- a/src/main/java/ru/bclib/world/features/NBTStructureFeature.java +++ b/src/main/java/ru/bclib/world/features/NBTStructureFeature.java @@ -10,6 +10,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Mirror; import net.minecraft.world.level.block.Rotation; import net.minecraft.world.level.block.state.BlockState; @@ -141,11 +142,14 @@ public abstract class NBTStructureFeature extends DefaultFeature { BlockState stateSt = world.getBlockState(mut); if (!stateSt.is(TagAPI.BLOCK_GEN_TERRAIN)) { if (merge == TerrainMerge.SURFACE) { - SurfaceBuilderConfiguration config = world.getBiome(mut) - .getGenerationSettings() - .getSurfaceBuilderConfig(); +// SurfaceBuilderConfiguration config = world.getBiome(mut) +// .getGenerationSettings() +// .getSurfaceBuilderConfig(); boolean isTop = mut.getY() == surfMax && state.getMaterial().isSolidBlocking(); - BlockState top = isTop ? config.getTopMaterial() : config.getUnderMaterial(); + BlockState top = + Blocks.PURPLE_CONCRETE.defaultBlockState(); + //TODO: 1.18 find another way to get the Top/Bottom Materiel + //isTop ? config.getTopMaterial() : config.getUnderMaterial(); BlocksHelper.setWithoutUpdate(world, mut, top); } else { @@ -155,10 +159,13 @@ public abstract class NBTStructureFeature extends DefaultFeature { else { if (stateSt.is(TagAPI.BLOCK_END_GROUND) && state.getMaterial().isSolidBlocking()) { if (merge == TerrainMerge.SURFACE) { - SurfaceBuilderConfiguration config = world.getBiome(mut) - .getGenerationSettings() - .getSurfaceBuilderConfig(); - BlocksHelper.setWithoutUpdate(world, mut, config.getUnderMaterial()); +// SurfaceBuilderConfiguration config = world.getBiome(mut) +// .getGenerationSettings() +// .getSurfaceBuilderConfig(); + BlockState bottom = Blocks.PURPLE_CONCRETE.defaultBlockState(); + //TODO: 1.18 find another way to get the Top Material + //config.getUnderMaterial() + BlocksHelper.setWithoutUpdate(world, mut, bottom); } else { BlocksHelper.setWithoutUpdate(world, mut, state); diff --git a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java index 5a8ea37e..5a2d283d 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java @@ -50,7 +50,7 @@ public class BCLibEndBiomeSource extends BiomeSource { BiomeAPI.END_LAND_BIOME_PICKER.clearMutables(); BiomeAPI.END_VOID_BIOME_PICKER.clearMutables(); - this.possibleBiomes.forEach(biome -> { + this.possibleBiomes().forEach(biome -> { ResourceLocation key = biomeRegistry.getKey(biome); if (!BiomeAPI.hasBiome(key)) { BCLBiome bclBiome = new BCLBiome(key, biome, 1, 1); diff --git a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java index a11aa935..ad4c7b96 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java @@ -39,7 +39,7 @@ public class BCLibNetherBiomeSource extends BiomeSource { BiomeAPI.NETHER_BIOME_PICKER.clearMutables(); - this.possibleBiomes.forEach(biome -> { + this.possibleBiomes().forEach(biome -> { ResourceLocation key = biomeRegistry.getKey(biome); if (!BiomeAPI.hasBiome(key)) { BCLBiome bclBiome = new BCLBiome(key, biome, 1, 1); diff --git a/src/main/java/ru/bclib/world/processors/TerrainStructureProcessor.java b/src/main/java/ru/bclib/world/processors/TerrainStructureProcessor.java index 1f758427..bcb70630 100644 --- a/src/main/java/ru/bclib/world/processors/TerrainStructureProcessor.java +++ b/src/main/java/ru/bclib/world/processors/TerrainStructureProcessor.java @@ -14,10 +14,12 @@ public class TerrainStructureProcessor extends StructureProcessor { public StructureBlockInfo processBlock(LevelReader worldView, BlockPos pos, BlockPos blockPos, StructureBlockInfo structureBlockInfo, StructureBlockInfo structureBlockInfo2, StructurePlaceSettings structurePlacementData) { BlockPos bpos = structureBlockInfo2.pos; if (structureBlockInfo2.state.is(Blocks.END_STONE) && worldView.isEmptyBlock(bpos.above())) { - BlockState top = worldView.getBiome(structureBlockInfo2.pos) - .getGenerationSettings() - .getSurfaceBuilderConfig() - .getTopMaterial(); + BlockState top = Blocks.PURPLE_CONCRETE.defaultBlockState(); + //TODO: 1.18 find another way to get the Top Materiel +// worldView.getBiome(structureBlockInfo2.pos) +// .getGenerationSettings() +// .getSurfaceBuilderConfig() +// .getTopMaterial(); return new StructureBlockInfo(bpos, top, structureBlockInfo2.nbt); } return structureBlockInfo2; diff --git a/src/main/resources/bclib.mixins.client.json b/src/main/resources/bclib.mixins.client.json index 4578ab58..7c845a35 100644 --- a/src/main/resources/bclib.mixins.client.json +++ b/src/main/resources/bclib.mixins.client.json @@ -11,7 +11,6 @@ "GameMixin", "MinecraftMixin", "GameMixin", - "StructureFeaturesMixin" "ModelBakeryMixin", "ModelManagerMixin", "SimpleReloadableResourceManagerMixin", From 22bf4384c67d6d803acb12cdac022946ed7a6749 Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 1 Dec 2021 01:33:33 +0100 Subject: [PATCH 27/96] Updated gradle for Java 17 --- gradle/wrapper/gradle-wrapper.jar | Bin 58694 -> 59536 bytes gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 269 ++++++++++++++--------- gradlew.bat | 22 +- 4 files changed, 165 insertions(+), 128 deletions(-) mode change 100644 => 100755 gradlew diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 490fda8577df6c95960ba7077c43220e5bb2c0d9..7454180f2ae8848c63b8b4dea2cb829da983f2fa 100644 GIT binary patch delta 18415 zcmY(KV|$=Y8>BO_ZQHhO+qP}pv2EM7C$=$3CX-BTYhvv49{XkYH+1(^U3JzqJ`I+% z1lAM?gXq(yH^>eS0`eOQ1VjWR)n%0+_2(~2pj=}|4Nn98%aJoT+yYHini^eKcoP?t zLW2(0#!inI7gv@7UA%Ulq8nk8vA1hO_&Y-IwR5#c2mRtW#@5$v~DggL|9;ADj6bE%;FTogDj+0L1n96e)j+fr|b}2$>|X{%rCWEZHMxlo79tyoT*&}@6DOR%5kU6QCDL> z#%AlvREAaj^AxLLbwgS&wOxpR?>BT^0v3mB7t%^R-CsUX-rK=_%U^2Uk<( zXoniJ(qY}#l( z%EHmZr1~Hv#)M2i+!HdMr_PFSf1#%Z2fw{rr z{@FfRQOrXA9x=}R+UuNl$@11Ie1RJu{m84`10WPX4&t`8bwu2PVXP{2AnMjWTHmKWtDf=mE37xsDHeeR|FjP zJWkDTw#Cvg#Tb$sjb~+^JELZb3-geckb}+3X*4H{lRm>4-;H1{xKy9{NIrvqd_aV|W-E4R#T$~7rtu^@C3BLVdt2@Qk#n(#dZ(#daZ;=JDw7YmGCEfD`mHZvbLEeb z2vqNk$e3a(o)_*_9p?SwGDf|6iH@{}HDS#Eb%uUZ>LdOQx%7${K+rsag#Lnz(ss^j zC=9j%Ad^X9l^$D=z&Arj=wRzqnC0QfPUDbbk=^5<){x2Fw6A#UU{H24Fjb1PaHN*7 zQ`G$Uvq%A^iFT%5f>+XDm!m#)D&AN3Z~LtOfMU`AA{7DukMIoEW_jYI{p?odFROEF zn7)d|sO}hl0;U=+CIdn0B+&;WWjQc#SP&3sXpsMnl!B1@&0;VRkU*$ZVnjYbt#~=<&#kiFz26Pg@o2YsN7`RL5ku-y z=DyJ+`p$AG#g*1Pu02mjIggm5ISO>qC3diWGTs@>c(EoJpjUIg*FWcg=$rvYf*scI z8(;X3ngi)Z<5*h_RLY&R(?dfjbT2^Xt<}7L&$qlnV8#Pmv0{0wci%4At*mg9NSx3V zfh^Q?Vl9F~R{hgiqX~E^ zFyD4RAC5TIJZ_LVOz+L3^=z zvN`O6*U_2&fKtrJ?>N&o!ytul0#@^^>C*8WzmRT355LnTl4RR)(wTd6oQ}E>tY(O$ zsiK5~N0D?Y=@a-IbasCZ>xd6dkY^23jd|ntSjqdSp{zA;YtjK!$~w-fk1K3>$TvdD z_Q{PPC!DQ49goLZN2)XbZK6}C{N&auD?hHX4p;8eu{zbnvgnNV^SZ5f2j;lplq59A^ukHFRPEG@>up~+FUD;Cp_&si0?wP1fezK6A{N;8=xZSM*C*6Q##IHJgqSf8t^ zPz@;l!C7X{iJx6WT4dFO4v@=<_<`FC4aPr?$9^x&=?v<$gs++Z_x6^_#w5osn|F9; zZ;`7>`n*Pr$+AE42_!i(iqUBZyQY+H$fkp_*O zAR=w%=U1Je(>wjCG}P}aBrOf$7t>EYc!R!=_7=on?zG63H%6pAR@fCfV7%|7eyfxu z9|3A8!L&_Ti(KrqN05TO5l1GGLRz*a&7truRU{BuU266IOyrF}x~Ci(EW-*-)6XiV zXZ-%a)fF#h&8@M_tPu*a4BaAv;Tmi~=p^ccq;fPqsaWcK#za_r`^Fs5{0;H{zu`n@ zrCAzO5RfWL5D=38eG zjp#Qz2scz$txwryRjuFP93F}3S{@m|zbV#uhrcw7VXsk=eNv2A(AZ?O2SKPi3@70J zgXw-z&p#o{kUj@+(?Ik-MG#cldl-8LU7|;sQ(dBeSj_F)8d>cVW#@ohuhBm#Ue&)L zy=x39`cKY$Pd)mTkJ1SZ$FQO$Y9TDzhq37T#>KRjp=cY&GMP~3%4xZx8^xq;HD6eZ z&yGrLQ06d7x>eaP#8+r@IK$WJwi@msksS6ci{CY9y}SYHVUcvMnm(B$MUg91%d4kF zkFC;sOQg@V&Z@0iXX&Ij^=mDkT2U&D?c=>#AK{}b(Q(A^MiuYM>GhgExuXm9HH~cs zcYO5TNDWSPLRBB_Bb0P9+8Y(0Mr~{jZ}mOwRLr=sICDL9rSdrRmF|mp5&;5^^@-<+ z5*L9!9vpy35w}|1irfO%*!(`&eRsE~jmLC!cCyHET!jASX8YIQ)_TA7wWn?6rb;~f ze80y4Uo-VY1g?l#b8^nDS@ku{#BzB7OUKnx8*5Cf`;I54-;3M5bm&{#^P?hADjY0x zf3`N=G@SgX+iL5C78~j-dwYM@Bk^6H!+8Sj&yUYn=dhlhkYZO^Iz+?!M;P*7 z+fN=Bv8>G9rFVNKE(ziJcZbdg&ZSuvtV zbTOiBo~oEAPex{;rZB2QPZLcc<1EFoe{QvC{D~9C>wN^zk`+td%W|wpRo>kn-k7Pt z^W+7}Ay~IEB}`FT!>ikUBT5V6+c5O9^BnG)NYvv;6gNq`(U* zkt+FXxSTQL_CdVBC4`s}$eSmw>B|T9tN8++H!P5I$7kq!X)Q_BNY`V$GzxoR!|QbL z*dF_Uk9CP5@CfE*@ML7IT z3b7X&gKupf;If{HAI0MmFNsL2I^AnpB$BC1!kA*TFPoK~%@C+{W+46(XuK#LB|{H1 zOkU%}WlOSFNHr7Zv!+}`An*a8^}Q=%Vx%zXm)2wB&5zcNBx#R1E^3LMxXmVRf&^a*_>H3uRK4FO_ zS){Tsm0V_Hs>g*YgOGW#+5Uk+@K%Or(Rw#(C`mw8lA1`UOek@s1O-_!b3uBCt%o#| zpz}F&7O<|>IVK`ZoA=c9NH;KOa?wQ~tmvj)vd$)R>-P~SGTFdOH0zaeKm`JGNwYeJ zW4M%XwJrJS#+D+zT~r$lRHZ0G99)TXJEAEr4uqw8C9wHEK6Hl$C2ER;7L$|d(q*A% zRgSoyJaTzPTYBLW85yxtv~`rk?f`%E$_wo1l(TV;nt^(V)M5v2b5mEDcYUzIG#yo? zE4vrJ1;*#HH*H}TBM&#JBPb9W3Y|$o$JCcpU2N?;v)XayQF92Q=_7jQ?z)J4m!O+; z7nJd0M17OtEk z_NbLsp4u2&jIyI4z$E|YZ`i;1iA3g6e*GfH@yxSXInz>TUbuqYDZb11&m1?}?d9l) zlB$F!SUHV+Oc;N@$4Xvn?Jn1_lqSn73{Kj=XLI^WOZui*+N!+!{0Nd9Py&jUm`(*= z6sh%@?kes=KP>b~tbj#>gUA;;Tp{|L#`|^lFJ3_GKT;?O*e88TP!p!pkSuKA1= zNGzz9j2G1KAP~UX!pGo^3z}OBiQ2235i=MQ?CvA7__rkV+|%A7;FUbPTe3vVW(KK_0L)O9W-y$OWtXkk^cFUE~We&9ea(P1n7EDc889-vk$ByT`Oc)(TxbRTpaxrsk zb$mwEgn?#eSk-j_L*@FH|Ef%9x~^^vjN)exIVGzTV{(C2yOW|!aPEOvLnRx7;dOcr zT?^8&<6SPc-79F2xU?E*g7@z%zc`?rwkWb+w$?^iCSKYqJ0eI?(a7?z8e`BP`9hc* zti^}R0c!DbYQg8_)t0Y-grU{}(LJBEmISMebHMeo&%C^hD@B6^HG>6&4N+wwKGYuQ zMZRF=Z#*)*eox+6SB375A@?yS{#PFQjERCmG+wx(6|R)Hn@&SDx7ckw*k&rCNN(a` zVxzOy)mMp*U5v_UE|bZ@v7(kBxUyqVH5ozjx^S&l;No7wwScN~T{e%Gz zB~jRQk&_UWPX~FHYePu+&(_jABAZodqq?tZNhrV|3(k}rUiPq@MS=0 z0Y)}PmaKy*K^kzuih zS?Z{vb$B!)-l**h2(b2dN@Ad6%R*8!0n9L;=1fFIm3Ka24Aqu&?y$EM#rAmNoFqZN zX*1IUNs`TWq3ABj!+mxU8@BJrad>#-crrzl-^JvSRf}F}*ESQq& z4-Pgnl1!TNcGzJmPvXKf1$-O{n)NJE!8aBJS*Oy0Z^;wj>Bt7O$ml*gO`62;(nCgsi4 z8_aC~)a-AO%)wVtKb6UP^(yc^a%>zYZExhy^x3|sXi6Y{7e_f(JX9sXoAw0rA6Dv}BENN_s=x%~VJz`=g%Z ziY|${cd=t*-@(n=-9CBxU}lHcbyG>MDe4ssJ*n!`$o-H6NGo!OR}J+-GPnnO zx)JmA6>Q$)1Qc_)LB1)|1Z`KRquGDVlFrg{G?QQ6S9Mj-P<3T9mnm&a9Bngnp_<-R zbtR388%v-VPVF8&{58&jA}8qweo~6G-}*b?nH*k7$An}0csziDV0Z%U<8SbK;!4p( zJ+kmVb<*Bs7<$?~XKl2XZ@F0=L2pstU6~nX?szys;+k5V(wLk-2kJU%K%PHG;E79) z!GRY6RRc~X4_Ld08T&K0MzBMHbD|jGo4+)LZ7@tjk!laBqplR-R)s-rQ+m`^U|Vf~ zTQv5E?4+Y7Z}Xg7QP%t>%02fK28!20sc3>?u5{zWYlxchoqlI{LG7_Eo)XLsd?6;s zDmvgnDP;h>p*F1)!qq)zdctN;7@=S&R&kLh6)Ky8>$*syExD#zjn=`TYgqG5I=ZtjOhV#k5!;K#Dg7cPuuz$1Ms_moi zINk>JDeuWPL8z_r(d>ZX<(69e1fHK+{E)kK;660S&44pFE;nJV)47vh{GU?f=nlBW z)$BE4D8%f*WYXe**1P&hM4Vqah3;e*k5g({a0oPVR+|Fud$>wxx=v?*SO;brEv=6R zbCy#gZBAfx(~D!TD_dN21$KMAKgxPrcXKPXl&r?^6C06h?SX4yS)@Z zSqGQl*v;&Q)#xtP^iiFuay@AgxXH2oa(CYsk=J<3VRO&k@yJmhpcBhnFRUndgKx(# zPoR{r=T-!?NbT2Ob=iJV&UbFFCm2R>zNEACoU5z(xRAsk?=uPggQpja-L7~JR`c&h zeF`YFnrVaxfHx+bmyM!K z$_{Rn-InQCLfvACU!^!`B{Ql6E68!?*GBZdBYgve94wq#zQG`WxtT9LpAmnO{RL5Q zJd|)pE0p4TVC5a2X7DVFfPgo5cE=)YpQ00*5#J@Oab_YjI{#3PpO_6j=Z-^i&6%eh=>K{SnMn7^-8v zr>g)k6hZG!g3c7)uN5wXj`N!23!a-suTiTKD_%$UH7Mpn_f;$IGzW!6<3m|O1NoNM zr|)L0$_cucRS`@}gUM?)PPwGfJdJ4*by6aR(LgtA`VNMe14n!{@jH|#q7C%2vC7Id zwo0x&pQttip&*~M=G?bJ3lvv48&-P8{)Z1-;8!w$^>6=Sfz3}TCJ@Hi)=zS9ggQbj zTjVPbm3R^&stn8yB!9g)d)`H+yXlJdfT)!lz2U!_eL&A6RyCJHcsjjk5DINMyJ!qo z#QF0EV#7+@K|*})uVqzg1;V1HCM3C8|67DNYc?nrf>;@Qi+Y~$ayMM_0VEMb*oy}^ zKQ;g7Fh$Xjp}%iiECenr+w_L|MwUGuzRkSWI0?5fKege;k+oe;r1x}4&54n|2R++C zCbsUr`s!(Us=LED0q1TI@p#R<`G?6pfK}`Z*Pjt@Ym6f*UEB2K zpOz1)9wL`q&^d_s6FL_Ke4c^(yk7dxu;Kb3=)=(6#3NPGV$k5b+GAePtQ6{to3}GK zXNPrX$@T}tCx!1%X?7sIU~n=yuRc+_cRwOp?vK)GV{vJdGef$(v0r2u3+O3ONecNS z4VTnuBl}Aa znisOq0HBW~xj=m6S6zi0T#1#gt_+IHd}vz9;8V&SAxCW{^yI+r;-&wgMCw z){Y=j2a2BUXVp#7eysME*GvI*HTkYtwER)od{Ountzzm@EZdoQy@%d_&HFZ-A^2RLta^=UO51+wVr4S7Dm~%C%YB~1cV_KpcMp4TuY)!3nloXN#$9zhmlEO z$o+|hQN?#bV%t&>uN}v>2`Lo!-78ZhV+bm-s9azb^HQ5YM-{z%Z&uHKrtWjUT0Oh> zv=9fp3bJ=T9M92x`#o&KCkoyzT7cM%kwPq}H$yC_7VmGkdMDr))b9Gw%93}3FK9Vu zhG4zii3$OR|O5}RIv%~;(Qn}T{@bJ!!(d{!B;!~$j2fZHS!`M2R=v5E9b;P(C z`nFQmGzkM?S_0d&Sf{rx#3Z>x>ja2i(tV#<=vQ+Go5~?yc?2^%P?xn==Id3G= zxsFJEdTS4n-9MPQ-W|{i1}kOkslBv?EJ)8wl}o1x#V$3?spZLcijI6BQtRx7q%UR~MWOetd>E5mW7+b4{YJz)lyD1Qe2FskJd zcEH$^-uj&%N5ED`_^JIXNiyft*L}cI;*ekAabqMoY_O%t27v=n=S}#RHNV3d8Ck?? z*GM*@vsLe-be`g?=?6v@8n60kOQ}I;1a%|u$4p09L2kQR5A=vpYSeyU%9r^@{i-u#Np&w^Bmp2YQ2?oYDy0lC53+4OmNGl3-# z7nmVFS4?7a3ED^nBqoMAy%3y;zCS}Lz(V@}DjAMy8hZ)2)m2sOhriDzN_=3920 z*&&Rj#g=0$M-3IK!}zWz8xE0mCp{DpmHoG48!*ij+$SFhX@sjoP$1X_RqIr=Tlr^N z?U^f6yW{-euQ(*4$AG~~#4p~KU3s9QMzq+3^cS}PR8I^vBcjw;61TI^Auva8El;>VA z7TQe&)%7G?qVPI7pX#9+`;q~M3OPO?fYnu(X3 zy%nlTSA=q&_l%B_xMt!h*DRIYAlt0~j)S|O7dzM-w z4W-1jDt;-9jiBSKp#cnQ%B+^7SJm<}lj-qp%&ci`S$T4Bw)(|vEgx8X^*%k@-cR#& z4vH?u#e}Svm!2$6B?jo8Y7~DjAvzRFX{}^TAZ!{Ia^Yt0Rmqr$WqKtvI|^y!H<=D9rZbp}F3 zE-+a(w~AfymJ`DQjF!u_qX3oGxa2BECnU{~k6h7}nD)%sqm@lrby~`5#Ul@c$`#I7 z&RVJ5GeP)sN+3>&xlD6Za5HORgR)E zmtBL9G$dw7*8Je#{opT>L;=I(+^c3S-TkLVZZ@S38{njADXoNLqE+p5Ib}c6-!j{7Dg3O7ri#ggp z$2AgzZOxG#XYQ4$R*`1FnZR$ERWLDx<>1iI26hflVt`d_%*nIiisf`O?O$bURR{-F zSG6<*k-OMkB*^$<@ds5GWDnGsiKbKB8LDe7=ow1B{b)ZDW?6o$TnxSi( z2y2&uIlvz&O`8*L@)4Mw+2)PWuEo)=hb{BWvgXa`2qkMnx1(Z_5%)Z){4-w-dF93B z02dUg7miR|!m_dv>XL%@;sfmNr+xA_7U5rsu8zh@C@fuW&?CxKwdr0{Bk)H&f86n@ zsIT}PVoArNMhOH!DF8{GMG(PkQtl{fq_9|5B=CC@cL_6f;?*j_f#l-0B|hu_dS%bXt^o=q&h z@pIoaO%xWis7;vub2vaTPNmV%A3g4awhM8 zvyQassrXb+lPnX9)rPgxFx*3JIiOeyMGC@N*QUg^Y*1e6RF1^B>MhlD6<)bLRed2e z;`ci~PQ_bC(<{ed_(%479)SNL!&HQI+*S{EXBgN}E9-QBP!JFt$kb*_oYVzjs8l3D zV!$454GA4RMx6#?H)lQT_tL`)A0u8qThUFM%#^Ez|8g`9)Jngjg%Oe`_$F(^- zyA8c=)R$)IYhj%St~*$QBc9hKzSY{#HJZl5Z@YIZYI`~)6q^dAynhsbib_z%C@SM;19Dlooxq|$Ow>~eB^?3C10UPWlK z87X3?IeP zzRX!5{0Xn;2}buZj#0d~&$73VQtX!g(<~}Z$SlD;K9AZr;3?K)(sT{hKI#N=4c`Q@_^Uu}fB$rUf31Oy+9OLO~ty z;`leH{}*K=i+~vB(;pP0gMf%JfPfJHk7Z;0cR8_vsoUSAB=EUpsFSk4GliRFpi$w2 zQ8OTQ|55nJNLoJ3;iWE0=wW1btgS7_7}(dRca&hHgDXhXuj+QLIeM=C30QG7!qU@y z6MCMLr<@WS+?in7df)zeQs9^I&GX#Hr}X(eWG3F0^^IHhQ=fcJXIVbELOZ8A+*-CQ zo3gPOAWna9kGJxU8hDUS3gK5fwv=Jxo3wJ%&T$Ljk6b`l{!u`uP(A(-!XADC7mz)E z^rHcK`KNxhi$+p~n@7_10R*cmnG)QQP4akbDEjf4h~cnY=&!+7q+;5P`K7P%LvoAO0soyY~RrC-O!a&jo1%VN~Se zmZWLI2k)3tA(1mTY!yo%AQ#j*EnPdl$-YgvOYmcx2FwXTRiIO*l}=jd_%H5&!a?WE zLAXdy5EJaOWWTlRv$J@PTu7Um2}-Ykt;Bg{pQz;fk@1q zrOh@&Sf-tS`1lP>3PoGyy`RNUdda1R$Xjn$u~g2$!z%90$_p;#Pnv?3cs|eheh(e7YaH#4z~&$IfdIXgc9M>U9wfsIQIW? z)OTP+do^0(?j#`xy7)z+DCGX=&zK@oaQDi^T!}jlTQyj5z{yu>typJGky)v+(M;9G zIhB7LFNG;hwdue!S?QVWyG&ufEZ~j8wo8OP;cc`{74rH)`@&N^M!sc~W1MMeX-=F=Im6*N$P^q0HOE#8k3)zv?DlR3Cy z*=ZIu@r{vs%p1uG!+k!W3p99BJKDoTCDHP#v74jew?& zR-d^uFP9LPNLY$La~+!+K%hx}_VRlZr@82gJW}Ymlw%IXBBE%-SBw;LM1cT@`E$yC zF-(dWTnnfI~{MMIfJo?=-uvKrJh zZzGeP&%RY{4!i`Bve@=FfzoTuJ2(SzewQD4wWN}1>YB9IR?`Y5z-i2 zw;Abo>sXMUJRPP?IXNhDXlb{|66nx=+g2ACZL3?YjXUoYyM-6!vL|Ar?ZrPBI?LZ3 zq_>jEAA?jI3E~A-vkaP|%dP>us2AjiZP0xB&FawKVzr!!q7Vh>6=_rGQsBzW?wVVYsl8`XwQIn$R($epgcU z=0E>g!iw)goQ5K&V)ocF9e(;T)#TyNw0YUR9=V3DX;xjz{}OSY(vN+*8N1hNpL|vc z3!i#q!&R$cz;69^KfUFJp|bf!e#K2>CuPq-bBeKc0UPF(g`082c4?SR6RS3~{#@G` zlt!GV%;1KTwwG;*ndRctyj#UGb)z&I7kdB){PV$?SlQ*27{+ zf!9E8{j4pqVd;g8_vR$={DY-m=K$>9HFlopMCtSckof|KU04@+CpCGZ$#*(Z5)1c7 zNG8|i`lV5-yZp-LkH;$UWp9Wa3g&*aaDT-MB-|{%5(C;N3lCUHOxrX)R0 zx>y&N=`%fbe612J9cG6gJYGCb!Ohzcvrt|es1xRkaA26|x7w zMi_3!f4nSjFOP|jbFh&*B=_?zy>OiA^dsOacwQ)NONW(n!dzZ?DM?z2PvfwNQxe`X_Q2V- zix<(0qV7-AVIh&thgm*Any`dg4dId&jXUy#=}w6wQ0JuZZo%UVqI7)4H@^f>Ju$j# z^!P&f#`LJO!zo{>{ou<7m=Zp~22$E@v;N4OXi@z8RN3NpYeVBqqz0`#s@(gaY5p!8 zB>>jWh#r;lzlXg*!l{(L3s^D~Sk^SfVW2XG!)0{scB2*= z%TL0hzCicCYGBH=t8i~wX)1pj4g%vbl44IDjv8P?L)mU|?GDZ1XO*krTXFF;9l2dq zanVVoi}-jcIPdU7@32s6&i5Bupti%7E9`Zs;qCTxJp93zoGunyhHEB+SJ?B#=s{Y= zRLL^ynb_V``_i2gko*g{baKVGcpSLttDZE}UI$Z3Xx5%za5OP0l>QCVwjZ6-Q=Nomgi0_XcXl2Jc2DPO z*SF}nm0;QYP5Q|EOIA4UfrNl!{p4`X3saH%Yt>?UDCxq$u!??1kIZR_@(H_I0cOTN zE{CNHqM4b|@o6J_ed%k80vX}h^_t+bSzvz7+ZtQPjBx<4z4st+neb$Ve)o0h%W_A& zDt9HlSBctI$V6Mg@TMzzR!-jH+3l8QBvv0tY*6`ZcPDsj74{SOiFEaT=Lx~>y|hq| zT{av;0^5NRpDV9~m=YK^uBA>$QeSco{YqDpxEMBK8;MkuuNc_o*2F5WcB((goN1{> zQ*gY5kW~#hdoM$sNs|5}XKnUHt%m)TI(am78hJW`jbf9an#BHSM+arSPsyIDOM6`j zh*|dyfdp4|m4k*yqI!^zv8qP?7^}t0i1nlXQvr zQ!eEk-KtDaRibt^A&MW1fxb{6uZ)8YNR<76Xm%eQB?G9upj_t&H_7b>{@)*Jlz0Bf z5o^|145bTZn);nWCpn*w5ZJgT;mJ(P`La&|?ornvvkdNne-RiBFZ(n4#h-%;gFI+# zs0P;>mki@&*?Y7~-?dBMqYX~laZ2Klf+mQQ7-C$^e~=W51OnN zUtZWv%%GXE|5_x_x%o&lNG5A?M&o_|^%>~gkW3Wqxsv%OXzG@l&n9db>$ryLk;I@T z=#@<5T-3$>p{Z-Ba7f46{ai&Yk#j7T5WZN>mzZHMH@2|L#R8kr+w@Du+ZkzMW~jTbt$esprJ>dc#$Z(w-){;2}0EtVTxx9WVLk%+J8sj+2%^#G$e;ktMmY*ESObV-& zasr-`m4Ogvh8sWtz@yD!7WuiNO^>B07LI>go$8$Y4*Kya`#9ljpXU|S7a3VqR^M_u z7pmSFtrt<%KlhEy(dHAgHgq8of6Jpk(C?8n?{)tIdFXOjQ~}l&7{%EEAS^*R+;8(s z=R#JOWBLTJ+5d##d_-E*`(q2Hq%0#%_vd_6mU@v_xSlVWXl!&-7jaoW@(PiEzl>Yf ziJ*uR=Qjl*>_OdPgf$m;fBoqdn0xUc@?Q`Gc3~`{2+lF+COeznb0<+$7vrwjijn~2 zHNucj!r>_&c=SY&kVI7mz*rMW`wBdc5mNJM5HE9Oz4`%b{~h#GIQX*}ACgebBt8Ta`>hz%k45=kDgJLf8f5NZAOK8<=%7)g)Hgn` zZb=dWCOl!qJ`M)C?^T>!d{d;w%^%wy5M{EAi6ZQikyl`1O;COR`HMw3e=c3(7{mi( zOHuHKWTE)K@*|ClQPAm5qz?en^(~EKRx?6U8li}GN`cWz>Kc?(P#FylasMuBxn9Z~ zcG!!NPCJWPbg_L1=x(QYRZ&RF|ZtYNbE#T&5E=c5#DxFX3%TFdV+@+U0w^MPS` zK&<+om-z_*6t%oyaT7o_eyf6>{Sw_t{K}u?%yj!F#of^3mF_dPDgS1c@`K9|Ht)nQf&EDEumgyENiPApGx ztAa74HyzA&9Bn7Agw@z;Ec_$lzk?0p!rQ3ydZ|;Rp!K|UOQL+>&Y40}j+Za%=BK%l zXPP_HjrnuLSZ+si`4+>wl8-wLCY`Z3pkd&lZDZi9Z(I1DsK$Z>CqM&Y^g%`DPNq49 zQlbHGG`KJJXbuJKt zM{r{WEQ=7$|D*c^GaffB`oIr{fS&L=66=$~i#z}1l@ zAq>vGDBj_F9v%8~K)B|C?jEKw{HT!MKm`#JCr>@m(?7XuxTbgBIsW(eb&B5$l#c(0 zwmS=C?}K18OBIMUq=3@+dXVvUC{yUqN5x+bYLl;CK_^8mbRR^mfJP4}#2Kn_Rzj+v zwi2+k<~>07qFjrOyn`-+E<#O99n$ZxS^gI{wMSufK~))?=mSJZHt#QHGi?+To15kF zY~DtIAK(Mgl<-QgioGy66vmm#SYa^B+@-N0%V?fz()4SWi$BSwiAk(^gW*bMENMF> zS-u1381ARSPwUsXp^f<35E8AFWNv$-^l*Up=qQObkf!1GHjb{^h3kymW5X1iwOv5B z(!4u=lH2qau|&G+Z&Igjh%TpWa}5N?SZy)1BZd=aIBbHC>Q3<+27;QLP{blapaQv( z+Hs!0$?JQ)&UvZUV$`6_mL|s1kHCc#j=6`Vp}I)HF2ZGJgISikZzDn&7Ftol)exZ6 zRZJZfvbV^{Wv|gjyG%)bX+ih49WutBA*v5S@~y@E9VTBbQbAD5ACj(te~7k0a43*j zePI#5#iJ#~8UcPE6)a8XbP*cq2j%iXcJ!lYtSQmRUydI>267lgCVv4$rQE}IoKp|n z9xxoqK#I+sDX)PfhB#cl2!5Y{nots&<@8sO|2KIS0V&$+-~<0}%bE@m1cdVc2G2se z_y7ah%mKuhOj9%37)&$$6s8PJ8h4p^M>GaK-#^KGka=m`nN(>u(~QwGMHo9chIduj z=ZxzL3e^}m|C^m(|8+>%%%(V9gPEMJ{oHm0P71tE=HH(yi2~twxdmYlur+m2q>>|7 znbq|XQ$4~XQIRZAaG5UntE0U6<2dVXV}PLyoRBdkzBuHD`+E+;HF15UQoJ4b1HBhd z>>ZOx?tZ-C=iwK@0_X$Oz`?atQpekeYUZ~)cBF+UZ_QCR5`Lm_kU;F=#NV$FgocO0 zLY5a)q=vA27Mw;fd#lKXaC;t4fY@j*sAKN(gR6}`2ZPw$Mn;VtXjxnZ&A7GKWnSECseH7juy>T>^eK~r+^>GgH9{v zQA$1ZDYp=xo1>|He}8SM^<;QTi!tqZnV}^TS6odcp}HJw_-PIHn+1had@W>rkBfou zZCXwBn#~U=v(2BK3lW$QFB6ZT62MiSDu=}%#uIci!})adikWW4>4<4JrzNNQnzX~g zG)Htb#@1gPVh!r(WFCecnhQzL7WeE?T2?B}9dhmXb{#h+&oZKQRT7&?8(!|GZYT-< z$Mo9sA8XX0IT1Fn)Wm723KqJS@nR6L7dZ|Q4Xth0@`qUL4|Q<15`*%WtpLo$IwK9rHF^m)f{o9d(hT8qXq@H6 zT5zrZ{6CsPvnpI`wgI`Z4}cY?`g5D>CyjUbwD71N=rB5$LgX?278d$Nb<J^@m`c!S)=Ee&5;!1gq zRW+;VAyrDtV=efcTj!1RpNJVx`+42BTZ3vHa=DrJGx|4bK8@XHf1WXP+h_}25Qfk9 zA(kd9DYY5zh05>iVj<{N$=+24PO^miM~t!2fvCYRgl=OjM-44%q0%z@mGHuMJ z7*b(*<3TSo6ILfCKND@m!?6Bz!GsL$x$Z1>QB>^~e(!yAnoPGSaGILomX}^Vq4w9J z9wn)dy!&=C?%E*^J4U0I=_V@tS}$2OcKfY`@37fZBT}bV7ppY$j5x}dPV=wLAEWg( zxNfk%7*t!h)z_k0VQ&&Cf1~Vkd|zZ%@LLPROJ})trkH<7Qw|oa3vnA-gWG>~#ZL7% z{z9G>s$ymZBz)e&4W`V)We01(9&#I1oURM|@06A)Ih8{RxSYVaOiZ$yYn#xn-!_~0 z%vbshmvnP^;_rfN#h+A#Y{Y8U3Z83Mob=T5q<9St=9wlz(6+6y7VApYZ_H1rvc{JY z+7zK%Gwin?J(h(wq)ygdSg&1*-t5Yn`Nw*tP(@)Tqk-GWe_35PL!ZUky1u~6^*vi8 z;`T-%=ZCl9-EvD+L0Zq=yUN+wJ`b~s!il$mlorDKs+=(zz2>BLxX#N;S-?-dah1_W znmi2UoRxTOdDA?)`;V&TJBvfS-Uo!?w#SR8tq~#0Nrb>?B>pWuP z?EZZEAiG6{PIDDhw$G-r^L2h1%2{bOuVvFZe0YA{O-Yz_448aGxcSW^3rG`bOadew zJmOLZ0Tjv!?kVu;k%~0*k%lF$DfC6n1YNAsMTA&D&l|zxr zn7CB@09Uhq7M|{j#4HNORV3o)htW$)sfg|KQK$#L>LNpqA&7Y+P!|+*VTi~^Zy5?T z4p&&XE``DK>)VeA-9z-iSeG^N^G(N+QYvaZ@KI=pEJEZH0;CgxP_A9uSyUn_c#Ic^pYV~24d<-41il78S>0pG_%u9 zU?&Dt_Yt6TIf!7oj|KVVA&}SqB_t?B;NyNDh+hIj8{kra1F|6uh#DY3iBg2RF+hjX z$`H8YA{Oyd2MN&eA7RQFoE#)WqH8d80L*d>Xc)i%Xb4`e|G*Rp*kAoC;2W4~u0W{N z>ucd0WN4uhHZ6eO@Fpnu_w4%?APh#~ZQ1wjfhjy`+{3?ruH+GTIUE6nc7T~S2JS1S Urq<#=aDw0M@QwXVor~800LZTgC;$Ke delta 17336 zcmY(LV{o8Nw5>DY#I`23t%+^h&cybcOeVH%+qP}nww>JX-l|)5PFL-J-T%5*b+5Ib zj+q4;8Uw5Gg@*SuIC$j(2LV}u0s#?>M@AutFNLNAHkENz(Y`mW*&RS%;WoC$n~8FAP$iMd(MZ*oVh#JvuGCNNC62o@2%Y8{N< z!s1)^{xZeaNN+KZEku@$sILbcXi}!@Jam0;hM0X+KXvJSBY?cw^STf{+E1{jzUtUF6eZqR7E$oLj>N+J;(=b5X zGZAeYLkYGg;bWkvP0=6yg#PBd8V0l{9fA_t-I>o=vthqGoM^HctZ^#CS8M3 zbs&3#_DV1UtoW>a#T$Hwp&=*)Y_J0`koSBf3Kow+Z#dS|(9j`ix*5dY|GUto%z_p=yQW_|{4w>JQWi zRhKT~UJBkCahnIxXut!jv}fd!yA=fOVta%_nH{#4l(yJQ)ZH2BDoo}< z^1(aEqkD*$x2S|ZD#1zd$801ZeAX68qf_LH!X@IBHi@$}95RE6by3#+O7v9lJMam~ ztgM`^12pqsQadD$c>(VgZm5BkUqFVw)1)K3?I$UXY%TZCfCCQaRX|!}ThVnJbq?{Q zKbq4&8?7D9fxH3UHNYJ~a?lou&jh|yx0-ud+zVfecS*>~v)d|xaFG%)H#RG)_kwt2 znoq@@L4BjcBQo3l_l1lgF$L{|PCgrj-xVH&RHO`@S>}!_8}No1GSzTSW6=SK`y(O= zmM0Cdl#sl#pg&?-O;mFRZI66WWWL~IfA}MR6e@Aa9pHp|r=cv48qJL!s~Xqgo|>vE z$y}N!rAd_`to3k#sex%7igJk1RYQ+Sc@7(sRlbWI!!tw`{UNL{nx;L=Z;YGj!ly&V;1kw2F6)>8m2UUBu-VL?Sl@bemMFW^D8D(W=SWDTNeA4>Bm#p1J z86{rT--zMazCeJ4+o>eAIh3;Z8WyK(uH!5oj{EcH9SXl;cUwaoSPX006b%{U(LP<; z;@Y^OvaPN9nxJ=c9&R-S>!xP+@?lL1k5T5lbtELF zY`Eq~P5hVCn_<3A3zm^P6XZ+u!o@3As)8a=IC@x=kRe05*{2ss#9uU^Co1o5E0nI0 zr*13^Kx28v3 zG1yRB&+3rIj=*{QQ#(|$Erwioj!busRd>_buB||Nj`Iw-rcH|-3Y)L?yK2AQaGLi0 z^2&bcbJO#I?@{v@i*|Vd*!bUWU#X|Ma)R{L`|Yq^Wcj^c=pOGx2OrnTeTSpB2d}YT z;s`N(x1;%c2;Xk;z9iuF)p&u5pz4=e2*7Bk9P(=+I`M^tUu|dl^9AHfi0-=(=WA@> z+_wV}s0^yce!+eG(B|KY?!Mo@zD2Zp8K$;+r$GI_7+$_*fcyd$2fANtp}(&J-;@zm z_Hkbj`Ll+Bv=;{cFWhYvl&(U`ZRQ*Pu_(LpU3fNcad;;@a4RG>6)YvokYTiHLj1ja zQ==54HzrEeq8Hgx_JO;6)NGEzAo)^NS{Ey|>6}q!egx^BghSsBVj3AuONjvDN@mkW zDnYPoc9Tf`r7=LZXrrQ_isb-9Sg2^jYRpraJ;gDd3OBJsb}VaM){@n|(ad#EAE_KxuO};XFnW z>DTGT>!zh!UugR*^15t{2FHw3N%6DBbZKwZmqbf*ur;t*d|B`6H4zovEWTmF`nyY6 zp`HR+zSVUDzromYIHB_I*_6M}d)u45Xy0%aO*SWKmvdOOCHqEKB9# zK}YI!!UfRIffL=<4xSk)tx>b`IG8XQ06LvDKp9za9yOGi^>9!V&ufJ^jECMa5Q2}} z5U=={MdG;;O3C7UuS7mSFc6pI!*JE5%3+HmIWU~Je_Bvq!|J?3gNv>#JJ2XTh1XQ< zxRsL6)mYIwRI$;r--P%O?4*?!`s6d4lFx?qbOMwxN4hAEjlE&JDA}@R&8up+B}2@( z*bbyBg>UF&FJniw%Q4#yTj+3OYyWCYU$>g4qGww4~=d|6@|%|<&{KW?tSfBkC&jCoFEexb5c(}F?AZqL^h?NE0HPC6%_8x z-U1qU5?!%fhO-VFMHAN5G1U5RUqywlSWVK2+_395WAKAEWCN6+QdnXlV3z29J{<-A zKo?)sU}AFoeYJKBG=2^8E+kK9(pA2X|xbE zTf6fc1!qFDS7)-WtD_n!4wbZf)KM{J8;S!b^QOI{WqJ5GuI-PY^RCeb*z3Ne`1QKx zIY^<8hb(GmO;I{J##vmVx$~iu}2yabImKJHK~jJs{hHp(!u3HL!44F`H1lor}j<9q$G&|T9px=9-hh#Ga; z+;poXUUWKrJaiv;zfB~QFGygHyntF|l0X)%jautRBLiwZrMu_yT|Y8IE{omcTSeIF zUGDr6IJ-s5`hyr}ZAT6FhAQ2@AJU$M({Utob`k?|`OF5RIdxBUc*a`!Furl8RLj_G z2R2D?qYk}ypkWUfQW{7T;c&9+r3$k{?4}nE!g3mSIT;NHL|kNkM2Ol(BsHQ0xU&*|B~P@qVw0%M#zphZx7&@K*=mDZ80_dDv1 zDV_n{s6D8VIfkiszqSd)Z`5SuO&h^Um{*1i4a%rL=-?g0Ld4r#20WX|qDR-IU+%P% zlY1ovB^0L{Gt(m);l=m!ZM zv*No@B#qdxqK8pzC{XjUCFZ2fB3T|oYvu+71gEA8G_|ieZWgY^4C_+WG6dIA(?x6F z{j<`5Pq#65`ek*v1vu_#B>QA$6k~;|Xk*lWW+cYgz~}$rC|ctv5{krC=6UR%6jhd{ zABq2$$!vhMrQM>v*@3ol`^MmQ;Kc?d%S$+>%XQ-WD%^qfdr$OY5M)L-?kgX4binxu zrKRpdk&^S_+cj8KJz~#_SDw4F+{`#8S$p&T?Vm2QjMiAkHvrq^^FcK{i7z*yF>9#X zS8TdK+2|TKU|n*4FMj(GxX9sQ#+oK``iG@<^_<-K1196%ZNW4$oMEhY=nhk?QBB%y ze=tqYaZp%OG6j3oo#t zdIck;p57hoS&;D2+IvmJk-5eqXgOAN2y5#Bg-E@+b!xI;nu`@7$XUViQ54x*b9Mt@jIrSFe(VAM>XXEHf3S3f}s7BT@SVqgAmG3QRk3Abn zy?i&xzAiU3jDfmam=VG*L=|Ejkh^KCU+yda2xIA}v^#w#ayuw{Z_ws^P;qAEE+w_m zbNAX#t$ajzfuT1W*S$+cPkhg4iQFD6=>Sa}{eT(+Gkwa?Xeibg%ahMqv}+o27u`2U zHP>K#1`?o8LYbN9pJNL^mpryqyXCAXk8|Jtc9l9zEA6VAa(+V`;7XHH*tq$tnr1K< zt46^#8{xkZVFmmDGDT%e_^WQi%)nm|pf{c8*>12pV`n#*d6@rD*ZT>mO>Af9C@EEAee zsFSMPJIx3q%!hf@9+#D6DY3Bf#ZHv1Waytqd+30(o2T^_o}^=8)C-afD)aa}KjEE` zt8`Pi!dNh(QQMJ&G{p!7PMSYM^C4O{W^ z1*pz_gS0X?gdc^os>)ScRVuY9U3|YbqrK{NyjWs?&z~y|@c?6QHGz@B5Q~B9p(bH8{aILw}5> zydqfsdvA7px(dPWo(-H?V{12kFf3QI0>I1L3&O5AgMMSy*xa?WLhv+0G8tKR#uAh_ zu$dXzDaxS;NayJo$GN4d?^m&FwtiN>EU8*kM16pqgcA~8FQ?85c7ks)^abk?D+TKvO;sW37$!P{r4#*^;MV?b;W7qn!L4cA<%A~i==B6ewcVWuX(2A@ zc8}$_JAhTQs8sL&c}tZ&j5Y!r?$p^9j{<}9N-1=WA#({C+?pijnE-#zi7!MRLVl=4 zCHde9$;UDkqu`QedBC*K$mREU19nM&hXmiiatu`mLTTQ^W}hS-=bsq(;@q0Nb5CjC?*Cn#$7kO9 z^>dx2Z|WQRgS5>!GpFh%EwLFYNUnt{HDx}^TT2+FKe&1Yy3Mh-IU}WFR&EjIEA0$xTI-~Z8c_4Zr>8m zzy9Kc2{hfC55rw`&GCgt0l7U>N7x%)x*P@}J5KV@q%!f22 zBTO2|8`weW%8H!%c$?K^%km&9YmRvTZKG!_ke`byt_?H5%!7DF29l2qz14r{xuWlw zV*Yv2M3({GWUw0PC?V?HTQ4!AR!7@w4VC$*n;ud&QaRfnBMZ6|fZXk;^AEtrgK<{( z#R+CPIkkj-D0}{mxE)LlCQeN1>aG=d{)sKZ-61GHGd}p0J9gAF3kNxZ^a=-AZGXJJ zFqJ!(DHxrwe|2->4B)G`40)?Ep88bG8eeQvoV?cRM5JM1*96Esja#|O;+B6Cy!rh5 zoSA;hHh|LUaf+C_=hj1H1}z`GblR1F(my0&cfM?Wo{{dtMEeV-l8}s zXTqt>=2(h!F3nxl;mlaaa`6mLZCpWjnP#bv8#_J zzZS){lG*+%y832d=!CL4%Di6MrTpjwaPR`EfvxhBVl;KhS_Tu?Oh|}@s+}2DE zyD#Ljp~H+XtmO<)dr2>b$tJygBvaM=Y1C# zz3XAz5BGc+e-0}5`mjLv@GuDX^1scc8ni#IhQVM69`-M(``m-W-1ccTH%V4sH%+Yv>x%g>_B){-}GXyh~ybyO4?2W&K{jDxriK>R4I9pkt!?5J9 zt1kArj-9&7ycBP9dv|36Bn_~uo|3xI^>^56e7Z7t0@Pw@a;^wp4E~@ z-jTh~FtT`;ESQM5*}@}LPZ?_h0+Ymc%XI!$$s}g%HsOQtRceTuBP3eh&H9LKQvOR%~=WlSh1l(^Q|&OZeHFXl`vb8%cDxzYG`-l9_x&;qqIBa-GOKg zHz5l%1z%w89}~^R&Sy7AU(73s);P!h(O-)iOdmR(lf(Q&n0U#G+E7mn*doA5m>zqI z67A7C>dPk0`7VVN*~EW@cf25?IZ8G+XGh{xalv#=?VNmm{^y6bQ0ZXB^rc2ro=G_- z>M0CtDd0`5RS3N@7X?bMd^ngDF3=?-OZMBYH8+R<`RjOuiR3j!X7g!1MR51;4#g&U z6=zwwlzsn&oh9?au9*WAf3#5p$3N6znZ#)$vQt_H-Kxf-{ z$kKG|Qj_qP0YeO7zn5XQJ^RFY$`kKLja@PzDcq$zS)LIo7V77?rF-jsQD6=xce=rb zsgrYBO)7?N@s82V*Y54gSK~?L7jLf&f*R^366JN zF{cy`6X$ZfX&!d4zHK)NtR)L0!0U(Nyt|Y83Bk|!Qkv`33a#Y|x>M|{1c8BU@P-fG zJjtsm^!-D*zAsInSD*C*9hkpy!`=XP(t?0Jobmq53D`fe0;;`9!0xu=wlU0C{;tD^ zdhRcx0W{GB%RY)Rbj4g~(U(+t4o<;`1$Vg%S&B=Iz7aYUeHAOAM6H)7We-^uXjucN z@+_G&*OKj=Sm+=|w8UfEkS`c~j!K0k3ZkXg8HaJ1e|dnlVP=M$(WXivDOmps5iu5?P% zLxQQ8ONs%l3V-K5i8a*Hr2fRuJ9q0}HcVWY$qOw?#wHAuZrpb!mABTZ9_tx_Ip>-xbD9Y z(APk1C7=d2v4@PPLf_VLi)z zs=mtAtUr2W%dt-3$Ermu5Rn8igEnRH*l5Y>_1r~A18zlg1CB~s&F*-cDe6Z@GHtaF z^c`e0CaZ_)u5mNlbu=l z6S$2_f-U}o+F=?;7TzZ**^Q_~lcUk03p{|mOo`oq)1`Z+fC=_K6&jziP|0$AqN^)I zCb3|zOIb<(6!R&wmf)b2X|r}V{I}udluIdD{Qg1s-!Sv+4L!`psK3kV1FZ5z!S0>V zgw`w3=|tbj;5S4eKV5|kFwK<}20h%iboRa7wmO3D`8@6|Z|>7MT%tM)SZ~#DnmYgo zEM1ES~_V&v9`^b-5!pb$Z<14>PtB_9!Dk{TfHKzs5U7 z0v1>t(ME>)GyD`vLt+``5%dPIRXK|en=$7Eczv027hjQX~O+4XFQT+0#amAeqG-L9mpsaJjl%7eu9(P7`!Pvw13wz*lD3_p*;UvBG zr1)H*U6wT|)x>j5y*o3BM=el8$1B@Rei-{cK8vp^|32Ef-`k zVK5T??p+p`q!JmrDta1M8_EEqkEGUbdJMAVsE&g&#}81U6|RsZ+HG3#UAUxsJJB4f z8s-4);My{*Djq~zHH4_@S=xg!(8m90M;g#FwAt&B|fyZw*~@QJ9v4)I8f7=~=Yjw#?YAh~k;v!)v@QP&L0L z^_?^>Yb}>Q(x>zGLa*?GON6{6sUx5V&*GHPm+x8;mB z!+=`4s`wkR9*!#t8hiyVjx;_?NDSB%qVxTg=Pj*GtqqfgG>9b`K`zR`D0^e85mZ<6 zIbvJ>MPk=7Ba$~eAkFZhIK)yftt|!5Dmy)~n)%Fiy_&ko4*(ya3VkGC4hNHpsM zs1^1eomQ6(yv2Hjs-7)jz22(N+8Zv-2!TEob8Rut~T=ScCT6GI&9WgYAwejyd5RWQ!?ki>rGUKD!wA18$mMxDV4(Y;sKW*EP^O#jV&Ceei>f zCh-A3J=pyiU80a$LPsEl`{+#-afVAiBz#}dw7TrWPLdJGg~@t~a%-_kS7^mnGlZtV znPv76a?DVs7G&6Qa{)rW*P00@oWo9)FPet!nMV1UJPK!`wSAY`;Xl;i+xY-o>;X#> zK`*N+yt~>+c)mDhA0Sf;0kJ=j|KulPX_|>D;}8}KR#R( z88CFG4gJSxjUe%h#!wv8C?1Iv3zUo&e&I~|E-qpMWxIn3TDPGRy|J=V%W77wQupL< zWeKST_1c=2cCwYtpUU=4%yyqOU*AI6@8ho2QBseeFYhmb?_2H9{{?P${Kr{d$HCvN z*I3AOyWLQh49C*Szb3KgWMYf#@zP4?(16k7hF^(}68onFd)d5L1;3_aYE$PXVD7Ac zE2r7V9N%pG!r!ScNG*17h$*`9&ehLxko1!daK=ow)FCK1)j=+3Z&mWd7}HMdpqq1d zi0Q+FxkJ&zDd5&4&mJ$-B$^z%b&i-uxS@_LH+6T3*&6>-aGwEEop{_T=nJ(B-U6tJ zor%1;2x$-&5bF`{+#j?G?g#y*eblWjohZI#sok0_LYxezYE0CM=O}@^C7|gVVfAuZmDLq zK~QjMZMA`XAa@lI6{scpYFTnwiEJ<00A;k8FC6ayD^NQLp}x8@*RT zE)n0~`sEU;+TLQv+d1V`=utg%4XYH9Uf|J<ofE zTyJKxwr#VQo@|1bfr!M!O~z4GB-zqjwAPMwKej4@c7fi-Y<9z%O~Bsqk@>R7tDkR3 zF=HjKm@1PSw}?(t{5caU2~ocD*ltheAQZ4;}6onR?2QNNo zK;K0f{OwgjWTFfS`Rvjf)HQBXFDt?YK6FY^WNew5Byp5&Q)ClgdW3BtOJw!zOFoW| z=6*DjZ0AA)F}_bL#zvY1h~{zhoM**cmAmA=v!1Q(-=Ctb27rb+`Fe#!^S-g2*TCPV zc>FJ{Xf-ym1nj>E=kTFea2zfsJr6GCf5~~R_R?aFs&y-Ghl3Yof~!$zsHSxFnAK|I zsiQ`gjH2du!1E{NuoWQ^9Y#gQtXNb9A~?L-C)wAn)k*wI0whatT!)pb&VCERN>E%9 zNS4i#XcTbGVFMf&34w!{ng5ot{(w+Q&R1PSJXtgCV9bY!#z}^P4D49gDzM7eaMG<` z`;A#|Tj5;FG0U!9h9+bVmTP(X^o3zJRsQTyB;~(3wG}0vW;(*4A+l^`M-S!Bs0p3J zHikACz(YnzuUBm6J_p$HiK56VRX8HDq?vnvDCrVoumF1@{P-f!H25w!`mph0aXcgr z*2Xi7%1UjpR%CIqK_GTI?bvK&n_BcwKXQ{~N-rUl_Go67AY5osdwv@?YiHenT;Y7; z(8~=zi{;#=Ryib{|H#H}uI#EnP4H)Ggwd?f6CWwq3<0{r?&aVmkSr_J* zvN){F!~&$R@k!CzwNt%^H*v&MhYwX<3B>W|-ctNnY!Y$Pmn$;T(%4Ju-7s~^fvopH zOW{>yGMrH;%51inB`%U%uB5ML_yWkwJGMmUXp_uFYtY6;V4mSQNCMBPSGlSBEm|41 zoZccF&r9H{(J78y=B(p)8{?6ntwn?5)sH8Hg^05ogZ`g5^`U2d_+m94HshRK3|#uZJ2r^%-&JHzXg8 zVqct@Q=BdY*le{$>iDYVQ|dOYVj9crA&!#|s;%n#;#aXqeiA|`=dMt@rPq3I7ORnF z0pQ)p@QEwaZdW^3s46Jr`3RmZk<#0_E0RAtXBvMJ+Q{Co%9{reJZ88{cK%}4FTNN2 zf^m%Y!p^%@clp8rbdQC-gQvE4?4+EEr-EO_GOzP6Q|Y`o%gBO)#34{}t2+?!Gg64Yvn4;pcGDDP}H+ z?GvEK@2@Fx*~RNFzJ7!Yuj`CdZkI826mvz6UYxVL>}(r`J*}5cVf%x(7=G)C0J+&i zV0(o0q;~>nIr7zgNO*K%|%Pz);llVrw z5VazrHby>#fS^K981XoTb(Hho!%Jo|YYim2OelZ)MjcPjmVT)L1HyGFvO!cirX~e6 z*kgCLQU^Sx_u<|(-7Rr2Ywgw<0NBOQ_-F) zshQb15_DUz0y>=eHqJQn8!5#3hpwmM@%3##H=w^o;16~R5gKanhcqk7*zg8SNqBp+IrZ89RJX3zbtGGf;4f?Rw%?d%%_RNdFd@q`Z@r8Gc~ouQOk zw1?p(w1)J`Wa3^C&^!0zLzi>Yz8+)Z@E70T?_tr!>R^cv7T>~hcaJbwe$-7>-;{HI z#{q%61jWA>UY9>`Gl6lSTUhc;3;FcH{Ht>cKob9o{Z6R8NvV@PUM79~)ZE~8YCvU= zE;%kbEZW^5s{Pgh|`ukvR_*=CG*VK-yVovgtK~Jx@GE9SVv5sy zH*7@}K;6=wBrYkE6Qa5>QrW{OkMj(rLeCe4UQArg+iskz{I`}erFtoA7dn5<>y!E*T-E)Mp*Y&h5c;57#B?4w4?)rJ5FrvF zZ`mzcRu12C9!P;@9=)6j-J8btCKcNVrOnGAx<*WHyph+nyiiilkIU1Lo1}y>7p1Qe z+R`fi;q_4X{$_zdGWaU2yM5k8OE)U(@iZeIE|_V`Qe5fmPR=sUT36eHA3U+K!r`Rn z#+&SNm0t*rBqj0lSZ3|RS}Up_){|WtR!>ekgWQkznH&K2D(t!E&L|Vc_}ePo#UE5? zTp|N!J0YSaYuqF{f)vt2z5Lj)e99VjoRic`Um6xXGEJYPg6V|(5qVwAZV%`)A-qJyFE)pL^%2S>}st=6zHDDdGDWXY=Wg{GR~Sp<MYM7`I}uIMWGtB32q9J=FXd}V?*M(f2`Gt3xZ4EkWKz|G~OSrzT;}{$i%XV~EPOZL-yzE8s zw+5(&S`U|WvS3I=iH#O|_|X=TLO-ld;1dILF!kda!tqCLmipZ9$BwY7p?kO)Jz+x8 zcP4LL1Oz?a<3#wGmO4S0CbWp@VsS_bej(JcvFI2zHHUv6ritPfdxnjD!?SV}{A;Z# z*hN&%7$zy=^`%&L_orGB30%CVs1K6FkK_PzttV>f-9q}vq2RTPGoPnOT0R;n{B+~t zC#xlD+NiAQ^NdKxfx4IQmM?Y5)98ML75^K>zmEXc!a~{u#8>Ju8mN+*?4sWiqHa-f z^=RBl{!S1kl?B)hNO25Gj<)t{<72H!wmI^G#DtZ3pAVMy&~waf$WM<3w%9&Fwn2ay zOU|+RsZ&mxG|MSQ$Lp!u#FNpHO-jIiOFrUuWEY6o6Q&H0RIY3QYiFUipBbx%n)^M) zd^6}`myq37C2KwN!Fh2iO-JCCcF>m=@|_1v?maCg~7@hX&L_0zcY$hUwff2QUo zeu4cs$Ykl0huRD5C((87x~1Z8_&}f|@T-uJQ_88lF=k2L+`}&amT3Dx^pn-je1t-G zkf-|QzBiY`r1jNJXhhPPJrnlFbRo{;17-bXj!*->LOCiLvcR!Xi#uYbq@tDp6Bcun z2S#NsshOrq^f9EABI@Ie+*zU8S-veuL-ZD`Ko?=nd0;4mI{CGqBrHfg!wi6Fn1ST( z8`=e@?7IK?3$AjOUQ15Dx1_}uSYmrWEoWrygW=Q9ucle8E)aHxGO^9OKf&GE8$A1S zn(j>T0gDf~b_saHK4+XGM%ZsP>La!xLnT*;;}_9cF@ z#snQ9xxa~gF}u$!t9UTb835b@$}mzL&&rnJ#d)ukiTH(gJWNXd6HYWi)Z&O9SA~Hd z;2|(+(MpTYf(;gEv2e6q%A>!!Qsnn%e8D~Sp(CG(cB&wes&f~y_z*ER;kno(t$gRwOBj5Jc4e7+#e zHRom{F3_CvxW_*zCj*Vb_3EwytBe~BLf;> z6xHc0Egyeq1q`Q=TXZ%kWq4QzqDBOEty@Nc@1aoqoaPen6qRUCUOI|J^=43uaJ^dY z{YHZGg+lv;lm+v{1nVpRrA4>J0rC&~n7+sx9TJB!dG`4fnGygQtqZf2;ohsWkE^rChAAo>VRy3%KBb+_L&wh#QDzSU(Xl3D*bI5bW1_(q&WmmT_00!3L+_1PVKcD{jQ*%oqzmkrON4oaI#CKO%?e=c z4Xw(GdFtuSl^@OPoWoYI%LTcsO{VXevJ>PEw|<1{qfnB$>ZfmD_|rq~7kR>f^@%H6 z^etHBi$C-V74a<39sHHNCHM_m3##e;ZYm%RKJ?OHQYvr-M zXfBwew;<-fkulmq+847=*xbFDts?l1=_I|E%_DvIKG{0wbrG?_AC`B=b76^peIt~1 zjG;qXeix16bVhOV$f@EC2F0i~;$@8gY-95bP@u*0h#xwH?>+CL4TVv}#`$~foe!89 zg--mg!#DZ>Be#D-UbTX#8hl-G1d}~1IWcRhxY?3HrJ+{sTz0cRVFPhuuT!4B(JPVC zK#0j6R{nj?8c&g{l`3=3$!|W*Fr}4;_0%P-nTMr1^~Y-3&59QBm$t}v@mWPPWg?JhY=;P^zU13D07oXYLgXKSkIecezlM#2M`tST zYMzN_@OM5Fq>5Ng<@f0HRfS7%k74Af$Av@c1%KnHp1^pjPNtlOuj)kWv@1#+e|h5e zER6TZO(!hjb?*ED>W+gYi=Dp79XSXOkEy7vUjX&| zv6eTl!T!+{@3ZOFT4wgR14T_As(W5K(@N$ubcCRX0NaWG`7_Ogm%ZbP^tJGX9MSRi zkF0<(yA9yS|8+Uz1vYT%6|^!yA*7_LDI()x9tjB7UtLMwEzK@QOv3_(h2%D-JU z>xH(FlB-2wK%oJ$_YK$wrGu;XK-sUZiHX!y7ALdk%g;k}fgj_V1&o>h_1M^$=}xq3 z7})=*OVk-7@3(L5we$G3zatQ2RIE-dIT*8*7%TIHmE`m(`)To+(MvVN*2}1r6w7I~ zt@01x-cO8S_T{R&yUCy_bznFpRj(UlG_xYpDmE$19N{#&LCBXVF&fdP6Qo-|)L0B? z+iO$+cMIc47lNSRZCxvVgNIlC!yhyQ@2g9yuY8m-yYcp{UB4h+orCN@-%?qY2m8@Q zrk!?76d;NSX3tl!+ooYe`Jqn$%|tCkuowXBO9`u>Lh=;rI~-P9Y81-L%uZ|FG(v`X z(}i@vi@nvEKtby&1k3u8e#0egpY)8`xf<}}l$l!~Xi7E-HvEAj89*{sYh&#*_6vP* zHzV$x$y*tAx04mnTUL6d&_K-YpC>P!5U5_C!5v||rCI%w>-r9~Hk@0biile-=1w6b z(M?7CpANJjNW-zSJI8-yV(fqX2l;>K5Jo(rE_|FmA|Q?9!K;_I0?qEKkRf0q*^~w% zo1T)e!W`ODr)#$WZ6G!$k|mPHR8Q(^DQ!6~^qf>>c`Bsd7LHMX)?6^&{3T1*y~V?l zWKD$mlJk7!)%G9jk?eN-`F_c<4Qdbb9cRzK#KQ<9+o!4%FF}2)a3qLnc=H6wkcDh0 z6;m_C17JwIVj)Z~lZCYOuBY=_hrYD@3vgHKqqvcT&Nd2ET6&@?>h10P(!7@T;N{ZnhR}R!@k_hdIg8Pw{g0 zv?}#2Yqy{djBB$lJrd2Iz#)h*DuKqlBdYbuCT8CoBY$jcKqnfx}BFw;1}V$Tdthl(IPzmZ=!KFK@1EV zGJvk!`XzAAxXg6Fjl0vbyzMZEFQA0F8F>$ljp{Bjgq?wY zOM-3rp)nNiE;U4bWXc;xyLq`e!tDE3-Q++qM|*3+Xl_;tVlm-XdFd6~S58oJ^aY}t z{6-qP+vrragLr4*oxyYHr7>iC1bCtIrPzCBK4O%|{GINrFhFSXfsBq_y(`cB6|oHQ z(0VcUFEwo;40}^8T;>v9Ekz*FauFQQTJZ-cByKxwl^ncwuve@e{+9C^Z??9uCpK4^%v*iKK?2s)R1aMss$u?7RLlOzo^S1_igW0W@yPRb{06yP zf9u=e@3_JYiFEvi<-&y+ByTaexFc=Hpnh2rs*Px#Cme5(G3Zz{&#A3%u*KnM(QiXO zFW~qQ%TSW;q>fbw;da;E@94-Q`>a4azeW!be;6rdJ0!#{{ySEE23BXKylW)U z2R!C;B38BEku-BTrYQNg{9NI70yyD+5ay}k?lpYfRJp|YF0e=<%o8*!;7re+`KCdn z1>EBNTh>{Oo}rwDgCp@HaZe##RqpeUnVSGn{@p`TFxrL!Hh^lEQ|Uh^+u%o;izf;t zrc)rC)f7E|GH--p3CO&s*u|5@9;M%kpkK0q*WH@H_pZKZxzQham zs46irO7-EZ7GOl2>Qu4s&%bNl$oLb|W-qE;l7u^Blgw8>0ivI?_uu&%zuq&^@KDfAc>9F@RBV6F%}qv@Q9-#BR^3o{ zxQ2BKYsumh3r#1Y(R7a8Mr2|0kjQxx$}^{vWH0`d<h@B<8D0niNq2dMM%{PKG2V&K~Cf-uz~E-tG(x%#5b$ z4H(_B8Y3Y+b{UK?ha~ymHBZLYmq?y#>X=l7due7}x!&^?O^AjRy4xyT-i}u64lAT} za?=cdSdz;pVVf9Js#-jwaA++OVH+LaE~?vi*5iCgLakL=Swb~+Pq!$1wO0?bRfo$F zNiLku@bJsb#yZCMu6Q|VYS3PUP5Azm$5Xj?Ud9UX-0K(M*2oU>4hlIDk!7(Atzj(3 z8}F^+H=htty|V*9cn_-9L{*^SWD(>`q`E?HvBp&y&XpliZgaI@I;xQ01HKAY>3ynv_oOKNljxzoi(IxN@6*9KuaI&{m`~^T)2vU(>(?65nN;Y_lrYDW z1Jry&$VAdX?{C7A8m3=<;dz}Jpr3cR+yryFpO&UEnm$ds2f~w2+o<*-m)+t^s0$`y zkGN^Z#|10po^aWYK%fC5DG7%&CfYY6TvM5YH2I9nHY{bjDEJoYTpJE$yD0sE%WXVd z2`{oH($6B8bx~vveT()&)EobwMx~#lse#W`lj>^BA{S;+DQRlWmnt9{Ygx6Nk1)o1 N`17riu>%}n>@TnYCZ_-Z diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f371643e..e750102e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 index 2fe81a7d..1b6c7873 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,78 +17,113 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +APP_BASE_NAME=${0##*/} # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -97,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + JAVACMD=java which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the @@ -105,79 +140,95 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=`expr $i + 1` - done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 9109989e..ac1b06f9 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if "%ERRORLEVEL%" == "0" goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -54,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -64,28 +64,14 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell From 39dda736af283f39659aa8785ba1c68f636ca75f Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 1 Dec 2021 04:58:13 +0100 Subject: [PATCH 28/96] Minor improvements --- src/main/java/ru/bclib/api/BiomeAPI.java | 11 ++++++++++ .../BiomeGenerationSettingsAccessor.java | 20 ------------------ .../common/FeatureDecoratorsAccessor.java | 9 -------- .../common/MobSpawnSettingsAccessor.java | 21 ------------------- 4 files changed, 11 insertions(+), 50 deletions(-) delete mode 100644 src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java delete mode 100644 src/main/java/ru/bclib/mixin/common/FeatureDecoratorsAccessor.java delete mode 100644 src/main/java/ru/bclib/mixin/common/MobSpawnSettingsAccessor.java diff --git a/src/main/java/ru/bclib/api/BiomeAPI.java b/src/main/java/ru/bclib/api/BiomeAPI.java index 982af38b..9b100b17 100644 --- a/src/main/java/ru/bclib/api/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/BiomeAPI.java @@ -419,6 +419,17 @@ public class BiomeAPI { }); } + /** + * Adds new features to existing biome. + * @param biome {@link Biome} to add features in. + * @param feature {@link ConfiguredFeature} to add. + * + */ + public static void addBiomeFeature(Biome biome, BCLFeature feature) { + addBiomeFeature(biome, feature.getPlacedFeature(), feature.getFeatureStep()); + } + + /** * Adds new features to existing biome. * @param biome {@link Biome} to add features in. diff --git a/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java b/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java deleted file mode 100644 index 9bdcd76c..00000000 --- a/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java +++ /dev/null @@ -1,20 +0,0 @@ -package ru.bclib.mixin.common; - -import net.minecraft.world.level.biome.BiomeGenerationSettings; -import net.minecraft.world.level.levelgen.placement.PlacedFeature; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.gen.Accessor; - -import java.util.List; -import java.util.function.Supplier; - -@Mixin(BiomeGenerationSettings.class) -public interface BiomeGenerationSettingsAccessor { - @Accessor("features") - List>> bcl_getFeatures(); - - @Accessor("features") - @Mutable - void bcl_setFeatures(List>> value); -} diff --git a/src/main/java/ru/bclib/mixin/common/FeatureDecoratorsAccessor.java b/src/main/java/ru/bclib/mixin/common/FeatureDecoratorsAccessor.java deleted file mode 100644 index e5bc92f3..00000000 --- a/src/main/java/ru/bclib/mixin/common/FeatureDecoratorsAccessor.java +++ /dev/null @@ -1,9 +0,0 @@ -package ru.bclib.mixin.common; - -import org.spongepowered.asm.mixin.Mixin; - -@Mixin(targets = "net.minecraft.data.worldgen.Features$Decorators") -public interface FeatureDecoratorsAccessor { - /*@Accessor("HEIGHTMAP_SQUARE") - ConfiguredDecorator bclib_getHeightmapSquare();*/ -} diff --git a/src/main/java/ru/bclib/mixin/common/MobSpawnSettingsAccessor.java b/src/main/java/ru/bclib/mixin/common/MobSpawnSettingsAccessor.java deleted file mode 100644 index e3491b73..00000000 --- a/src/main/java/ru/bclib/mixin/common/MobSpawnSettingsAccessor.java +++ /dev/null @@ -1,21 +0,0 @@ -package ru.bclib.mixin.common; - -import net.minecraft.util.random.WeightedRandomList; -import net.minecraft.world.entity.MobCategory; -import net.minecraft.world.level.biome.MobSpawnSettings; -import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -import org.spongepowered.asm.mixin.gen.Accessor; - -import java.util.Map; - -@Mixin(MobSpawnSettings.class) -public interface MobSpawnSettingsAccessor { - @Accessor("spawners") - Map> bcl_getSpawners(); - - @Accessor("spawners") - @Mutable - void bcl_setSpawners(Map> spawners); -} From 0b560b6dce846674b8c261b3bfbc474bba7fd219 Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 1 Dec 2021 05:08:57 +0100 Subject: [PATCH 29/96] Dependency and Version update --- gradle.properties | 2 +- src/main/resources/fabric.mod.json | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index 47e71b78..b83defa9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,7 +11,7 @@ loader_version= 0.12.6 fabric_version = 0.43.1+1.18 # Mod Properties -mod_version = 0.5.5 +mod_version = 1.0.0 maven_group = ru.bclib archives_base_name = bclib diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index b1298afc..4af9010c 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -33,9 +33,9 @@ "bclib.mixins.client.json" ], "depends": { - "fabricloader": ">=0.11.6", - "fabric": ">=0.41.0", - "minecraft": ">=1.17.1" + "fabricloader": ">=0.12.6", + "fabric": ">=0.43.0", + "minecraft": ">=1.18" }, "custom":{ "modmenu":{ From 3b672af0f82c44d138951747abf3b570e0ae326a Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 1 Dec 2021 05:19:31 +0100 Subject: [PATCH 30/96] Mixin Compat Level --- src/main/resources/bclib.mixins.client.json | 2 +- src/main/resources/bclib.mixins.common.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/bclib.mixins.client.json b/src/main/resources/bclib.mixins.client.json index 7c845a35..d8d18a6d 100644 --- a/src/main/resources/bclib.mixins.client.json +++ b/src/main/resources/bclib.mixins.client.json @@ -2,7 +2,7 @@ "required": true, "minVersion": "0.8", "package": "ru.bclib.mixin.client", - "compatibilityLevel": "JAVA_16", + "compatibilityLevel": "JAVA_17", "client": [ "AnvilScreenMixin", "BackgroundRendererMixin", diff --git a/src/main/resources/bclib.mixins.common.json b/src/main/resources/bclib.mixins.common.json index b2bdd97c..a2ac975c 100644 --- a/src/main/resources/bclib.mixins.common.json +++ b/src/main/resources/bclib.mixins.common.json @@ -2,7 +2,7 @@ "required": true, "minVersion": "0.8", "package": "ru.bclib.mixin.common", - "compatibilityLevel": "JAVA_16", + "compatibilityLevel": "JAVA_17", "mixins": [ "AnvilBlockMixin", "AnvilMenuMixin", From 7a073c651955d7f1b2aefc0f810a26a4c1e56954 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Wed, 1 Dec 2021 07:41:46 +0300 Subject: [PATCH 31/96] Biome API cleanup (removed reduntant functions, style changes, imports cleanup) --- README.md | 2 +- src/main/java/ru/bclib/api/BiomeAPI.java | 96 +++--------------------- 2 files changed, 10 insertions(+), 88 deletions(-) diff --git a/README.md b/README.md index 0521236a..7310d2e9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![](https://jitpack.io/v/paulevsGitch/BCLib.svg)](https://jitpack.io/#paulevsGitch/BCLib) # BCLib -BCLib is a library mod for BetterX team mods, developed for Fabric, MC 1.17.1 +BCLib is a library mod for BetterX team mods, developed for Fabric, MC 1.18 ## Features: ### Rendering diff --git a/src/main/java/ru/bclib/api/BiomeAPI.java b/src/main/java/ru/bclib/api/BiomeAPI.java index 9b100b17..4b3bf80c 100644 --- a/src/main/java/ru/bclib/api/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/BiomeAPI.java @@ -1,6 +1,5 @@ package ru.bclib.api; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; @@ -35,14 +34,11 @@ import ru.bclib.world.features.BCLFeature; import ru.bclib.world.generator.BiomePicker; import ru.bclib.world.structures.BCLStructureFeature; -import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Random; import java.util.Set; import java.util.function.BiConsumer; -import java.util.function.Supplier; public class BiomeAPI { /** @@ -428,8 +424,7 @@ public class BiomeAPI { public static void addBiomeFeature(Biome biome, BCLFeature feature) { addBiomeFeature(biome, feature.getPlacedFeature(), feature.getFeatureStep()); } - - + /** * Adds new features to existing biome. * @param biome {@link Biome} to add features in. @@ -437,18 +432,9 @@ public class BiomeAPI { * @param step a {@link Decoration} step for the feature. */ public static void addBiomeFeature(Biome biome, PlacedFeature feature, Decoration step) { - BuiltinRegistries.PLACED_FEATURE.getResourceKey(feature) - .ifPresent((key)-> - BiomeModifications.addFeature( - (ctx)->ctx.getBiomeKey().equals(BuiltinRegistries.BIOME.getKey(biome)), - step, - key - )); -// BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings(); -// List>> biomeFeatures = getMutableList(accessor.bcl_getFeatures()); -// List> list = getList(step, biomeFeatures); -// list.add(() -> feature); -// accessor.bcl_setFeatures(biomeFeatures); + BuiltinRegistries.PLACED_FEATURE + .getResourceKey(feature) + .ifPresent(key -> BiomeModifications.addFeature(ctx -> ctx.getBiomeKey().equals(BuiltinRegistries.BIOME.getKey(biome)), step, key)); } /** @@ -460,31 +446,6 @@ public class BiomeAPI { for (BCLFeature feature: features) { addBiomeFeature(biome, feature.getPlacedFeature(), feature.getFeatureStep()); } -// BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings(); -// List>> biomeFeatures = getMutableList(accessor.bcl_getFeatures()); -// for (BCLFeature feature: features) { -// List> list = getList(feature.getFeatureStep(), biomeFeatures); -// list.add(feature::getPlacedFeature); -// } -// accessor.bcl_setFeatures(biomeFeatures); - } - - /** - * Getter for correct feature list from all biome feature list of lists. - * @param step feature {@link Decoration} step. - * @param lists biome accessor lists. - * @return mutable {@link ConfiguredFeature} list. - */ - private static List> getList(Decoration step, List>> lists) { - int index = step.ordinal(); - if (lists.size() <= index) { - for (int i = lists.size(); i <= index; i++) { - lists.add(Lists.newArrayList()); - } - } - List> list = getMutableList(lists.get(index)); - lists.set(index, list); - return list; } // TODO: 1.18 There are no more StructureFeatures in the Biomes, they are in a separate registry now @@ -494,16 +455,9 @@ public class BiomeAPI { * @param structure {@link ConfiguredStructureFeature} to add. */ public static void addBiomeStructure(Biome biome, ConfiguredStructureFeature structure) { - BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE.getResourceKey(structure) - .ifPresent((key)-> - BiomeModifications.addStructure( - (ctx)->ctx.getBiomeKey().equals(BuiltinRegistries.BIOME.getKey(biome)), - key - )); -// BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings(); -// List>> biomeStructures = getMutableList(accessor.fabric_getStructureFeatures()); -// biomeStructures.add(() -> structure); -// accessor.fabric_setStructureFeatures(biomeStructures); + BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE + .getResourceKey(structure) + .ifPresent(key -> BiomeModifications.addStructure(ctx -> ctx.getBiomeKey().equals(BuiltinRegistries.BIOME.getKey(biome)), key)); } /** @@ -515,12 +469,6 @@ public class BiomeAPI { for (BCLStructureFeature structure: structures) { addBiomeStructure(biome, structure.getFeatureConfigured()); } -// GenerationSettingsAccessor accessor = (GenerationSettingsAccessor) biome.getGenerationSettings(); -// List>> biomeStructures = getMutableList(accessor.fabric_getStructureFeatures()); -// for (BCLStructureFeature structure: structures) { -// biomeStructures.add(structure::getFeatureConfigured); -// } -// accessor.fabric_setStructureFeatures(biomeStructures); } /** @@ -532,40 +480,14 @@ public class BiomeAPI { * @param maxGroupCount maximum mobs in group. */ public static void addBiomeMobSpawn(Biome biome, EntityType entityType, int weight, int minGroupCount, int maxGroupCount) { + ResourceLocation biomeKey = BuiltinRegistries.BIOME.getKey(biome); BiomeModifications.addSpawn( - (ctx)->ctx.getBiomeKey().equals(BuiltinRegistries.BIOME.getKey(biome)), + ctx -> ctx.getBiomeKey().equals(biomeKey), entityType.getCategory(), entityType, weight, minGroupCount, maxGroupCount ); -// MobCategory category = entityType.getCategory(); -// MobSpawnSettingsAccessor accessor = (MobSpawnSettingsAccessor) biome.getMobSettings(); -// Map> spawners = getMutableMap(accessor.bcl_getSpawners()); -// List mobs = spawners.containsKey(category) ? getMutableList(spawners.get(category).unwrap()) : Lists.newArrayList(); -// mobs.add(new SpawnerData(entityType, weight, minGroupCount, maxGroupCount)); -// spawners.put(category, WeightedRandomList.create(mobs)); -// accessor.bcl_setSpawners(spawners); - } - - private static List getMutableList(List input) { - if (input!=null) { - System.out.println("getMutableList: " + input.getClass().getName()); - for (Class cl : input.getClass().getInterfaces()){ - System.out.println(" - " + cl.getName()); - } - } - if (/*input instanceof ImmutableList ||*/ !(input instanceof ArrayList || input instanceof LinkedList)) { - return Lists.newArrayList(input); - } - return input; - } - - private static Map getMutableMap(Map input) { - if (input instanceof ImmutableMap) { - return Maps.newHashMap(input); - } - return input; } } From 97ba6b4df146b74d15bfaa20039d29a3f3f93497 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Wed, 1 Dec 2021 07:51:03 +0300 Subject: [PATCH 32/96] BCL Biome terrain height (for the End terrain generator) --- .../java/ru/bclib/world/biomes/BCLBiome.java | 21 ++++++++++++------- .../ru/bclib/world/biomes/BCLBiomeDef.java | 10 ++++++--- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiome.java b/src/main/java/ru/bclib/world/biomes/BCLBiome.java index bf86b175..b1bce5f5 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiome.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiome.java @@ -24,19 +24,20 @@ import java.util.Map; import java.util.Random; public class BCLBiome { - protected WeightedList subbiomes = new WeightedList(); + protected WeightedList subbiomes = new WeightedList<>(); - protected final Biome biome; protected final ResourceLocation mcID; - protected BCLBiome edge; - protected int edgeSize; - - protected BCLBiome biomeParent; - protected float maxSubBiomeChance = 1; + protected final float terrainHeight; protected final float genChance; + protected final Biome biome; private final Map customData; private final float fogDensity; + + protected BCLBiome biomeParent; + protected BCLBiome edge; + protected int edgeSize; + private BCLFeature structuresFeature; private Biome actualBiome; @@ -51,6 +52,7 @@ public class BCLBiome { this.genChance = definition.getGenChance(); this.fogDensity = definition.getFodDensity(); this.customData = definition.getCustomData(); + this.terrainHeight = definition.getTerrainHeight(); subbiomes.add(this, 1); } @@ -68,6 +70,7 @@ public class BCLBiome { } this.readStructureList(); this.customData = Maps.newHashMap(); + this.terrainHeight = 0.1F; subbiomes.add(this, 1); } @@ -210,4 +213,8 @@ public class BCLBiome { public void addCustomData(String name, Object obj) { customData.put(name, obj); } + + public float getTerrainHeight() { + return terrainHeight; + } } diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java index ac8731ae..9147f52f 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java @@ -63,7 +63,7 @@ public class BCLBiomeDef { private int fogColor = 10518688; private int skyColor = 0; private float fogDensity = 1F; - private float depth = 0.1F; + private float terrainHeight = 0.1F; private Precipitation precipitation = Precipitation.NONE; private BiomeCategory category = BiomeCategory.NONE; @@ -165,8 +165,8 @@ public class BCLBiomeDef { return this; } - public BCLBiomeDef setDepth(float depth) { - this.depth = depth; + public BCLBiomeDef setTerrainHeight(float terrainHeight) { + this.terrainHeight = terrainHeight; return this; } @@ -361,6 +361,10 @@ public class BCLBiomeDef { .build(); } + public float getTerrainHeight() { + return terrainHeight; + } + private static final class SpawnInfo { EntityType type; int weight; From 48f4b69a98ad8e74a68e67d97e8d3bff199c8c22 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Wed, 1 Dec 2021 08:37:30 +0300 Subject: [PATCH 33/96] BCL Biome cahnges, biome builder (WIP) --- .../java/ru/bclib/world/biomes/BCLBiome.java | 251 +++++++++++------- .../bclib/world/biomes/BCLBiomeBuilder.java | 28 ++ .../ru/bclib/world/biomes/BCLBiomeDef.java | 1 + 3 files changed, 178 insertions(+), 102 deletions(-) create mode 100644 src/main/java/ru/bclib/world/biomes/BCLBiomeBuilder.java diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiome.java b/src/main/java/ru/bclib/world/biomes/BCLBiome.java index b1bce5f5..00db3a40 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiome.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiome.java @@ -9,6 +9,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biomes; import net.minecraft.world.level.levelgen.GenerationStep.Decoration; +import org.jetbrains.annotations.Nullable; import ru.bclib.config.Configs; import ru.bclib.util.JsonFactory; import ru.bclib.util.StructureHelper; @@ -24,161 +25,168 @@ import java.util.Map; import java.util.Random; public class BCLBiome { - protected WeightedList subbiomes = new WeightedList<>(); + private final WeightedList subbiomes = new WeightedList<>(); + private final Map customData = Maps.newHashMap(); + private final ResourceLocation biomeID; + private final Biome biome; - protected final ResourceLocation mcID; - protected final float terrainHeight; - protected final float genChance; - protected final Biome biome; - - private final Map customData; - private final float fogDensity; - - protected BCLBiome biomeParent; - protected BCLBiome edge; - protected int edgeSize; - - private BCLFeature structuresFeature; + private BCLBiome biomeParent; private Biome actualBiome; + private BCLBiome edge; - public BCLBiome(BCLBiomeDef definition) { - definition.loadConfigValues(Configs.BIOMES_CONFIG); - this.mcID = definition.getID(); - this.readStructureList(); - if (structuresFeature != null) { - definition.addFeature(structuresFeature); - } - this.biome = definition.build(); - this.genChance = definition.getGenChance(); - this.fogDensity = definition.getFodDensity(); - this.customData = definition.getCustomData(); - this.terrainHeight = definition.getTerrainHeight(); - subbiomes.add(this, 1); - } + private float terrainHeight = 0.1F; + private float fogDensity = 1.0F; + private float genChance = 1.0F; + private float edgeSize = 0.0F; - public BCLBiome(ResourceLocation id, Biome biome, float fogDensity, float genChance) { - this.mcID = id; + public BCLBiome(ResourceLocation biomeID, Biome biome) { + this.biomeID = biomeID; this.biome = biome; - if (id.equals(Biomes.THE_VOID.location())) { - this.genChance = fogDensity; - this.fogDensity = genChance; - } - else { - String biomePath = id.getNamespace() + "." + id.getPath(); - this.genChance = Configs.BIOMES_CONFIG.getFloat(biomePath, "generation_chance", genChance); - this.fogDensity = Configs.BIOMES_CONFIG.getFloat(biomePath, "fog_density", fogDensity); - } - this.readStructureList(); - this.customData = Maps.newHashMap(); - this.terrainHeight = 0.1F; - subbiomes.add(this, 1); } + /** + * Get current bime edge. + * @return {@link BCLBiome} edge. + */ + @Nullable public BCLBiome getEdge() { - return edge == null ? this : edge; + return edge; } + /** + * Set biome edge for this biome instance. + * @param edge {@link BCLBiome} as the edge biome. + */ public void setEdge(BCLBiome edge) { this.edge = edge; edge.biomeParent = this; } - public int getEdgeSize() { + /** + * Getter for biome edge size. + * @return edge size. + */ + public float getEdgeSize() { return edgeSize; } - public void setEdgeSize(int size) { + /** + * Set edges size for this biome. Size is in relative units to work fine with biome scale. + * @param size as a float value. + */ + public void setEdgeSize(float size) { edgeSize = size; } + /** + * Adds sub-biome into this biome instance. Biome chance will be interpreted as a sub-biome generation chance. + * Biome itself has chance 1.0 compared to all its sub-biomes. + * @param biome {@link Random} to be added. + */ public void addSubBiome(BCLBiome biome) { biome.biomeParent = this; subbiomes.add(biome, biome.getGenChance()); } + /** + * Checks if specified biome is a sub-biome of this one. + * @param biome {@link Random}. + * @return true if this instance contains specified biome as a sub-biome. + */ public boolean containsSubBiome(BCLBiome biome) { return subbiomes.contains(biome); } + /** + * Getter for a random sub-biome from all existing sub-biomes. Will return biome itself if there are no sub-biomes. + * @param random {@link Random}. + * @return {@link BCLBiome}. + */ public BCLBiome getSubBiome(Random random) { return subbiomes.get(random); } + /** + * Getter for parent {@link BCLBiome} or null if there are no parent biome. + * @return {@link BCLBiome} or null. + */ + @Nullable public BCLBiome getParentBiome() { return this.biomeParent; } + /** + * Checks if this biome has edge biome. + * @return true if it has edge. + */ + @Deprecated(forRemoval = true) public boolean hasEdge() { return edge != null; } + /** + * Checks if this biome has parent biome. + * @return true if it has parent. + */ + @Deprecated(forRemoval = true) public boolean hasParentBiome() { return biomeParent != null; } + /** + * Compares biome instances (directly) and their parents. Used in custom world generator. + * @param biome {@link BCLBiome} + * @return true if biome or its parent is same. + */ + @Deprecated(forRemoval = true) public boolean isSame(BCLBiome biome) { return biome == this || (biome.hasParentBiome() && biome.getParentBiome() == this); } - public Biome getBiome() { - return biome; - } - - @Override - public String toString() { - return mcID.toString(); - } - + /** + * Getter for biome identifier. + * @return {@link ResourceLocation} + */ public ResourceLocation getID() { - return mcID; + return biomeID; } + /** + * Getter for fog density, used in custom for renderer. + * @return fog density as a float. + */ public float getFogDensity() { return fogDensity; } - protected void readStructureList() { - String ns = mcID.getNamespace(); - String nm = mcID.getPath(); - - String path = "/data/" + ns + "/structures/biome/" + nm + "/"; - InputStream inputstream = StructureHelper.class.getResourceAsStream(path + "structures.json"); - if (inputstream != null) { - JsonObject obj = JsonFactory.getJsonObject(inputstream); - JsonArray enties = obj.getAsJsonArray("structures"); - if (enties != null) { - List list = Lists.newArrayList(); - enties.forEach((entry) -> { - JsonObject e = entry.getAsJsonObject(); - String structure = path + e.get("nbt").getAsString() + ".nbt"; - TerrainMerge terrainMerge = TerrainMerge.getFromString(e.get("terrainMerge").getAsString()); - int offsetY = e.get("offsetY").getAsInt(); - list.add(new StructureInfo(structure, offsetY, terrainMerge)); - }); - if (!list.isEmpty()) { - structuresFeature = BCLFeature.makeChancedFeature( - new ResourceLocation(ns, nm + "_structures"), - Decoration.SURFACE_STRUCTURES, - new ListFeature(list), - 10 - ); - } - } - } - } - - public BCLFeature getStructuresFeature() { - return structuresFeature; + /** + * Getter for biome from buil-in registry. For datapack biomes will be same as actual biome. + * @return {@link Biome}. + */ + public Biome getBiome() { + return biome; } + /** + * Getter for actual biome (biome from current world registry with same {@link ResourceLocation} id). + * @return {@link Biome}. + */ public Biome getActualBiome() { return this.actualBiome; } + /** + * Getter for biome generation chance, used in {@link ru.bclib.world.generator.BiomePicker} and in custom generators. + * @return biome generation chance as float. + */ public float getGenChance() { return this.genChance; } + /** + * Recursively update biomes to correct world biome registry instances, for internal usage only. + * @param biomeRegistry {@link Registry} for {@link Biome}. + */ public void updateActualBiomes(Registry biomeRegistry) { subbiomes.forEach((sub) -> { if (sub != this) { @@ -188,7 +196,54 @@ public class BCLBiome { if (edge != null && edge != this) { edge.updateActualBiomes(biomeRegistry); } - this.actualBiome = biomeRegistry.get(mcID); + this.actualBiome = biomeRegistry.get(biomeID); + } + + /** + * Getter for custom data. Will get custom data object or null if object doesn't exists. + * @param name {@link String} name of data object. + * @return object value or null. + */ + @Nullable + @SuppressWarnings("unchecked") + public T getCustomData(String name) { + return (T) customData.get(name); + } + + /** + * Getter for custom data. Will get custom data object or default value if object doesn't exists. + * @param name {@link String} name of data object. + * @param defaultValue object default value. + * @return object value or default value. + */ + @SuppressWarnings("unchecked") + public T getCustomData(String name, T defaultValue) { + return (T) customData.getOrDefault(name, defaultValue); + } + + /** + * Adds custom data object to this biome instance. + * @param name {@link String} name of data object. + * @param obj any data to add. + */ + public void addCustomData(String name, Object obj) { + customData.put(name, obj); + } + + /** + * Adds custom data object to this biome instance. + * @param data a {@link Map} with custom data. + */ + public void addCustomData(Map data) { + customData.putAll(data); + } + + /** + * Getter for terrain height, can be used in custom terrain generator. + * @return terrain height. + */ + public float getTerrainHeight() { + return terrainHeight; } @Override @@ -197,24 +252,16 @@ public class BCLBiome { return true; } BCLBiome biome = (BCLBiome) obj; - return biome == null ? false : biome.mcID.equals(mcID); + return biome == null ? false : biomeID.equals(biome.biomeID); } @Override public int hashCode() { - return mcID.hashCode(); + return biomeID.hashCode(); } - @SuppressWarnings("unchecked") - public T getCustomData(String name, T defaultValue) { - return (T) customData.getOrDefault(name, defaultValue); - } - - public void addCustomData(String name, Object obj) { - customData.put(name, obj); - } - - public float getTerrainHeight() { - return terrainHeight; + @Override + public String toString() { + return biomeID.toString(); } } diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/world/biomes/BCLBiomeBuilder.java new file mode 100644 index 00000000..33604824 --- /dev/null +++ b/src/main/java/ru/bclib/world/biomes/BCLBiomeBuilder.java @@ -0,0 +1,28 @@ +package ru.bclib.world.biomes; + +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.biome.Biome; + +public class BCLBiomeBuilder { + private static final BCLBiomeBuilder INSTANCE = new BCLBiomeBuilder(); + + private ResourceLocation biomeID; + + public static BCLBiomeBuilder start(ResourceLocation biomeID) { + INSTANCE.biomeID = biomeID; + return INSTANCE; + } + + public BCLBiome build() { + Biome biome = new Biome.BiomeBuilder() + /*.precipitation(precipitation) + .biomeCategory(category) + .temperature(temperature) + .downfall(downfall) + .specialEffects(effects.build()) + .mobSpawnSettings(spawnSettings.build()) + .generationSettings(generationSettings.build())*/ + .build(); + return new BCLBiome(biomeID, biome); + } +} diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java index 9147f52f..16d7313b 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java @@ -36,6 +36,7 @@ import ru.bclib.world.structures.BCLStructureFeature; import java.util.List; import java.util.Map; +@Deprecated(forRemoval = true) public class BCLBiomeDef { public static final int DEF_FOLIAGE_OVERWORLD = ColorUtil.color(110, 143, 64); public static final int DEF_FOLIAGE_NETHER = ColorUtil.color(117, 10, 10); From 161c5ef1f317793385caf28f91e53bc4a6ddd46b Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 1 Dec 2021 07:57:21 +0100 Subject: [PATCH 34/96] Make sure Nether Cities are placed --- src/main/java/ru/bclib/api/BiomeAPI.java | 3 ++- src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/bclib/api/BiomeAPI.java b/src/main/java/ru/bclib/api/BiomeAPI.java index 9b100b17..3e032f24 100644 --- a/src/main/java/ru/bclib/api/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/BiomeAPI.java @@ -497,7 +497,8 @@ public class BiomeAPI { BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE.getResourceKey(structure) .ifPresent((key)-> BiomeModifications.addStructure( - (ctx)->ctx.getBiomeKey().equals(BuiltinRegistries.BIOME.getKey(biome)), + (ctx)-> ctx.getBiomeKey().location() + .equals(BuiltinRegistries.BIOME.getKey(biome)), key )); // BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings(); diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java index ac8731ae..ccb062ed 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java @@ -27,6 +27,7 @@ import net.minecraft.world.level.levelgen.carver.CarverConfiguration; import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import net.minecraft.world.level.levelgen.placement.PlacedFeature; +import ru.bclib.api.BiomeAPI; import ru.bclib.config.IdConfig; import ru.bclib.config.PathConfig; import ru.bclib.util.ColorUtil; @@ -348,7 +349,7 @@ public class BCLBiomeDef { if (particleConfig != null) effects.ambientParticle(particleConfig); effects.backgroundMusic(music != null ? new Music(music, 600, 2400, true) : Musics.END); - return new Biome.BiomeBuilder() + Biome b = new Biome.BiomeBuilder() .precipitation(precipitation) .biomeCategory(category) //.depth(depth) @@ -359,6 +360,9 @@ public class BCLBiomeDef { .mobSpawnSettings(spawnSettings.build()) .generationSettings(generationSettings.build()) .build(); + + structures.forEach((structure) -> BiomeAPI.addBiomeStructure(b, structure)); + return b; } private static final class SpawnInfo { From e7b66af02e235f96c9f51a1bfc945deb8862eb6d Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 1 Dec 2021 08:31:22 +0100 Subject: [PATCH 35/96] Added missing TODOs --- src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java index ccb062ed..e4f517be 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java @@ -147,12 +147,12 @@ public class BCLBiomeDef { } public BCLBiomeDef setSurface(Block block) { - + //TODO: 1.18 add back surface Code return this; } public BCLBiomeDef setSurface(Block block1, Block block2) { - + //TODO: 1.18 add back surface Code return this; } From 1365339c1ef7eebbab67c9ae719dc5a8cd1e7247 Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 1 Dec 2021 08:53:14 +0100 Subject: [PATCH 36/96] Allow usage of BCLStructureFeature to add Structures --- src/main/java/ru/bclib/api/BiomeAPI.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/ru/bclib/api/BiomeAPI.java b/src/main/java/ru/bclib/api/BiomeAPI.java index 3e032f24..5f255b74 100644 --- a/src/main/java/ru/bclib/api/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/BiomeAPI.java @@ -497,14 +497,17 @@ public class BiomeAPI { BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE.getResourceKey(structure) .ifPresent((key)-> BiomeModifications.addStructure( - (ctx)-> ctx.getBiomeKey().location() - .equals(BuiltinRegistries.BIOME.getKey(biome)), + (ctx)-> ctx.getBiomeKey().location().equals(BuiltinRegistries.BIOME.getKey(biome)), key )); -// BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings(); -// List>> biomeStructures = getMutableList(accessor.fabric_getStructureFeatures()); -// biomeStructures.add(() -> structure); -// accessor.fabric_setStructureFeatures(biomeStructures); + } + /** + * Adds new structure feature to existing biome. + * @param biome {@link Biome} to add structure feature in. + * @param structure {@link BCLStructureFeature} to add. + */ + public static void addBiomeStructure(Biome biome, BCLStructureFeature structure) { + addBiomeStructure(biome, structure.getFeatureConfigured()); } /** From 86dd202ca42e5faa50c0067a3179c90b67389510 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Wed, 1 Dec 2021 11:15:34 +0300 Subject: [PATCH 37/96] More biome builder functions --- .../bclib/world/biomes/BCLBiomeBuilder.java | 57 ++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/world/biomes/BCLBiomeBuilder.java index 33604824..f9659e69 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiomeBuilder.java @@ -2,23 +2,78 @@ package ru.bclib.world.biomes; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.Biome.BiomeCategory; +import net.minecraft.world.level.biome.Biome.Precipitation; public class BCLBiomeBuilder { private static final BCLBiomeBuilder INSTANCE = new BCLBiomeBuilder(); + private Precipitation precipitation; private ResourceLocation biomeID; + private BiomeCategory category; + private float temperature; + private float downfall; + /** + * Starts new biome building process. + * @param biomeID {@link ResourceLocation} biome identifier. + * @return prepared {@link BCLBiomeBuilder} instance. + */ public static BCLBiomeBuilder start(ResourceLocation biomeID) { INSTANCE.biomeID = biomeID; + INSTANCE.precipitation = Precipitation.NONE; + INSTANCE.category = BiomeCategory.NONE; + INSTANCE.temperature = 1.0F; return INSTANCE; } + /** + * Set biome {@link Precipitation}. Affect biome visual effects (rain, snow, none). + * @param precipitation {@link Precipitation} + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder precipitation(Precipitation precipitation) { + this.precipitation = precipitation; + return this; + } + + /** + * Set biome category. Doesn't affect biome worldgen, but Fabric biome modifications can target biome by it. + * @param category {@link BiomeCategory} + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder category(BiomeCategory category) { + this.category = category; + return this; + } + + /** + * Set biome temperature, affect plant color, biome generation and ice formation. + * @param temperature biome temperature. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder temperature(float temperature) { + this.temperature = temperature; + return this; + } + + /** + * Set biome wetness (same as downfall). Affect plant color and biome generation. + * @param wetness biome wetness (downfall). + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder wetness(float wetness) { + this.downfall = wetness; + return this; + } + public BCLBiome build() { Biome biome = new Biome.BiomeBuilder() - /*.precipitation(precipitation) + .precipitation(precipitation) .biomeCategory(category) .temperature(temperature) .downfall(downfall) + /* .specialEffects(effects.build()) .mobSpawnSettings(spawnSettings.build()) .generationSettings(generationSettings.build())*/ From e1e09c4efa94842a6acd066c2b99d57843a6da4e Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Wed, 1 Dec 2021 12:31:25 +0300 Subject: [PATCH 38/96] More biome API changes --- src/main/java/ru/bclib/api/BiomeAPI.java | 49 ++++------- .../ru/bclib/gui/gridlayout/GridScreen.java | 1 - .../bclib/mixin/common/ServerLevelMixin.java | 8 +- .../java/ru/bclib/world/biomes/BCLBiome.java | 82 ++++++++++--------- .../bclib/world/biomes/BCLBiomeBuilder.java | 55 +++++++++++-- .../world/generator/BCLibEndBiomeSource.java | 6 +- .../generator/BCLibNetherBiomeSource.java | 6 +- .../ru/bclib/world/generator/BiomeMap.java | 4 +- 8 files changed, 121 insertions(+), 90 deletions(-) diff --git a/src/main/java/ru/bclib/api/BiomeAPI.java b/src/main/java/ru/bclib/api/BiomeAPI.java index 5c664ce0..3950f754 100644 --- a/src/main/java/ru/bclib/api/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/BiomeAPI.java @@ -45,7 +45,7 @@ public class BiomeAPI { * Empty biome used as default value if requested biome doesn't exist or linked. Shouldn't be registered anywhere to prevent bugs. * Have {@code Biomes.THE_VOID} as the reference biome. */ - public static final BCLBiome EMPTY_BIOME = new BCLBiome(Biomes.THE_VOID.location(), BuiltinRegistries.BIOME.get(Biomes.THE_VOID), 1, 0); + public static final BCLBiome EMPTY_BIOME = new BCLBiome(Biomes.THE_VOID.location()); public static final BiomePicker NETHER_BIOME_PICKER = new BiomePicker(); public static final BiomePicker END_LAND_BIOME_PICKER = new BiomePicker(); @@ -100,9 +100,8 @@ public class BiomeAPI { return subBiome; } - public static BCLBiome registerSubBiome(BCLBiome parent, Biome biome, float chance) { - ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome).get(); - BCLBiome subBiome = new BCLBiome(key.location(), biome, 1, chance); + public static BCLBiome registerSubBiome(BCLBiome parent, Biome biome, float genChance) { + BCLBiome subBiome = new BCLBiome(biome).setGenChance(genChance); return registerSubBiome(parent, subBiome); } @@ -122,8 +121,8 @@ public class BiomeAPI { Climate.ParameterPoint parameters = Climate.parameters( MHelper.randRange(-1.5F, 1.5F, random), MHelper.randRange(-1.5F, 1.5F, random), - 0.0f, //new in 1.18 - 0.0f, //new in 1.18 + MHelper.randRange(-1.5F, 1.5F, random), //new in 1.18 + MHelper.randRange(-1.5F, 1.5F, random), //new in 1.18 MHelper.randRange(-1.5F, 1.5F, random), MHelper.randRange(-1.5F, 1.5F, random), random.nextFloat() @@ -140,8 +139,7 @@ public class BiomeAPI { * @return {@link BCLBiome} */ public static BCLBiome registerNetherBiome(Biome biome) { - ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome).get(); - BCLBiome bclBiome = new BCLBiome(key.location(), biome, 1, 1); + BCLBiome bclBiome = new BCLBiome(biome); NETHER_BIOME_PICKER.addBiome(bclBiome); registerBiome(bclBiome); return bclBiome; @@ -170,8 +168,7 @@ public class BiomeAPI { * @return {@link BCLBiome} */ public static BCLBiome registerEndLandBiome(Biome biome) { - ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome).get(); - BCLBiome bclBiome = new BCLBiome(key.location(), biome, 1, 1); + BCLBiome bclBiome = new BCLBiome(biome); END_LAND_BIOME_PICKER.addBiome(bclBiome); registerBiome(bclBiome); return bclBiome; @@ -181,12 +178,11 @@ public class BiomeAPI { * Register {@link BCLBiome} wrapper for {@link Biome}. * After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a land biome (will generate only on islands). * @param biome {@link BCLBiome}; - * @param weight float generation chance. + * @param genChance float generation chance. * @return {@link BCLBiome} */ - public static BCLBiome registerEndLandBiome(Biome biome, float weight) { - ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome).get(); - BCLBiome bclBiome = new BCLBiome(key.location(), biome, 1, weight); + public static BCLBiome registerEndLandBiome(Biome biome, float genChance) { + BCLBiome bclBiome = new BCLBiome(biome).setGenChance(genChance); END_LAND_BIOME_PICKER.addBiome(bclBiome); registerBiome(bclBiome); return bclBiome; @@ -214,8 +210,7 @@ public class BiomeAPI { * @return {@link BCLBiome} */ public static BCLBiome registerEndVoidBiome(Biome biome) { - ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome).get(); - BCLBiome bclBiome = new BCLBiome(key.location(), biome, 1, 1); + BCLBiome bclBiome = new BCLBiome(biome); END_VOID_BIOME_PICKER.addBiome(bclBiome); registerBiome(bclBiome); return bclBiome; @@ -224,13 +219,13 @@ public class BiomeAPI { /** * Register {@link BCLBiome} instance and its {@link Biome} if necessary. * After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a void biome (will generate only in the End void - between islands). - * @param biome {@link BCLBiome}; - * @param weight float generation chance. + * @param biome {@link BCLBiome}. + * @param genChance float generation chance. * @return {@link BCLBiome} */ - public static BCLBiome registerEndVoidBiome(Biome biome, float weight) { + public static BCLBiome registerEndVoidBiome(Biome biome, float genChance) { ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome).get(); - BCLBiome bclBiome = new BCLBiome(key.location(), biome, 1, weight); + BCLBiome bclBiome = new BCLBiome(biome).setGenChance(genChance); END_VOID_BIOME_PICKER.addBiome(bclBiome); registerBiome(bclBiome); return bclBiome; @@ -238,7 +233,6 @@ public class BiomeAPI { /** * Get {@link BCLBiome} from {@link Biome} instance on server. Used to convert world biomes to BCLBiomes. - * * @param biome - {@link Biome} from world. * @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}. */ @@ -251,7 +245,6 @@ public class BiomeAPI { /** * Get {@link BCLBiome} from biome on client. Used in fog rendering. - * * @param biome - {@link Biome} from client world. * @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}. */ @@ -269,7 +262,6 @@ public class BiomeAPI { /** * Get biome {@link ResourceLocation} from given {@link Biome}. - * * @param biome - {@link Biome} from server world. * @return biome {@link ResourceLocation}. */ @@ -280,7 +272,6 @@ public class BiomeAPI { /** * Get {@link BCLBiome} from given {@link ResourceLocation}. - * * @param biomeID - biome {@link ResourceLocation}. * @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}. */ @@ -290,7 +281,6 @@ public class BiomeAPI { /** * Check if biome with {@link ResourceLocation} exists in API registry. - * * @param biomeID - biome {@link ResourceLocation}. * @return {@code true} if biome exists in API registry and {@code false} if not. */ @@ -455,12 +445,9 @@ public class BiomeAPI { * @param structure {@link ConfiguredStructureFeature} to add. */ public static void addBiomeStructure(Biome biome, ConfiguredStructureFeature structure) { - BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE.getResourceKey(structure) - .ifPresent((key)-> - BiomeModifications.addStructure( - (ctx)-> ctx.getBiomeKey().location().equals(BuiltinRegistries.BIOME.getKey(biome)), - key - )); + BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE + .getResourceKey(structure) + .ifPresent(key -> BiomeModifications.addStructure(ctx -> ctx.getBiomeKey().location().equals(BuiltinRegistries.BIOME.getKey(biome)), key)); } /** * Adds new structure feature to existing biome. diff --git a/src/main/java/ru/bclib/gui/gridlayout/GridScreen.java b/src/main/java/ru/bclib/gui/gridlayout/GridScreen.java index 3d21990e..663ca0dd 100644 --- a/src/main/java/ru/bclib/gui/gridlayout/GridScreen.java +++ b/src/main/java/ru/bclib/gui/gridlayout/GridScreen.java @@ -18,7 +18,6 @@ import net.minecraft.network.chat.Component; import net.minecraft.util.Mth; import org.jetbrains.annotations.Nullable; import ru.bclib.gui.gridlayout.GridLayout.Alignment; -import ru.bclib.util.Pair; @Environment(EnvType.CLIENT) diff --git a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java index 91c2c4d2..b9ae402c 100644 --- a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java +++ b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java @@ -1,9 +1,5 @@ package ru.bclib.mixin.common; -import java.util.List; -import java.util.concurrent.Executor; -import java.util.function.Supplier; - import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; @@ -23,6 +19,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import ru.bclib.api.BiomeAPI; import ru.bclib.api.LifeCycleAPI; +import java.util.List; +import java.util.concurrent.Executor; +import java.util.function.Supplier; + @Mixin(ServerLevel.class) public abstract class ServerLevelMixin extends Level { private static String bclib_lastWorld = null; diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiome.java b/src/main/java/ru/bclib/world/biomes/BCLBiome.java index 00db3a40..39c851a9 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiome.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiome.java @@ -1,26 +1,13 @@ package ru.bclib.world.biomes; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; import net.minecraft.core.Registry; +import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.Biomes; -import net.minecraft.world.level.levelgen.GenerationStep.Decoration; import org.jetbrains.annotations.Nullable; -import ru.bclib.config.Configs; -import ru.bclib.util.JsonFactory; -import ru.bclib.util.StructureHelper; import ru.bclib.util.WeightedList; -import ru.bclib.world.features.BCLFeature; -import ru.bclib.world.features.ListFeature; -import ru.bclib.world.features.ListFeature.StructureInfo; -import ru.bclib.world.features.NBTStructureFeature.TerrainMerge; -import java.io.InputStream; -import java.util.List; import java.util.Map; import java.util.Random; @@ -39,6 +26,22 @@ public class BCLBiome { private float genChance = 1.0F; private float edgeSize = 0.0F; + /** + * Create wrapper for existing biome using its {@link ResourceLocation} identifier. + * @param biomeID {@link ResourceLocation} biome ID. + */ + public BCLBiome(ResourceLocation biomeID) { + this(biomeID, BuiltinRegistries.BIOME.get(biomeID)); + } + + /** + * Create wrapper for existing biome using biome instance from {@link BuiltinRegistries}. + * @param biome {@link Biome} to wrap. + */ + public BCLBiome(Biome biome) { + this(BuiltinRegistries.BIOME.getKey(biome), biome); + } + public BCLBiome(ResourceLocation biomeID, Biome biome) { this.biomeID = biomeID; this.biome = biome; @@ -56,10 +59,12 @@ public class BCLBiome { /** * Set biome edge for this biome instance. * @param edge {@link BCLBiome} as the edge biome. + * @return same {@link BCLBiome}. */ - public void setEdge(BCLBiome edge) { + public BCLBiome setEdge(BCLBiome edge) { this.edge = edge; edge.biomeParent = this; + return this; } /** @@ -73,19 +78,23 @@ public class BCLBiome { /** * Set edges size for this biome. Size is in relative units to work fine with biome scale. * @param size as a float value. + * @return same {@link BCLBiome}. */ - public void setEdgeSize(float size) { + public BCLBiome setEdgeSize(float size) { edgeSize = size; + return this; } /** * Adds sub-biome into this biome instance. Biome chance will be interpreted as a sub-biome generation chance. * Biome itself has chance 1.0 compared to all its sub-biomes. * @param biome {@link Random} to be added. + * @return same {@link BCLBiome}. */ - public void addSubBiome(BCLBiome biome) { + public BCLBiome addSubBiome(BCLBiome biome) { biome.biomeParent = this; subbiomes.add(biome, biome.getGenChance()); + return this; } /** @@ -115,32 +124,13 @@ public class BCLBiome { return this.biomeParent; } - /** - * Checks if this biome has edge biome. - * @return true if it has edge. - */ - @Deprecated(forRemoval = true) - public boolean hasEdge() { - return edge != null; - } - - /** - * Checks if this biome has parent biome. - * @return true if it has parent. - */ - @Deprecated(forRemoval = true) - public boolean hasParentBiome() { - return biomeParent != null; - } - /** * Compares biome instances (directly) and their parents. Used in custom world generator. * @param biome {@link BCLBiome} * @return true if biome or its parent is same. */ - @Deprecated(forRemoval = true) public boolean isSame(BCLBiome biome) { - return biome == this || (biome.hasParentBiome() && biome.getParentBiome() == this); + return biome == this || (biome.biomeParent != null && biome.biomeParent == this); } /** @@ -183,6 +173,16 @@ public class BCLBiome { return this.genChance; } + /** + * Set gen chance for this biome, default value is 1.0. + * @param genChance chance of this biome to be generated. + * @return same {@link BCLBiome}. + */ + public BCLBiome setGenChance(float genChance) { + this.genChance = genChance; + return this; + } + /** * Recursively update biomes to correct world biome registry instances, for internal usage only. * @param biomeRegistry {@link Registry} for {@link Biome}. @@ -225,17 +225,21 @@ public class BCLBiome { * Adds custom data object to this biome instance. * @param name {@link String} name of data object. * @param obj any data to add. + * @return same {@link BCLBiome}. */ - public void addCustomData(String name, Object obj) { + public BCLBiome addCustomData(String name, Object obj) { customData.put(name, obj); + return this; } /** * Adds custom data object to this biome instance. * @param data a {@link Map} with custom data. + * @return same {@link BCLBiome}. */ - public void addCustomData(Map data) { + public BCLBiome addCustomData(Map data) { customData.putAll(data); + return this; } /** diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/world/biomes/BCLBiomeBuilder.java index f9659e69..df7400d7 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiomeBuilder.java @@ -1,13 +1,23 @@ package ru.bclib.world.biomes; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.level.biome.Biome.BiomeBuilder; import net.minecraft.world.level.biome.Biome.BiomeCategory; import net.minecraft.world.level.biome.Biome.Precipitation; +import net.minecraft.world.level.biome.BiomeSpecialEffects; +import net.minecraft.world.level.biome.MobSpawnSettings; +import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; + +import java.util.ArrayList; +import java.util.List; public class BCLBiomeBuilder { private static final BCLBiomeBuilder INSTANCE = new BCLBiomeBuilder(); + private List mobs = new ArrayList<>(32); + private BiomeSpecialEffects.Builder effectsBuilder; private Precipitation precipitation; private ResourceLocation biomeID; private BiomeCategory category; @@ -23,7 +33,9 @@ public class BCLBiomeBuilder { INSTANCE.biomeID = biomeID; INSTANCE.precipitation = Precipitation.NONE; INSTANCE.category = BiomeCategory.NONE; + INSTANCE.effectsBuilder = null; INSTANCE.temperature = 1.0F; + INSTANCE.mobs.clear(); return INSTANCE; } @@ -67,17 +79,46 @@ public class BCLBiomeBuilder { return this; } + /** + * Adds mob spawning to biome. + * @param entityType {@link EntityType} mob type. + * @param weight spawn weight. + * @param minGroupCount minimum mobs in group. + * @param maxGroupCount maximum mobs in group. + * @return + */ + public BCLBiomeBuilder spawn(EntityType entityType, int weight, int minGroupCount, int maxGroupCount) { + mobs.add(new SpawnerData(entityType, weight, minGroupCount, maxGroupCount)); + return this; + } + public BCLBiome build() { - Biome biome = new Biome.BiomeBuilder() + BiomeBuilder builder = new BiomeBuilder() .precipitation(precipitation) .biomeCategory(category) .temperature(temperature) - .downfall(downfall) + .downfall(downfall); /* - .specialEffects(effects.build()) - .mobSpawnSettings(spawnSettings.build()) .generationSettings(generationSettings.build())*/ - .build(); - return new BCLBiome(biomeID, biome); + //.build(); + + if (!mobs.isEmpty()) { + MobSpawnSettings.Builder spawnSettings = new MobSpawnSettings.Builder(); + mobs.forEach(spawn -> spawnSettings.addSpawn(spawn.type.getCategory(), spawn)); + builder.mobSpawnSettings(spawnSettings.build()); + } + + if (effectsBuilder != null) { + builder.specialEffects(effectsBuilder.build()); + } + + return new BCLBiome(biomeID, builder.build()); + } + + private BiomeSpecialEffects.Builder getEffects() { + if (effectsBuilder == null) { + effectsBuilder = new BiomeSpecialEffects.Builder(); + } + return effectsBuilder; } } diff --git a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java index 5a2d283d..89fc2c53 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java @@ -53,12 +53,12 @@ public class BCLibEndBiomeSource extends BiomeSource { this.possibleBiomes().forEach(biome -> { ResourceLocation key = biomeRegistry.getKey(biome); if (!BiomeAPI.hasBiome(key)) { - BCLBiome bclBiome = new BCLBiome(key, biome, 1, 1); + BCLBiome bclBiome = new BCLBiome(key, biome); BiomeAPI.END_LAND_BIOME_PICKER.addBiomeMutable(bclBiome); } else { BCLBiome bclBiome = BiomeAPI.getBiome(key); - if (bclBiome != BiomeAPI.EMPTY_BIOME && !bclBiome.hasParentBiome()) { + if (bclBiome != BiomeAPI.EMPTY_BIOME && bclBiome.getParentBiome() == null) { if (!BiomeAPI.END_LAND_BIOME_PICKER.containsImmutable(key) && !BiomeAPI.END_VOID_BIOME_PICKER.containsImmutable(key)) { BiomeAPI.END_LAND_BIOME_PICKER.addBiomeMutable(bclBiome); } @@ -105,7 +105,7 @@ public class BCLibEndBiomeSource extends BiomeSource { BCLBiome bclBiome = BiomeAPI.getBiome(key); if (bclBiome != BiomeAPI.EMPTY_BIOME) { - if (bclBiome.hasParentBiome()) { + if (bclBiome.getParentBiome() != null) { bclBiome = bclBiome.getParentBiome(); } key = bclBiome.getID(); diff --git a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java index ad4c7b96..fefbdc91 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java @@ -42,12 +42,12 @@ public class BCLibNetherBiomeSource extends BiomeSource { this.possibleBiomes().forEach(biome -> { ResourceLocation key = biomeRegistry.getKey(biome); if (!BiomeAPI.hasBiome(key)) { - BCLBiome bclBiome = new BCLBiome(key, biome, 1, 1); + BCLBiome bclBiome = new BCLBiome(key, biome); BiomeAPI.NETHER_BIOME_PICKER.addBiomeMutable(bclBiome); } else { BCLBiome bclBiome = BiomeAPI.getBiome(key); - if (bclBiome != BiomeAPI.EMPTY_BIOME && !bclBiome.hasParentBiome()) { + if (bclBiome != BiomeAPI.EMPTY_BIOME && bclBiome.getParentBiome() == null) { if (!BiomeAPI.NETHER_BIOME_PICKER.containsImmutable(key)) { BiomeAPI.NETHER_BIOME_PICKER.addBiomeMutable(bclBiome); } @@ -82,7 +82,7 @@ public class BCLibNetherBiomeSource extends BiomeSource { BCLBiome bclBiome = BiomeAPI.getBiome(key); if (bclBiome != BiomeAPI.EMPTY_BIOME) { - if (bclBiome.hasParentBiome()) { + if (bclBiome.getParentBiome() != null) { bclBiome = bclBiome.getParentBiome(); } key = bclBiome.getID(); diff --git a/src/main/java/ru/bclib/world/generator/BiomeMap.java b/src/main/java/ru/bclib/world/generator/BiomeMap.java index 078bac1f..34251623 100644 --- a/src/main/java/ru/bclib/world/generator/BiomeMap.java +++ b/src/main/java/ru/bclib/world/generator/BiomeMap.java @@ -87,9 +87,9 @@ public class BiomeMap { public BCLBiome getBiome(int x, int z) { BCLBiome biome = getRawBiome(x, z); - if (biome.hasEdge() || (biome.hasParentBiome() && biome.getParentBiome().hasEdge())) { + if (biome.getEdge() != null || (biome.getParentBiome() != null && biome.getParentBiome().getEdge() != null)) { BCLBiome search = biome; - if (biome.hasParentBiome()) { + if (biome.getParentBiome() != null) { search = biome.getParentBiome(); } int d = (int) Math.ceil(search.getEdgeSize() / 4F) << 2; From 6895d705f8c7539a271e155f668b98f5c8c65348 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Wed, 1 Dec 2021 12:35:39 +0300 Subject: [PATCH 39/96] Moved biome API to all other APIs --- src/main/java/ru/bclib/api/PostInitAPI.java | 1 + .../biomes/BCLBiomeBuilder.java | 3 +- .../ru/bclib/api/{ => biomes}/BiomeAPI.java | 982 +++++++++--------- .../render/CustomBackgroundRenderer.java | 2 +- .../bclib/mixin/common/BoneMealItemMixin.java | 2 +- .../mixin/common/MinecraftServerMixin.java | 2 +- .../bclib/mixin/common/ServerLevelMixin.java | 2 +- .../ru/bclib/world/biomes/BCLBiomeDef.java | 2 +- .../world/features/NBTStructureFeature.java | 2 +- .../world/generator/BCLibEndBiomeSource.java | 2 +- .../generator/BCLibNetherBiomeSource.java | 2 +- 11 files changed, 502 insertions(+), 500 deletions(-) rename src/main/java/ru/bclib/{world => api}/biomes/BCLBiomeBuilder.java (98%) rename src/main/java/ru/bclib/api/{ => biomes}/BiomeAPI.java (97%) diff --git a/src/main/java/ru/bclib/api/PostInitAPI.java b/src/main/java/ru/bclib/api/PostInitAPI.java index 29adf17b..58f97714 100644 --- a/src/main/java/ru/bclib/api/PostInitAPI.java +++ b/src/main/java/ru/bclib/api/PostInitAPI.java @@ -7,6 +7,7 @@ import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; import net.minecraft.client.renderer.RenderType; import net.minecraft.core.Registry; import net.minecraft.world.level.block.Block; +import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.blocks.BaseBarrelBlock; import ru.bclib.blocks.BaseChestBlock; import ru.bclib.blocks.BaseFurnaceBlock; diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java similarity index 98% rename from src/main/java/ru/bclib/world/biomes/BCLBiomeBuilder.java rename to src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index df7400d7..2fb4bdcf 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java @@ -1,4 +1,4 @@ -package ru.bclib.world.biomes; +package ru.bclib.api.biomes; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.EntityType; @@ -9,6 +9,7 @@ import net.minecraft.world.level.biome.Biome.Precipitation; import net.minecraft.world.level.biome.BiomeSpecialEffects; import net.minecraft.world.level.biome.MobSpawnSettings; import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; +import ru.bclib.world.biomes.BCLBiome; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/ru/bclib/api/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java similarity index 97% rename from src/main/java/ru/bclib/api/BiomeAPI.java rename to src/main/java/ru/bclib/api/biomes/BiomeAPI.java index 3950f754..60005087 100644 --- a/src/main/java/ru/bclib/api/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -1,491 +1,491 @@ -package ru.bclib.api; - -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.biome.v1.BiomeModifications; -import net.fabricmc.fabric.impl.biome.NetherBiomeData; -import net.fabricmc.fabric.impl.biome.TheEndBiomeData; -import net.minecraft.client.Minecraft; -import net.minecraft.core.Registry; -import net.minecraft.data.BuiltinRegistries; -import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.Mob; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.BiomeSource; -import net.minecraft.world.level.biome.Biomes; -import net.minecraft.world.level.biome.Climate; -import net.minecraft.world.level.levelgen.GenerationStep.Decoration; -import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; -import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; -import net.minecraft.world.level.levelgen.placement.PlacedFeature; -import org.jetbrains.annotations.Nullable; -import ru.bclib.util.MHelper; -import ru.bclib.world.biomes.BCLBiome; -import ru.bclib.world.biomes.FabricBiomesData; -import ru.bclib.world.features.BCLFeature; -import ru.bclib.world.generator.BiomePicker; -import ru.bclib.world.structures.BCLStructureFeature; - -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.Set; -import java.util.function.BiConsumer; - -public class BiomeAPI { - /** - * Empty biome used as default value if requested biome doesn't exist or linked. Shouldn't be registered anywhere to prevent bugs. - * Have {@code Biomes.THE_VOID} as the reference biome. - */ - public static final BCLBiome EMPTY_BIOME = new BCLBiome(Biomes.THE_VOID.location()); - - public static final BiomePicker NETHER_BIOME_PICKER = new BiomePicker(); - public static final BiomePicker END_LAND_BIOME_PICKER = new BiomePicker(); - public static final BiomePicker END_VOID_BIOME_PICKER = new BiomePicker(); - - private static final Map ID_MAP = Maps.newHashMap(); - private static final Map CLIENT = Maps.newHashMap(); - private static Registry biomeRegistry; - - private static final Map>> MODIFICATIONS = Maps.newHashMap(); - private static final Set MODIFIED_BIOMES = Sets.newHashSet(); - - 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 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"))); - - /** - * Initialize registry for current server. - * - * @param server - {@link MinecraftServer} - */ - public static void initRegistry(MinecraftServer server) { - biomeRegistry = server.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY); - CLIENT.clear(); - } - - /** - * Register {@link BCLBiome} instance and its {@link Biome} if necessary. - * @param biome {@link BCLBiome} - * @return {@link BCLBiome} - */ - public static BCLBiome registerBiome(BCLBiome biome) { - if (BuiltinRegistries.BIOME.get(biome.getID()) == null) { - Registry.register(BuiltinRegistries.BIOME, biome.getID(), biome.getBiome()); - } - ID_MAP.put(biome.getID(), biome); - return biome; - } - - public static BCLBiome registerSubBiome(BCLBiome parent, BCLBiome subBiome) { - registerBiome(subBiome); - parent.addSubBiome(subBiome); - return subBiome; - } - - public static BCLBiome registerSubBiome(BCLBiome parent, Biome biome, float genChance) { - BCLBiome subBiome = new BCLBiome(biome).setGenChance(genChance); - return registerSubBiome(parent, subBiome); - } - - /** - * Register {@link BCLBiome} instance and its {@link Biome} if necessary. - * After that biome will be added to BCLib Nether Biome Generator and into Fabric Biome API. - * @param biome {@link BCLBiome} - * @return {@link BCLBiome} - */ - public static BCLBiome registerNetherBiome(BCLBiome biome) { - registerBiome(biome); - NETHER_BIOME_PICKER.addBiome(biome); - Random random = new Random(biome.getID().hashCode()); - - //TODO: 1.18 Check parameters, depth was previously called altitude - //temperature, humidity, continentalness, erosion, depth, weirdness, offset - Climate.ParameterPoint parameters = Climate.parameters( - MHelper.randRange(-1.5F, 1.5F, random), - MHelper.randRange(-1.5F, 1.5F, random), - MHelper.randRange(-1.5F, 1.5F, random), //new in 1.18 - MHelper.randRange(-1.5F, 1.5F, random), //new in 1.18 - MHelper.randRange(-1.5F, 1.5F, random), - MHelper.randRange(-1.5F, 1.5F, random), - random.nextFloat() - ); - ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get(); - NetherBiomeData.addNetherBiome(key, parameters); - return biome; - } - - /** - * Register {@link BCLBiome} instance and its {@link Biome} if necessary. - * After that biome will be added to BCLib Nether Biome Generator and into Fabric Biome API. - * @param biome {@link BCLBiome} - * @return {@link BCLBiome} - */ - public static BCLBiome registerNetherBiome(Biome biome) { - BCLBiome bclBiome = new BCLBiome(biome); - NETHER_BIOME_PICKER.addBiome(bclBiome); - registerBiome(bclBiome); - return bclBiome; - } - - /** - * Register {@link BCLBiome} instance and its {@link Biome} if necessary. - * After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a land biome (will generate only on islands). - * @param biome {@link BCLBiome} - * @return {@link BCLBiome} - */ - public static BCLBiome registerEndLandBiome(BCLBiome biome) { - registerBiome(biome); - END_LAND_BIOME_PICKER.addBiome(biome); - float weight = biome.getGenChance(); - ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get(); - TheEndBiomeData.addEndBiomeReplacement(Biomes.END_HIGHLANDS, key, weight); - TheEndBiomeData.addEndBiomeReplacement(Biomes.END_MIDLANDS, key, weight); - return biome; - } - - /** - * Register {@link BCLBiome} wrapper for {@link Biome}. - * After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a land biome (will generate only on islands). - * @param biome {@link BCLBiome} - * @return {@link BCLBiome} - */ - public static BCLBiome registerEndLandBiome(Biome biome) { - BCLBiome bclBiome = new BCLBiome(biome); - END_LAND_BIOME_PICKER.addBiome(bclBiome); - registerBiome(bclBiome); - return bclBiome; - } - - /** - * Register {@link BCLBiome} wrapper for {@link Biome}. - * After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a land biome (will generate only on islands). - * @param biome {@link BCLBiome}; - * @param genChance float generation chance. - * @return {@link BCLBiome} - */ - public static BCLBiome registerEndLandBiome(Biome biome, float genChance) { - BCLBiome bclBiome = new BCLBiome(biome).setGenChance(genChance); - END_LAND_BIOME_PICKER.addBiome(bclBiome); - registerBiome(bclBiome); - return bclBiome; - } - - /** - * Register {@link BCLBiome} instance and its {@link Biome} if necessary. - * After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a void biome (will generate only in the End void - between islands). - * @param biome {@link BCLBiome} - * @return {@link BCLBiome} - */ - public static BCLBiome registerEndVoidBiome(BCLBiome biome) { - registerBiome(biome); - END_VOID_BIOME_PICKER.addBiome(biome); - float weight = biome.getGenChance(); - ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get(); - TheEndBiomeData.addEndBiomeReplacement(Biomes.SMALL_END_ISLANDS, key, weight); - return biome; - } - - /** - * Register {@link BCLBiome} instance and its {@link Biome} if necessary. - * After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a void biome (will generate only in the End void - between islands). - * @param biome {@link BCLBiome} - * @return {@link BCLBiome} - */ - public static BCLBiome registerEndVoidBiome(Biome biome) { - BCLBiome bclBiome = new BCLBiome(biome); - END_VOID_BIOME_PICKER.addBiome(bclBiome); - registerBiome(bclBiome); - return bclBiome; - } - - /** - * Register {@link BCLBiome} instance and its {@link Biome} if necessary. - * After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a void biome (will generate only in the End void - between islands). - * @param biome {@link BCLBiome}. - * @param genChance float generation chance. - * @return {@link BCLBiome} - */ - public static BCLBiome registerEndVoidBiome(Biome biome, float genChance) { - ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome).get(); - BCLBiome bclBiome = new BCLBiome(biome).setGenChance(genChance); - END_VOID_BIOME_PICKER.addBiome(bclBiome); - registerBiome(bclBiome); - return bclBiome; - } - - /** - * Get {@link BCLBiome} from {@link Biome} instance on server. Used to convert world biomes to BCLBiomes. - * @param biome - {@link Biome} from world. - * @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}. - */ - public static BCLBiome getFromBiome(Biome biome) { - if (biomeRegistry == null) { - return EMPTY_BIOME; - } - return ID_MAP.getOrDefault(biomeRegistry.getKey(biome), EMPTY_BIOME); - } - - /** - * Get {@link BCLBiome} from biome on client. Used in fog rendering. - * @param biome - {@link Biome} from client world. - * @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}. - */ - @Environment(EnvType.CLIENT) - public static BCLBiome getRenderBiome(Biome biome) { - BCLBiome endBiome = CLIENT.get(biome); - if (endBiome == null) { - Minecraft minecraft = Minecraft.getInstance(); - ResourceLocation id = minecraft.level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getKey(biome); - endBiome = id == null ? EMPTY_BIOME : ID_MAP.getOrDefault(id, EMPTY_BIOME); - CLIENT.put(biome, endBiome); - } - return endBiome; - } - - /** - * Get biome {@link ResourceLocation} from given {@link Biome}. - * @param biome - {@link Biome} from server world. - * @return biome {@link ResourceLocation}. - */ - public static ResourceLocation getBiomeID(Biome biome) { - ResourceLocation id = biomeRegistry.getKey(biome); - return id == null ? EMPTY_BIOME.getID() : id; - } - - /** - * Get {@link BCLBiome} from given {@link ResourceLocation}. - * @param biomeID - biome {@link ResourceLocation}. - * @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}. - */ - public static BCLBiome getBiome(ResourceLocation biomeID) { - return ID_MAP.getOrDefault(biomeID, EMPTY_BIOME); - } - - /** - * Check if biome with {@link ResourceLocation} exists in API registry. - * @param biomeID - biome {@link ResourceLocation}. - * @return {@code true} if biome exists in API registry and {@code false} if not. - */ - public static boolean hasBiome(ResourceLocation biomeID) { - return ID_MAP.containsKey(biomeID); - } - - /** - * Load biomes from Fabric API. For internal usage only. - */ - public static void loadFabricAPIBiomes() { - FabricBiomesData.NETHER_BIOMES.forEach((key) -> { - if (!hasBiome(key.location())) { - registerNetherBiome(BuiltinRegistries.BIOME.get(key.location())); - } - }); - - FabricBiomesData.END_LAND_BIOMES.forEach((key, weight) -> { - if (!hasBiome(key.location())) { - registerEndLandBiome(BuiltinRegistries.BIOME.get(key.location()), weight); - } - }); - - FabricBiomesData.END_VOID_BIOMES.forEach((key, weight) -> { - if (!hasBiome(key.location())) { - registerEndVoidBiome(BuiltinRegistries.BIOME.get(key.location()), weight); - } - }); - } - - @Nullable - public static Biome getFromRegistry(ResourceLocation key) { - return BuiltinRegistries.BIOME.get(key); - } - - @Nullable - public static Biome getFromRegistry(ResourceKey key) { - return BuiltinRegistries.BIOME.get(key); - } - - public static boolean isDatapackBiome(ResourceLocation biomeID) { - return getFromRegistry(biomeID) == null; - } - - public static boolean isNetherBiome(ResourceLocation biomeID) { - return pickerHasBiome(NETHER_BIOME_PICKER, biomeID); - } - - public static boolean isEndBiome(ResourceLocation biomeID) { - return pickerHasBiome(END_LAND_BIOME_PICKER, biomeID) || pickerHasBiome(END_VOID_BIOME_PICKER, biomeID); - } - - private static boolean pickerHasBiome(BiomePicker picker, ResourceLocation key) { - return picker.getBiomes().stream().filter(biome -> biome.getID().equals(key)).findFirst().isPresent(); - } - - /** - * Registers new biome modification for specified dimension. Will work both for mod and datapack biomes. - * @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.get(dimensionID); - if (modifications == null) { - modifications = Lists.newArrayList(); - MODIFICATIONS.put(dimensionID, modifications); - } - modifications.add(modification); - } - - /** - * 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) { - registerBiomeModification(Level.OVERWORLD, modification); - } - - /** - * 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) { - registerBiomeModification(Level.NETHER, modification); - } - - /** - * 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) { - registerBiomeModification(Level.END, modification); - } - - /** - * Will apply biome modifications to world, internal usage only. - * @param level - */ - public static void applyModifications(ServerLevel level) { - List> modifications = MODIFICATIONS.get(level.dimension()); - if (modifications == null) { - return; - } - BiomeSource source = level.getChunkSource().getGenerator().getBiomeSource(); - Set biomes = source.possibleBiomes(); - - biomes.forEach(biome -> { - ResourceLocation biomeID = getBiomeID(biome); - boolean modify = isDatapackBiome(biomeID); - if (biome != BuiltinRegistries.BIOME.get(biomeID)) { - modify = true; - } - else if (!modify && !MODIFIED_BIOMES.contains(biomeID)) { - MODIFIED_BIOMES.add(biomeID); - modify = true; - } - if (modify) { - modifications.forEach(consumer -> { - consumer.accept(biomeID, biome); - }); - } - }); - } - - /** - * Adds new features to existing biome. - * @param biome {@link Biome} to add features in. - * @param feature {@link ConfiguredFeature} to add. - * - */ - public static void addBiomeFeature(Biome biome, BCLFeature feature) { - addBiomeFeature(biome, feature.getPlacedFeature(), feature.getFeatureStep()); - } - - /** - * Adds new features to existing biome. - * @param biome {@link Biome} to add features in. - * @param feature {@link ConfiguredFeature} to add. - * @param step a {@link Decoration} step for the feature. - */ - public static void addBiomeFeature(Biome biome, PlacedFeature feature, Decoration step) { - BuiltinRegistries.PLACED_FEATURE - .getResourceKey(feature) - .ifPresent(key -> BiomeModifications.addFeature(ctx -> ctx.getBiomeKey().equals(BuiltinRegistries.BIOME.getKey(biome)), step, key)); - } - - /** - * Adds new features to existing biome. - * @param biome {@link Biome} to add features in. - * @param features array of {@link BCLFeature} to add. - */ - public static void addBiomeFeatures(Biome biome, BCLFeature... features) { - for (BCLFeature feature: features) { - addBiomeFeature(biome, feature.getPlacedFeature(), feature.getFeatureStep()); - } - } - - // TODO: 1.18 There are no more StructureFeatures in the Biomes, they are in a separate registry now - /** - * Adds new structure feature to existing biome. - * @param biome {@link Biome} to add structure feature in. - * @param structure {@link ConfiguredStructureFeature} to add. - */ - public static void addBiomeStructure(Biome biome, ConfiguredStructureFeature structure) { - BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE - .getResourceKey(structure) - .ifPresent(key -> BiomeModifications.addStructure(ctx -> ctx.getBiomeKey().location().equals(BuiltinRegistries.BIOME.getKey(biome)), key)); - } - /** - * Adds new structure feature to existing biome. - * @param biome {@link Biome} to add structure feature in. - * @param structure {@link BCLStructureFeature} to add. - */ - public static void addBiomeStructure(Biome biome, BCLStructureFeature structure) { - addBiomeStructure(biome, structure.getFeatureConfigured()); - } - - /** - * Adds new structure features to existing biome. - * @param biome {@link Biome} to add structure features in. - * @param structures array of {@link BCLStructureFeature} to add. - */ - public static void addBiomeStructures(Biome biome, BCLStructureFeature... structures) { - for (BCLStructureFeature structure: structures) { - addBiomeStructure(biome, structure.getFeatureConfigured()); - } - } - - /** - * Adds mob spawning to specified biome. - * @param biome {@link Biome} to add mob spawning. - * @param entityType {@link EntityType} mob type. - * @param weight spawn weight. - * @param minGroupCount minimum mobs in group. - * @param maxGroupCount maximum mobs in group. - */ - public static void addBiomeMobSpawn(Biome biome, EntityType entityType, int weight, int minGroupCount, int maxGroupCount) { - ResourceLocation biomeKey = BuiltinRegistries.BIOME.getKey(biome); - BiomeModifications.addSpawn( - ctx -> ctx.getBiomeKey().equals(biomeKey), - entityType.getCategory(), - entityType, - weight, - minGroupCount, - maxGroupCount - ); - } -} +package ru.bclib.api.biomes; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.fabricmc.fabric.api.biome.v1.BiomeModifications; +import net.fabricmc.fabric.impl.biome.NetherBiomeData; +import net.fabricmc.fabric.impl.biome.TheEndBiomeData; +import net.minecraft.client.Minecraft; +import net.minecraft.core.Registry; +import net.minecraft.data.BuiltinRegistries; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.BiomeSource; +import net.minecraft.world.level.biome.Biomes; +import net.minecraft.world.level.biome.Climate; +import net.minecraft.world.level.levelgen.GenerationStep.Decoration; +import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; +import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; +import org.jetbrains.annotations.Nullable; +import ru.bclib.util.MHelper; +import ru.bclib.world.biomes.BCLBiome; +import ru.bclib.world.biomes.FabricBiomesData; +import ru.bclib.world.features.BCLFeature; +import ru.bclib.world.generator.BiomePicker; +import ru.bclib.world.structures.BCLStructureFeature; + +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.Set; +import java.util.function.BiConsumer; + +public class BiomeAPI { + /** + * Empty biome used as default value if requested biome doesn't exist or linked. Shouldn't be registered anywhere to prevent bugs. + * Have {@code Biomes.THE_VOID} as the reference biome. + */ + public static final BCLBiome EMPTY_BIOME = new BCLBiome(Biomes.THE_VOID.location()); + + public static final BiomePicker NETHER_BIOME_PICKER = new BiomePicker(); + public static final BiomePicker END_LAND_BIOME_PICKER = new BiomePicker(); + public static final BiomePicker END_VOID_BIOME_PICKER = new BiomePicker(); + + private static final Map ID_MAP = Maps.newHashMap(); + private static final Map CLIENT = Maps.newHashMap(); + private static Registry biomeRegistry; + + private static final Map>> MODIFICATIONS = Maps.newHashMap(); + private static final Set MODIFIED_BIOMES = Sets.newHashSet(); + + 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 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"))); + + /** + * Initialize registry for current server. + * + * @param server - {@link MinecraftServer} + */ + public static void initRegistry(MinecraftServer server) { + biomeRegistry = server.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY); + CLIENT.clear(); + } + + /** + * Register {@link BCLBiome} instance and its {@link Biome} if necessary. + * @param biome {@link BCLBiome} + * @return {@link BCLBiome} + */ + public static BCLBiome registerBiome(BCLBiome biome) { + if (BuiltinRegistries.BIOME.get(biome.getID()) == null) { + Registry.register(BuiltinRegistries.BIOME, biome.getID(), biome.getBiome()); + } + ID_MAP.put(biome.getID(), biome); + return biome; + } + + public static BCLBiome registerSubBiome(BCLBiome parent, BCLBiome subBiome) { + registerBiome(subBiome); + parent.addSubBiome(subBiome); + return subBiome; + } + + public static BCLBiome registerSubBiome(BCLBiome parent, Biome biome, float genChance) { + BCLBiome subBiome = new BCLBiome(biome).setGenChance(genChance); + return registerSubBiome(parent, subBiome); + } + + /** + * Register {@link BCLBiome} instance and its {@link Biome} if necessary. + * After that biome will be added to BCLib Nether Biome Generator and into Fabric Biome API. + * @param biome {@link BCLBiome} + * @return {@link BCLBiome} + */ + public static BCLBiome registerNetherBiome(BCLBiome biome) { + registerBiome(biome); + NETHER_BIOME_PICKER.addBiome(biome); + Random random = new Random(biome.getID().hashCode()); + + //TODO: 1.18 Check parameters, depth was previously called altitude + //temperature, humidity, continentalness, erosion, depth, weirdness, offset + Climate.ParameterPoint parameters = Climate.parameters( + MHelper.randRange(-1.5F, 1.5F, random), + MHelper.randRange(-1.5F, 1.5F, random), + MHelper.randRange(-1.5F, 1.5F, random), //new in 1.18 + MHelper.randRange(-1.5F, 1.5F, random), //new in 1.18 + MHelper.randRange(-1.5F, 1.5F, random), + MHelper.randRange(-1.5F, 1.5F, random), + random.nextFloat() + ); + ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get(); + NetherBiomeData.addNetherBiome(key, parameters); + return biome; + } + + /** + * Register {@link BCLBiome} instance and its {@link Biome} if necessary. + * After that biome will be added to BCLib Nether Biome Generator and into Fabric Biome API. + * @param biome {@link BCLBiome} + * @return {@link BCLBiome} + */ + public static BCLBiome registerNetherBiome(Biome biome) { + BCLBiome bclBiome = new BCLBiome(biome); + NETHER_BIOME_PICKER.addBiome(bclBiome); + registerBiome(bclBiome); + return bclBiome; + } + + /** + * Register {@link BCLBiome} instance and its {@link Biome} if necessary. + * After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a land biome (will generate only on islands). + * @param biome {@link BCLBiome} + * @return {@link BCLBiome} + */ + public static BCLBiome registerEndLandBiome(BCLBiome biome) { + registerBiome(biome); + END_LAND_BIOME_PICKER.addBiome(biome); + float weight = biome.getGenChance(); + ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get(); + TheEndBiomeData.addEndBiomeReplacement(Biomes.END_HIGHLANDS, key, weight); + TheEndBiomeData.addEndBiomeReplacement(Biomes.END_MIDLANDS, key, weight); + return biome; + } + + /** + * Register {@link BCLBiome} wrapper for {@link Biome}. + * After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a land biome (will generate only on islands). + * @param biome {@link BCLBiome} + * @return {@link BCLBiome} + */ + public static BCLBiome registerEndLandBiome(Biome biome) { + BCLBiome bclBiome = new BCLBiome(biome); + END_LAND_BIOME_PICKER.addBiome(bclBiome); + registerBiome(bclBiome); + return bclBiome; + } + + /** + * Register {@link BCLBiome} wrapper for {@link Biome}. + * After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a land biome (will generate only on islands). + * @param biome {@link BCLBiome}; + * @param genChance float generation chance. + * @return {@link BCLBiome} + */ + public static BCLBiome registerEndLandBiome(Biome biome, float genChance) { + BCLBiome bclBiome = new BCLBiome(biome).setGenChance(genChance); + END_LAND_BIOME_PICKER.addBiome(bclBiome); + registerBiome(bclBiome); + return bclBiome; + } + + /** + * Register {@link BCLBiome} instance and its {@link Biome} if necessary. + * After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a void biome (will generate only in the End void - between islands). + * @param biome {@link BCLBiome} + * @return {@link BCLBiome} + */ + public static BCLBiome registerEndVoidBiome(BCLBiome biome) { + registerBiome(biome); + END_VOID_BIOME_PICKER.addBiome(biome); + float weight = biome.getGenChance(); + ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get(); + TheEndBiomeData.addEndBiomeReplacement(Biomes.SMALL_END_ISLANDS, key, weight); + return biome; + } + + /** + * Register {@link BCLBiome} instance and its {@link Biome} if necessary. + * After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a void biome (will generate only in the End void - between islands). + * @param biome {@link BCLBiome} + * @return {@link BCLBiome} + */ + public static BCLBiome registerEndVoidBiome(Biome biome) { + BCLBiome bclBiome = new BCLBiome(biome); + END_VOID_BIOME_PICKER.addBiome(bclBiome); + registerBiome(bclBiome); + return bclBiome; + } + + /** + * Register {@link BCLBiome} instance and its {@link Biome} if necessary. + * After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a void biome (will generate only in the End void - between islands). + * @param biome {@link BCLBiome}. + * @param genChance float generation chance. + * @return {@link BCLBiome} + */ + public static BCLBiome registerEndVoidBiome(Biome biome, float genChance) { + ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome).get(); + BCLBiome bclBiome = new BCLBiome(biome).setGenChance(genChance); + END_VOID_BIOME_PICKER.addBiome(bclBiome); + registerBiome(bclBiome); + return bclBiome; + } + + /** + * Get {@link BCLBiome} from {@link Biome} instance on server. Used to convert world biomes to BCLBiomes. + * @param biome - {@link Biome} from world. + * @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}. + */ + public static BCLBiome getFromBiome(Biome biome) { + if (biomeRegistry == null) { + return EMPTY_BIOME; + } + return ID_MAP.getOrDefault(biomeRegistry.getKey(biome), EMPTY_BIOME); + } + + /** + * Get {@link BCLBiome} from biome on client. Used in fog rendering. + * @param biome - {@link Biome} from client world. + * @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}. + */ + @Environment(EnvType.CLIENT) + public static BCLBiome getRenderBiome(Biome biome) { + BCLBiome endBiome = CLIENT.get(biome); + if (endBiome == null) { + Minecraft minecraft = Minecraft.getInstance(); + ResourceLocation id = minecraft.level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getKey(biome); + endBiome = id == null ? EMPTY_BIOME : ID_MAP.getOrDefault(id, EMPTY_BIOME); + CLIENT.put(biome, endBiome); + } + return endBiome; + } + + /** + * Get biome {@link ResourceLocation} from given {@link Biome}. + * @param biome - {@link Biome} from server world. + * @return biome {@link ResourceLocation}. + */ + public static ResourceLocation getBiomeID(Biome biome) { + ResourceLocation id = biomeRegistry.getKey(biome); + return id == null ? EMPTY_BIOME.getID() : id; + } + + /** + * Get {@link BCLBiome} from given {@link ResourceLocation}. + * @param biomeID - biome {@link ResourceLocation}. + * @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}. + */ + public static BCLBiome getBiome(ResourceLocation biomeID) { + return ID_MAP.getOrDefault(biomeID, EMPTY_BIOME); + } + + /** + * Check if biome with {@link ResourceLocation} exists in API registry. + * @param biomeID - biome {@link ResourceLocation}. + * @return {@code true} if biome exists in API registry and {@code false} if not. + */ + public static boolean hasBiome(ResourceLocation biomeID) { + return ID_MAP.containsKey(biomeID); + } + + /** + * Load biomes from Fabric API. For internal usage only. + */ + public static void loadFabricAPIBiomes() { + FabricBiomesData.NETHER_BIOMES.forEach((key) -> { + if (!hasBiome(key.location())) { + registerNetherBiome(BuiltinRegistries.BIOME.get(key.location())); + } + }); + + FabricBiomesData.END_LAND_BIOMES.forEach((key, weight) -> { + if (!hasBiome(key.location())) { + registerEndLandBiome(BuiltinRegistries.BIOME.get(key.location()), weight); + } + }); + + FabricBiomesData.END_VOID_BIOMES.forEach((key, weight) -> { + if (!hasBiome(key.location())) { + registerEndVoidBiome(BuiltinRegistries.BIOME.get(key.location()), weight); + } + }); + } + + @Nullable + public static Biome getFromRegistry(ResourceLocation key) { + return BuiltinRegistries.BIOME.get(key); + } + + @Nullable + public static Biome getFromRegistry(ResourceKey key) { + return BuiltinRegistries.BIOME.get(key); + } + + public static boolean isDatapackBiome(ResourceLocation biomeID) { + return getFromRegistry(biomeID) == null; + } + + public static boolean isNetherBiome(ResourceLocation biomeID) { + return pickerHasBiome(NETHER_BIOME_PICKER, biomeID); + } + + public static boolean isEndBiome(ResourceLocation biomeID) { + return pickerHasBiome(END_LAND_BIOME_PICKER, biomeID) || pickerHasBiome(END_VOID_BIOME_PICKER, biomeID); + } + + private static boolean pickerHasBiome(BiomePicker picker, ResourceLocation key) { + return picker.getBiomes().stream().filter(biome -> biome.getID().equals(key)).findFirst().isPresent(); + } + + /** + * Registers new biome modification for specified dimension. Will work both for mod and datapack biomes. + * @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.get(dimensionID); + if (modifications == null) { + modifications = Lists.newArrayList(); + MODIFICATIONS.put(dimensionID, modifications); + } + modifications.add(modification); + } + + /** + * 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) { + registerBiomeModification(Level.OVERWORLD, modification); + } + + /** + * 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) { + registerBiomeModification(Level.NETHER, modification); + } + + /** + * 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) { + registerBiomeModification(Level.END, modification); + } + + /** + * Will apply biome modifications to world, internal usage only. + * @param level + */ + public static void applyModifications(ServerLevel level) { + List> modifications = MODIFICATIONS.get(level.dimension()); + if (modifications == null) { + return; + } + BiomeSource source = level.getChunkSource().getGenerator().getBiomeSource(); + Set biomes = source.possibleBiomes(); + + biomes.forEach(biome -> { + ResourceLocation biomeID = getBiomeID(biome); + boolean modify = isDatapackBiome(biomeID); + if (biome != BuiltinRegistries.BIOME.get(biomeID)) { + modify = true; + } + else if (!modify && !MODIFIED_BIOMES.contains(biomeID)) { + MODIFIED_BIOMES.add(biomeID); + modify = true; + } + if (modify) { + modifications.forEach(consumer -> { + consumer.accept(biomeID, biome); + }); + } + }); + } + + /** + * Adds new features to existing biome. + * @param biome {@link Biome} to add features in. + * @param feature {@link ConfiguredFeature} to add. + * + */ + public static void addBiomeFeature(Biome biome, BCLFeature feature) { + addBiomeFeature(biome, feature.getPlacedFeature(), feature.getFeatureStep()); + } + + /** + * Adds new features to existing biome. + * @param biome {@link Biome} to add features in. + * @param feature {@link ConfiguredFeature} to add. + * @param step a {@link Decoration} step for the feature. + */ + public static void addBiomeFeature(Biome biome, PlacedFeature feature, Decoration step) { + BuiltinRegistries.PLACED_FEATURE + .getResourceKey(feature) + .ifPresent(key -> BiomeModifications.addFeature(ctx -> ctx.getBiomeKey().equals(BuiltinRegistries.BIOME.getKey(biome)), step, key)); + } + + /** + * Adds new features to existing biome. + * @param biome {@link Biome} to add features in. + * @param features array of {@link BCLFeature} to add. + */ + public static void addBiomeFeatures(Biome biome, BCLFeature... features) { + for (BCLFeature feature: features) { + addBiomeFeature(biome, feature.getPlacedFeature(), feature.getFeatureStep()); + } + } + + // TODO: 1.18 There are no more StructureFeatures in the Biomes, they are in a separate registry now + /** + * Adds new structure feature to existing biome. + * @param biome {@link Biome} to add structure feature in. + * @param structure {@link ConfiguredStructureFeature} to add. + */ + public static void addBiomeStructure(Biome biome, ConfiguredStructureFeature structure) { + BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE + .getResourceKey(structure) + .ifPresent(key -> BiomeModifications.addStructure(ctx -> ctx.getBiomeKey().location().equals(BuiltinRegistries.BIOME.getKey(biome)), key)); + } + /** + * Adds new structure feature to existing biome. + * @param biome {@link Biome} to add structure feature in. + * @param structure {@link BCLStructureFeature} to add. + */ + public static void addBiomeStructure(Biome biome, BCLStructureFeature structure) { + addBiomeStructure(biome, structure.getFeatureConfigured()); + } + + /** + * Adds new structure features to existing biome. + * @param biome {@link Biome} to add structure features in. + * @param structures array of {@link BCLStructureFeature} to add. + */ + public static void addBiomeStructures(Biome biome, BCLStructureFeature... structures) { + for (BCLStructureFeature structure: structures) { + addBiomeStructure(biome, structure.getFeatureConfigured()); + } + } + + /** + * Adds mob spawning to specified biome. + * @param biome {@link Biome} to add mob spawning. + * @param entityType {@link EntityType} mob type. + * @param weight spawn weight. + * @param minGroupCount minimum mobs in group. + * @param maxGroupCount maximum mobs in group. + */ + public static void addBiomeMobSpawn(Biome biome, EntityType entityType, int weight, int minGroupCount, int maxGroupCount) { + ResourceLocation biomeKey = BuiltinRegistries.BIOME.getKey(biome); + BiomeModifications.addSpawn( + ctx -> ctx.getBiomeKey().equals(biomeKey), + entityType.getCategory(), + entityType, + weight, + minGroupCount, + maxGroupCount + ); + } +} diff --git a/src/main/java/ru/bclib/client/render/CustomBackgroundRenderer.java b/src/main/java/ru/bclib/client/render/CustomBackgroundRenderer.java index 1828ad51..c26d4e5a 100644 --- a/src/main/java/ru/bclib/client/render/CustomBackgroundRenderer.java +++ b/src/main/java/ru/bclib/client/render/CustomBackgroundRenderer.java @@ -13,7 +13,7 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.level.Level; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.material.FogType; -import ru.bclib.api.BiomeAPI; +import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.util.BackgroundInfo; import ru.bclib.util.MHelper; import ru.bclib.world.biomes.BCLBiome; diff --git a/src/main/java/ru/bclib/mixin/common/BoneMealItemMixin.java b/src/main/java/ru/bclib/mixin/common/BoneMealItemMixin.java index 52357c1a..78ad381b 100644 --- a/src/main/java/ru/bclib/mixin/common/BoneMealItemMixin.java +++ b/src/main/java/ru/bclib/mixin/common/BoneMealItemMixin.java @@ -15,7 +15,7 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import ru.bclib.api.BiomeAPI; +import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.api.BonemealAPI; import ru.bclib.util.BlocksHelper; import ru.bclib.util.MHelper; diff --git a/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java b/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java index 0b7cfc6a..5d455fb1 100644 --- a/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java +++ b/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java @@ -21,7 +21,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import ru.bclib.api.BiomeAPI; +import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.api.dataexchange.DataExchangeAPI; import ru.bclib.recipes.BCLRecipeManager; diff --git a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java index b9ae402c..60c82e64 100644 --- a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java +++ b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java @@ -16,7 +16,7 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import ru.bclib.api.BiomeAPI; +import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.api.LifeCycleAPI; import java.util.List; diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java index 2df240f3..a95b3e1b 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java @@ -27,7 +27,7 @@ import net.minecraft.world.level.levelgen.carver.CarverConfiguration; import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import net.minecraft.world.level.levelgen.placement.PlacedFeature; -import ru.bclib.api.BiomeAPI; +import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.config.IdConfig; import ru.bclib.config.PathConfig; import ru.bclib.util.ColorUtil; diff --git a/src/main/java/ru/bclib/world/features/NBTStructureFeature.java b/src/main/java/ru/bclib/world/features/NBTStructureFeature.java index 63a37fdd..f8f7dabe 100644 --- a/src/main/java/ru/bclib/world/features/NBTStructureFeature.java +++ b/src/main/java/ru/bclib/world/features/NBTStructureFeature.java @@ -19,7 +19,7 @@ import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConf import net.minecraft.world.level.levelgen.structure.BoundingBox; import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings; import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; -import ru.bclib.api.BiomeAPI; +import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.api.TagAPI; import ru.bclib.util.BlocksHelper; import ru.bclib.world.processors.DestructionStructureProcessor; diff --git a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java index 89fc2c53..5debd380 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java @@ -15,7 +15,7 @@ import net.minecraft.world.level.levelgen.LegacyRandomSource; import net.minecraft.world.level.levelgen.WorldgenRandom; import net.minecraft.world.level.levelgen.synth.SimplexNoise; import ru.bclib.BCLib; -import ru.bclib.api.BiomeAPI; +import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.config.ConfigKeeper.StringArrayEntry; import ru.bclib.config.Configs; import ru.bclib.noise.OpenSimplexNoise; diff --git a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java index fefbdc91..8e2dff94 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java @@ -10,7 +10,7 @@ import net.minecraft.world.level.biome.Biome.BiomeCategory; import net.minecraft.world.level.biome.BiomeSource; import net.minecraft.world.level.biome.Climate; import ru.bclib.BCLib; -import ru.bclib.api.BiomeAPI; +import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.config.ConfigKeeper.StringArrayEntry; import ru.bclib.config.Configs; import ru.bclib.world.biomes.BCLBiome; From 7541e39cf9e13a2d6fe7cd6ee6323ceeaf1986af Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Wed, 1 Dec 2021 12:54:38 +0300 Subject: [PATCH 40/96] More biome builder functions (mobs, visual effects) --- .../ru/bclib/api/biomes/BCLBiomeBuilder.java | 106 +++++++++++++++--- .../java/ru/bclib/world/biomes/BCLBiome.java | 10 ++ 2 files changed, 102 insertions(+), 14 deletions(-) diff --git a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index 2fb4bdcf..31ec79cb 100644 --- a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java @@ -1,28 +1,30 @@ package ru.bclib.api.biomes; +import net.minecraft.core.particles.ParticleOptions; import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Mth; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; +import net.minecraft.world.level.biome.AmbientParticleSettings; import net.minecraft.world.level.biome.Biome.BiomeBuilder; import net.minecraft.world.level.biome.Biome.BiomeCategory; import net.minecraft.world.level.biome.Biome.Precipitation; import net.minecraft.world.level.biome.BiomeSpecialEffects; import net.minecraft.world.level.biome.MobSpawnSettings; import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; +import ru.bclib.util.ColorUtil; import ru.bclib.world.biomes.BCLBiome; -import java.util.ArrayList; -import java.util.List; - public class BCLBiomeBuilder { private static final BCLBiomeBuilder INSTANCE = new BCLBiomeBuilder(); - private List mobs = new ArrayList<>(32); private BiomeSpecialEffects.Builder effectsBuilder; + private MobSpawnSettings.Builder spawnSettings; private Precipitation precipitation; private ResourceLocation biomeID; private BiomeCategory category; private float temperature; + private float fogDensity; private float downfall; /** @@ -35,8 +37,9 @@ public class BCLBiomeBuilder { INSTANCE.precipitation = Precipitation.NONE; INSTANCE.category = BiomeCategory.NONE; INSTANCE.effectsBuilder = null; + INSTANCE.spawnSettings = null; INSTANCE.temperature = 1.0F; - INSTANCE.mobs.clear(); + INSTANCE.fogDensity = 1.0F; return INSTANCE; } @@ -86,26 +89,94 @@ public class BCLBiomeBuilder { * @param weight spawn weight. * @param minGroupCount minimum mobs in group. * @param maxGroupCount maximum mobs in group. - * @return + * @return same {@link BCLBiomeBuilder} instance. */ public BCLBiomeBuilder spawn(EntityType entityType, int weight, int minGroupCount, int maxGroupCount) { - mobs.add(new SpawnerData(entityType, weight, minGroupCount, maxGroupCount)); + getSpawns().addSpawn(entityType.getCategory(), new SpawnerData(entityType, weight, minGroupCount, maxGroupCount)); return this; } + /** + * Adds ambient particles to thr biome. + * @param particle {@link ParticleOptions} particles (or {@link net.minecraft.core.particles.ParticleType}). + * @param probability particle spawn probability, should have low value (example: 0.01F). + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder particles(ParticleOptions particle, float probability) { + getEffects().ambientParticle(new AmbientParticleSettings(particle, probability)); + return this; + } + + /** + * Sets sky color for the biome. Color is in ARGB int format. + * @param color ARGB color as integer. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder skyColor(int color) { + getEffects().skyColor(color); + return this; + } + + /** + * Sets sky color for the biome. Color represented as red, green and blue channel values. + * @param red red color component [0-255] + * @param green green color component [0-255] + * @param blue blue color component [0-255] + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder skyColor(int red, int green, int blue) { + red = Mth.clamp(red, 0, 255); + green = Mth.clamp(green, 0, 255); + blue = Mth.clamp(blue, 0, 255); + return skyColor(ColorUtil.color(red, green, blue)); + } + + /** + * Sets fog color for the biome. Color is in ARGB int format. + * @param color ARGB color as integer. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder fogColor(int color) { + getEffects().fogColor(color); + return this; + } + + /** + * Sets fog color for the biome. Color represented as red, green and blue channel values. + * @param red red color component [0-255] + * @param green green color component [0-255] + * @param blue blue color component [0-255] + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder fogColor(int red, int green, int blue) { + red = Mth.clamp(red, 0, 255); + green = Mth.clamp(green, 0, 255); + blue = Mth.clamp(blue, 0, 255); + return fogColor(ColorUtil.color(red, green, blue)); + } + + /** + * Sets fog density for the biome. + * @param density fog density as a float, default value is 1.0F. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder fogDensity(float density) { + this.fogDensity = density; + return this; + } + + /** + * Finalize biome creation. + * @return created {@link BCLBiome} instance. + */ public BCLBiome build() { BiomeBuilder builder = new BiomeBuilder() .precipitation(precipitation) .biomeCategory(category) .temperature(temperature) .downfall(downfall); - /* - .generationSettings(generationSettings.build())*/ - //.build(); - if (!mobs.isEmpty()) { - MobSpawnSettings.Builder spawnSettings = new MobSpawnSettings.Builder(); - mobs.forEach(spawn -> spawnSettings.addSpawn(spawn.type.getCategory(), spawn)); + if (spawnSettings != null) { builder.mobSpawnSettings(spawnSettings.build()); } @@ -113,7 +184,7 @@ public class BCLBiomeBuilder { builder.specialEffects(effectsBuilder.build()); } - return new BCLBiome(biomeID, builder.build()); + return new BCLBiome(biomeID, builder.build()).setFogDensity(fogDensity); } private BiomeSpecialEffects.Builder getEffects() { @@ -122,4 +193,11 @@ public class BCLBiomeBuilder { } return effectsBuilder; } + + private MobSpawnSettings.Builder getSpawns() { + if (spawnSettings == null) { + spawnSettings = new MobSpawnSettings.Builder(); + } + return spawnSettings; + } } diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiome.java b/src/main/java/ru/bclib/world/biomes/BCLBiome.java index 39c851a9..19a345a2 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiome.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiome.java @@ -149,6 +149,16 @@ public class BCLBiome { return fogDensity; } + /** + * Sets fog density for this biome. + * @param fogDensity + * @return same {@link BCLBiome}. + */ + public BCLBiome setFogDensity(float fogDensity) { + this.fogDensity = fogDensity; + return this; + } + /** * Getter for biome from buil-in registry. For datapack biomes will be same as actual biome. * @return {@link Biome}. From 14ab0c878bf03d686eedd9778cd2d694668d05aa Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Wed, 1 Dec 2021 13:16:59 +0300 Subject: [PATCH 41/96] More biome builder functions (visual effects) --- .../ru/bclib/api/biomes/BCLBiomeBuilder.java | 204 ++++++++++++++++++ 1 file changed, 204 insertions(+) diff --git a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index 31ec79cb..4b103ea9 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.minecraft.core.particles.ParticleOptions; import net.minecraft.resources.ResourceLocation; +import net.minecraft.sounds.Music; +import net.minecraft.sounds.SoundEvent; import net.minecraft.util.Mth; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; +import net.minecraft.world.level.biome.AmbientAdditionsSettings; import net.minecraft.world.level.biome.AmbientParticleSettings; import net.minecraft.world.level.biome.Biome.BiomeBuilder; import net.minecraft.world.level.biome.Biome.BiomeCategory; @@ -165,6 +168,197 @@ public class BCLBiomeBuilder { return this; } + /** + * Sets water color for the biome. Color is in ARGB int format. + * @param color ARGB color as integer. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder waterColor(int color) { + getEffects().waterColor(color); + return this; + } + + /** + * Sets water color for the biome. Color represented as red, green and blue channel values. + * @param red red color component [0-255] + * @param green green color component [0-255] + * @param blue blue color component [0-255] + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder waterColor(int red, int green, int blue) { + red = Mth.clamp(red, 0, 255); + green = Mth.clamp(green, 0, 255); + blue = Mth.clamp(blue, 0, 255); + return waterColor(ColorUtil.color(red, green, blue)); + } + + /** + * Sets underwater fog color for the biome. Color is in ARGB int format. + * @param color ARGB color as integer. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder waterFogColor(int color) { + getEffects().waterFogColor(color); + return this; + } + + /** + * Sets underwater fog color for the biome. Color represented as red, green and blue channel values. + * @param red red color component [0-255] + * @param green green color component [0-255] + * @param blue blue color component [0-255] + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder waterFogColor(int red, int green, int blue) { + red = Mth.clamp(red, 0, 255); + green = Mth.clamp(green, 0, 255); + blue = Mth.clamp(blue, 0, 255); + return waterFogColor(ColorUtil.color(red, green, blue)); + } + + /** + * Sets water and underwater fig color for the biome. Color is in ARGB int format. + * @param color ARGB color as integer. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder waterAndFogColor(int color) { + return waterColor(color).waterFogColor(color); + } + + /** + * Sets water and underwater fig color for the biome. Color is in ARGB int format. + * @param red red color component [0-255] + * @param green green color component [0-255] + * @param blue blue color component [0-255] + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder waterAndFogColor(int red, int green, int blue) { + red = Mth.clamp(red, 0, 255); + green = Mth.clamp(green, 0, 255); + blue = Mth.clamp(blue, 0, 255); + return waterAndFogColor(ColorUtil.color(red, green, blue)); + } + + /** + * Sets grass color for the biome. Color is in ARGB int format. + * @param color ARGB color as integer. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder grassColor(int color) { + getEffects().grassColorOverride(color); + return this; + } + + /** + * Sets grass color for the biome. Color represented as red, green and blue channel values. + * @param red red color component [0-255] + * @param green green color component [0-255] + * @param blue blue color component [0-255] + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder grassColor(int red, int green, int blue) { + red = Mth.clamp(red, 0, 255); + green = Mth.clamp(green, 0, 255); + blue = Mth.clamp(blue, 0, 255); + return grassColor(ColorUtil.color(red, green, blue)); + } + + /** + * Sets leaves and plants color for the biome. Color is in ARGB int format. + * @param color ARGB color as integer. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder foliageColor(int color) { + getEffects().foliageColorOverride(color); + return this; + } + + /** + * Sets leaves and plants color for the biome. Color represented as red, green and blue channel values. + * @param red red color component [0-255] + * @param green green color component [0-255] + * @param blue blue color component [0-255] + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder foliageColor(int red, int green, int blue) { + red = Mth.clamp(red, 0, 255); + green = Mth.clamp(green, 0, 255); + blue = Mth.clamp(blue, 0, 255); + return foliageColor(ColorUtil.color(red, green, blue)); + } + + /** + * Sets grass, leaves and all plants color for the biome. Color is in ARGB int format. + * @param color ARGB color as integer. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder plantsColor(int color) { + return grassColor(color).foliageColor(color); + } + + /** + * Sets grass, leaves and all plants color for the biome. Color represented as red, green and blue channel values. + * @param red red color component [0-255] + * @param green green color component [0-255] + * @param blue blue color component [0-255] + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder plantsColor(int red, int green, int blue) { + red = Mth.clamp(red, 0, 255); + green = Mth.clamp(green, 0, 255); + blue = Mth.clamp(blue, 0, 255); + return plantsColor(ColorUtil.color(red, green, blue)); + } + + /** + * Sets biome music, used for biomes in the Nether and End. + * @param music {@link Music} to use. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder music(Music music) { + getEffects().backgroundMusic(music); + return this; + } + + /** + * Sets biome music, used for biomes in the Nether and End. + * @param music {@link SoundEvent} to use. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder music(SoundEvent music) { + return music(new Music(music, 600, 2400, true)); + } + + /** + * Sets biome ambient loop sound. Can be used for biome environment. + * @param loopSound {@link SoundEvent} to use as a loop. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder loop(SoundEvent loopSound) { + getEffects().ambientLoopSound(loopSound); + return this; + } + + /** + * Sets biome additionsl ambient sounds. + * @param additions {@link SoundEvent} to use. + * @param intensity sound intensity. Default is 0.0111F. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder additions(SoundEvent additions, float intensity) { + getEffects().ambientAdditionsSound(new AmbientAdditionsSettings(additions, intensity)); + return this; + } + + /** + * Sets biome additionsl ambient sounds. + * @param additions {@link SoundEvent} to use. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder additions(SoundEvent additions) { + return additions(additions, 0.0111F); + } + /** * Finalize biome creation. * @return created {@link BCLBiome} instance. @@ -187,6 +381,11 @@ public class BCLBiomeBuilder { return new BCLBiome(biomeID, builder.build()).setFogDensity(fogDensity); } + /** + * Get or create {@link BiomeSpecialEffects.Builder} for biome visual effects. + * For internal usage only. + * @return new or same {@link BiomeSpecialEffects.Builder} instance. + */ private BiomeSpecialEffects.Builder getEffects() { if (effectsBuilder == null) { effectsBuilder = new BiomeSpecialEffects.Builder(); @@ -194,6 +393,11 @@ public class BCLBiomeBuilder { return effectsBuilder; } + /** + * Get or create {@link MobSpawnSettings.Builder} for biome mob spawning. + * For internal usage only. + * @return new or same {@link MobSpawnSettings.Builder} instance. + */ private MobSpawnSettings.Builder getSpawns() { if (spawnSettings == null) { spawnSettings = new MobSpawnSettings.Builder(); From c7c11d0b4c147ed2d9f498355de5d400ba0820ab Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Wed, 1 Dec 2021 13:56:37 +0300 Subject: [PATCH 42/96] More biome builder functions (generation settings, music) --- .../ru/bclib/api/biomes/BCLBiomeBuilder.java | 66 +++++++++++++++++++ .../java/ru/bclib/api/biomes/BiomeAPI.java | 4 +- .../bclib/mixin/common/BoneMealItemMixin.java | 2 +- .../bclib/mixin/common/ServerLevelMixin.java | 2 +- .../ru/bclib/world/biomes/BCLBiomeDef.java | 2 +- .../ru/bclib/world/features/BCLFeature.java | 2 +- .../world/features/NBTStructureFeature.java | 2 +- 7 files changed, 73 insertions(+), 7 deletions(-) diff --git a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index 4b103ea9..f49e6935 100644 --- a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java @@ -8,19 +8,25 @@ import net.minecraft.util.Mth; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.level.biome.AmbientAdditionsSettings; +import net.minecraft.world.level.biome.AmbientMoodSettings; import net.minecraft.world.level.biome.AmbientParticleSettings; import net.minecraft.world.level.biome.Biome.BiomeBuilder; import net.minecraft.world.level.biome.Biome.BiomeCategory; import net.minecraft.world.level.biome.Biome.Precipitation; +import net.minecraft.world.level.biome.BiomeGenerationSettings; import net.minecraft.world.level.biome.BiomeSpecialEffects; import net.minecraft.world.level.biome.MobSpawnSettings; import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; +import net.minecraft.world.level.levelgen.GenerationStep.Decoration; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; import ru.bclib.util.ColorUtil; import ru.bclib.world.biomes.BCLBiome; +import ru.bclib.world.features.BCLFeature; public class BCLBiomeBuilder { private static final BCLBiomeBuilder INSTANCE = new BCLBiomeBuilder(); + private BiomeGenerationSettings.Builder generationSettings; private BiomeSpecialEffects.Builder effectsBuilder; private MobSpawnSettings.Builder spawnSettings; private Precipitation precipitation; @@ -39,10 +45,12 @@ public class BCLBiomeBuilder { INSTANCE.biomeID = biomeID; INSTANCE.precipitation = Precipitation.NONE; INSTANCE.category = BiomeCategory.NONE; + INSTANCE.generationSettings = null; INSTANCE.effectsBuilder = null; INSTANCE.spawnSettings = null; INSTANCE.temperature = 1.0F; INSTANCE.fogDensity = 1.0F; + INSTANCE.downfall = 1.0F; return INSTANCE; } @@ -339,6 +347,28 @@ public class BCLBiomeBuilder { return this; } + /** + * Sets biome mood sound. Can be used for biome environment. + * @param mood {@link SoundEvent} to use as a mood. + * @param tickDelay delay between sound events in ticks. + * @param blockSearchExtent block search radius (for area available for sound). + * @param soundPositionOffset offset in sound. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder mood(SoundEvent mood, int tickDelay, int blockSearchExtent, float soundPositionOffset) { + getEffects().ambientMoodSound(new AmbientMoodSettings(mood, tickDelay, blockSearchExtent, soundPositionOffset)); + return this; + } + + /** + * Sets biome mood sound. Can be used for biome environment. + * @param mood {@link SoundEvent} to use as a mood. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder mood(SoundEvent mood) { + return mood(mood, 6000, 8, 2.0F); + } + /** * Sets biome additionsl ambient sounds. * @param additions {@link SoundEvent} to use. @@ -359,6 +389,26 @@ public class BCLBiomeBuilder { return additions(additions, 0.0111F); } + /** + * Adds new feature to the biome. + * @param decoration {@link Decoration} feature step. + * @param feature {@link PlacedFeature}. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder feature(Decoration decoration, PlacedFeature feature) { + getGeneration().addFeature(decoration, feature); + return this; + } + + /** + * Adds new feature to the biome. + * @param feature {@link BCLFeature}. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder feature(BCLFeature feature) { + return feature(feature.getDecoration(), feature.getPlacedFeature()); + } + /** * Finalize biome creation. * @return created {@link BCLBiome} instance. @@ -378,6 +428,10 @@ public class BCLBiomeBuilder { builder.specialEffects(effectsBuilder.build()); } + if (generationSettings != null) { + builder.generationSettings(generationSettings.build()); + } + return new BCLBiome(biomeID, builder.build()).setFogDensity(fogDensity); } @@ -404,4 +458,16 @@ public class BCLBiomeBuilder { } return spawnSettings; } + + /** + * Get or create {@link BiomeGenerationSettings.Builder} for biome features and generation. + * For internal usage only. + * @return new or same {@link BiomeGenerationSettings.Builder} instance. + */ + private BiomeGenerationSettings.Builder getGeneration() { + if (generationSettings == null) { + generationSettings = new BiomeGenerationSettings.Builder(); + } + return generationSettings; + } } diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index 60005087..1ef912f2 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -412,7 +412,7 @@ public class BiomeAPI { * */ public static void addBiomeFeature(Biome biome, BCLFeature feature) { - addBiomeFeature(biome, feature.getPlacedFeature(), feature.getFeatureStep()); + addBiomeFeature(biome, feature.getPlacedFeature(), feature.getDecoration()); } /** @@ -434,7 +434,7 @@ public class BiomeAPI { */ public static void addBiomeFeatures(Biome biome, BCLFeature... features) { for (BCLFeature feature: features) { - addBiomeFeature(biome, feature.getPlacedFeature(), feature.getFeatureStep()); + addBiomeFeature(biome, feature.getPlacedFeature(), feature.getDecoration()); } } diff --git a/src/main/java/ru/bclib/mixin/common/BoneMealItemMixin.java b/src/main/java/ru/bclib/mixin/common/BoneMealItemMixin.java index 78ad381b..1ad99193 100644 --- a/src/main/java/ru/bclib/mixin/common/BoneMealItemMixin.java +++ b/src/main/java/ru/bclib/mixin/common/BoneMealItemMixin.java @@ -15,8 +15,8 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.api.BonemealAPI; +import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.util.BlocksHelper; import ru.bclib.util.MHelper; diff --git a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java index 60c82e64..d22aceec 100644 --- a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java +++ b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java @@ -16,8 +16,8 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.api.LifeCycleAPI; +import ru.bclib.api.biomes.BiomeAPI; import java.util.List; import java.util.concurrent.Executor; diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java index a95b3e1b..69a57055 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java @@ -217,7 +217,7 @@ public class BCLBiomeDef { public BCLBiomeDef addFeature(BCLFeature feature) { FeatureInfo info = new FeatureInfo(); - info.featureStep = feature.getFeatureStep(); + info.featureStep = feature.getDecoration(); info.feature = feature.getPlacedFeature(); features.add(info); return this; diff --git a/src/main/java/ru/bclib/world/features/BCLFeature.java b/src/main/java/ru/bclib/world/features/BCLFeature.java index 0987c81a..9f82066b 100644 --- a/src/main/java/ru/bclib/world/features/BCLFeature.java +++ b/src/main/java/ru/bclib/world/features/BCLFeature.java @@ -58,7 +58,7 @@ public class BCLFeature { * Get feature decoration step. * @return {@link Decoration}. */ - public Decoration getFeatureStep() { + public Decoration getDecoration() { return featureStep; } /** diff --git a/src/main/java/ru/bclib/world/features/NBTStructureFeature.java b/src/main/java/ru/bclib/world/features/NBTStructureFeature.java index f8f7dabe..e0b44884 100644 --- a/src/main/java/ru/bclib/world/features/NBTStructureFeature.java +++ b/src/main/java/ru/bclib/world/features/NBTStructureFeature.java @@ -19,8 +19,8 @@ import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConf import net.minecraft.world.level.levelgen.structure.BoundingBox; import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings; import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; -import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.api.TagAPI; +import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.util.BlocksHelper; import ru.bclib.world.processors.DestructionStructureProcessor; From 211d0fc751426efdf9d74968b18b07054bcbb735 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Wed, 1 Dec 2021 14:28:27 +0300 Subject: [PATCH 43/96] Hexagonal biome generator --- .../world/generator/BCLibEndBiomeSource.java | 9 +- .../generator/BCLibNetherBiomeSource.java | 5 +- .../generator/map/hex/HexBiomeChunk.java | 130 ++++++++++ .../world/generator/map/hex/HexBiomeMap.java | 156 ++++++++++++ .../square/SquareBiomeChunk.java} | 110 ++++----- .../square/SquareBiomeMap.java} | 228 +++++++++--------- 6 files changed, 465 insertions(+), 173 deletions(-) create mode 100644 src/main/java/ru/bclib/world/generator/map/hex/HexBiomeChunk.java create mode 100644 src/main/java/ru/bclib/world/generator/map/hex/HexBiomeMap.java rename src/main/java/ru/bclib/world/generator/{BiomeChunk.java => map/square/SquareBiomeChunk.java} (86%) rename src/main/java/ru/bclib/world/generator/{BiomeMap.java => map/square/SquareBiomeMap.java} (80%) diff --git a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java index 5debd380..d100eb3a 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java @@ -20,6 +20,7 @@ import ru.bclib.config.ConfigKeeper.StringArrayEntry; import ru.bclib.config.Configs; import ru.bclib.noise.OpenSimplexNoise; import ru.bclib.world.biomes.BCLBiome; +import ru.bclib.world.generator.map.hex.HexBiomeMap; import java.awt.Point; import java.util.List; @@ -39,8 +40,8 @@ public class BCLibEndBiomeSource extends BiomeSource { private final SimplexNoise noise; private final Biome centerBiome; private final Biome barrens; - private BiomeMap mapLand; - private BiomeMap mapVoid; + private HexBiomeMap mapLand; + private HexBiomeMap mapVoid; private final long seed; private final Point pos; @@ -74,8 +75,8 @@ public class BCLibEndBiomeSource extends BiomeSource { BiomeAPI.END_LAND_BIOME_PICKER.rebuild(); BiomeAPI.END_VOID_BIOME_PICKER.rebuild(); - this.mapLand = new BiomeMap(seed, GeneratorOptions.getBiomeSizeEndLand(), BiomeAPI.END_LAND_BIOME_PICKER); - this.mapVoid = new BiomeMap(seed, GeneratorOptions.getBiomeSizeEndVoid(), BiomeAPI.END_VOID_BIOME_PICKER); + this.mapLand = new HexBiomeMap(seed, GeneratorOptions.getBiomeSizeEndLand(), BiomeAPI.END_LAND_BIOME_PICKER); + 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.biomeRegistry = biomeRegistry; diff --git a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java index 8e2dff94..5b8361f9 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java @@ -14,6 +14,7 @@ import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.config.ConfigKeeper.StringArrayEntry; import ru.bclib.config.Configs; import ru.bclib.world.biomes.BCLBiome; +import ru.bclib.world.generator.map.hex.HexBiomeMap; import java.util.LinkedList; import java.util.List; @@ -28,7 +29,7 @@ public class BCLibNetherBiomeSource extends BiomeSource { })).apply(instance, instance.stable(BCLibNetherBiomeSource::new)); }); private final Registry biomeRegistry; - private BiomeMap biomeMap; + private HexBiomeMap biomeMap; private final long seed; @Deprecated(forRemoval = true) @@ -59,7 +60,7 @@ public class BCLibNetherBiomeSource extends BiomeSource { BiomeAPI.NETHER_BIOME_PICKER.getBiomes().forEach(biome -> biome.updateActualBiomes(biomeRegistry)); BiomeAPI.NETHER_BIOME_PICKER.rebuild(); - this.biomeMap = new BiomeMap(seed, GeneratorOptions.getBiomeSizeNether(), BiomeAPI.NETHER_BIOME_PICKER); + this.biomeMap = new HexBiomeMap(seed, GeneratorOptions.getBiomeSizeNether(), BiomeAPI.NETHER_BIOME_PICKER); this.biomeRegistry = biomeRegistry; this.seed = seed; diff --git a/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeChunk.java b/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeChunk.java new file mode 100644 index 00000000..57d46f79 --- /dev/null +++ b/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeChunk.java @@ -0,0 +1,130 @@ +package ru.bclib.world.generator.map.hex; + +import ru.bclib.world.biomes.BCLBiome; +import ru.bclib.world.generator.BiomePicker; + +import java.util.Random; + +public class HexBiomeChunk { + private static final short SIDE = 32; + private static final short SIZE = SIDE * SIDE; + private static final byte SIDE_MASK = SIDE - 1; + private static final byte SIDE_OFFSET = (byte) Math.round(Math.log(SIDE) / Math.log(2)); + private static final short[][] NEIGHBOURS; + public static final short SCALE = SIDE / 4; + + private final BCLBiome[] biomes; + + public HexBiomeChunk(Random random, BiomePicker picker) { + BCLBiome[][] buffers = new BCLBiome[2][SIZE]; + + byte scale = SIDE / 4; + for (byte x = 0; x < 4; x++) { + for (byte z = 0; z < 4; z++) { + byte px = (byte) (x * scale + random.nextInt(scale)); + byte pz = (byte) (z * scale + random.nextInt(scale)); + circle(buffers[0], getIndex(px, pz), picker.getBiome(random), null); + } + } + + short maxSide = SIZE - SIDE; + boolean hasEmptyCells = true; + byte bufferIndex = 0; + while (hasEmptyCells) { + BCLBiome[] inBuffer = buffers[bufferIndex]; + bufferIndex = (byte) ((bufferIndex + 1) & 1); + BCLBiome[] outBuffer = buffers[bufferIndex]; + hasEmptyCells = false; + + for (short index = SIDE; index < maxSide; index++) { + byte z = (byte) (index & SIDE_MASK); + if (z == 0 || z == SIDE_MASK) { + continue; + } + if (inBuffer[index] != null) { + outBuffer[index] = inBuffer[index]; + short[] neighbours = getNeighbours(index & SIDE_MASK); + short indexSide = (short) (index + neighbours[random.nextInt(6)]); + if (indexSide >= 0 && indexSide < SIZE && outBuffer[indexSide] == null) { + outBuffer[indexSide] = inBuffer[index]; + } + } + else { + hasEmptyCells = true; + } + } + } + + BCLBiome[] outBuffer = buffers[bufferIndex]; + byte preN = (byte) (SIDE_MASK - 2); + for (byte index = 0; index < SIDE; index++) { + outBuffer[getIndex(index, (byte) 0)] = outBuffer[getIndex(index, (byte) 2)]; + outBuffer[getIndex((byte) 0, index)] = outBuffer[getIndex((byte) 2, index)]; + outBuffer[getIndex(index, SIDE_MASK)] = outBuffer[getIndex(index, preN)]; + outBuffer[getIndex(SIDE_MASK, index)] = outBuffer[getIndex(preN, index)]; + } + + for (short index = 0; index < SIZE; index++) { + if (random.nextInt(4) == 0) { + circle(outBuffer, index, outBuffer[index].getSubBiome(random), outBuffer[index]); + } + } + + this.biomes = outBuffer; + } + + private void circle(BCLBiome[] buffer, short center, BCLBiome biome, BCLBiome mask) { + if (buffer[center] == mask) { + buffer[center] = biome; + } + short[] neighbours = getNeighbours(center & SIDE_MASK); + for (short i: neighbours) { + short index = (short) (center + i); + if (index >= 0 && index < SIZE && buffer[index] == mask) { + buffer[index] = biome; + } + } + } + + private static byte wrap(int value) { + return (byte) (value & SIDE_MASK); + } + + private short getIndex(byte x, byte z) { + return (short) ((short) x << SIDE_OFFSET | z); + } + + public BCLBiome getBiome(int x, int z) { + return biomes[getIndex(wrap(x), wrap(z))]; + } + + public static int scaleCoordinate(int value) { + return value >> SIDE_OFFSET; + } + + public static boolean isBorder(int value) { + return wrap(value) == SIDE_MASK; + } + + private short[] getNeighbours(int z) { + return NEIGHBOURS[z & 1]; + } + + static { + NEIGHBOURS = new short[2][6]; + + NEIGHBOURS[0][0] = 1; + NEIGHBOURS[0][1] = -1; + NEIGHBOURS[0][2] = SIDE; + NEIGHBOURS[0][3] = -SIDE; + NEIGHBOURS[0][4] = SIDE + 1; + NEIGHBOURS[0][5] = SIDE - 1; + + NEIGHBOURS[1][0] = 1; + NEIGHBOURS[1][1] = -1; + NEIGHBOURS[1][2] = SIDE; + NEIGHBOURS[1][3] = -SIDE; + NEIGHBOURS[1][4] = -SIDE + 1; + NEIGHBOURS[1][5] = -SIDE - 1; + } +} diff --git a/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeMap.java b/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeMap.java new file mode 100644 index 00000000..0eafcad3 --- /dev/null +++ b/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeMap.java @@ -0,0 +1,156 @@ +package ru.bclib.world.generator.map.hex; + +import ru.bclib.noise.OpenSimplexNoise; +import ru.bclib.util.MHelper; +import ru.bclib.world.biomes.BCLBiome; +import ru.bclib.world.generator.BiomePicker; + +import java.awt.Point; +import java.util.HashMap; +import java.util.Random; + +public class HexBiomeMap { + private static final float RAD_INNER = (float) Math.sqrt(3.0) * 0.5F; + private static final float COEF = 0.25F * (float) Math.sqrt(3.0); + private static final float COEF_HALF = COEF * 0.5F; + private static final float SIN = (float) Math.sin(0.4); + private static final float COS = (float) Math.cos(0.4); + private static final Random RANDOM = new Random(); + private static final float[] EDGE_CIRCLE_X; + private static final float[] EDGE_CIRCLE_Z; + + private final HashMap chunks = new HashMap<>(); + private final Point selector = new Point(); + private final BiomePicker picker; + + private final OpenSimplexNoise[] noises = new OpenSimplexNoise[2]; + private final byte noiseIterations; + private final float scale; + private final int seed; + + public HexBiomeMap(long seed, int size, BiomePicker picker) { + this.picker = picker; + this.scale = (float) size / HexBiomeChunk.SCALE; + Random random = new Random(seed); + noises[0] = new OpenSimplexNoise(random.nextInt()); + noises[1] = new OpenSimplexNoise(random.nextInt()); + noiseIterations = (byte) Math.min(Math.ceil(Math.log(scale) / Math.log(2)), 5); + this.seed = (int) (seed & 0xFFFFFFFF); + } + + public void clearCache() { + if (chunks.size() > 127) { + chunks.clear(); + } + } + + public BCLBiome getBiome(double x, double z) { + BCLBiome BCLBiome = getRawBiome(x, z); + if (BCLBiome.getEdge() != null) { + float offset = scale * BCLBiome.getEdgeSize(); + for (byte i = 0; i < 8; i++) { + if (getRawBiome(x + offset * EDGE_CIRCLE_X[i], z + offset * EDGE_CIRCLE_Z[i]) != BCLBiome) { + return BCLBiome.getEdge(); + } + } + } + return BCLBiome; + } + + private BCLBiome getRawBiome(double x, double z) { + double px = x / scale * RAD_INNER; + double pz = z / scale; + double dx = rotateX(px, pz); + double dz = rotateZ(px, pz); + px = dx; + pz = dz; + + dx = getNoise(px, pz, (byte) 0) * 0.2F; + dz = getNoise(pz, px, (byte) 1) * 0.2F; + px += dx; + pz += dz; + + int cellZ = (int) Math.floor(pz); + boolean offset = (cellZ & 1) == 1; + + if (offset) { + px += 0.5; + } + + int cellX = (int) Math.floor(px); + + float pointX = (float) (px - cellX - 0.5); + float pointZ = (float) (pz - cellZ - 0.5); + + if (Math.abs(pointZ) < 0.3333F) { + return getChunkBiome(cellX, cellZ); + } + + if (insideHexagon(0, 0, 1.1555F, pointZ * RAD_INNER, pointX)) { + return getChunkBiome(cellX, cellZ); + } + + cellX = pointX < 0 ? (offset ? cellX - 1 : cellX) : (offset ? cellX : cellX + 1); + cellZ = pointZ < 0 ? cellZ - 1 : cellZ + 1; + + return getChunkBiome(cellX, cellZ); + } + + private BCLBiome getChunkBiome(int x, int z) { + int cx = HexBiomeChunk.scaleCoordinate(x); + int cz = HexBiomeChunk.scaleCoordinate(z); + + if (((z >> 2) & 1) == 0 && HexBiomeChunk.isBorder(x)) { + x = 0; + cx += 1; + } + else if (((x >> 2) & 1) == 0 && HexBiomeChunk.isBorder(z)) { + z = 0; + cz += 1; + } + + selector.setLocation(cx, cz); + HexBiomeChunk chunk = chunks.get(selector); + if (chunk == null) { + RANDOM.setSeed(MHelper.getSeed(seed, cx, cz)); + chunk = new HexBiomeChunk(RANDOM, picker); + chunks.put(new Point(selector), chunk); + } + return chunk.getBiome(x, z); + } + + private boolean insideHexagon(float centerX, float centerZ, float radius, float x, float z) { + double dx = Math.abs(x - centerX) / radius; + double dy = Math.abs(z - centerZ) / radius; + return (dy <= COEF) && (COEF * dx + 0.25F * dy <= COEF_HALF); + } + + private double getNoise(double x, double z, byte state) { + double result = 0; + for (byte i = 1; i <= noiseIterations; i++) { + OpenSimplexNoise noise = noises[state]; + state = (byte) ((state + 1) & 1); + result += noise.eval(x * i, z * i) / i; + } + return result; + } + + private double rotateX(double x, double z) { + return x * COS - z * SIN; + } + + private double rotateZ(double x, double z) { + return x * SIN + z * COS; + } + + static { + EDGE_CIRCLE_X = new float[8]; + EDGE_CIRCLE_Z = new float[8]; + + for (byte i = 0; i < 8; i++) { + float angle = i / 4F * (float) Math.PI; + EDGE_CIRCLE_X[i] = (float) Math.sin(angle); + EDGE_CIRCLE_Z[i] = (float) Math.cos(angle); + } + } +} diff --git a/src/main/java/ru/bclib/world/generator/BiomeChunk.java b/src/main/java/ru/bclib/world/generator/map/square/SquareBiomeChunk.java similarity index 86% rename from src/main/java/ru/bclib/world/generator/BiomeChunk.java rename to src/main/java/ru/bclib/world/generator/map/square/SquareBiomeChunk.java index d424462e..9b057ffd 100644 --- a/src/main/java/ru/bclib/world/generator/BiomeChunk.java +++ b/src/main/java/ru/bclib/world/generator/map/square/SquareBiomeChunk.java @@ -1,54 +1,56 @@ -package ru.bclib.world.generator; - -import ru.bclib.world.biomes.BCLBiome; - -import java.util.Random; - -public class BiomeChunk { - private static final int BIT_OFFSET = 4; - protected static final int WIDTH = 1 << BIT_OFFSET; - private static final int SM_WIDTH = WIDTH >> 1; - private static final int SM_BIT_OFFSET = BIT_OFFSET >> 1; - private static final int MASK_OFFSET = SM_WIDTH - 1; - protected static final int MASK_WIDTH = WIDTH - 1; - - private static final int SM_CAPACITY = SM_WIDTH * SM_WIDTH; - private static final int CAPACITY = WIDTH * WIDTH; - - private final BCLBiome[] biomes; - - public BiomeChunk(BiomeMap map, Random random, BiomePicker picker) { - BCLBiome[] PreBio = new BCLBiome[SM_CAPACITY]; - biomes = new BCLBiome[CAPACITY]; - - for (int x = 0; x < SM_WIDTH; x++) { - int offset = x << SM_BIT_OFFSET; - for (int z = 0; z < SM_WIDTH; z++) { - PreBio[offset | z] = picker.getBiome(random); - } - } - - for (int x = 0; x < WIDTH; x++) { - int offset = x << BIT_OFFSET; - for (int z = 0; z < WIDTH; z++) { - biomes[offset | z] = PreBio[getSmIndex(offsetXZ(x, random), offsetXZ(z, random))].getSubBiome(random); - } - } - } - - public BCLBiome getBiome(int x, int z) { - return biomes[getIndex(x & MASK_WIDTH, z & MASK_WIDTH)]; - } - - private int offsetXZ(int x, Random random) { - return ((x + random.nextInt(2)) >> 1) & MASK_OFFSET; - } - - private int getIndex(int x, int z) { - return x << BIT_OFFSET | z; - } - - private int getSmIndex(int x, int z) { - return x << SM_BIT_OFFSET | z; - } -} +package ru.bclib.world.generator.map.square; + +import ru.bclib.world.biomes.BCLBiome; +import ru.bclib.world.generator.BiomePicker; + +import java.util.Random; + +@Deprecated +public class SquareBiomeChunk { + private static final int BIT_OFFSET = 4; + protected static final int WIDTH = 1 << BIT_OFFSET; + private static final int SM_WIDTH = WIDTH >> 1; + private static final int SM_BIT_OFFSET = BIT_OFFSET >> 1; + private static final int MASK_OFFSET = SM_WIDTH - 1; + protected static final int MASK_WIDTH = WIDTH - 1; + + private static final int SM_CAPACITY = SM_WIDTH * SM_WIDTH; + private static final int CAPACITY = WIDTH * WIDTH; + + private final BCLBiome[] biomes; + + public SquareBiomeChunk(SquareBiomeMap map, Random random, BiomePicker picker) { + BCLBiome[] PreBio = new BCLBiome[SM_CAPACITY]; + biomes = new BCLBiome[CAPACITY]; + + for (int x = 0; x < SM_WIDTH; x++) { + int offset = x << SM_BIT_OFFSET; + for (int z = 0; z < SM_WIDTH; z++) { + PreBio[offset | z] = picker.getBiome(random); + } + } + + for (int x = 0; x < WIDTH; x++) { + int offset = x << BIT_OFFSET; + for (int z = 0; z < WIDTH; z++) { + biomes[offset | z] = PreBio[getSmIndex(offsetXZ(x, random), offsetXZ(z, random))].getSubBiome(random); + } + } + } + + public BCLBiome getBiome(int x, int z) { + return biomes[getIndex(x & MASK_WIDTH, z & MASK_WIDTH)]; + } + + private int offsetXZ(int x, Random random) { + return ((x + random.nextInt(2)) >> 1) & MASK_OFFSET; + } + + private int getIndex(int x, int z) { + return x << BIT_OFFSET | z; + } + + private int getSmIndex(int x, int z) { + return x << SM_BIT_OFFSET | z; + } +} diff --git a/src/main/java/ru/bclib/world/generator/BiomeMap.java b/src/main/java/ru/bclib/world/generator/map/square/SquareBiomeMap.java similarity index 80% rename from src/main/java/ru/bclib/world/generator/BiomeMap.java rename to src/main/java/ru/bclib/world/generator/map/square/SquareBiomeMap.java index 34251623..022366c4 100644 --- a/src/main/java/ru/bclib/world/generator/BiomeMap.java +++ b/src/main/java/ru/bclib/world/generator/map/square/SquareBiomeMap.java @@ -1,113 +1,115 @@ -package ru.bclib.world.generator; - -import com.google.common.collect.Maps; -import net.minecraft.world.level.ChunkPos; -import net.minecraft.world.level.levelgen.LegacyRandomSource; -import net.minecraft.world.level.levelgen.WorldgenRandom; -import ru.bclib.noise.OpenSimplexNoise; -import ru.bclib.util.MHelper; -import ru.bclib.world.biomes.BCLBiome; - -import java.util.Map; - -public class BiomeMap { - private final WorldgenRandom RANDOM; - - private final Map maps = Maps.newHashMap(); - private final int size; - private final int sizeXZ; - private final int depth; - private final OpenSimplexNoise noiseX; - private final OpenSimplexNoise noiseZ; - private final BiomePicker picker; - private final long seed; - - public BiomeMap(long seed, int size, BiomePicker picker) { - maps.clear(); - RANDOM = new WorldgenRandom(new LegacyRandomSource(seed)); - noiseX = new OpenSimplexNoise(RANDOM.nextLong()); - noiseZ = new OpenSimplexNoise(RANDOM.nextLong()); - this.sizeXZ = size; - depth = (int) Math.ceil(Math.log(size) / Math.log(2)) - 2; - this.size = 1 << depth; - this.picker = picker; - this.seed = seed; - } - - public long getSeed() { - return seed; - } - - public void clearCache() { - if (maps.size() > 32) { - maps.clear(); - } - } - - private BCLBiome getRawBiome(int bx, int bz) { - double x = (double) bx * size / sizeXZ; - double z = (double) bz * size / sizeXZ; - double nx = x; - double nz = z; - - double px = bx * 0.2; - double pz = bz * 0.2; - - for (int i = 0; i < depth; i++) { - nx = (x + noiseX.eval(px, pz)) / 2F; - nz = (z + noiseZ.eval(px, pz)) / 2F; - - x = nx; - z = nz; - - px = px / 2 + i; - pz = pz / 2 + i; - } - - bx = MHelper.floor(x); - bz = MHelper.floor(z); - if ((bx & BiomeChunk.MASK_WIDTH) == BiomeChunk.MASK_WIDTH) { - x += (bz / 2) & 1; - } - if ((bz & BiomeChunk.MASK_WIDTH) == BiomeChunk.MASK_WIDTH) { - z += (bx / 2) & 1; - } - - ChunkPos cpos = new ChunkPos(MHelper.floor(x / BiomeChunk.WIDTH), MHelper.floor(z / BiomeChunk.WIDTH)); - BiomeChunk chunk = maps.get(cpos); - if (chunk == null) { - RANDOM.setLargeFeatureWithSalt(0, cpos.x, cpos.z, 0); - chunk = new BiomeChunk(this, RANDOM, picker); - maps.put(cpos, chunk); - } - - return chunk.getBiome(MHelper.floor(x), MHelper.floor(z)); - } - - public BCLBiome getBiome(int x, int z) { - BCLBiome biome = getRawBiome(x, z); - - if (biome.getEdge() != null || (biome.getParentBiome() != null && biome.getParentBiome().getEdge() != null)) { - BCLBiome search = biome; - if (biome.getParentBiome() != null) { - search = biome.getParentBiome(); - } - int d = (int) Math.ceil(search.getEdgeSize() / 4F) << 2; - - boolean edge = !search.isSame(getRawBiome(x + d, z)); - edge = edge || !search.isSame(getRawBiome(x - d, z)); - edge = edge || !search.isSame(getRawBiome(x, z + d)); - edge = edge || !search.isSame(getRawBiome(x, z - d)); - edge = edge || !search.isSame(getRawBiome(x - 1, z - 1)); - edge = edge || !search.isSame(getRawBiome(x - 1, z + 1)); - edge = edge || !search.isSame(getRawBiome(x + 1, z - 1)); - edge = edge || !search.isSame(getRawBiome(x + 1, z + 1)); - - if (edge) { - biome = search.getEdge(); - } - } - - return biome; - } -} +package ru.bclib.world.generator.map.square; + +import com.google.common.collect.Maps; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.levelgen.LegacyRandomSource; +import net.minecraft.world.level.levelgen.WorldgenRandom; +import ru.bclib.noise.OpenSimplexNoise; +import ru.bclib.util.MHelper; +import ru.bclib.world.biomes.BCLBiome; +import ru.bclib.world.generator.BiomePicker; + +import java.util.Map; + +@Deprecated +public class SquareBiomeMap { + private final WorldgenRandom RANDOM; + + private final Map maps = Maps.newHashMap(); + private final int size; + private final int sizeXZ; + private final int depth; + private final OpenSimplexNoise noiseX; + private final OpenSimplexNoise noiseZ; + private final BiomePicker picker; + private final long seed; + + public SquareBiomeMap(long seed, int size, BiomePicker picker) { + maps.clear(); + RANDOM = new WorldgenRandom(new LegacyRandomSource(seed)); + noiseX = new OpenSimplexNoise(RANDOM.nextLong()); + noiseZ = new OpenSimplexNoise(RANDOM.nextLong()); + this.sizeXZ = size; + depth = (int) Math.ceil(Math.log(size) / Math.log(2)) - 2; + this.size = 1 << depth; + this.picker = picker; + this.seed = seed; + } + + public long getSeed() { + return seed; + } + + public void clearCache() { + if (maps.size() > 32) { + maps.clear(); + } + } + + private BCLBiome getRawBiome(int bx, int bz) { + double x = (double) bx * size / sizeXZ; + double z = (double) bz * size / sizeXZ; + double nx = x; + double nz = z; + + double px = bx * 0.2; + double pz = bz * 0.2; + + for (int i = 0; i < depth; i++) { + nx = (x + noiseX.eval(px, pz)) / 2F; + nz = (z + noiseZ.eval(px, pz)) / 2F; + + x = nx; + z = nz; + + px = px / 2 + i; + pz = pz / 2 + i; + } + + bx = MHelper.floor(x); + bz = MHelper.floor(z); + if ((bx & SquareBiomeChunk.MASK_WIDTH) == SquareBiomeChunk.MASK_WIDTH) { + x += (bz / 2) & 1; + } + if ((bz & SquareBiomeChunk.MASK_WIDTH) == SquareBiomeChunk.MASK_WIDTH) { + z += (bx / 2) & 1; + } + + ChunkPos cpos = new ChunkPos(MHelper.floor(x / SquareBiomeChunk.WIDTH), MHelper.floor(z / SquareBiomeChunk.WIDTH)); + SquareBiomeChunk chunk = maps.get(cpos); + if (chunk == null) { + RANDOM.setLargeFeatureWithSalt(0, cpos.x, cpos.z, 0); + chunk = new SquareBiomeChunk(this, RANDOM, picker); + maps.put(cpos, chunk); + } + + return chunk.getBiome(MHelper.floor(x), MHelper.floor(z)); + } + + public BCLBiome getBiome(int x, int z) { + BCLBiome biome = getRawBiome(x, z); + + if (biome.getEdge() != null || (biome.getParentBiome() != null && biome.getParentBiome().getEdge() != null)) { + BCLBiome search = biome; + if (biome.getParentBiome() != null) { + search = biome.getParentBiome(); + } + int d = (int) Math.ceil(search.getEdgeSize() / 4F) << 2; + + boolean edge = !search.isSame(getRawBiome(x + d, z)); + edge = edge || !search.isSame(getRawBiome(x - d, z)); + edge = edge || !search.isSame(getRawBiome(x, z + d)); + edge = edge || !search.isSame(getRawBiome(x, z - d)); + edge = edge || !search.isSame(getRawBiome(x - 1, z - 1)); + edge = edge || !search.isSame(getRawBiome(x - 1, z + 1)); + edge = edge || !search.isSame(getRawBiome(x + 1, z - 1)); + edge = edge || !search.isSame(getRawBiome(x + 1, z + 1)); + + if (edge) { + biome = search.getEdge(); + } + } + + return biome; + } +} From 72e29223a1de97ce02f05c1a1d74ef2b2ce19f3a Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Wed, 1 Dec 2021 14:52:21 +0300 Subject: [PATCH 44/96] Small fix, cleanup --- .../java/ru/bclib/world/biomes/BCLBiome.java | 10 ++++ .../generator/map/hex/HexBiomeChunk.java | 2 +- src/main/resources/bclib.mixins.client.json | 14 ++--- src/main/resources/bclib.mixins.common.json | 59 +++++++++---------- 4 files changed, 47 insertions(+), 38 deletions(-) diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiome.java b/src/main/java/ru/bclib/world/biomes/BCLBiome.java index 19a345a2..59833b74 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiome.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiome.java @@ -3,6 +3,7 @@ package ru.bclib.world.biomes; import com.google.common.collect.Maps; 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.biome.Biome; import org.jetbrains.annotations.Nullable; @@ -26,6 +27,14 @@ public class BCLBiome { private float genChance = 1.0F; private float edgeSize = 0.0F; + /** + * Create wrapper for existing biome using its {@link ResourceLocation} identifier. + * @param biomeKey {@link ResourceKey} for the {@link Biome}. + */ + public BCLBiome(ResourceKey biomeKey) { + this(biomeKey.location()); + } + /** * Create wrapper for existing biome using its {@link ResourceLocation} identifier. * @param biomeID {@link ResourceLocation} biome ID. @@ -43,6 +52,7 @@ public class BCLBiome { } public BCLBiome(ResourceLocation biomeID, Biome biome) { + this.subbiomes.add(this, 1.0F); this.biomeID = biomeID; this.biome = biome; } diff --git a/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeChunk.java b/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeChunk.java index 57d46f79..fa737803 100644 --- a/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeChunk.java +++ b/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeChunk.java @@ -65,7 +65,7 @@ public class HexBiomeChunk { } for (short index = 0; index < SIZE; index++) { - if (random.nextInt(4) == 0) { + if (outBuffer[index] != null && random.nextInt(4) == 0) { circle(outBuffer, index, outBuffer[index].getSubBiome(random), outBuffer[index]); } } diff --git a/src/main/resources/bclib.mixins.client.json b/src/main/resources/bclib.mixins.client.json index d8d18a6d..b633a525 100644 --- a/src/main/resources/bclib.mixins.client.json +++ b/src/main/resources/bclib.mixins.client.json @@ -4,17 +4,17 @@ "package": "ru.bclib.mixin.client", "compatibilityLevel": "JAVA_17", "client": [ - "AnvilScreenMixin", + "SimpleReloadableResourceManagerMixin", + "EnchantingTableBlockMixin", "BackgroundRendererMixin", "ClientRecipeBookMixin", - "EnchantingTableBlockMixin", - "GameMixin", + "ModelManagerMixin", + "TextureAtlasMixin", + "AnvilScreenMixin", + "ModelBakeryMixin", "MinecraftMixin", "GameMixin", - "ModelBakeryMixin", - "ModelManagerMixin", - "SimpleReloadableResourceManagerMixin", - "TextureAtlasMixin" + "GameMixin" ], "injectors": { "defaultRequire": 1 diff --git a/src/main/resources/bclib.mixins.common.json b/src/main/resources/bclib.mixins.common.json index a2ac975c..bb587aa9 100644 --- a/src/main/resources/bclib.mixins.common.json +++ b/src/main/resources/bclib.mixins.common.json @@ -4,41 +4,40 @@ "package": "ru.bclib.mixin.common", "compatibilityLevel": "JAVA_17", "mixins": [ - "AnvilBlockMixin", - "AnvilMenuMixin", - "ChunkGeneratorMixin", - "BoneMealItemMixin", + "SimpleReloadableResourceManagerMixin", + "shears.DiggingEnchantmentMixin", + "LayerLightSectionStorageMixin", + "shears.TripWireBlockMixin", + "shears.BeehiveBlockMixin", + "shears.PumpkinBlockMixin", + "shears.MushroomCowMixin", "ComposterBlockAccessor", "PotionBrewingAccessor", - "RecipeManagerAccessor", - "CraftingMenuMixin", - "EnchantmentMenuMixin", - "LayerLightSectionStorageMixin", - "MainMixin", - "MinecraftServerMixin", - "PistonBaseBlockMixin", - "WorldGenRegionMixin", - "TheEndBiomeDataMixin", - "NetherBiomeDataMixin", - "RecipeManagerMixin", - "CraftingMenuMixin", - "BoneMealItemMixin", - "shears.SheepMixin", - "PortalShapeMixin", "PotionBrewingAccessor", "RecipeManagerAccessor", - "RecipeManagerMixin", - "ServerLevelMixin", - "SimpleReloadableResourceManagerMixin", - "TagLoaderMixin", - "WorldGenRegionMixin", - "shears.BeehiveBlockMixin", - "shears.DiggingEnchantmentMixin", - "shears.MushroomCowMixin", - "shears.PumpkinBlockMixin", - "shears.SheepMixin", + "RecipeManagerAccessor", "shears.SnowGolemMixin", - "shears.TripWireBlockMixin" + "EnchantmentMenuMixin", + "MinecraftServerMixin", + "NetherBiomeDataMixin", + "PistonBaseBlockMixin", + "TheEndBiomeDataMixin", + "ChunkGeneratorMixin", + "WorldGenRegionMixin", + "WorldGenRegionMixin", + "RecipeManagerMixin", + "RecipeManagerMixin", + "BoneMealItemMixin", + "CraftingMenuMixin", + "CraftingMenuMixin", + "shears.SheepMixin", + "shears.SheepMixin", + "PortalShapeMixin", + "ServerLevelMixin", + "AnvilBlockMixin", + "AnvilMenuMixin", + "TagLoaderMixin", + "MainMixin" ], "injectors": { "defaultRequire": 1 From 801f9e5a746c39ca64b35ef36675ebbd7dc11a58 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Wed, 1 Dec 2021 15:43:04 +0300 Subject: [PATCH 45/96] Possibility to change biome generator --- .../java/ru/bclib/interfaces/BiomeMap.java | 9 ++ .../world/generator/BCLibEndBiomeSource.java | 17 ++- .../generator/BCLibNetherBiomeSource.java | 12 +- .../world/generator/GeneratorOptions.java | 6 + .../world/generator/map/hex/HexBiomeMap.java | 5 +- .../map/square/SquareBiomeChunk.java | 3 +- .../generator/map/square/SquareBiomeMap.java | 108 +++++++++--------- 7 files changed, 96 insertions(+), 64 deletions(-) create mode 100644 src/main/java/ru/bclib/interfaces/BiomeMap.java diff --git a/src/main/java/ru/bclib/interfaces/BiomeMap.java b/src/main/java/ru/bclib/interfaces/BiomeMap.java new file mode 100644 index 00000000..89d79521 --- /dev/null +++ b/src/main/java/ru/bclib/interfaces/BiomeMap.java @@ -0,0 +1,9 @@ +package ru.bclib.interfaces; + +import ru.bclib.world.biomes.BCLBiome; + +public interface BiomeMap { + void clearCache(); + + BCLBiome getBiome(double x, double z); +} diff --git a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java index d100eb3a..1fb41e50 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java @@ -18,9 +18,11 @@ import ru.bclib.BCLib; 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.noise.OpenSimplexNoise; import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.generator.map.hex.HexBiomeMap; +import ru.bclib.world.generator.map.square.SquareBiomeMap; import java.awt.Point; import java.util.List; @@ -40,8 +42,8 @@ public class BCLibEndBiomeSource extends BiomeSource { private final SimplexNoise noise; private final Biome centerBiome; private final Biome barrens; - private HexBiomeMap mapLand; - private HexBiomeMap mapVoid; + private BiomeMap mapLand; + private BiomeMap mapVoid; private final long seed; private final Point pos; @@ -75,8 +77,15 @@ public class BCLibEndBiomeSource extends BiomeSource { BiomeAPI.END_LAND_BIOME_PICKER.rebuild(); BiomeAPI.END_VOID_BIOME_PICKER.rebuild(); - this.mapLand = new HexBiomeMap(seed, GeneratorOptions.getBiomeSizeEndLand(), BiomeAPI.END_LAND_BIOME_PICKER); - this.mapVoid = new HexBiomeMap(seed, GeneratorOptions.getBiomeSizeEndVoid(), BiomeAPI.END_VOID_BIOME_PICKER); + if (GeneratorOptions.useOldBiomeGenerator()) { + this.mapLand = new SquareBiomeMap(seed, GeneratorOptions.getBiomeSizeEndLand(), BiomeAPI.END_LAND_BIOME_PICKER); + this.mapVoid = new SquareBiomeMap(seed, GeneratorOptions.getBiomeSizeEndVoid(), BiomeAPI.END_VOID_BIOME_PICKER); + } + else { + this.mapLand = new HexBiomeMap(seed, GeneratorOptions.getBiomeSizeEndLand(), BiomeAPI.END_LAND_BIOME_PICKER); + 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.biomeRegistry = biomeRegistry; diff --git a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java index 5b8361f9..ad1f157a 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java @@ -13,8 +13,10 @@ import ru.bclib.BCLib; 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.world.biomes.BCLBiome; import ru.bclib.world.generator.map.hex.HexBiomeMap; +import ru.bclib.world.generator.map.square.SquareBiomeMap; import java.util.LinkedList; import java.util.List; @@ -29,7 +31,7 @@ public class BCLibNetherBiomeSource extends BiomeSource { })).apply(instance, instance.stable(BCLibNetherBiomeSource::new)); }); private final Registry biomeRegistry; - private HexBiomeMap biomeMap; + private BiomeMap biomeMap; private final long seed; @Deprecated(forRemoval = true) @@ -60,7 +62,13 @@ public class BCLibNetherBiomeSource extends BiomeSource { BiomeAPI.NETHER_BIOME_PICKER.getBiomes().forEach(biome -> biome.updateActualBiomes(biomeRegistry)); BiomeAPI.NETHER_BIOME_PICKER.rebuild(); - this.biomeMap = new HexBiomeMap(seed, GeneratorOptions.getBiomeSizeNether(), BiomeAPI.NETHER_BIOME_PICKER); + if (GeneratorOptions.useOldBiomeGenerator()) { + this.biomeMap = new SquareBiomeMap(seed, GeneratorOptions.getBiomeSizeNether(), BiomeAPI.NETHER_BIOME_PICKER); + } + else { + this.biomeMap = new HexBiomeMap(seed, GeneratorOptions.getBiomeSizeNether(), BiomeAPI.NETHER_BIOME_PICKER); + } + this.biomeRegistry = biomeRegistry; this.seed = seed; diff --git a/src/main/java/ru/bclib/world/generator/GeneratorOptions.java b/src/main/java/ru/bclib/world/generator/GeneratorOptions.java index af5c084d..76032ab9 100644 --- a/src/main/java/ru/bclib/world/generator/GeneratorOptions.java +++ b/src/main/java/ru/bclib/world/generator/GeneratorOptions.java @@ -16,6 +16,7 @@ public class GeneratorOptions { private static boolean customEndBiomeSource = true; private static boolean addNetherBiomesByCategory = false; private static boolean addEndBiomesByCategory = false; + private static boolean useOldBiomeGenerator = false; public static void init() { biomeSizeNether = Configs.GENERATOR_CONFIG.getInt("nether.biomeMap", "biomeSize", 256); @@ -25,6 +26,7 @@ public class GeneratorOptions { customEndBiomeSource = Configs.GENERATOR_CONFIG.getBoolean("options", "customEndBiomeSource", true); addNetherBiomesByCategory = Configs.GENERATOR_CONFIG.getBoolean("options", "addNetherBiomesByCategory", false); addEndBiomesByCategory = Configs.GENERATOR_CONFIG.getBoolean("options", "addEndBiomesByCategory", false); + useOldBiomeGenerator = Configs.GENERATOR_CONFIG.getBoolean("options", "useOldBiomeGenerator", false); } public static int getBiomeSizeNether() { @@ -70,4 +72,8 @@ public class GeneratorOptions { public static boolean addEndBiomesByCategory() { return addEndBiomesByCategory; } + + public static boolean useOldBiomeGenerator() { + return useOldBiomeGenerator; + } } diff --git a/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeMap.java b/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeMap.java index 0eafcad3..704a3c89 100644 --- a/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeMap.java +++ b/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeMap.java @@ -1,5 +1,6 @@ package ru.bclib.world.generator.map.hex; +import ru.bclib.interfaces.BiomeMap; import ru.bclib.noise.OpenSimplexNoise; import ru.bclib.util.MHelper; import ru.bclib.world.biomes.BCLBiome; @@ -9,7 +10,7 @@ import java.awt.Point; import java.util.HashMap; import java.util.Random; -public class HexBiomeMap { +public class HexBiomeMap implements BiomeMap { private static final float RAD_INNER = (float) Math.sqrt(3.0) * 0.5F; private static final float COEF = 0.25F * (float) Math.sqrt(3.0); private static final float COEF_HALF = COEF * 0.5F; @@ -38,12 +39,14 @@ public class HexBiomeMap { this.seed = (int) (seed & 0xFFFFFFFF); } + @Override public void clearCache() { if (chunks.size() > 127) { chunks.clear(); } } + @Override public BCLBiome getBiome(double x, double z) { BCLBiome BCLBiome = getRawBiome(x, z); if (BCLBiome.getEdge() != null) { diff --git a/src/main/java/ru/bclib/world/generator/map/square/SquareBiomeChunk.java b/src/main/java/ru/bclib/world/generator/map/square/SquareBiomeChunk.java index 9b057ffd..c4d366b6 100644 --- a/src/main/java/ru/bclib/world/generator/map/square/SquareBiomeChunk.java +++ b/src/main/java/ru/bclib/world/generator/map/square/SquareBiomeChunk.java @@ -5,7 +5,6 @@ import ru.bclib.world.generator.BiomePicker; import java.util.Random; -@Deprecated public class SquareBiomeChunk { private static final int BIT_OFFSET = 4; protected static final int WIDTH = 1 << BIT_OFFSET; @@ -19,7 +18,7 @@ public class SquareBiomeChunk { private final BCLBiome[] biomes; - public SquareBiomeChunk(SquareBiomeMap map, Random random, BiomePicker picker) { + public SquareBiomeChunk(Random random, BiomePicker picker) { BCLBiome[] PreBio = new BCLBiome[SM_CAPACITY]; biomes = new BCLBiome[CAPACITY]; diff --git a/src/main/java/ru/bclib/world/generator/map/square/SquareBiomeMap.java b/src/main/java/ru/bclib/world/generator/map/square/SquareBiomeMap.java index 022366c4..6c523db8 100644 --- a/src/main/java/ru/bclib/world/generator/map/square/SquareBiomeMap.java +++ b/src/main/java/ru/bclib/world/generator/map/square/SquareBiomeMap.java @@ -4,6 +4,7 @@ import com.google.common.collect.Maps; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.levelgen.LegacyRandomSource; import net.minecraft.world.level.levelgen.WorldgenRandom; +import ru.bclib.interfaces.BiomeMap; import ru.bclib.noise.OpenSimplexNoise; import ru.bclib.util.MHelper; import ru.bclib.world.biomes.BCLBiome; @@ -11,24 +12,23 @@ import ru.bclib.world.generator.BiomePicker; import java.util.Map; -@Deprecated -public class SquareBiomeMap { - private final WorldgenRandom RANDOM; - +public class SquareBiomeMap implements BiomeMap { private final Map maps = Maps.newHashMap(); - private final int size; - private final int sizeXZ; - private final int depth; private final OpenSimplexNoise noiseX; private final OpenSimplexNoise noiseZ; + private final WorldgenRandom random; private final BiomePicker picker; + private final long seed; + private final int sizeXZ; + private final int depth; + private final int size; public SquareBiomeMap(long seed, int size, BiomePicker picker) { maps.clear(); - RANDOM = new WorldgenRandom(new LegacyRandomSource(seed)); - noiseX = new OpenSimplexNoise(RANDOM.nextLong()); - noiseZ = new OpenSimplexNoise(RANDOM.nextLong()); + random = new WorldgenRandom(new LegacyRandomSource(seed)); + noiseX = new OpenSimplexNoise(random.nextLong()); + noiseZ = new OpenSimplexNoise(random.nextLong()); this.sizeXZ = size; depth = (int) Math.ceil(Math.log(size) / Math.log(2)) - 2; this.size = 1 << depth; @@ -36,57 +36,15 @@ public class SquareBiomeMap { this.seed = seed; } - public long getSeed() { - return seed; - } - + @Override public void clearCache() { if (maps.size() > 32) { maps.clear(); } } - private BCLBiome getRawBiome(int bx, int bz) { - double x = (double) bx * size / sizeXZ; - double z = (double) bz * size / sizeXZ; - double nx = x; - double nz = z; - - double px = bx * 0.2; - double pz = bz * 0.2; - - for (int i = 0; i < depth; i++) { - nx = (x + noiseX.eval(px, pz)) / 2F; - nz = (z + noiseZ.eval(px, pz)) / 2F; - - x = nx; - z = nz; - - px = px / 2 + i; - pz = pz / 2 + i; - } - - bx = MHelper.floor(x); - bz = MHelper.floor(z); - if ((bx & SquareBiomeChunk.MASK_WIDTH) == SquareBiomeChunk.MASK_WIDTH) { - x += (bz / 2) & 1; - } - if ((bz & SquareBiomeChunk.MASK_WIDTH) == SquareBiomeChunk.MASK_WIDTH) { - z += (bx / 2) & 1; - } - - ChunkPos cpos = new ChunkPos(MHelper.floor(x / SquareBiomeChunk.WIDTH), MHelper.floor(z / SquareBiomeChunk.WIDTH)); - SquareBiomeChunk chunk = maps.get(cpos); - if (chunk == null) { - RANDOM.setLargeFeatureWithSalt(0, cpos.x, cpos.z, 0); - chunk = new SquareBiomeChunk(this, RANDOM, picker); - maps.put(cpos, chunk); - } - - return chunk.getBiome(MHelper.floor(x), MHelper.floor(z)); - } - - public BCLBiome getBiome(int x, int z) { + @Override + public BCLBiome getBiome(double x, double z) { BCLBiome biome = getRawBiome(x, z); if (biome.getEdge() != null || (biome.getParentBiome() != null && biome.getParentBiome().getEdge() != null)) { @@ -112,4 +70,44 @@ public class SquareBiomeMap { return biome; } + + private BCLBiome getRawBiome(double bx, double bz) { + double x = bx * size / sizeXZ; + double z = bz * size / sizeXZ; + double nx = x; + double nz = z; + + double px = bx * 0.2; + double pz = bz * 0.2; + + for (int i = 0; i < depth; i++) { + nx = (x + noiseX.eval(px, pz)) / 2F; + nz = (z + noiseZ.eval(px, pz)) / 2F; + + x = nx; + z = nz; + + px = px / 2 + i; + pz = pz / 2 + i; + } + + int ix = MHelper.floor(x); + int iz = MHelper.floor(z); + if ((ix & SquareBiomeChunk.MASK_WIDTH) == SquareBiomeChunk.MASK_WIDTH) { + x += (iz / 2) & 1; + } + if ((iz & SquareBiomeChunk.MASK_WIDTH) == SquareBiomeChunk.MASK_WIDTH) { + z += (ix / 2) & 1; + } + + ChunkPos cpos = new ChunkPos(MHelper.floor(x / SquareBiomeChunk.WIDTH), MHelper.floor(z / SquareBiomeChunk.WIDTH)); + SquareBiomeChunk chunk = maps.get(cpos); + if (chunk == null) { + random.setLargeFeatureWithSalt(0, cpos.x, cpos.z, 0); + chunk = new SquareBiomeChunk(random, picker); + maps.put(cpos, chunk); + } + + return chunk.getBiome(MHelper.floor(x), MHelper.floor(z)); + } } From 3801c44aab094188e45e8a24517b5297b323902e Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 1 Dec 2021 18:01:51 +0100 Subject: [PATCH 46/96] let Builder add some vanilla features --- .../ru/bclib/api/biomes/BCLBiomeBuilder.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index f49e6935..405270b1 100644 --- a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java @@ -1,6 +1,8 @@ package ru.bclib.api.biomes; import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.data.worldgen.BiomeDefaultFeatures; +import net.minecraft.data.worldgen.placement.OrePlacements; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.Music; import net.minecraft.sounds.SoundEvent; @@ -10,10 +12,12 @@ import net.minecraft.world.entity.Mob; import net.minecraft.world.level.biome.AmbientAdditionsSettings; import net.minecraft.world.level.biome.AmbientMoodSettings; import net.minecraft.world.level.biome.AmbientParticleSettings; +import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome.BiomeBuilder; import net.minecraft.world.level.biome.Biome.BiomeCategory; import net.minecraft.world.level.biome.Biome.Precipitation; import net.minecraft.world.level.biome.BiomeGenerationSettings; +import net.minecraft.world.level.biome.BiomeGenerationSettings.Builder; import net.minecraft.world.level.biome.BiomeSpecialEffects; import net.minecraft.world.level.biome.MobSpawnSettings; import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; @@ -400,6 +404,24 @@ public class BCLBiomeBuilder { return this; } + /** + * Adds vanilla Mushrooms. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder defaultMushrooms(){ + BiomeDefaultFeatures.addDefaultMushrooms(getGeneration()); + return this; + } + + /** + * Adds vanilla Nether Ores. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder netherDefaultOres(){ + BiomeDefaultFeatures.addNetherDefaultOres(getGeneration()); + return this; + } + /** * Adds new feature to the biome. * @param feature {@link BCLFeature}. From 9f9849d9b09a2bd53b4752ad07e119989fa3458a Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 1 Dec 2021 19:38:57 +0100 Subject: [PATCH 47/96] Make sure we do not crash out --- src/main/java/ru/bclib/world/generator/map/hex/HexBiomeMap.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeMap.java b/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeMap.java index 704a3c89..1d99916a 100644 --- a/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeMap.java +++ b/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeMap.java @@ -49,7 +49,7 @@ public class HexBiomeMap implements BiomeMap { @Override public BCLBiome getBiome(double x, double z) { BCLBiome BCLBiome = getRawBiome(x, z); - if (BCLBiome.getEdge() != null) { + if (BCLBiome!=null && BCLBiome.getEdge() != null) { float offset = scale * BCLBiome.getEdgeSize(); for (byte i = 0; i < 8; i++) { if (getRawBiome(x + offset * EDGE_CIRCLE_X[i], z + offset * EDGE_CIRCLE_Z[i]) != BCLBiome) { From 59d2874c1a403b530fedaed07ad43b992bb346c1 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Thu, 2 Dec 2021 01:10:55 +0300 Subject: [PATCH 48/96] Custom biome class init --- .../java/ru/bclib/api/biomes/BCLBiomeBuilder.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index 405270b1..e63623e8 100644 --- a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java @@ -27,6 +27,8 @@ import ru.bclib.util.ColorUtil; import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.features.BCLFeature; +import java.util.function.BiFunction; + public class BCLBiomeBuilder { private static final BCLBiomeBuilder INSTANCE = new BCLBiomeBuilder(); @@ -436,6 +438,15 @@ public class BCLBiomeBuilder { * @return created {@link BCLBiome} instance. */ public BCLBiome build() { + return build(BCLBiome::new); + } + + /** + * Finalize biome creation. + * @param biomeConstructor {@link BiFunction} biome constructor. + * @return created {@link BCLBiome} instance. + */ + public BCLBiome build(BiFunction biomeConstructor) { BiomeBuilder builder = new BiomeBuilder() .precipitation(precipitation) .biomeCategory(category) @@ -454,7 +465,7 @@ public class BCLBiomeBuilder { builder.generationSettings(generationSettings.build()); } - return new BCLBiome(biomeID, builder.build()).setFogDensity(fogDensity); + return biomeConstructor.apply(biomeID, builder.build()).setFogDensity(fogDensity); } /** From 0bfefa460f71b6d985100f46d90b02d9a5bc4d5d Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Thu, 2 Dec 2021 01:56:26 +0300 Subject: [PATCH 49/96] Possible hexmap fixes & tests --- .../ru/bclib/api/biomes/BCLBiomeBuilder.java | 25 +++++++++++++++---- .../generator/map/hex/HexBiomeChunk.java | 3 +++ .../world/generator/map/hex/HexBiomeMap.java | 23 ++++++++++------- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index e63623e8..880a936f 100644 --- a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java @@ -26,8 +26,10 @@ import net.minecraft.world.level.levelgen.placement.PlacedFeature; import ru.bclib.util.ColorUtil; import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.features.BCLFeature; +import ru.bclib.world.structures.BCLStructureFeature; import java.util.function.BiFunction; +import java.util.function.Consumer; public class BCLBiomeBuilder { private static final BCLBiomeBuilder INSTANCE = new BCLBiomeBuilder(); @@ -410,17 +412,25 @@ public class BCLBiomeBuilder { * Adds vanilla Mushrooms. * @return same {@link BCLBiomeBuilder} instance. */ - public BCLBiomeBuilder defaultMushrooms(){ - BiomeDefaultFeatures.addDefaultMushrooms(getGeneration()); - return this; + public BCLBiomeBuilder defaultMushrooms() { + return feature(BiomeDefaultFeatures::addDefaultMushrooms); } /** * Adds vanilla Nether Ores. * @return same {@link BCLBiomeBuilder} instance. */ - public BCLBiomeBuilder netherDefaultOres(){ - BiomeDefaultFeatures.addNetherDefaultOres(getGeneration()); + public BCLBiomeBuilder netherDefaultOres() { + return feature(BiomeDefaultFeatures::addNetherDefaultOres); + } + + /** + * Will add features into biome, used for vanilla feature adding functions. + * @param featureAdd {@link Consumer} with {@link BiomeGenerationSettings.Builder}. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder feature(Consumer featureAdd) { + featureAdd.accept(getGeneration()); return this; } @@ -433,6 +443,11 @@ public class BCLBiomeBuilder { return feature(feature.getDecoration(), feature.getPlacedFeature()); } + // TODO Make feature registration + public BCLBiomeBuilder structure(BCLStructureFeature structure) { + return this; + } + /** * Finalize biome creation. * @return created {@link BCLBiome} instance. diff --git a/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeChunk.java b/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeChunk.java index fa737803..77887f9e 100644 --- a/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeChunk.java +++ b/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeChunk.java @@ -65,6 +65,9 @@ public class HexBiomeChunk { } for (short index = 0; index < SIZE; index++) { + if (outBuffer[index] == null) { + System.out.println("Buffer is null at " + index + ": " + (index >> SIDE_OFFSET) + " " + (index & SIDE_MASK)); + } if (outBuffer[index] != null && random.nextInt(4) == 0) { circle(outBuffer, index, outBuffer[index].getSubBiome(random), outBuffer[index]); } diff --git a/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeMap.java b/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeMap.java index 1d99916a..812807fe 100644 --- a/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeMap.java +++ b/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeMap.java @@ -48,16 +48,16 @@ public class HexBiomeMap implements BiomeMap { @Override public BCLBiome getBiome(double x, double z) { - BCLBiome BCLBiome = getRawBiome(x, z); - if (BCLBiome!=null && BCLBiome.getEdge() != null) { - float offset = scale * BCLBiome.getEdgeSize(); + BCLBiome biome = getRawBiome(x, z); + if (biome.getEdge() != null) { + float offset = scale * biome.getEdgeSize(); for (byte i = 0; i < 8; i++) { - if (getRawBiome(x + offset * EDGE_CIRCLE_X[i], z + offset * EDGE_CIRCLE_Z[i]) != BCLBiome) { - return BCLBiome.getEdge(); + if (getRawBiome(x + offset * EDGE_CIRCLE_X[i], z + offset * EDGE_CIRCLE_Z[i]) != biome) { + return biome.getEdge(); } } } - return BCLBiome; + return biome; } private BCLBiome getRawBiome(double x, double z) { @@ -112,13 +112,18 @@ public class HexBiomeMap implements BiomeMap { cz += 1; } - selector.setLocation(cx, cz); - HexBiomeChunk chunk = chunks.get(selector); + HexBiomeChunk chunk; + synchronized (selector) { + selector.setLocation(cx, cz); + chunk = chunks.get(selector); + } + if (chunk == null) { RANDOM.setSeed(MHelper.getSeed(seed, cx, cz)); chunk = new HexBiomeChunk(RANDOM, picker); - chunks.put(new Point(selector), chunk); + chunks.put(new Point(cx, cz), chunk); } + return chunk.getBiome(x, z); } From 7daf9f614c079f14e984e966a95ee51e1069caaf Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Thu, 2 Dec 2021 03:34:04 +0300 Subject: [PATCH 50/96] Hex biome map fixes --- .../java/ru/bclib/world/generator/map/hex/HexBiomeChunk.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeChunk.java b/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeChunk.java index 77887f9e..0edd9a8f 100644 --- a/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeChunk.java +++ b/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeChunk.java @@ -66,9 +66,9 @@ public class HexBiomeChunk { for (short index = 0; index < SIZE; index++) { if (outBuffer[index] == null) { - System.out.println("Buffer is null at " + index + ": " + (index >> SIDE_OFFSET) + " " + (index & SIDE_MASK)); + outBuffer[index] = picker.getBiome(random); } - if (outBuffer[index] != null && random.nextInt(4) == 0) { + else if (random.nextInt(4) == 0) { circle(outBuffer, index, outBuffer[index].getSubBiome(random), outBuffer[index]); } } From 6c2c943b0d329eb9e47e72cb35eb47dda58bc053 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Thu, 2 Dec 2021 04:49:56 +0300 Subject: [PATCH 51/96] Biome generator fix --- .../ru/bclib/api/biomes/BCLBiomeBuilder.java | 2 - .../handler/autosync/Chunker.java | 2 +- .../handler/autosync/HelloClient.java | 2 +- .../handler/autosync/HelloServer.java | 2 +- .../handler/autosync/RequestFiles.java | 2 +- .../handler/autosync/SendFiles.java | 2 +- .../java/ru/bclib/api/datafixer/Patch.java | 27 ++------ .../mixin/common/DimensionTypeMixin.java | 63 +++++++++++++++++++ src/main/resources/bclib.mixins.common.json | 1 + 9 files changed, 75 insertions(+), 28 deletions(-) create mode 100644 src/main/java/ru/bclib/mixin/common/DimensionTypeMixin.java diff --git a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index 880a936f..80d28aae 100644 --- a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java @@ -2,7 +2,6 @@ package ru.bclib.api.biomes; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.data.worldgen.BiomeDefaultFeatures; -import net.minecraft.data.worldgen.placement.OrePlacements; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.Music; import net.minecraft.sounds.SoundEvent; @@ -17,7 +16,6 @@ import net.minecraft.world.level.biome.Biome.BiomeBuilder; import net.minecraft.world.level.biome.Biome.BiomeCategory; import net.minecraft.world.level.biome.Biome.Precipitation; import net.minecraft.world.level.biome.BiomeGenerationSettings; -import net.minecraft.world.level.biome.BiomeGenerationSettings.Builder; import net.minecraft.world.level.biome.BiomeSpecialEffects; import net.minecraft.world.level.biome.MobSpawnSettings; import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; diff --git a/src/main/java/ru/bclib/api/dataexchange/handler/autosync/Chunker.java b/src/main/java/ru/bclib/api/dataexchange/handler/autosync/Chunker.java index 33a16719..bc669f3b 100644 --- a/src/main/java/ru/bclib/api/dataexchange/handler/autosync/Chunker.java +++ b/src/main/java/ru/bclib/api/dataexchange/handler/autosync/Chunker.java @@ -189,7 +189,7 @@ public class Chunker extends DataHandler.FromServer { public static final int MAX_PACKET_SIZE = 1024*1024; private static final int MAX_PAYLOAD_SIZE = MAX_PACKET_SIZE - HEADER_SIZE; - public static DataHandlerDescriptor DESCRIPTOR = new DataHandlerDescriptor(new ResourceLocation(BCLib.MOD_ID, "chunker"), Chunker::new, false, false); + public static final DataHandlerDescriptor DESCRIPTOR = new DataHandlerDescriptor(new ResourceLocation(BCLib.MOD_ID, "chunker"), Chunker::new, false, false); private int serialNo; private UUID uuid; diff --git a/src/main/java/ru/bclib/api/dataexchange/handler/autosync/HelloClient.java b/src/main/java/ru/bclib/api/dataexchange/handler/autosync/HelloClient.java index 83762718..206735d4 100644 --- a/src/main/java/ru/bclib/api/dataexchange/handler/autosync/HelloClient.java +++ b/src/main/java/ru/bclib/api/dataexchange/handler/autosync/HelloClient.java @@ -48,7 +48,7 @@ public class HelloClient extends DataHandler.FromServer { public interface IServerModMap extends Map {} public static class ServerModMap extends HashMap implements IServerModMap {} - public static DataHandlerDescriptor DESCRIPTOR = new DataHandlerDescriptor(new ResourceLocation(BCLib.MOD_ID, "hello_client"), HelloClient::new, false, false); + public static final DataHandlerDescriptor DESCRIPTOR = new DataHandlerDescriptor(new ResourceLocation(BCLib.MOD_ID, "hello_client"), HelloClient::new, false, false); public HelloClient() { super(DESCRIPTOR.IDENTIFIER); diff --git a/src/main/java/ru/bclib/api/dataexchange/handler/autosync/HelloServer.java b/src/main/java/ru/bclib/api/dataexchange/handler/autosync/HelloServer.java index a3abd668..300f8ba6 100644 --- a/src/main/java/ru/bclib/api/dataexchange/handler/autosync/HelloServer.java +++ b/src/main/java/ru/bclib/api/dataexchange/handler/autosync/HelloServer.java @@ -57,7 +57,7 @@ import java.io.File; * */ public class HelloServer extends DataHandler.FromClient { - public static DataHandlerDescriptor DESCRIPTOR = new DataHandlerDescriptor(new ResourceLocation(BCLib.MOD_ID, "hello_server"), HelloServer::new, true, false); + public static final DataHandlerDescriptor DESCRIPTOR = new DataHandlerDescriptor(new ResourceLocation(BCLib.MOD_ID, "hello_server"), HelloServer::new, true, false); protected String bclibVersion = "0.0.0"; diff --git a/src/main/java/ru/bclib/api/dataexchange/handler/autosync/RequestFiles.java b/src/main/java/ru/bclib/api/dataexchange/handler/autosync/RequestFiles.java index 45579906..6e69dd8a 100644 --- a/src/main/java/ru/bclib/api/dataexchange/handler/autosync/RequestFiles.java +++ b/src/main/java/ru/bclib/api/dataexchange/handler/autosync/RequestFiles.java @@ -17,7 +17,7 @@ import java.util.UUID; import java.util.stream.Collectors; public class RequestFiles extends DataHandler.FromClient { - public static DataHandlerDescriptor DESCRIPTOR = new DataHandlerDescriptor(new ResourceLocation(BCLib.MOD_ID, "request_files"), RequestFiles::new, false, false); + public static final DataHandlerDescriptor DESCRIPTOR = new DataHandlerDescriptor(new ResourceLocation(BCLib.MOD_ID, "request_files"), RequestFiles::new, false, false); static String currentToken = ""; protected List files; diff --git a/src/main/java/ru/bclib/api/dataexchange/handler/autosync/SendFiles.java b/src/main/java/ru/bclib/api/dataexchange/handler/autosync/SendFiles.java index 000be5c0..2b3e419a 100644 --- a/src/main/java/ru/bclib/api/dataexchange/handler/autosync/SendFiles.java +++ b/src/main/java/ru/bclib/api/dataexchange/handler/autosync/SendFiles.java @@ -24,7 +24,7 @@ import java.util.List; import java.util.stream.Collectors; public class SendFiles extends DataHandler.FromServer { - public static DataHandlerDescriptor DESCRIPTOR = new DataHandlerDescriptor(new ResourceLocation(BCLib.MOD_ID, "send_files"), SendFiles::new, false, false); + public static final DataHandlerDescriptor DESCRIPTOR = new DataHandlerDescriptor(new ResourceLocation(BCLib.MOD_ID, "send_files"), SendFiles::new, false, false); protected List files; private String token; diff --git a/src/main/java/ru/bclib/api/datafixer/Patch.java b/src/main/java/ru/bclib/api/datafixer/Patch.java index 30a26ce7..4fcb48be 100644 --- a/src/main/java/ru/bclib/api/datafixer/Patch.java +++ b/src/main/java/ru/bclib/api/datafixer/Patch.java @@ -13,8 +13,7 @@ import java.util.List; import java.util.Map; public abstract class Patch { - - private static List ALL = new ArrayList<>(10); + private static final List ALL = new ArrayList<>(10); /** * The Patch-Level derived from {@link #version} @@ -50,12 +49,7 @@ public abstract class Patch { * @return The highest Patch-Version that was found */ public static String maxPatchVersion(@NotNull String modID) { - return ALL.stream() - .filter(p -> p.modID - .equals(modID)) - .map(p -> p.version) - .reduce((p, c) -> c) - .orElse("0.0.0"); + return ALL.stream().filter(p -> p.modID.equals(modID)).map(p -> p.version).reduce((p, c) -> c).orElse("0.0.0"); } /** @@ -66,12 +60,7 @@ public abstract class Patch { * @return The highest Patch-Level that was found */ public static int maxPatchLevel(@NotNull String modID) { - return ALL.stream() - .filter(p -> p.modID - .equals(modID)) - .mapToInt(p -> p.level) - .max() - .orElse(0); + return ALL.stream().filter(p -> p.modID.equals(modID)).mapToInt(p -> p.level).max().orElse(0); } /** @@ -103,21 +92,18 @@ public abstract class Patch { */ Patch(@NotNull String modID, String version, boolean alwaysApply) { //Patchlevels need to be unique and registered in ascending order - if (modID == null || "".equals(modID)) { + if (modID == null || modID.isEmpty()) { throw new RuntimeException("[INTERNAL ERROR] Patches need a valid modID!"); } - if (version == null || "".equals(version)) { + if (version == null || version.isEmpty()) { throw new RuntimeException("Invalid Mod-Version"); } this.version = version; this.alwaysApply = alwaysApply; this.level = ModUtil.convertModVersion(version); - if (!ALL.stream() - .filter(p -> p.modID - .equals(modID)) - .noneMatch(p -> p.level >= this.level) || this.level <= 0) { + if (!ALL.stream().filter(p -> p.modID.equals(modID)).noneMatch(p -> p.level >= this.level) || this.level <= 0) { throw new RuntimeException("[INTERNAL ERROR] Patch-levels need to be created in ascending order beginning with 1."); } @@ -239,5 +225,4 @@ public abstract class Patch { public List getWorldDataIDPaths() { return null; } - } diff --git a/src/main/java/ru/bclib/mixin/common/DimensionTypeMixin.java b/src/main/java/ru/bclib/mixin/common/DimensionTypeMixin.java new file mode 100644 index 00000000..3b73c4bf --- /dev/null +++ b/src/main/java/ru/bclib/mixin/common/DimensionTypeMixin.java @@ -0,0 +1,63 @@ +package ru.bclib.mixin.common; + +import com.mojang.serialization.Lifecycle; +import net.minecraft.core.MappedRegistry; +import net.minecraft.core.Registry; +import net.minecraft.core.RegistryAccess; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.dimension.DimensionType; +import net.minecraft.world.level.dimension.LevelStem; +import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator; +import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; +import net.minecraft.world.level.levelgen.synth.NormalNoise; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; +import ru.bclib.world.generator.BCLibEndBiomeSource; +import ru.bclib.world.generator.BCLibNetherBiomeSource; + +import java.util.OptionalInt; + +@Mixin(DimensionType.class) +public class DimensionTypeMixin { + @Inject( + method = "defaultDimensions(Lnet/minecraft/core/RegistryAccess;JZ)Lnet/minecraft/core/MappedRegistry;", + locals = LocalCapture.CAPTURE_FAILHARD, + at = @At("TAIL") + ) + private static void bclib_updateDimensions(RegistryAccess registryAccess, long seed, boolean bl, CallbackInfoReturnable> info, MappedRegistry mappedRegistry, Registry registry, Registry biomeRegistry, Registry noiseSettingsRegistry, Registry noiseParamRegistry) { + int id = mappedRegistry.getId(mappedRegistry.get(LevelStem.NETHER)); + mappedRegistry.registerOrOverride( + OptionalInt.of(id), + LevelStem.NETHER, + new LevelStem( + () -> registry.getOrThrow(DimensionType.NETHER_LOCATION), + new NoiseBasedChunkGenerator( + noiseParamRegistry, + new BCLibNetherBiomeSource(biomeRegistry, seed), + seed, + () -> noiseSettingsRegistry.getOrThrow(NoiseGeneratorSettings.NETHER) + ) + ), + Lifecycle.stable() + ); + + id = mappedRegistry.getId(mappedRegistry.get(LevelStem.END)); + mappedRegistry.registerOrOverride( + OptionalInt.of(id), + LevelStem.END, + new LevelStem( + () -> registry.getOrThrow(DimensionType.END_LOCATION), + new NoiseBasedChunkGenerator( + noiseParamRegistry, + new BCLibEndBiomeSource(biomeRegistry, seed), + seed, + () -> noiseSettingsRegistry.getOrThrow(NoiseGeneratorSettings.END) + ) + ), + Lifecycle.stable() + ); + } +} diff --git a/src/main/resources/bclib.mixins.common.json b/src/main/resources/bclib.mixins.common.json index bb587aa9..7e9c2373 100644 --- a/src/main/resources/bclib.mixins.common.json +++ b/src/main/resources/bclib.mixins.common.json @@ -25,6 +25,7 @@ "ChunkGeneratorMixin", "WorldGenRegionMixin", "WorldGenRegionMixin", + "DimensionTypeMixin", "RecipeManagerMixin", "RecipeManagerMixin", "BoneMealItemMixin", From 31f61f3f37b14c97a17f4b6eb8bb763abf988fff Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Thu, 2 Dec 2021 05:23:21 +0300 Subject: [PATCH 52/96] Biome configuration fix --- .../java/ru/bclib/api/biomes/BiomeAPI.java | 19 ++++++++++++-- src/main/java/ru/bclib/config/Configs.java | 12 ++++----- .../world/generator/BCLibEndBiomeSource.java | 25 +++++++++++++++---- .../generator/BCLibNetherBiomeSource.java | 5 +++- 4 files changed, 47 insertions(+), 14 deletions(-) diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index 1ef912f2..ac80904a 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -27,6 +27,7 @@ import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import net.minecraft.world.level.levelgen.placement.PlacedFeature; import org.jetbrains.annotations.Nullable; +import ru.bclib.config.Configs; import ru.bclib.util.MHelper; import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.biomes.FabricBiomesData; @@ -140,6 +141,7 @@ public class BiomeAPI { */ public static BCLBiome registerNetherBiome(Biome biome) { BCLBiome bclBiome = new BCLBiome(biome); + configureBiome(bclBiome, 1.0F, 1.0F); NETHER_BIOME_PICKER.addBiome(bclBiome); registerBiome(bclBiome); return bclBiome; @@ -153,6 +155,7 @@ public class BiomeAPI { */ public static BCLBiome registerEndLandBiome(BCLBiome biome) { registerBiome(biome); + configureBiome(biome, 1.0F, 1.0F); END_LAND_BIOME_PICKER.addBiome(biome); float weight = biome.getGenChance(); ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get(); @@ -169,6 +172,7 @@ public class BiomeAPI { */ public static BCLBiome registerEndLandBiome(Biome biome) { BCLBiome bclBiome = new BCLBiome(biome); + configureBiome(bclBiome, 1.0F, 1.0F); END_LAND_BIOME_PICKER.addBiome(bclBiome); registerBiome(bclBiome); return bclBiome; @@ -182,7 +186,8 @@ public class BiomeAPI { * @return {@link BCLBiome} */ public static BCLBiome registerEndLandBiome(Biome biome, float genChance) { - BCLBiome bclBiome = new BCLBiome(biome).setGenChance(genChance); + BCLBiome bclBiome = new BCLBiome(biome); + configureBiome(bclBiome, genChance, 1.0F); END_LAND_BIOME_PICKER.addBiome(bclBiome); registerBiome(bclBiome); return bclBiome; @@ -196,6 +201,7 @@ public class BiomeAPI { */ public static BCLBiome registerEndVoidBiome(BCLBiome biome) { registerBiome(biome); + configureBiome(biome, 1.0F, 1.0F); END_VOID_BIOME_PICKER.addBiome(biome); float weight = biome.getGenChance(); ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get(); @@ -211,6 +217,7 @@ public class BiomeAPI { */ public static BCLBiome registerEndVoidBiome(Biome biome) { BCLBiome bclBiome = new BCLBiome(biome); + configureBiome(bclBiome, 1.0F, 1.0F); END_VOID_BIOME_PICKER.addBiome(bclBiome); registerBiome(bclBiome); return bclBiome; @@ -225,7 +232,8 @@ public class BiomeAPI { */ public static BCLBiome registerEndVoidBiome(Biome biome, float genChance) { ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome).get(); - BCLBiome bclBiome = new BCLBiome(biome).setGenChance(genChance); + BCLBiome bclBiome = new BCLBiome(biome); + configureBiome(bclBiome, genChance, 1.0F); END_VOID_BIOME_PICKER.addBiome(bclBiome); registerBiome(bclBiome); return bclBiome; @@ -488,4 +496,11 @@ public class BiomeAPI { maxGroupCount ); } + + private static void configureBiome(BCLBiome biome, float chance, float fog) { + String group = biome.getID().getNamespace() + "." + biome.getID().getPath(); + chance = Configs.BIOMES_CONFIG.getFloat(group, "generation_chance", chance); + fog = Configs.BIOMES_CONFIG.getFloat(group, "fog_density", fog); + biome.setGenChance(chance).setFogDensity(fog); + } } diff --git a/src/main/java/ru/bclib/config/Configs.java b/src/main/java/ru/bclib/config/Configs.java index deac17d2..1e82f759 100644 --- a/src/main/java/ru/bclib/config/Configs.java +++ b/src/main/java/ru/bclib/config/Configs.java @@ -26,12 +26,12 @@ public class Configs { MAIN_CONFIG.saveChanges(); RECIPE_CONFIG.saveChanges(); GENERATOR_CONFIG.saveChanges(); - initForcedConfig(); - } - - private static void initForcedConfig() { - BIOMES_CONFIG.keeper.registerEntry(new ConfigKey("end_biomes", "force_include"), new StringArrayEntry(Collections.EMPTY_LIST)); - BIOMES_CONFIG.keeper.registerEntry(new ConfigKey("nether_biomes", "force_include"), new StringArrayEntry(Collections.EMPTY_LIST)); BIOMES_CONFIG.saveChanges(); } + + static { + BIOMES_CONFIG.keeper.registerEntry(new ConfigKey("end_land_biomes", "force_include"), new StringArrayEntry(Collections.EMPTY_LIST)); + BIOMES_CONFIG.keeper.registerEntry(new ConfigKey("end_void_biomes", "force_include"), new StringArrayEntry(Collections.EMPTY_LIST)); + BIOMES_CONFIG.keeper.registerEntry(new ConfigKey("nether_biomes", "force_include"), new StringArrayEntry(Collections.EMPTY_LIST)); + } } diff --git a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java index 1fb41e50..9392481f 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java @@ -53,17 +53,31 @@ public class BCLibEndBiomeSource extends BiomeSource { BiomeAPI.END_LAND_BIOME_PICKER.clearMutables(); BiomeAPI.END_VOID_BIOME_PICKER.clearMutables(); + List includeVoid = Configs.BIOMES_CONFIG.getEntry("force_include", "end_void_biomes", StringArrayEntry.class).getValue(); this.possibleBiomes().forEach(biome -> { ResourceLocation key = biomeRegistry.getKey(biome); if (!BiomeAPI.hasBiome(key)) { - BCLBiome bclBiome = new BCLBiome(key, biome); - BiomeAPI.END_LAND_BIOME_PICKER.addBiomeMutable(bclBiome); + String group = key.getNamespace() + "." + key.getPath(); + float chance = Configs.BIOMES_CONFIG.getFloat(group, "generation_chance", 1.0F); + float fog = Configs.BIOMES_CONFIG.getFloat(group, "fog_density", 1.0F); + BCLBiome bclBiome = new BCLBiome(key, biome).setGenChance(chance).setFogDensity(fog); + if (includeVoid.contains(key.toString())) { + BiomeAPI.END_VOID_BIOME_PICKER.addBiomeMutable(bclBiome); + } + else { + BiomeAPI.END_LAND_BIOME_PICKER.addBiomeMutable(bclBiome); + } } else { BCLBiome bclBiome = BiomeAPI.getBiome(key); if (bclBiome != BiomeAPI.EMPTY_BIOME && bclBiome.getParentBiome() == null) { if (!BiomeAPI.END_LAND_BIOME_PICKER.containsImmutable(key) && !BiomeAPI.END_VOID_BIOME_PICKER.containsImmutable(key)) { - BiomeAPI.END_LAND_BIOME_PICKER.addBiomeMutable(bclBiome); + if (includeVoid.contains(key.toString())) { + BiomeAPI.END_VOID_BIOME_PICKER.addBiomeMutable(bclBiome); + } + else { + BiomeAPI.END_LAND_BIOME_PICKER.addBiomeMutable(bclBiome); + } } } } @@ -100,12 +114,13 @@ public class BCLibEndBiomeSource extends BiomeSource { } private static List getBiomes(Registry biomeRegistry) { - List include = Configs.BIOMES_CONFIG.getEntry("force_include", "end_biomes", StringArrayEntry.class).getValue(); + List includeLand = Configs.BIOMES_CONFIG.getEntry("force_include", "end_land_biomes", StringArrayEntry.class).getValue(); + List includeVoid = Configs.BIOMES_CONFIG.getEntry("force_include", "end_void_biomes", StringArrayEntry.class).getValue(); return biomeRegistry.stream().filter(biome -> { ResourceLocation key = biomeRegistry.getKey(biome); - if (include.contains(key.toString())) { + if (includeLand.contains(key.toString()) || includeVoid.contains(key.toString())) { return true; } diff --git a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java index ad1f157a..9e524341 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java @@ -45,7 +45,10 @@ public class BCLibNetherBiomeSource extends BiomeSource { this.possibleBiomes().forEach(biome -> { ResourceLocation key = biomeRegistry.getKey(biome); if (!BiomeAPI.hasBiome(key)) { - BCLBiome bclBiome = new BCLBiome(key, biome); + String group = key.getNamespace() + "." + key.getPath(); + float chance = Configs.BIOMES_CONFIG.getFloat(group, "generation_chance", 1.0F); + float fog = Configs.BIOMES_CONFIG.getFloat(group, "fog_density", 1.0F); + BCLBiome bclBiome = new BCLBiome(key, biome).setGenChance(chance).setFogDensity(fog); BiomeAPI.NETHER_BIOME_PICKER.addBiomeMutable(bclBiome); } else { From 1c3696fd0283241f8f7155c4e8a060cd048c4191 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Thu, 2 Dec 2021 08:31:42 +0300 Subject: [PATCH 53/96] Prevent random desync --- .../java/ru/bclib/world/generator/map/hex/HexBiomeMap.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeMap.java b/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeMap.java index 812807fe..f7ed1e8e 100644 --- a/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeMap.java +++ b/src/main/java/ru/bclib/world/generator/map/hex/HexBiomeMap.java @@ -119,8 +119,10 @@ public class HexBiomeMap implements BiomeMap { } if (chunk == null) { - RANDOM.setSeed(MHelper.getSeed(seed, cx, cz)); - chunk = new HexBiomeChunk(RANDOM, picker); + synchronized (RANDOM) { + RANDOM.setSeed(MHelper.getSeed(seed, cx, cz)); + chunk = new HexBiomeChunk(RANDOM, picker); + } chunks.put(new Point(cx, cz), chunk); } From 97473004a8822f268b00f4e98fad58935fd71238 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Thu, 2 Dec 2021 12:45:35 +0300 Subject: [PATCH 54/96] Biome Builder structure features --- .../ru/bclib/api/biomes/BCLBiomeBuilder.java | 25 +++++++++++- .../world/structures/BCLStructureFeature.java | 39 +++++++++++++++++-- 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index 80d28aae..1932bbe6 100644 --- a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java @@ -1,6 +1,9 @@ package ru.bclib.api.biomes; +import net.fabricmc.fabric.api.biome.v1.BiomeModifications; +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.ResourceLocation; import net.minecraft.sounds.Music; @@ -20,6 +23,7 @@ import net.minecraft.world.level.biome.BiomeSpecialEffects; import net.minecraft.world.level.biome.MobSpawnSettings; import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; import net.minecraft.world.level.levelgen.GenerationStep.Decoration; +import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import net.minecraft.world.level.levelgen.placement.PlacedFeature; import ru.bclib.util.ColorUtil; import ru.bclib.world.biomes.BCLBiome; @@ -441,11 +445,28 @@ public class BCLBiomeBuilder { return feature(feature.getDecoration(), feature.getPlacedFeature()); } - // TODO Make feature registration - public BCLBiomeBuilder structure(BCLStructureFeature structure) { + /** + * Adds new structure feature into thr biome. + * @param structure {@link ConfiguredStructureFeature} to add. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder structure(ConfiguredStructureFeature structure) { + BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE + .getResourceKey(structure) + .ifPresent(key -> BiomeModifications.addStructure(ctx -> ctx.getBiomeKey().location().equals(biomeID), key)); return this; } + /** + * Adds new structure feature into thr biome. Will add building biome into the structure list. + * @param structure {@link BCLStructureFeature} to add. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder structure(BCLStructureFeature structure) { + structure.addInternalBiome(biomeID); + return structure(structure.getFeatureConfigured()); + } + /** * Finalize biome creation. * @return created {@link BCLBiome} instance. diff --git a/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java b/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java index f171d945..5688a59d 100644 --- a/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java +++ b/src/main/java/ru/bclib/world/structures/BCLStructureFeature.java @@ -1,5 +1,6 @@ package ru.bclib.world.structures; +import com.google.common.collect.Lists; import net.fabricmc.fabric.api.structure.v1.FabricStructureBuilder; import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceLocation; @@ -8,6 +9,7 @@ import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import net.minecraft.world.level.levelgen.feature.StructureFeature; import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration; +import java.util.List; import java.util.Random; public class BCLStructureFeature { @@ -15,13 +17,17 @@ public class BCLStructureFeature { private final StructureFeature structure; private final ConfiguredStructureFeature featureConfigured; private final GenerationStep.Decoration featureStep; + private final List biomes = Lists.newArrayList(); + private final ResourceLocation id; public BCLStructureFeature(ResourceLocation id, StructureFeature structure, GenerationStep.Decoration step, int spacing, int separation) { + this.id = id; this.featureStep = step; - this.structure = FabricStructureBuilder.create(id, structure) - .step(step) - .defaultConfig(spacing, separation, RANDOM.nextInt(8192)) - .register(); + this.structure = FabricStructureBuilder + .create(id, structure) + .step(step) + .defaultConfig(spacing, separation, RANDOM.nextInt(8192)) + .register(); this.featureConfigured = this.structure.configured(NoneFeatureConfiguration.NONE); BuiltinRegistries.register(BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE, id, this.featureConfigured); //TODO: 1.18 check if structures are added correctly @@ -39,4 +45,29 @@ public class BCLStructureFeature { public GenerationStep.Decoration getFeatureStep() { return featureStep; } + + /** + * Get the structure ID; + * @return {@link ResourceLocation} id. + */ + public ResourceLocation getID() { + return id; + } + + /** + * Adds biome into internal biome list, used in {@link ru.bclib.api.biomes.BCLBiomeBuilder}. + * @param biome {@link ResourceLocation} biome ID. + */ + public void addInternalBiome(ResourceLocation biome) { + biomes.add(biome); + } + + /** + * Get biome list where this structure feature can generate. Only represents biomes made with {@link ru.bclib.api.biomes.BCLBiomeBuilder} and only + * if structure was added during building process. Modification of this list will not affect structure generation. + * @return {@link List} of biome {@link ResourceLocation}. + */ + public List getBiomes() { + return biomes; + } } From 750c98c1773ecdf116f5d2251a8b31b2f854bdc9 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 2 Dec 2021 22:56:55 +0100 Subject: [PATCH 55/96] Fixed mixin signature --- .../java/ru/bclib/mixin/common/ServerLevelMixin.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java index d22aceec..ccb3b8be 100644 --- a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java +++ b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java @@ -10,10 +10,12 @@ 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; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.At.Shift; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import ru.bclib.api.LifeCycleAPI; @@ -32,18 +34,18 @@ public abstract class ServerLevelMixin extends Level { } @Inject(method = "*", at = @At("TAIL")) - private void bclib_onServerWorldInit(MinecraftServer server, Executor workerExecutor, LevelStorageSource.LevelStorageAccess session, ServerLevelData properties, ResourceKey registryKey, DimensionType dimensionType, ChunkProgressListener worldGenerationProgressListener, ChunkGenerator chunkGenerator, boolean debugWorld, long l, List list, boolean bl, CallbackInfo info) { + 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) { ServerLevel world = ServerLevel.class.cast(this); - LifeCycleAPI._runLevelLoad(world, server, workerExecutor, session, properties, registryKey, dimensionType, worldGenerationProgressListener, chunkGenerator, debugWorld, l, list, bl); + LifeCycleAPI._runLevelLoad(world, server, executor, levelStorageAccess, serverLevelData, resourceKey, dimensionType, chunkProgressListener, chunkGenerator, bl, l, list, bl2); BiomeAPI.initRegistry(server); BiomeAPI.applyModifications(ServerLevel.class.cast(this)); - if (bclib_lastWorld != null && bclib_lastWorld.equals(session.getLevelId())) { + if (bclib_lastWorld != null && bclib_lastWorld.equals(levelStorageAccess.getLevelId())) { return; } - bclib_lastWorld = session.getLevelId(); + bclib_lastWorld = levelStorageAccess.getLevelId(); } From 81801b3df9fcdff9a5819a4a7b24e3845c5d71a9 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 2 Dec 2021 22:57:31 +0100 Subject: [PATCH 56/96] build return-type is actual type of Biome --- src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index 1932bbe6..008d9265 100644 --- a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java @@ -480,7 +480,7 @@ public class BCLBiomeBuilder { * @param biomeConstructor {@link BiFunction} biome constructor. * @return created {@link BCLBiome} instance. */ - public BCLBiome build(BiFunction biomeConstructor) { + public T build(BiFunction biomeConstructor) { BiomeBuilder builder = new BiomeBuilder() .precipitation(precipitation) .biomeCategory(category) @@ -499,7 +499,9 @@ public class BCLBiomeBuilder { builder.generationSettings(generationSettings.build()); } - return biomeConstructor.apply(biomeID, builder.build()).setFogDensity(fogDensity); + final T res = biomeConstructor.apply(biomeID, builder.build()); + res.setFogDensity(fogDensity); + return res; } /** From cd2b4e481e400cb8c7a341542f0b200ce92de2ec Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 2 Dec 2021 23:34:49 +0100 Subject: [PATCH 57/96] New files on `WorldDataAPI`did not get an initial version tag --- src/main/java/ru/bclib/api/WorldDataAPI.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/bclib/api/WorldDataAPI.java b/src/main/java/ru/bclib/api/WorldDataAPI.java index b1794df7..d15cf43b 100644 --- a/src/main/java/ru/bclib/api/WorldDataAPI.java +++ b/src/main/java/ru/bclib/api/WorldDataAPI.java @@ -44,6 +44,7 @@ public class WorldDataAPI { catch (IOException e) { BCLib.LOGGER.error("World data loading failed", e); } + TAGS.put(modID, root); } else { Optional optional = FabricLoader.getInstance() @@ -58,11 +59,10 @@ public class WorldDataAPI { .getVersion() .toString()); } + TAGS.put(modID, root); saveFile(modID); } } - - TAGS.put(modID, root); }); } From 39255e140ff6d1310f54d4c4b81d75fd4736ad03 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 3 Dec 2021 00:30:55 +0100 Subject: [PATCH 58/96] New lifecycle hook that is called before the level is loaded --- src/main/java/ru/bclib/api/LifeCycleAPI.java | 25 +++++++++++++++++++ .../ru/bclib/mixin/client/MinecraftMixin.java | 5 ++++ .../java/ru/bclib/mixin/common/MainMixin.java | 3 +++ 3 files changed, 33 insertions(+) diff --git a/src/main/java/ru/bclib/api/LifeCycleAPI.java b/src/main/java/ru/bclib/api/LifeCycleAPI.java index c50b83b9..05ade7a5 100644 --- a/src/main/java/ru/bclib/api/LifeCycleAPI.java +++ b/src/main/java/ru/bclib/api/LifeCycleAPI.java @@ -23,6 +23,13 @@ import java.util.concurrent.Executor; public class LifeCycleAPI { private final static List onLoadLevelBiomes = new ArrayList<>(2); private final static List onLoadLevel = new ArrayList<>(2); + private final static List beforeLoadLevel = new ArrayList<>(2); + /** + * A callback function that is used for each new ServerLevel instance + */ + public interface BeforeLevelLoadCall { + void beforeLoad(); + } /** * A callback function that is used for each new ServerLevel instance @@ -51,6 +58,17 @@ public class LifeCycleAPI { boolean bl2); } + /** + * Register a callback that is called before a level is loaded or created, + * but after the {@link WorldDataAPI} was initialized and patches from + * the {@link ru.bclib.api.datafixer.DataFixerAPI} were applied. + * + * @param call The callback Method + */ + public static void beforeLevelLoad(BeforeLevelLoadCall call){ + beforeLoadLevel.add(call); + } + /** * Register a callback that is called when a new {@code ServerLevel is instantiated}. * This callback will receive the world seed as well as it's biome registry. @@ -69,6 +87,13 @@ public class LifeCycleAPI { onLoadLevel.add(call); } + /** + * For internal use, You should not call this method! + * @param src + */ + public static void _runBeforeLevelLoad(){ + beforeLoadLevel.forEach(c -> c.beforeLoad()); + } /** * For internal use, You should not call this method! * @param minecraftServer diff --git a/src/main/java/ru/bclib/mixin/client/MinecraftMixin.java b/src/main/java/ru/bclib/mixin/client/MinecraftMixin.java index f1cb2523..6c884bcf 100644 --- a/src/main/java/ru/bclib/mixin/client/MinecraftMixin.java +++ b/src/main/java/ru/bclib/mixin/client/MinecraftMixin.java @@ -22,6 +22,7 @@ import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import ru.bclib.api.LifeCycleAPI; import ru.bclib.api.dataexchange.DataExchangeAPI; import ru.bclib.api.datafixer.DataFixerAPI; import ru.bclib.interfaces.CustomColorProvider; @@ -61,14 +62,18 @@ public abstract class MinecraftMixin { DataExchangeAPI.prepareServerside(); if (DataFixerAPI.fixData(this.levelSource, levelID, true, (appliedFixes) -> { + LifeCycleAPI._runBeforeLevelLoad(); this.doLoadLevel(levelID, RegistryAccess.builtin(), Minecraft::loadDataPacks, Minecraft::loadWorldData, false, appliedFixes?ExperimentalDialogType.NONE:ExperimentalDialogType.BACKUP); })) { ci.cancel(); + } else { + LifeCycleAPI._runBeforeLevelLoad(); } } @Inject(method = "createLevel", at = @At("HEAD")) private void bclib_initPatchData(String levelID, LevelSettings levelSettings, RegistryHolder registryHolder, WorldGenSettings worldGenSettings, CallbackInfo ci) { DataFixerAPI.initializeWorldData(this.levelSource, levelID, true); + LifeCycleAPI._runBeforeLevelLoad(); } } diff --git a/src/main/java/ru/bclib/mixin/common/MainMixin.java b/src/main/java/ru/bclib/mixin/common/MainMixin.java index 72f17ecf..e672681d 100644 --- a/src/main/java/ru/bclib/mixin/common/MainMixin.java +++ b/src/main/java/ru/bclib/mixin/common/MainMixin.java @@ -1,10 +1,12 @@ package ru.bclib.mixin.common; import net.minecraft.server.Main; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.storage.LevelStorageSource; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArg; +import ru.bclib.api.LifeCycleAPI; import ru.bclib.api.datafixer.DataFixerAPI; @Mixin(Main.class) @@ -12,6 +14,7 @@ abstract public class MainMixin { @ModifyArg(method="main", at=@At(value="INVOKE_ASSIGN", target="Lnet/minecraft/world/level/storage/LevelStorageSource$LevelStorageAccess;getSummary()Lnet/minecraft/world/level/storage/LevelSummary;")) private static LevelStorageSource.LevelStorageAccess bclib_callServerFix(LevelStorageSource.LevelStorageAccess session){ DataFixerAPI.fixData(session, false, (didFix)->{/* not called when showUI==false */}); + LifeCycleAPI._runBeforeLevelLoad(); return session; } } From c6dc52a60d4ab36a33403b6a27e2c3e860c412f4 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 3 Dec 2021 00:31:53 +0100 Subject: [PATCH 59/96] override for the nether biome generator that is used by BN when older worlds are loaded --- .../world/generator/BCLibNetherBiomeSource.java | 16 ++++++++++++++-- .../bclib/world/generator/GeneratorOptions.java | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java index 9e524341..044e4c99 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java @@ -22,7 +22,7 @@ import java.util.LinkedList; import java.util.List; import java.util.function.Consumer; -public class BCLibNetherBiomeSource extends BiomeSource { +public class BCLibNetherBiomeSource extends BiomeSource { public static final Codec CODEC = RecordCodecBuilder.create((instance) -> { return instance.group(RegistryLookupCodec.create(Registry.BIOME_REGISTRY).forGetter((theEndBiomeSource) -> { return theEndBiomeSource.biomeRegistry; @@ -33,6 +33,18 @@ public class BCLibNetherBiomeSource extends BiomeSource { private final Registry biomeRegistry; private BiomeMap biomeMap; private final long seed; + private static boolean forceLegacyGenerator = false; + + /** + * When true, the older square generator is used for the nether. + * + * This override is used (for example) by BetterNether to force the legacy generation for worlds + * that were created before 1.18 + * @param val wether or not you want to force the old generatore. + */ + public static void setForceLegacyGeneration(boolean val){ + forceLegacyGenerator = val; + } @Deprecated(forRemoval = true) public static final List> onInit = new LinkedList<>(); @@ -65,7 +77,7 @@ public class BCLibNetherBiomeSource extends BiomeSource { BiomeAPI.NETHER_BIOME_PICKER.getBiomes().forEach(biome -> biome.updateActualBiomes(biomeRegistry)); BiomeAPI.NETHER_BIOME_PICKER.rebuild(); - if (GeneratorOptions.useOldBiomeGenerator()) { + if (GeneratorOptions.useOldBiomeGenerator() || forceLegacyGenerator) { this.biomeMap = new SquareBiomeMap(seed, GeneratorOptions.getBiomeSizeNether(), BiomeAPI.NETHER_BIOME_PICKER); } else { diff --git a/src/main/java/ru/bclib/world/generator/GeneratorOptions.java b/src/main/java/ru/bclib/world/generator/GeneratorOptions.java index 76032ab9..8cdf8911 100644 --- a/src/main/java/ru/bclib/world/generator/GeneratorOptions.java +++ b/src/main/java/ru/bclib/world/generator/GeneratorOptions.java @@ -16,7 +16,7 @@ public class GeneratorOptions { private static boolean customEndBiomeSource = true; private static boolean addNetherBiomesByCategory = false; private static boolean addEndBiomesByCategory = false; - private static boolean useOldBiomeGenerator = false; + private static boolean useOldBiomeGenerator = false; public static void init() { biomeSizeNether = Configs.GENERATOR_CONFIG.getInt("nether.biomeMap", "biomeSize", 256); From 4ac42025554feb50a52a1ebf6c95dadd6a70e630 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 3 Dec 2021 01:40:50 +0100 Subject: [PATCH 60/96] Fixed ID handling --- .../java/ru/bclib/api/biomes/BiomeAPI.java | 65 ++++++++++++++++--- 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index ac80904a..8752a34b 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -423,6 +423,16 @@ public class BiomeAPI { addBiomeFeature(biome, feature.getPlacedFeature(), feature.getDecoration()); } + /** + * Adds new features to existing biome. + * @param biomeID {@link ResourceLocation} for the {@link Biome} to add features in. + * @param feature {@link ConfiguredFeature} to add. + * + */ + public static void addBiomeFeature(ResourceLocation biomeID, BCLFeature feature) { + addBiomeFeature(biomeID, feature.getPlacedFeature(), feature.getDecoration()); + } + /** * Adds new features to existing biome. * @param biome {@link Biome} to add features in. @@ -430,9 +440,19 @@ public class BiomeAPI { * @param step a {@link Decoration} step for the feature. */ public static void addBiomeFeature(Biome biome, PlacedFeature feature, Decoration step) { + addBiomeFeature(getBiomeID(biome), feature, step); + } + + /** + * Adds new features to existing biome. + * @param biomeID {@link ResourceLocation} of the {@link Biome} to add features in. + * @param feature {@link ConfiguredFeature} to add. + * @param step a {@link Decoration} step for the feature. + */ + private static void addBiomeFeature(ResourceLocation biomeID, PlacedFeature feature, Decoration step) { BuiltinRegistries.PLACED_FEATURE .getResourceKey(feature) - .ifPresent(key -> BiomeModifications.addFeature(ctx -> ctx.getBiomeKey().equals(BuiltinRegistries.BIOME.getKey(biome)), step, key)); + .ifPresent(key -> BiomeModifications.addFeature(ctx -> ctx.getBiomeKey().location().equals(biomeID), step, key)); } /** @@ -446,17 +466,26 @@ public class BiomeAPI { } } - // TODO: 1.18 There are no more StructureFeatures in the Biomes, they are in a separate registry now /** * Adds new structure feature to existing biome. * @param biome {@link Biome} to add structure feature in. * @param structure {@link ConfiguredStructureFeature} to add. */ public static void addBiomeStructure(Biome biome, ConfiguredStructureFeature structure) { + addBiomeStructure(getBiomeID(biome), structure); + } + + /** + * Adds new structure feature to existing biome. + * @param biomeID {@link ResourceLocation} of the {@link Biome} to add structure feature in. + * @param structure {@link ConfiguredStructureFeature} to add. + */ + public static void addBiomeStructure(ResourceLocation biomeID, ConfiguredStructureFeature structure) { BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE .getResourceKey(structure) - .ifPresent(key -> BiomeModifications.addStructure(ctx -> ctx.getBiomeKey().location().equals(BuiltinRegistries.BIOME.getKey(biome)), key)); + .ifPresent(key -> BiomeModifications.addStructure(ctx -> ctx.getBiomeKey().location().equals(biomeID), key)); } + /** * Adds new structure feature to existing biome. * @param biome {@link Biome} to add structure feature in. @@ -465,6 +494,15 @@ public class BiomeAPI { public static void addBiomeStructure(Biome biome, BCLStructureFeature structure) { addBiomeStructure(biome, structure.getFeatureConfigured()); } + + /** + * Adds new structure feature to existing biome. + * @param biomeID {@link ResourceLocation} of the {@link Biome} to add structure feature in. + * @param structure {@link BCLStructureFeature} to add. + */ + public static void addBiomeStructure(ResourceLocation biomeID, BCLStructureFeature structure) { + addBiomeStructure(biomeID, structure.getFeatureConfigured()); + } /** * Adds new structure features to existing biome. @@ -486,14 +524,21 @@ public class BiomeAPI { * @param maxGroupCount maximum mobs in group. */ public static void addBiomeMobSpawn(Biome biome, EntityType entityType, int weight, int minGroupCount, int maxGroupCount) { - ResourceLocation biomeKey = BuiltinRegistries.BIOME.getKey(biome); + addBiomeMobSpawn(getBiomeID(biome), entityType, weight, minGroupCount, maxGroupCount); + } + + /** + * Adds mob spawning to specified biome. + * @param biomeID {@link ResourceLocation} of the {@link Biome }to add mob spawning. + * @param entityType {@link EntityType} mob type. + * @param weight spawn weight. + * @param minGroupCount minimum mobs in group. + * @param maxGroupCount maximum mobs in group. + */ + public static void addBiomeMobSpawn(ResourceLocation biomeID, EntityType entityType, int weight, int minGroupCount, int maxGroupCount) { BiomeModifications.addSpawn( - ctx -> ctx.getBiomeKey().equals(biomeKey), - entityType.getCategory(), - entityType, - weight, - minGroupCount, - maxGroupCount + ctx -> ctx.getBiomeKey().location().equals(biomeID), + entityType.getCategory(), entityType, weight, minGroupCount, maxGroupCount ); } From f5ee249bbbb3bee06e30c7bd51e8a293db12654c Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 3 Dec 2021 01:54:00 +0100 Subject: [PATCH 61/96] Adding Carvers --- .../ru/bclib/api/biomes/BCLBiomeBuilder.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index 008d9265..97fde8e7 100644 --- a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java @@ -22,7 +22,9 @@ import net.minecraft.world.level.biome.BiomeGenerationSettings; import net.minecraft.world.level.biome.BiomeSpecialEffects; import net.minecraft.world.level.biome.MobSpawnSettings; import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; +import net.minecraft.world.level.levelgen.GenerationStep; import net.minecraft.world.level.levelgen.GenerationStep.Decoration; +import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import net.minecraft.world.level.levelgen.placement.PlacedFeature; import ru.bclib.util.ColorUtil; @@ -446,7 +448,7 @@ public class BCLBiomeBuilder { } /** - * Adds new structure feature into thr biome. + * Adds new structure feature into the biome. * @param structure {@link ConfiguredStructureFeature} to add. * @return same {@link BCLBiomeBuilder} instance. */ @@ -467,6 +469,18 @@ public class BCLBiomeBuilder { return structure(structure.getFeatureConfigured()); } + /** + * Adds new world carver into the biome. + * @param carver {@link ConfiguredWorldCarver} to add. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder carver(GenerationStep.Carving step, ConfiguredWorldCarver carver) { + BuiltinRegistries.CONFIGURED_CARVER + .getResourceKey(carver) + .ifPresent(key -> BiomeModifications.addCarver(ctx -> ctx.getBiomeKey().location().equals(biomeID), step, key)); + return this; + } + /** * Finalize biome creation. * @return created {@link BCLBiome} instance. From 7b64221b55fbd3d95f960de2aea4f13665e2d7ce Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 3 Dec 2021 03:03:10 +0100 Subject: [PATCH 62/96] Different mixin for BiomeModification call --- .../java/ru/bclib/api/biomes/BiomeAPI.java | 38 ++++++++++++++++--- .../mixin/common/RegistryReadOpsMixin.java | 25 ++++++++++++ .../bclib/mixin/common/ServerLevelMixin.java | 5 ++- src/main/resources/bclib.mixins.common.json | 8 +--- 4 files changed, 63 insertions(+), 13 deletions(-) create mode 100644 src/main/java/ru/bclib/mixin/common/RegistryReadOpsMixin.java diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index 8752a34b..99a889b0 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.NetherBiomeData; import net.fabricmc.fabric.impl.biome.TheEndBiomeData; import net.minecraft.client.Minecraft; import net.minecraft.core.Registry; +import net.minecraft.core.RegistryAccess; import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; @@ -40,6 +41,7 @@ import java.util.Map; import java.util.Random; import java.util.Set; import java.util.function.BiConsumer; +import java.util.stream.Collectors; public class BiomeAPI { /** @@ -78,7 +80,16 @@ public class BiomeAPI { * @param server - {@link MinecraftServer} */ public static void initRegistry(MinecraftServer server) { - biomeRegistry = server.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY); + initRegistry(server.registryAccess()); + } + + /** + * Initialize registry for current server. + * + * @param access - {@link RegistryAccess} + */ + public static void initRegistry(RegistryAccess access) { + biomeRegistry = access.registryOrThrow(Registry.BIOME_REGISTRY); CLIENT.clear(); } @@ -388,13 +399,30 @@ public class BiomeAPI { * @param level */ public static void applyModifications(ServerLevel level) { - List> modifications = MODIFICATIONS.get(level.dimension()); - if (modifications == null) { - return; - } BiomeSource source = level.getChunkSource().getGenerator().getBiomeSource(); Set biomes = source.possibleBiomes(); + applyModifications(biomes, level.dimension()); + } + + /** + * Will apply biome modifications to world, internal usage only. + * @param registryAccess + */ + public static void applyModifications(RegistryAccess registryAccess) { + Registry biomeReg = registryAccess.registryOrThrow(Registry.BIOME_REGISTRY); + Set biomes = biomeReg.entrySet().stream().map(e -> e.getValue()).collect(Collectors.toSet()); + + applyModifications(biomes, Level.NETHER); + applyModifications(biomes, Level.OVERWORLD); + applyModifications(biomes, Level.END); + } + + private static void applyModifications(Set biomes, ResourceKey dimension) { + List> modifications = MODIFICATIONS.get(dimension); + if (modifications == null) { + return; + } biomes.forEach(biome -> { ResourceLocation biomeID = getBiomeID(biome); boolean modify = isDatapackBiome(biomeID); diff --git a/src/main/java/ru/bclib/mixin/common/RegistryReadOpsMixin.java b/src/main/java/ru/bclib/mixin/common/RegistryReadOpsMixin.java new file mode 100644 index 00000000..1ca0f981 --- /dev/null +++ b/src/main/java/ru/bclib/mixin/common/RegistryReadOpsMixin.java @@ -0,0 +1,25 @@ +package ru.bclib.mixin.common; + +import com.mojang.serialization.DynamicOps; +import net.minecraft.core.RegistryAccess; +import net.minecraft.resources.RegistryReadOps; +import net.minecraft.resources.RegistryResourceAccess; +import net.minecraft.server.level.ServerLevel; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import ru.bclib.api.biomes.BiomeAPI; + +/** + * Fabrics BiomeModifications API is called at this point. We have to ensure that BCLibs Modification API + * runs before Fabric, so we need to hook into the same class. + */ +@Mixin(RegistryReadOps.class) +public class RegistryReadOpsMixin { + @Inject(method = "createAndLoad(Lcom/mojang/serialization/DynamicOps;Lnet/minecraft/resources/RegistryResourceAccess;Lnet/minecraft/core/RegistryAccess;)Lnet/minecraft/resources/RegistryReadOps;", at = @At("RETURN")) + private static void foo(DynamicOps dynamicOps, RegistryResourceAccess registryResourceAccess, RegistryAccess registryAccess, CallbackInfoReturnable> cir){ + BiomeAPI.initRegistry(registryAccess); + BiomeAPI.applyModifications(registryAccess); + } +} diff --git a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java index ccb3b8be..e94c49e2 100644 --- a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java +++ b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java @@ -38,8 +38,9 @@ public abstract class ServerLevelMixin extends Level { ServerLevel world = ServerLevel.class.cast(this); LifeCycleAPI._runLevelLoad(world, server, executor, levelStorageAccess, serverLevelData, resourceKey, dimensionType, chunkProgressListener, chunkGenerator, bl, l, list, bl2); - BiomeAPI.initRegistry(server); - BiomeAPI.applyModifications(ServerLevel.class.cast(this)); + //called from RegistryReadOpsMixin for now +// BiomeAPI.initRegistry(server); +// BiomeAPI.applyModifications(ServerLevel.class.cast(this)); if (bclib_lastWorld != null && bclib_lastWorld.equals(levelStorageAccess.getLevelId())) { return; diff --git a/src/main/resources/bclib.mixins.common.json b/src/main/resources/bclib.mixins.common.json index 7e9c2373..d7578488 100644 --- a/src/main/resources/bclib.mixins.common.json +++ b/src/main/resources/bclib.mixins.common.json @@ -13,8 +13,6 @@ "shears.MushroomCowMixin", "ComposterBlockAccessor", "PotionBrewingAccessor", - "PotionBrewingAccessor", - "RecipeManagerAccessor", "RecipeManagerAccessor", "shears.SnowGolemMixin", "EnchantmentMenuMixin", @@ -24,21 +22,19 @@ "TheEndBiomeDataMixin", "ChunkGeneratorMixin", "WorldGenRegionMixin", - "WorldGenRegionMixin", "DimensionTypeMixin", "RecipeManagerMixin", "RecipeManagerMixin", "BoneMealItemMixin", "CraftingMenuMixin", - "CraftingMenuMixin", - "shears.SheepMixin", "shears.SheepMixin", "PortalShapeMixin", "ServerLevelMixin", "AnvilBlockMixin", "AnvilMenuMixin", "TagLoaderMixin", - "MainMixin" + "MainMixin", + "RegistryReadOpsMixin" ], "injectors": { "defaultRequire": 1 From 298aa47e7c918f801dd49fe0ae27eb6789c8fdd8 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 3 Dec 2021 03:16:50 +0100 Subject: [PATCH 63/96] Filter Biomes --- src/main/java/ru/bclib/api/biomes/BiomeAPI.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index 99a889b0..2d5837e9 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -20,6 +20,7 @@ import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.level.Level; import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.Biome.BiomeCategory; import net.minecraft.world.level.biome.BiomeSource; import net.minecraft.world.level.biome.Biomes; import net.minecraft.world.level.biome.Climate; @@ -413,9 +414,18 @@ public class BiomeAPI { Registry biomeReg = registryAccess.registryOrThrow(Registry.BIOME_REGISTRY); Set biomes = biomeReg.entrySet().stream().map(e -> e.getValue()).collect(Collectors.toSet()); - applyModifications(biomes, Level.NETHER); - applyModifications(biomes, Level.OVERWORLD); - applyModifications(biomes, Level.END); + applyModifications( + biomes.stream().filter(b->b.getBiomeCategory().equals(BiomeCategory.NETHER)).collect(Collectors.toSet()), + Level.NETHER + ); + applyModifications( + biomes.stream().filter(b->!b.getBiomeCategory().equals(BiomeCategory.NETHER) && !b.getBiomeCategory().equals(BiomeCategory.THEEND)).collect(Collectors.toSet()), + Level.OVERWORLD + ); + applyModifications( + biomes.stream().filter(b->b.getBiomeCategory().equals(BiomeCategory.THEEND)).collect(Collectors.toSet()), + Level.END + ); } private static void applyModifications(Set biomes, ResourceKey dimension) { From fb79201b51219df79528365c9b41cf3a4c4c8aae Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 3 Dec 2021 03:58:53 +0100 Subject: [PATCH 64/96] Make sure biomes are not modified twice --- src/main/java/ru/bclib/api/biomes/BiomeAPI.java | 9 ++++++++- .../java/ru/bclib/mixin/common/RegistryReadOpsMixin.java | 1 - 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index 2d5837e9..f431106a 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -37,6 +37,7 @@ import ru.bclib.world.features.BCLFeature; import ru.bclib.world.generator.BiomePicker; import ru.bclib.world.structures.BCLStructureFeature; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Random; @@ -406,13 +407,19 @@ public class BiomeAPI { applyModifications(biomes, level.dimension()); } + private static final Set modifiedBiomes = new HashSet<>(); /** * Will apply biome modifications to world, internal usage only. * @param registryAccess */ public static void applyModifications(RegistryAccess registryAccess) { Registry biomeReg = registryAccess.registryOrThrow(Registry.BIOME_REGISTRY); - Set biomes = biomeReg.entrySet().stream().map(e -> e.getValue()).collect(Collectors.toSet()); + Set biomes = biomeReg + .entrySet() + .stream() + .map(e -> e.getValue()) + .filter(b -> modifiedBiomes.add(getBiomeID(b))) + .collect(Collectors.toSet()); applyModifications( biomes.stream().filter(b->b.getBiomeCategory().equals(BiomeCategory.NETHER)).collect(Collectors.toSet()), diff --git a/src/main/java/ru/bclib/mixin/common/RegistryReadOpsMixin.java b/src/main/java/ru/bclib/mixin/common/RegistryReadOpsMixin.java index 1ca0f981..a33d6c59 100644 --- a/src/main/java/ru/bclib/mixin/common/RegistryReadOpsMixin.java +++ b/src/main/java/ru/bclib/mixin/common/RegistryReadOpsMixin.java @@ -4,7 +4,6 @@ import com.mojang.serialization.DynamicOps; import net.minecraft.core.RegistryAccess; import net.minecraft.resources.RegistryReadOps; import net.minecraft.resources.RegistryResourceAccess; -import net.minecraft.server.level.ServerLevel; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; From 26fa4bb3fd6cc22a9f7a58b9c209e59d81bfb440 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 3 Dec 2021 09:48:55 +0100 Subject: [PATCH 65/96] Reverted changes to BiomeModification API --- .../java/ru/bclib/api/biomes/BiomeAPI.java | 52 +++---------------- .../mixin/common/RegistryReadOpsMixin.java | 24 --------- .../bclib/mixin/common/ServerLevelMixin.java | 5 +- src/main/resources/bclib.mixins.common.json | 3 +- 4 files changed, 9 insertions(+), 75 deletions(-) delete mode 100644 src/main/java/ru/bclib/mixin/common/RegistryReadOpsMixin.java diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index f431106a..934ced83 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -82,16 +82,7 @@ public class BiomeAPI { * @param server - {@link MinecraftServer} */ public static void initRegistry(MinecraftServer server) { - initRegistry(server.registryAccess()); - } - - /** - * Initialize registry for current server. - * - * @param access - {@link RegistryAccess} - */ - public static void initRegistry(RegistryAccess access) { - biomeRegistry = access.registryOrThrow(Registry.BIOME_REGISTRY); + biomeRegistry = server.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY); CLIENT.clear(); } @@ -401,45 +392,14 @@ public class BiomeAPI { * @param level */ public static void applyModifications(ServerLevel level) { - BiomeSource source = level.getChunkSource().getGenerator().getBiomeSource(); - Set biomes = source.possibleBiomes(); - - applyModifications(biomes, level.dimension()); - } - - private static final Set modifiedBiomes = new HashSet<>(); - /** - * Will apply biome modifications to world, internal usage only. - * @param registryAccess - */ - public static void applyModifications(RegistryAccess registryAccess) { - Registry biomeReg = registryAccess.registryOrThrow(Registry.BIOME_REGISTRY); - Set biomes = biomeReg - .entrySet() - .stream() - .map(e -> e.getValue()) - .filter(b -> modifiedBiomes.add(getBiomeID(b))) - .collect(Collectors.toSet()); - - applyModifications( - biomes.stream().filter(b->b.getBiomeCategory().equals(BiomeCategory.NETHER)).collect(Collectors.toSet()), - Level.NETHER - ); - applyModifications( - biomes.stream().filter(b->!b.getBiomeCategory().equals(BiomeCategory.NETHER) && !b.getBiomeCategory().equals(BiomeCategory.THEEND)).collect(Collectors.toSet()), - Level.OVERWORLD - ); - applyModifications( - biomes.stream().filter(b->b.getBiomeCategory().equals(BiomeCategory.THEEND)).collect(Collectors.toSet()), - Level.END - ); - } - - private static void applyModifications(Set biomes, ResourceKey dimension) { - List> modifications = MODIFICATIONS.get(dimension); + List> modifications = MODIFICATIONS.get(level.dimension()); if (modifications == null) { return; } + + BiomeSource source = level.getChunkSource().getGenerator().getBiomeSource(); + Set biomes = source.possibleBiomes(); + biomes.forEach(biome -> { ResourceLocation biomeID = getBiomeID(biome); boolean modify = isDatapackBiome(biomeID); diff --git a/src/main/java/ru/bclib/mixin/common/RegistryReadOpsMixin.java b/src/main/java/ru/bclib/mixin/common/RegistryReadOpsMixin.java deleted file mode 100644 index a33d6c59..00000000 --- a/src/main/java/ru/bclib/mixin/common/RegistryReadOpsMixin.java +++ /dev/null @@ -1,24 +0,0 @@ -package ru.bclib.mixin.common; - -import com.mojang.serialization.DynamicOps; -import net.minecraft.core.RegistryAccess; -import net.minecraft.resources.RegistryReadOps; -import net.minecraft.resources.RegistryResourceAccess; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import ru.bclib.api.biomes.BiomeAPI; - -/** - * Fabrics BiomeModifications API is called at this point. We have to ensure that BCLibs Modification API - * runs before Fabric, so we need to hook into the same class. - */ -@Mixin(RegistryReadOps.class) -public class RegistryReadOpsMixin { - @Inject(method = "createAndLoad(Lcom/mojang/serialization/DynamicOps;Lnet/minecraft/resources/RegistryResourceAccess;Lnet/minecraft/core/RegistryAccess;)Lnet/minecraft/resources/RegistryReadOps;", at = @At("RETURN")) - private static void foo(DynamicOps dynamicOps, RegistryResourceAccess registryResourceAccess, RegistryAccess registryAccess, CallbackInfoReturnable> cir){ - BiomeAPI.initRegistry(registryAccess); - BiomeAPI.applyModifications(registryAccess); - } -} diff --git a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java index e94c49e2..ccb3b8be 100644 --- a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java +++ b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java @@ -38,9 +38,8 @@ public abstract class ServerLevelMixin extends Level { ServerLevel world = ServerLevel.class.cast(this); LifeCycleAPI._runLevelLoad(world, server, executor, levelStorageAccess, serverLevelData, resourceKey, dimensionType, chunkProgressListener, chunkGenerator, bl, l, list, bl2); - //called from RegistryReadOpsMixin for now -// BiomeAPI.initRegistry(server); -// BiomeAPI.applyModifications(ServerLevel.class.cast(this)); + BiomeAPI.initRegistry(server); + BiomeAPI.applyModifications(ServerLevel.class.cast(this)); if (bclib_lastWorld != null && bclib_lastWorld.equals(levelStorageAccess.getLevelId())) { return; diff --git a/src/main/resources/bclib.mixins.common.json b/src/main/resources/bclib.mixins.common.json index d7578488..004e65c3 100644 --- a/src/main/resources/bclib.mixins.common.json +++ b/src/main/resources/bclib.mixins.common.json @@ -33,8 +33,7 @@ "AnvilBlockMixin", "AnvilMenuMixin", "TagLoaderMixin", - "MainMixin", - "RegistryReadOpsMixin" + "MainMixin" ], "injectors": { "defaultRequire": 1 From 39fe678d39a252252749bb977db6bce316920b01 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Fri, 3 Dec 2021 13:44:58 +0300 Subject: [PATCH 66/96] Biome feature adding --- .../java/ru/bclib/api/biomes/BiomeAPI.java | 32 ++++++++++++++++--- .../BiomeGenerationSettingsAccessor.java | 25 +++++++++++++++ 2 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index 934ced83..cad8cfb0 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -5,6 +5,7 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.fabricmc.fabric.api.biome.v1.BiomeModificationContext.GenerationSettingsContext; import net.fabricmc.fabric.api.biome.v1.BiomeModifications; import net.fabricmc.fabric.impl.biome.NetherBiomeData; import net.fabricmc.fabric.impl.biome.TheEndBiomeData; @@ -30,6 +31,7 @@ import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import net.minecraft.world.level.levelgen.placement.PlacedFeature; import org.jetbrains.annotations.Nullable; import ru.bclib.config.Configs; +import ru.bclib.mixin.common.BiomeGenerationSettingsAccessor; import ru.bclib.util.MHelper; import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.biomes.FabricBiomesData; @@ -37,12 +39,14 @@ import ru.bclib.world.features.BCLFeature; import ru.bclib.world.generator.BiomePicker; import ru.bclib.world.structures.BCLStructureFeature; +import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Random; import java.util.Set; import java.util.function.BiConsumer; +import java.util.function.Supplier; import java.util.stream.Collectors; public class BiomeAPI { @@ -401,7 +405,7 @@ public class BiomeAPI { Set biomes = source.possibleBiomes(); biomes.forEach(biome -> { - ResourceLocation biomeID = getBiomeID(biome); + ResourceLocation biomeID = getBiomeID(biome); boolean modify = isDatapackBiome(biomeID); if (biome != BuiltinRegistries.BIOME.get(biomeID)) { modify = true; @@ -445,7 +449,10 @@ public class BiomeAPI { * @param step a {@link Decoration} step for the feature. */ public static void addBiomeFeature(Biome biome, PlacedFeature feature, Decoration step) { - addBiomeFeature(getBiomeID(biome), feature, step); + BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings(); + List>> allFeatures = getMutable(accessor.bclib_getFeatures()); + List> features = getFeaturesList(allFeatures, step); + features.add(() -> feature); } /** @@ -455,9 +462,7 @@ public class BiomeAPI { * @param step a {@link Decoration} step for the feature. */ private static void addBiomeFeature(ResourceLocation biomeID, PlacedFeature feature, Decoration step) { - BuiltinRegistries.PLACED_FEATURE - .getResourceKey(feature) - .ifPresent(key -> BiomeModifications.addFeature(ctx -> ctx.getBiomeKey().location().equals(biomeID), step, key)); + addBiomeFeature(BuiltinRegistries.BIOME.get(biomeID), feature, step); } /** @@ -553,4 +558,21 @@ public class BiomeAPI { fog = Configs.BIOMES_CONFIG.getFloat(group, "fog_density", fog); biome.setGenChance(chance).setFogDensity(fog); } + + private static List getMutable(List list) { + if (list instanceof ArrayList) { + return list; + } + return new ArrayList<>(list); + } + + private static List> getFeaturesList(List>> features, Decoration step) { + int index = step.ordinal(); + while (features.size() <= index) { + features.add(Lists.newArrayList()); + } + List> mutable = getMutable(features.get(index)); + features.set(index, mutable); + return mutable; + } } diff --git a/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java b/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java new file mode 100644 index 00000000..ac100c07 --- /dev/null +++ b/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java @@ -0,0 +1,25 @@ +package ru.bclib.mixin.common; + +import net.minecraft.world.level.biome.BiomeGenerationSettings; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.List; +import java.util.Set; +import java.util.function.Supplier; + +@Mixin(BiomeGenerationSettings.class) +public interface BiomeGenerationSettingsAccessor { + @Accessor("features") + List>> bclib_getFeatures(); + + @Accessor("features") + void bclib_setFeatures(List>> features); + + @Accessor("featureSet") + Set bclib_getFeatureSet(); + + @Accessor("featureSet") + void bclib_setFeatureSet(Set features); +} From eaba9bf698b35312fa32091529de2b65a8763794 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Fri, 3 Dec 2021 13:49:42 +0300 Subject: [PATCH 67/96] Collections util --- .../java/ru/bclib/util/CollectionsUtil.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/main/java/ru/bclib/util/CollectionsUtil.java diff --git a/src/main/java/ru/bclib/util/CollectionsUtil.java b/src/main/java/ru/bclib/util/CollectionsUtil.java new file mode 100644 index 00000000..609d392a --- /dev/null +++ b/src/main/java/ru/bclib/util/CollectionsUtil.java @@ -0,0 +1,46 @@ +package ru.bclib.util; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class CollectionsUtil { + /** + * Will return mutable copy of list. + * @param list {@link List} to make mutable. + * @return {@link ArrayList} or original {@link List} if it is mutable. + */ + public static List getMutable(List list) { + if (list instanceof ArrayList) { + return list; + } + return new ArrayList<>(list); + } + + /** + * Will return mutable copy of set. + * @param set {@link Set} to make mutable. + * @return {@link HashSet} or original {@link Set} if it is mutable. + */ + public static Set getMutable(Set set) { + if (set instanceof HashSet) { + return set; + } + return new HashSet<>(set); + } + + /** + * Will return mutable copy of map. + * @param map {@link Map} to make mutable. + * @return {@link HashMap} or original {@link Map} if it is mutable. + */ + public static Map getMutable(Map map) { + if (map instanceof HashMap) { + return map; + } + return new HashMap<>(map); + } +} From 8234a1c9dc5abc3eff543c5d2e75b8536eb9f69c Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Fri, 3 Dec 2021 13:51:36 +0300 Subject: [PATCH 68/96] Biome feature modification fixes --- src/main/java/ru/bclib/api/biomes/BiomeAPI.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index cad8cfb0..ed557e64 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -32,6 +32,7 @@ import net.minecraft.world.level.levelgen.placement.PlacedFeature; import org.jetbrains.annotations.Nullable; import ru.bclib.config.Configs; import ru.bclib.mixin.common.BiomeGenerationSettingsAccessor; +import ru.bclib.util.CollectionsUtil; import ru.bclib.util.MHelper; import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.biomes.FabricBiomesData; @@ -450,9 +451,13 @@ public class BiomeAPI { */ public static void addBiomeFeature(Biome biome, PlacedFeature feature, Decoration step) { BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings(); - List>> allFeatures = getMutable(accessor.bclib_getFeatures()); + List>> allFeatures = CollectionsUtil.getMutable(accessor.bclib_getFeatures()); + Set set = CollectionsUtil.getMutable(accessor.bclib_getFeatureSet()); List> features = getFeaturesList(allFeatures, step); features.add(() -> feature); + set.add(feature); + accessor.bclib_setFeatures(allFeatures); + accessor.bclib_setFeatureSet(set); } /** @@ -559,19 +564,12 @@ public class BiomeAPI { biome.setGenChance(chance).setFogDensity(fog); } - private static List getMutable(List list) { - if (list instanceof ArrayList) { - return list; - } - return new ArrayList<>(list); - } - private static List> getFeaturesList(List>> features, Decoration step) { int index = step.ordinal(); while (features.size() <= index) { features.add(Lists.newArrayList()); } - List> mutable = getMutable(features.get(index)); + List> mutable = CollectionsUtil.getMutable(features.get(index)); features.set(index, mutable); return mutable; } From db07cd18878da17d78ddf4a8b67c44808f3dfba0 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Fri, 3 Dec 2021 13:54:07 +0300 Subject: [PATCH 69/96] BCL Biome feature adding optimisation --- src/main/java/ru/bclib/api/biomes/BiomeAPI.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index ed557e64..50a30723 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -476,9 +476,16 @@ public class BiomeAPI { * @param features array of {@link BCLFeature} to add. */ public static void addBiomeFeatures(Biome biome, BCLFeature... features) { + BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings(); + List>> allFeatures = CollectionsUtil.getMutable(accessor.bclib_getFeatures()); + Set set = CollectionsUtil.getMutable(accessor.bclib_getFeatureSet()); for (BCLFeature feature: features) { - addBiomeFeature(biome, feature.getPlacedFeature(), feature.getDecoration()); + List> featureList = getFeaturesList(allFeatures, feature.getDecoration()); + featureList.add(() -> feature.getPlacedFeature()); + set.add(feature.getPlacedFeature()); } + accessor.bclib_setFeatures(allFeatures); + accessor.bclib_setFeatureSet(set); } /** From e470610294a29197488d8cef65cb8479135ab783 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 3 Dec 2021 12:22:00 +0100 Subject: [PATCH 70/96] WIP: No longer using Fabric BiomeModification API for features/structures/spawns --- .../ru/bclib/api/biomes/BCLBiomeBuilder.java | 9 +- .../java/ru/bclib/api/biomes/BiomeAPI.java | 221 ++++++++++++------ .../BiomeGenerationSettingsAccessor.java | 21 ++ .../common/MobSpawnSettingsAccessor.java | 21 ++ .../common/StructureSettingsAccessor.java | 28 +++ .../java/ru/bclib/world/biomes/BCLBiome.java | 15 +- .../ru/bclib/world/biomes/BCLBiomeDef.java | 2 +- src/main/resources/bclib.mixins.common.json | 5 +- 8 files changed, 245 insertions(+), 77 deletions(-) create mode 100644 src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java create mode 100644 src/main/java/ru/bclib/mixin/common/MobSpawnSettingsAccessor.java create mode 100644 src/main/java/ru/bclib/mixin/common/StructureSettingsAccessor.java diff --git a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index 97fde8e7..da74bf61 100644 --- a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java @@ -32,6 +32,8 @@ import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.features.BCLFeature; import ru.bclib.world.structures.BCLStructureFeature; +import java.util.ArrayList; +import java.util.List; import java.util.function.BiFunction; import java.util.function.Consumer; @@ -447,15 +449,14 @@ public class BCLBiomeBuilder { return feature(feature.getDecoration(), feature.getPlacedFeature()); } + private List structures = new ArrayList<>(2); /** * Adds new structure feature into the biome. * @param structure {@link ConfiguredStructureFeature} to add. * @return same {@link BCLBiomeBuilder} instance. */ public BCLBiomeBuilder structure(ConfiguredStructureFeature structure) { - BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE - .getResourceKey(structure) - .ifPresent(key -> BiomeModifications.addStructure(ctx -> ctx.getBiomeKey().location().equals(biomeID), key)); + structures.add(structure); return this; } @@ -514,6 +515,7 @@ public class BCLBiomeBuilder { } final T res = biomeConstructor.apply(biomeID, builder.build()); + res.attachedStructures = structures; res.setFogDensity(fogDensity); return res; } @@ -521,6 +523,7 @@ public class BCLBiomeBuilder { /** * Get or create {@link BiomeSpecialEffects.Builder} for biome visual effects. * For internal usage only. + * For internal usage only. * @return new or same {@link BiomeSpecialEffects.Builder} instance. */ private BiomeSpecialEffects.Builder getEffects() { diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index 934ced83..f46e3a5a 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -1,49 +1,64 @@ package ru.bclib.api.biomes; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.google.common.collect.Multimap; import com.google.common.collect.Sets; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.biome.v1.BiomeModifications; import net.fabricmc.fabric.impl.biome.NetherBiomeData; import net.fabricmc.fabric.impl.biome.TheEndBiomeData; import net.minecraft.client.Minecraft; import net.minecraft.core.Registry; -import net.minecraft.core.RegistryAccess; import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.random.WeightedRandomList; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.MobCategory; import net.minecraft.world.level.Level; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.Biome.BiomeCategory; import net.minecraft.world.level.biome.BiomeSource; import net.minecraft.world.level.biome.Biomes; import net.minecraft.world.level.biome.Climate; +import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; import net.minecraft.world.level.levelgen.GenerationStep.Decoration; +import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; +import net.minecraft.world.level.levelgen.feature.StructureFeature; import net.minecraft.world.level.levelgen.placement.PlacedFeature; import org.jetbrains.annotations.Nullable; +import ru.bclib.BCLib; import ru.bclib.config.Configs; +import ru.bclib.mixin.common.BiomeGenerationSettingsAccessor; +import ru.bclib.mixin.common.MobSpawnSettingsAccessor; +import ru.bclib.mixin.common.StructureSettingsAccessor; import ru.bclib.util.MHelper; import ru.bclib.world.biomes.BCLBiome; +import ru.bclib.world.biomes.BCLBiomeDef; import ru.bclib.world.biomes.FabricBiomesData; import ru.bclib.world.features.BCLFeature; import ru.bclib.world.generator.BiomePicker; import ru.bclib.world.structures.BCLStructureFeature; -import java.util.HashSet; +import java.util.ArrayList; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Random; import java.util.Set; import java.util.function.BiConsumer; -import java.util.stream.Collectors; +import java.util.function.Consumer; +import java.util.function.Supplier; public class BiomeAPI { /** @@ -272,6 +287,15 @@ public class BiomeAPI { return endBiome; } + /** + * Get biome {@link ResourceKey} from given {@link Biome}. + * @param biome - {@link Biome} from server world. + * @return biome {@link ResourceKey} or {@code null}. + */ + public static ResourceKey getBiomeKey(Biome biome) { + return biomeRegistry.getResourceKey(biome).orElse(null); + } + /** * Get biome {@link ResourceLocation} from given {@link Biome}. * @param biome - {@link Biome} from server world. @@ -428,16 +452,6 @@ public class BiomeAPI { addBiomeFeature(biome, feature.getPlacedFeature(), feature.getDecoration()); } - /** - * Adds new features to existing biome. - * @param biomeID {@link ResourceLocation} for the {@link Biome} to add features in. - * @param feature {@link ConfiguredFeature} to add. - * - */ - public static void addBiomeFeature(ResourceLocation biomeID, BCLFeature feature) { - addBiomeFeature(biomeID, feature.getPlacedFeature(), feature.getDecoration()); - } - /** * Adds new features to existing biome. * @param biome {@link Biome} to add features in. @@ -445,19 +459,13 @@ public class BiomeAPI { * @param step a {@link Decoration} step for the feature. */ public static void addBiomeFeature(Biome biome, PlacedFeature feature, Decoration step) { - addBiomeFeature(getBiomeID(biome), feature, step); - } - - /** - * Adds new features to existing biome. - * @param biomeID {@link ResourceLocation} of the {@link Biome} to add features in. - * @param feature {@link ConfiguredFeature} to add. - * @param step a {@link Decoration} step for the feature. - */ - private static void addBiomeFeature(ResourceLocation biomeID, PlacedFeature feature, Decoration step) { - BuiltinRegistries.PLACED_FEATURE - .getResourceKey(feature) - .ifPresent(key -> BiomeModifications.addFeature(ctx -> ctx.getBiomeKey().location().equals(biomeID), step, key)); +// BiomeModificationContextImpl ctx = new BiomeModificationContextImpl(,,biome); +// ctx.getGenerationSettings().addFeature(step, feature.); + BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings(); + List>> biomeFeatures = getMutableList(accessor.bcl_getFeatures()); + List> list = getList(step, biomeFeatures); + list.add(() -> feature); + accessor.bcl_setFeatures(biomeFeatures); } /** @@ -473,50 +481,69 @@ public class BiomeAPI { /** * Adds new structure feature to existing biome. - * @param biome {@link Biome} to add structure feature in. + * @param biomeKey {@link ResourceKey} for the {@link Biome} to add structure feature in. * @param structure {@link ConfiguredStructureFeature} to add. */ + public static void addBiomeStructure(ResourceKey biomeKey, ConfiguredStructureFeature structure) { + //BiomeStructureStartsImpl.addStart(registries, structure, getBiomeID(biome)); + changeStructureStarts(structureMap -> { + Multimap, ResourceKey> configuredMap = structureMap.computeIfAbsent(structure.feature, k -> HashMultimap.create()); + + configuredMap.put(structure, biomeKey); + }); + + + } + public static void addBiomeStructure(Biome biome, ConfiguredStructureFeature structure) { - addBiomeStructure(getBiomeID(biome), structure); + //BiomeStructureStartsImpl.addStart(registries, structure, getBiomeID(biome)); + changeStructureStarts(structureMap -> { + Multimap, ResourceKey> configuredMap = structureMap.computeIfAbsent(structure.feature, k -> HashMultimap.create()); + + var key = getBiomeKey(biome); + if (key!=null) { + configuredMap.put(structure, key); + } else { + BCLib.LOGGER.error("Unable to find Biome " + getBiomeID(biome)); + } + }); + + } + + private static void changeStructureStarts(Consumer, Multimap, ResourceKey>>> modifier) { + Registry chunkGenSettingsRegistry = BuiltinRegistries.NOISE_GENERATOR_SETTINGS; + + for (Map.Entry, NoiseGeneratorSettings> entry : chunkGenSettingsRegistry.entrySet()) { + Map, Multimap, ResourceKey>> structureMap = getMutableStructureConfig(entry.getValue()); + + modifier.accept(structureMap); + setMutableStructureConfig(entry.getValue(), structureMap); + } + + + } + + /** * Adds new structure feature to existing biome. - * @param biomeID {@link ResourceLocation} of the {@link Biome} to add structure feature in. - * @param structure {@link ConfiguredStructureFeature} to add. - */ - public static void addBiomeStructure(ResourceLocation biomeID, ConfiguredStructureFeature structure) { - BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE - .getResourceKey(structure) - .ifPresent(key -> BiomeModifications.addStructure(ctx -> ctx.getBiomeKey().location().equals(biomeID), key)); - } - - /** - * Adds new structure feature to existing biome. - * @param biome {@link Biome} to add structure feature in. + * @param biomeKey {@link ResourceKey} for the {@link Biome} to add structure feature in. * @param structure {@link BCLStructureFeature} to add. */ - public static void addBiomeStructure(Biome biome, BCLStructureFeature structure) { - addBiomeStructure(biome, structure.getFeatureConfigured()); + public static void addBiomeStructure(ResourceKey biomeKey, BCLStructureFeature structure) { + addBiomeStructure(biomeKey, structure.getFeatureConfigured()); } - /** - * Adds new structure feature to existing biome. - * @param biomeID {@link ResourceLocation} of the {@link Biome} to add structure feature in. - * @param structure {@link BCLStructureFeature} to add. - */ - public static void addBiomeStructure(ResourceLocation biomeID, BCLStructureFeature structure) { - addBiomeStructure(biomeID, structure.getFeatureConfigured()); - } /** * Adds new structure features to existing biome. - * @param biome {@link Biome} to add structure features in. + * @param biomeKey {@link ResourceKey} for the {@link Biome} to add structure features in. * @param structures array of {@link BCLStructureFeature} to add. */ - public static void addBiomeStructures(Biome biome, BCLStructureFeature... structures) { + public static void addBiomeStructures(ResourceKey biomeKey, BCLStructureFeature... structures) { for (BCLStructureFeature structure: structures) { - addBiomeStructure(biome, structure.getFeatureConfigured()); + addBiomeStructure(biomeKey, structure.getFeatureConfigured()); } } @@ -529,22 +556,13 @@ public class BiomeAPI { * @param maxGroupCount maximum mobs in group. */ public static void addBiomeMobSpawn(Biome biome, EntityType entityType, int weight, int minGroupCount, int maxGroupCount) { - addBiomeMobSpawn(getBiomeID(biome), entityType, weight, minGroupCount, maxGroupCount); - } - - /** - * Adds mob spawning to specified biome. - * @param biomeID {@link ResourceLocation} of the {@link Biome }to add mob spawning. - * @param entityType {@link EntityType} mob type. - * @param weight spawn weight. - * @param minGroupCount minimum mobs in group. - * @param maxGroupCount maximum mobs in group. - */ - public static void addBiomeMobSpawn(ResourceLocation biomeID, EntityType entityType, int weight, int minGroupCount, int maxGroupCount) { - BiomeModifications.addSpawn( - ctx -> ctx.getBiomeKey().location().equals(biomeID), - entityType.getCategory(), entityType, weight, minGroupCount, maxGroupCount - ); + final MobCategory category = entityType.getCategory(); + MobSpawnSettingsAccessor accessor = (MobSpawnSettingsAccessor) biome.getMobSettings(); + Map> spawners = getMutableMap(accessor.bcl_getSpawners()); + List mobs = spawners.containsKey(category) ? getMutableList(spawners.get(category).unwrap()) : Lists.newArrayList(); + mobs.add(new SpawnerData(entityType, weight, minGroupCount, maxGroupCount)); + spawners.put(category, WeightedRandomList.create(mobs)); + accessor.bcl_setSpawners(spawners); } private static void configureBiome(BCLBiome biome, float chance, float fog) { @@ -553,4 +571,65 @@ public class BiomeAPI { fog = Configs.BIOMES_CONFIG.getFloat(group, "fog_density", fog); biome.setGenChance(chance).setFogDensity(fog); } + + /** + * Getter for correct feature list from all biome feature list of lists. + * @param step feature {@link Decoration} step. + * @param lists biome accessor lists. + * @return mutable {@link ConfiguredFeature} list. + */ + private static List> getList(Decoration step, List>> lists) { + int index = step.ordinal(); + if (lists.size() <= index) { + for (int i = lists.size(); i <= index; i++) { + lists.add(Lists.newArrayList()); + } + } + List> list = getMutableList(lists.get(index)); + lists.set(index, list); + return list; + } + + private static List getMutableList(List input) { + if (input!=null) { + System.out.println("getMutableList: " + input.getClass().getName()); + for (Class cl : input.getClass().getInterfaces()){ + System.out.println(" - " + cl.getName()); + } + } + if (/*input instanceof ImmutableList ||*/ !(input instanceof ArrayList || input instanceof LinkedList)) { + return Lists.newArrayList(input); + } + return input; + } + + private static Map getMutableMap(Map input) { + if (/*input instanceof ImmutableMap*/ !(input instanceof HashMap ||input instanceof EnumMap)) { + return Maps.newHashMap(input); + } + return input; + } + + //inspired by net.fabricmc.fabric.impl.biome.modification.BiomeStructureStartsImpl + private static Map, Multimap, ResourceKey>> getMutableStructureConfig(NoiseGeneratorSettings settings) { + final StructureSettingsAccessor access = (StructureSettingsAccessor)settings.structureSettings(); + ImmutableMap, ImmutableMultimap, ResourceKey>> immutableMap = access.bcl_getStructureConfig(); + Map, Multimap, ResourceKey>> result = new HashMap<>(immutableMap.size()); + + for (Map.Entry, ImmutableMultimap, ResourceKey>> entry : immutableMap.entrySet()) { + result.put(entry.getKey(), HashMultimap.create(entry.getValue())); + } + + return result; + } + + //inspired by net.fabricmc.fabric.impl.biome.modification.BiomeStructureStartsImpl + private static void setMutableStructureConfig(NoiseGeneratorSettings settings, Map, Multimap, ResourceKey>> structureStarts) { + final StructureSettingsAccessor access = (StructureSettingsAccessor)settings.structureSettings(); + access.bcl_setStructureConfig(structureStarts.entrySet().stream() + .collect(ImmutableMap.toImmutableMap( + Map.Entry::getKey, + e -> ImmutableMultimap.copyOf(e.getValue()) + ))); + } } diff --git a/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java b/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java new file mode 100644 index 00000000..f8037293 --- /dev/null +++ b/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java @@ -0,0 +1,21 @@ +package ru.bclib.mixin.common; + +import net.minecraft.world.level.biome.BiomeGenerationSettings; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.List; +import java.util.function.Supplier; + +@Mixin(BiomeGenerationSettings.class) +public interface BiomeGenerationSettingsAccessor { + @Accessor("features") + List>> bcl_getFeatures(); + + @Accessor("features") + @Mutable + void bcl_setFeatures(List>> value); +} + diff --git a/src/main/java/ru/bclib/mixin/common/MobSpawnSettingsAccessor.java b/src/main/java/ru/bclib/mixin/common/MobSpawnSettingsAccessor.java new file mode 100644 index 00000000..e3491b73 --- /dev/null +++ b/src/main/java/ru/bclib/mixin/common/MobSpawnSettingsAccessor.java @@ -0,0 +1,21 @@ +package ru.bclib.mixin.common; + +import net.minecraft.util.random.WeightedRandomList; +import net.minecraft.world.entity.MobCategory; +import net.minecraft.world.level.biome.MobSpawnSettings; +import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.Map; + +@Mixin(MobSpawnSettings.class) +public interface MobSpawnSettingsAccessor { + @Accessor("spawners") + Map> bcl_getSpawners(); + + @Accessor("spawners") + @Mutable + void bcl_setSpawners(Map> spawners); +} diff --git a/src/main/java/ru/bclib/mixin/common/StructureSettingsAccessor.java b/src/main/java/ru/bclib/mixin/common/StructureSettingsAccessor.java new file mode 100644 index 00000000..e48342ef --- /dev/null +++ b/src/main/java/ru/bclib/mixin/common/StructureSettingsAccessor.java @@ -0,0 +1,28 @@ +package ru.bclib.mixin.common; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMultimap; +import net.minecraft.resources.ResourceKey; +import net.minecraft.util.random.WeightedRandomList; +import net.minecraft.world.entity.MobCategory; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; +import net.minecraft.world.level.levelgen.StructureSettings; +import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; +import net.minecraft.world.level.levelgen.feature.StructureFeature; +import net.minecraft.world.level.levelgen.feature.configurations.StructureFeatureConfiguration; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.Map; + +@Mixin(StructureSettings.class) +public interface StructureSettingsAccessor { + @Accessor("configuredStructures") + ImmutableMap, ImmutableMultimap, ResourceKey>> bcl_getStructureConfig(); + + @Accessor("configuredStructures") + @Mutable + void bcl_setStructureConfig(ImmutableMap, ImmutableMultimap, ResourceKey>> structureConfig); +} diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiome.java b/src/main/java/ru/bclib/world/biomes/BCLBiome.java index 59833b74..ab00606f 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiome.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiome.java @@ -6,9 +6,14 @@ import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import org.jetbrains.annotations.Nullable; +import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.util.WeightedList; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Random; @@ -58,7 +63,7 @@ public class BCLBiome { } /** - * Get current bime edge. + * Get current biome edge. * @return {@link BCLBiome} edge. */ @Nullable @@ -203,6 +208,14 @@ public class BCLBiome { return this; } + /** + * For internal use only!!! + * maintains a list of all structures added to this biome, this is automatically set by + * {@link ru.bclib.api.biomes.BCLBiomeBuilder} + */ + + public List attachedStructures = null; + /** * Recursively update biomes to correct world biome registry instances, for internal usage only. * @param biomeRegistry {@link Registry} for {@link Biome}. diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java index 69a57055..9fe6fdd1 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java @@ -362,7 +362,7 @@ public class BCLBiomeDef { .generationSettings(generationSettings.build()) .build(); - structures.forEach((structure) -> BiomeAPI.addBiomeStructure(b, structure)); + //structures.forEach((structure) -> BiomeAPI.addBiomeStructure(b., structure)); return b; } diff --git a/src/main/resources/bclib.mixins.common.json b/src/main/resources/bclib.mixins.common.json index 004e65c3..ea83b6ad 100644 --- a/src/main/resources/bclib.mixins.common.json +++ b/src/main/resources/bclib.mixins.common.json @@ -33,7 +33,10 @@ "AnvilBlockMixin", "AnvilMenuMixin", "TagLoaderMixin", - "MainMixin" + "MainMixin", + "BiomeGenerationSettingsAccessor", + "MobSpawnSettingsAccessor", + "StructureSettingsAccessor" ], "injectors": { "defaultRequire": 1 From 14451494ffa325320ed24a1cb8fca0eeb829c9a5 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Fri, 3 Dec 2021 14:26:12 +0300 Subject: [PATCH 71/96] Biome registry init changes --- .../java/ru/bclib/api/biomes/BiomeAPI.java | 4 ++-- .../mixin/common/MinecraftServerMixin.java | 2 +- .../bclib/mixin/common/ServerLevelMixin.java | 2 +- .../bclib/mixin/common/WorldPresetMixin.java | 19 +++++++++++++++++++ .../world/generator/BCLibEndBiomeSource.java | 1 + .../generator/BCLibNetherBiomeSource.java | 1 + src/main/resources/bclib.mixins.common.json | 1 + 7 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 src/main/java/ru/bclib/mixin/common/WorldPresetMixin.java diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index 50a30723..57dcdde7 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -86,8 +86,8 @@ public class BiomeAPI { * * @param server - {@link MinecraftServer} */ - public static void initRegistry(MinecraftServer server) { - biomeRegistry = server.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY); + public static void initRegistry( Registry biomeRegistry) { + BiomeAPI.biomeRegistry = biomeRegistry; CLIENT.clear(); } diff --git a/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java b/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java index 5d455fb1..23bf14d9 100644 --- a/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java +++ b/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java @@ -56,7 +56,7 @@ public class MinecraftServerMixin { @Inject(method = "loadLevel", at = @At(value = "RETURN"), cancellable = true) private void bclib_loadLevel(CallbackInfo info) { bclib_injectRecipes(); - BiomeAPI.initRegistry(MinecraftServer.class.cast(this)); + //BiomeAPI.initRegistry(MinecraftServer.class.cast(this)); } private void bclib_injectRecipes() { diff --git a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java index ccb3b8be..d0910008 100644 --- a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java +++ b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java @@ -38,7 +38,7 @@ public abstract class ServerLevelMixin extends Level { ServerLevel world = ServerLevel.class.cast(this); LifeCycleAPI._runLevelLoad(world, server, executor, levelStorageAccess, serverLevelData, resourceKey, dimensionType, chunkProgressListener, chunkGenerator, bl, l, list, bl2); - BiomeAPI.initRegistry(server); + //BiomeAPI.initRegistry(server); BiomeAPI.applyModifications(ServerLevel.class.cast(this)); if (bclib_lastWorld != null && bclib_lastWorld.equals(levelStorageAccess.getLevelId())) { diff --git a/src/main/java/ru/bclib/mixin/common/WorldPresetMixin.java b/src/main/java/ru/bclib/mixin/common/WorldPresetMixin.java new file mode 100644 index 00000000..d5bfd443 --- /dev/null +++ b/src/main/java/ru/bclib/mixin/common/WorldPresetMixin.java @@ -0,0 +1,19 @@ +package ru.bclib.mixin.common; + +import net.minecraft.client.gui.screens.worldselection.WorldPreset; +import net.minecraft.core.Registry; +import net.minecraft.core.RegistryAccess; +import net.minecraft.world.level.levelgen.WorldGenSettings; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import ru.bclib.api.biomes.BiomeAPI; + +@Mixin(WorldPreset.class) +public class WorldPresetMixin { + @Inject(method = "create", at = @At("HEAD")) + private void create(RegistryAccess.RegistryHolder registryHolder, long l, boolean bl, boolean bl2, CallbackInfoReturnable info) { + BiomeAPI.initRegistry(registryHolder.registryOrThrow(Registry.BIOME_REGISTRY)); + } +} diff --git a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java index 9392481f..bfae3eed 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java @@ -50,6 +50,7 @@ public class BCLibEndBiomeSource extends BiomeSource { public BCLibEndBiomeSource(Registry biomeRegistry, long seed) { super(getBiomes(biomeRegistry)); + BiomeAPI.initRegistry(biomeRegistry); BiomeAPI.END_LAND_BIOME_PICKER.clearMutables(); BiomeAPI.END_VOID_BIOME_PICKER.clearMutables(); diff --git a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java index 044e4c99..a17f0a3b 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java @@ -52,6 +52,7 @@ public class BCLibNetherBiomeSource extends BiomeSource { public BCLibNetherBiomeSource(Registry biomeRegistry, long seed) { super(getBiomes(biomeRegistry)); + BiomeAPI.initRegistry(biomeRegistry); BiomeAPI.NETHER_BIOME_PICKER.clearMutables(); this.possibleBiomes().forEach(biome -> { diff --git a/src/main/resources/bclib.mixins.common.json b/src/main/resources/bclib.mixins.common.json index 004e65c3..b1c56e5c 100644 --- a/src/main/resources/bclib.mixins.common.json +++ b/src/main/resources/bclib.mixins.common.json @@ -30,6 +30,7 @@ "shears.SheepMixin", "PortalShapeMixin", "ServerLevelMixin", + "WorldPresetMixin", "AnvilBlockMixin", "AnvilMenuMixin", "TagLoaderMixin", From 5154513cd44ff7af7d22432572d5d6bf26485689 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 3 Dec 2021 12:34:39 +0100 Subject: [PATCH 72/96] Use `CollectionUtils` --- .../java/ru/bclib/api/biomes/BiomeAPI.java | 26 +++---------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index e2fffc82..41a4f745 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -576,8 +576,8 @@ public class BiomeAPI { public static void addBiomeMobSpawn(Biome biome, EntityType entityType, int weight, int minGroupCount, int maxGroupCount) { final MobCategory category = entityType.getCategory(); MobSpawnSettingsAccessor accessor = (MobSpawnSettingsAccessor) biome.getMobSettings(); - Map> spawners = getMutableMap(accessor.bcl_getSpawners()); - List mobs = spawners.containsKey(category) ? getMutableList(spawners.get(category).unwrap()) : Lists.newArrayList(); + Map> spawners = CollectionsUtil.getMutable(accessor.bcl_getSpawners()); + List mobs = spawners.containsKey(category) ? CollectionsUtil.getMutable(spawners.get(category).unwrap()) : Lists.newArrayList(); mobs.add(new SpawnerData(entityType, weight, minGroupCount, maxGroupCount)); spawners.put(category, WeightedRandomList.create(mobs)); accessor.bcl_setSpawners(spawners); @@ -603,24 +603,11 @@ public class BiomeAPI { lists.add(Lists.newArrayList()); } } - List> list = getMutableList(lists.get(index)); + List> list = CollectionsUtil.getMutable(lists.get(index)); lists.set(index, list); return list; } - private static List getMutableList(List input) { - if (input!=null) { - System.out.println("getMutableList: " + input.getClass().getName()); - for (Class cl : input.getClass().getInterfaces()){ - System.out.println(" - " + cl.getName()); - } - } - if (/*input instanceof ImmutableList ||*/ !(input instanceof ArrayList || input instanceof LinkedList)) { - return Lists.newArrayList(input); - } - return input; - } - private static List> getFeaturesList(List>> features, Decoration step) { int index = step.ordinal(); while (features.size() <= index) { @@ -631,13 +618,6 @@ public class BiomeAPI { return mutable; } - private static Map getMutableMap(Map input) { - if (/*input instanceof ImmutableMap*/ !(input instanceof HashMap ||input instanceof EnumMap)) { - return Maps.newHashMap(input); - } - return input; - } - //inspired by net.fabricmc.fabric.impl.biome.modification.BiomeStructureStartsImpl private static Map, Multimap, ResourceKey>> getMutableStructureConfig(NoiseGeneratorSettings settings) { final StructureSettingsAccessor access = (StructureSettingsAccessor)settings.structureSettings(); From dea05bce0d229455fe41dcf6c98557c172bce225 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Fri, 3 Dec 2021 14:46:02 +0300 Subject: [PATCH 73/96] Biome carvers modifications --- .../ru/bclib/api/biomes/BCLBiomeBuilder.java | 1 - .../java/ru/bclib/api/biomes/BiomeAPI.java | 76 +++++++------------ .../BiomeGenerationSettingsAccessor.java | 10 +++ .../java/ru/bclib/mixin/common/MainMixin.java | 1 - .../mixin/common/MinecraftServerMixin.java | 1 - .../bclib/mixin/common/ServerLevelMixin.java | 2 - .../common/StructureSettingsAccessor.java | 6 -- .../java/ru/bclib/world/biomes/BCLBiome.java | 3 - .../ru/bclib/world/biomes/BCLBiomeDef.java | 1 - 9 files changed, 39 insertions(+), 62 deletions(-) diff --git a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index da74bf61..4d6332a5 100644 --- a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java @@ -1,7 +1,6 @@ package ru.bclib.api.biomes; import net.fabricmc.fabric.api.biome.v1.BiomeModifications; -import net.minecraft.core.Registry; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.data.BuiltinRegistries; import net.minecraft.data.worldgen.BiomeDefaultFeatures; diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index e2fffc82..663bd6a0 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -16,7 +16,6 @@ import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; import net.minecraft.util.random.WeightedRandomList; import net.minecraft.world.entity.EntityType; @@ -28,8 +27,10 @@ import net.minecraft.world.level.biome.BiomeSource; import net.minecraft.world.level.biome.Biomes; import net.minecraft.world.level.biome.Climate; import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; +import net.minecraft.world.level.levelgen.GenerationStep.Carving; import net.minecraft.world.level.levelgen.GenerationStep.Decoration; import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; +import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import net.minecraft.world.level.levelgen.feature.StructureFeature; @@ -49,9 +50,7 @@ import ru.bclib.world.generator.BiomePicker; import ru.bclib.world.structures.BCLStructureFeature; import java.util.ArrayList; -import java.util.EnumMap; import java.util.HashMap; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Random; @@ -93,10 +92,9 @@ public class BiomeAPI { /** * Initialize registry for current server. - * - * @param server - {@link MinecraftServer} + * @param biomeRegistry - {@link Registry} for {@link Biome}. */ - public static void initRegistry( Registry biomeRegistry) { + public static void initRegistry(Registry biomeRegistry) { BiomeAPI.biomeRegistry = biomeRegistry; CLIENT.clear(); } @@ -503,21 +501,16 @@ public class BiomeAPI { * @param structure {@link ConfiguredStructureFeature} to add. */ public static void addBiomeStructure(ResourceKey biomeKey, ConfiguredStructureFeature structure) { - //BiomeStructureStartsImpl.addStart(registries, structure, getBiomeID(biome)); changeStructureStarts(structureMap -> { Multimap, ResourceKey> configuredMap = structureMap.computeIfAbsent(structure.feature, k -> HashMultimap.create()); configuredMap.put(structure, biomeKey); }); - - } public static void addBiomeStructure(Biome biome, ConfiguredStructureFeature structure) { - //BiomeStructureStartsImpl.addStart(registries, structure, getBiomeID(biome)); changeStructureStarts(structureMap -> { Multimap, ResourceKey> configuredMap = structureMap.computeIfAbsent(structure.feature, k -> HashMultimap.create()); - var key = getBiomeKey(biome); if (key!=null) { configuredMap.put(structure, key); @@ -525,11 +518,8 @@ public class BiomeAPI { BCLib.LOGGER.error("Unable to find Biome " + getBiomeID(biome)); } }); - - } - private static void changeStructureStarts(Consumer, Multimap, ResourceKey>>> modifier) { Registry chunkGenSettingsRegistry = BuiltinRegistries.NOISE_GENERATOR_SETTINGS; @@ -539,11 +529,8 @@ public class BiomeAPI { modifier.accept(structureMap); setMutableStructureConfig(entry.getValue(), structureMap); } - - } - /** * Adds new structure feature to existing biome. * @param biomeKey {@link ResourceKey} for the {@link Biome} to add structure feature in. @@ -552,7 +539,6 @@ public class BiomeAPI { public static void addBiomeStructure(ResourceKey biomeKey, BCLStructureFeature structure) { addBiomeStructure(biomeKey, structure.getFeatureConfigured()); } - /** * Adds new structure features to existing biome. @@ -565,6 +551,21 @@ public class BiomeAPI { } } + /** + * Adds new carver into existing biome. + * @param biome {@link Biome} to add carver in. + * @param carver {@link ConfiguredWorldCarver} to add. + * @param stage {@link Carving} stage. + */ + 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<>())); + carvers.put(stage, carverList); + carverList.add(() -> carver); + accessor.bclib_setCarvers(carvers); + } + /** * Adds mob spawning to specified biome. * @param biome {@link Biome} to add mob spawning. @@ -576,8 +577,8 @@ public class BiomeAPI { public static void addBiomeMobSpawn(Biome biome, EntityType entityType, int weight, int minGroupCount, int maxGroupCount) { final MobCategory category = entityType.getCategory(); MobSpawnSettingsAccessor accessor = (MobSpawnSettingsAccessor) biome.getMobSettings(); - Map> spawners = getMutableMap(accessor.bcl_getSpawners()); - List mobs = spawners.containsKey(category) ? getMutableList(spawners.get(category).unwrap()) : Lists.newArrayList(); + Map> spawners = CollectionsUtil.getMutable(accessor.bcl_getSpawners()); + List mobs = spawners.containsKey(category) ? CollectionsUtil.getMutable(spawners.get(category).unwrap()) : Lists.newArrayList(); mobs.add(new SpawnerData(entityType, weight, minGroupCount, maxGroupCount)); spawners.put(category, WeightedRandomList.create(mobs)); accessor.bcl_setSpawners(spawners); @@ -603,24 +604,11 @@ public class BiomeAPI { lists.add(Lists.newArrayList()); } } - List> list = getMutableList(lists.get(index)); + List> list = CollectionsUtil.getMutable(lists.get(index)); lists.set(index, list); return list; } - private static List getMutableList(List input) { - if (input!=null) { - System.out.println("getMutableList: " + input.getClass().getName()); - for (Class cl : input.getClass().getInterfaces()){ - System.out.println(" - " + cl.getName()); - } - } - if (/*input instanceof ImmutableList ||*/ !(input instanceof ArrayList || input instanceof LinkedList)) { - return Lists.newArrayList(input); - } - return input; - } - private static List> getFeaturesList(List>> features, Decoration step) { int index = step.ordinal(); while (features.size() <= index) { @@ -631,13 +619,6 @@ public class BiomeAPI { return mutable; } - private static Map getMutableMap(Map input) { - if (/*input instanceof ImmutableMap*/ !(input instanceof HashMap ||input instanceof EnumMap)) { - return Maps.newHashMap(input); - } - return input; - } - //inspired by net.fabricmc.fabric.impl.biome.modification.BiomeStructureStartsImpl private static Map, Multimap, ResourceKey>> getMutableStructureConfig(NoiseGeneratorSettings settings) { final StructureSettingsAccessor access = (StructureSettingsAccessor)settings.structureSettings(); @@ -653,11 +634,12 @@ public class BiomeAPI { //inspired by net.fabricmc.fabric.impl.biome.modification.BiomeStructureStartsImpl private static void setMutableStructureConfig(NoiseGeneratorSettings settings, Map, Multimap, ResourceKey>> structureStarts) { - final StructureSettingsAccessor access = (StructureSettingsAccessor)settings.structureSettings(); - access.bcl_setStructureConfig(structureStarts.entrySet().stream() - .collect(ImmutableMap.toImmutableMap( - Map.Entry::getKey, - e -> ImmutableMultimap.copyOf(e.getValue()) - ))); + final StructureSettingsAccessor access = (StructureSettingsAccessor) settings.structureSettings(); + access.bcl_setStructureConfig( + structureStarts + .entrySet() + .stream() + .collect(ImmutableMap.toImmutableMap(Map.Entry::getKey, e -> ImmutableMultimap.copyOf(e.getValue()))) + ); } } diff --git a/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java b/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java index b31f859e..fcb6ec6f 100644 --- a/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java +++ b/src/main/java/ru/bclib/mixin/common/BiomeGenerationSettingsAccessor.java @@ -1,12 +1,16 @@ package ru.bclib.mixin.common; import net.minecraft.world.level.biome.BiomeGenerationSettings; +import net.minecraft.world.level.levelgen.GenerationStep; +import net.minecraft.world.level.levelgen.GenerationStep.Carving; +import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver; import net.minecraft.world.level.levelgen.placement.PlacedFeature; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; import org.spongepowered.asm.mixin.gen.Accessor; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.function.Supplier; @@ -24,4 +28,10 @@ public interface BiomeGenerationSettingsAccessor { @Accessor("featureSet") void bclib_setFeatureSet(Set features); + + @Accessor("carvers") + Map>>> bclib_getCarvers(); + + @Accessor("carvers") + void bclib_setCarvers(Map>>> features); } diff --git a/src/main/java/ru/bclib/mixin/common/MainMixin.java b/src/main/java/ru/bclib/mixin/common/MainMixin.java index e672681d..059129e0 100644 --- a/src/main/java/ru/bclib/mixin/common/MainMixin.java +++ b/src/main/java/ru/bclib/mixin/common/MainMixin.java @@ -1,7 +1,6 @@ package ru.bclib.mixin.common; import net.minecraft.server.Main; -import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.storage.LevelStorageSource; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; diff --git a/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java b/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java index 23bf14d9..e337b2c6 100644 --- a/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java +++ b/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java @@ -21,7 +21,6 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.api.dataexchange.DataExchangeAPI; import ru.bclib.recipes.BCLRecipeManager; diff --git a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java index d0910008..d405536a 100644 --- a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java +++ b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java @@ -9,13 +9,11 @@ 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; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.At.Shift; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import ru.bclib.api.LifeCycleAPI; diff --git a/src/main/java/ru/bclib/mixin/common/StructureSettingsAccessor.java b/src/main/java/ru/bclib/mixin/common/StructureSettingsAccessor.java index e48342ef..cb323706 100644 --- a/src/main/java/ru/bclib/mixin/common/StructureSettingsAccessor.java +++ b/src/main/java/ru/bclib/mixin/common/StructureSettingsAccessor.java @@ -3,20 +3,14 @@ package ru.bclib.mixin.common; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; import net.minecraft.resources.ResourceKey; -import net.minecraft.util.random.WeightedRandomList; -import net.minecraft.world.entity.MobCategory; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; import net.minecraft.world.level.levelgen.StructureSettings; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import net.minecraft.world.level.levelgen.feature.StructureFeature; -import net.minecraft.world.level.levelgen.feature.configurations.StructureFeatureConfiguration; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; import org.spongepowered.asm.mixin.gen.Accessor; -import java.util.Map; - @Mixin(StructureSettings.class) public interface StructureSettingsAccessor { @Accessor("configuredStructures") diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiome.java b/src/main/java/ru/bclib/world/biomes/BCLBiome.java index ab00606f..bc0cb223 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiome.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiome.java @@ -8,11 +8,8 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import org.jetbrains.annotations.Nullable; -import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.util.WeightedList; -import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Random; diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java index 9fe6fdd1..f0a59596 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java @@ -27,7 +27,6 @@ import net.minecraft.world.level.levelgen.carver.CarverConfiguration; import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import net.minecraft.world.level.levelgen.placement.PlacedFeature; -import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.config.IdConfig; import ru.bclib.config.PathConfig; import ru.bclib.util.ColorUtil; From 8e3147f17613406f55dc72ca2c9afc9586b28035 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Fri, 3 Dec 2021 15:39:08 +0300 Subject: [PATCH 74/96] Rule source prototype --- .../java/ru/bclib/api/biomes/BiomeAPI.java | 70 ++++++++++++++++++- .../mixin/common/SurfaceRuleDataMixin.java | 27 +++++++ 2 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 src/main/java/ru/bclib/mixin/common/SurfaceRuleDataMixin.java diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index 663bd6a0..0b1d564f 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -14,6 +14,7 @@ import net.fabricmc.fabric.impl.biome.TheEndBiomeData; import net.minecraft.client.Minecraft; import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; +import net.minecraft.data.worldgen.SurfaceRuleData; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; @@ -27,9 +28,11 @@ import net.minecraft.world.level.biome.BiomeSource; import net.minecraft.world.level.biome.Biomes; import net.minecraft.world.level.biome.Climate; import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; +import net.minecraft.world.level.dimension.DimensionType; import net.minecraft.world.level.levelgen.GenerationStep.Carving; import net.minecraft.world.level.levelgen.GenerationStep.Decoration; import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; +import net.minecraft.world.level.levelgen.SurfaceRules; import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; @@ -58,6 +61,7 @@ import java.util.Set; import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Supplier; +import java.util.stream.Collectors; public class BiomeAPI { /** @@ -75,6 +79,7 @@ public class BiomeAPI { private static Registry biomeRegistry; private static final Map>> MODIFICATIONS = Maps.newHashMap(); + private static final Map SURFACE_RULES = Maps.newHashMap(); private static final Set MODIFIED_BIOMES = Sets.newHashSet(); public static final BCLBiome NETHER_WASTES_BIOME = registerNetherBiome(getFromRegistry(Biomes.NETHER_WASTES)); @@ -90,6 +95,9 @@ public class BiomeAPI { 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"))); + private static SurfaceRules.RuleSource netherRuleSource; + private static SurfaceRules.RuleSource endRuleSource; + /** * Initialize registry for current server. * @param biomeRegistry - {@link Registry} for {@link Biome}. @@ -409,19 +417,56 @@ public class BiomeAPI { registerBiomeModification(Level.END, modification); } + /** + * Returns surface rule source for the Nether. + * @return {@link SurfaceRules.RuleSource}. + */ + public static SurfaceRules.RuleSource getNetherRuleSource() { + return netherRuleSource; + } + + /** + * Returns surface rule source for the End. + * @return {@link SurfaceRules.RuleSource}. + */ + public static SurfaceRules.RuleSource getEndRuleSource() { + return endRuleSource; + } + /** * Will apply biome modifications to world, internal usage only. * @param level */ public static void applyModifications(ServerLevel level) { + BiomeSource source = level.getChunkSource().getGenerator().getBiomeSource(); + Set biomes = source.possibleBiomes(); + + if (level.dimension() == Level.NETHER) { + Set biomeIDs = biomes.stream().map(biome -> getBiomeID(biome)).collect(Collectors.toSet()); + List rules = Lists.newArrayList(); + SURFACE_RULES.forEach((biomeID, rule) -> { + if (biomeIDs.contains(biomeID)) { + rules.add(rule); + } + }); + netherRuleSource = SurfaceRules.sequence(rules.toArray(new SurfaceRules.RuleSource[rules.size()])); + } + else if (level.dimension() == Level.END) { + Set biomeIDs = biomes.stream().map(biome -> getBiomeID(biome)).collect(Collectors.toSet()); + List rules = Lists.newArrayList(); + SURFACE_RULES.forEach((biomeID, rule) -> { + if (biomeIDs.contains(biomeID)) { + rules.add(rule); + } + }); + endRuleSource = SurfaceRules.sequence(rules.toArray(new SurfaceRules.RuleSource[rules.size()])); + } + List> modifications = MODIFICATIONS.get(level.dimension()); if (modifications == null) { return; } - BiomeSource source = level.getChunkSource().getGenerator().getBiomeSource(); - Set biomes = source.possibleBiomes(); - biomes.forEach(biome -> { ResourceLocation biomeID = getBiomeID(biome); boolean modify = isDatapackBiome(biomeID); @@ -566,6 +611,25 @@ public class BiomeAPI { accessor.bclib_setCarvers(carvers); } + /** + * Adds surface rule to specified biome. + * @param biomeID biome {@link ResourceLocation}. + * @param source {@link SurfaceRules.RuleSource}. + */ + public static void addSurfaceRule(ResourceLocation biomeID, SurfaceRules.RuleSource source) { + SURFACE_RULES.put(biomeID, source); + } + + /** + * Get surface rule for the biome using its {@link ResourceLocation} ID as a key. + * @param biomeID {@link ResourceLocation} biome ID. + * @return {@link SurfaceRules.RuleSource}. + */ + @Nullable + public static SurfaceRules.RuleSource getSurfaceRule(ResourceLocation biomeID) { + return SURFACE_RULES.get(biomeID); + } + /** * Adds mob spawning to specified biome. * @param biome {@link Biome} to add mob spawning. diff --git a/src/main/java/ru/bclib/mixin/common/SurfaceRuleDataMixin.java b/src/main/java/ru/bclib/mixin/common/SurfaceRuleDataMixin.java new file mode 100644 index 00000000..3a12b90b --- /dev/null +++ b/src/main/java/ru/bclib/mixin/common/SurfaceRuleDataMixin.java @@ -0,0 +1,27 @@ +package ru.bclib.mixin.common; + +import net.minecraft.data.worldgen.SurfaceRuleData; +import net.minecraft.world.level.levelgen.SurfaceRules; +import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import ru.bclib.api.biomes.BiomeAPI; + +@Mixin(SurfaceRuleData.class) +public class SurfaceRuleDataMixin { + @Inject(method = "nether", at = @At("RETURN"), cancellable = true) + private static void bclib_addNetherRuleSource(CallbackInfoReturnable info) { + RuleSource source = info.getReturnValue(); + source = SurfaceRules.sequence(source, BiomeAPI.getNetherRuleSource()); + info.setReturnValue(source); + } + + @Inject(method = "end", at = @At("RETURN"), cancellable = true) + private static void bclib_addEndRuleSource(CallbackInfoReturnable info) { + RuleSource source = info.getReturnValue(); + source = SurfaceRules.sequence(source, BiomeAPI.getEndRuleSource()); + info.setReturnValue(source); + } +} From d3273f609a52c96339943e9496fb7c0bce202bb6 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Fri, 3 Dec 2021 15:45:19 +0300 Subject: [PATCH 75/96] Crash fix --- .../java/ru/bclib/api/biomes/BiomeAPI.java | 34 ++++++++++--------- .../mixin/common/SurfaceRuleDataMixin.java | 16 +++++---- src/main/resources/bclib.mixins.common.json | 3 +- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index 0b1d564f..2e84194e 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -33,6 +33,7 @@ import net.minecraft.world.level.levelgen.GenerationStep.Carving; import net.minecraft.world.level.levelgen.GenerationStep.Decoration; import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; import net.minecraft.world.level.levelgen.SurfaceRules; +import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource; import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; @@ -442,24 +443,14 @@ public class BiomeAPI { Set biomes = source.possibleBiomes(); if (level.dimension() == Level.NETHER) { - Set biomeIDs = biomes.stream().map(biome -> getBiomeID(biome)).collect(Collectors.toSet()); - List rules = Lists.newArrayList(); - SURFACE_RULES.forEach((biomeID, rule) -> { - if (biomeIDs.contains(biomeID)) { - rules.add(rule); - } - }); - netherRuleSource = SurfaceRules.sequence(rules.toArray(new SurfaceRules.RuleSource[rules.size()])); + RuleSource[] rules = getRuleSources(biomes); + netherRuleSource = rules.length > 0 ? SurfaceRules.sequence(rules) : null; + System.out.println("Adding nether sources! " + rules.length); } else if (level.dimension() == Level.END) { - Set biomeIDs = biomes.stream().map(biome -> getBiomeID(biome)).collect(Collectors.toSet()); - List rules = Lists.newArrayList(); - SURFACE_RULES.forEach((biomeID, rule) -> { - if (biomeIDs.contains(biomeID)) { - rules.add(rule); - } - }); - endRuleSource = SurfaceRules.sequence(rules.toArray(new SurfaceRules.RuleSource[rules.size()])); + RuleSource[] rules = getRuleSources(biomes); + endRuleSource = rules.length > 0 ? SurfaceRules.sequence(rules) : null; + System.out.println("Adding end sources! " + rules.length); } List> modifications = MODIFICATIONS.get(level.dimension()); @@ -485,6 +476,17 @@ public class BiomeAPI { }); } + private static SurfaceRules.RuleSource[] getRuleSources(Set biomes) { + Set biomeIDs = biomes.stream().map(biome -> getBiomeID(biome)).collect(Collectors.toSet()); + List rules = Lists.newArrayList(); + SURFACE_RULES.forEach((biomeID, rule) -> { + if (biomeIDs.contains(biomeID)) { + rules.add(rule); + } + }); + return rules.toArray(new SurfaceRules.RuleSource[rules.size()]); + } + /** * Adds new features to existing biome. * @param biome {@link Biome} to add features in. diff --git a/src/main/java/ru/bclib/mixin/common/SurfaceRuleDataMixin.java b/src/main/java/ru/bclib/mixin/common/SurfaceRuleDataMixin.java index 3a12b90b..4e04d7e0 100644 --- a/src/main/java/ru/bclib/mixin/common/SurfaceRuleDataMixin.java +++ b/src/main/java/ru/bclib/mixin/common/SurfaceRuleDataMixin.java @@ -13,15 +13,19 @@ import ru.bclib.api.biomes.BiomeAPI; public class SurfaceRuleDataMixin { @Inject(method = "nether", at = @At("RETURN"), cancellable = true) private static void bclib_addNetherRuleSource(CallbackInfoReturnable info) { - RuleSource source = info.getReturnValue(); - source = SurfaceRules.sequence(source, BiomeAPI.getNetherRuleSource()); - info.setReturnValue(source); + if (BiomeAPI.getNetherRuleSource() != null) { + RuleSource source = info.getReturnValue(); + source = SurfaceRules.sequence(source, BiomeAPI.getNetherRuleSource()); + info.setReturnValue(source); + } } @Inject(method = "end", at = @At("RETURN"), cancellable = true) private static void bclib_addEndRuleSource(CallbackInfoReturnable info) { - RuleSource source = info.getReturnValue(); - source = SurfaceRules.sequence(source, BiomeAPI.getEndRuleSource()); - info.setReturnValue(source); + if (BiomeAPI.getEndRuleSource() != null) { + RuleSource source = info.getReturnValue(); + source = SurfaceRules.sequence(source, BiomeAPI.getEndRuleSource()); + info.setReturnValue(source); + } } } diff --git a/src/main/resources/bclib.mixins.common.json b/src/main/resources/bclib.mixins.common.json index df63f458..da8faabc 100644 --- a/src/main/resources/bclib.mixins.common.json +++ b/src/main/resources/bclib.mixins.common.json @@ -37,7 +37,8 @@ "MainMixin", "BiomeGenerationSettingsAccessor", "MobSpawnSettingsAccessor", - "StructureSettingsAccessor" + "StructureSettingsAccessor", + "SurfaceRuleDataMixin" ], "injectors": { "defaultRequire": 1 From 113118afbd9aa2d8dea524600c96b2302400a976 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Fri, 3 Dec 2021 15:55:02 +0300 Subject: [PATCH 76/96] Small changes --- .../java/ru/bclib/api/biomes/BiomeAPI.java | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index 2e84194e..2fe2f267 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -24,6 +24,7 @@ import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.MobCategory; import net.minecraft.world.level.Level; import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.Biome.BiomeCategory; import net.minecraft.world.level.biome.BiomeSource; import net.minecraft.world.level.biome.Biomes; import net.minecraft.world.level.biome.Climate; @@ -57,6 +58,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Random; import java.util.Set; import java.util.function.BiConsumer; @@ -443,12 +445,12 @@ public class BiomeAPI { Set biomes = source.possibleBiomes(); if (level.dimension() == Level.NETHER) { - RuleSource[] rules = getRuleSources(biomes); + RuleSource[] rules = getRuleSources(biomes, level.dimension()); netherRuleSource = rules.length > 0 ? SurfaceRules.sequence(rules) : null; System.out.println("Adding nether sources! " + rules.length); } else if (level.dimension() == Level.END) { - RuleSource[] rules = getRuleSources(biomes); + RuleSource[] rules = getRuleSources(biomes, level.dimension()); endRuleSource = rules.length > 0 ? SurfaceRules.sequence(rules) : null; System.out.println("Adding end sources! " + rules.length); } @@ -476,7 +478,7 @@ public class BiomeAPI { }); } - private static SurfaceRules.RuleSource[] getRuleSources(Set biomes) { + private static SurfaceRules.RuleSource[] getRuleSources(Set biomes, ResourceKey dimensionType) { Set biomeIDs = biomes.stream().map(biome -> getBiomeID(biome)).collect(Collectors.toSet()); List rules = Lists.newArrayList(); SURFACE_RULES.forEach((biomeID, rule) -> { @@ -484,6 +486,30 @@ public class BiomeAPI { rules.add(rule); } }); + + // Try handle biomes from other dimension, may work not as expected + // Will not work + /*Optional optional = biomes + .stream() + .filter(biome -> biome.getBiomeCategory() != BiomeCategory.THEEND && biome.getBiomeCategory() != BiomeCategory.NETHER) + .findAny(); + if (optional.isPresent()) { + rules.add(SurfaceRuleData.overworld()); + } + + if (dimensionType == Level.NETHER) { + optional = biomes.stream().filter(biome -> biome.getBiomeCategory() != BiomeCategory.THEEND).findAny(); + if (optional.isPresent()) { + rules.add(SurfaceRuleData.end()); + } + } + else if (dimensionType == Level.END) { + optional = biomes.stream().filter(biome -> biome.getBiomeCategory() != BiomeCategory.NETHER).findAny(); + if (optional.isPresent()) { + rules.add(SurfaceRuleData.end()); + } + }*/ + return rules.toArray(new SurfaceRules.RuleSource[rules.size()]); } From 77eba4b33ffa0f19cce1695be68ad0ebc35b7d3d Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 3 Dec 2021 14:44:14 +0100 Subject: [PATCH 77/96] Minor cleanup for tool breaking behavior --- .../java/ru/bclib/blocks/BaseLeavesBlock.java | 11 ++++--- .../java/ru/bclib/blocks/BaseOreBlock.java | 31 ++++++++++++++----- .../java/ru/bclib/registry/BlockRegistry.java | 6 +++- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java b/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java index 3dd32197..784667b3 100644 --- a/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java @@ -4,8 +4,10 @@ import com.google.common.collect.Lists; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.client.renderer.block.model.BlockModel; +import net.minecraft.data.loot.BlockLoot; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.ShovelItem; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.level.block.Block; @@ -15,6 +17,7 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; +import ru.bclib.api.TagAPI; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.BlockModelProvider; import ru.bclib.interfaces.RenderLayerProvider; @@ -30,9 +33,9 @@ public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, private static FabricBlockSettings makeLeaves(MaterialColor color) { return FabricBlockSettings.copyOf(Blocks.OAK_LEAVES) .mapColor(color) - .breakByTool(FabricToolTags.HOES) + .requiresTool() .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) + .breakByTool(FabricToolTags.HOES) .allowsSpawning((state, world, pos, type) -> false) .suffocates((state, world, pos) -> false) .blockVision((state, world, pos) -> false); @@ -42,7 +45,7 @@ public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, super(BaseBlock.acceptAndReturn(customizeProperties, makeLeaves(color))); this.sapling = sapling; } - + public BaseLeavesBlock(Block sapling, MaterialColor color, int light, Consumer customizeProperties) { super(BaseBlock.acceptAndReturn(customizeProperties, makeLeaves(color).luminance(light))); this.sapling = sapling; @@ -68,7 +71,7 @@ public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, public List getDrops(BlockState state, LootContext.Builder builder) { ItemStack tool = builder.getParameter(LootContextParams.TOOL); if (tool != null) { - if (FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel( + if (tool.isCorrectToolForDrops(state) || EnchantmentHelper.getItemEnchantmentLevel( Enchantments.SILK_TOUCH, tool ) > 0) { diff --git a/src/main/java/ru/bclib/blocks/BaseOreBlock.java b/src/main/java/ru/bclib/blocks/BaseOreBlock.java index 31963438..fa009b6f 100644 --- a/src/main/java/ru/bclib/blocks/BaseOreBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseOreBlock.java @@ -1,6 +1,8 @@ package ru.bclib.blocks; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; +import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; +import net.fabricmc.fabric.impl.object.builder.FabricBlockInternals; import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; @@ -17,6 +19,7 @@ import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; +import ru.bclib.api.TagAPI; import ru.bclib.interfaces.BlockModelProvider; import ru.bclib.util.MHelper; @@ -29,16 +32,30 @@ public class BaseOreBlock extends OreBlock implements BlockModelProvider { private final int maxCount; public BaseOreBlock(Item drop, int minCount, int maxCount, int experience) { - this(drop, minCount, maxCount, experience, FabricBlockSettings.of(Material.STONE, MaterialColor.SAND) - .destroyTime(3F) - .explosionResistance(9F) - .requiresCorrectToolForDrops() - .sound(SoundType.STONE)); + this(drop, minCount, maxCount, experience, 0); } - public BaseOreBlock(Item drop, int minCount, int maxCount, int experience, Properties properties) { - super(properties, UniformInt.of(experience>0?1:0, experience)); + public BaseOreBlock(Item drop, int minCount, int maxCount, int experience, int miningLevel) { + this(drop, minCount, maxCount, experience, miningLevel, FabricBlockSettings.of(Material.STONE, MaterialColor.SAND) + .requiresTool() + .destroyTime(3F) + .explosionResistance(9F) + .sound(SoundType.STONE)); + + } + + private static Properties makeProps(Properties properties, int level){ + FabricBlockInternals.computeExtraData(properties).addMiningLevel(FabricToolTags.PICKAXES, level); + return properties; + } + + public BaseOreBlock(Item drop, int minCount, int maxCount, int experience, Properties properties) { + this(drop, minCount, maxCount, experience, 0, properties); + } + + public BaseOreBlock(Item drop, int minCount, int maxCount, int experience, int miningLevel, Properties properties) { + super(makeProps(properties, miningLevel), UniformInt.of(experience>0?1:0, experience)); this.dropItem = drop; this.minCount = minCount; this.maxCount = maxCount; diff --git a/src/main/java/ru/bclib/registry/BlockRegistry.java b/src/main/java/ru/bclib/registry/BlockRegistry.java index 608e9ca7..bf067f1e 100644 --- a/src/main/java/ru/bclib/registry/BlockRegistry.java +++ b/src/main/java/ru/bclib/registry/BlockRegistry.java @@ -1,5 +1,6 @@ package ru.bclib.registry; +import net.fabricmc.fabric.api.mininglevel.v1.FabricMineableTags; import net.fabricmc.fabric.api.registry.FlammableBlockRegistry; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; @@ -10,6 +11,7 @@ import net.minecraft.world.item.Items; import net.minecraft.world.level.block.Block; import ru.bclib.api.TagAPI; import ru.bclib.blocks.BaseLeavesBlock; +import ru.bclib.blocks.BaseOreBlock; import ru.bclib.blocks.FeatureSaplingBlock; import ru.bclib.config.PathConfig; import ru.bclib.interfaces.CustomItemProvider; @@ -41,10 +43,12 @@ public class BlockRegistry extends BaseRegistry { getModBlocks(id.getNamespace()).add(block); if (block instanceof BaseLeavesBlock){ - TagAPI.addTags(block, TagAPI.BLOCK_LEAVES); + TagAPI.addTags(block, TagAPI.BLOCK_LEAVES, TagAPI.MINEABLE_HOE, FabricMineableTags.SHEARS_MINEABLE); if (item != null){ TagAPI.addTags(item, TagAPI.ITEM_LEAVES); } + } else if (block instanceof BaseOreBlock){ + TagAPI.addTags(block, TagAPI.MINEABLE_PICKAXE); } else if (block instanceof FeatureSaplingBlock){ TagAPI.addTags(block, TagAPI.BLOCK_SAPLINGS); if (item != null){ From d09a3a06dfe0d2139fcb95d9d2bdae18dd90393b Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 3 Dec 2021 14:59:35 +0100 Subject: [PATCH 78/96] added back surface-Block to BiomeBuilder --- .../java/ru/bclib/api/biomes/BCLBiomeBuilder.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index 4d6332a5..298cfedc 100644 --- a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java @@ -4,6 +4,7 @@ import net.fabricmc.fabric.api.biome.v1.BiomeModifications; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.data.BuiltinRegistries; import net.minecraft.data.worldgen.BiomeDefaultFeatures; +import net.minecraft.data.worldgen.SurfaceRuleData; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.Music; import net.minecraft.sounds.SoundEvent; @@ -21,8 +22,10 @@ import net.minecraft.world.level.biome.BiomeGenerationSettings; import net.minecraft.world.level.biome.BiomeSpecialEffects; import net.minecraft.world.level.biome.MobSpawnSettings; import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.levelgen.GenerationStep; import net.minecraft.world.level.levelgen.GenerationStep.Decoration; +import net.minecraft.world.level.levelgen.SurfaceRules; import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import net.minecraft.world.level.levelgen.placement.PlacedFeature; @@ -481,6 +484,17 @@ public class BCLBiomeBuilder { return this; } + private List surfaceRules = new ArrayList<>(2); + /** + * Adds new world surface rule for the given block + * @param surfaceBlock {@link Block} to use. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder surface(Block surfaceBlock) { + surfaceRules.add(SurfaceRules.ifTrue(SurfaceRules.ON_FLOOR, SurfaceRules.state(surfaceBlock.defaultBlockState()))); + return this; + } + /** * Finalize biome creation. * @return created {@link BCLBiome} instance. @@ -515,6 +529,7 @@ public class BCLBiomeBuilder { final T res = biomeConstructor.apply(biomeID, builder.build()); res.attachedStructures = structures; + surfaceRules.forEach(s -> BiomeAPI.addSurfaceRule(BiomeAPI.getBiomeID(res.getBiome()), s)); res.setFogDensity(fogDensity); return res; } From 699332600b4f6cec5332f531bfba9183740129c0 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 3 Dec 2021 15:10:33 +0100 Subject: [PATCH 79/96] Tets application of surface rules --- .../java/ru/bclib/api/biomes/BCLBiomeBuilder.java | 2 +- src/main/java/ru/bclib/world/biomes/BCLBiome.java | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index 298cfedc..7da9a5e2 100644 --- a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java @@ -529,7 +529,7 @@ public class BCLBiomeBuilder { final T res = biomeConstructor.apply(biomeID, builder.build()); res.attachedStructures = structures; - surfaceRules.forEach(s -> BiomeAPI.addSurfaceRule(BiomeAPI.getBiomeID(res.getBiome()), s)); + res.surfaceRules = surfaceRules; res.setFogDensity(fogDensity); return res; } diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiome.java b/src/main/java/ru/bclib/world/biomes/BCLBiome.java index bc0cb223..132eedb5 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiome.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiome.java @@ -6,8 +6,10 @@ import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.levelgen.SurfaceRules; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import org.jetbrains.annotations.Nullable; +import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.util.WeightedList; import java.util.List; @@ -210,9 +212,15 @@ public class BCLBiome { * maintains a list of all structures added to this biome, this is automatically set by * {@link ru.bclib.api.biomes.BCLBiomeBuilder} */ - public List attachedStructures = null; + /** + * For internal use only!!! + * maintains a list of all structures added to this biome, this is automatically set by + * {@link ru.bclib.api.biomes.BCLBiomeBuilder} + */ + public List surfaceRules = null; + /** * Recursively update biomes to correct world biome registry instances, for internal usage only. * @param biomeRegistry {@link Registry} for {@link Biome}. @@ -227,6 +235,11 @@ public class BCLBiome { edge.updateActualBiomes(biomeRegistry); } this.actualBiome = biomeRegistry.get(biomeID); + if (this.attachedStructures!=null) + attachedStructures.forEach(s -> BiomeAPI.addBiomeStructure(BiomeAPI.getBiomeKey(actualBiome), s)); + + if (this.surfaceRules!=null) + surfaceRules.forEach(s -> BiomeAPI.addSurfaceRule(biomeID, s)); } /** From 92dae621f196fb7a64fb0e8ecaeec84f1d87b05c Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Fri, 3 Dec 2021 17:34:35 +0300 Subject: [PATCH 80/96] Surface rule fixes --- .../ru/bclib/api/biomes/BCLBiomeBuilder.java | 21 +++++++--- .../java/ru/bclib/api/biomes/BiomeAPI.java | 4 -- .../java/ru/bclib/blocks/BaseLeavesBlock.java | 3 -- .../java/ru/bclib/blocks/BaseOreBlock.java | 1 - .../java/ru/bclib/world/biomes/BCLBiome.java | 42 +++++++++++-------- 5 files changed, 39 insertions(+), 32 deletions(-) diff --git a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index 7da9a5e2..2299d185 100644 --- a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java @@ -4,7 +4,6 @@ import net.fabricmc.fabric.api.biome.v1.BiomeModifications; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.data.BuiltinRegistries; import net.minecraft.data.worldgen.BiomeDefaultFeatures; -import net.minecraft.data.worldgen.SurfaceRuleData; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.Music; import net.minecraft.sounds.SoundEvent; @@ -42,9 +41,11 @@ import java.util.function.Consumer; public class BCLBiomeBuilder { private static final BCLBiomeBuilder INSTANCE = new BCLBiomeBuilder(); + private List structures = new ArrayList<>(16); private BiomeGenerationSettings.Builder generationSettings; private BiomeSpecialEffects.Builder effectsBuilder; private MobSpawnSettings.Builder spawnSettings; + private SurfaceRules.RuleSource surfaceRule; private Precipitation precipitation; private ResourceLocation biomeID; private BiomeCategory category; @@ -64,6 +65,7 @@ public class BCLBiomeBuilder { INSTANCE.generationSettings = null; INSTANCE.effectsBuilder = null; INSTANCE.spawnSettings = null; + INSTANCE.structures.clear(); INSTANCE.temperature = 1.0F; INSTANCE.fogDensity = 1.0F; INSTANCE.downfall = 1.0F; @@ -451,7 +453,6 @@ public class BCLBiomeBuilder { return feature(feature.getDecoration(), feature.getPlacedFeature()); } - private List structures = new ArrayList<>(2); /** * Adds new structure feature into the biome. * @param structure {@link ConfiguredStructureFeature} to add. @@ -484,14 +485,22 @@ public class BCLBiomeBuilder { return this; } - private List surfaceRules = new ArrayList<>(2); /** * Adds new world surface rule for the given block * @param surfaceBlock {@link Block} to use. * @return same {@link BCLBiomeBuilder} instance. */ public BCLBiomeBuilder surface(Block surfaceBlock) { - surfaceRules.add(SurfaceRules.ifTrue(SurfaceRules.ON_FLOOR, SurfaceRules.state(surfaceBlock.defaultBlockState()))); + return surface(SurfaceRules.ifTrue(SurfaceRules.ON_FLOOR, SurfaceRules.state(surfaceBlock.defaultBlockState()))); + } + + /** + * Adds surface rule to this biome. + * @param surfaceRule {link SurfaceRules.RuleSource} surface rule. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder surface(SurfaceRules.RuleSource surfaceRule) { + this.surfaceRule = surfaceRule; return this; } @@ -528,8 +537,8 @@ public class BCLBiomeBuilder { } final T res = biomeConstructor.apply(biomeID, builder.build()); - res.attachedStructures = structures; - res.surfaceRules = surfaceRules; + res.attachStructures(structures); + res.setSurface(surfaceRule); res.setFogDensity(fogDensity); return res; } diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index 2fe2f267..a59cd923 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -14,7 +14,6 @@ import net.fabricmc.fabric.impl.biome.TheEndBiomeData; import net.minecraft.client.Minecraft; import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; -import net.minecraft.data.worldgen.SurfaceRuleData; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; @@ -24,12 +23,10 @@ import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.MobCategory; import net.minecraft.world.level.Level; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.Biome.BiomeCategory; import net.minecraft.world.level.biome.BiomeSource; import net.minecraft.world.level.biome.Biomes; import net.minecraft.world.level.biome.Climate; import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; -import net.minecraft.world.level.dimension.DimensionType; import net.minecraft.world.level.levelgen.GenerationStep.Carving; import net.minecraft.world.level.levelgen.GenerationStep.Decoration; import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; @@ -58,7 +55,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Random; import java.util.Set; import java.util.function.BiConsumer; diff --git a/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java b/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java index 784667b3..f4dc27e9 100644 --- a/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java @@ -4,10 +4,8 @@ import com.google.common.collect.Lists; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.client.renderer.block.model.BlockModel; -import net.minecraft.data.loot.BlockLoot; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.ShovelItem; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.level.block.Block; @@ -17,7 +15,6 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import ru.bclib.api.TagAPI; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.BlockModelProvider; import ru.bclib.interfaces.RenderLayerProvider; diff --git a/src/main/java/ru/bclib/blocks/BaseOreBlock.java b/src/main/java/ru/bclib/blocks/BaseOreBlock.java index fa009b6f..c996c5f1 100644 --- a/src/main/java/ru/bclib/blocks/BaseOreBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseOreBlock.java @@ -19,7 +19,6 @@ import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import ru.bclib.api.TagAPI; import ru.bclib.interfaces.BlockModelProvider; import ru.bclib.util.MHelper; diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiome.java b/src/main/java/ru/bclib/world/biomes/BCLBiome.java index 132eedb5..4ac623eb 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiome.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiome.java @@ -1,5 +1,6 @@ package ru.bclib.world.biomes; +import com.google.common.collect.Lists; import com.google.common.collect.Maps; import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; @@ -17,11 +18,13 @@ import java.util.Map; import java.util.Random; public class BCLBiome { + private final List structures = Lists.newArrayList(); private final WeightedList subbiomes = new WeightedList<>(); private final Map customData = Maps.newHashMap(); private final ResourceLocation biomeID; private final Biome biome; + private SurfaceRules.RuleSource surface; private BCLBiome biomeParent; private Biome actualBiome; private BCLBiome edge; @@ -207,20 +210,6 @@ public class BCLBiome { return this; } - /** - * For internal use only!!! - * maintains a list of all structures added to this biome, this is automatically set by - * {@link ru.bclib.api.biomes.BCLBiomeBuilder} - */ - public List attachedStructures = null; - - /** - * For internal use only!!! - * maintains a list of all structures added to this biome, this is automatically set by - * {@link ru.bclib.api.biomes.BCLBiomeBuilder} - */ - public List surfaceRules = null; - /** * Recursively update biomes to correct world biome registry instances, for internal usage only. * @param biomeRegistry {@link Registry} for {@link Biome}. @@ -235,11 +224,10 @@ public class BCLBiome { edge.updateActualBiomes(biomeRegistry); } this.actualBiome = biomeRegistry.get(biomeID); - if (this.attachedStructures!=null) - attachedStructures.forEach(s -> BiomeAPI.addBiomeStructure(BiomeAPI.getBiomeKey(actualBiome), s)); - if (this.surfaceRules!=null) - surfaceRules.forEach(s -> BiomeAPI.addSurfaceRule(biomeID, s)); + if (!this.structures.isEmpty()) { + structures.forEach(s -> BiomeAPI.addBiomeStructure(BiomeAPI.getBiomeKey(actualBiome), s)); + } } /** @@ -311,4 +299,22 @@ public class BCLBiome { public String toString() { return biomeID.toString(); } + + /** + * Adds structures to this biome. For internal use only. + * Used inside {@link ru.bclib.api.biomes.BCLBiomeBuilder}. + */ + public void attachStructures(List structures) { + this.structures.addAll(structures); + } + + /** + * Sets biome surface rule. + * @param surface {@link SurfaceRules.RuleSource} rule. + */ + public void setSurface(SurfaceRules.RuleSource surface) { + ResourceKey key = BiomeAPI.getBiomeKey(biome); + BiomeAPI.addSurfaceRule(biomeID, SurfaceRules.ifTrue(SurfaceRules.isBiome(key), surface)); + this.surface = surface; + } } From c7ce0b55470b659cff705e808a3315cb520d28fc Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Fri, 3 Dec 2021 18:16:37 +0300 Subject: [PATCH 81/96] Surface rules API --- .../java/ru/bclib/api/biomes/BiomeAPI.java | 55 +++++++++---------- .../bclib/api/biomes/SurfaceRuleBuilder.java | 21 +++++++ .../bclib/interfaces/SurfaceRuleProvider.java | 9 +++ .../common/NoiseGeneratorSettingsMixin.java | 38 +++++++++++++ .../mixin/common/SurfaceRuleDataMixin.java | 31 ----------- src/main/resources/bclib.mixins.common.json | 2 +- 6 files changed, 94 insertions(+), 62 deletions(-) create mode 100644 src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java create mode 100644 src/main/java/ru/bclib/interfaces/SurfaceRuleProvider.java create mode 100644 src/main/java/ru/bclib/mixin/common/NoiseGeneratorSettingsMixin.java delete mode 100644 src/main/java/ru/bclib/mixin/common/SurfaceRuleDataMixin.java diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index a59cd923..9bad5eee 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -31,7 +31,6 @@ import net.minecraft.world.level.levelgen.GenerationStep.Carving; import net.minecraft.world.level.levelgen.GenerationStep.Decoration; import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; import net.minecraft.world.level.levelgen.SurfaceRules; -import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource; import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; @@ -40,6 +39,7 @@ import net.minecraft.world.level.levelgen.placement.PlacedFeature; import org.jetbrains.annotations.Nullable; import ru.bclib.BCLib; import ru.bclib.config.Configs; +import ru.bclib.interfaces.SurfaceRuleProvider; import ru.bclib.mixin.common.BiomeGenerationSettingsAccessor; import ru.bclib.mixin.common.MobSpawnSettingsAccessor; import ru.bclib.mixin.common.StructureSettingsAccessor; @@ -94,9 +94,6 @@ public class BiomeAPI { 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"))); - private static SurfaceRules.RuleSource netherRuleSource; - private static SurfaceRules.RuleSource endRuleSource; - /** * Initialize registry for current server. * @param biomeRegistry - {@link Registry} for {@link Biome}. @@ -297,8 +294,10 @@ public class BiomeAPI { * @param biome - {@link Biome} from server world. * @return biome {@link ResourceKey} or {@code null}. */ + @Nullable public static ResourceKey getBiomeKey(Biome biome) { - return biomeRegistry.getResourceKey(biome).orElse(null); + ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome).orElse(null); + return key != null ? key : biomeRegistry != null ? biomeRegistry.getResourceKey(biome).orElse(null) : null; } /** @@ -307,7 +306,10 @@ public class BiomeAPI { * @return biome {@link ResourceLocation}. */ public static ResourceLocation getBiomeID(Biome biome) { - ResourceLocation id = biomeRegistry.getKey(biome); + ResourceLocation id = BuiltinRegistries.BIOME.getKey(biome); + if (id == null && biomeRegistry != null) { + id = biomeRegistry.getKey(biome); + } return id == null ? EMPTY_BIOME.getID() : id; } @@ -416,22 +418,6 @@ public class BiomeAPI { registerBiomeModification(Level.END, modification); } - /** - * Returns surface rule source for the Nether. - * @return {@link SurfaceRules.RuleSource}. - */ - public static SurfaceRules.RuleSource getNetherRuleSource() { - return netherRuleSource; - } - - /** - * Returns surface rule source for the End. - * @return {@link SurfaceRules.RuleSource}. - */ - public static SurfaceRules.RuleSource getEndRuleSource() { - return endRuleSource; - } - /** * Will apply biome modifications to world, internal usage only. * @param level @@ -440,15 +426,24 @@ public class BiomeAPI { BiomeSource source = level.getChunkSource().getGenerator().getBiomeSource(); Set biomes = source.possibleBiomes(); + NoiseGeneratorSettings generator = null; if (level.dimension() == Level.NETHER) { - RuleSource[] rules = getRuleSources(biomes, level.dimension()); - netherRuleSource = rules.length > 0 ? SurfaceRules.sequence(rules) : null; - System.out.println("Adding nether sources! " + rules.length); + generator = BuiltinRegistries.NOISE_GENERATOR_SETTINGS.get(NoiseGeneratorSettings.NETHER); } else if (level.dimension() == Level.END) { - RuleSource[] rules = getRuleSources(biomes, level.dimension()); - endRuleSource = rules.length > 0 ? SurfaceRules.sequence(rules) : null; - System.out.println("Adding end sources! " + rules.length); + generator = BuiltinRegistries.NOISE_GENERATOR_SETTINGS.get(NoiseGeneratorSettings.END); + } + + if (generator != null) { + List rules = getRuleSources(biomes, level.dimension()); + SurfaceRuleProvider provider = SurfaceRuleProvider.class.cast(generator); + if (rules.size() > 0) { + rules.add(provider.getSurfaceRule()); + provider.setSurfaceRule(SurfaceRules.sequence(rules.toArray(new SurfaceRules.RuleSource[rules.size()]))); + } + else { + provider.setSurfaceRule(null); + } } List> modifications = MODIFICATIONS.get(level.dimension()); @@ -474,7 +469,7 @@ public class BiomeAPI { }); } - private static SurfaceRules.RuleSource[] getRuleSources(Set biomes, ResourceKey dimensionType) { + private static List getRuleSources(Set biomes, ResourceKey dimensionType) { Set biomeIDs = biomes.stream().map(biome -> getBiomeID(biome)).collect(Collectors.toSet()); List rules = Lists.newArrayList(); SURFACE_RULES.forEach((biomeID, rule) -> { @@ -506,7 +501,7 @@ public class BiomeAPI { } }*/ - return rules.toArray(new SurfaceRules.RuleSource[rules.size()]); + return rules; } /** diff --git a/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java b/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java new file mode 100644 index 00000000..c46e3704 --- /dev/null +++ b/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java @@ -0,0 +1,21 @@ +package ru.bclib.api.biomes; + +import net.minecraft.world.level.levelgen.SurfaceRules; +import net.minecraft.world.level.levelgen.SurfaceRules.ConditionSource; + +import java.util.List; + +public class SurfaceRuleBuilder { + private static final SurfaceRuleBuilder INSTANCE = new SurfaceRuleBuilder(); + private List conditions; + + private SurfaceRuleBuilder() {} + + public static SurfaceRuleBuilder start() { + return INSTANCE; + } + + public static SurfaceRules.RuleSource build() { + return null; + } +} diff --git a/src/main/java/ru/bclib/interfaces/SurfaceRuleProvider.java b/src/main/java/ru/bclib/interfaces/SurfaceRuleProvider.java new file mode 100644 index 00000000..214fd851 --- /dev/null +++ b/src/main/java/ru/bclib/interfaces/SurfaceRuleProvider.java @@ -0,0 +1,9 @@ +package ru.bclib.interfaces; + +import net.minecraft.world.level.levelgen.SurfaceRules; + +public interface SurfaceRuleProvider { + void setSurfaceRule(SurfaceRules.RuleSource surfaceRule); + + SurfaceRules.RuleSource getSurfaceRule(); +} diff --git a/src/main/java/ru/bclib/mixin/common/NoiseGeneratorSettingsMixin.java b/src/main/java/ru/bclib/mixin/common/NoiseGeneratorSettingsMixin.java new file mode 100644 index 00000000..267df1f6 --- /dev/null +++ b/src/main/java/ru/bclib/mixin/common/NoiseGeneratorSettingsMixin.java @@ -0,0 +1,38 @@ +package ru.bclib.mixin.common; + +import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; +import net.minecraft.world.level.levelgen.SurfaceRules; +import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import ru.bclib.interfaces.SurfaceRuleProvider; + +@Mixin(NoiseGeneratorSettings.class) +public class NoiseGeneratorSettingsMixin implements SurfaceRuleProvider { + @Final + @Shadow + private SurfaceRules.RuleSource surfaceRule; + + private SurfaceRules.RuleSource bclib_surfaceRule; + + @Override + public void setSurfaceRule(SurfaceRules.RuleSource surfaceRule) { + bclib_surfaceRule = surfaceRule; + } + + @Override + public RuleSource getSurfaceRule() { + return surfaceRule; + } + + @Inject(method = "surfaceRule", at = @At("HEAD"), cancellable = true) + private void bclib_surfaceRule(CallbackInfoReturnable info) { + if (bclib_surfaceRule != null) { + info.setReturnValue(bclib_surfaceRule); + } + } +} diff --git a/src/main/java/ru/bclib/mixin/common/SurfaceRuleDataMixin.java b/src/main/java/ru/bclib/mixin/common/SurfaceRuleDataMixin.java deleted file mode 100644 index 4e04d7e0..00000000 --- a/src/main/java/ru/bclib/mixin/common/SurfaceRuleDataMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -package ru.bclib.mixin.common; - -import net.minecraft.data.worldgen.SurfaceRuleData; -import net.minecraft.world.level.levelgen.SurfaceRules; -import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import ru.bclib.api.biomes.BiomeAPI; - -@Mixin(SurfaceRuleData.class) -public class SurfaceRuleDataMixin { - @Inject(method = "nether", at = @At("RETURN"), cancellable = true) - private static void bclib_addNetherRuleSource(CallbackInfoReturnable info) { - if (BiomeAPI.getNetherRuleSource() != null) { - RuleSource source = info.getReturnValue(); - source = SurfaceRules.sequence(source, BiomeAPI.getNetherRuleSource()); - info.setReturnValue(source); - } - } - - @Inject(method = "end", at = @At("RETURN"), cancellable = true) - private static void bclib_addEndRuleSource(CallbackInfoReturnable info) { - if (BiomeAPI.getEndRuleSource() != null) { - RuleSource source = info.getReturnValue(); - source = SurfaceRules.sequence(source, BiomeAPI.getEndRuleSource()); - info.setReturnValue(source); - } - } -} diff --git a/src/main/resources/bclib.mixins.common.json b/src/main/resources/bclib.mixins.common.json index da8faabc..c787876f 100644 --- a/src/main/resources/bclib.mixins.common.json +++ b/src/main/resources/bclib.mixins.common.json @@ -38,7 +38,7 @@ "BiomeGenerationSettingsAccessor", "MobSpawnSettingsAccessor", "StructureSettingsAccessor", - "SurfaceRuleDataMixin" + "NoiseGeneratorSettingsMixin" ], "injectors": { "defaultRequire": 1 From ae6c0e9aac3097b4e12b2479acb67421626332c3 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Fri, 3 Dec 2021 20:10:15 +0300 Subject: [PATCH 82/96] Surface builder for two blocks --- src/main/java/ru/bclib/BCLib.java | 17 ++++++++++++----- .../ru/bclib/api/biomes/BCLBiomeBuilder.java | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/main/java/ru/bclib/BCLib.java b/src/main/java/ru/bclib/BCLib.java index 4478b912..5066dcd2 100644 --- a/src/main/java/ru/bclib/BCLib.java +++ b/src/main/java/ru/bclib/BCLib.java @@ -4,6 +4,8 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.ModInitializer; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.levelgen.Noises; +import net.minecraft.world.level.levelgen.SurfaceRules; import ru.bclib.api.TagAPI; import ru.bclib.api.WorldDataAPI; import ru.bclib.api.dataexchange.DataExchangeAPI; @@ -40,11 +42,11 @@ public class BCLib implements ModInitializer { DataExchangeAPI.registerMod(MOD_ID); DataExchangeAPI.registerDescriptors(List.of( - HelloClient.DESCRIPTOR, - HelloServer.DESCRIPTOR, - RequestFiles.DESCRIPTOR, - SendFiles.DESCRIPTOR, - Chunker.DESCRIPTOR + HelloClient.DESCRIPTOR, + HelloServer.DESCRIPTOR, + RequestFiles.DESCRIPTOR, + SendFiles.DESCRIPTOR, + Chunker.DESCRIPTOR )); BCLibPatch.register(); @@ -62,4 +64,9 @@ public class BCLib implements ModInitializer { public static ResourceLocation makeID(String path) { return new ResourceLocation(MOD_ID, path); } + + private static SurfaceRules.ConditionSource surfaceNoiseAbove(double d) { + + return SurfaceRules.noiseCondition(Noises.SURFACE, d / 8.25, Double.MAX_VALUE); + } } diff --git a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index 2299d185..d0a28865 100644 --- a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java @@ -24,9 +24,11 @@ import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.levelgen.GenerationStep; import net.minecraft.world.level.levelgen.GenerationStep.Decoration; +import net.minecraft.world.level.levelgen.Noises; import net.minecraft.world.level.levelgen.SurfaceRules; import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; +import net.minecraft.world.level.levelgen.placement.CaveSurface; import net.minecraft.world.level.levelgen.placement.PlacedFeature; import ru.bclib.util.ColorUtil; import ru.bclib.world.biomes.BCLBiome; @@ -40,6 +42,7 @@ import java.util.function.Consumer; public class BCLBiomeBuilder { private static final BCLBiomeBuilder INSTANCE = new BCLBiomeBuilder(); + private static final SurfaceRules.ConditionSource SURFACE_NOISE = SurfaceRules.noiseCondition(Noises.SOUL_SAND_LAYER, -0.012); private List structures = new ArrayList<>(16); private BiomeGenerationSettings.Builder generationSettings; @@ -494,6 +497,21 @@ public class BCLBiomeBuilder { return surface(SurfaceRules.ifTrue(SurfaceRules.ON_FLOOR, SurfaceRules.state(surfaceBlock.defaultBlockState()))); } + /** + * Adds blocks to the biome surface and below it (with specified depth). + * @param surfaceBlock {@link Block} that will cover biome. + * @param subterrainBlock {@link Block} below it with specified depth. + * @param depth thickness of bottom block layer. + * @return same {@link BCLBiomeBuilder} instance. + */ + public BCLBiomeBuilder surface(Block surfaceBlock, Block subterrainBlock, int depth) { + SurfaceRules.RuleSource topRule = SurfaceRules.state(surfaceBlock.defaultBlockState()); + SurfaceRules.RuleSource subterrainRule = SurfaceRules.state(subterrainBlock.defaultBlockState()); + topRule = SurfaceRules.ifTrue(SurfaceRules.ON_FLOOR, topRule); + subterrainRule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(depth, false, false, CaveSurface.FLOOR), subterrainRule); + return surface(SurfaceRules.sequence(topRule, subterrainRule)); + } + /** * Adds surface rule to this biome. * @param surfaceRule {link SurfaceRules.RuleSource} surface rule. From b14cae82ff82eb79d13981b18f8d689e1997d43a Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Fri, 3 Dec 2021 20:12:18 +0300 Subject: [PATCH 83/96] Surface builder for two blocks --- src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index d0a28865..1cfe1521 100644 --- a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java @@ -501,7 +501,7 @@ public class BCLBiomeBuilder { * Adds blocks to the biome surface and below it (with specified depth). * @param surfaceBlock {@link Block} that will cover biome. * @param subterrainBlock {@link Block} below it with specified depth. - * @param depth thickness of bottom block layer. + * @param depth thickness of bottom block layer.` * @return same {@link BCLBiomeBuilder} instance. */ public BCLBiomeBuilder surface(Block surfaceBlock, Block subterrainBlock, int depth) { From 6118dcb2cf8c1370ce2dd1a12017755da9058587 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Fri, 3 Dec 2021 20:12:55 +0300 Subject: [PATCH 84/96] Small fix --- src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index 1cfe1521..d0a28865 100644 --- a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java @@ -501,7 +501,7 @@ public class BCLBiomeBuilder { * Adds blocks to the biome surface and below it (with specified depth). * @param surfaceBlock {@link Block} that will cover biome. * @param subterrainBlock {@link Block} below it with specified depth. - * @param depth thickness of bottom block layer.` + * @param depth thickness of bottom block layer. * @return same {@link BCLBiomeBuilder} instance. */ public BCLBiomeBuilder surface(Block surfaceBlock, Block subterrainBlock, int depth) { From a5e6344cddb7ab7b8f896ea55f03bda6f84b21a0 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Fri, 3 Dec 2021 20:38:49 +0300 Subject: [PATCH 85/96] Surface rule builder prototype --- .../bclib/api/biomes/SurfaceRuleBuilder.java | 107 +++++++++++++++++- .../ru/bclib/api/biomes/SurfaceRuleEntry.java | 24 ++++ .../ru/bclib/api/spawning/SpawnRuleEntry.java | 2 +- 3 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 src/main/java/ru/bclib/api/biomes/SurfaceRuleEntry.java diff --git a/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java b/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java index c46e3704..bde5b093 100644 --- a/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java @@ -1,21 +1,122 @@ package ru.bclib.api.biomes; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.SurfaceRules; import net.minecraft.world.level.levelgen.SurfaceRules.ConditionSource; +import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource; +import net.minecraft.world.level.levelgen.placement.CaveSurface; +import ru.bclib.api.spawning.SpawnRuleBuilder; +import ru.bclib.api.spawning.SpawnRuleEntry; +import java.util.Collections; import java.util.List; +import java.util.Map; +import java.util.function.Supplier; public class SurfaceRuleBuilder { + private static final Map RULES_CACHE = Maps.newHashMap(); private static final SurfaceRuleBuilder INSTANCE = new SurfaceRuleBuilder(); - private List conditions; + private List rules = Lists.newArrayList(); + private SurfaceRuleEntry entryInstance; + private ResourceKey biomeKey; private SurfaceRuleBuilder() {} public static SurfaceRuleBuilder start() { + INSTANCE.biomeKey = null; + INSTANCE.rules.clear(); return INSTANCE; } - public static SurfaceRules.RuleSource build() { - return null; + /** + * Restricts surface to only one biome. + * @param biomeKey {@link ResourceKey} for the {@link Biome}. + * @return same {@link SurfaceRuleBuilder} instance. + */ + public SurfaceRuleBuilder biome(ResourceKey biomeKey) { + this.biomeKey = biomeKey; + return this; + } + + /** + * Restricts surface to only one biome. + * @param biome {@link Biome}. + * @return same {@link SurfaceRuleBuilder} instance. + */ + public SurfaceRuleBuilder biome(Biome biome) { + return biome(BiomeAPI.getBiomeKey(biome)); + } + + /** + * Set biome surface with specified {@link BlockState}. Example - block of grass in the Overworld biomes + * @param state {@link BlockState} for the ground cover. + * @return same {@link SurfaceRuleBuilder} instance. + */ + public SurfaceRuleBuilder surface(BlockState state) { + entryInstance = getFromCache("surface_" + state.toString(), () -> { + RuleSource rule = SurfaceRules.state(state); + return new SurfaceRuleEntry(1, SurfaceRules.ifTrue(SurfaceRules.ON_FLOOR, rule)); + }); + return this; + } + + /** + * Set biome subsurface with specified {@link BlockState}. Example - dirt in the Overworld biomes. + * @param state {@link BlockState} for the subterrain layer. + * @param depth block layer depth. + * @return same {@link SurfaceRuleBuilder} instance. + */ + 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); + return new SurfaceRuleEntry(2, SurfaceRules.ifTrue(SurfaceRules.ON_FLOOR, rule)); + }); + return this; + } + + /** + * Set biome filler with specified {@link BlockState}. Example - stone in the Overworld biomes. + * @param state {@link BlockState} for filling. + * @return same {@link SurfaceRuleBuilder} instance. + */ + public SurfaceRuleBuilder filler(BlockState state) { + entryInstance = getFromCache("fill_" + state.toString(), () -> { + return new SurfaceRuleEntry(3, SurfaceRules.state(state)); + }); + return this; + } + + /** + * Finalise rule building process. + * @return {@link SurfaceRules.RuleSource}. + */ + public SurfaceRules.RuleSource build() { + Collections.sort(rules); + SurfaceRules.RuleSource[] ruleArray = rules.toArray(new SurfaceRules.RuleSource[rules.size()]); + SurfaceRules.RuleSource rule = SurfaceRules.sequence(ruleArray); + if (biomeKey != null) { + rule = SurfaceRules.ifTrue(SurfaceRules.isBiome(biomeKey), rule); + } + return rule; + } + + /** + * Internal function, will take entry from cache or create it if necessary. + * @param name {@link String} entry internal name. + * @param supplier {@link Supplier} for {@link SurfaceRuleEntry}. + * @return new or existing {@link SurfaceRuleEntry}. + */ + private static SurfaceRuleEntry getFromCache(String name, Supplier supplier) { + SurfaceRuleEntry entry = RULES_CACHE.get(name); + if (entry == null) { + entry = supplier.get(); + RULES_CACHE.put(name, entry); + } + return entry; } } diff --git a/src/main/java/ru/bclib/api/biomes/SurfaceRuleEntry.java b/src/main/java/ru/bclib/api/biomes/SurfaceRuleEntry.java new file mode 100644 index 00000000..348dbbfb --- /dev/null +++ b/src/main/java/ru/bclib/api/biomes/SurfaceRuleEntry.java @@ -0,0 +1,24 @@ +package ru.bclib.api.biomes; + +import net.minecraft.world.entity.Mob; +import net.minecraft.world.level.levelgen.SurfaceRules; +import org.jetbrains.annotations.NotNull; + +public class SurfaceRuleEntry implements Comparable { + private final SurfaceRules.RuleSource rule; + private final byte priority; + + public SurfaceRuleEntry(int priority, SurfaceRules.RuleSource rule) { + this.priority = (byte) priority; + this.rule = rule; + } + + protected SurfaceRules.RuleSource getRule() { + return rule; + } + + @Override + public int compareTo(@NotNull SurfaceRuleEntry entry) { + return Integer.compare(priority, entry.priority); + } +} diff --git a/src/main/java/ru/bclib/api/spawning/SpawnRuleEntry.java b/src/main/java/ru/bclib/api/spawning/SpawnRuleEntry.java index 710860c6..08461e44 100644 --- a/src/main/java/ru/bclib/api/spawning/SpawnRuleEntry.java +++ b/src/main/java/ru/bclib/api/spawning/SpawnRuleEntry.java @@ -19,7 +19,7 @@ public class SpawnRuleEntry implements Comparable this.rule = rule; } - boolean canSpawn(EntityType type, LevelAccessor world, MobSpawnType spawnReason, BlockPos pos, Random random) { + protected boolean canSpawn(EntityType type, LevelAccessor world, MobSpawnType spawnReason, BlockPos pos, Random random) { return rule.canSpawn(type, world, spawnReason, pos, random); } From 17ded1bbccbbf886159fdeaa5f21253cd88dd67e Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Fri, 3 Dec 2021 20:42:28 +0300 Subject: [PATCH 86/96] Cleanup, fixes --- .../java/ru/bclib/api/biomes/SurfaceRuleBuilder.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java b/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java index bde5b093..af29fc50 100644 --- a/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java @@ -6,11 +6,8 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.SurfaceRules; -import net.minecraft.world.level.levelgen.SurfaceRules.ConditionSource; import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource; import net.minecraft.world.level.levelgen.placement.CaveSurface; -import ru.bclib.api.spawning.SpawnRuleBuilder; -import ru.bclib.api.spawning.SpawnRuleEntry; import java.util.Collections; import java.util.List; @@ -61,6 +58,7 @@ public class SurfaceRuleBuilder { RuleSource rule = SurfaceRules.state(state); return new SurfaceRuleEntry(1, SurfaceRules.ifTrue(SurfaceRules.ON_FLOOR, rule)); }); + rules.add(entryInstance); return this; } @@ -76,6 +74,7 @@ public class SurfaceRuleBuilder { rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(depth, false, false, CaveSurface.FLOOR), rule); return new SurfaceRuleEntry(2, SurfaceRules.ifTrue(SurfaceRules.ON_FLOOR, rule)); }); + rules.add(entryInstance); return this; } @@ -85,9 +84,8 @@ public class SurfaceRuleBuilder { * @return same {@link SurfaceRuleBuilder} instance. */ public SurfaceRuleBuilder filler(BlockState state) { - entryInstance = getFromCache("fill_" + state.toString(), () -> { - return new SurfaceRuleEntry(3, SurfaceRules.state(state)); - }); + entryInstance = getFromCache("fill_" + state.toString(), () -> new SurfaceRuleEntry(3, SurfaceRules.state(state))); + rules.add(entryInstance); return this; } From 1a0cb36739969e4d04dd0e49f8c123e4ed120ba4 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Fri, 3 Dec 2021 20:54:01 +0300 Subject: [PATCH 87/96] More rules --- .../bclib/api/biomes/SurfaceRuleBuilder.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java b/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java index af29fc50..5a6e2001 100644 --- a/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java @@ -89,6 +89,40 @@ public class SurfaceRuleBuilder { return this; } + /** + * Set biome ceiling with specified {@link BlockState}. Example - block of sandstone in the Overworld desert in air pockets. + * @param state {@link BlockState} for the ground cover. + * @return same {@link SurfaceRuleBuilder} instance. + */ + public SurfaceRuleBuilder ceil(BlockState state) { + entryInstance = getFromCache("ceil_" + state.toString(), () -> { + RuleSource rule = SurfaceRules.state(state); + return new SurfaceRuleEntry(1, SurfaceRules.ifTrue(SurfaceRules.ON_CEILING, rule)); + }); + rules.add(entryInstance); + return this; + } + + /** + * Allows to add custom rule. + * @param priority rule priority, lower values = higher priority (rule will be applied before others). + * @param rule custom {@link SurfaceRules.RuleSource}. + * @return same {@link SurfaceRuleBuilder} instance. + */ + public SurfaceRuleBuilder rule(int priority, SurfaceRules.RuleSource rule) { + rules.add(new SurfaceRuleEntry(priority, rule)); + return this; + } + + /** + * Allows to add custom rule. + * @param rule + * @return + */ + public SurfaceRuleBuilder rule(SurfaceRules.RuleSource rule) { + return rule(7, rule); + } + /** * Finalise rule building process. * @return {@link SurfaceRules.RuleSource}. From 1af5bf2e2de0f53d6b4a4a364559f5c5536d68fc Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Fri, 3 Dec 2021 20:55:19 +0300 Subject: [PATCH 88/96] Javadoc & mixin order fixes --- .../java/ru/bclib/api/biomes/SurfaceRuleBuilder.java | 4 ++-- src/main/resources/bclib.mixins.common.json | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java b/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java index 5a6e2001..767a2e6f 100644 --- a/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java @@ -116,8 +116,8 @@ public class SurfaceRuleBuilder { /** * Allows to add custom rule. - * @param rule - * @return + * @param rule custom {@link SurfaceRules.RuleSource}. + * @return same {@link SurfaceRuleBuilder} instance. */ public SurfaceRuleBuilder rule(SurfaceRules.RuleSource rule) { return rule(7, rule); diff --git a/src/main/resources/bclib.mixins.common.json b/src/main/resources/bclib.mixins.common.json index c787876f..8716bd49 100644 --- a/src/main/resources/bclib.mixins.common.json +++ b/src/main/resources/bclib.mixins.common.json @@ -5,9 +5,13 @@ "compatibilityLevel": "JAVA_17", "mixins": [ "SimpleReloadableResourceManagerMixin", + "BiomeGenerationSettingsAccessor", "shears.DiggingEnchantmentMixin", "LayerLightSectionStorageMixin", + "NoiseGeneratorSettingsMixin", "shears.TripWireBlockMixin", + "StructureSettingsAccessor", + "MobSpawnSettingsAccessor", "shears.BeehiveBlockMixin", "shears.PumpkinBlockMixin", "shears.MushroomCowMixin", @@ -34,11 +38,7 @@ "AnvilBlockMixin", "AnvilMenuMixin", "TagLoaderMixin", - "MainMixin", - "BiomeGenerationSettingsAccessor", - "MobSpawnSettingsAccessor", - "StructureSettingsAccessor", - "NoiseGeneratorSettingsMixin" + "MainMixin" ], "injectors": { "defaultRequire": 1 From d6faafd4c051548c1987ef67ad78f331f7f23d10 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Sat, 4 Dec 2021 05:22:27 +0300 Subject: [PATCH 89/96] Removed deprecated code, sapling refactor --- .../blocks/FeatureHangingSaplingBlock.java | 2 +- .../ru/bclib/blocks/FeatureSaplingBlock.java | 127 +++++- .../blocks/FeatureSaplingBlockCommon.java | 130 ------ .../blocks/properties/StringProperty.java | 61 --- .../ru/bclib/world/biomes/BCLBiomeDef.java | 426 ------------------ .../ru/bclib/world/features/BCLFeature.java | 40 -- .../generator/BCLibNetherBiomeSource.java | 7 - 7 files changed, 122 insertions(+), 671 deletions(-) delete mode 100644 src/main/java/ru/bclib/blocks/FeatureSaplingBlockCommon.java delete mode 100644 src/main/java/ru/bclib/blocks/properties/StringProperty.java delete mode 100644 src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java diff --git a/src/main/java/ru/bclib/blocks/FeatureHangingSaplingBlock.java b/src/main/java/ru/bclib/blocks/FeatureHangingSaplingBlock.java index 049f8c10..642ca5cb 100644 --- a/src/main/java/ru/bclib/blocks/FeatureHangingSaplingBlock.java +++ b/src/main/java/ru/bclib/blocks/FeatureHangingSaplingBlock.java @@ -8,7 +8,7 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; -public abstract class FeatureHangingSaplingBlock extends FeatureSaplingBlockCommon{ +public abstract class FeatureHangingSaplingBlock extends FeatureSaplingBlock { private static final VoxelShape SHAPE = Block.box(4, 2, 4, 12, 16, 12); public FeatureHangingSaplingBlock() { super(); diff --git a/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java b/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java index f0045a0e..db585f73 100644 --- a/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java +++ b/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java @@ -1,22 +1,137 @@ package ru.bclib.blocks; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; +import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.SaplingBlock; +import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.levelgen.feature.Feature; +import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext; +import net.minecraft.world.level.material.Material; +import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; +import org.jetbrains.annotations.Nullable; +import ru.bclib.client.models.BasePatterns; +import ru.bclib.client.models.ModelsHelper; +import ru.bclib.client.models.PatternsHelper; +import ru.bclib.client.render.BCLRenderLayer; +import ru.bclib.interfaces.BlockModelProvider; +import ru.bclib.interfaces.RenderLayerProvider; -@SuppressWarnings("deprecation") -public abstract class FeatureSaplingBlock extends FeatureSaplingBlockCommon { +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.Random; +import java.util.function.Function; + +public class FeatureSaplingBlock extends SaplingBlock implements RenderLayerProvider, BlockModelProvider { private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12); + private final Function> feature; - public FeatureSaplingBlock() { - super(); + public FeatureSaplingBlock(Function> featureSupplier) { + this(FabricBlockSettings.of(Material.PLANT) + .breakByHand(true) + .collidable(false) + .instabreak() + .sound(SoundType.GRASS) + .randomTicks(), + featureSupplier + ); } - public FeatureSaplingBlock(int light) { - super(light); + public FeatureSaplingBlock(int light, Function> featureSupplier) { + this(FabricBlockSettings.of(Material.PLANT) + .breakByHand(true) + .collidable(false) + .luminance(light) + .instabreak() + .sound(SoundType.GRASS) + .randomTicks(), + featureSupplier + ); + } + + public FeatureSaplingBlock(BlockBehaviour.Properties settings, Function> featureSupplier) { + super(null, settings); + this.feature = featureSupplier; + } + + protected Feature getFeature(BlockState state) { + return feature.apply(state); + } + + @Override + public List getDrops(BlockState state, LootContext.Builder builder) { + return Collections.singletonList(new ItemStack(this)); + } + + @Override + public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { + if (!canSurvive(state, world, pos)) return Blocks.AIR.defaultBlockState(); + else return state; + } + + @Override + public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) { + return random.nextInt(16) == 0; + } + + @Override + public void advanceTree(ServerLevel world, BlockPos pos, BlockState blockState, Random random) { + FeaturePlaceContext context = new FeaturePlaceContext( + Optional.empty(), + world, + world.getChunkSource().getGenerator(), + random, + pos, + null + ); + getFeature(blockState).place(context); + } + + @Override + public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { + this.tick(state, world, pos, random); + } + + @Override + public void tick(BlockState state, ServerLevel world, BlockPos pos, Random random) { + super.tick(state, world, pos, random); + if (isBonemealSuccess(world, random, pos, state)) { + performBonemeal(world, random, pos, state); + } + } + + @Override + public BCLRenderLayer getRenderLayer() { + return BCLRenderLayer.CUTOUT; + } + + @Override + @Environment(EnvType.CLIENT) + public BlockModel getItemModel(ResourceLocation resourceLocation) { + return ModelsHelper.createBlockItem(resourceLocation); + } + + @Override + @Environment(EnvType.CLIENT) + public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) { + Optional pattern = PatternsHelper.createJson(BasePatterns.BLOCK_CROSS, resourceLocation); + return ModelsHelper.fromPattern(pattern); } @Override diff --git a/src/main/java/ru/bclib/blocks/FeatureSaplingBlockCommon.java b/src/main/java/ru/bclib/blocks/FeatureSaplingBlockCommon.java deleted file mode 100644 index 83d86edf..00000000 --- a/src/main/java/ru/bclib/blocks/FeatureSaplingBlockCommon.java +++ /dev/null @@ -1,130 +0,0 @@ -package ru.bclib.blocks; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.minecraft.client.renderer.block.model.BlockModel; -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.SaplingBlock; -import net.minecraft.world.level.block.SoundType; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.levelgen.feature.Feature; -import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext; -import net.minecraft.world.level.material.Material; -import net.minecraft.world.level.storage.loot.LootContext; -import org.jetbrains.annotations.Nullable; -import ru.bclib.client.models.BasePatterns; -import ru.bclib.client.models.ModelsHelper; -import ru.bclib.client.models.PatternsHelper; -import ru.bclib.client.render.BCLRenderLayer; -import ru.bclib.interfaces.BlockModelProvider; -import ru.bclib.interfaces.RenderLayerProvider; - -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.Random; - -abstract class FeatureSaplingBlockCommon extends SaplingBlock implements RenderLayerProvider, BlockModelProvider { - public FeatureSaplingBlockCommon() { - super( - null, - FabricBlockSettings.of(Material.PLANT) - .breakByHand(true) - .collidable(false) - .instabreak() - .sound(SoundType.GRASS) - .randomTicks() - ); - } - - public FeatureSaplingBlockCommon(int light) { - super( - null, - FabricBlockSettings.of(Material.PLANT) - .breakByHand(true) - .collidable(false) - .luminance(light) - .instabreak() - .sound(SoundType.GRASS) - .randomTicks() - ); - } - - @Deprecated - /** - * Override {@link #getFeature(BlockState)} directly. Will be removed in 5.x - */ - protected Feature getFeature() { return null; } - - protected Feature getFeature(BlockState state){ - return getFeature(); - } - - @Override - public List getDrops(BlockState state, LootContext.Builder builder) { - return Collections.singletonList(new ItemStack(this)); - } - - @Override - public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { - if (!canSurvive(state, world, pos)) return Blocks.AIR.defaultBlockState(); - else return state; - } - - @Override - public boolean isBonemealSuccess(Level world, Random random, BlockPos pos, BlockState state) { - return random.nextInt(16) == 0; - } - - @Override - public void advanceTree(ServerLevel world, BlockPos pos, BlockState blockState, Random random) { - FeaturePlaceContext context = new FeaturePlaceContext( - Optional.empty(), - world, - world.getChunkSource().getGenerator(), - random, - pos, - null - ); - getFeature(blockState).place(context); - } - - @Override - public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { - this.tick(state, world, pos, random); - } - - @Override - public void tick(BlockState state, ServerLevel world, BlockPos pos, Random random) { - super.tick(state, world, pos, random); - if (isBonemealSuccess(world, random, pos, state)) { - performBonemeal(world, random, pos, state); - } - } - - @Override - public BCLRenderLayer getRenderLayer() { - return BCLRenderLayer.CUTOUT; - } - - @Override - @Environment(EnvType.CLIENT) - public BlockModel getItemModel(ResourceLocation resourceLocation) { - return ModelsHelper.createBlockItem(resourceLocation); - } - - @Override - @Environment(EnvType.CLIENT) - public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) { - Optional pattern = PatternsHelper.createJson(BasePatterns.BLOCK_CROSS, resourceLocation); - return ModelsHelper.fromPattern(pattern); - } -} diff --git a/src/main/java/ru/bclib/blocks/properties/StringProperty.java b/src/main/java/ru/bclib/blocks/properties/StringProperty.java deleted file mode 100644 index 8aaff298..00000000 --- a/src/main/java/ru/bclib/blocks/properties/StringProperty.java +++ /dev/null @@ -1,61 +0,0 @@ -package ru.bclib.blocks.properties; - -import com.google.common.collect.Sets; -import net.minecraft.world.level.block.state.properties.Property; - -import java.util.Collection; -import java.util.Collections; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; - -@Deprecated -public class StringProperty extends Property { - private final Set values; - - public static StringProperty create(String name, String... values) { - return new StringProperty(name, values); - } - - protected StringProperty(String string, String... values) { - super(string, String.class); - this.values = Sets.newHashSet(values); - } - - public void addValue(String name) { - values.add(name); - } - - @Override - public Collection getPossibleValues() { - return Collections.unmodifiableSet(values); - } - - @Override - public String getName(String comparable) { - return comparable; - } - - @Override - public Optional getValue(String string) { - if (values.contains(string)) { - return Optional.of(string); - } - else { - return Optional.empty(); - } - } - - @Override - public int generateHashCode() { - return super.generateHashCode() + Objects.hashCode(values); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof StringProperty that)) return false; - if (!super.equals(o)) return false; - return values.equals(that.values); - } -} diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java b/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java deleted file mode 100644 index f0a59596..00000000 --- a/src/main/java/ru/bclib/world/biomes/BCLBiomeDef.java +++ /dev/null @@ -1,426 +0,0 @@ -package ru.bclib.world.biomes; - -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import net.minecraft.core.Registry; -import net.minecraft.core.particles.ParticleOptions; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.sounds.Music; -import net.minecraft.sounds.Musics; -import net.minecraft.sounds.SoundEvent; -import net.minecraft.util.Mth; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.level.biome.AmbientAdditionsSettings; -import net.minecraft.world.level.biome.AmbientMoodSettings; -import net.minecraft.world.level.biome.AmbientParticleSettings; -import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.Biome.BiomeCategory; -import net.minecraft.world.level.biome.Biome.Precipitation; -import net.minecraft.world.level.biome.BiomeGenerationSettings; -import net.minecraft.world.level.biome.BiomeSpecialEffects.Builder; -import net.minecraft.world.level.biome.MobSpawnSettings; -import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.levelgen.GenerationStep.Carving; -import net.minecraft.world.level.levelgen.GenerationStep.Decoration; -import net.minecraft.world.level.levelgen.carver.CarverConfiguration; -import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver; -import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; -import net.minecraft.world.level.levelgen.placement.PlacedFeature; -import ru.bclib.config.IdConfig; -import ru.bclib.config.PathConfig; -import ru.bclib.util.ColorUtil; -import ru.bclib.world.features.BCLFeature; -import ru.bclib.world.structures.BCLStructureFeature; - -import java.util.List; -import java.util.Map; - -@Deprecated(forRemoval = true) -public class BCLBiomeDef { - public static final int DEF_FOLIAGE_OVERWORLD = ColorUtil.color(110, 143, 64); - public static final int DEF_FOLIAGE_NETHER = ColorUtil.color(117, 10, 10); - public static final int DEF_FOLIAGE_END = ColorUtil.color(197, 210, 112); - - private final List> structures = Lists.newArrayList(); - private final List features = Lists.newArrayList(); - private final List carvers = Lists.newArrayList(); - private final List mobs = Lists.newArrayList(); - private final List spawns = Lists.newArrayList(); - private final Map customData = Maps.newHashMap(); - - private final ResourceLocation id; - - private AmbientParticleSettings particleConfig; - private AmbientAdditionsSettings additions; - private AmbientMoodSettings mood; - private SoundEvent music; - private SoundEvent loop; - - private int foliageColor = DEF_FOLIAGE_OVERWORLD; - private int grassColor = DEF_FOLIAGE_OVERWORLD; - private int waterFogColor = 329011; - private int waterColor = 4159204; - private int fogColor = 10518688; - private int skyColor = 0; - private float fogDensity = 1F; - private float terrainHeight = 0.1F; - - private Precipitation precipitation = Precipitation.NONE; - private BiomeCategory category = BiomeCategory.NONE; - private float temperature = 1F; - private float genChance = 1F; - private float downfall = 0F; - private int edgeSize = 32; - - /** - * Custom biome definition. Can be extended with new parameters. - * - * @param id - Biome {@link ResourceLocation} (identifier). - */ - public BCLBiomeDef(ResourceLocation id) { - this.id = id; - } - - /** - * Create default definition for The Nether biome. - * - * @return {@link BCLBiomeDef}. - */ - public BCLBiomeDef netherBiome() { - this.foliageColor = DEF_FOLIAGE_NETHER; - this.grassColor = DEF_FOLIAGE_NETHER; - this.setCategory(BiomeCategory.NETHER); - return this; - } - - /** - * Create default definition for The End biome. - * - * @return {@link BCLBiomeDef}. - */ - public BCLBiomeDef endBiome() { - this.foliageColor = DEF_FOLIAGE_END; - this.grassColor = DEF_FOLIAGE_END; - this.setCategory(BiomeCategory.THEEND); - return this; - } - - /** - * Used to load biome settings from config. - * @param config - {@link IdConfig}. - * @return this {@link BCLBiomeDef}. - */ - public BCLBiomeDef loadConfigValues(IdConfig config) { - this.fogDensity = config.getFloat(id, "fog_density", this.fogDensity); - this.genChance = config.getFloat(id, "generation_chance", this.genChance); - this.edgeSize = config.getInt(id, "edge_size", this.edgeSize); - return this; - } - - /** - * Used to load biome settings from config. - * @param config - {@link PathConfig}. - * @return this {@link BCLBiomeDef}. - */ - public BCLBiomeDef loadConfigValues(PathConfig config) { - String biomePath = id.getNamespace() + "." + id.getPath(); - this.fogDensity = config.getFloat(biomePath, "fog_density", this.fogDensity); - this.genChance = config.getFloat(biomePath, "generation_chance", this.genChance); - this.edgeSize = config.getInt(biomePath, "edge_size", this.edgeSize); - return this; - } - - /** - * Set category of the biome. - * @param category - {@link BiomeCategory}. - * @return this {@link BCLBiomeDef}. - */ - public BCLBiomeDef setCategory(BiomeCategory category) { - this.category = category; - return this; - } - - public BCLBiomeDef setPrecipitation(Precipitation precipitation) { - this.precipitation = precipitation; - return this; - } - - public BCLBiomeDef setSurface(Block block) { - //TODO: 1.18 add back surface Code - return this; - } - - public BCLBiomeDef setSurface(Block block1, Block block2) { - //TODO: 1.18 add back surface Code - return this; - } - - public BCLBiomeDef setParticles(ParticleOptions particle, float probability) { - this.particleConfig = new AmbientParticleSettings(particle, probability); - return this; - } - - public BCLBiomeDef setGenChance(float genChance) { - this.genChance = genChance; - return this; - } - - public BCLBiomeDef setTerrainHeight(float terrainHeight) { - this.terrainHeight = terrainHeight; - return this; - } - - public BCLBiomeDef setTemperature(float temperature) { - this.temperature = temperature; - return this; - } - - public BCLBiomeDef setDownfall(float downfall) { - this.downfall = downfall; - return this; - } - - public BCLBiomeDef setEdgeSize(int edgeSize) { - this.edgeSize = edgeSize; - return this; - } - - public BCLBiomeDef addMobSpawn(EntityType type, int weight, int minGroupSize, int maxGroupSize) { - ResourceLocation eID = Registry.ENTITY_TYPE.getKey(type); - if (eID != Registry.ENTITY_TYPE.getDefaultKey()) { - SpawnInfo info = new SpawnInfo(); - info.type = type; - info.weight = weight; - info.minGroupSize = minGroupSize; - info.maxGroupSize = maxGroupSize; - mobs.add(info); - } - return this; - } - - public BCLBiomeDef addMobSpawn(SpawnerData entry) { - spawns.add(entry); - return this; - } - - public BCLBiomeDef addStructureFeature(ConfiguredStructureFeature feature) { - structures.add(feature); - return this; - } - - public BCLBiomeDef addStructureFeature(BCLStructureFeature feature) { - structures.add(feature.getFeatureConfigured()); - return this; - } - - public BCLBiomeDef addFeature(BCLFeature feature) { - FeatureInfo info = new FeatureInfo(); - info.featureStep = feature.getDecoration(); - info.feature = feature.getPlacedFeature(); - features.add(info); - return this; - } - - public BCLBiomeDef addFeature(Decoration featureStep, PlacedFeature feature) { - FeatureInfo info = new FeatureInfo(); - info.featureStep = featureStep; - info.feature = feature; - features.add(info); - return this; - } - - private int getColor(int r, int g, int b) { - r = Mth.clamp(r, 0, 255); - g = Mth.clamp(g, 0, 255); - b = Mth.clamp(b, 0, 255); - return ColorUtil.color(r, g, b); - } - - public BCLBiomeDef setSkyColor(int rgb) { - this.skyColor = rgb; - return this; - } - - public BCLBiomeDef setSkyColor(int r, int g, int b) { - return setSkyColor(getColor(r, g, b)); - } - - public BCLBiomeDef setFogColor(int rgb) { - this.fogColor = rgb; - return this; - } - - public BCLBiomeDef setFogColor(int r, int g, int b) { - return setFogColor(getColor(r, g, b)); - } - - public BCLBiomeDef setFogDensity(float density) { - this.fogDensity = density; - return this; - } - - public BCLBiomeDef setWaterColor(int r, int g, int b) { - this.waterColor = getColor(r, g, b); - return this; - } - - public BCLBiomeDef setWaterFogColor(int r, int g, int b) { - this.waterFogColor = getColor(r, g, b); - return this; - } - - public BCLBiomeDef setWaterAndFogColor(int r, int g, int b) { - return setWaterColor(r, g, b).setWaterFogColor(r, g, b); - } - - public BCLBiomeDef setFoliageColor(int r, int g, int b) { - this.foliageColor = getColor(r, g, b); - return this; - } - - public BCLBiomeDef setGrassColor(int r, int g, int b) { - this.grassColor = getColor(r, g, b); - return this; - } - - public BCLBiomeDef setPlantsColor(int r, int g, int b) { - return this.setFoliageColor(r, g, b).setGrassColor(r, g, b); - } - - public BCLBiomeDef setLoop(SoundEvent loop) { - this.loop = loop; - return this; - } - - public BCLBiomeDef setMood(SoundEvent mood) { - this.mood = new AmbientMoodSettings(mood, 6000, 8, 2.0D); - return this; - } - - public BCLBiomeDef setAdditions(SoundEvent additions) { - this.additions = new AmbientAdditionsSettings(additions, 0.0111); - return this; - } - - public BCLBiomeDef setMusic(SoundEvent music) { - this.music = music; - return this; - } - - protected void addCustomToBuild(BiomeGenerationSettings.Builder generationSettings){ - - } - - public Biome build() { - MobSpawnSettings.Builder spawnSettings = new MobSpawnSettings.Builder(); - BiomeGenerationSettings.Builder generationSettings = new BiomeGenerationSettings.Builder(); - Builder effects = new Builder(); - - mobs.forEach((spawn) -> { - spawnSettings.addSpawn( - spawn.type.getCategory(), - new MobSpawnSettings.SpawnerData(spawn.type, spawn.weight, spawn.minGroupSize, spawn.maxGroupSize) - ); - }); - - spawns.forEach((entry) -> { - spawnSettings.addSpawn(entry.type.getCategory(), entry); - }); - - //generationSettings.surfaceBuilder(surface == null ? net.minecraft.data.worldgen.SurfaceBuilders.END : surface); - - //TODO: 1.18 Done elsewhere now - //structures.forEach((structure) -> generationSettings.addStructureStart(structure)); - features.forEach((info) -> generationSettings.addFeature(info.featureStep, info.feature)); - carvers.forEach((info) -> generationSettings.addCarver(info.carverStep, info.carver)); - - addCustomToBuild(generationSettings); - - effects.skyColor(skyColor) - .waterColor(waterColor) - .waterFogColor(waterFogColor) - .fogColor(fogColor) - .foliageColorOverride(foliageColor) - .grassColorOverride(grassColor); - if (loop != null) effects.ambientLoopSound(loop); - if (mood != null) effects.ambientMoodSound(mood); - if (additions != null) effects.ambientAdditionsSound(additions); - if (particleConfig != null) effects.ambientParticle(particleConfig); - effects.backgroundMusic(music != null ? new Music(music, 600, 2400, true) : Musics.END); - - Biome b = new Biome.BiomeBuilder() - .precipitation(precipitation) - .biomeCategory(category) - //.depth(depth) - //.scale(0.2F) - .temperature(temperature) - .downfall(downfall) - .specialEffects(effects.build()) - .mobSpawnSettings(spawnSettings.build()) - .generationSettings(generationSettings.build()) - .build(); - - //structures.forEach((structure) -> BiomeAPI.addBiomeStructure(b., structure)); - return b; - } - - public float getTerrainHeight() { - return terrainHeight; - } - - private static final class SpawnInfo { - EntityType type; - int weight; - int minGroupSize; - int maxGroupSize; - } - - private static final class FeatureInfo { - Decoration featureStep; - PlacedFeature feature; - } - - private static final class CarverInfo { - Carving carverStep; - ConfiguredWorldCarver carver; - } - - public ResourceLocation getID() { - return id; - } - - public float getFodDensity() { - return fogDensity; - } - - public float getGenChance() { - return genChance; - } - - public int getEdgeSize() { - return edgeSize; - } - - public BCLBiomeDef addCarver(Carving carverStep, ConfiguredWorldCarver carver) { - CarverInfo info = new CarverInfo(); - info.carverStep = carverStep; - info.carver = carver; - carvers.add(info); - return this; - } - - public BCLBiomeDef addCustomData(String name, Object value) { - customData.put(name, value); - return this; - } - - @SuppressWarnings("unchecked") - public T getCustomData(String name, Object defaultValue) { - return (T) customData.getOrDefault(name, defaultValue); - } - - protected Map getCustomData() { - return customData; - } -} \ No newline at end of file diff --git a/src/main/java/ru/bclib/world/features/BCLFeature.java b/src/main/java/ru/bclib/world/features/BCLFeature.java index 9f82066b..a988107a 100644 --- a/src/main/java/ru/bclib/world/features/BCLFeature.java +++ b/src/main/java/ru/bclib/world/features/BCLFeature.java @@ -77,8 +77,6 @@ public class BCLFeature { PlacementUtils.HEIGHTMAP, BiomeFilter.biome() ); - //.decorated(BCLDecorators.HEIGHTMAP_SQUARE) - //.countRandom(density); return new BCLFeature(id, feature, Decoration.VEGETAL_DECORATION, configured); } /** @@ -129,12 +127,6 @@ public class BCLFeature { ) ), BiomeFilter.biome()); -// .rangeUniform( -// VerticalAnchor.absolute(minY), -// VerticalAnchor.absolute(maxY) -// ) -// .squared() -// .count(veins); return new BCLFeature( net.minecraft.world.level.levelgen.feature.Feature.ORE, Registry.register(BuiltinRegistries.PLACED_FEATURE, id, oreFeature), @@ -153,7 +145,6 @@ public class BCLFeature { PlacedFeature configured = feature .configured(FeatureConfiguration.NONE) .placed(CountPlacement.of(1)); - //.decorated(FeatureDecorator.COUNT.configured(new CountConfiguration(1))); return new BCLFeature(id, feature, step, configured); } @@ -169,7 +160,6 @@ public class BCLFeature { PlacedFeature configured = feature .configured(FeatureConfiguration.NONE) .placed(RarityFilter.onAverageOnceEvery(chance)); - //.decorated(FeatureDecorator.CHANCE.configured(new ChanceDecoratorConfiguration(chance))); return new BCLFeature(id, feature, step, configured); } @@ -200,34 +190,4 @@ public class BCLFeature { PlacedFeature configured = feature.configured(FeatureConfiguration.NONE).placed(); return new BCLFeature(id, feature, step, configured); } - - @Deprecated(forRemoval = true) - public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, Block hostBlock, int veins, int veinSize, int offset, int minY, int maxY) { - return makeOreFeature(id, blockOre, hostBlock, veins, veinSize, minY, maxY); - } - - @Deprecated(forRemoval = true) - public static BCLFeature makeRawGenFeature(ResourceLocation id, Feature feature, int chance) { - return makeChancedFeature(id, Decoration.RAW_GENERATION, feature, chance); - } - - @Deprecated(forRemoval = true) - public static BCLFeature makeChunkFeature(ResourceLocation id, Feature feature) { - return makeChunkFeature(id, Decoration.LOCAL_MODIFICATIONS, feature); - } - - @Deprecated(forRemoval = true) - public static BCLFeature makeChansedFeature(ResourceLocation id, Feature feature, int chance) { - return makeChancedFeature(id, Decoration.SURFACE_STRUCTURES, feature, chance); - } - - @Deprecated(forRemoval = true) - public static BCLFeature makeCountRawFeature(ResourceLocation id, Feature feature, int chance) { - return makeCountFeature(id, Decoration.RAW_GENERATION, feature, chance); - } - - @Deprecated(forRemoval = true) - public static BCLFeature makeFeatureConfigured(ResourceLocation id, Feature feature) { - return makeFeatureConfigured(id, Decoration.RAW_GENERATION, feature); - } } diff --git a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java index a17f0a3b..11625350 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java @@ -18,9 +18,7 @@ import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.generator.map.hex.HexBiomeMap; import ru.bclib.world.generator.map.square.SquareBiomeMap; -import java.util.LinkedList; import java.util.List; -import java.util.function.Consumer; public class BCLibNetherBiomeSource extends BiomeSource { public static final Codec CODEC = RecordCodecBuilder.create((instance) -> { @@ -46,9 +44,6 @@ public class BCLibNetherBiomeSource extends BiomeSource { forceLegacyGenerator = val; } - @Deprecated(forRemoval = true) - public static final List> onInit = new LinkedList<>(); - public BCLibNetherBiomeSource(Registry biomeRegistry, long seed) { super(getBiomes(biomeRegistry)); @@ -87,8 +82,6 @@ public class BCLibNetherBiomeSource extends BiomeSource { this.biomeRegistry = biomeRegistry; this.seed = seed; - - onInit.forEach(consumer->consumer.accept(this)); } private static List getBiomes(Registry biomeRegistry) { From 3dacd0727f11ffc18328de57b0289164c70fad6b Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Sat, 4 Dec 2021 05:46:16 +0300 Subject: [PATCH 90/96] Block constructors refactoring --- .../java/ru/bclib/blocks/BaseAnvilBlock.java | 7 ++- .../java/ru/bclib/blocks/BaseBarrelBlock.java | 7 ++- .../ru/bclib/blocks/BaseBlockNotFull.java | 1 - .../ru/bclib/blocks/BaseBookshelfBlock.java | 7 ++- .../java/ru/bclib/blocks/BaseButtonBlock.java | 1 - .../java/ru/bclib/blocks/BaseChainBlock.java | 7 ++- .../bclib/blocks/BaseCraftingTableBlock.java | 7 ++- .../java/ru/bclib/blocks/BaseCropBlock.java | 21 +++++---- .../java/ru/bclib/blocks/BaseDoorBlock.java | 7 ++- .../ru/bclib/blocks/BaseDoublePlantBlock.java | 33 ++++++++----- .../ru/bclib/blocks/BaseFurnaceBlock.java | 7 ++- .../java/ru/bclib/blocks/BaseLadderBlock.java | 7 ++- .../java/ru/bclib/blocks/BaseLeavesBlock.java | 16 +++---- .../ru/bclib/blocks/BaseMetalBarsBlock.java | 7 ++- .../java/ru/bclib/blocks/BaseOreBlock.java | 47 ++++++++++--------- .../java/ru/bclib/blocks/BasePlantBlock.java | 30 +++++++----- .../bclib/blocks/BasePlantWithAgeBlock.java | 14 +++--- .../ru/bclib/blocks/FeatureSaplingBlock.java | 4 +- 18 files changed, 146 insertions(+), 84 deletions(-) diff --git a/src/main/java/ru/bclib/blocks/BaseAnvilBlock.java b/src/main/java/ru/bclib/blocks/BaseAnvilBlock.java index dc5826af..5eae1c38 100644 --- a/src/main/java/ru/bclib/blocks/BaseAnvilBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseAnvilBlock.java @@ -15,6 +15,7 @@ import net.minecraft.world.item.PickaxeItem; import net.minecraft.world.level.block.AnvilBlock; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.IntegerProperty; @@ -40,7 +41,11 @@ public abstract class BaseAnvilBlock extends AnvilBlock implements BlockModelPro public IntegerProperty durability; public BaseAnvilBlock(MaterialColor color) { - super(FabricBlockSettings.copyOf(Blocks.ANVIL).color(color)); + this(FabricBlockSettings.copyOf(Blocks.ANVIL).color(color)); + } + + public BaseAnvilBlock(BlockBehaviour.Properties properties) { + super(properties); } @Override diff --git a/src/main/java/ru/bclib/blocks/BaseBarrelBlock.java b/src/main/java/ru/bclib/blocks/BaseBarrelBlock.java index c5d8dd8b..adfff85a 100644 --- a/src/main/java/ru/bclib/blocks/BaseBarrelBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseBarrelBlock.java @@ -22,6 +22,7 @@ import net.minecraft.world.level.block.BarrelBlock; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.RenderShape; import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.phys.BlockHitResult; @@ -40,7 +41,11 @@ import java.util.Random; public class BaseBarrelBlock extends BarrelBlock implements BlockModelProvider { public BaseBarrelBlock(Block source) { - super(FabricBlockSettings.copyOf(source).noOcclusion()); + this(FabricBlockSettings.copyOf(source).noOcclusion()); + } + + public BaseBarrelBlock(BlockBehaviour.Properties properties) { + super(properties); } @Override diff --git a/src/main/java/ru/bclib/blocks/BaseBlockNotFull.java b/src/main/java/ru/bclib/blocks/BaseBlockNotFull.java index 0ddc700c..d483ea4f 100644 --- a/src/main/java/ru/bclib/blocks/BaseBlockNotFull.java +++ b/src/main/java/ru/bclib/blocks/BaseBlockNotFull.java @@ -6,7 +6,6 @@ import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.state.BlockState; public class BaseBlockNotFull extends BaseBlock { - public BaseBlockNotFull(Properties settings) { super(settings); } diff --git a/src/main/java/ru/bclib/blocks/BaseBookshelfBlock.java b/src/main/java/ru/bclib/blocks/BaseBookshelfBlock.java index 68999421..0a6e570f 100644 --- a/src/main/java/ru/bclib/blocks/BaseBookshelfBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseBookshelfBlock.java @@ -10,6 +10,7 @@ import net.minecraft.world.item.Items; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; @@ -24,7 +25,11 @@ import java.util.Optional; public class BaseBookshelfBlock extends BaseBlock { public BaseBookshelfBlock(Block source) { - super(FabricBlockSettings.copyOf(source)); + this(FabricBlockSettings.copyOf(source)); + } + + public BaseBookshelfBlock(BlockBehaviour.Properties properties) { + super(properties); } @Override diff --git a/src/main/java/ru/bclib/blocks/BaseButtonBlock.java b/src/main/java/ru/bclib/blocks/BaseButtonBlock.java index 289eef21..e60f2ba0 100644 --- a/src/main/java/ru/bclib/blocks/BaseButtonBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseButtonBlock.java @@ -25,7 +25,6 @@ import java.util.Map; import java.util.Optional; public abstract class BaseButtonBlock extends ButtonBlock implements BlockModelProvider { - private final Block parent; protected BaseButtonBlock(Block parent, Properties properties, boolean sensitive) { diff --git a/src/main/java/ru/bclib/blocks/BaseChainBlock.java b/src/main/java/ru/bclib/blocks/BaseChainBlock.java index a0c5863c..4af5392b 100644 --- a/src/main/java/ru/bclib/blocks/BaseChainBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseChainBlock.java @@ -10,6 +10,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.ChainBlock; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.storage.loot.LootContext; @@ -28,7 +29,11 @@ import java.util.Optional; public class BaseChainBlock extends ChainBlock implements BlockModelProvider, RenderLayerProvider { public BaseChainBlock(MaterialColor color) { - super(FabricBlockSettings.copyOf(Blocks.CHAIN).color(color)); + this(FabricBlockSettings.copyOf(Blocks.CHAIN).color(color)); + } + + public BaseChainBlock(BlockBehaviour.Properties properties) { + super(properties); } @Override diff --git a/src/main/java/ru/bclib/blocks/BaseCraftingTableBlock.java b/src/main/java/ru/bclib/blocks/BaseCraftingTableBlock.java index 6be8cbb9..a161d979 100644 --- a/src/main/java/ru/bclib/blocks/BaseCraftingTableBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseCraftingTableBlock.java @@ -8,6 +8,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.CraftingTableBlock; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.storage.loot.LootContext; import org.jetbrains.annotations.Nullable; @@ -23,7 +24,11 @@ import java.util.Optional; public class BaseCraftingTableBlock extends CraftingTableBlock implements BlockModelProvider { public BaseCraftingTableBlock(Block source) { - super(FabricBlockSettings.copyOf(source)); + this(FabricBlockSettings.copyOf(source)); + } + + public BaseCraftingTableBlock(BlockBehaviour.Properties properties) { + super(properties); } @Override diff --git a/src/main/java/ru/bclib/blocks/BaseCropBlock.java b/src/main/java/ru/bclib/blocks/BaseCropBlock.java index 18a16c06..72f7f20a 100644 --- a/src/main/java/ru/bclib/blocks/BaseCropBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseCropBlock.java @@ -2,7 +2,6 @@ package ru.bclib.blocks; import com.google.common.collect.Lists; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; import net.minecraft.util.Mth; @@ -31,19 +30,25 @@ import java.util.List; import java.util.Random; public class BaseCropBlock extends BasePlantBlock { - private static final VoxelShape SHAPE = Block.box(2, 0, 2, 14, 14, 14); public static final IntegerProperty AGE = IntegerProperty.create("age", 0, 3); + private static final VoxelShape SHAPE = Block.box(2, 0, 2, 14, 14, 14); private final Block[] terrain; private final Item drop; public BaseCropBlock(Item drop, Block... terrain) { - super(FabricBlockSettings.of(Material.PLANT) - .breakByTool(FabricToolTags.HOES) - .breakByHand(true) - .sound(SoundType.GRASS) - .randomTicks() - .noCollission()); + this( + FabricBlockSettings.of(Material.PLANT) + .breakByHand(true) + .sound(SoundType.GRASS) + .randomTicks() + .noCollission(), + drop, terrain + ); + } + + public BaseCropBlock(BlockBehaviour.Properties properties, Item drop, Block... terrain) { + super(properties); this.drop = drop; this.terrain = terrain; this.registerDefaultState(defaultBlockState().setValue(AGE, 0)); diff --git a/src/main/java/ru/bclib/blocks/BaseDoorBlock.java b/src/main/java/ru/bclib/blocks/BaseDoorBlock.java index 2e8f8d8b..881085a9 100644 --- a/src/main/java/ru/bclib/blocks/BaseDoorBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseDoorBlock.java @@ -12,6 +12,7 @@ import net.minecraft.util.StringRepresentable; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.DoorBlock; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.DoorHingeSide; import net.minecraft.world.level.block.state.properties.DoubleBlockHalf; @@ -31,7 +32,11 @@ import java.util.Optional; public class BaseDoorBlock extends DoorBlock implements RenderLayerProvider, BlockModelProvider { public BaseDoorBlock(Block source) { - super(FabricBlockSettings.copyOf(source).strength(3F, 3F).noOcclusion()); + this(FabricBlockSettings.copyOf(source).strength(3F, 3F).noOcclusion()); + } + + public BaseDoorBlock(BlockBehaviour.Properties properties) { + super(properties); } @Override diff --git a/src/main/java/ru/bclib/blocks/BaseDoublePlantBlock.java b/src/main/java/ru/bclib/blocks/BaseDoublePlantBlock.java index ad065758..7c80d49e 100644 --- a/src/main/java/ru/bclib/blocks/BaseDoublePlantBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseDoublePlantBlock.java @@ -37,28 +37,32 @@ import ru.bclib.util.BlocksHelper; import java.util.List; import java.util.Random; -@SuppressWarnings("deprecation") public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock { private static final VoxelShape SHAPE = Block.box(4, 2, 4, 12, 16, 12); public static final IntegerProperty ROTATION = BlockProperties.ROTATION; public static final BooleanProperty TOP = BooleanProperty.create("top"); public BaseDoublePlantBlock() { - super(FabricBlockSettings.of(Material.PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .sound(SoundType.WET_GRASS) - .noCollission()); - this.registerDefaultState(this.stateDefinition.any().setValue(TOP, false)); + this( + FabricBlockSettings.of(Material.PLANT) + .breakByHand(true) + .sound(SoundType.GRASS) + .noCollission() + ); } public BaseDoublePlantBlock(int light) { - super(FabricBlockSettings.of(Material.PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .sound(SoundType.WET_GRASS) - .lightLevel((state) -> state.getValue(TOP) ? light : 0) - .noCollission()); + this( + FabricBlockSettings.of(Material.PLANT) + .breakByHand(true) + .sound(SoundType.GRASS) + .lightLevel((state) -> state.getValue(TOP) ? light : 0) + .noCollission() + ); + } + + public BaseDoublePlantBlock(BlockBehaviour.Properties properties) { + super(properties); this.registerDefaultState(this.stateDefinition.any().setValue(TOP, false)); } @@ -68,6 +72,7 @@ public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements R } @Override + @SuppressWarnings("deprecation") public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { Vec3 vec3d = state.getOffset(view, pos); return SHAPE.move(vec3d.x, vec3d.y, vec3d.z); @@ -79,6 +84,7 @@ public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements R } @Override + @SuppressWarnings("deprecation") public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { BlockState down = world.getBlockState(pos.below()); BlockState up = world.getBlockState(pos.above()); @@ -94,6 +100,7 @@ public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements R protected abstract boolean isTerrain(BlockState state); @Override + @SuppressWarnings("deprecation") public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { if (!canStayAt(state, world, pos)) { return Blocks.AIR.defaultBlockState(); diff --git a/src/main/java/ru/bclib/blocks/BaseFurnaceBlock.java b/src/main/java/ru/bclib/blocks/BaseFurnaceBlock.java index ef5c0557..52844196 100644 --- a/src/main/java/ru/bclib/blocks/BaseFurnaceBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseFurnaceBlock.java @@ -20,6 +20,7 @@ import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityTicker; import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; @@ -39,7 +40,11 @@ import java.util.Optional; public class BaseFurnaceBlock extends FurnaceBlock implements BlockModelProvider, RenderLayerProvider { public BaseFurnaceBlock(Block source) { - super(FabricBlockSettings.copyOf(source).lightLevel(state -> state.getValue(LIT) ? 13 : 0)); + this(FabricBlockSettings.copyOf(source).lightLevel(state -> state.getValue(LIT) ? 13 : 0)); + } + + public BaseFurnaceBlock(BlockBehaviour.Properties properties) { + super(properties); } @Override diff --git a/src/main/java/ru/bclib/blocks/BaseLadderBlock.java b/src/main/java/ru/bclib/blocks/BaseLadderBlock.java index d43d8fdf..2128a780 100644 --- a/src/main/java/ru/bclib/blocks/BaseLadderBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseLadderBlock.java @@ -9,6 +9,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.LadderBlock; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.storage.loot.LootContext; import org.jetbrains.annotations.Nullable; @@ -26,7 +27,11 @@ import java.util.Optional; public class BaseLadderBlock extends LadderBlock implements RenderLayerProvider, BlockModelProvider { public BaseLadderBlock(Block block) { - super(FabricBlockSettings.copyOf(block).noOcclusion()); + this(FabricBlockSettings.copyOf(block).noOcclusion()); + } + + public BaseLadderBlock(BlockBehaviour.Properties properties) { + super(properties); } @Override diff --git a/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java b/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java index f4dc27e9..6096864e 100644 --- a/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java @@ -2,7 +2,6 @@ package ru.bclib.blocks; import com.google.common.collect.Lists; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; @@ -28,14 +27,13 @@ public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, protected final Block sapling; private static FabricBlockSettings makeLeaves(MaterialColor color) { - return FabricBlockSettings.copyOf(Blocks.OAK_LEAVES) - .mapColor(color) - .requiresTool() - .breakByTool(FabricToolTags.SHEARS) - .breakByTool(FabricToolTags.HOES) - .allowsSpawning((state, world, pos, type) -> false) - .suffocates((state, world, pos) -> false) - .blockVision((state, world, pos) -> false); + return FabricBlockSettings + .copyOf(Blocks.OAK_LEAVES) + .mapColor(color) + .requiresTool() + .allowsSpawning((state, world, pos, type) -> false) + .suffocates((state, world, pos) -> false) + .blockVision((state, world, pos) -> false); } public BaseLeavesBlock(Block sapling, MaterialColor color, Consumer customizeProperties) { diff --git a/src/main/java/ru/bclib/blocks/BaseMetalBarsBlock.java b/src/main/java/ru/bclib/blocks/BaseMetalBarsBlock.java index 5c64bf7f..895ff38e 100644 --- a/src/main/java/ru/bclib/blocks/BaseMetalBarsBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseMetalBarsBlock.java @@ -12,6 +12,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.IronBarsBlock; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.storage.loot.LootContext; import org.jetbrains.annotations.Nullable; @@ -29,7 +30,11 @@ import java.util.Optional; public class BaseMetalBarsBlock extends IronBarsBlock implements BlockModelProvider, RenderLayerProvider { public BaseMetalBarsBlock(Block source) { - super(FabricBlockSettings.copyOf(source).strength(5.0F, 6.0F).noOcclusion()); + this(FabricBlockSettings.copyOf(source).strength(5.0F, 6.0F).noOcclusion()); + } + + public BaseMetalBarsBlock(BlockBehaviour.Properties properties) { + super(properties); } @Override diff --git a/src/main/java/ru/bclib/blocks/BaseOreBlock.java b/src/main/java/ru/bclib/blocks/BaseOreBlock.java index c996c5f1..c899efcf 100644 --- a/src/main/java/ru/bclib/blocks/BaseOreBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseOreBlock.java @@ -24,24 +24,38 @@ import ru.bclib.util.MHelper; import java.util.Collections; import java.util.List; +import java.util.function.Supplier; public class BaseOreBlock extends OreBlock implements BlockModelProvider { - private final Item dropItem; + private final Supplier dropItem; private final int minCount; private final int maxCount; - public BaseOreBlock(Item drop, int minCount, int maxCount, int experience) { + public BaseOreBlock(Supplier drop, int minCount, int maxCount, int experience) { this(drop, minCount, maxCount, experience, 0); - } - public BaseOreBlock(Item drop, int minCount, int maxCount, int experience, int miningLevel) { - this(drop, minCount, maxCount, experience, miningLevel, FabricBlockSettings.of(Material.STONE, MaterialColor.SAND) - .requiresTool() - .destroyTime(3F) - .explosionResistance(9F) - .sound(SoundType.STONE)); - + public BaseOreBlock(Supplier drop, int minCount, int maxCount, int experience, int miningLevel) { + this( + FabricBlockSettings + .of(Material.STONE, MaterialColor.SAND) + .requiresTool() + .destroyTime(3F) + .explosionResistance(9F) + .sound(SoundType.STONE), + drop, minCount, maxCount, experience, miningLevel + ); + } + + public BaseOreBlock(Properties properties, Supplier drop, int minCount, int maxCount, int experience) { + this(properties, drop, minCount, maxCount, experience, 0); + } + + public BaseOreBlock(Properties properties, Supplier drop, int minCount, int maxCount, int experience, int miningLevel) { + super(makeProps(properties, miningLevel), UniformInt.of(experience>0?1:0, experience)); + this.dropItem = drop; + this.minCount = minCount; + this.maxCount = maxCount; } private static Properties makeProps(Properties properties, int level){ @@ -49,21 +63,10 @@ public class BaseOreBlock extends OreBlock implements BlockModelProvider { return properties; } - public BaseOreBlock(Item drop, int minCount, int maxCount, int experience, Properties properties) { - this(drop, minCount, maxCount, experience, 0, properties); - } - - public BaseOreBlock(Item drop, int minCount, int maxCount, int experience, int miningLevel, Properties properties) { - super(makeProps(properties, miningLevel), UniformInt.of(experience>0?1:0, experience)); - this.dropItem = drop; - this.minCount = minCount; - this.maxCount = maxCount; - } - @Override @SuppressWarnings("deprecation") public List getDrops(BlockState state, LootContext.Builder builder) { - return getDroppedItems(this, dropItem, maxCount, minCount, state, builder); + return getDroppedItems(this, dropItem.get(), maxCount, minCount, state, builder); } public static List getDroppedItems(ItemLike block, Item dropItem, int maxCount, int minCount, BlockState state, LootContext.Builder builder) { diff --git a/src/main/java/ru/bclib/blocks/BasePlantBlock.java b/src/main/java/ru/bclib/blocks/BasePlantBlock.java index 23114bfb..8a5f92fc 100644 --- a/src/main/java/ru/bclib/blocks/BasePlantBlock.java +++ b/src/main/java/ru/bclib/blocks/BasePlantBlock.java @@ -41,7 +41,6 @@ import java.util.List; import java.util.Optional; import java.util.Random; -@SuppressWarnings("deprecation") public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock { private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12); @@ -54,20 +53,24 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderL } public BasePlantBlock(boolean replaceable) { - super(FabricBlockSettings.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .sound(SoundType.GRASS) - .noCollission()); + this( + FabricBlockSettings + .of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT) + .breakByHand(true) + .sound(SoundType.GRASS) + .noCollission() + ); } public BasePlantBlock(boolean replaceable, int light) { - super(FabricBlockSettings.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .luminance(light) - .sound(SoundType.GRASS) - .noCollission()); + this( + FabricBlockSettings + .of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT) + .breakByHand(true) + .luminance(light) + .sound(SoundType.GRASS) + .noCollission() + ); } public BasePlantBlock(Properties settings) { @@ -77,6 +80,7 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderL protected abstract boolean isTerrain(BlockState state); @Override + @SuppressWarnings("deprecation") public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { Vec3 vec3d = state.getOffset(view, pos); return SHAPE.move(vec3d.x, vec3d.y, vec3d.z); @@ -88,12 +92,14 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderL } @Override + @SuppressWarnings("deprecation") public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { BlockState down = world.getBlockState(pos.below()); return isTerrain(down); } @Override + @SuppressWarnings("deprecation") public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { if (!canSurvive(state, world, pos)) { return Blocks.AIR.defaultBlockState(); diff --git a/src/main/java/ru/bclib/blocks/BasePlantWithAgeBlock.java b/src/main/java/ru/bclib/blocks/BasePlantWithAgeBlock.java index 4d8ce1b0..3beb20d8 100644 --- a/src/main/java/ru/bclib/blocks/BasePlantWithAgeBlock.java +++ b/src/main/java/ru/bclib/blocks/BasePlantWithAgeBlock.java @@ -1,7 +1,6 @@ package ru.bclib.blocks; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.Level; @@ -19,12 +18,13 @@ public abstract class BasePlantWithAgeBlock extends BasePlantBlock { public static final IntegerProperty AGE = BlockProperties.AGE; public BasePlantWithAgeBlock() { - this(FabricBlockSettings.of(Material.PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .sound(SoundType.GRASS) - .randomTicks() - .noCollission()); + this( + FabricBlockSettings.of(Material.PLANT) + .breakByHand(true) + .sound(SoundType.GRASS) + .randomTicks() + .noCollission() + ); } public BasePlantWithAgeBlock(Properties settings) { diff --git a/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java b/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java index db585f73..dfee5df8 100644 --- a/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java +++ b/src/main/java/ru/bclib/blocks/FeatureSaplingBlock.java @@ -65,8 +65,8 @@ public class FeatureSaplingBlock extends SaplingBlock implements RenderLayerProv ); } - public FeatureSaplingBlock(BlockBehaviour.Properties settings, Function> featureSupplier) { - super(null, settings); + public FeatureSaplingBlock(BlockBehaviour.Properties properties, Function> featureSupplier) { + super(null, properties); this.feature = featureSupplier; } From f8eb65d60017202aa7c15a9e68a8246b60dbe262 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Sat, 4 Dec 2021 10:32:48 +0300 Subject: [PATCH 91/96] Block constructors refactoring and fixes --- .../java/ru/bclib/blocks/BasePathBlock.java | 3 +- .../bclib/blocks/BaseRotatedPillarBlock.java | 2 +- .../java/ru/bclib/blocks/BaseSignBlock.java | 5 +- .../java/ru/bclib/blocks/BaseStairsBlock.java | 1 - .../ru/bclib/blocks/BaseStoneButtonBlock.java | 1 - .../ru/bclib/blocks/BaseTrapdoorBlock.java | 7 ++- .../blocks/BaseUnderwaterWallPlantBlock.java | 28 ++++++----- .../java/ru/bclib/blocks/BaseVineBlock.java | 18 ++++--- .../java/ru/bclib/blocks/BaseWallBlock.java | 1 - .../ru/bclib/blocks/BaseWallPlantBlock.java | 39 +++++++-------- .../bclib/blocks/BaseWoodenButtonBlock.java | 1 - .../blocks/FeatureHangingSaplingBlock.java | 17 +++++-- .../ru/bclib/blocks/SimpleLeavesBlock.java | 49 +++++++++++-------- .../java/ru/bclib/blocks/StalactiteBlock.java | 12 +++-- .../ru/bclib/blocks/UnderwaterPlantBlock.java | 31 +++++++----- .../blocks/UnderwaterPlantWithAgeBlock.java | 15 +++--- .../ru/bclib/blocks/UpDownPlantBlock.java | 20 +++++--- .../ru/bclib/blocks/WallMushroomBlock.java | 24 +++++---- 18 files changed, 161 insertions(+), 113 deletions(-) diff --git a/src/main/java/ru/bclib/blocks/BasePathBlock.java b/src/main/java/ru/bclib/blocks/BasePathBlock.java index d39e1891..c0f212ef 100644 --- a/src/main/java/ru/bclib/blocks/BasePathBlock.java +++ b/src/main/java/ru/bclib/blocks/BasePathBlock.java @@ -30,7 +30,6 @@ import java.util.List; import java.util.Map; import java.util.Optional; -@SuppressWarnings("deprecation") public class BasePathBlock extends BaseBlockNotFull { private static final VoxelShape SHAPE = Block.box(0, 0, 0, 16, 15, 16); @@ -56,11 +55,13 @@ public class BasePathBlock extends BaseBlockNotFull { } @Override + @SuppressWarnings("deprecation") public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return SHAPE; } @Override + @SuppressWarnings("deprecation") public VoxelShape getCollisionShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return SHAPE; } diff --git a/src/main/java/ru/bclib/blocks/BaseRotatedPillarBlock.java b/src/main/java/ru/bclib/blocks/BaseRotatedPillarBlock.java index dc1560fa..1b4f14e7 100644 --- a/src/main/java/ru/bclib/blocks/BaseRotatedPillarBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseRotatedPillarBlock.java @@ -27,7 +27,7 @@ public class BaseRotatedPillarBlock extends RotatedPillarBlock implements BlockM } public BaseRotatedPillarBlock(Block block) { - super(FabricBlockSettings.copyOf(block)); + this(FabricBlockSettings.copyOf(block)); } @Override diff --git a/src/main/java/ru/bclib/blocks/BaseSignBlock.java b/src/main/java/ru/bclib/blocks/BaseSignBlock.java index f8f4f9d8..1a2620a1 100644 --- a/src/main/java/ru/bclib/blocks/BaseSignBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseSignBlock.java @@ -64,10 +64,7 @@ public class BaseSignBlock extends SignBlock implements BlockModelProvider, Cust public BaseSignBlock(Block source) { super(FabricBlockSettings.copyOf(source).strength(1.0F, 1.0F).noCollission().noOcclusion(), WoodType.OAK); - this.registerDefaultState(this.stateDefinition.any() - .setValue(ROTATION, 0) - .setValue(FLOOR, false) - .setValue(WATERLOGGED, false)); + this.registerDefaultState(this.stateDefinition.any().setValue(ROTATION, 0).setValue(FLOOR, false).setValue(WATERLOGGED, false)); this.parent = source; } diff --git a/src/main/java/ru/bclib/blocks/BaseStairsBlock.java b/src/main/java/ru/bclib/blocks/BaseStairsBlock.java index 7e9de0a0..6074ff55 100644 --- a/src/main/java/ru/bclib/blocks/BaseStairsBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseStairsBlock.java @@ -27,7 +27,6 @@ import java.util.Map; import java.util.Optional; public class BaseStairsBlock extends StairBlock implements BlockModelProvider { - private final Block parent; public BaseStairsBlock(Block source) { diff --git a/src/main/java/ru/bclib/blocks/BaseStoneButtonBlock.java b/src/main/java/ru/bclib/blocks/BaseStoneButtonBlock.java index 6c6bf59b..ed10c5a5 100644 --- a/src/main/java/ru/bclib/blocks/BaseStoneButtonBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseStoneButtonBlock.java @@ -6,7 +6,6 @@ import net.minecraft.sounds.SoundEvents; import net.minecraft.world.level.block.Block; public class BaseStoneButtonBlock extends BaseButtonBlock { - public BaseStoneButtonBlock(Block source) { super(source, FabricBlockSettings.copyOf(source).noOcclusion(), false); } diff --git a/src/main/java/ru/bclib/blocks/BaseTrapdoorBlock.java b/src/main/java/ru/bclib/blocks/BaseTrapdoorBlock.java index 7e4c0ba7..7f09fee6 100644 --- a/src/main/java/ru/bclib/blocks/BaseTrapdoorBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseTrapdoorBlock.java @@ -10,6 +10,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.TrapDoorBlock; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.Half; import net.minecraft.world.level.storage.loot.LootContext; @@ -29,7 +30,11 @@ import java.util.Optional; public class BaseTrapdoorBlock extends TrapDoorBlock implements RenderLayerProvider, BlockModelProvider { public BaseTrapdoorBlock(Block source) { - super(FabricBlockSettings.copyOf(source).strength(3.0F, 3.0F).noOcclusion()); + this(FabricBlockSettings.copyOf(source).strength(3.0F, 3.0F).noOcclusion()); + } + + public BaseTrapdoorBlock(BlockBehaviour.Properties properties) { + super(properties); } @Override diff --git a/src/main/java/ru/bclib/blocks/BaseUnderwaterWallPlantBlock.java b/src/main/java/ru/bclib/blocks/BaseUnderwaterWallPlantBlock.java index 2c226cf4..e8fc1233 100644 --- a/src/main/java/ru/bclib/blocks/BaseUnderwaterWallPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseUnderwaterWallPlantBlock.java @@ -1,7 +1,6 @@ package ru.bclib.blocks; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.core.BlockPos; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.LevelAccessor; @@ -15,22 +14,25 @@ import net.minecraft.world.level.material.Fluids; import net.minecraft.world.level.material.Material; public abstract class BaseUnderwaterWallPlantBlock extends BaseWallPlantBlock implements LiquidBlockContainer { - public BaseUnderwaterWallPlantBlock() { - super(FabricBlockSettings.of(Material.WATER_PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .sound(SoundType.WET_GRASS) - .noCollission()); + this( + FabricBlockSettings + .of(Material.WATER_PLANT) + .breakByHand(true) + .sound(SoundType.WET_GRASS) + .noCollission() + ); } public BaseUnderwaterWallPlantBlock(int light) { - super(FabricBlockSettings.of(Material.WATER_PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .luminance(light) - .sound(SoundType.WET_GRASS) - .noCollission()); + this( + FabricBlockSettings + .of(Material.WATER_PLANT) + .breakByHand(true) + .luminance(light) + .sound(SoundType.WET_GRASS) + .noCollission() + ); } public BaseUnderwaterWallPlantBlock(Properties settings) { diff --git a/src/main/java/ru/bclib/blocks/BaseVineBlock.java b/src/main/java/ru/bclib/blocks/BaseVineBlock.java index 67688cba..6e156b43 100644 --- a/src/main/java/ru/bclib/blocks/BaseVineBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseVineBlock.java @@ -50,12 +50,18 @@ public class BaseVineBlock extends BaseBlockNotFull implements RenderLayerProvid } public BaseVineBlock(int light, boolean bottomOnly) { - super(FabricBlockSettings.of(Material.PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .sound(SoundType.GRASS) - .lightLevel((state) -> bottomOnly ? state.getValue(SHAPE) == TripleShape.BOTTOM ? light : 0 : light) - .noCollission()); + this( + FabricBlockSettings + .of(Material.PLANT) + .breakByHand(true) + .sound(SoundType.GRASS) + .lightLevel((state) -> bottomOnly ? state.getValue(SHAPE) == TripleShape.BOTTOM ? light : 0 : light) + .noCollission() + ); + } + + public BaseVineBlock(BlockBehaviour.Properties properties) { + super(properties); this.registerDefaultState(this.stateDefinition.any().setValue(SHAPE, TripleShape.BOTTOM)); } diff --git a/src/main/java/ru/bclib/blocks/BaseWallBlock.java b/src/main/java/ru/bclib/blocks/BaseWallBlock.java index 3f0eea73..2081d5f6 100644 --- a/src/main/java/ru/bclib/blocks/BaseWallBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseWallBlock.java @@ -26,7 +26,6 @@ import java.util.Map; import java.util.Optional; public class BaseWallBlock extends WallBlock implements BlockModelProvider { - private final Block parent; public BaseWallBlock(Block source) { diff --git a/src/main/java/ru/bclib/blocks/BaseWallPlantBlock.java b/src/main/java/ru/bclib/blocks/BaseWallPlantBlock.java index ee022070..54e8dbd3 100644 --- a/src/main/java/ru/bclib/blocks/BaseWallPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseWallPlantBlock.java @@ -3,7 +3,6 @@ package ru.bclib.blocks; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.item.context.BlockPlaceContext; @@ -29,32 +28,32 @@ import java.util.EnumMap; public abstract class BaseWallPlantBlock extends BasePlantBlock { private static final EnumMap SHAPES = Maps.newEnumMap(ImmutableMap.of( - Direction.NORTH, - Block.box(1, 1, 8, 15, 15, 16), - Direction.SOUTH, - Block.box(1, 1, 0, 15, 15, 8), - Direction.WEST, - Block.box(8, 1, 1, 16, 15, 15), - Direction.EAST, - Block.box(0, 1, 1, 8, 15, 15) + Direction.NORTH, Block.box(1, 1, 8, 15, 15, 16), + Direction.SOUTH, Block.box(1, 1, 0, 15, 15, 8), + Direction.WEST, Block.box(8, 1, 1, 16, 15, 15), + Direction.EAST, Block.box(0, 1, 1, 8, 15, 15) )); public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING; public BaseWallPlantBlock() { - this(FabricBlockSettings.of(Material.PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .sound(SoundType.GRASS) - .noCollission()); + this( + FabricBlockSettings + .of(Material.PLANT) + .breakByHand(true) + .sound(SoundType.GRASS) + .noCollission() + ); } public BaseWallPlantBlock(int light) { - this(FabricBlockSettings.of(Material.PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .luminance(light) - .sound(SoundType.GRASS) - .noCollission()); + this( + FabricBlockSettings + .of(Material.PLANT) + .breakByHand(true) + .luminance(light) + .sound(SoundType.GRASS) + .noCollission() + ); } public BaseWallPlantBlock(Properties settings) { diff --git a/src/main/java/ru/bclib/blocks/BaseWoodenButtonBlock.java b/src/main/java/ru/bclib/blocks/BaseWoodenButtonBlock.java index 3d92013b..d6f34264 100644 --- a/src/main/java/ru/bclib/blocks/BaseWoodenButtonBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseWoodenButtonBlock.java @@ -6,7 +6,6 @@ import net.minecraft.sounds.SoundEvents; import net.minecraft.world.level.block.Block; public class BaseWoodenButtonBlock extends BaseButtonBlock { - public BaseWoodenButtonBlock(Block source) { super(source, FabricBlockSettings.copyOf(source).strength(0.5F, 0.5F).noOcclusion(), true); } diff --git a/src/main/java/ru/bclib/blocks/FeatureHangingSaplingBlock.java b/src/main/java/ru/bclib/blocks/FeatureHangingSaplingBlock.java index 642ca5cb..d75b5e07 100644 --- a/src/main/java/ru/bclib/blocks/FeatureHangingSaplingBlock.java +++ b/src/main/java/ru/bclib/blocks/FeatureHangingSaplingBlock.java @@ -4,18 +4,27 @@ import net.minecraft.core.BlockPos; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.levelgen.feature.Feature; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; +import java.util.function.Function; + public abstract class FeatureHangingSaplingBlock extends FeatureSaplingBlock { private static final VoxelShape SHAPE = Block.box(4, 2, 4, 12, 16, 12); - public FeatureHangingSaplingBlock() { - super(); + + public FeatureHangingSaplingBlock(Function> featureSupplier) { + super(featureSupplier); } - public FeatureHangingSaplingBlock(int light) { - super(light); + public FeatureHangingSaplingBlock(Function> featureSupplier, int light) { + super(light, featureSupplier); + } + + public FeatureHangingSaplingBlock(BlockBehaviour.Properties properties, Function> featureSupplier) { + super(properties, featureSupplier); } @Override diff --git a/src/main/java/ru/bclib/blocks/SimpleLeavesBlock.java b/src/main/java/ru/bclib/blocks/SimpleLeavesBlock.java index 51d6bf29..9846f7d9 100644 --- a/src/main/java/ru/bclib/blocks/SimpleLeavesBlock.java +++ b/src/main/java/ru/bclib/blocks/SimpleLeavesBlock.java @@ -2,6 +2,7 @@ package ru.bclib.blocks; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.MaterialColor; import ru.bclib.api.TagAPI; @@ -10,29 +11,37 @@ import ru.bclib.interfaces.RenderLayerProvider; public class SimpleLeavesBlock extends BaseBlockNotFull implements RenderLayerProvider { public SimpleLeavesBlock(MaterialColor color) { - super(FabricBlockSettings.of(Material.LEAVES) - .strength(0.2F) - .color(color) - .sound(SoundType.GRASS) - .noOcclusion() - .isValidSpawn((state, world, pos, type) -> false) - .isSuffocating((state, world, pos) -> false) - .isViewBlocking((state, world, pos) -> false)); - - TagAPI.addTags(this, TagAPI.BLOCK_LEAVES); + this( + FabricBlockSettings + .of(Material.LEAVES) + .strength(0.2F) + .color(color) + .sound(SoundType.GRASS) + .noOcclusion() + .isValidSpawn((state, world, pos, type) -> false) + .isSuffocating((state, world, pos) -> false) + .isViewBlocking((state, world, pos) -> false) + ); } public SimpleLeavesBlock(MaterialColor color, int light) { - super(FabricBlockSettings.of(Material.LEAVES) - .luminance(light) - .color(color) - .strength(0.2F) - .sound(SoundType.GRASS) - .noOcclusion() - .isValidSpawn((state, world, pos, type) -> false) - .isSuffocating((state, world, pos) -> false) - .isViewBlocking((state, world, pos) -> false)); - + this( + FabricBlockSettings + .of(Material.LEAVES) + .luminance(light) + .color(color) + .strength(0.2F) + .sound(SoundType.GRASS) + .noOcclusion() + .isValidSpawn((state, world, pos, type) -> false) + .isSuffocating((state, world, pos) -> false) + .isViewBlocking((state, world, pos) -> false) + ); + } + + public SimpleLeavesBlock(BlockBehaviour.Properties properties) { + super(properties); + // TODO handle all tags instead of adding them like this TagAPI.addTags(this, TagAPI.BLOCK_LEAVES); } diff --git a/src/main/java/ru/bclib/blocks/StalactiteBlock.java b/src/main/java/ru/bclib/blocks/StalactiteBlock.java index be53dd4f..944b8b79 100644 --- a/src/main/java/ru/bclib/blocks/StalactiteBlock.java +++ b/src/main/java/ru/bclib/blocks/StalactiteBlock.java @@ -22,6 +22,7 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.LiquidBlockContainer; import net.minecraft.world.level.block.SimpleWaterloggedBlock; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BlockStateProperties; @@ -50,11 +51,12 @@ public class StalactiteBlock extends BaseBlockNotFull implements SimpleWaterlogg private static final VoxelShape[] SHAPES; public StalactiteBlock(Block source) { - super(FabricBlockSettings.copy(source).noOcclusion()); - this.registerDefaultState(getStateDefinition().any() - .setValue(SIZE, 0) - .setValue(IS_FLOOR, true) - .setValue(WATERLOGGED, false)); + this(FabricBlockSettings.copy(source).noOcclusion()); + } + + public StalactiteBlock(BlockBehaviour.Properties properties) { + super(properties); + this.registerDefaultState(getStateDefinition().any().setValue(SIZE, 0).setValue(IS_FLOOR, true).setValue(WATERLOGGED, false)); } @Override diff --git a/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java b/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java index 957ee59d..cbd6f34a 100644 --- a/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java @@ -36,25 +36,28 @@ import ru.bclib.interfaces.RenderLayerProvider; import java.util.List; import java.util.Random; -@SuppressWarnings("deprecation") public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock, LiquidBlockContainer { private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12); public UnderwaterPlantBlock() { - super(FabricBlockSettings.of(Material.WATER_PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .sound(SoundType.WET_GRASS) - .noCollission()); + this( + FabricBlockSettings + .of(Material.WATER_PLANT) + .breakByHand(true) + .sound(SoundType.WET_GRASS) + .noCollission() + ); } public UnderwaterPlantBlock(int light) { - super(FabricBlockSettings.of(Material.WATER_PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .luminance(light) - .sound(SoundType.WET_GRASS) - .noCollission()); + this( + FabricBlockSettings + .of(Material.WATER_PLANT) + .breakByHand(true) + .luminance(light) + .sound(SoundType.WET_GRASS) + .noCollission() + ); } public UnderwaterPlantBlock(Properties settings) { @@ -62,6 +65,7 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements R } @Override + @SuppressWarnings("deprecation") public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { Vec3 vec3d = state.getOffset(view, pos); return SHAPE.move(vec3d.x, vec3d.y, vec3d.z); @@ -73,6 +77,7 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements R } @Override + @SuppressWarnings("deprecation") public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { BlockState down = world.getBlockState(pos.below()); state = world.getBlockState(pos); @@ -82,6 +87,7 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements R protected abstract boolean isTerrain(BlockState state); @Override + @SuppressWarnings("deprecation") public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { if (!canSurvive(state, world, pos)) { world.destroyBlock(pos, true); @@ -144,6 +150,7 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements R } @Override + @SuppressWarnings("deprecation") public FluidState getFluidState(BlockState state) { return Fluids.WATER.getSource(false); } diff --git a/src/main/java/ru/bclib/blocks/UnderwaterPlantWithAgeBlock.java b/src/main/java/ru/bclib/blocks/UnderwaterPlantWithAgeBlock.java index a2ad3dd0..e5ba1b6b 100644 --- a/src/main/java/ru/bclib/blocks/UnderwaterPlantWithAgeBlock.java +++ b/src/main/java/ru/bclib/blocks/UnderwaterPlantWithAgeBlock.java @@ -1,7 +1,6 @@ package ru.bclib.blocks; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.WorldGenLevel; @@ -18,12 +17,14 @@ public abstract class UnderwaterPlantWithAgeBlock extends UnderwaterPlantBlock { public static final IntegerProperty AGE = BlockProperties.AGE; public UnderwaterPlantWithAgeBlock() { - super(FabricBlockSettings.of(Material.WATER_PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .sound(SoundType.WET_GRASS) - .randomTicks() - .noCollission()); + super( + FabricBlockSettings + .of(Material.WATER_PLANT) + .breakByHand(true) + .sound(SoundType.WET_GRASS) + .randomTicks() + .noCollission() + ); } @Override diff --git a/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java b/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java index 758f06e5..493b9141 100644 --- a/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java @@ -17,6 +17,7 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.Material; import net.minecraft.world.level.storage.loot.LootContext; @@ -28,26 +29,32 @@ import ru.bclib.interfaces.RenderLayerProvider; import java.util.List; -@SuppressWarnings("deprecation") public abstract class UpDownPlantBlock extends BaseBlockNotFull implements RenderLayerProvider { private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 16, 12); public UpDownPlantBlock() { - super(FabricBlockSettings.of(Material.PLANT) - .breakByTool(FabricToolTags.SHEARS) - .breakByHand(true) - .sound(SoundType.GRASS) - .noCollission()); + this(FabricBlockSettings + .of(Material.PLANT) + .breakByHand(true) + .sound(SoundType.GRASS) + .noCollission() + ); + } + + public UpDownPlantBlock(BlockBehaviour.Properties properties) { + super(properties); } protected abstract boolean isTerrain(BlockState state); @Override + @SuppressWarnings("deprecation") public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return SHAPE; } @Override + @SuppressWarnings("deprecation") public boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) { BlockState down = world.getBlockState(pos.below()); BlockState up = world.getBlockState(pos.above()); @@ -59,6 +66,7 @@ public abstract class UpDownPlantBlock extends BaseBlockNotFull implements Rende } @Override + @SuppressWarnings("deprecation") public BlockState updateShape(BlockState state, Direction facing, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) { if (!canSurvive(state, world, pos)) { return Blocks.AIR.defaultBlockState(); diff --git a/src/main/java/ru/bclib/blocks/WallMushroomBlock.java b/src/main/java/ru/bclib/blocks/WallMushroomBlock.java index f03999e7..6c3379a0 100644 --- a/src/main/java/ru/bclib/blocks/WallMushroomBlock.java +++ b/src/main/java/ru/bclib/blocks/WallMushroomBlock.java @@ -2,12 +2,12 @@ package ru.bclib.blocks; import com.google.common.collect.Lists; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; -import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.block.SoundType; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.Material; import net.minecraft.world.level.storage.loot.LootContext; @@ -16,14 +16,20 @@ import java.util.List; public abstract class WallMushroomBlock extends BaseWallPlantBlock { public WallMushroomBlock(int light) { - super(FabricBlockSettings.of(Material.PLANT) - .breakByTool(FabricToolTags.AXES) - .breakByHand(true) - .luminance(light) - .destroyTime(0.2F) - .sound(SoundType.GRASS) - .sound(SoundType.WOOD) - .noCollission()); + this( + FabricBlockSettings + .of(Material.PLANT) + .breakByHand(true) + .luminance(light) + .destroyTime(0.2F) + .sound(SoundType.GRASS) + .sound(SoundType.WOOD) + .noCollission() + ); + } + + public WallMushroomBlock(BlockBehaviour.Properties properties) { + super(properties); } @Override From 7f17e1261c00ee47dfeb055bcf1cdb611c62b181 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Sat, 4 Dec 2021 11:16:13 +0300 Subject: [PATCH 92/96] Tag Provider, list to array function, surface builder fix --- src/main/java/ru/bclib/api/PostInitAPI.java | 15 +++++++++++++ .../java/ru/bclib/api/biomes/BiomeAPI.java | 2 +- .../bclib/api/biomes/SurfaceRuleBuilder.java | 4 +++- .../java/ru/bclib/interfaces/TagProvider.java | 12 +++++++++++ .../registry/BaseBlockEntityRenders.java | 6 +++--- .../java/ru/bclib/util/CollectionsUtil.java | 21 ++++++++++++++++--- 6 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 src/main/java/ru/bclib/interfaces/TagProvider.java diff --git a/src/main/java/ru/bclib/api/PostInitAPI.java b/src/main/java/ru/bclib/api/PostInitAPI.java index 58f97714..4f0db942 100644 --- a/src/main/java/ru/bclib/api/PostInitAPI.java +++ b/src/main/java/ru/bclib/api/PostInitAPI.java @@ -6,6 +6,8 @@ import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; import net.minecraft.client.renderer.RenderType; import net.minecraft.core.Registry; +import net.minecraft.tags.Tag; +import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.blocks.BaseBarrelBlock; @@ -17,13 +19,17 @@ import ru.bclib.client.render.BaseChestBlockEntityRenderer; import ru.bclib.client.render.BaseSignBlockEntityRenderer; import ru.bclib.interfaces.PostInitable; import ru.bclib.interfaces.RenderLayerProvider; +import ru.bclib.interfaces.TagProvider; import ru.bclib.registry.BaseBlockEntities; +import ru.bclib.util.CollectionsUtil; import java.util.List; import java.util.function.Consumer; public class PostInitAPI { private static List> postInitFunctions = Lists.newArrayList(); + private static List> blockTags = Lists.newArrayList(); + private static List> itemTags = Lists.newArrayList(); /** * Register a new function which will be called after all mods are initiated. Will be called on both client and server. @@ -49,6 +55,8 @@ public class PostInitAPI { } }); postInitFunctions = null; + blockTags = null; + itemTags = null; BiomeAPI.loadFabricAPIBiomes(); } @@ -83,5 +91,12 @@ public class PostInitAPI { else if (block instanceof BaseFurnaceBlock) { BaseBlockEntities.FURNACE.registerBlock(block); } + if (block instanceof TagProvider) { + TagProvider.class.cast(block).addTags(blockTags, itemTags); + TagAPI.addTags(block, CollectionsUtil.toArray(blockTags)); + TagAPI.addTags(block, CollectionsUtil.toArray(itemTags)); + blockTags.clear(); + itemTags.clear(); + } } } diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index 9bad5eee..0367f9a4 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -439,7 +439,7 @@ public class BiomeAPI { SurfaceRuleProvider provider = SurfaceRuleProvider.class.cast(generator); if (rules.size() > 0) { rules.add(provider.getSurfaceRule()); - provider.setSurfaceRule(SurfaceRules.sequence(rules.toArray(new SurfaceRules.RuleSource[rules.size()]))); + provider.setSurfaceRule(SurfaceRules.sequence(CollectionsUtil.toArray(rules))); } else { provider.setSurfaceRule(null); diff --git a/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java b/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java index 767a2e6f..44ec50ee 100644 --- a/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java @@ -8,6 +8,7 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.SurfaceRules; import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource; import net.minecraft.world.level.levelgen.placement.CaveSurface; +import ru.bclib.util.CollectionsUtil; import java.util.Collections; import java.util.List; @@ -129,7 +130,8 @@ public class SurfaceRuleBuilder { */ public SurfaceRules.RuleSource build() { Collections.sort(rules); - SurfaceRules.RuleSource[] ruleArray = rules.toArray(new SurfaceRules.RuleSource[rules.size()]); + List ruleList = rules.stream().map(entry -> entry.getRule()).toList(); + SurfaceRules.RuleSource[] ruleArray = CollectionsUtil.toArray(ruleList); SurfaceRules.RuleSource rule = SurfaceRules.sequence(ruleArray); if (biomeKey != null) { rule = SurfaceRules.ifTrue(SurfaceRules.isBiome(biomeKey), rule); diff --git a/src/main/java/ru/bclib/interfaces/TagProvider.java b/src/main/java/ru/bclib/interfaces/TagProvider.java new file mode 100644 index 00000000..3f0ede66 --- /dev/null +++ b/src/main/java/ru/bclib/interfaces/TagProvider.java @@ -0,0 +1,12 @@ +package ru.bclib.interfaces; + +import net.minecraft.tags.Tag; +import net.minecraft.tags.Tag.Named; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; + +import java.util.List; + +public interface TagProvider { + void addTags(List> blockTags, List> itemTags); +} diff --git a/src/main/java/ru/bclib/registry/BaseBlockEntityRenders.java b/src/main/java/ru/bclib/registry/BaseBlockEntityRenders.java index 5b8050ba..98994667 100644 --- a/src/main/java/ru/bclib/registry/BaseBlockEntityRenders.java +++ b/src/main/java/ru/bclib/registry/BaseBlockEntityRenders.java @@ -2,14 +2,14 @@ package ru.bclib.registry; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.client.rendereregistry.v1.BlockEntityRendererRegistry; +import net.fabricmc.fabric.api.client.rendering.v1.BlockEntityRendererRegistry; import ru.bclib.client.render.BaseChestBlockEntityRenderer; import ru.bclib.client.render.BaseSignBlockEntityRenderer; @Environment(EnvType.CLIENT) public class BaseBlockEntityRenders { public static void register() { - BlockEntityRendererRegistry.INSTANCE.register(BaseBlockEntities.CHEST, BaseChestBlockEntityRenderer::new); - BlockEntityRendererRegistry.INSTANCE.register(BaseBlockEntities.SIGN, BaseSignBlockEntityRenderer::new); + BlockEntityRendererRegistry.register(BaseBlockEntities.CHEST, BaseChestBlockEntityRenderer::new); + BlockEntityRendererRegistry.register(BaseBlockEntities.SIGN, BaseSignBlockEntityRenderer::new); } } diff --git a/src/main/java/ru/bclib/util/CollectionsUtil.java b/src/main/java/ru/bclib/util/CollectionsUtil.java index 609d392a..a7309cab 100644 --- a/src/main/java/ru/bclib/util/CollectionsUtil.java +++ b/src/main/java/ru/bclib/util/CollectionsUtil.java @@ -1,5 +1,6 @@ package ru.bclib.util; +import java.lang.reflect.Array; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -13,7 +14,7 @@ public class CollectionsUtil { * @param list {@link List} to make mutable. * @return {@link ArrayList} or original {@link List} if it is mutable. */ - public static List getMutable(List list) { + public static List getMutable(List list) { if (list instanceof ArrayList) { return list; } @@ -25,7 +26,7 @@ public class CollectionsUtil { * @param set {@link Set} to make mutable. * @return {@link HashSet} or original {@link Set} if it is mutable. */ - public static Set getMutable(Set set) { + public static Set getMutable(Set set) { if (set instanceof HashSet) { return set; } @@ -37,10 +38,24 @@ public class CollectionsUtil { * @param map {@link Map} to make mutable. * @return {@link HashMap} or original {@link Map} if it is mutable. */ - public static Map getMutable(Map map) { + public static Map getMutable(Map map) { if (map instanceof HashMap) { return map; } return new HashMap<>(map); } + + /** + * Converts list into array. + * @param list {@link List} to convert. + * @return array of list elements. If list is empty will return empty {@link Object} array. + */ + public static E[] toArray(List list) { + if (list.isEmpty()) { + return (E[]) new Object[0]; + } + E[] result = (E[]) Array.newInstance(list.get(0).getClass(), list.size()); + result = list.toArray(result); + return result; + }; } From 8809fa7dbc75d9607d09aa872e3843458b1a8572 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Sat, 4 Dec 2021 11:22:19 +0300 Subject: [PATCH 93/96] Tag provider implementation for some blocks --- .../java/ru/bclib/blocks/BaseLeavesBlock.java | 15 ++++++++++++++- .../java/ru/bclib/blocks/BasePlantBlock.java | 13 ++++++++++++- .../java/ru/bclib/blocks/SimpleLeavesBlock.java | 17 ++++++++++++++++- .../ru/bclib/blocks/UnderwaterPlantBlock.java | 13 ++++++++++++- .../java/ru/bclib/blocks/UpDownPlantBlock.java | 13 ++++++++++++- 5 files changed, 66 insertions(+), 5 deletions(-) diff --git a/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java b/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java index 6096864e..6e538ef3 100644 --- a/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java +++ b/src/main/java/ru/bclib/blocks/BaseLeavesBlock.java @@ -1,9 +1,13 @@ package ru.bclib.blocks; import com.google.common.collect.Lists; +import net.fabricmc.fabric.api.mininglevel.v1.FabricMineableTags; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.BlockTags; +import net.minecraft.tags.Tag.Named; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.Enchantments; @@ -14,16 +18,18 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; +import ru.bclib.api.TagAPI; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.BlockModelProvider; import ru.bclib.interfaces.RenderLayerProvider; +import ru.bclib.interfaces.TagProvider; import ru.bclib.util.MHelper; import java.util.Collections; import java.util.List; import java.util.function.Consumer; -public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, RenderLayerProvider { +public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, RenderLayerProvider, TagProvider { protected final Block sapling; private static FabricBlockSettings makeLeaves(MaterialColor color) { @@ -85,4 +91,11 @@ public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, public BlockModel getItemModel(ResourceLocation resourceLocation) { return getBlockModel(resourceLocation, defaultBlockState()); } + + @Override + public void addTags(List> blockTags, List> itemTags) { + blockTags.add(FabricMineableTags.SHEARS_MINEABLE); + blockTags.add(TagAPI.MINEABLE_HOE); + blockTags.add(BlockTags.LEAVES); + } } diff --git a/src/main/java/ru/bclib/blocks/BasePlantBlock.java b/src/main/java/ru/bclib/blocks/BasePlantBlock.java index 8a5f92fc..04474e2b 100644 --- a/src/main/java/ru/bclib/blocks/BasePlantBlock.java +++ b/src/main/java/ru/bclib/blocks/BasePlantBlock.java @@ -3,6 +3,7 @@ package ru.bclib.blocks; import com.google.common.collect.Lists; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.fabricmc.fabric.api.mininglevel.v1.FabricMineableTags; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.client.renderer.block.model.BlockModel; @@ -10,7 +11,9 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; +import net.minecraft.tags.Tag.Named; import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.Enchantments; @@ -31,17 +34,19 @@ import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; import org.jetbrains.annotations.Nullable; +import ru.bclib.api.TagAPI; import ru.bclib.client.models.BasePatterns; import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.PatternsHelper; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.RenderLayerProvider; +import ru.bclib.interfaces.TagProvider; import java.util.List; import java.util.Optional; import java.util.Random; -public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock { +public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock, TagProvider { private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12); public BasePlantBlock() { @@ -163,4 +168,10 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderL Optional pattern = PatternsHelper.createJson(BasePatterns.BLOCK_CROSS, resourceLocation); return ModelsHelper.fromPattern(pattern); } + + @Override + public void addTags(List> blockTags, List> itemTags) { + blockTags.add(FabricMineableTags.SHEARS_MINEABLE); + blockTags.add(TagAPI.MINEABLE_HOE); + } } diff --git a/src/main/java/ru/bclib/blocks/SimpleLeavesBlock.java b/src/main/java/ru/bclib/blocks/SimpleLeavesBlock.java index 9846f7d9..2f9ac66e 100644 --- a/src/main/java/ru/bclib/blocks/SimpleLeavesBlock.java +++ b/src/main/java/ru/bclib/blocks/SimpleLeavesBlock.java @@ -1,6 +1,11 @@ package ru.bclib.blocks; +import net.fabricmc.fabric.api.mininglevel.v1.FabricMineableTags; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; +import net.minecraft.tags.BlockTags; +import net.minecraft.tags.Tag.Named; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.material.Material; @@ -8,8 +13,11 @@ import net.minecraft.world.level.material.MaterialColor; import ru.bclib.api.TagAPI; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.RenderLayerProvider; +import ru.bclib.interfaces.TagProvider; -public class SimpleLeavesBlock extends BaseBlockNotFull implements RenderLayerProvider { +import java.util.List; + +public class SimpleLeavesBlock extends BaseBlockNotFull implements RenderLayerProvider, TagProvider { public SimpleLeavesBlock(MaterialColor color) { this( FabricBlockSettings @@ -49,4 +57,11 @@ public class SimpleLeavesBlock extends BaseBlockNotFull implements RenderLayerPr public BCLRenderLayer getRenderLayer() { return BCLRenderLayer.CUTOUT; } + + @Override + public void addTags(List> blockTags, List> itemTags) { + blockTags.add(FabricMineableTags.SHEARS_MINEABLE); + blockTags.add(TagAPI.MINEABLE_HOE); + blockTags.add(BlockTags.LEAVES); + } } \ No newline at end of file diff --git a/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java b/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java index cbd6f34a..4a12e548 100644 --- a/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/UnderwaterPlantBlock.java @@ -1,12 +1,15 @@ package ru.bclib.blocks; import com.google.common.collect.Lists; +import net.fabricmc.fabric.api.mininglevel.v1.FabricMineableTags; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.server.level.ServerLevel; +import net.minecraft.tags.Tag.Named; import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.Enchantments; @@ -30,13 +33,15 @@ import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; +import ru.bclib.api.TagAPI; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.RenderLayerProvider; +import ru.bclib.interfaces.TagProvider; import java.util.List; import java.util.Random; -public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock, LiquidBlockContainer { +public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock, LiquidBlockContainer, TagProvider { private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12); public UnderwaterPlantBlock() { @@ -154,4 +159,10 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements R public FluidState getFluidState(BlockState state) { return Fluids.WATER.getSource(false); } + + @Override + public void addTags(List> blockTags, List> itemTags) { + blockTags.add(FabricMineableTags.SHEARS_MINEABLE); + blockTags.add(TagAPI.MINEABLE_HOE); + } } diff --git a/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java b/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java index 493b9141..21f3cabe 100644 --- a/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java +++ b/src/main/java/ru/bclib/blocks/UpDownPlantBlock.java @@ -1,11 +1,14 @@ package ru.bclib.blocks; import com.google.common.collect.Lists; +import net.fabricmc.fabric.api.mininglevel.v1.FabricMineableTags; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.tags.Tag.Named; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.Enchantments; @@ -24,12 +27,14 @@ import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; +import ru.bclib.api.TagAPI; import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.interfaces.RenderLayerProvider; +import ru.bclib.interfaces.TagProvider; import java.util.List; -public abstract class UpDownPlantBlock extends BaseBlockNotFull implements RenderLayerProvider { +public abstract class UpDownPlantBlock extends BaseBlockNotFull implements RenderLayerProvider, TagProvider { private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 16, 12); public UpDownPlantBlock() { @@ -100,4 +105,10 @@ public abstract class UpDownPlantBlock extends BaseBlockNotFull implements Rende super.playerDestroy(world, player, pos, state, blockEntity, stack); world.neighborChanged(pos, Blocks.AIR, pos.below()); } + + @Override + public void addTags(List> blockTags, List> itemTags) { + blockTags.add(FabricMineableTags.SHEARS_MINEABLE); + blockTags.add(TagAPI.MINEABLE_HOE); + } } From 3a06c128ed3634ac41c9f41b44649d610ed05c9c Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Sat, 4 Dec 2021 11:52:58 +0300 Subject: [PATCH 94/96] Surface rule builder fixes --- src/main/java/ru/bclib/BCLib.java | 20 ++++++++++++++----- src/main/java/ru/bclib/api/PostInitAPI.java | 5 ++--- .../java/ru/bclib/api/biomes/BiomeAPI.java | 2 +- .../bclib/api/biomes/SurfaceRuleBuilder.java | 8 ++++---- .../java/ru/bclib/util/CollectionsUtil.java | 15 -------------- 5 files changed, 22 insertions(+), 28 deletions(-) diff --git a/src/main/java/ru/bclib/BCLib.java b/src/main/java/ru/bclib/BCLib.java index 5066dcd2..efaa5042 100644 --- a/src/main/java/ru/bclib/BCLib.java +++ b/src/main/java/ru/bclib/BCLib.java @@ -4,10 +4,15 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.ModInitializer; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.biome.Biomes; +import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.levelgen.Noises; import net.minecraft.world.level.levelgen.SurfaceRules; +import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource; import ru.bclib.api.TagAPI; import ru.bclib.api.WorldDataAPI; +import ru.bclib.api.biomes.BiomeAPI; +import ru.bclib.api.biomes.SurfaceRuleBuilder; import ru.bclib.api.dataexchange.DataExchangeAPI; import ru.bclib.api.dataexchange.handler.autosync.Chunker; import ru.bclib.api.dataexchange.handler.autosync.HelloClient; @@ -51,6 +56,16 @@ public class BCLib implements ModInitializer { BCLibPatch.register(); Configs.save(); + + RuleSource rule = SurfaceRuleBuilder + .start() + .biome(Biomes.END_HIGHLANDS) + .filler(Blocks.STONE.defaultBlockState()) + .subsurface(Blocks.DIRT.defaultBlockState(), 3) + .surface(Blocks.GRASS_BLOCK.defaultBlockState()) + .ceil(Blocks.DEEPSLATE.defaultBlockState()) + .build(); + BiomeAPI.addSurfaceRule(Biomes.END_HIGHLANDS.location(), rule); } public static boolean isDevEnvironment() { @@ -64,9 +79,4 @@ public class BCLib implements ModInitializer { public static ResourceLocation makeID(String path) { return new ResourceLocation(MOD_ID, path); } - - private static SurfaceRules.ConditionSource surfaceNoiseAbove(double d) { - - return SurfaceRules.noiseCondition(Noises.SURFACE, d / 8.25, Double.MAX_VALUE); - } } diff --git a/src/main/java/ru/bclib/api/PostInitAPI.java b/src/main/java/ru/bclib/api/PostInitAPI.java index 4f0db942..63b2c1d5 100644 --- a/src/main/java/ru/bclib/api/PostInitAPI.java +++ b/src/main/java/ru/bclib/api/PostInitAPI.java @@ -21,7 +21,6 @@ import ru.bclib.interfaces.PostInitable; import ru.bclib.interfaces.RenderLayerProvider; import ru.bclib.interfaces.TagProvider; import ru.bclib.registry.BaseBlockEntities; -import ru.bclib.util.CollectionsUtil; import java.util.List; import java.util.function.Consumer; @@ -93,8 +92,8 @@ public class PostInitAPI { } if (block instanceof TagProvider) { TagProvider.class.cast(block).addTags(blockTags, itemTags); - TagAPI.addTags(block, CollectionsUtil.toArray(blockTags)); - TagAPI.addTags(block, CollectionsUtil.toArray(itemTags)); + blockTags.forEach(tag -> TagAPI.addTag(tag, block)); + itemTags.forEach(tag -> TagAPI.addTag(tag, block)); blockTags.clear(); itemTags.clear(); } diff --git a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java index 0367f9a4..9bad5eee 100644 --- a/src/main/java/ru/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/biomes/BiomeAPI.java @@ -439,7 +439,7 @@ public class BiomeAPI { SurfaceRuleProvider provider = SurfaceRuleProvider.class.cast(generator); if (rules.size() > 0) { rules.add(provider.getSurfaceRule()); - provider.setSurfaceRule(SurfaceRules.sequence(CollectionsUtil.toArray(rules))); + provider.setSurfaceRule(SurfaceRules.sequence(rules.toArray(new SurfaceRules.RuleSource[rules.size()]))); } else { provider.setSurfaceRule(null); diff --git a/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java b/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java index 44ec50ee..2f75f94e 100644 --- a/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java @@ -8,7 +8,6 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.SurfaceRules; import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource; import net.minecraft.world.level.levelgen.placement.CaveSurface; -import ru.bclib.util.CollectionsUtil; import java.util.Collections; import java.util.List; @@ -57,7 +56,8 @@ public class SurfaceRuleBuilder { public SurfaceRuleBuilder surface(BlockState state) { entryInstance = getFromCache("surface_" + state.toString(), () -> { RuleSource rule = SurfaceRules.state(state); - return new SurfaceRuleEntry(1, SurfaceRules.ifTrue(SurfaceRules.ON_FLOOR, rule)); + rule = SurfaceRules.ifTrue(SurfaceRules.ON_FLOOR, rule); + return new SurfaceRuleEntry(1, rule); }); rules.add(entryInstance); return this; @@ -73,7 +73,7 @@ public class SurfaceRuleBuilder { entryInstance = getFromCache("subsurface_" + depth + "_" + state.toString(), () -> { RuleSource rule = SurfaceRules.state(state); rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(depth, false, false, CaveSurface.FLOOR), rule); - return new SurfaceRuleEntry(2, SurfaceRules.ifTrue(SurfaceRules.ON_FLOOR, rule)); + return new SurfaceRuleEntry(2, rule); }); rules.add(entryInstance); return this; @@ -131,7 +131,7 @@ public class SurfaceRuleBuilder { public SurfaceRules.RuleSource build() { Collections.sort(rules); List ruleList = rules.stream().map(entry -> entry.getRule()).toList(); - SurfaceRules.RuleSource[] ruleArray = CollectionsUtil.toArray(ruleList); + SurfaceRules.RuleSource[] ruleArray = ruleList.toArray(new SurfaceRules.RuleSource[ruleList.size()]); SurfaceRules.RuleSource rule = SurfaceRules.sequence(ruleArray); if (biomeKey != null) { rule = SurfaceRules.ifTrue(SurfaceRules.isBiome(biomeKey), rule); diff --git a/src/main/java/ru/bclib/util/CollectionsUtil.java b/src/main/java/ru/bclib/util/CollectionsUtil.java index a7309cab..e7b472c9 100644 --- a/src/main/java/ru/bclib/util/CollectionsUtil.java +++ b/src/main/java/ru/bclib/util/CollectionsUtil.java @@ -1,6 +1,5 @@ package ru.bclib.util; -import java.lang.reflect.Array; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -44,18 +43,4 @@ public class CollectionsUtil { } return new HashMap<>(map); } - - /** - * Converts list into array. - * @param list {@link List} to convert. - * @return array of list elements. If list is empty will return empty {@link Object} array. - */ - public static E[] toArray(List list) { - if (list.isEmpty()) { - return (E[]) new Object[0]; - } - E[] result = (E[]) Array.newInstance(list.get(0).getClass(), list.size()); - result = list.toArray(result); - return result; - }; } From 9609db9f9b1b6586742026e2e3da80618987b163 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Sat, 4 Dec 2021 12:00:31 +0300 Subject: [PATCH 95/96] Ceiling rules --- src/main/java/ru/bclib/BCLib.java | 3 ++- .../ru/bclib/api/biomes/SurfaceRuleBuilder.java | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/bclib/BCLib.java b/src/main/java/ru/bclib/BCLib.java index efaa5042..d5f34722 100644 --- a/src/main/java/ru/bclib/BCLib.java +++ b/src/main/java/ru/bclib/BCLib.java @@ -63,7 +63,8 @@ public class BCLib implements ModInitializer { .filler(Blocks.STONE.defaultBlockState()) .subsurface(Blocks.DIRT.defaultBlockState(), 3) .surface(Blocks.GRASS_BLOCK.defaultBlockState()) - .ceil(Blocks.DEEPSLATE.defaultBlockState()) + .aboveCeil(Blocks.DEEPSLATE.defaultBlockState(), 4) + .ceil(Blocks.BASALT.defaultBlockState()) .build(); BiomeAPI.addSurfaceRule(Biomes.END_HIGHLANDS.location(), rule); } diff --git a/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java b/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java index 2f75f94e..66f0edef 100644 --- a/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java @@ -104,6 +104,22 @@ public class SurfaceRuleBuilder { return this; } + /** + * Set biome ceiling material with specified {@link BlockState} and height. Example - sandstone in the Overworld deserts. + * @param state {@link BlockState} for the subterrain layer. + * @param height block layer height. + * @return same {@link SurfaceRuleBuilder} instance. + */ + 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); + return new SurfaceRuleEntry(2, rule); + }); + rules.add(entryInstance); + return this; + } + /** * Allows to add custom rule. * @param priority rule priority, lower values = higher priority (rule will be applied before others). From bf1b3917f45ccadba39a44333f498a7f7cf8f62a Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Sat, 4 Dec 2021 12:15:46 +0300 Subject: [PATCH 96/96] Steep rules & cleanup --- src/main/java/ru/bclib/BCLib.java | 18 ------------- .../ru/bclib/api/biomes/BCLBiomeBuilder.java | 13 +++++----- .../bclib/api/biomes/SurfaceRuleBuilder.java | 26 ++++++++++++++++--- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/main/java/ru/bclib/BCLib.java b/src/main/java/ru/bclib/BCLib.java index d5f34722..bc71a685 100644 --- a/src/main/java/ru/bclib/BCLib.java +++ b/src/main/java/ru/bclib/BCLib.java @@ -4,15 +4,8 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.ModInitializer; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.biome.Biomes; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.levelgen.Noises; -import net.minecraft.world.level.levelgen.SurfaceRules; -import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource; import ru.bclib.api.TagAPI; import ru.bclib.api.WorldDataAPI; -import ru.bclib.api.biomes.BiomeAPI; -import ru.bclib.api.biomes.SurfaceRuleBuilder; import ru.bclib.api.dataexchange.DataExchangeAPI; import ru.bclib.api.dataexchange.handler.autosync.Chunker; import ru.bclib.api.dataexchange.handler.autosync.HelloClient; @@ -56,17 +49,6 @@ public class BCLib implements ModInitializer { BCLibPatch.register(); Configs.save(); - - RuleSource rule = SurfaceRuleBuilder - .start() - .biome(Biomes.END_HIGHLANDS) - .filler(Blocks.STONE.defaultBlockState()) - .subsurface(Blocks.DIRT.defaultBlockState(), 3) - .surface(Blocks.GRASS_BLOCK.defaultBlockState()) - .aboveCeil(Blocks.DEEPSLATE.defaultBlockState(), 4) - .ceil(Blocks.BASALT.defaultBlockState()) - .build(); - BiomeAPI.addSurfaceRule(Biomes.END_HIGHLANDS.location(), rule); } public static boolean isDevEnvironment() { diff --git a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java index d0a28865..eb53ef05 100644 --- a/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/BCLBiomeBuilder.java @@ -28,7 +28,6 @@ import net.minecraft.world.level.levelgen.Noises; import net.minecraft.world.level.levelgen.SurfaceRules; import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; -import net.minecraft.world.level.levelgen.placement.CaveSurface; import net.minecraft.world.level.levelgen.placement.PlacedFeature; import ru.bclib.util.ColorUtil; import ru.bclib.world.biomes.BCLBiome; @@ -494,7 +493,7 @@ public class BCLBiomeBuilder { * @return same {@link BCLBiomeBuilder} instance. */ public BCLBiomeBuilder surface(Block surfaceBlock) { - return surface(SurfaceRules.ifTrue(SurfaceRules.ON_FLOOR, SurfaceRules.state(surfaceBlock.defaultBlockState()))); + return surface(SurfaceRuleBuilder.start().surface(surfaceBlock.defaultBlockState()).build()); } /** @@ -505,11 +504,11 @@ public class BCLBiomeBuilder { * @return same {@link BCLBiomeBuilder} instance. */ public BCLBiomeBuilder surface(Block surfaceBlock, Block subterrainBlock, int depth) { - SurfaceRules.RuleSource topRule = SurfaceRules.state(surfaceBlock.defaultBlockState()); - SurfaceRules.RuleSource subterrainRule = SurfaceRules.state(subterrainBlock.defaultBlockState()); - topRule = SurfaceRules.ifTrue(SurfaceRules.ON_FLOOR, topRule); - subterrainRule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(depth, false, false, CaveSurface.FLOOR), subterrainRule); - return surface(SurfaceRules.sequence(topRule, subterrainRule)); + return surface(SurfaceRuleBuilder + .start() + .surface(surfaceBlock.defaultBlockState()) + .subsurface(subterrainBlock.defaultBlockState(), depth) + .build()); } /** diff --git a/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java b/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java index 66f0edef..13082e90 100644 --- a/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java +++ b/src/main/java/ru/bclib/api/biomes/SurfaceRuleBuilder.java @@ -57,7 +57,7 @@ public class SurfaceRuleBuilder { entryInstance = getFromCache("surface_" + state.toString(), () -> { RuleSource rule = SurfaceRules.state(state); rule = SurfaceRules.ifTrue(SurfaceRules.ON_FLOOR, rule); - return new SurfaceRuleEntry(1, rule); + return new SurfaceRuleEntry(2, rule); }); rules.add(entryInstance); return this; @@ -73,7 +73,7 @@ public class SurfaceRuleBuilder { entryInstance = getFromCache("subsurface_" + depth + "_" + state.toString(), () -> { RuleSource rule = SurfaceRules.state(state); rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(depth, false, false, CaveSurface.FLOOR), rule); - return new SurfaceRuleEntry(2, rule); + return new SurfaceRuleEntry(3, rule); }); rules.add(entryInstance); return this; @@ -98,7 +98,7 @@ public class SurfaceRuleBuilder { public SurfaceRuleBuilder ceil(BlockState state) { entryInstance = getFromCache("ceil_" + state.toString(), () -> { RuleSource rule = SurfaceRules.state(state); - return new SurfaceRuleEntry(1, SurfaceRules.ifTrue(SurfaceRules.ON_CEILING, rule)); + return new SurfaceRuleEntry(2, SurfaceRules.ifTrue(SurfaceRules.ON_CEILING, rule)); }); rules.add(entryInstance); return this; @@ -114,7 +114,25 @@ public class SurfaceRuleBuilder { entryInstance = getFromCache("above_ceil_" + height + "_" + state.toString(), () -> { RuleSource rule = SurfaceRules.state(state); rule = SurfaceRules.ifTrue(SurfaceRules.stoneDepthCheck(height, false, false, CaveSurface.CEILING), rule); - return new SurfaceRuleEntry(2, rule); + return new SurfaceRuleEntry(3, rule); + }); + rules.add(entryInstance); + return this; + } + + /** + * Will cover steep areas (with large terrain angle). Example - Overworld mountains. + * @param state {@link BlockState} for the steep layer. + * @param depth layer depth + * @return + */ + 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.steep(), rule); + int priority = depth < 1 ? 0 : 1; + return new SurfaceRuleEntry(priority, rule); }); rules.add(entryInstance); return this;