允许为无人机挂载实体设置显示用NBT
This commit is contained in:
parent
f2224c1d80
commit
dc59ff7af5
3 changed files with 31 additions and 9 deletions
|
@ -115,6 +115,7 @@ public class DroneRenderer extends GeoEntityRenderer<DroneEntity> {
|
||||||
|
|
||||||
private String entityNameCache = "";
|
private String entityNameCache = "";
|
||||||
private Entity entityCache = null;
|
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) {
|
private void renderAttachments(DroneEntity entity, float entityYaw, float partialTicks, PoseStack poseStack, MultiBufferSource buffer, int packedLight) {
|
||||||
|
@ -131,9 +132,17 @@ public class DroneRenderer extends GeoEntityRenderer<DroneEntity> {
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
if (renderEntity == null) return;
|
if (renderEntity == null) return;
|
||||||
|
|
||||||
|
// 填充tag
|
||||||
|
var tag = entity.getEntityData().get(ATTACHED_ENTITY_TAG);
|
||||||
|
if (!tag.isEmpty()) {
|
||||||
|
renderEntity.load(tag);
|
||||||
|
}
|
||||||
|
|
||||||
entityNameCache = attached;
|
entityNameCache = attached;
|
||||||
entityCache = renderEntity;
|
entityCache = renderEntity;
|
||||||
|
attachedTick = entity.tickCount;
|
||||||
}
|
}
|
||||||
|
renderEntity.tickCount = entity.tickCount - attachedTick;
|
||||||
|
|
||||||
var displayData = entity.getEntityData().get(ATTACHMENT_DISPLAY);
|
var displayData = entity.getEntityData().get(ATTACHMENT_DISPLAY);
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class DroneAttachmentData implements IDBasedData {
|
||||||
private int count = 1;
|
private int count = 1;
|
||||||
|
|
||||||
public int count() {
|
public int count() {
|
||||||
return Math.min(1, this.count);
|
return isKamikaze ? 1 : Math.max(1, this.count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SerializedName("IsKamikaze")
|
@SerializedName("IsKamikaze")
|
||||||
|
@ -35,6 +35,12 @@ 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
|
||||||
|
@ -60,6 +66,9 @@ public class DroneAttachmentData implements IDBasedData {
|
||||||
return (this.rotation != null && this.rotation.length < 3) ? new float[]{0, 0, 0} : this.rotation;
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,7 @@ import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity;
|
||||||
import com.atsuishio.superbwarfare.init.*;
|
import com.atsuishio.superbwarfare.init.*;
|
||||||
import com.atsuishio.superbwarfare.item.Monitor;
|
import com.atsuishio.superbwarfare.item.Monitor;
|
||||||
import com.atsuishio.superbwarfare.item.common.ammo.MortarShell;
|
import com.atsuishio.superbwarfare.item.common.ammo.MortarShell;
|
||||||
import com.atsuishio.superbwarfare.tools.CustomExplosion;
|
import com.atsuishio.superbwarfare.tools.*;
|
||||||
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
|
|
||||||
import com.atsuishio.superbwarfare.tools.NBTTool;
|
|
||||||
import com.atsuishio.superbwarfare.tools.ParticleTool;
|
|
||||||
import net.minecraft.ChatFormatting;
|
import net.minecraft.ChatFormatting;
|
||||||
import net.minecraft.core.component.DataComponents;
|
import net.minecraft.core.component.DataComponents;
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
|
@ -69,6 +66,7 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
||||||
|
|
||||||
// scale[3], offset[3], rotation[3]
|
// scale[3], offset[3], rotation[3]
|
||||||
public static final EntityDataAccessor<List<Float>> ATTACHMENT_DISPLAY = SynchedEntityData.defineId(DroneEntity.class, ModSerializers.FLOAT_LIST_SERIALIZER.get());
|
public static final EntityDataAccessor<List<Float>> ATTACHMENT_DISPLAY = SynchedEntityData.defineId(DroneEntity.class, ModSerializers.FLOAT_LIST_SERIALIZER.get());
|
||||||
|
public static final EntityDataAccessor<CompoundTag> ATTACHED_ENTITY_TAG = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.COMPOUND_TAG);
|
||||||
|
|
||||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||||
|
|
||||||
|
@ -109,7 +107,8 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
||||||
.define(LINKED, false)
|
.define(LINKED, false)
|
||||||
.define(KAMIKAZE_MODE, 0)
|
.define(KAMIKAZE_MODE, 0)
|
||||||
.define(ATTACHED_ENTITY, "")
|
.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
|
@Override
|
||||||
|
@ -381,7 +380,7 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
||||||
// 不同种物品挂载
|
// 不同种物品挂载
|
||||||
this.entityData.set(ATTACHED_ENTITY, attachmentData.entityID);
|
this.entityData.set(ATTACHED_ENTITY, attachmentData.entityID);
|
||||||
// TODO 正确处理和渲染AMMO
|
// TODO 正确处理和渲染AMMO
|
||||||
// this.entityData.set(AMMO, this.entityData.get(AMMO) + 1);
|
this.entityData.set(AMMO, this.entityData.get(AMMO) + 1);
|
||||||
|
|
||||||
if (!player.isCreative()) {
|
if (!player.isCreative()) {
|
||||||
stack.shrink(1);
|
stack.shrink(1);
|
||||||
|
@ -394,6 +393,11 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
|
||||||
var offset = attachmentData.offset();
|
var offset = attachmentData.offset();
|
||||||
var rotation = attachmentData.rotation();
|
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]));
|
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]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue