diff --git a/src/main/java/com/atsuishio/superbwarfare/client/renderer/entity/DroneRenderer.java b/src/main/java/com/atsuishio/superbwarfare/client/renderer/entity/DroneRenderer.java index c812384fb..fd5b936ce 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/renderer/entity/DroneRenderer.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/renderer/entity/DroneRenderer.java @@ -115,6 +115,7 @@ public class DroneRenderer extends GeoEntityRenderer { private String entityNameCache = ""; private Entity entityCache = null; + private int attachedTick = Integer.MAX_VALUE; // 统一渲染挂载实体 private void renderAttachments(DroneEntity entity, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource buffer, int packedLight) { @@ -131,9 +132,17 @@ public class DroneRenderer extends GeoEntityRenderer { .orElse(null); if (renderEntity == null) return; + // 填充tag + var tag = entity.getEntityData().get(ATTACHED_ENTITY_TAG); + if (!tag.isEmpty()) { + renderEntity.load(tag); + } + entityNameCache = attached; entityCache = renderEntity; + attachedTick = entity.tickCount; } + renderEntity.tickCount = entity.tickCount - attachedTick; var displayData = entity.getEntityData().get(ATTACHMENT_DISPLAY); diff --git a/src/main/java/com/atsuishio/superbwarfare/data/drone_attachment/DroneAttachmentData.java b/src/main/java/com/atsuishio/superbwarfare/data/drone_attachment/DroneAttachmentData.java index e854eeffe..705bad31d 100644 --- a/src/main/java/com/atsuishio/superbwarfare/data/drone_attachment/DroneAttachmentData.java +++ b/src/main/java/com/atsuishio/superbwarfare/data/drone_attachment/DroneAttachmentData.java @@ -20,7 +20,7 @@ public class DroneAttachmentData implements IDBasedData { private int count = 1; public int count() { - return Math.min(1, this.count); + return isKamikaze ? 1 : Math.max(1, this.count); } @SerializedName("IsKamikaze") @@ -35,6 +35,12 @@ public class DroneAttachmentData implements IDBasedData { @SerializedName("ExplosionRadius") public float explosionRadius = 0; + /** + * 投弹时需要写入的实体数据 + */ + @SerializedName("DropData") + public JsonObject dropData; + // TODO 其他挂载设置 // display settings @@ -60,6 +66,9 @@ public class DroneAttachmentData implements IDBasedData { return (this.rotation != null && this.rotation.length < 3) ? new float[]{0, 0, 0} : this.rotation; } - @SerializedName("Data") - public JsonObject data; + /** + * 无人机显示的挂载实体的实体数据 + */ + @SerializedName("DisplayData") + public JsonObject displayData; } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/DroneEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/DroneEntity.java index 7f7e0f727..2ce80c194 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/DroneEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/DroneEntity.java @@ -7,10 +7,7 @@ import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.item.Monitor; import com.atsuishio.superbwarfare.item.common.ammo.MortarShell; -import com.atsuishio.superbwarfare.tools.CustomExplosion; -import com.atsuishio.superbwarfare.tools.EntityFindUtil; -import com.atsuishio.superbwarfare.tools.NBTTool; -import com.atsuishio.superbwarfare.tools.ParticleTool; +import com.atsuishio.superbwarfare.tools.*; import net.minecraft.ChatFormatting; import net.minecraft.core.component.DataComponents; import net.minecraft.core.registries.Registries; @@ -69,6 +66,7 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity { // scale[3], offset[3], rotation[3] public static final EntityDataAccessor> ATTACHMENT_DISPLAY = SynchedEntityData.defineId(DroneEntity.class, ModSerializers.FLOAT_LIST_SERIALIZER.get()); + public static final EntityDataAccessor ATTACHED_ENTITY_TAG = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.COMPOUND_TAG); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); @@ -109,7 +107,8 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity { .define(LINKED, false) .define(KAMIKAZE_MODE, 0) .define(ATTACHED_ENTITY, "") - .define(ATTACHMENT_DISPLAY, List.of(1f, 1f, 1f, 0f, 0f, 0f, 0f, 0f, 0f)); + .define(ATTACHMENT_DISPLAY, List.of(1f, 1f, 1f, 0f, 0f, 0f, 0f, 0f, 0f)) + .define(ATTACHED_ENTITY_TAG, new CompoundTag()); } @Override @@ -381,7 +380,7 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity { // 不同种物品挂载 this.entityData.set(ATTACHED_ENTITY, attachmentData.entityID); // TODO 正确处理和渲染AMMO -// this.entityData.set(AMMO, this.entityData.get(AMMO) + 1); + this.entityData.set(AMMO, this.entityData.get(AMMO) + 1); if (!player.isCreative()) { stack.shrink(1); @@ -394,6 +393,11 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity { var offset = attachmentData.offset(); var rotation = attachmentData.rotation(); + if (attachmentData.displayData != null) { + // TODO 数据替换 + this.entityData.set(ATTACHED_ENTITY_TAG, TagDataParser.parse(attachmentData.displayData)); + } + this.entityData.set(ATTACHMENT_DISPLAY, List.of(scale[0], scale[1], scale[2], offset[0], offset[1], offset[2], rotation[0], rotation[1], rotation[2])); } }