From 73d1685a2b73e65924b0ee2a6dba4c77a10c47ee Mon Sep 17 00:00:00 2001 From: Thomas Couchoud Date: Fri, 4 Sep 2020 18:10:34 +0200 Subject: [PATCH] Fix #20 for 1.16.2 (Fabric) --- CHANGELOG.md | 3 +++ changes.md | 2 +- gradle.properties | 6 +++--- .../fallingtree/config/Configuration.java | 4 ++-- .../leaves/LeafBreakingHandler.java | 21 ++++++++----------- .../fallingtree/mixin/WorldMixin.java | 6 +++++- 6 files changed, 23 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9ffe4b9..8878d3cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## [Fabric-1.16.2-2.3.0] - 2020-09-04 +* Perform less ticking on leaves (#20) + ## [Fabric-1.16.2-2.2.3] - 2020-09-01 * Make break speed mixin cancellable, should fix #19 diff --git a/changes.md b/changes.md index 6f0d1d3b..af56398d 100644 --- a/changes.md +++ b/changes.md @@ -1 +1 @@ -* Make break speed mixin cancellable, should fix #19 \ No newline at end of file +* Perform less ticking on leaves (#20) \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index efd763bb..873431f8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,15 +4,15 @@ org.gradle.daemon=false group=fr.raksrinana loader=Fabric mod_id=falling_tree -version=2.2.3 +version=2.3.0 repoName=FallingTree name=FallingTree minecraft_version=1.16.2 -yarn_mappings=1.16.2+build.31 +yarn_mappings=1.16.2+build.46 loader_version=0.9.2+build.206 -fabric_version=0.19.0+build.398-1.16 +fabric_version=0.20.1+build.401-1.16 curseforge_project_id=349559 curseforge_release_type=beta diff --git a/src/main/java/fr/raksrinana/fallingtree/config/Configuration.java b/src/main/java/fr/raksrinana/fallingtree/config/Configuration.java index afcbe6b3..1a57acfa 100644 --- a/src/main/java/fr/raksrinana/fallingtree/config/Configuration.java +++ b/src/main/java/fr/raksrinana/fallingtree/config/Configuration.java @@ -21,9 +21,9 @@ @Config(name = "fallingtree") public class Configuration implements ConfigData{ @Comment("When set to true, a tree will only be chopped down if the player is sneaking.") - public final boolean reverseSneaking = false; + public boolean reverseSneaking = false; @Comment("When set to true, the mod will cut down trees in creative too.") - public final boolean breakInCreative = false; + public boolean breakInCreative = false; @ConfigEntry.Category("trees") @ConfigEntry.Gui.TransitiveObject public TreeConfiguration trees = new TreeConfiguration(); diff --git a/src/main/java/fr/raksrinana/fallingtree/leaves/LeafBreakingHandler.java b/src/main/java/fr/raksrinana/fallingtree/leaves/LeafBreakingHandler.java index afcca2d5..6ef48696 100644 --- a/src/main/java/fr/raksrinana/fallingtree/leaves/LeafBreakingHandler.java +++ b/src/main/java/fr/raksrinana/fallingtree/leaves/LeafBreakingHandler.java @@ -1,13 +1,13 @@ package fr.raksrinana.fallingtree.leaves; import io.netty.util.internal.ConcurrentSet; -import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.server.MinecraftServer; import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.world.chunk.Chunk; import java.util.Iterator; import java.util.Set; -import static fr.raksrinana.fallingtree.FallingTreeUtils.isLeafBlock; public class LeafBreakingHandler implements net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents.EndTick{ public static final Set scheduledLeavesBreaking = new ConcurrentSet<>(); @@ -19,19 +19,16 @@ public void onEndTick(MinecraftServer minecraftServer){ LeafBreakingSchedule leafBreakingSchedule = leavesBreak.next(); ServerWorld world = leafBreakingSchedule.getWorld(); if(leafBreakingSchedule.getRemainingTicks() <= 0){ - if(world.isChunkLoaded(leafBreakingSchedule.getBlockPos())){ + Chunk chunk = world.getChunk(leafBreakingSchedule.getBlockPos()); + ChunkPos chunkPos = chunk.getPos(); + if(world.isChunkLoaded(chunkPos.x, chunkPos.z)){ BlockState state = world.getBlockState(leafBreakingSchedule.getBlockPos()); - Block block = state.getBlock(); - if(isLeafBlock(block)){ - block.randomTick(state, world, leafBreakingSchedule.getBlockPos(), world.getRandom()); + state.scheduledTick(world, leafBreakingSchedule.getBlockPos(), world.getRandom()); + if(state.hasRandomTicks()){ + state.randomTick(world, leafBreakingSchedule.getBlockPos(), world.getRandom()); } - else{ - leavesBreak.remove(); - } - } - else{ - leavesBreak.remove(); } + leavesBreak.remove(); } else{ leafBreakingSchedule.tick(); diff --git a/src/main/java/fr/raksrinana/fallingtree/mixin/WorldMixin.java b/src/main/java/fr/raksrinana/fallingtree/mixin/WorldMixin.java index e392a4c8..932a82f7 100644 --- a/src/main/java/fr/raksrinana/fallingtree/mixin/WorldMixin.java +++ b/src/main/java/fr/raksrinana/fallingtree/mixin/WorldMixin.java @@ -8,8 +8,10 @@ import net.minecraft.block.Blocks; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.Direction; import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -33,7 +35,9 @@ private static void onUpdate(ServerWorld world, BlockPos eventPos, BlockState ev if(eventBlock.is(Blocks.AIR)){ for(Direction facing : notifiedSides){ BlockPos neighborPos = eventPos.offset(facing); - if(world.isChunkLoaded(neighborPos)){ + Chunk chunk = world.getChunk(neighborPos); + ChunkPos chunkPos = chunk.getPos(); + if(world.isChunkLoaded(chunkPos.x, chunkPos.z)){ BlockState neighborState = world.getBlockState(neighborPos); if(isLeafBlock(neighborState.getBlock())){ LeafBreakingHandler.scheduledLeavesBreaking.add(new LeafBreakingSchedule(world, neighborPos, 4));