增强BEAST效果

This commit is contained in:
Light_Quanta 2025-05-14 20:06:27 +08:00
parent 24d77c71ba
commit f48b8f5892
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
4 changed files with 62 additions and 1 deletions

View file

@ -0,0 +1,12 @@
package com.atsuishio.superbwarfare.entity.mixin;
import net.minecraft.world.entity.LivingEntity;
public interface BeastEntityKiller {
static BeastEntityKiller getInstance(LivingEntity entity) {
return (BeastEntityKiller) entity;
}
void sbw$kill();
}

View file

@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.item;
import com.atsuishio.superbwarfare.config.server.MiscConfig;
import com.atsuishio.superbwarfare.entity.DPSGeneratorEntity;
import com.atsuishio.superbwarfare.entity.TargetEntity;
import com.atsuishio.superbwarfare.entity.mixin.BeastEntityKiller;
import com.atsuishio.superbwarfare.init.ModDamageTypes;
import com.atsuishio.superbwarfare.init.ModEnumExtensions;
import com.atsuishio.superbwarfare.init.ModSounds;
@ -99,6 +100,7 @@ public class Beast extends SwordItem {
);
} else {
if (target instanceof LivingEntity living) {
BeastEntityKiller.getInstance(living).sbw$kill();
living.setHealth(0);
}
target.level().broadcastEntityEvent(target, (byte) 60);
@ -129,7 +131,7 @@ public class Beast extends SwordItem {
@Override
@ParametersAreNonnullByDefault
public boolean onEntitySwing(ItemStack stack, LivingEntity entity, InteractionHand hand) {
var target = TraceTool.findMeleeEntity(entity, 50);
var target = TraceTool.findMeleeEntity(entity, 51.4);
if (target != null) {
beastKill(entity, target);
}

View file

@ -0,0 +1,46 @@
package com.atsuishio.superbwarfare.mixins;
import com.atsuishio.superbwarfare.entity.mixin.BeastEntityKiller;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
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.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(LivingEntity.class)
public abstract class BeastMixin implements BeastEntityKiller {
@Unique
public boolean sbw$beastKilled = false;
@Override
public void sbw$kill() {
this.sbw$beastKilled = true;
}
@Inject(method = "isDeadOrDying", at = @At("HEAD"), cancellable = true, order = Integer.MAX_VALUE)
public void isDeadOrDying(CallbackInfoReturnable<Boolean> cir) {
if (this.sbw$beastKilled) {
cir.cancel();
cir.setReturnValue(true);
}
}
@Inject(method = "getHealth", at = @At("HEAD"), cancellable = true, order = Integer.MAX_VALUE)
public void getHealth(CallbackInfoReturnable<Float> cir) {
if (this.sbw$beastKilled) {
cir.cancel();
cir.setReturnValue(0f);
}
}
@Inject(method = "remove", at = @At("RETURN"), order = Integer.MAX_VALUE)
public void onRemove(Entity.RemovalReason reason, CallbackInfo ci) {
if (this.sbw$beastKilled) {
((LivingEntity) (Object) this).setRemoved(reason);
}
}
}

View file

@ -4,6 +4,7 @@
"compatibilityLevel": "JAVA_21",
"refmap": "mixins.superbwarfare.refmap.json",
"mixins": [
"BeastMixin",
"ClientboundSetPassengersPacketMixin",
"EntityMixin",
"FishingHookMixin",