Skip to content

Commit

Permalink
Fix #20 for 1.16.2 (Fabric)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakambda committed Sep 4, 2020
1 parent b61233b commit 73d1685
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion changes.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* Make break speed mixin cancellable, should fix #19
* Perform less ticking on leaves (#20)
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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<LeafBreakingSchedule> scheduledLeavesBreaking = new ConcurrentSet<>();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand Down

0 comments on commit 73d1685

Please sign in to comment.