|
| 1 | +package org.teneted.neotenet.mixin.world.entity.boss.enderdragon; |
| 2 | + |
| 3 | +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; |
| 4 | +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; |
| 5 | +import com.llamalad7.mixinextras.sugar.Cancellable; |
| 6 | +import com.llamalad7.mixinextras.sugar.Local; |
| 7 | +import net.minecraft.core.BlockPos; |
| 8 | +import net.minecraft.world.damagesource.DamageSource; |
| 9 | +import net.minecraft.world.entity.Entity; |
| 10 | +import net.minecraft.world.entity.EntityType; |
| 11 | +import net.minecraft.world.entity.boss.enderdragon.EndCrystal; |
| 12 | +import net.minecraft.world.level.Explosion; |
| 13 | +import net.minecraft.world.level.ExplosionDamageCalculator; |
| 14 | +import net.minecraft.world.level.Level; |
| 15 | +import net.minecraft.world.level.block.state.BlockState; |
| 16 | +import org.bukkit.craftbukkit.event.CraftEventFactory; |
| 17 | +import org.bukkit.event.entity.EntityRemoveEvent; |
| 18 | +import org.bukkit.event.entity.ExplosionPrimeEvent; |
| 19 | +import org.spongepowered.asm.mixin.Mixin; |
| 20 | +import org.spongepowered.asm.mixin.injection.At; |
| 21 | +import org.spongepowered.asm.mixin.injection.Redirect; |
| 22 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; |
| 23 | + |
| 24 | +@Mixin(EndCrystal.class) |
| 25 | +public abstract class MixinEndCrystal extends Entity { |
| 26 | + |
| 27 | + public MixinEndCrystal(EntityType<?> p_19870_, Level p_19871_) { |
| 28 | + super(p_19870_, p_19871_); |
| 29 | + } |
| 30 | + |
| 31 | + @WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z")) |
| 32 | + private boolean neotenet$callBlockIgniteEvent(Level instance, BlockPos p_46598_, BlockState p_46599_, Operation<Boolean> original) { |
| 33 | + if (!CraftEventFactory.callBlockIgniteEvent(instance, p_46598_, ((EndCrystal) (Object) this)).isCancelled()) { |
| 34 | + return original.call(instance, p_46598_, p_46599_); |
| 35 | + } else { |
| 36 | + return false; |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + @Redirect(method = "hurt", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/boss/enderdragon/EndCrystal;remove(Lnet/minecraft/world/entity/Entity$RemovalReason;)V")) |
| 41 | + private void neotenet$handleNonLivingEntityDamageEvent(EndCrystal instance, Entity.RemovalReason removalReason, @Local(argsOnly = true) DamageSource p_31050_, @Local(argsOnly = true) float p_31051_, @Cancellable CallbackInfoReturnable<Boolean> cir) { |
| 42 | + // CraftBukkit start - All non-living entities need this |
| 43 | + if (CraftEventFactory.handleNonLivingEntityDamageEvent(instance, p_31050_, p_31051_, false)) { |
| 44 | + cir.setReturnValue(false); |
| 45 | + } |
| 46 | + // CraftBukkit end |
| 47 | + } |
| 48 | + |
| 49 | + @Redirect(method = "hurt", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;explode(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Lnet/minecraft/world/level/ExplosionDamageCalculator;DDDFZLnet/minecraft/world/level/Level$ExplosionInteraction;)Lnet/minecraft/world/level/Explosion;")) |
| 50 | + private Explosion neotenet$callExplosionPrimeEvent(Level instance, Entity p_256145_, DamageSource p_256004_, ExplosionDamageCalculator p_255696_, double p_256208_, double p_256036_, double p_255746_, float p_256647_, boolean p_256098_, Level.ExplosionInteraction p_256104_, @Cancellable CallbackInfoReturnable<Boolean> cir) { |
| 51 | + // CraftBukkit start |
| 52 | + ExplosionPrimeEvent event = CraftEventFactory.callExplosionPrimeEvent(this, 6.0F, false); |
| 53 | + if (event.isCancelled()) { |
| 54 | + cir.setReturnValue(false); |
| 55 | + } |
| 56 | + |
| 57 | + this.remove(Entity.RemovalReason.KILLED, EntityRemoveEvent.Cause.EXPLODE); // CraftBukkit - add Bukkit remove cause |
| 58 | + return this.level().explode(this, p_256004_, (ExplosionDamageCalculator) null, this.getX(), this.getY(), this.getZ(), event.getRadius(), event.getFire(), Level.ExplosionInteraction.BLOCK); |
| 59 | + } |
| 60 | +} |
0 commit comments