Skip to content

Commit

Permalink
fast leaf decay
Browse files Browse the repository at this point in the history
  • Loading branch information
FalsePattern committed Dec 28, 2024
1 parent d6935a9 commit 9be8973
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/java/mega/blendtronic/config/MinecraftConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ public final class MinecraftConfig {
@Config.DefaultBoolean(true)
public static boolean allowToolSwitchOnBlockBreak;

@Config.Comment("[SERVER] Whether or not enable faster leaf decay. Decay speed is controlled by Decay Speed and Fuzz")
@Config.DefaultBoolean(true)
public static boolean FAST_LEAF_DECAY;

@Config.Comment("[SERVER] The amount of ticks every leave needs to decay (Lower is faster)")
@Config.DefaultInt(21)
@Config.NoSync
public static int DECAY_SPEED;

@Config.Comment({"[SERVER] A random number from 0 to (this config value) will be added to the decay speed for every leaf block.",
"Setting this to 0 will decay leaves rather linear while higher numbers will let the whole thing look more natural"})
@Config.DefaultInt(15)
@Config.NoSync
public static int DECAY_FUZZ;

static {
ConfigurationManager.selfInit();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Blendtronic
*
* Copyright (C) 2021-2024 SirFell, the MEGA team
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package mega.blendtronic.mixin.mixins.common.FastLeafDecay;

import mega.blendtronic.modules.FastLeafDecay.LeafDecayHelper;
import org.spongepowered.asm.mixin.Mixin;

import net.minecraft.block.Block;
import net.minecraft.block.BlockLeavesBase;
import net.minecraft.block.material.Material;
import net.minecraft.world.World;

@Mixin(BlockLeavesBase.class)
public abstract class BlockLeavesBaseMixin extends Block {
protected BlockLeavesBaseMixin(Material materialIn) {
super(materialIn);
}

@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block neighbor) {
LeafDecayHelper.handleLeafDecay(world, x, y, z, this);
}
}
4 changes: 4 additions & 0 deletions src/main/java/mega/blendtronic/mixin/plugin/Mixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ public enum Mixin implements IMixin {
client_fancyfurnace_BlockFurnaceMixin(CLIENT, always(), "fancyfurnace.BlockFurnaceMixin"),
common_fancyfurnace_TileEntityFurnace(COMMON, always(), "fancyfurnace.TileEntityFurnaceMixin"),
// endregion

// region Fast Leaf Decay
common_FastLeafDecay_BlockLeavesBaseMixin(COMMON, always(), "FastLeafDecay.BlockLeavesBaseMixin"),
// endregion
;

@Getter
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Blendtronic
*
* Copyright (C) 2021-2024 SirFell, the MEGA team
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package mega.blendtronic.modules.FastLeafDecay;

import mega.blendtronic.config.MinecraftConfig;

import net.minecraft.block.Block;
import net.minecraft.world.World;

import java.util.Random;

public class LeafDecayHelper {
private static final Random rng = new Random();
public static void handleLeafDecay(World world, int x, int y, int z, Block block) {
if (MinecraftConfig.FAST_LEAF_DECAY) {
world.scheduleBlockUpdate(x, y, z, block, MinecraftConfig.DECAY_SPEED + (MinecraftConfig.DECAY_FUZZ > 0 ? rng.nextInt(MinecraftConfig.DECAY_FUZZ) : 0));
}
}
}

0 comments on commit 9be8973

Please sign in to comment.