diff --git a/gradle.properties b/gradle.properties index 290c367c..e11b676a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ yarn_mappings= 6 loader_version= 0.11.6 # Mod Properties -mod_version = 0.2.2 +mod_version = 0.2.3 maven_group = ru.bclib archives_base_name = bclib diff --git a/src/main/java/ru/bclib/api/BonemealAPI.java b/src/main/java/ru/bclib/api/BonemealAPI.java index 56276fd3..b6a5232e 100644 --- a/src/main/java/ru/bclib/api/BonemealAPI.java +++ b/src/main/java/ru/bclib/api/BonemealAPI.java @@ -15,38 +15,51 @@ public class BonemealAPI { private static final Map>> LAND_GRASS_BIOMES = Maps.newHashMap(); private static final Map> WATER_GRASS_TYPES = Maps.newHashMap(); private static final Map> LAND_GRASS_TYPES = Maps.newHashMap(); - private static final Set SPREADABLE_BLOCKS = Sets.newHashSet(); + private static final Map SPREADABLE_BLOCKS = Maps.newHashMap(); + private static final Set TERRAIN_TO_SPREAD = Sets.newHashSet(); + private static final Set TERRAIN = Sets.newHashSet(); - public static void addSpreadableBlock(Block block) { - SPREADABLE_BLOCKS.add(block); + public static void addSpreadableBlock(Block spreadableBlock, Block surfaceForSpread) { + SPREADABLE_BLOCKS.put(spreadableBlock, surfaceForSpread); + TERRAIN_TO_SPREAD.add(surfaceForSpread); + TERRAIN.add(surfaceForSpread); } - public static boolean isSpreadable(Block block) { - return SPREADABLE_BLOCKS.contains(block); + public static boolean isTerrain(Block block) { + return TERRAIN.contains(block); + } + + public static boolean isSpreadableTerrain(Block block) { + return TERRAIN_TO_SPREAD.contains(block); + } + + public static Block getSpreadable(Block block) { + return SPREADABLE_BLOCKS.get(block); } public static void addLandGrass(Block plant, Block... terrain) { for (Block block : terrain) { - addLandGrass(block, plant, 1F); + addLandGrass(plant, block, 1F); } } public static void addLandGrass(ResourceLocation biome, Block plant, Block... terrain) { for (Block block : terrain) { - addLandGrass(biome, block, plant, 1F); + addLandGrass(biome, plant, block, 1F); } } - public static void addLandGrass(Block terrain, Block plant, float chance) { + public static void addLandGrass(Block plant, Block terrain, float chance) { WeightedList list = LAND_GRASS_TYPES.get(terrain); if (list == null) { list = new WeightedList(); LAND_GRASS_TYPES.put(terrain, list); } + TERRAIN.add(terrain); list.add(plant, chance); } - public static void addLandGrass(ResourceLocation biome, Block terrain, Block plant, float chance) { + public static void addLandGrass(ResourceLocation biome, Block plant, Block terrain, float chance) { Map> map = LAND_GRASS_BIOMES.get(biome); if (map == null) { map = Maps.newHashMap(); @@ -57,31 +70,33 @@ public class BonemealAPI { list = new WeightedList(); map.put(terrain, list); } + TERRAIN.add(terrain); list.add(plant, chance); } public static void addWaterGrass(Block plant, Block... terrain) { for (Block block : terrain) { - addWaterGrass(block, plant, 1F); + addWaterGrass(plant, block, 1F); } } public static void addWaterGrass(ResourceLocation biome, Block plant, Block... terrain) { for (Block block : terrain) { - addWaterGrass(biome, block, plant, 1F); + addWaterGrass(biome, plant, block, 1F); } } - public static void addWaterGrass(Block terrain, Block plant, float chance) { + public static void addWaterGrass(Block plant, Block terrain, float chance) { WeightedList list = WATER_GRASS_TYPES.get(terrain); if (list == null) { list = new WeightedList(); WATER_GRASS_TYPES.put(terrain, list); } + TERRAIN.add(terrain); list.add(plant, chance); } - public static void addWaterGrass(ResourceLocation biome, Block terrain, Block plant, float chance) { + public static void addWaterGrass(ResourceLocation biome, Block plant, Block terrain, float chance) { Map> map = WATER_GRASS_BIOMES.get(biome); if (map == null) { map = Maps.newHashMap(); @@ -92,6 +107,7 @@ public class BonemealAPI { list = new WeightedList(); map.put(terrain, list); } + TERRAIN.add(terrain); list.add(plant, chance); } @@ -111,16 +127,16 @@ public class BonemealAPI { } public static Block getWaterGrass(ResourceLocation biomeID, Block terrain, Random random) { - Map> map = LAND_GRASS_BIOMES.get(biomeID); + Map> map = WATER_GRASS_BIOMES.get(biomeID); WeightedList list = null; if (map != null) { list = map.get(terrain); if (list == null) { - list = LAND_GRASS_TYPES.get(terrain); + list = WATER_GRASS_TYPES.get(terrain); } } else { - list = LAND_GRASS_TYPES.get(terrain); + list = WATER_GRASS_TYPES.get(terrain); } return list == null ? null : list.get(random); } diff --git a/src/main/java/ru/bclib/mixin/client/BackgroundRendererMixin.java b/src/main/java/ru/bclib/mixin/client/BackgroundRendererMixin.java index c35fcd4b..2fc492bd 100644 --- a/src/main/java/ru/bclib/mixin/client/BackgroundRendererMixin.java +++ b/src/main/java/ru/bclib/mixin/client/BackgroundRendererMixin.java @@ -25,9 +25,9 @@ import ru.bclib.world.biomes.BCLBiome; @Mixin(FogRenderer.class) public class BackgroundRendererMixin { - private static final MutableBlockPos BCL_LAST_POS = new MutableBlockPos(0, -100, 0); - private static final MutableBlockPos BCL_MUT_POS = new MutableBlockPos(); - private static final float[] BCL_FOG_DENSITY = new float[8]; + private static final MutableBlockPos BCLIB_LAST_POS = new MutableBlockPos(0, -100, 0); + private static final MutableBlockPos BCLIB_MUT_POS = new MutableBlockPos(); + private static final float[] BCLIB_FOG_DENSITY = new float[8]; @Shadow private static float fogRed; @@ -37,7 +37,7 @@ public class BackgroundRendererMixin { private static float fogBlue; @Inject(method = "setupColor", at = @At("RETURN")) - private static void bcl_onRender(Camera camera, float tickDelta, ClientLevel world, int i, float f, CallbackInfo info) { + private static void bclib_onRender(Camera camera, float tickDelta, ClientLevel world, int i, float f, CallbackInfo info) { FogType fogType = camera.getFluidInCamera(); if (fogType != FogType.WATER && world.dimension().equals(Level.END)) { Entity entity = camera.getEntity(); @@ -59,14 +59,14 @@ public class BackgroundRendererMixin { } @Inject(method = "setupFog", at = @At("HEAD"), cancellable = true) - private static void bcl_fogDensity(Camera camera, FogRenderer.FogMode fogMode, float viewDistance, boolean thickFog, CallbackInfo info) { + private static void bclib_fogDensity(Camera camera, FogRenderer.FogMode fogMode, float viewDistance, boolean thickFog, CallbackInfo info) { Entity entity = camera.getEntity(); FogType fogType = camera.getFluidInCamera(); if (fogType != FogType.WATER) { - if (bcl_shouldIgnore(entity.level, (int) entity.getX(), (int) entity.getEyeY(), (int) entity.getZ())) { + if (bclib_shouldIgnore(entity.level, (int) entity.getX(), (int) entity.getEyeY(), (int) entity.getZ())) { return; } - float fog = bcl_getFogDensity(entity.level, entity.getX(), entity.getEyeY(), entity.getZ()); + float fog = bclib_getFogDensity(entity.level, entity.getX(), entity.getEyeY(), entity.getZ()); BackgroundInfo.fogDensity = fog; float start = viewDistance * 0.75F / fog; float end = viewDistance / fog; @@ -99,18 +99,18 @@ public class BackgroundRendererMixin { } } - private static boolean bcl_shouldIgnore(Level level, int x, int y, int z) { - Biome biome = level.getBiome(BCL_MUT_POS.set(x, y, z)); + private static boolean bclib_shouldIgnore(Level level, int x, int y, int z) { + Biome biome = level.getBiome(BCLIB_MUT_POS.set(x, y, z)); return BiomeAPI.getRenderBiome(biome) == BiomeAPI.EMPTY_BIOME; } - private static float bcl_getFogDensityI(Level level, int x, int y, int z) { - Biome biome = level.getBiome(BCL_MUT_POS.set(x, y, z)); + private static float bclib_getFogDensityI(Level level, int x, int y, int z) { + Biome biome = level.getBiome(BCLIB_MUT_POS.set(x, y, z)); BCLBiome renderBiome = BiomeAPI.getRenderBiome(biome); return renderBiome.getFogDensity(); } - private static float bcl_getFogDensity(Level level, double x, double y, double z) { + private static float bclib_getFogDensity(Level level, double x, double y, double z) { int x1 = (MHelper.floor(x) >> 3) << 3; int y1 = (MHelper.floor(y) >> 3) << 3; int z1 = (MHelper.floor(z) >> 3) << 3; @@ -118,25 +118,25 @@ public class BackgroundRendererMixin { float dy = (float) (y - y1) / 8F; float dz = (float) (z - z1) / 8F; - if (BCL_LAST_POS.getX() != x1 || BCL_LAST_POS.getY() != y1 || BCL_LAST_POS.getZ() != z1) { + if (BCLIB_LAST_POS.getX() != x1 || BCLIB_LAST_POS.getY() != y1 || BCLIB_LAST_POS.getZ() != z1) { int x2 = x1 + 8; int y2 = y1 + 8; int z2 = z1 + 8; - BCL_LAST_POS.set(x1, y1, z1); - BCL_FOG_DENSITY[0] = bcl_getFogDensityI(level, x1, y1, z1); - BCL_FOG_DENSITY[1] = bcl_getFogDensityI(level, x2, y1, z1); - BCL_FOG_DENSITY[2] = bcl_getFogDensityI(level, x1, y2, z1); - BCL_FOG_DENSITY[3] = bcl_getFogDensityI(level, x2, y2, z1); - BCL_FOG_DENSITY[4] = bcl_getFogDensityI(level, x1, y1, z2); - BCL_FOG_DENSITY[5] = bcl_getFogDensityI(level, x2, y1, z2); - BCL_FOG_DENSITY[6] = bcl_getFogDensityI(level, x1, y2, z2); - BCL_FOG_DENSITY[7] = bcl_getFogDensityI(level, x2, y2, z2); + BCLIB_LAST_POS.set(x1, y1, z1); + BCLIB_FOG_DENSITY[0] = bclib_getFogDensityI(level, x1, y1, z1); + BCLIB_FOG_DENSITY[1] = bclib_getFogDensityI(level, x2, y1, z1); + BCLIB_FOG_DENSITY[2] = bclib_getFogDensityI(level, x1, y2, z1); + BCLIB_FOG_DENSITY[3] = bclib_getFogDensityI(level, x2, y2, z1); + BCLIB_FOG_DENSITY[4] = bclib_getFogDensityI(level, x1, y1, z2); + BCLIB_FOG_DENSITY[5] = bclib_getFogDensityI(level, x2, y1, z2); + BCLIB_FOG_DENSITY[6] = bclib_getFogDensityI(level, x1, y2, z2); + BCLIB_FOG_DENSITY[7] = bclib_getFogDensityI(level, x2, y2, z2); } - float a = Mth.lerp(dx, BCL_FOG_DENSITY[0], BCL_FOG_DENSITY[1]); - float b = Mth.lerp(dx, BCL_FOG_DENSITY[2], BCL_FOG_DENSITY[3]); - float c = Mth.lerp(dx, BCL_FOG_DENSITY[4], BCL_FOG_DENSITY[5]); - float d = Mth.lerp(dx, BCL_FOG_DENSITY[6], BCL_FOG_DENSITY[7]); + float a = Mth.lerp(dx, BCLIB_FOG_DENSITY[0], BCLIB_FOG_DENSITY[1]); + float b = Mth.lerp(dx, BCLIB_FOG_DENSITY[2], BCLIB_FOG_DENSITY[3]); + float c = Mth.lerp(dx, BCLIB_FOG_DENSITY[4], BCLIB_FOG_DENSITY[5]); + float d = Mth.lerp(dx, BCLIB_FOG_DENSITY[6], BCLIB_FOG_DENSITY[7]); a = Mth.lerp(dy, a, b); b = Mth.lerp(dy, c, d); diff --git a/src/main/java/ru/bclib/mixin/common/BoneMealItemMixin.java b/src/main/java/ru/bclib/mixin/common/BoneMealItemMixin.java index 2d3a06d0..cd84cb8a 100644 --- a/src/main/java/ru/bclib/mixin/common/BoneMealItemMixin.java +++ b/src/main/java/ru/bclib/mixin/common/BoneMealItemMixin.java @@ -11,6 +11,7 @@ import net.minecraft.world.level.biome.Biome.BiomeCategory; 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.block.state.properties.Property; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -21,6 +22,8 @@ import ru.bclib.api.TagAPI; import ru.bclib.util.BlocksHelper; import ru.bclib.util.MHelper; +import java.util.Collection; + @Mixin(BoneMealItem.class) public class BoneMealItemMixin { private static final MutableBlockPos bclib_BLOCK_POS = new MutableBlockPos(); @@ -31,24 +34,23 @@ public class BoneMealItemMixin { BlockPos blockPos = context.getClickedPos(); if (!world.isClientSide) { BlockPos offseted = blockPos.relative(context.getClickedFace()); - boolean endBiome = world.getBiome(offseted).getBiomeCategory() == BiomeCategory.THEEND; - - if (world.getBlockState(blockPos).is(TagAPI.END_GROUND)) { + if (BonemealAPI.isTerrain(world.getBlockState(blockPos).getBlock())) { boolean consume = false; - if (world.getBlockState(blockPos).is(Blocks.END_STONE)) { - BlockState nylium = bclib_getNylium(world, blockPos); - if (nylium != null) { - BlocksHelper.setWithoutUpdate(world, blockPos, nylium); + if (BonemealAPI.isSpreadableTerrain(world.getBlockState(blockPos).getBlock())) { + BlockState terrain = bclib_getSpreadable(world, blockPos); + if (terrain != null) { + BlocksHelper.setWithoutUpdate(world, blockPos, terrain); consume = true; } } else { - if (!world.getFluidState(offseted).isEmpty() && endBiome) { - if (world.getBlockState(offseted).getBlock().equals(Blocks.WATER)) { + BlockState stateAbove = world.getBlockState(blockPos.above()); + if (!stateAbove.getFluidState().isEmpty()) { + if (stateAbove.is(Blocks.WATER)) { consume = bclib_growWaterGrass(world, blockPos); } } - else { + else if (stateAbove.isAir()) { consume = bclib_growLandGrass(world, blockPos); } } @@ -61,12 +63,6 @@ public class BoneMealItemMixin { info.cancel(); } } - else if (!world.getFluidState(offseted).isEmpty() && endBiome) { - if (world.getBlockState(offseted).getBlock().equals(Blocks.WATER)) { - info.setReturnValue(InteractionResult.FAIL); - info.cancel(); - } - } } } @@ -130,19 +126,42 @@ public class BoneMealItemMixin { private BlockState bclib_getWaterGrassState(Level world, BlockPos pos) { BlockState state = world.getBlockState(pos); Block block = state.getBlock(); - block = BonemealAPI.getLandGrass(BiomeAPI.getBiomeID(world.getBiome(pos)), block, world.getRandom()); + block = BonemealAPI.getWaterGrass(BiomeAPI.getBiomeID(world.getBiome(pos)), block, world.getRandom()); return block == null ? null : block.defaultBlockState(); } - private BlockState bclib_getNylium(Level world, BlockPos pos) { + private BlockState bclib_getSpreadable(Level world, BlockPos pos) { Vec3i[] offsets = MHelper.getOffsets(world.getRandom()); + BlockState center = world.getBlockState(pos); for (Vec3i dir : offsets) { BlockPos p = pos.offset(dir); BlockState state = world.getBlockState(p); - if (BonemealAPI.isSpreadable(state.getBlock())) { + Block terrain = BonemealAPI.getSpreadable(state.getBlock()); + if (center.is(terrain)) { + if (haveSameProperties(state, center)) { + for (Property property: center.getProperties()) { + state = state.setValue(property, center.getValue(property)); + } + } return state; } } return null; } + + private boolean haveSameProperties(BlockState state1, BlockState state2) { + Property[] properties1 = state1.getProperties().toArray(new Property[0]); + Property[] properties2 = state2.getProperties().toArray(new Property[0]); + if (properties1.length != properties2.length) { + return false; + } + for (int i = 0; i < properties1.length; i++) { + String name1 = properties1[i].getName(); + String name2 = properties2[i].getName(); + if (!name1.equals(name2)) { + return false; + } + } + return true; + } } \ No newline at end of file diff --git a/src/main/java/ru/bclib/mixin/common/FeatureDecoratorsAccessor.java b/src/main/java/ru/bclib/mixin/common/FeatureDecoratorsAccessor.java index ba18731a..5e6ed7ad 100644 --- a/src/main/java/ru/bclib/mixin/common/FeatureDecoratorsAccessor.java +++ b/src/main/java/ru/bclib/mixin/common/FeatureDecoratorsAccessor.java @@ -7,5 +7,5 @@ import org.spongepowered.asm.mixin.gen.Accessor; @Mixin(targets = "net.minecraft.data.worldgen.Features$Decorators") public interface FeatureDecoratorsAccessor { @Accessor("HEIGHTMAP_SQUARE") - ConfiguredDecorator bcl_getHeightmapSquare(); + ConfiguredDecorator bclib_getHeightmapSquare(); } diff --git a/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java b/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java index fe2b5897..d5876718 100644 --- a/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java +++ b/src/main/java/ru/bclib/mixin/common/MinecraftServerMixin.java @@ -35,20 +35,20 @@ public class MinecraftServerMixin { protected WorldData worldData; @Inject(method = "reloadResources", at = @At(value = "RETURN"), cancellable = true) - private void bcl_reloadResources(Collection collection, CallbackInfoReturnable> info) { - bcl_injectRecipes(); + private void bclib_reloadResources(Collection collection, CallbackInfoReturnable> info) { + bclib_injectRecipes(); } @Inject(method = "loadLevel", at = @At(value = "RETURN"), cancellable = true) - private void bcl_loadLevel(CallbackInfo info) { - bcl_injectRecipes(); + private void bclib_loadLevel(CallbackInfo info) { + bclib_injectRecipes(); BiomeAPI.initRegistry(MinecraftServer.class.cast(this)); } - private void bcl_injectRecipes() { + private void bclib_injectRecipes() { if (FabricLoader.getInstance().isModLoaded("kubejs")) { RecipeManagerAccessor accessor = (RecipeManagerAccessor) resources.getRecipeManager(); - accessor.bcl_setRecipes(BCLRecipeManager.getMap(accessor.bcl_getRecipes())); + accessor.bclib_setRecipes(BCLRecipeManager.getMap(accessor.bclib_getRecipes())); } } } diff --git a/src/main/java/ru/bclib/mixin/common/RecipeManagerAccessor.java b/src/main/java/ru/bclib/mixin/common/RecipeManagerAccessor.java index c17bfdfd..3920b687 100644 --- a/src/main/java/ru/bclib/mixin/common/RecipeManagerAccessor.java +++ b/src/main/java/ru/bclib/mixin/common/RecipeManagerAccessor.java @@ -12,8 +12,8 @@ import java.util.Map; @Mixin(RecipeManager.class) public interface RecipeManagerAccessor { @Accessor("recipes") - Map, Map>> bcl_getRecipes(); + Map, Map>> bclib_getRecipes(); @Accessor("recipes") - void bcl_setRecipes(Map, Map>> recipes); + void bclib_setRecipes(Map, Map>> recipes); } \ No newline at end of file diff --git a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java index 6a62af48..af47e301 100644 --- a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java +++ b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java @@ -27,21 +27,21 @@ import java.util.function.Supplier; @Mixin(ServerLevel.class) public abstract class ServerLevelMixin extends Level { - private static String bcl_lastWorld = null; + private static String bclib_lastWorld = null; protected ServerLevelMixin(WritableLevelData writableLevelData, ResourceKey resourceKey, DimensionType dimensionType, Supplier supplier, boolean bl, boolean bl2, long l) { super(writableLevelData, resourceKey, dimensionType, supplier, bl, bl2, l); } @Inject(method = "*", at = @At("TAIL")) - private void bcl_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 workerExecutor, LevelStorageSource.LevelStorageAccess session, ServerLevelData properties, ResourceKey registryKey, DimensionType dimensionType, ChunkProgressListener worldGenerationProgressListener, ChunkGenerator chunkGenerator, boolean debugWorld, long l, List list, boolean bl, CallbackInfo info) { BiomeAPI.initRegistry(server); - if (bcl_lastWorld != null && bcl_lastWorld.equals(session.getLevelId())) { + if (bclib_lastWorld != null && bclib_lastWorld.equals(session.getLevelId())) { return; } - bcl_lastWorld = session.getLevelId(); + bclib_lastWorld = session.getLevelId(); ServerLevel world = ServerLevel.class.cast(this); File dir = session.getDimensionPath(world.dimension()); diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiome.java b/src/main/java/ru/bclib/world/biomes/BCLBiome.java index dcae78c1..7b021574 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiome.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiome.java @@ -47,6 +47,7 @@ public class BCLBiome { this.genChance = definition.getGenChance(); this.fogDensity = definition.getFodDensity(); this.customData = definition.getCustomData(); + subbiomes.add(this, 1); } public BCLBiome(ResourceLocation id, Biome biome, float fogDensity, float genChance) { @@ -56,6 +57,7 @@ public class BCLBiome { this.fogDensity = fogDensity; this.readStructureList(); this.customData = Maps.newHashMap(); + subbiomes.add(this, 1); } public BCLBiome getEdge() { @@ -85,8 +87,7 @@ public class BCLBiome { } public BCLBiome getSubBiome(Random random) { - BCLBiome biome = subbiomes.get(random); - return biome == null ? this : biome; + return subbiomes.get(random); } public BCLBiome getParentBiome() {