Skip to content

Commit

Permalink
write down the damage of the helmet and reuse it instead of 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan-1F committed Jan 26, 2022
1 parent c9379ad commit a59635e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@

@Mixin(AbstractSkeletonEntity.class)
public class AbstractSkeletonEntityMixin {
private int damage;
@Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;setDamage(I)V", shift = At.Shift.BEFORE))
private void beforeDamagingHelmet(CallbackInfo ci) {
if (IvanCarpetAdditionSettings.unbreakableHelmetInSunlight) {
damage = ((AbstractSkeletonEntity) (Object) this).getEquippedStack(EquipmentSlot.HEAD).getDamage();
}
}
@Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;setDamage(I)V", shift = At.Shift.AFTER))
private void repairHelmet(CallbackInfo ci) {
private void afterDamagingHelmet(CallbackInfo ci) {
if (IvanCarpetAdditionSettings.unbreakableHelmetInSunlight) {
((AbstractSkeletonEntity) (Object) this).getEquippedStack(EquipmentSlot.HEAD).setDamage(0);
((AbstractSkeletonEntity) (Object) this).getEquippedStack(EquipmentSlot.HEAD).setDamage(damage);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@

@Mixin(ZombieEntity.class)
public class ZombieEntityMixin {
private int damage;
@Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;setDamage(I)V", shift = At.Shift.BEFORE))
private void beforeDamagingHelmet(CallbackInfo ci) {
if (IvanCarpetAdditionSettings.unbreakableHelmetInSunlight) {
damage = ((ZombieEntity) (Object) this).getEquippedStack(EquipmentSlot.HEAD).getDamage();
}
}
@Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;setDamage(I)V", shift = At.Shift.AFTER))
private void repairHelmet(CallbackInfo ci) {
private void afterDamagingHelmet(CallbackInfo ci) {
if (IvanCarpetAdditionSettings.unbreakableHelmetInSunlight) {
((ZombieEntity) (Object) this).getEquippedStack(EquipmentSlot.HEAD).setDamage(0);
((ZombieEntity) (Object) this).getEquippedStack(EquipmentSlot.HEAD).setDamage(damage);
}
}
}
3 changes: 2 additions & 1 deletion src/main/resources/ivan-carpet-addition.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"rule.endLightningRod.EndRodBlockMixin",
"rule.endLightningRod.TridentEntityAccessor",
"rule.undeadImmuneToSunlight.MobEntityMixin",
"rule.unbreakableHelmetInSunlight.ZombieEntityMixin"
"rule.unbreakableHelmetInSunlight.ZombieEntityMixin",
"rule.unbreakableHelmetInSunlight.AbstractSkeletonEntityMixin"
],
"client": [
],
Expand Down

0 comments on commit a59635e

Please sign in to comment.