trying fixing flower generation error, but failed
This commit is contained in:
parent
b68cb9114b
commit
d6c306c78a
|
@ -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<Block>)ImmutableSet.of(Blocks.GRASS_BLOCK))
|
||||
.whitelist((Set<Block>)ImmutableSet.of(Blocks.GRASS_BLOCK.getDefaultState().getBlock()))
|
||||
.cannotProject()
|
||||
.build());
|
||||
.build())
|
||||
.decorate(Decorators.SQUARE_HEIGHTMAP_SPREAD_DOUBLE)
|
||||
.applyChance(24);
|
||||
}
|
||||
|
||||
// ================ biome register
|
||||
private static Predicate<BiomeSelectionContext> getAllBiomeSelector() {
|
||||
return BiomeSelectors.foundInOverworld();
|
||||
}
|
||||
private static Predicate<BiomeSelectionContext> 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<BiomeSelectionContext> 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();
|
||||
|
|
|
@ -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<ConfiguredFeature<?, ?>> 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,7 +8,8 @@
|
|||
"client": [
|
||||
"TeyvatCraftMixin",
|
||||
"VillagerAccess",
|
||||
"FlowerForestAccess"
|
||||
"FlowerForestAccess",
|
||||
"GrassBlockFixer"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
Loading…
Reference in New Issue
Block a user