允许为无人机挂载实体设置显示用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 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<DroneEntity> {
|
|||
.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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<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);
|
||||
|
||||
|
@ -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]));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue