Skip to content

Commit

Permalink
Merge pull request #20 from pajicadvance/mixin_update
Browse files Browse the repository at this point in the history
Mixin improvements
  • Loading branch information
ExDrill authored Oct 27, 2024
2 parents bd62ba8 + f7a4e06 commit 6387eb7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
package com.teamabode.guarding.core.mixin;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.teamabode.guarding.core.registry.GuardingItems;
import com.teamabode.guarding.core.registry.GuardingSounds;
import net.minecraft.stats.Stat;
import net.minecraft.stats.Stats;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemCooldowns;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -28,25 +22,9 @@ protected NetheriteShieldMixin(EntityType<? extends LivingEntity> entityType, Le
super(entityType, level);
}

@Shadow public abstract void awardStat(Stat<?> stat);

@Inject(method = "hurtCurrentlyUsedShield", at = @At("HEAD"), cancellable = true)
private void guarding$hurtCurrentlyUsedShield(float damageAmount, CallbackInfo ci) {
if (useItem.is(GuardingItems.NETHERITE_SHIELD)) {
if (!level().isClientSide) this.awardStat(Stats.ITEM_USED.get(useItem.getItem()));
if (damageAmount >= 3.0f) {
int damage = 1 + Mth.floor(damageAmount);
InteractionHand hand = this.getUsedItemHand();

useItem.hurtAndBreak(damage, this, getSlotForHand(hand));
if (useItem.isEmpty()) {
this.setItemSlot(hand == InteractionHand.MAIN_HAND ? EquipmentSlot.MAINHAND : EquipmentSlot.OFFHAND, ItemStack.EMPTY);
this.useItem = ItemStack.EMPTY;
this.playSound(GuardingSounds.ITEM_NETHERITE_SHIELD_BREAK, 0.8f, 0.8f + this.level().random.nextFloat() * 0.4f);
}
}
ci.cancel();
}
@ModifyExpressionValue(method = "hurtCurrentlyUsedShield", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;is(Lnet/minecraft/world/item/Item;)Z"))
private boolean guarding$hurtCurrentlyUsedShield(boolean original) {
return original || useItem.is(GuardingItems.NETHERITE_SHIELD);
}

@Inject(method = "disableShield", at = @At("HEAD"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ public abstract class NetheriteShieldSoundMixin {

@Shadow public abstract ItemStack getUseItem();

@Inject(method = "hurt", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;broadcastEntityEvent(Lnet/minecraft/world/entity/Entity;B)V", shift = At.Shift.BEFORE), cancellable = true)
@Inject(method = "hurt", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;broadcastEntityEvent(Lnet/minecraft/world/entity/Entity;B)V"))
private void guarding$hurt(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {
if (this.getUseItem().is(GuardingItems.NETHERITE_SHIELD)) {
LivingEntity livingEntity = LivingEntity.class.cast(this);
livingEntity.level().playSound(null, livingEntity.blockPosition(), GuardingSounds.ITEM_NETHERITE_SHIELD_BLOCK, SoundSource.NEUTRAL, 1.0f, 1.0f);
cir.cancel();
}
}
}

0 comments on commit 6387eb7

Please sign in to comment.