优化部分参数命名和获取方式

This commit is contained in:
Light_Quanta 2025-07-03 14:24:38 +08:00
parent 24fb5c99aa
commit 5fc159ee3f
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
7 changed files with 62 additions and 46 deletions

View file

@ -119,7 +119,7 @@ public class DroneRenderer extends GeoEntityRenderer<DroneEntity> {
// 统一渲染挂载实体 // 统一渲染挂载实体
private void renderAttachments(DroneEntity entity, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource buffer, int packedLight) { private void renderAttachments(DroneEntity entity, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource buffer, int packedLight) {
var data = entity.getEntityData(); var data = entity.getEntityData();
var attached = data.get(ATTACHED_ENTITY); var attached = data.get(DISPLAY_ENTITY);
if (attached.isEmpty()) return; if (attached.isEmpty()) return;
Entity renderEntity; Entity renderEntity;
@ -133,7 +133,7 @@ public class DroneRenderer extends GeoEntityRenderer<DroneEntity> {
if (renderEntity == null) return; if (renderEntity == null) return;
// 填充tag // 填充tag
var tag = data.get(ATTACHED_ENTITY_TAG); var tag = data.get(DISPLAY_ENTITY_TAG);
if (!tag.isEmpty()) { if (!tag.isEmpty()) {
renderEntity.load(tag); renderEntity.load(tag);
} }
@ -142,7 +142,7 @@ public class DroneRenderer extends GeoEntityRenderer<DroneEntity> {
entityCache = renderEntity; entityCache = renderEntity;
attachedTick = entity.tickCount; 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; renderEntity.tickCount = displayData.get(11) >= 0 ? displayData.get(11).intValue() : entity.tickCount - attachedTick;

View file

@ -8,8 +8,40 @@ public class DroneAttachmentData implements IDBasedData {
@SerializedName("ItemID") @SerializedName("ItemID")
public String itemID = ""; public String itemID = "";
@SerializedName("EntityID") @SerializedName("Entity")
public String entityID = ""; 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 @Override
public String getId() { public String getId() {
@ -35,12 +67,6 @@ public class DroneAttachmentData implements IDBasedData {
@SerializedName("ExplosionRadius") @SerializedName("ExplosionRadius")
public float explosionRadius = 0; public float explosionRadius = 0;
/**
* 投弹时需要写入的实体数据
*/
@SerializedName("DropData")
public JsonObject dropData;
// TODO 其他挂载设置 // TODO 其他挂载设置
// display settings // display settings
@ -74,10 +100,4 @@ public class DroneAttachmentData implements IDBasedData {
@SerializedName("TickCount") @SerializedName("TickCount")
public int tickCount = -1; public int tickCount = -1;
/**
* 无人机显示的挂载实体的实体数据
*/
@SerializedName("DisplayData")
public JsonObject displayData;
} }

View file

@ -64,11 +64,11 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
public static final EntityDataAccessor<String> CONTROLLER = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.STRING); 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<Integer> KAMIKAZE_MODE = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Float> DELTA_X_ROT = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor<Float> DELTA_X_ROT = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<String> ATTACHED_ENTITY = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.STRING); 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);
// scale[3], offset[3], rotation[3], xLength, zLength, tickCount // scale[3], offset[3], rotation[3], xLength, zLength, tickCount
public static final EntityDataAccessor<List<Float>> ATTACHMENT_DISPLAY = SynchedEntityData.defineId(DroneEntity.class, ModSerializers.FLOAT_LIST_SERIALIZER.get()); public static final EntityDataAccessor<List<Float>> DISPLAY_DATA = SynchedEntityData.defineId(DroneEntity.class, ModSerializers.FLOAT_LIST_SERIALIZER.get());
public static final EntityDataAccessor<CompoundTag> ATTACHED_ENTITY_TAG = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.COMPOUND_TAG);
public static final EntityDataAccessor<Integer> MAX_AMMO = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.INT); public static final EntityDataAccessor<Integer> MAX_AMMO = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.INT);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
@ -111,15 +111,15 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
.define(CONTROLLER, "undefined") .define(CONTROLLER, "undefined")
.define(LINKED, false) .define(LINKED, false)
.define(KAMIKAZE_MODE, 0) .define(KAMIKAZE_MODE, 0)
.define(ATTACHED_ENTITY, "") .define(DISPLAY_ENTITY, "")
.define(ATTACHMENT_DISPLAY, List.of( .define(DISPLAY_DATA, List.of(
data.scale()[0], data.scale()[1], data.scale()[2], data.scale()[0], data.scale()[1], data.scale()[2],
data.offset()[0], data.offset()[1], data.offset()[2], data.offset()[0], data.offset()[1], data.offset()[2],
data.rotation()[0], data.rotation()[1], data.rotation()[2], data.rotation()[0], data.rotation()[1], data.rotation()[2],
data.xLength, data.zLength, data.xLength, data.zLength,
(float) data.tickCount (float) data.tickCount
)) ))
.define(ATTACHED_ENTITY_TAG, new CompoundTag()) .define(DISPLAY_ENTITY_TAG, new CompoundTag())
.define(MAX_AMMO, 1); .define(MAX_AMMO, 1);
} }
@ -326,7 +326,7 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
ItemHandlerHelper.giveItemToPlayer(player, this.currentItem.copy()); ItemHandlerHelper.giveItemToPlayer(player, this.currentItem.copy());
this.entityData.set(AMMO, ammo - 1); this.entityData.set(AMMO, ammo - 1);
if (ammo == 1) { if (ammo == 1) {
this.entityData.set(ATTACHED_ENTITY, ""); this.entityData.set(DISPLAY_ENTITY, "");
this.entityData.set(MAX_AMMO, 1); this.entityData.set(MAX_AMMO, 1);
this.currentItem = ItemStack.EMPTY; this.currentItem = ItemStack.EMPTY;
} }
@ -334,12 +334,12 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
} }
} else { } else {
// 自定义挂载 // 自定义挂载
var itemID = stack.getItem().toString(); var itemID = getItemId(stack);
var attachmentData = CustomData.DRONE_ATTACHMENT.get(itemID); var attachmentData = CustomData.DRONE_ATTACHMENT.get(itemID);
// 是否能挂载该物品 // 是否能挂载该物品
if (attachmentData != null && this.entityData.get(AMMO) < attachmentData.count()) { 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)) && 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) { } else if (this.entityData.get(AMMO) == 0) {
// 不同种物品挂载 // 不同种物品挂载
this.currentItem = stack.copyWithCount(1); this.currentItem = stack.copyWithCount(1);
this.entityData.set(ATTACHED_ENTITY, attachmentData.entityID); this.entityData.set(DISPLAY_ENTITY, attachmentData.displayEntity());
// TODO 正确处理和渲染AMMO // TODO 正确处理和渲染AMMO
this.entityData.set(AMMO, this.entityData.get(AMMO) + 1); this.entityData.set(AMMO, this.entityData.get(AMMO) + 1);
@ -371,10 +371,10 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
if (attachmentData.displayData != null) { if (attachmentData.displayData != null) {
// TODO 数据替换 // 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], scale[0], scale[1], scale[2],
offset[0], offset[1], offset[2], offset[0], offset[1], offset[2],
rotation[0], rotation[1], rotation[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) { public void hitEntityCrash(Player player, Entity target) {
if (lastTickSpeed > 0.12) { 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()) { if (!attachedEntity.isEmpty() && 20 * lastTickSpeed > this.getHealth()) {
var data = CustomData.DRONE_ATTACHMENT.values().stream().filter(d -> attachedEntity.equals(d.entityID)) var data = CustomData.DRONE_ATTACHMENT.get(getItemId(this.currentItem));
.findAny()
.orElse(null);
if (data != null) { if (data != null) {
if (data.isKamikaze) { if (data.isKamikaze) {
EntityType.byString(attachedEntity).ifPresent(entityType -> { 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 @Override
public void destroy() { public void destroy() {
Player controller = EntityFindUtil.findPlayer(this.level(), this.entityData.get(CONTROLLER)); 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); 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.get(getItemId(this.currentItem));
var data = CustomData.DRONE_ATTACHMENT.values().stream().filter(d -> attachedEntity.equals(d.entityID))
.findAny()
.orElse(null);
if (data != null) { if (data != null) {
if (data.isKamikaze) { if (data.isKamikaze) {
kamikazeExplosion(); kamikazeExplosion();
@ -625,12 +623,10 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
CustomExplosion explosion; CustomExplosion explosion;
// 挂载实体的数据 // 挂载实体的数据
var attachedEntity = this.entityData.get(ATTACHED_ENTITY); var attachedEntity = this.entityData.get(DISPLAY_ENTITY);
if (attachedEntity.isEmpty()) return; if (attachedEntity.isEmpty()) return;
var data = CustomData.DRONE_ATTACHMENT.values().stream().filter(d -> attachedEntity.equals(d.entityID)) var data = CustomData.DRONE_ATTACHMENT.get(getItemId(this.currentItem));
.findAny()
.orElse(null);
if (data == null) return; if (data == null) return;
var bomb = EntityType.byString(attachedEntity).map(entityType -> var bomb = EntityType.byString(attachedEntity).map(entityType ->

View file

@ -1,6 +1,6 @@
{ {
"ItemID": "superbwarfare:c4_bomb", "ItemID": "superbwarfare:c4_bomb",
"EntityID": "superbwarfare:c4", "Entity": "superbwarfare:c4",
"HitDamage": 150, "HitDamage": 150,
"ExplosionDamage": 300, "ExplosionDamage": 300,
"ExplosionRadius": 10, "ExplosionRadius": 10,

View file

@ -1,6 +1,6 @@
{ {
"ItemID": "superbwarfare:mortar_shell", "ItemID": "superbwarfare:mortar_shell",
"EntityID": "superbwarfare:mortar_shell", "Entity": "superbwarfare:mortar_shell",
"HitDamage": 200, "HitDamage": 200,
"ExplosionDamage": 160, "ExplosionDamage": 160,
"ExplosionRadius": 9, "ExplosionRadius": 9,

View file

@ -1,6 +1,6 @@
{ {
"ItemID": "superbwarfare:rgo_grenade", "ItemID": "superbwarfare:rgo_grenade",
"EntityID": "superbwarfare:rgo_grenade", "Entity": "superbwarfare:rgo_grenade",
"IsKamikaze": false, "IsKamikaze": false,
"Count": 6, "Count": 6,
"HitDamage": 270, "HitDamage": 270,

View file

@ -1,6 +1,6 @@
{ {
"ItemID": "superbwarfare:rocket", "ItemID": "superbwarfare:rocket",
"EntityID": "superbwarfare:rpg_rocket", "Entity": "superbwarfare:rpg_rocket",
"HitDamage": 270, "HitDamage": 270,
"ExplosionDamage": 130, "ExplosionDamage": 130,
"ExplosionRadius": 10, "ExplosionRadius": 10,