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 0d6b47546..5601af63f 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 @@ -119,7 +119,7 @@ public class DroneRenderer extends GeoEntityRenderer { // 统一渲染挂载实体 private void renderAttachments(DroneEntity entity, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource buffer, int packedLight) { var data = entity.getEntityData(); - var attached = data.get(ATTACHED_ENTITY); + var attached = data.get(DISPLAY_ENTITY); if (attached.isEmpty()) return; Entity renderEntity; @@ -133,7 +133,7 @@ public class DroneRenderer extends GeoEntityRenderer { if (renderEntity == null) return; // 填充tag - var tag = data.get(ATTACHED_ENTITY_TAG); + var tag = data.get(DISPLAY_ENTITY_TAG); if (!tag.isEmpty()) { renderEntity.load(tag); } @@ -142,7 +142,7 @@ public class DroneRenderer extends GeoEntityRenderer { entityCache = renderEntity; attachedTick = entity.tickCount; } - var displayData = data.get(ATTACHMENT_DISPLAY); + var displayData = data.get(DISPLAY_DATA); renderEntity.tickCount = displayData.get(11) >= 0 ? displayData.get(11).intValue() : entity.tickCount - attachedTick; 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 4752c8fff..39db86c55 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 @@ -8,8 +8,40 @@ public class DroneAttachmentData implements IDBasedData { @SerializedName("ItemID") public String itemID = ""; - @SerializedName("EntityID") - public String entityID = ""; + @SerializedName("Entity") + private String entity = ""; + @SerializedName("DisplayEntity") + private String displayEntity = ""; + + @SerializedName("DropEntity") + private String dropEntity = ""; + + public String displayEntity() { + if (!this.entity.isEmpty()) { + return this.entity; + } + return this.displayEntity.isEmpty() ? this.dropEntity : this.displayEntity; + } + + public String dropEntity() { + if (!this.entity.isEmpty()) { + return this.entity; + } + return this.dropEntity.isEmpty() ? this.displayEntity : this.dropEntity; + } + + + /** + * 无人机显示的挂载实体的实体数据 + */ + @SerializedName("DisplayData") + public JsonObject displayData; + + /** + * 无人机投弹实体的实体数据 + */ + @SerializedName("DropData") + public JsonObject dropData; @Override public String getId() { @@ -35,12 +67,6 @@ public class DroneAttachmentData implements IDBasedData { @SerializedName("ExplosionRadius") public float explosionRadius = 0; - /** - * 投弹时需要写入的实体数据 - */ - @SerializedName("DropData") - public JsonObject dropData; - // TODO 其他挂载设置 // display settings @@ -74,10 +100,4 @@ public class DroneAttachmentData implements IDBasedData { @SerializedName("TickCount") public int tickCount = -1; - - /** - * 无人机显示的挂载实体的实体数据 - */ - @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 97ee789f0..1f56fd0f7 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/DroneEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/DroneEntity.java @@ -64,11 +64,11 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity { public static final EntityDataAccessor CONTROLLER = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.STRING); public static final EntityDataAccessor KAMIKAZE_MODE = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.INT); 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); + public static final EntityDataAccessor DISPLAY_ENTITY = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.STRING); + public static final EntityDataAccessor DISPLAY_ENTITY_TAG = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.COMPOUND_TAG); // scale[3], offset[3], rotation[3], xLength, zLength, tickCount - 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> DISPLAY_DATA = SynchedEntityData.defineId(DroneEntity.class, ModSerializers.FLOAT_LIST_SERIALIZER.get()); public static final EntityDataAccessor MAX_AMMO = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.INT); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); @@ -111,15 +111,15 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity { .define(CONTROLLER, "undefined") .define(LINKED, false) .define(KAMIKAZE_MODE, 0) - .define(ATTACHED_ENTITY, "") - .define(ATTACHMENT_DISPLAY, List.of( + .define(DISPLAY_ENTITY, "") + .define(DISPLAY_DATA, List.of( data.scale()[0], data.scale()[1], data.scale()[2], data.offset()[0], data.offset()[1], data.offset()[2], data.rotation()[0], data.rotation()[1], data.rotation()[2], data.xLength, data.zLength, (float) data.tickCount )) - .define(ATTACHED_ENTITY_TAG, new CompoundTag()) + .define(DISPLAY_ENTITY_TAG, new CompoundTag()) .define(MAX_AMMO, 1); } @@ -326,7 +326,7 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity { ItemHandlerHelper.giveItemToPlayer(player, this.currentItem.copy()); this.entityData.set(AMMO, ammo - 1); if (ammo == 1) { - this.entityData.set(ATTACHED_ENTITY, ""); + this.entityData.set(DISPLAY_ENTITY, ""); this.entityData.set(MAX_AMMO, 1); this.currentItem = ItemStack.EMPTY; } @@ -334,12 +334,12 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity { } } else { // 自定义挂载 - var itemID = stack.getItem().toString(); + var itemID = getItemId(stack); var attachmentData = CustomData.DRONE_ATTACHMENT.get(itemID); // 是否能挂载该物品 if (attachmentData != null && this.entityData.get(AMMO) < attachmentData.count()) { - if (this.entityData.get(ATTACHED_ENTITY).equals(attachmentData.entityID) + if (this.entityData.get(DISPLAY_ENTITY).equals(attachmentData.displayEntity()) && ItemStack.matches(this.currentItem, stack.copyWithCount(1)) ) { // 同种物品挂载 @@ -354,7 +354,7 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity { } else if (this.entityData.get(AMMO) == 0) { // 不同种物品挂载 this.currentItem = stack.copyWithCount(1); - this.entityData.set(ATTACHED_ENTITY, attachmentData.entityID); + this.entityData.set(DISPLAY_ENTITY, attachmentData.displayEntity()); // TODO 正确处理和渲染AMMO this.entityData.set(AMMO, this.entityData.get(AMMO) + 1); @@ -371,10 +371,10 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity { if (attachmentData.displayData != null) { // TODO 数据替换 - this.entityData.set(ATTACHED_ENTITY_TAG, TagDataParser.parse(attachmentData.displayData)); + this.entityData.set(DISPLAY_ENTITY_TAG, TagDataParser.parse(attachmentData.displayData)); } - this.entityData.set(ATTACHMENT_DISPLAY, List.of( + this.entityData.set(DISPLAY_DATA, List.of( scale[0], scale[1], scale[2], offset[0], offset[1], offset[2], rotation[0], rotation[1], rotation[2], @@ -488,11 +488,9 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity { public void hitEntityCrash(Player player, Entity target) { if (lastTickSpeed > 0.12) { - var attachedEntity = this.entityData.get(ATTACHED_ENTITY); + var attachedEntity = this.entityData.get(DISPLAY_ENTITY); if (!attachedEntity.isEmpty() && 20 * lastTickSpeed > this.getHealth()) { - var data = CustomData.DRONE_ATTACHMENT.values().stream().filter(d -> attachedEntity.equals(d.entityID)) - .findAny() - .orElse(null); + var data = CustomData.DRONE_ATTACHMENT.get(getItemId(this.currentItem)); if (data != null) { if (data.isKamikaze) { EntityType.byString(attachedEntity).ifPresent(entityType -> { @@ -557,6 +555,10 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity { } } + static String getItemId(ItemStack stack) { + return stack.getItem().toString(); + } + @Override public void destroy() { Player controller = EntityFindUtil.findPlayer(this.level(), this.entityData.get(CONTROLLER)); @@ -574,11 +576,7 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity { level().explode(null, this.getX(), this.getY(), this.getZ(), 0, Level.ExplosionInteraction.NONE); } - var attachedEntity = this.entityData.get(ATTACHED_ENTITY); - var data = CustomData.DRONE_ATTACHMENT.values().stream().filter(d -> attachedEntity.equals(d.entityID)) - .findAny() - .orElse(null); - + var data = CustomData.DRONE_ATTACHMENT.get(getItemId(this.currentItem)); if (data != null) { if (data.isKamikaze) { kamikazeExplosion(); @@ -625,12 +623,10 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity { CustomExplosion explosion; // 挂载实体的数据 - var attachedEntity = this.entityData.get(ATTACHED_ENTITY); + var attachedEntity = this.entityData.get(DISPLAY_ENTITY); if (attachedEntity.isEmpty()) return; - var data = CustomData.DRONE_ATTACHMENT.values().stream().filter(d -> attachedEntity.equals(d.entityID)) - .findAny() - .orElse(null); + var data = CustomData.DRONE_ATTACHMENT.get(getItemId(this.currentItem)); if (data == null) return; var bomb = EntityType.byString(attachedEntity).map(entityType -> diff --git a/src/main/resources/data/superbwarfare/drone_attachments/c4.json b/src/main/resources/data/superbwarfare/drone_attachments/c4.json index ec765a0a2..963bb689d 100644 --- a/src/main/resources/data/superbwarfare/drone_attachments/c4.json +++ b/src/main/resources/data/superbwarfare/drone_attachments/c4.json @@ -1,6 +1,6 @@ { "ItemID": "superbwarfare:c4_bomb", - "EntityID": "superbwarfare:c4", + "Entity": "superbwarfare:c4", "HitDamage": 150, "ExplosionDamage": 300, "ExplosionRadius": 10, diff --git a/src/main/resources/data/superbwarfare/drone_attachments/mortar.json b/src/main/resources/data/superbwarfare/drone_attachments/mortar.json index 7b1dcb279..73ad963bd 100644 --- a/src/main/resources/data/superbwarfare/drone_attachments/mortar.json +++ b/src/main/resources/data/superbwarfare/drone_attachments/mortar.json @@ -1,6 +1,6 @@ { "ItemID": "superbwarfare:mortar_shell", - "EntityID": "superbwarfare:mortar_shell", + "Entity": "superbwarfare:mortar_shell", "HitDamage": 200, "ExplosionDamage": 160, "ExplosionRadius": 9, diff --git a/src/main/resources/data/superbwarfare/drone_attachments/rgo.json b/src/main/resources/data/superbwarfare/drone_attachments/rgo.json index 1776a0783..845e8126c 100644 --- a/src/main/resources/data/superbwarfare/drone_attachments/rgo.json +++ b/src/main/resources/data/superbwarfare/drone_attachments/rgo.json @@ -1,6 +1,6 @@ { "ItemID": "superbwarfare:rgo_grenade", - "EntityID": "superbwarfare:rgo_grenade", + "Entity": "superbwarfare:rgo_grenade", "IsKamikaze": false, "Count": 6, "HitDamage": 270, diff --git a/src/main/resources/data/superbwarfare/drone_attachments/rpg.json b/src/main/resources/data/superbwarfare/drone_attachments/rpg.json index ce05682dc..a16104bb5 100644 --- a/src/main/resources/data/superbwarfare/drone_attachments/rpg.json +++ b/src/main/resources/data/superbwarfare/drone_attachments/rpg.json @@ -1,6 +1,6 @@ { "ItemID": "superbwarfare:rocket", - "EntityID": "superbwarfare:rpg_rocket", + "Entity": "superbwarfare:rpg_rocket", "HitDamage": 270, "ExplosionDamage": 130, "ExplosionRadius": 10,