正确处理无人机destroy事件

This commit is contained in:
Light_Quanta 2025-01-25 00:10:35 +08:00
parent 845e2f0123
commit 0b983f8b1d
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959

View file

@ -514,11 +514,37 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
@Override @Override
public void destroy() { public void destroy() {
// 无人机爆炸
if (level() instanceof ServerLevel) {
level().explode(null, this.getX(), this.getY(), this.getZ(), 0, Level.ExplosionInteraction.NONE);
}
// 神风自爆
if (this.entityData.get(KAMIKAZE_MODE) != 0) {
kamikazeExplosion(this.entityData.get(KAMIKAZE_MODE));
}
// RGO投弹
ItemStack rgoGrenade = new ItemStack(ModItems.RGO_GRENADE.get(), this.entityData.get(AMMO));
if (this.level() instanceof ServerLevel level) {
ItemEntity itemEntity = new ItemEntity(level, this.getX(), this.getY(), this.getZ(), rgoGrenade);
itemEntity.setPickUpDelay(10);
level.addFreshEntity(itemEntity);
}
Player controller = EntityFindUtil.findPlayer(this.level(), this.entityData.get(CONTROLLER));
if (controller != null) {
if (controller.getMainHandItem().is(ModItems.MONITOR.get())) {
Monitor.disLink(controller.getMainHandItem(), controller);
}
}
String id = this.entityData.get(CONTROLLER); String id = this.entityData.get(CONTROLLER);
UUID uuid; UUID uuid;
try { try {
uuid = UUID.fromString(id); uuid = UUID.fromString(id);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException ignored) {
this.discard();
return; return;
} }
@ -532,28 +558,6 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
}); });
} }
Player controller = EntityFindUtil.findPlayer(this.level(), this.entityData.get(CONTROLLER));
if (controller != null) {
if (controller.getMainHandItem().is(ModItems.MONITOR.get())) {
Monitor.disLink(controller.getMainHandItem(), controller);
}
}
if (this.entityData.get(KAMIKAZE_MODE) != 0) {
kamikazeExplosion(this.entityData.get(KAMIKAZE_MODE));
}
ItemStack stack = new ItemStack(ModItems.RGO_GRENADE.get(), this.entityData.get(AMMO));
if (this.level() instanceof ServerLevel level) {
ItemEntity itemEntity = new ItemEntity(level, this.getX(), this.getY(), this.getZ(), stack);
itemEntity.setPickUpDelay(10);
level.addFreshEntity(itemEntity);
}
if (level() instanceof ServerLevel) {
level().explode(null, this.getX(), this.getY(), this.getZ(), 0, Level.ExplosionInteraction.NONE);
}
this.discard(); this.discard();
} }