Skip to content

Commit

Permalink
[skip ci] Implement sapling behavior tweak, closes #300
Browse files Browse the repository at this point in the history
  • Loading branch information
ACGaming committed Dec 20, 2023
1 parent cc17c60 commit 09c43e4
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ All changes are toggleable via config files.
* **Remove Realms Button:** Removes the redundant Minecraft Realms button from the main menu
* **Remove Recipe Book:** Removes the recipe book button from GUIs
* **Remove Snooper:** Forcefully turns off the snooper and hides the snooper settings button from the options menu
* **Sapling Behavior:** Allows customization of sapling behavior while utilizing an optimized method
* **Sea Level:** Sets the default height of the overworld's sea level
* **Selected Item Tooltip Height:** Sets the Y value of the selected item tooltip, displayed when held items are changed
* **Shield Parry:** Allows parrying of projectiles with shields
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ org.gradle.jvmargs = -Xmx3G
maven_group = mod.acgaming
mod_id = universaltweaks
mod_name = Universal Tweaks
mod_version = 1.9.0
mod_version = 1.9.1
archives_base_name = UniversalTweaks-1.12.2

# If any properties changes below this line, run `gradlew setupDecompWorkspace` and refresh gradle again to ensure everything is working correctly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public static class BlocksCategory
@Config.Name("Finite Water")
public final FiniteWaterCategory FINITE_WATER = new FiniteWaterCategory();

@Config.LangKey("cfg.universaltweaks.tweaks.blocks.sapling")
@Config.Name("Sapling Behavior")
public final SaplingBehaviorCategory SAPLING_BEHAVIOR = new SaplingBehaviorCategory();

@Config.RequiresMcRestart
@Config.Name("Bed Obstruction Replacement")
@Config.Comment("Replaces bed obstruction checks with an improved version")
Expand Down Expand Up @@ -221,6 +225,27 @@ public static class FiniteWaterCategory
@Config.Comment("Inclusive maximum altitude at which water is infinite")
public int utFiniteWaterInfMax = 63;
}

public static class SaplingBehaviorCategory
{
@Config.RequiresMcRestart
@Config.Name("[1] Sapling Behavior Toggle")
@Config.Comment("Allows customization of sapling behavior while utilizing an optimized method")
public boolean utSaplingBehaviorToggle = true;

@Config.Name("[2] Minimum Light Level")
@Config.Comment("Inclusive minimum light level at which saplings grow into trees")
public int utSaplingLightLevel = 9;

@Config.Name("[3] Growth Chance")
@Config.Comment
({
"Chance per update tick at which saplings grow into trees",
"Note: General growth rate is still affected by the random tick speed"
})
@Config.RangeDouble(min = 0.0D, max = 1.0D)
public double utSaplingGrowthChance = 0.125D;
}
}

public static class EntitiesCategory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public List<String> getMixinConfigs()
configs.add("mixins.tweaks.blocks.hitdelay.json");
configs.add("mixins.tweaks.blocks.leafdecay.json");
configs.add("mixins.tweaks.blocks.lenientpaths.json");
configs.add("mixins.tweaks.blocks.sapling.json");
configs.add("mixins.tweaks.entities.ai.json");
configs.add("mixins.tweaks.entities.ai.saddledwandering.json");
configs.add("mixins.tweaks.entities.ai.wither.json");
Expand Down Expand Up @@ -370,6 +371,8 @@ public boolean shouldMixinConfigQueue(String mixinConfig)
return UTConfigTweaks.BLOCKS.utLeafDecayToggle;
case "mixins.tweaks.blocks.lenientpaths.json":
return UTConfigTweaks.BLOCKS.utLenientPathsToggle;
case "mixins.tweaks.blocks.sapling.json":
return UTConfigTweaks.BLOCKS.SAPLING_BEHAVIOR.utSaplingBehaviorToggle;
case "mixins.tweaks.entities.ai.json":
return UTConfigTweaks.ENTITIES.utAIReplacementToggle;
case "mixins.tweaks.entities.ai.saddledwandering.json":
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package mod.acgaming.universaltweaks.tweaks.blocks.sapling.mixin;

import java.util.Random;

import net.minecraft.block.BlockBush;
import net.minecraft.block.BlockSapling;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import mod.acgaming.universaltweaks.config.UTConfigTweaks;
import mod.acgaming.universaltweaks.util.UTRandomUtil;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(BlockSapling.class)
public abstract class UTSaplingMixin extends BlockBush
{
@Shadow
public abstract void grow(World worldIn, BlockPos pos, IBlockState state, Random rand);

/**
* @author ACGaming
* @reason Optimized + customizable sapling update tick
*/
@Overwrite
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
if (!worldIn.isRemote)
{
super.updateTick(worldIn, pos, state, rand);
if (worldIn.getLightFromNeighbors(pos.up()) >= UTConfigTweaks.BLOCKS.SAPLING_BEHAVIOR.utSaplingLightLevel && UTRandomUtil.chance(UTConfigTweaks.BLOCKS.SAPLING_BEHAVIOR.utSaplingGrowthChance) && worldIn.isAreaLoaded(pos, 1)) this.grow(worldIn, pos, state, rand);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Courtesy of UeberallGebannt
public class UTRandomUtil
{
public static final Random RANDOM = new Random();

/**
* Returns true with a certain chance
*
Expand All @@ -26,6 +28,6 @@ public static boolean chance(double chance, Random random)
*/
public static boolean chance(double chance)
{
return chance(chance, new Random());
return chance(chance, RANDOM);
}
}
1 change: 1 addition & 0 deletions src/main/resources/assets/universaltweaks/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ cfg.universaltweaks.tweaks.blocks.betterplacement=Better Placement
cfg.universaltweaks.tweaks.blocks.blockdispenser=Block Dispenser
cfg.universaltweaks.tweaks.blocks.breakablebedrock=Breakable Bedrock
cfg.universaltweaks.tweaks.blocks.finitewater=Finite Water
cfg.universaltweaks.tweaks.blocks.sapling=Sapling Behavior
cfg.universaltweaks.tweaks.entities.attributes=Attributes
cfg.universaltweaks.tweaks.entities.betterburning=Better Burning
cfg.universaltweaks.tweaks.entities.collisiondamage=Collision Damage
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/mixins.tweaks.blocks.sapling.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"package": "mod.acgaming.universaltweaks.tweaks.blocks.sapling.mixin",
"refmap": "universaltweaks.refmap.json",
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"mixins": ["UTSaplingMixin"]
}

0 comments on commit 09c43e4

Please sign in to comment.