From 0138e5df95c8fa7c723ab074271497256bde7126 Mon Sep 17 00:00:00 2001 From: Raycoms Date: Thu, 8 Dec 2022 19:35:28 +0100 Subject: [PATCH] Further setup --- gradle.properties | 2 +- .../com/ldtteam/overgrowth/Overgrowth.java | 2 + .../ldtteam/overgrowth/handlers/ByeTorch.java | 6 +-- .../overgrowth/handlers/CoastDecline.java | 4 +- .../handlers/CrackedBlocksDegradation.java | 6 +-- .../overgrowth/handlers/DegradeFarmland.java | 4 +- .../overgrowth/handlers/GrowMushrooms.java | 4 +- .../handlers/GrowPlantsOnGrass.java | 6 +-- .../overgrowth/handlers/GrowWaterPlants.java | 4 +- .../handlers/ITransformationHandler.java | 18 ++++++- .../ldtteam/overgrowth/handlers/LavaDry.java | 4 +- .../handlers/MossyBlocksDegradation.java | 6 +-- .../ldtteam/overgrowth/handlers/MudDry.java | 51 +++++++++++++++++++ .../overgrowth/handlers/MuddyRain.java | 51 +++++++++++++++++++ .../overgrowth/handlers/NightCampfire.java | 4 +- .../overgrowth/handlers/SandToSandstone.java | 4 +- .../overgrowth/handlers/SpiderWebs.java | 4 +- .../ldtteam/overgrowth/handlers/UndoPath.java | 4 +- .../overgrowth/mixin/ChunkTickMixin.java | 24 +++++---- 19 files changed, 165 insertions(+), 43 deletions(-) create mode 100644 src/main/java/com/ldtteam/overgrowth/handlers/MudDry.java create mode 100644 src/main/java/com/ldtteam/overgrowth/handlers/MuddyRain.java diff --git a/gradle.properties b/gradle.properties index d21a56e..4b584da 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ # This is required to provide enough memory for the Minecraft decompilation process. org.gradle.jvmargs=-Xmx3G -Djava.net.preferIPv4Stack=true org.gradle.daemon=false -mod_version=1.0.4 +mod_version=1.0.6 modid=overgrowth mc_version=1.19.2 forge_version=43.0.8 diff --git a/src/main/java/com/ldtteam/overgrowth/Overgrowth.java b/src/main/java/com/ldtteam/overgrowth/Overgrowth.java index 6bdef6c..f0047df 100644 --- a/src/main/java/com/ldtteam/overgrowth/Overgrowth.java +++ b/src/main/java/com/ldtteam/overgrowth/Overgrowth.java @@ -33,6 +33,8 @@ public Overgrowth() ITransformationHandler.HANDLERS.add(new NightCampfire()); ITransformationHandler.HANDLERS.add(new SandToSandstone()); ITransformationHandler.HANDLERS.add(new UndoPath()); + ITransformationHandler.HANDLERS.add(new MuddyRain()); + ITransformationHandler.HANDLERS.add(new MudDry()); Mod.EventBusSubscriber.Bus.FORGE.bus().get().register(EntityHandling.class); } diff --git a/src/main/java/com/ldtteam/overgrowth/handlers/ByeTorch.java b/src/main/java/com/ldtteam/overgrowth/handlers/ByeTorch.java index c50d591..7ad1d7b 100644 --- a/src/main/java/com/ldtteam/overgrowth/handlers/ByeTorch.java +++ b/src/main/java/com/ldtteam/overgrowth/handlers/ByeTorch.java @@ -24,13 +24,13 @@ public boolean transforms(final BlockState state) @Override public boolean ready(final long worldTick) { - return worldTick % 199 == 0; + return worldTick % 19 == 0; } @Override - public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection) + public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection, final BlockState input) { final BlockPos worldPos = Utils.getWorldPos(chunk, chunk.getSections()[chunkSection], relativePos); - chunk.getLevel().destroyBlock(worldPos, true); + chunk.getLevel().destroyBlock(worldPos, false); } } diff --git a/src/main/java/com/ldtteam/overgrowth/handlers/CoastDecline.java b/src/main/java/com/ldtteam/overgrowth/handlers/CoastDecline.java index 6f80114..f9a3c15 100644 --- a/src/main/java/com/ldtteam/overgrowth/handlers/CoastDecline.java +++ b/src/main/java/com/ldtteam/overgrowth/handlers/CoastDecline.java @@ -40,11 +40,11 @@ public boolean transforms(final BlockState state) @Override public boolean ready(final long worldTick) { - return worldTick % 99 == 0; + return worldTick % 18 == 0; } @Override - public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection) + public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection, final BlockState input) { for (final Direction direction : Direction.Plane.HORIZONTAL) { diff --git a/src/main/java/com/ldtteam/overgrowth/handlers/CrackedBlocksDegradation.java b/src/main/java/com/ldtteam/overgrowth/handlers/CrackedBlocksDegradation.java index 761474c..1242b94 100644 --- a/src/main/java/com/ldtteam/overgrowth/handlers/CrackedBlocksDegradation.java +++ b/src/main/java/com/ldtteam/overgrowth/handlers/CrackedBlocksDegradation.java @@ -52,11 +52,11 @@ public boolean transforms(final BlockState state) @Override public boolean ready(final long worldTick) { - return worldTick % 97 == 0; + return worldTick % 17 == 0; } @Override - public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection) + public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection, final BlockState input) { for (final Direction direction : Direction.values()) { @@ -66,7 +66,7 @@ public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, f final LevelChunkSection section = chunk.getSections()[chunkSection]; final BlockPos worldPos = Utils.getWorldPos(chunk, section, relativePos); - chunk.getLevel().setBlock(worldPos, transformationMapping.get(Utils.getBlockState(chunk, relativePos, chunkSection).getBlock()).defaultBlockState(), UPDATE_ALL_IMMEDIATE); + chunk.getLevel().setBlock(worldPos, transformationMapping.get(input.getBlock()).withPropertiesOf(input), UPDATE_ALL_IMMEDIATE); return; } } diff --git a/src/main/java/com/ldtteam/overgrowth/handlers/DegradeFarmland.java b/src/main/java/com/ldtteam/overgrowth/handlers/DegradeFarmland.java index 59dc4a2..ea28cb0 100644 --- a/src/main/java/com/ldtteam/overgrowth/handlers/DegradeFarmland.java +++ b/src/main/java/com/ldtteam/overgrowth/handlers/DegradeFarmland.java @@ -30,11 +30,11 @@ public boolean transforms(final BlockState state) @Override public boolean ready(final long worldTick) { - return worldTick % 96 == 0; + return worldTick % 16 == 0; } @Override - public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection) + public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection, final BlockState input) { final BlockState upState = Utils.getBlockState(chunk, relativePos.above(), chunkSection); if (upState.isAir() || chunk.getLevel().getRandom().nextInt(100) < 1) diff --git a/src/main/java/com/ldtteam/overgrowth/handlers/GrowMushrooms.java b/src/main/java/com/ldtteam/overgrowth/handlers/GrowMushrooms.java index 461280b..b756ff6 100644 --- a/src/main/java/com/ldtteam/overgrowth/handlers/GrowMushrooms.java +++ b/src/main/java/com/ldtteam/overgrowth/handlers/GrowMushrooms.java @@ -53,11 +53,11 @@ public boolean transforms(final BlockState state) @Override public boolean ready(final long worldTick) { - return worldTick % 130 == 0; + return worldTick % 23 == 0; } @Override - public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection) + public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection, final BlockState input) { for (final Direction direction : Direction.values()) { diff --git a/src/main/java/com/ldtteam/overgrowth/handlers/GrowPlantsOnGrass.java b/src/main/java/com/ldtteam/overgrowth/handlers/GrowPlantsOnGrass.java index 14f60a2..17df65a 100644 --- a/src/main/java/com/ldtteam/overgrowth/handlers/GrowPlantsOnGrass.java +++ b/src/main/java/com/ldtteam/overgrowth/handlers/GrowPlantsOnGrass.java @@ -28,13 +28,13 @@ public boolean transforms(final BlockState state) } @Override - public boolean ready(final long worldTick) + public boolean ready(final long worldTick, final LevelChunk chunk) { - return worldTick % 101 == 0; + return chunk.getLevel().isRaining() ? worldTick % 6 == 0 : worldTick % 11 == 0; } @Override - public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection) + public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection, final BlockState input) { final BlockState upState = Utils.getBlockState(chunk, relativePos.above(), chunkSection); if (upState.isAir()) diff --git a/src/main/java/com/ldtteam/overgrowth/handlers/GrowWaterPlants.java b/src/main/java/com/ldtteam/overgrowth/handlers/GrowWaterPlants.java index 69d120a..5ffc14f 100644 --- a/src/main/java/com/ldtteam/overgrowth/handlers/GrowWaterPlants.java +++ b/src/main/java/com/ldtteam/overgrowth/handlers/GrowWaterPlants.java @@ -28,11 +28,11 @@ public boolean transforms(final BlockState state) @Override public boolean ready(final long worldTick) { - return worldTick % 102 == 0; + return worldTick % 12 == 0; } @Override - public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection) + public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection, final BlockState input) { final BlockState state = Utils.getBlockState(chunk, relativePos, chunkSection); final LevelChunkSection section = chunk.getSections()[chunkSection]; diff --git a/src/main/java/com/ldtteam/overgrowth/handlers/ITransformationHandler.java b/src/main/java/com/ldtteam/overgrowth/handlers/ITransformationHandler.java index 5d4fc9e..1b09502 100644 --- a/src/main/java/com/ldtteam/overgrowth/handlers/ITransformationHandler.java +++ b/src/main/java/com/ldtteam/overgrowth/handlers/ITransformationHandler.java @@ -35,15 +35,29 @@ public interface ITransformationHandler * @param worldTick the relative world tick to do a transformation in. * @return true if so. */ - boolean ready(final long worldTick); + default boolean ready(final long worldTick) + { + return true; + } + + /** + * Check if the transformation handler is ready to do a transformation now. + * @param worldTick the relative world tick to do a transformation in. + * @return true if so. + */ + default boolean ready(final long worldTick, final LevelChunk chunk) + { + return ready(worldTick); + } /** * Transform a given block in a given chunk. * @param relativePos the relative position in the chunk section. * @param chunk the chunk itself. * @param chunkSection the chunk section id. + * @param input the input state. */ - void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection); + void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection, final BlockState input); /** * Add a new handler to the list of handlers. diff --git a/src/main/java/com/ldtteam/overgrowth/handlers/LavaDry.java b/src/main/java/com/ldtteam/overgrowth/handlers/LavaDry.java index ddaf972..70c4c10 100644 --- a/src/main/java/com/ldtteam/overgrowth/handlers/LavaDry.java +++ b/src/main/java/com/ldtteam/overgrowth/handlers/LavaDry.java @@ -24,11 +24,11 @@ public boolean transforms(final BlockState state) @Override public boolean ready(final long worldTick) { - return worldTick % 103 == 0; + return worldTick % 13 == 0; } @Override - public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection) + public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection, final BlockState input) { int lavaCount = 0; for (final Direction direction : Direction.values()) diff --git a/src/main/java/com/ldtteam/overgrowth/handlers/MossyBlocksDegradation.java b/src/main/java/com/ldtteam/overgrowth/handlers/MossyBlocksDegradation.java index 20f2d70..c838d6d 100644 --- a/src/main/java/com/ldtteam/overgrowth/handlers/MossyBlocksDegradation.java +++ b/src/main/java/com/ldtteam/overgrowth/handlers/MossyBlocksDegradation.java @@ -45,11 +45,11 @@ public boolean transforms(final BlockState state) @Override public boolean ready(final long worldTick) { - return worldTick % 104 == 0; + return worldTick % 14 == 0; } @Override - public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection) + public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection, final BlockState input) { for (final Direction direction : Direction.values()) { @@ -60,7 +60,7 @@ public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, f final BlockPos worldPos = Utils.getWorldPos(chunk, section, relativePos); - chunk.getLevel().setBlock(worldPos, transformationMapping.get(Utils.getBlockState(chunk, relativePos, chunkSection).getBlock()).defaultBlockState(), UPDATE_ALL_IMMEDIATE); + chunk.getLevel().setBlock(worldPos, transformationMapping.get(input.getBlock()).withPropertiesOf(input), UPDATE_ALL_IMMEDIATE); return; } } diff --git a/src/main/java/com/ldtteam/overgrowth/handlers/MudDry.java b/src/main/java/com/ldtteam/overgrowth/handlers/MudDry.java new file mode 100644 index 0000000..613bdfe --- /dev/null +++ b/src/main/java/com/ldtteam/overgrowth/handlers/MudDry.java @@ -0,0 +1,51 @@ +package com.ldtteam.overgrowth.handlers; + +import com.ldtteam.overgrowth.utils.Utils; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.LevelChunk; +import net.minecraft.world.level.chunk.LevelChunkSection; + +import static net.minecraft.world.level.block.Block.UPDATE_ALL_IMMEDIATE; + +/** + * Mud dries up + */ +public class MudDry implements ITransformationHandler +{ + @Override + public boolean transforms(final BlockState state) + { + return state.getBlock() == Blocks.MUD; + } + + @Override + public boolean ready(final long worldTick, final LevelChunk chunk) + { + return !chunk.getLevel().isRaining() && worldTick % 17 == 0; + } + + @Override + public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection, final BlockState input) + { + int waterCount = 0; + for (final Direction direction : Direction.values()) + { + final BlockState relativeState = Utils.getBlockState(chunk, relativePos.relative(direction), chunkSection); + if (relativeState.getBlock() == Blocks.WATER || relativeState.getBlock() == Blocks.MUD) + { + waterCount++; + } + } + + if (waterCount < 3) + { + final LevelChunkSection section = chunk.getSections()[chunkSection]; + final BlockPos worldPos = Utils.getWorldPos(chunk, section, relativePos); + + chunk.getLevel().setBlock(worldPos, Blocks.DIRT.defaultBlockState(), UPDATE_ALL_IMMEDIATE); + } + } +} diff --git a/src/main/java/com/ldtteam/overgrowth/handlers/MuddyRain.java b/src/main/java/com/ldtteam/overgrowth/handlers/MuddyRain.java new file mode 100644 index 0000000..6866622 --- /dev/null +++ b/src/main/java/com/ldtteam/overgrowth/handlers/MuddyRain.java @@ -0,0 +1,51 @@ +package com.ldtteam.overgrowth.handlers; + +import com.ldtteam.overgrowth.utils.Utils; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; +import net.minecraft.data.worldgen.placement.VegetationPlacements; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.BonemealableBlock; +import net.minecraft.world.level.block.TallGrassBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.LevelChunk; +import net.minecraft.world.level.chunk.LevelChunkSection; +import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; +import net.minecraft.world.level.levelgen.feature.configurations.RandomPatchConfiguration; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; + +import java.util.List; + +import static net.minecraft.world.level.block.Block.UPDATE_ALL_IMMEDIATE; + +/** + * Makes grass or dirt randomly to mud in the rain + */ +public class MuddyRain implements ITransformationHandler +{ + @Override + public boolean transforms(final BlockState state) + { + return state.getBlock() == Blocks.DIRT || state.getBlock() == Blocks.GRASS_BLOCK; + } + + @Override + public boolean ready(final long worldTick, final LevelChunk chunk) + { + return chunk.getLevel().isRaining() && worldTick % 17 == 0; + } + + @Override + public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection, final BlockState input) + { + final LevelChunkSection section = chunk.getSections()[chunkSection]; + final BlockPos worldPos = Utils.getWorldPos(chunk, section, relativePos); + + if (chunk.getLevel().canSeeSky(worldPos.above())) + { + chunk.getLevel().setBlock(worldPos, Blocks.MUD.defaultBlockState(), UPDATE_ALL_IMMEDIATE); + } + } +} diff --git a/src/main/java/com/ldtteam/overgrowth/handlers/NightCampfire.java b/src/main/java/com/ldtteam/overgrowth/handlers/NightCampfire.java index db024a1..59e99e9 100644 --- a/src/main/java/com/ldtteam/overgrowth/handlers/NightCampfire.java +++ b/src/main/java/com/ldtteam/overgrowth/handlers/NightCampfire.java @@ -20,11 +20,11 @@ public boolean transforms(final BlockState state) @Override public boolean ready(final long worldTick) { - return worldTick % 99 == 0; + return worldTick % 11 == 0; } @Override - public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection) + public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection, final BlockState input) { final BlockState relativeState = Utils.getBlockState(chunk, relativePos.below(), chunkSection); if (relativeState.getBlock() == Blocks.HAY_BLOCK) diff --git a/src/main/java/com/ldtteam/overgrowth/handlers/SandToSandstone.java b/src/main/java/com/ldtteam/overgrowth/handlers/SandToSandstone.java index 12e009d..446dd21 100644 --- a/src/main/java/com/ldtteam/overgrowth/handlers/SandToSandstone.java +++ b/src/main/java/com/ldtteam/overgrowth/handlers/SandToSandstone.java @@ -24,11 +24,11 @@ public boolean transforms(final BlockState state) @Override public boolean ready(final long worldTick) { - return worldTick % 103 == 0; + return worldTick % 13 == 0; } @Override - public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection) + public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection, final BlockState input) { final BlockState relativeState = Utils.getBlockState(chunk, relativePos.below(), chunkSection); if (relativeState.getBlock() == Blocks.SAND) diff --git a/src/main/java/com/ldtteam/overgrowth/handlers/SpiderWebs.java b/src/main/java/com/ldtteam/overgrowth/handlers/SpiderWebs.java index 21725c0..a503054 100644 --- a/src/main/java/com/ldtteam/overgrowth/handlers/SpiderWebs.java +++ b/src/main/java/com/ldtteam/overgrowth/handlers/SpiderWebs.java @@ -39,11 +39,11 @@ public boolean transforms(final BlockState state) @Override public boolean ready(final long worldTick) { - return worldTick % 105 == 0; + return worldTick % 15 == 0; } @Override - public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection) + public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection, final BlockState input) { for (final Direction direction : Direction.values()) { diff --git a/src/main/java/com/ldtteam/overgrowth/handlers/UndoPath.java b/src/main/java/com/ldtteam/overgrowth/handlers/UndoPath.java index 0f207c6..dd31820 100644 --- a/src/main/java/com/ldtteam/overgrowth/handlers/UndoPath.java +++ b/src/main/java/com/ldtteam/overgrowth/handlers/UndoPath.java @@ -20,11 +20,11 @@ public boolean transforms(final BlockState state) @Override public boolean ready(final long worldTick) { - return worldTick % 299 == 0; + return worldTick % 29 == 0; } @Override - public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection) + public void transformBlock(final BlockPos relativePos, final LevelChunk chunk, final int chunkSection, final BlockState input) { final BlockPos worldPos = Utils.getWorldPos(chunk, chunk.getSections()[chunkSection], relativePos); chunk.getLevel().setBlock(worldPos, Blocks.DIRT.defaultBlockState(), 0x03); diff --git a/src/main/java/com/ldtteam/overgrowth/mixin/ChunkTickMixin.java b/src/main/java/com/ldtteam/overgrowth/mixin/ChunkTickMixin.java index cf5acf0..63c4753 100644 --- a/src/main/java/com/ldtteam/overgrowth/mixin/ChunkTickMixin.java +++ b/src/main/java/com/ldtteam/overgrowth/mixin/ChunkTickMixin.java @@ -24,27 +24,31 @@ public abstract class ChunkTickMixin @Inject(method = "tickChunk", at = @At("HEAD")) public void tickChunk(final LevelChunk chunk, final int k, final CallbackInfo ci) { - if (k > 0) + if (k <= 0 || chunk.getLevel().getGameTime() != 0 && chunk.getLevel().getRandom().nextInt(20) != 1) { - LevelChunkSection[] chunkSections = chunk.getSections(); + return; + } - for (int sectionId = 0; sectionId < chunkSections.length; sectionId++) - { - LevelChunkSection levelchunksection = chunkSections[sectionId]; + LevelChunkSection[] chunkSections = chunk.getSections(); - for (int times = 0; times < k; times++) - { - BlockPos randomPos = this.getBlockRandomPos(); + for (int sectionId = 0; sectionId < chunkSections.length; sectionId++) + { + LevelChunkSection levelchunksection = chunkSections[sectionId]; + for (int times = 0; times < k; times++) + { + if (chunk.getLevel().getRandom().nextInt(20) == 1) + { + final BlockPos randomPos = this.getBlockRandomPos(); for (ITransformationHandler handler : ITransformationHandler.HANDLERS) { BlockState randomState = levelchunksection.getBlockState(randomPos.getX(), randomPos.getY(), randomPos.getZ()); - if (handler.transforms(randomState) && handler.ready(chunk.getLevel().getGameTime() + times)) + if (handler.transforms(randomState) && handler.ready(chunk.getLevel().getGameTime() + times, chunk)) { try { - handler.transformBlock(randomPos, chunk, sectionId); + handler.transformBlock(randomPos, chunk, sectionId, randomState); } catch (final Exception ex) {