Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.0.7'
id 'fabric-loom' version '1.3.+'
id 'maven-publish'
}

Expand Down
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.19.2
yarn_mappings=1.19.2+build.11
loader_version=0.14.9
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.10
loader_version=0.14.22

# Mod Properties
mod_version = 1.5.0
mod_version = 1.6.0
maven_group = leaf-decay
archives_base_name = leaf-decay

# Dependencies
fabric_version=0.60.0+1.19.2
cloth_config_version = 7.0.72
mod_menu_version = 4.0.0
fabric_version=0.90.4+1.20.1
cloth_config_version = 11.1.106
mod_menu_version = 7.2.2
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
3 changes: 2 additions & 1 deletion src/main/java/draylar/leafdecay/mixin/LogBreakMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import draylar.leafdecay.scheduler.LeafBreakHandler;
import net.minecraft.block.*;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
Expand All @@ -20,7 +21,7 @@ public class LogBreakMixin {
at = @At("TAIL")
)
private void afterBreak(World world, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfo info) {
if (!world.isClient && (state.getBlock() instanceof PillarBlock) && state.getMaterial().equals(Material.WOOD)) {
if (!world.isClient && (state.getBlock() instanceof PillarBlock) && state.isIn(BlockTags.LOGS)) {
BlockPos upPosition = pos.up();
BlockState upState = world.getBlockState(upPosition);

Expand Down
23 changes: 6 additions & 17 deletions src/main/java/draylar/leafdecay/scheduler/FutureBlockBreak.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ItemScatterer;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import java.util.List;

/**
* Provides information about a block that should break in the future.
*
Expand Down Expand Up @@ -45,19 +39,14 @@ public FutureBlockBreak(ServerWorld world, BlockPos pos, int maxTime) {
* <p>The block broken will drop stacks as normal.
*/
public void realize() {
BlockState state = world.getBlockState(pos);
world.setBlockState(pos, Blocks.AIR.getDefaultState());

if (!world.isClient) {
List<ItemStack> drops = Block.getDroppedStacks(state, world, pos, null);
DefaultedList<ItemStack> defaultedDropList = DefaultedList.ofSize(drops.size(), ItemStack.EMPTY);
if (world.isClient) {
return;
}

for (int i = 0; i < drops.size(); i++) {
defaultedDropList.set(i, drops.get(i));
}
BlockState state = world.getBlockState(pos);

ItemScatterer.spawn(world, pos, defaultedDropList);
}
Block.dropStacks(state, world, pos);
world.removeBlock(pos, false);
}

public int getElapsedTime() {
Expand Down
34 changes: 17 additions & 17 deletions src/main/java/draylar/leafdecay/scheduler/LeafBreakHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,32 @@
import net.minecraft.block.BlockState;
import net.minecraft.block.LeavesBlock;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Pair;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class LeafBreakHandler {

private static final ArrayList<FutureBlockBreak> breakList = new ArrayList<>();
private static final ArrayList<FutureBlockBreak> BREAK_LIST = new ArrayList<>();

public static void init() {
ServerTickEvents.END_SERVER_TICK.register(tick -> {
List<FutureBlockBreak> nearbyFutureBreakOrigins = new ArrayList<>();

for(Iterator<FutureBlockBreak> iterator = breakList.iterator(); iterator.hasNext();) {
for (Iterator<FutureBlockBreak> iterator = BREAK_LIST.iterator(); iterator.hasNext();) {
FutureBlockBreak leafBreak = iterator.next();
// should be broken
if (leafBreak.getElapsedTime() >= leafBreak.getMaxTime()) {
int elapsed = leafBreak.getElapsedTime();

if (elapsed >= leafBreak.getMaxTime()) {
// should be broken
leafBreak.realize();
iterator.remove();
nearbyFutureBreakOrigins.add(leafBreak);
}

// increment time
else {
leafBreak.setElapsedTime(leafBreak.getElapsedTime() + 1);
} else {
// increment time
leafBreak.setElapsedTime(elapsed + 1);
}
}

Expand All @@ -48,18 +45,21 @@ public static void addNearbyFutureBreaks(ServerWorld world, BlockPos pos) {
BlockState newState = world.getBlockState(offset);

// ensure new position is a leaf and that the break list doesn't already contain it
if (newState.getBlock() instanceof LeavesBlock && !breakListContains(offset)) {
if (!breakListContains(offset) &&
world.getBlockState(offset).getBlock() instanceof LeavesBlock leavesBlock) {

// if the leaf would naturally decay, add it to the break list
if (!newState.get(LeavesBlock.PERSISTENT) && newState.get(LeavesBlock.DISTANCE) == 7) {
// (hasRandomTicks() is identical to shouldDecay() but is public without an access widener)
if (leavesBlock.hasRandomTicks(newState)) {
LeafBreakHandler.addFutureBreak(new FutureBlockBreak(world, offset, 5));
}
}
}
}

private static boolean breakListContains(BlockPos offset) {
for(FutureBlockBreak futureBreak : breakList) {
if(futureBreak.getPos().equals(offset)) {
for (FutureBlockBreak futureBreak : BREAK_LIST) {
if (futureBreak.getPos().equals(offset)) {
return true;
}
}
Expand All @@ -69,6 +69,6 @@ private static boolean breakListContains(BlockPos offset) {


public static void addFutureBreak(FutureBlockBreak futureBreak) {
breakList.add(futureBreak);
BREAK_LIST.add(futureBreak);
}
}
5 changes: 2 additions & 3 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"schemaVersion": 1,
"id": "leaf-decay",
Expand Down Expand Up @@ -29,7 +28,7 @@
],

"depends": {
"fabricloader": ">=0.7.0",
"fabric": ">=0.14.0"
"fabricloader": ">=0.13.3",
"fabric-api": "*"
}
}