Skip to content

Commit

Permalink
fix #173
Browse files Browse the repository at this point in the history
  • Loading branch information
MoriyaShiine committed Apr 8, 2024
1 parent 807e665 commit 20306d8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected void onBlockHit(BlockHitResult blockHitResult) {
}
}
}
if (getOwner() instanceof PlayerEntity) {
if (getOwner() instanceof PlayerEntity player && !player.isCreative()) {
dropStack(asItemStack(), 0.1F);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,24 @@
import moriyashiine.enchancement.common.init.ModEnchantments;
import moriyashiine.enchancement.common.util.EnchancementUtil;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemConvertible;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.function.Predicate;

@Mixin(PlayerEntity.class)
public class PlayerEntityMixin {
@Unique
private static boolean torch = false;

@ModifyVariable(method = "getProjectileType", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/item/RangedWeaponItem;getHeldProjectiles()Ljava/util/function/Predicate;"))
private Predicate<ItemStack> enchancement$torchHeld(Predicate<ItemStack> value, ItemStack stack) {
if (EnchancementUtil.hasEnchantment(ModEnchantments.TORCH, stack)) {
Expand All @@ -32,4 +40,17 @@ public class PlayerEntityMixin {
}
return value;
}

@Inject(method = "getProjectileType", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;<init>(Lnet/minecraft/item/ItemConvertible;)V"))
private void enchancement$torch(ItemStack stack, CallbackInfoReturnable<ItemStack> cir) {
torch = EnchancementUtil.hasEnchantment(ModEnchantments.TORCH, stack);
}

@ModifyArg(method = "getProjectileType", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;<init>(Lnet/minecraft/item/ItemConvertible;)V"))
private ItemConvertible enchancement$torch(ItemConvertible value) {
if (torch) {
return Items.TORCH;
}
return value;
}
}

0 comments on commit 20306d8

Please sign in to comment.