diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/DroneHudOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/DroneHudOverlay.java index 2e62bb954..ab8603165 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/DroneHudOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/DroneHudOverlay.java @@ -31,8 +31,7 @@ import javax.annotation.ParametersAreNonnullByDefault; import java.util.List; import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit; -import static com.atsuishio.superbwarfare.entity.vehicle.DroneEntity.AMMO; -import static com.atsuishio.superbwarfare.entity.vehicle.DroneEntity.KAMIKAZE_MODE; +import static com.atsuishio.superbwarfare.entity.vehicle.DroneEntity.*; @OnlyIn(Dist.CLIENT) public class DroneHudOverlay implements LayeredDraw.Layer { @@ -122,7 +121,7 @@ public class DroneHudOverlay implements LayeredDraw.Layer { if (entity.getEntityData().get(KAMIKAZE_MODE) == 0) { // 弹药 guiGraphics.drawString(mc.font, Component.translatable("tips.superbwarfare.drone.ammo") - .append(Component.literal(FormatTool.format1D(entity.getEntityData().get(AMMO), " / 6"))), + .append(Component.literal(entity.getEntityData().get(AMMO) + " / " + entity.getEntityData().get(MAX_AMMO))), w / 2 + 12, h / 2 - 37, -1, false); } else { // 神风 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 fd5b936ce..731cd1555 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 @@ -3,7 +3,6 @@ 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.projectile.RgoGrenadeEntity; import com.atsuishio.superbwarfare.entity.vehicle.DroneEntity; import com.atsuishio.superbwarfare.init.ModEntities; import com.atsuishio.superbwarfare.init.ModItems; @@ -68,43 +67,43 @@ public class DroneRenderer extends GeoEntityRenderer { 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(); - } +// 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); } @@ -119,7 +118,8 @@ public class DroneRenderer extends GeoEntityRenderer { // 统一渲染挂载实体 private void renderAttachments(DroneEntity entity, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource buffer, int packedLight) { - var attached = entity.getEntityData().get(ATTACHED_ENTITY); + var data = entity.getEntityData(); + var attached = data.get(ATTACHED_ENTITY); if (attached.isEmpty()) return; Entity renderEntity; @@ -133,7 +133,7 @@ public class DroneRenderer extends GeoEntityRenderer { if (renderEntity == null) return; // 填充tag - var tag = entity.getEntityData().get(ATTACHED_ENTITY_TAG); + var tag = data.get(ATTACHED_ENTITY_TAG); if (!tag.isEmpty()) { renderEntity.load(tag); } @@ -144,22 +144,45 @@ public class DroneRenderer extends GeoEntityRenderer { } renderEntity.tickCount = entity.tickCount - attachedTick; - var displayData = entity.getEntityData().get(ATTACHMENT_DISPLAY); + var displayData = data.get(ATTACHMENT_DISPLAY); var scale = new float[]{displayData.get(0), displayData.get(1), displayData.get(2)}; var offset = new float[]{displayData.get(3), displayData.get(4), displayData.get(5)}; var rotation = new float[]{displayData.get(6), displayData.get(7), displayData.get(8)}; + var xLength = displayData.get(9); + var yLength = displayData.get(10); - poseStack.pushPose(); - poseStack.translate(offset[0], offset[1], offset[2]); - poseStack.scale(scale[0], scale[1], scale[2]); - poseStack.mulPose(Axis.XP.rotationDegrees(rotation[0])); - poseStack.mulPose(Axis.YP.rotationDegrees(rotation[2])); - poseStack.mulPose(Axis.ZP.rotationDegrees(rotation[1])); + for (int i = 0; i < data.get(AMMO); i++) { + float x, z; + if (data.get(MAX_AMMO) == 1) { + // 神风或单个挂载 + x = 0; + z = 0; + } else { + // 投弹 + x = xLength / 2 * (i % 2 == 0 ? 1 : -1); - entityRenderDispatcher.render(renderEntity, 0, 0, 0, entityYaw, partialTicks, poseStack, buffer, packedLight); + var rows = data.get(MAX_AMMO) / 2; + var row = i / 2; + if (rows < 2) { + z = 0; + } else { + var rowLength = yLength / rows; + z = -yLength / 2 + rowLength * row; + } + } - poseStack.popPose(); + poseStack.pushPose(); + poseStack.translate(x + offset[0], offset[1], z + offset[2]); + poseStack.scale(scale[0], scale[1], scale[2]); + poseStack.mulPose(Axis.XP.rotationDegrees(rotation[0])); + poseStack.mulPose(Axis.YP.rotationDegrees(rotation[2])); + poseStack.mulPose(Axis.ZP.rotationDegrees(rotation[1])); + + entityRenderDispatcher.render(renderEntity, 0, 0, 0, entityYaw, partialTicks, poseStack, buffer, packedLight); + + poseStack.popPose(); + } } @Override 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 705bad31d..3d04e89b9 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 @@ -66,6 +66,12 @@ public class DroneAttachmentData implements IDBasedData { return (this.rotation != null && this.rotation.length < 3) ? new float[]{0, 0, 0} : this.rotation; } + @SerializedName("XLength") + public float xLength = 0.1f; + + @SerializedName("ZLength") + public float zLength = 0.35f; + /** * 无人机显示的挂载实体的实体数据 */ 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 2ce80c194..79b5c7637 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/DroneEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/DroneEntity.java @@ -64,9 +64,10 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity { public static final EntityDataAccessor DELTA_X_ROT = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor ATTACHED_ENTITY = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.STRING); - // scale[3], offset[3], rotation[3] + // scale[3], offset[3], rotation[3], xLength, zLength 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); + public static final EntityDataAccessor MAX_AMMO = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.INT); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); @@ -107,8 +108,9 @@ 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(ATTACHED_ENTITY_TAG, new CompoundTag()); + .define(ATTACHMENT_DISPLAY, List.of(1f, 1f, 1f, 0f, 0f, 0f, 0f, 0f, 0f, 0.2f, 0.5f)) + .define(ATTACHED_ENTITY_TAG, new CompoundTag()) + .define(MAX_AMMO, 1); } @Override @@ -398,7 +400,13 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity { 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])); + 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], + attachmentData.xLength, attachmentData.zLength) + ); + this.entityData.set(MAX_AMMO, attachmentData.count()); } }