From b6a648fddf81f740573ffa443b559642a147c346 Mon Sep 17 00:00:00 2001 From: patience Date: Fri, 31 Jul 2026 01:09:15 +0100 Subject: [PATCH] Change potion throwing to chargeable Charging too long makes you accidentally drink your potion This also significantly increases how far you can throw potions. Doesn't quite match bows still though. --- .../mc_rebalance/mixin/PotionThrowRework.java | 54 ++++++++++++++++--- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/src/main/java/xyz/nearmisses/patience/mc_rebalance/mixin/PotionThrowRework.java b/src/main/java/xyz/nearmisses/patience/mc_rebalance/mixin/PotionThrowRework.java index e1c0ca8..e1432a2 100644 --- a/src/main/java/xyz/nearmisses/patience/mc_rebalance/mixin/PotionThrowRework.java +++ b/src/main/java/xyz/nearmisses/patience/mc_rebalance/mixin/PotionThrowRework.java @@ -1,12 +1,54 @@ package xyz.nearmisses.patience.mc_rebalance.mixin; -import net.minecraft.world.item.ThrowablePotionItem; +import net.minecraft.stats.Stats; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.projectile.ThrownPotion; +import net.minecraft.world.item.*; +import net.minecraft.world.level.Level; +import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.Constant; -import org.spongepowered.asm.mixin.injection.ModifyConstant; +import org.spongepowered.asm.mixin.Overwrite; @Mixin(ThrowablePotionItem.class) -public class PotionThrowRework { - @ModifyConstant(method="use", constant = @Constant(floatValue = 0.5F)) - private float teachSteveToThrow(float constant){return constant*1.8F;} +public abstract class PotionThrowRework extends PotionItem implements ProjectileItem { + public PotionThrowRework(Properties properties) { + super(properties); + } + + /** + * @author emeraldquartz + * @reason This fundamentally changes the way potions are managed in a way that can't be cleanly handled inside the original use() function. + */ + @Overwrite + public @NotNull InteractionResultHolder use(Level level, Player player, InteractionHand interactionHand) { + ItemStack itemStack = player.getItemInHand(interactionHand); + + player.startUsingItem(interactionHand); + return InteractionResultHolder.sidedSuccess(itemStack, level.isClientSide()); + } + + @Override + public void releaseUsing(ItemStack itemStack, Level level, LivingEntity livingEntity, int i){ + if( livingEntity instanceof Player player) { + if (!level.isClientSide) { + ThrownPotion thrownPotion = new ThrownPotion(level, player); + thrownPotion.setItem(itemStack); + i = Math.max(28-i, 4); + + thrownPotion.shootFromRotation(player, player.getXRot(), player.getYRot(), -20.0F, 0.04F*i, 1.0F); + level.addFreshEntity(thrownPotion); + } + + player.awardStat(Stats.ITEM_USED.get(this)); + itemStack.consume(1, player); + } + } + + @Override + public @NotNull UseAnim getUseAnimation(ItemStack itemStack) { + return UseAnim.BOW; + } }