Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,6 +34,7 @@ public class EntityDisplayBlockEntity extends DisplayBlockEntity implements Stac
protected @Nullable Entity displayEntity = null;
protected @Nullable EntityType<?> entityType = null;
protected Map<String, PartPoseInfo> partPoses = new HashMap<>();
protected boolean isBaby = false;

public EntityDisplayBlockEntity(BlockPos pos, BlockState state) {
super(Glowcase.ENTITY_DISPLAY_BLOCK_ENTITY.get(), pos, state);
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
Expand All @@ -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<Map<String, PartPoseInfo>> optionalStringPartPoseInfoMap = view.read("partPoses", Codec.unboundedMap(Codec.STRING, PartPoseInfo.CODEC));
optionalStringPartPoseInfoMap.ifPresent(stringPartPoseInfoMap -> this.partPoses.putAll(stringPartPoseInfoMap));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,7 +26,7 @@ public class EntityDisplayEditScreen extends DisplayBlockEditScreen {
private final Set<String> 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);
Expand All @@ -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")),
_ -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.util.Map;
import java.util.Optional;

public record C2SEditEntityDisplayBlock(BlockPos pos, DisplayBlockSettings settings, Optional<Map<String, PartPoseInfo>> partPoses) implements C2SEditBlockEntity, C2SEditDisplayBlock {
public record C2SEditEntityDisplayBlock(BlockPos pos, DisplayBlockSettings settings, Optional<Map<String, PartPoseInfo>> partPoses, Optional<Boolean> isBaby) implements C2SEditBlockEntity, C2SEditDisplayBlock {
public static final Type<C2SEditEntityDisplayBlock> ID = new Type<>(Glowcase.id("channel.entity_display"));

private static final StreamCodec<ByteBuf, Map<String, PartPoseInfo>> PART_POSES_CODEC =
Expand All @@ -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
Expand All @@ -43,8 +44,9 @@ public Type<? extends CustomPacketPayload> 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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/assets/glowcase/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Loading