正确持久化无人机数据
This commit is contained in:
parent
bf5900d1e0
commit
53f998d5ae
3 changed files with 20 additions and 53 deletions
|
@ -118,7 +118,7 @@ public class DroneHudOverlay implements LayeredDraw.Layer {
|
|||
guiGraphics.drawString(mc.font, Component.translatable("tips.superbwarfare.drone.health")
|
||||
.append(Component.literal(FormatTool.format1D(entity.getHealth()) + " / " + FormatTool.format1D(entity.getMaxHealth()))),
|
||||
w / 2 - 77, h / 2 + 33, -1, false);
|
||||
if (entity.getEntityData().get(KAMIKAZE_MODE) == 0) {
|
||||
if (!entity.getEntityData().get(IS_KAMIKAZE)) {
|
||||
// 弹药
|
||||
guiGraphics.drawString(mc.font, Component.translatable("tips.superbwarfare.drone.ammo")
|
||||
.append(Component.literal(entity.getEntityData().get(AMMO) + " / " + entity.getEntityData().get(MAX_AMMO))),
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
package com.atsuishio.superbwarfare.client.renderer.entity;
|
||||
|
||||
import com.atsuishio.superbwarfare.client.model.entity.DroneModel;
|
||||
import com.atsuishio.superbwarfare.entity.projectile.MortarShellEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.DroneEntity;
|
||||
import com.atsuishio.superbwarfare.init.ModEntities;
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
|
||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
||||
|
@ -62,49 +60,6 @@ public class DroneRenderer extends GeoEntityRenderer<DroneEntity> {
|
|||
DroneEntity drone = EntityFindUtil.findDrone(player.level(), tag.getString("LinkedDrone"));
|
||||
|
||||
if (!(stack.is(ModItems.MONITOR.get()) && tag.getBoolean("Using") && tag.getBoolean("Linked") && drone != null && drone.getUUID() == entityIn.getUUID())) {
|
||||
if (entityIn.getEntityData().get(KAMIKAZE_MODE) == 1) {
|
||||
Entity entity = new MortarShellEntity(ModEntities.MORTAR_SHELL.get(), entityIn.level());
|
||||
entityRenderDispatcher.render(entity, 0, 0.03, 0.25, entityYaw, partialTicks, poseStack, bufferIn, packedLightIn);
|
||||
}
|
||||
|
||||
// for (int i = 0; i < entityIn.getEntityData().get(AMMO); i++) {
|
||||
// double yOffset = 0;
|
||||
// double xOffset = 0;
|
||||
//
|
||||
// if (i == 0) {
|
||||
// yOffset = 0.2;
|
||||
// xOffset = 0.1;
|
||||
// }
|
||||
// if (i == 1) {
|
||||
// yOffset = 0.2;
|
||||
// xOffset = -0.1;
|
||||
// }
|
||||
// if (i == 2) {
|
||||
// yOffset = -0.05;
|
||||
// xOffset = 0.1;
|
||||
// }
|
||||
// if (i == 3) {
|
||||
// yOffset = -0.05;
|
||||
// xOffset = -0.1;
|
||||
// }
|
||||
// if (i == 4) {
|
||||
// yOffset = -0.3;
|
||||
// xOffset = 0.1;
|
||||
// }
|
||||
// if (i == 5) {
|
||||
// yOffset = -0.3;
|
||||
// xOffset = -0.1;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// poseStack.pushPose();
|
||||
// poseStack.mulPose(Axis.XP.rotationDegrees(90));
|
||||
// poseStack.scale(0.35f, 0.35f, 0.35f);
|
||||
// Entity entity = new RgoGrenadeEntity(ModEntities.RGO_GRENADE.get(), entityIn.level());
|
||||
// entityRenderDispatcher.render(entity, xOffset, yOffset, 0, entityYaw, partialTicks, poseStack, bufferIn, packedLightIn);
|
||||
// poseStack.popPose();
|
||||
// }
|
||||
|
||||
renderAttachments(entityIn, entityYaw, partialTicks, poseStack, bufferIn, packedLightIn);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,12 +55,13 @@ import software.bernie.geckolib.animation.AnimatableManager;
|
|||
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
||||
|
||||
public static final EntityDataAccessor<Boolean> LINKED = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.BOOLEAN);
|
||||
public static final EntityDataAccessor<String> CONTROLLER = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.STRING);
|
||||
public static final EntityDataAccessor<Integer> KAMIKAZE_MODE = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.INT);
|
||||
public static final EntityDataAccessor<Boolean> IS_KAMIKAZE = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.BOOLEAN);
|
||||
public static final EntityDataAccessor<Float> DELTA_X_ROT = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.FLOAT);
|
||||
public static final EntityDataAccessor<String> DISPLAY_ENTITY = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.STRING);
|
||||
public static final EntityDataAccessor<CompoundTag> DISPLAY_ENTITY_TAG = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.COMPOUND_TAG);
|
||||
|
@ -108,7 +109,7 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
builder.define(DELTA_X_ROT, 0f)
|
||||
.define(CONTROLLER, "undefined")
|
||||
.define(LINKED, false)
|
||||
.define(KAMIKAZE_MODE, 0)
|
||||
.define(IS_KAMIKAZE, false)
|
||||
.define(DISPLAY_ENTITY, "")
|
||||
.define(DISPLAY_DATA, List.of(
|
||||
data.scale()[0], data.scale()[1], data.scale()[2],
|
||||
|
@ -142,7 +143,11 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
compound.putBoolean("Linked", this.entityData.get(LINKED));
|
||||
compound.putString("Controller", this.entityData.get(CONTROLLER));
|
||||
compound.putInt("Ammo", this.entityData.get(AMMO));
|
||||
compound.putInt("KamikazeMode", this.entityData.get(KAMIKAZE_MODE));
|
||||
compound.putBoolean("KamikazeMode", this.entityData.get(IS_KAMIKAZE));
|
||||
compound.putInt("MaxAmmo", this.entityData.get(MAX_AMMO));
|
||||
compound.putString("DisplayEntity", this.entityData.get(DISPLAY_ENTITY));
|
||||
compound.putString("DisplayEntityTag", this.entityData.get(DISPLAY_ENTITY_TAG).toString());
|
||||
compound.putString("DisplayData", this.entityData.get(DISPLAY_DATA).stream().map(Object::toString).collect(Collectors.joining(",")));
|
||||
|
||||
CompoundTag item = new CompoundTag();
|
||||
if (!item.isEmpty()) {
|
||||
|
@ -161,10 +166,18 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
if (compound.contains("Ammo"))
|
||||
this.entityData.set(AMMO, compound.getInt("Ammo"));
|
||||
if (compound.contains("KamikazeMode"))
|
||||
this.entityData.set(KAMIKAZE_MODE, compound.getInt("KamikazeMode"));
|
||||
this.entityData.set(IS_KAMIKAZE, compound.getBoolean("KamikazeMode"));
|
||||
if (compound.contains("Item"))
|
||||
this.currentItem = ItemStack.parse(level().registryAccess(), compound.getCompound("Item"))
|
||||
.orElse(ItemStack.EMPTY);
|
||||
if (compound.contains("MaxAmmo"))
|
||||
this.entityData.set(MAX_AMMO, compound.getInt("MaxAmmo"));
|
||||
if (compound.contains("DisplayEntity"))
|
||||
this.entityData.set(DISPLAY_ENTITY, compound.getString("DisplayEntity"));
|
||||
if (compound.contains("DisplayEntityTag"))
|
||||
this.entityData.set(DISPLAY_ENTITY_TAG, compound.getCompound("DisplayEntityTag"));
|
||||
if (compound.contains("DisplayData"))
|
||||
this.entityData.set(DISPLAY_DATA, Arrays.stream(compound.getString("DisplayData").split(",")).map(Float::valueOf).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -226,7 +239,7 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
droneDrop(controller);
|
||||
}
|
||||
}
|
||||
if (this.entityData.get(KAMIKAZE_MODE) != 0) {
|
||||
if (!this.entityData.get(DISPLAY_ENTITY).isEmpty()) {
|
||||
if (controller != null) {
|
||||
var stack = controller.getMainHandItem();
|
||||
if (stack.is(ModItems.MONITOR.get())) {
|
||||
|
@ -538,7 +551,7 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
NBTTool.saveTag(stack, tag);
|
||||
}
|
||||
}
|
||||
this.hurt(new DamageSource(level().registryAccess().registryOrThrow(Registries.DAMAGE_TYPE).getHolderOrThrow(DamageTypes.EXPLOSION), Objects.requireNonNullElse(player, this)), (float) (((this.entityData.get(KAMIKAZE_MODE) != 0) ? 20 : 4) * lastTickSpeed));
|
||||
this.hurt(new DamageSource(level().registryAccess().registryOrThrow(Registries.DAMAGE_TYPE).getHolderOrThrow(DamageTypes.EXPLOSION), Objects.requireNonNullElse(player, this)), (float) ((!this.entityData.get(DISPLAY_ENTITY).isEmpty() ? 20 : 4) * lastTickSpeed));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -609,7 +622,6 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
|||
if (data.isKamikaze) {
|
||||
kamikazeExplosion();
|
||||
} else {
|
||||
// TODO 清理 RGO投弹
|
||||
if (this.level() instanceof ServerLevel) {
|
||||
int count = this.entityData.get(AMMO);
|
||||
for (int i = 0; i < count; i++) {
|
||||
|
|
Loading…
Add table
Reference in a new issue