修改无人机被毁后的逻辑
This commit is contained in:
parent
9402c35894
commit
47cb60a213
1 changed files with 19 additions and 20 deletions
|
@ -47,6 +47,7 @@ import net.minecraft.world.phys.Vec3;
|
|||
import net.neoforged.neoforge.event.EventHooks;
|
||||
import net.neoforged.neoforge.items.ItemHandlerHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.joml.Math;
|
||||
import org.joml.Vector3f;
|
||||
import software.bernie.geckolib.animatable.GeoEntity;
|
||||
|
@ -238,14 +239,12 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
this.refreshDimensions();
|
||||
}
|
||||
|
||||
|
||||
private void droneDrop(Player player) {
|
||||
Level level = player.level();
|
||||
if (!level.isClientSide()) {
|
||||
RgoGrenadeEntity rgoGrenadeEntity = new RgoGrenadeEntity(player, level, 160);
|
||||
private void droneDrop(@Nullable Player player) {
|
||||
if (!this.level().isClientSide()) {
|
||||
RgoGrenadeEntity rgoGrenadeEntity = new RgoGrenadeEntity(player, this.level(), 160);
|
||||
rgoGrenadeEntity.setPos(this.getX(), this.getEyeY() - 0.09, this.getZ());
|
||||
rgoGrenadeEntity.droneShoot(this);
|
||||
level.addFreshEntity(rgoGrenadeEntity);
|
||||
this.level().addFreshEntity(rgoGrenadeEntity);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -515,6 +514,16 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
|
||||
@Override
|
||||
public void destroy() {
|
||||
Player controller = EntityFindUtil.findPlayer(this.level(), this.entityData.get(CONTROLLER));
|
||||
if (controller != null) {
|
||||
if (controller.getMainHandItem().is(ModItems.MONITOR.get())) {
|
||||
var item = controller.getMainHandItem();
|
||||
var tag = NBTTool.getTag(item);
|
||||
Monitor.disLink(tag, controller);
|
||||
NBTTool.saveTag(item, tag);
|
||||
}
|
||||
}
|
||||
|
||||
// 无人机爆炸
|
||||
if (level() instanceof ServerLevel) {
|
||||
level().explode(null, this.getX(), this.getY(), this.getZ(), 0, Level.ExplosionInteraction.NONE);
|
||||
|
@ -526,20 +535,10 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
}
|
||||
|
||||
// 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())) {
|
||||
var item = controller.getMainHandItem();
|
||||
var tag = NBTTool.getTag(item);
|
||||
Monitor.disLink(tag, controller);
|
||||
NBTTool.saveTag(item, tag);
|
||||
if (this.level() instanceof ServerLevel) {
|
||||
int count = this.entityData.get(AMMO);
|
||||
for (int i = 0; i < count; i++) {
|
||||
droneDrop(controller);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue