diff --git a/src/main/java/dev/hephaestus/glowcase/block/entity/EntityDisplayBlockEntity.java b/src/main/java/dev/hephaestus/glowcase/block/entity/EntityDisplayBlockEntity.java index 4cbbaada..8ceb88dc 100644 --- a/src/main/java/dev/hephaestus/glowcase/block/entity/EntityDisplayBlockEntity.java +++ b/src/main/java/dev/hephaestus/glowcase/block/entity/EntityDisplayBlockEntity.java @@ -11,6 +11,7 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntitySpawnReason; import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.Mob; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.SpawnEggItem; import net.minecraft.world.level.Level; @@ -33,6 +34,7 @@ public class EntityDisplayBlockEntity extends DisplayBlockEntity implements Stac protected @Nullable Entity displayEntity = null; protected @Nullable EntityType entityType = null; protected Map partPoses = new HashMap<>(); + protected boolean isBaby = false; public EntityDisplayBlockEntity(BlockPos pos, BlockState state) { super(Glowcase.ENTITY_DISPLAY_BLOCK_ENTITY.get(), pos, state); @@ -71,6 +73,7 @@ public void unsetFromStack() { public void setDisplayEntity(@Nullable Entity displayEntity) { this.displayEntity = displayEntity; this.entityType = displayEntity == null ? null : displayEntity.getType(); + applyBabyStateToDisplayEntity(); this.setChanged(); } @@ -113,12 +116,27 @@ public void setPartPoseInfo(String name, PartPoseInfo partPoseInfo) { this.partPoses.put(name,partPoseInfo); } + public void setBaby(boolean baby) { + this.isBaby = baby; + applyBabyStateToDisplayEntity(); + } + + public void applyBabyStateToDisplayEntity(){ + if(displayEntity != null && displayEntity instanceof Mob displayMob) { + displayMob.setBaby(isBaby()); + } + } + + public boolean isBaby(){ + return this.isBaby; + } @Override protected void saveAdditional(ValueOutput view) { super.saveAdditional(view); if (entityType != null) { view.store("type", EntityType.CODEC, entityType); + view.store("isBaby", Codec.BOOL, isBaby); } if(!partPoses.isEmpty()) { view.store("partPoses", Codec.unboundedMap(Codec.STRING, PartPoseInfo.CODEC), partPoses); @@ -133,6 +151,8 @@ protected void loadAdditional(ValueInput view) { this.entityType = view.read("type", EntityType.CODEC).orElse(null); this.displayEntity = null; + this.isBaby = view.read("isBaby", Codec.BOOL).orElse(false); + this.partPoses.clear(); Optional> optionalStringPartPoseInfoMap = view.read("partPoses", Codec.unboundedMap(Codec.STRING, PartPoseInfo.CODEC)); optionalStringPartPoseInfoMap.ifPresent(stringPartPoseInfoMap -> this.partPoses.putAll(stringPartPoseInfoMap)); diff --git a/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/EntityDisplayEditScreen.java b/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/EntityDisplayEditScreen.java index 487dbb0b..252ee81a 100644 --- a/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/EntityDisplayEditScreen.java +++ b/src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/EntityDisplayEditScreen.java @@ -7,11 +7,13 @@ import dev.hephaestus.glowcase.packet.C2SEditEntityDisplayBlock; import dev.hephaestus.glowcase.util.PartPoseInfo; import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.Checkbox; import net.minecraft.client.gui.components.StringWidget; import net.minecraft.client.model.geom.ModelPart; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.Mob; import net.minecraft.world.phys.Vec3; import java.util.HashSet; @@ -24,7 +26,7 @@ public class EntityDisplayEditScreen extends DisplayBlockEditScreen { private final Set expandedParts = new HashSet<>(); private boolean expanded = false; private final int STARTING_X = 10; - private final int STARTING_Y = 200; + private final int STARTING_Y = 220; public EntityDisplayEditScreen(DisplayBlockEntity displayBlock) { super(displayBlock); @@ -37,7 +39,22 @@ public void init() { int bottom = STARTING_Y + 22; Entity displayEntity = this.entityDisplay.getDisplayEntity(); + EntityDisplayBlockEntity entityDisplayBlockEntity = ((EntityDisplayBlockEntity)(this.blockEntity)); if(displayEntity != null) { + if(displayEntity instanceof Mob) { + this.addRenderableWidget(Checkbox.builder(Component.translatable("gui.glowcase.baby"), this.minecraft.font) + .selected(entityDisplayBlockEntity.isBaby()) + .onValueChange((_, checked) -> { + entityDisplayBlockEntity.setBaby(checked); + editDisplayBlock(); + this.expanded = false; + this.rebuildWidgets(); + } + ) + .pos(STARTING_X, 190) + .build()); + } + this.addRenderableWidget(Button.builder( Component.literal(this.expanded ? "▼ " : "▶ ").append(Component.translatable("gui.glowcase.model_parts")), _ -> { diff --git a/src/main/java/dev/hephaestus/glowcase/packet/C2SEditEntityDisplayBlock.java b/src/main/java/dev/hephaestus/glowcase/packet/C2SEditEntityDisplayBlock.java index 750727a7..f5034262 100644 --- a/src/main/java/dev/hephaestus/glowcase/packet/C2SEditEntityDisplayBlock.java +++ b/src/main/java/dev/hephaestus/glowcase/packet/C2SEditEntityDisplayBlock.java @@ -18,7 +18,7 @@ import java.util.Map; import java.util.Optional; -public record C2SEditEntityDisplayBlock(BlockPos pos, DisplayBlockSettings settings, Optional> partPoses) implements C2SEditBlockEntity, C2SEditDisplayBlock { +public record C2SEditEntityDisplayBlock(BlockPos pos, DisplayBlockSettings settings, Optional> partPoses, Optional isBaby) implements C2SEditBlockEntity, C2SEditDisplayBlock { public static final Type ID = new Type<>(Glowcase.id("channel.entity_display")); private static final StreamCodec> PART_POSES_CODEC = @@ -28,12 +28,13 @@ public record C2SEditEntityDisplayBlock(BlockPos pos, DisplayBlockSettings setti BlockPos.STREAM_CODEC, C2SEditEntityDisplayBlock::pos, DisplayBlockSettings.PACKET_CODEC, C2SEditEntityDisplayBlock::settings, ByteBufCodecs.optional(PART_POSES_CODEC), C2SEditEntityDisplayBlock::partPoses, + ByteBufCodecs.optional(ByteBufCodecs.BOOL), C2SEditEntityDisplayBlock::isBaby, C2SEditEntityDisplayBlock::new ); public static C2SEditEntityDisplayBlock of(DisplayBlockEntity be) { EntityDisplayBlockEntity entityDisplayBlock = (EntityDisplayBlockEntity)be; - return new C2SEditEntityDisplayBlock(be.getBlockPos(), be.toSettings(), Optional.of(entityDisplayBlock.getPartPoses())); + return new C2SEditEntityDisplayBlock(be.getBlockPos(), be.toSettings(), Optional.of(entityDisplayBlock.getPartPoses()), Optional.of(entityDisplayBlock.isBaby())); } @Override @@ -43,8 +44,9 @@ public Type type() { @Override public void receive(ServerLevel world, BlockEntity blockEntity) { - if(blockEntity instanceof EntityDisplayBlockEntity entityDisplayBlock) { + if(blockEntity instanceof EntityDisplayBlockEntity entityDisplayBlock) { partPoses().ifPresent(entityDisplayBlock::loadPartPoses); + isBaby().ifPresent(entityDisplayBlock::setBaby); } C2SEditDisplayBlock.super.receive(world, blockEntity); } diff --git a/src/main/resources/assets/glowcase/lang/en_us.json b/src/main/resources/assets/glowcase/lang/en_us.json index cb042823..9e294a49 100644 --- a/src/main/resources/assets/glowcase/lang/en_us.json +++ b/src/main/resources/assets/glowcase/lang/en_us.json @@ -200,5 +200,6 @@ "gui.glowcase.color_text": "Color Text (Via QuickText Tags)", "gui.glowcase.insert_font": "Insert Font (Via QuickText Tags)", "gui.glowcase.model_parts": "Model Parts", - "gui.glowcase.rotation": "Rotation" + "gui.glowcase.rotation": "Rotation", + "gui.glowcase.baby": "Baby" }