diff --git a/src/main/java/net/yyc12345/teyvatcraft/init/TerrainsManager.java b/src/main/java/net/yyc12345/teyvatcraft/init/TerrainsManager.java index 442e722..1f9ddc1 100644 --- a/src/main/java/net/yyc12345/teyvatcraft/init/TerrainsManager.java +++ b/src/main/java/net/yyc12345/teyvatcraft/init/TerrainsManager.java @@ -17,6 +17,8 @@ import net.fabricmc.fabric.api.biome.v1.BiomeSelectors; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; +import net.minecraft.block.SweetBerryBushBlock; +import net.minecraft.state.property.Property; import net.minecraft.util.Identifier; import net.minecraft.world.biome.BiomeKeys; import net.minecraft.world.gen.GenerationStep; @@ -31,6 +33,7 @@ import net.minecraft.world.gen.placer.SimpleBlockPlacer; import net.minecraft.world.gen.stateprovider.BlockStateProvider; import net.minecraft.world.gen.stateprovider.SimpleBlockStateProvider; import net.minecraft.world.gen.stateprovider.WeightedBlockStateProvider; +import net.yyc12345.teyvatcraft.blocks.TeyvatSweetBerryBushLikePlantBlock; import net.yyc12345.teyvatcraft.mixin.FlowerForestAccess; public class TerrainsManager { @@ -98,16 +101,16 @@ public class TerrainsManager { .configure((new RandomPatchFeatureConfig.Builder( (BlockStateProvider)provider, (BlockPlacer)SimpleBlockPlacer.INSTANCE)) - .tries(64) + .tries(32) .build()) .decorate(Decorators.SPREAD_32_ABOVE) .decorate(Decorators.SQUARE_HEIGHTMAP) - .repeat(2); + .repeat(16); } private static ConfiguredFeature generateSweetBerryBushLikePlantFreature(Block[] plantBlks) { WeightedBlockStateProvider provider = new WeightedBlockStateProvider(); for(Block item : plantBlks) { - provider.addState(item.getDefaultState(), 1); + provider.addState(item.getDefaultState().with(SweetBerryBushBlock.AGE, Integer.valueOf(3)), 1); } return Feature.RANDOM_PATCH @@ -115,15 +118,27 @@ public class TerrainsManager { (BlockStateProvider)provider, (BlockPlacer)SimpleBlockPlacer.INSTANCE)) .tries(64) - .whitelist((Set)ImmutableSet.of(Blocks.GRASS_BLOCK)) + .whitelist((Set)ImmutableSet.of(Blocks.GRASS_BLOCK.getDefaultState().getBlock())) .cannotProject() - .build()); + .build()) + .decorate(Decorators.SQUARE_HEIGHTMAP_SPREAD_DOUBLE) + .applyChance(24); } // ================ biome register private static Predicate getAllBiomeSelector() { return BiomeSelectors.foundInOverworld(); } + private static Predicate getPlainBiomeSelector() { + return BiomeSelectors.includeByKey( + BiomeKeys.PLAINS, + BiomeKeys.FOREST, + BiomeKeys.BIRCH_FOREST, + BiomeKeys.TALL_BIRCH_FOREST, + BiomeKeys.BIRCH_FOREST_HILLS, + BiomeKeys.TALL_BIRCH_HILLS + ); + } private static Predicate getMountainsBiomeSelector() { return BiomeSelectors.includeByKey( BiomeKeys.MOUNTAINS, @@ -184,11 +199,11 @@ public class TerrainsManager { registerOreGeneration("oregen_cor_lapis_ore", OREGEN_COR_LAPIS_ORE, getBadlandsBiomeSelector()); // flower gen - registerPlantGeneration("flowergen_normal", FLOWERGEN_NORMAL, getAllBiomeSelector()); + registerPlantGeneration("flowergen_normal", FLOWERGEN_NORMAL, getPlainBiomeSelector()); registerPlantGeneration("flowergen_swamp", FLOWERGEN_SWAMP, getSwampBiomeSelector()); registerPlantGeneration("flowergen_mountains", FLOWERGEN_MOUNTAINS, getMountainsBiomeSelector()); - registerPlantGeneration("sbbgen_normal", SBBGEN_NORMAL, getAllBiomeSelector()); + registerPlantGeneration("sbbgen_normal", SBBGEN_NORMAL, getPlainBiomeSelector()); // patch flower forest BlockState[] flowerForestArray = FlowerForestAccess.getFlowers(); diff --git a/src/main/java/net/yyc12345/teyvatcraft/mixin/GrassBlockFixer.java b/src/main/java/net/yyc12345/teyvatcraft/mixin/GrassBlockFixer.java new file mode 100644 index 0000000..0f87466 --- /dev/null +++ b/src/main/java/net/yyc12345/teyvatcraft/mixin/GrassBlockFixer.java @@ -0,0 +1,64 @@ +package net.yyc12345.teyvatcraft.mixin; + +import java.util.List; +import java.util.Random; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.At; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.block.GrassBlock; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.BlockView; +import net.minecraft.world.WorldView; +import net.minecraft.world.gen.feature.ConfiguredFeature; +import net.minecraft.world.gen.feature.FlowerFeature; + +// due to minecraft shit design, the bone meal only can grow grass block's first flowerFeature +// this mixin class is designed to fix this shitty design. + +@Mixin(GrassBlock.class) +public class GrassBlockFixer { + @Inject(method = "grow", at = @At("HEAD")) + public void grow(ServerWorld world, Random random, BlockPos pos, BlockState state, CallbackInfo ci) { + BlockPos blockPos = pos.up(); + BlockState blockState = Blocks.GRASS.getDefaultState(); + int i; + label32: for (i = 0; i < 128; i++) { + BlockState blockState4; + BlockPos blockPos2 = blockPos; + // random walk + for (int j = 0; j < i / 16; ) { + blockPos2 = blockPos2.add(random.nextInt(3) - 1, (random.nextInt(3) - 1) * random.nextInt(3) / 2, random.nextInt(3) - 1); + if (world.getBlockState(blockPos2.down()).isOf(world.getBlockState(pos).getBlock()/* this */)) { + if (world.getBlockState(blockPos2).isFullCube((BlockView)world, blockPos2)) + continue label32; + j++; + } + continue label32; + } + + // try place flower + if (random.nextInt(8) == 0) { + List> list = world.getBiome(blockPos2).getGenerationSettings().getFlowerFeatures(); + if (list.isEmpty()) + continue; + ConfiguredFeature configuredFeature = list.get(random.nextInt(list.size() - 1) + 1); + FlowerFeature flowerFeature = (FlowerFeature)configuredFeature.feature; + blockState4 = flowerFeature.getFlowerState(random, blockPos2, configuredFeature.getConfig()); + } else { + blockState4 = blockState; + } + + // place flower + if (blockState4.canPlaceAt((WorldView)world, blockPos2)) + world.setBlockState(blockPos2, blockState4, 3); + continue; + } + } +} diff --git a/src/main/resources/teyvatcraft.mixins.json b/src/main/resources/teyvatcraft.mixins.json index f41cbfa..1ae248b 100644 --- a/src/main/resources/teyvatcraft.mixins.json +++ b/src/main/resources/teyvatcraft.mixins.json @@ -8,7 +8,8 @@ "client": [ "TeyvatCraftMixin", "VillagerAccess", - "FlowerForestAccess" + "FlowerForestAccess", + "GrassBlockFixer" ], "injectors": { "defaultRequire": 1