From e117a7e25c94794d395270fb35efd815ce7eac20 Mon Sep 17 00:00:00 2001 From: Wynd Date: Tue, 24 Dec 2024 00:57:16 +0200 Subject: [PATCH] Config option for apples dropping from leaves --- .../xyz/pixelatedw/finalbeta/ModConfig.java | 2 ++ .../xyz/pixelatedw/finalbeta/WyHelper.java | 2 +- .../finalbeta/mixin/LeavesTileMixin.java | 27 +++++++++++++++++++ .../mixin/ResourceDownloadThreadMixin.java | 10 ++++--- src/main/resources/finalbeta.mixins.json | 3 ++- 5 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 src/main/java/xyz/pixelatedw/finalbeta/mixin/LeavesTileMixin.java diff --git a/src/main/java/xyz/pixelatedw/finalbeta/ModConfig.java b/src/main/java/xyz/pixelatedw/finalbeta/ModConfig.java index c013e52..d47c5ed 100644 --- a/src/main/java/xyz/pixelatedw/finalbeta/ModConfig.java +++ b/src/main/java/xyz/pixelatedw/finalbeta/ModConfig.java @@ -54,6 +54,8 @@ public class ModConfig { "Allows crafting coal and redstone as blocks for better storage"); public static final Option DISABLE_EATING_WHEN_MAX_HP = make("Disable eating when at max HP", false, "Makes it so players can no longer eat if they're at max HP so they don't accidently waste food"); + public static final Option APPLE_DROP_RATE = make("Apple Drop Rate", 0.0, + "Chance for apples to drop from leaves (decimal between 0.0 and 1.0)"); public static final Option FIX_BOW_MODEL = make("Fix bow model", true, "Makes the box model held by players and skeletons bigger and facing forward"); diff --git a/src/main/java/xyz/pixelatedw/finalbeta/WyHelper.java b/src/main/java/xyz/pixelatedw/finalbeta/WyHelper.java index 24fa2b5..e7cd69a 100644 --- a/src/main/java/xyz/pixelatedw/finalbeta/WyHelper.java +++ b/src/main/java/xyz/pixelatedw/finalbeta/WyHelper.java @@ -115,7 +115,7 @@ public class WyHelper { // player.dropItem(new ItemInstance(Tile.SLAB, 64)); // player.dropItem(new ItemInstance(ItemType.minecart, 1)); // player.dropItem(new ItemInstance(ItemType.minecartFurnace, 1)); - player.dropItem(new ItemInstance(ItemType.bow, 1)); + player.dropItem(new ItemInstance(ItemType.flintAndSteel, 1)); // player.dropItem(new ItemInstance(Tile.GOLDEN_RAIL, 64)); // player.dropItem(new ItemInstance(Tile.COBBLESTONE, 64)); diff --git a/src/main/java/xyz/pixelatedw/finalbeta/mixin/LeavesTileMixin.java b/src/main/java/xyz/pixelatedw/finalbeta/mixin/LeavesTileMixin.java new file mode 100644 index 0000000..bd5e6fb --- /dev/null +++ b/src/main/java/xyz/pixelatedw/finalbeta/mixin/LeavesTileMixin.java @@ -0,0 +1,27 @@ +package xyz.pixelatedw.finalbeta.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.entity.ItemEntity; +import net.minecraft.entity.player.Player; +import net.minecraft.item.ItemInstance; +import net.minecraft.item.ItemType; +import net.minecraft.level.Level; +import net.minecraft.tile.LeavesTile; +import xyz.pixelatedw.finalbeta.ModConfig; + +@Mixin(LeavesTile.class) +public class LeavesTileMixin { + @Inject(method = "afterBreak", at = @At(value = "INVOKE", target = "Lnet/minecraft/tile/FancyTile;afterBreak(Lnet/minecraft/level/Level;Lnet/minecraft/entity/player/Player;IIII)V")) + public void afterBreak(Level level, Player player, int x, int y, int z, int meta, CallbackInfo ci) { + boolean dropItem = level.rand.nextDouble() <= ModConfig.APPLE_DROP_RATE.get(); + if (dropItem) { + ItemEntity appleItem = new ItemEntity(level, x + 0.5, y - 0.5, z + 0.5, new ItemInstance(ItemType.apple)); + appleItem.pickupDelay = 20; + level.spawnEntity(appleItem); + } + } +} diff --git a/src/main/java/xyz/pixelatedw/finalbeta/mixin/ResourceDownloadThreadMixin.java b/src/main/java/xyz/pixelatedw/finalbeta/mixin/ResourceDownloadThreadMixin.java index ff8942a..71f9fc9 100644 --- a/src/main/java/xyz/pixelatedw/finalbeta/mixin/ResourceDownloadThreadMixin.java +++ b/src/main/java/xyz/pixelatedw/finalbeta/mixin/ResourceDownloadThreadMixin.java @@ -1,6 +1,8 @@ package xyz.pixelatedw.finalbeta.mixin; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.Constant; +import org.spongepowered.asm.mixin.injection.ModifyConstant; import net.minecraft.client.util.ResourceDownloadThread; @@ -9,8 +11,8 @@ public class ResourceDownloadThreadMixin { private static final String RESOURCES_URL = "http://mcresources.modification-station.net/MinecraftResources/"; -// @ModifyConstant(method = "run", constant = @Constant(stringValue = "http://s3.amazonaws.com/MinecraftResources/"), remap = false) -// private String getResourcesUrl(String def) { -// return RESOURCES_URL; -// } + @ModifyConstant(method = "run", constant = @Constant(stringValue = "http://s3.amazonaws.com/MinecraftResources/"), remap = false) + private String getResourcesUrl(String def) { + return RESOURCES_URL; + } } \ No newline at end of file diff --git a/src/main/resources/finalbeta.mixins.json b/src/main/resources/finalbeta.mixins.json index d2e6b7e..a6af6fc 100644 --- a/src/main/resources/finalbeta.mixins.json +++ b/src/main/resources/finalbeta.mixins.json @@ -47,7 +47,8 @@ "RecipeRegistryAccessor", "FoodItemMixin", "ItemTypeAccessor", - "PressurePlateTileMixin" + "PressurePlateTileMixin", + "LeavesTileMixin" ], "injectors": { "defaultRequire": -1