修改无人机被毁后的逻辑
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.event.EventHooks;
|
||||||
import net.neoforged.neoforge.items.ItemHandlerHelper;
|
import net.neoforged.neoforge.items.ItemHandlerHelper;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.joml.Math;
|
import org.joml.Math;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
import software.bernie.geckolib.animatable.GeoEntity;
|
import software.bernie.geckolib.animatable.GeoEntity;
|
||||||
|
@ -238,14 +239,12 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
||||||
this.refreshDimensions();
|
this.refreshDimensions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void droneDrop(@Nullable Player player) {
|
||||||
private void droneDrop(Player player) {
|
if (!this.level().isClientSide()) {
|
||||||
Level level = player.level();
|
RgoGrenadeEntity rgoGrenadeEntity = new RgoGrenadeEntity(player, this.level(), 160);
|
||||||
if (!level.isClientSide()) {
|
|
||||||
RgoGrenadeEntity rgoGrenadeEntity = new RgoGrenadeEntity(player, level, 160);
|
|
||||||
rgoGrenadeEntity.setPos(this.getX(), this.getEyeY() - 0.09, this.getZ());
|
rgoGrenadeEntity.setPos(this.getX(), this.getEyeY() - 0.09, this.getZ());
|
||||||
rgoGrenadeEntity.droneShoot(this);
|
rgoGrenadeEntity.droneShoot(this);
|
||||||
level.addFreshEntity(rgoGrenadeEntity);
|
this.level().addFreshEntity(rgoGrenadeEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -515,6 +514,16 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy() {
|
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) {
|
if (level() instanceof ServerLevel) {
|
||||||
level().explode(null, this.getX(), this.getY(), this.getZ(), 0, Level.ExplosionInteraction.NONE);
|
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投弹
|
// RGO投弹
|
||||||
ItemStack rgoGrenade = new ItemStack(ModItems.RGO_GRENADE.get(), this.entityData.get(AMMO));
|
if (this.level() instanceof ServerLevel) {
|
||||||
if (this.level() instanceof ServerLevel level) {
|
int count = this.entityData.get(AMMO);
|
||||||
ItemEntity itemEntity = new ItemEntity(level, this.getX(), this.getY(), this.getZ(), rgoGrenade);
|
for (int i = 0; i < count; i++) {
|
||||||
itemEntity.setPickUpDelay(10);
|
droneDrop(controller);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue