Skip to content

Commit

Permalink
fix: chest display name (close: #502)
Browse files Browse the repository at this point in the history
  • Loading branch information
Snownee committed Nov 25, 2024
1 parent 6abb41e commit 18759d1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main/java/snownee/jade/addon/core/ObjectNameProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.ComponentSerialization;
import net.minecraft.network.chat.contents.TranslatableContents;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.MenuProvider;
Expand All @@ -19,6 +20,7 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.ChestBlock;
import net.minecraft.world.level.block.entity.ChestBlockEntity;
import net.minecraft.world.level.block.state.properties.ChestType;
import snownee.jade.api.BlockAccessor;
import snownee.jade.api.EntityAccessor;
import snownee.jade.api.IBlockComponentProvider;
Expand Down Expand Up @@ -122,10 +124,15 @@ public Component streamData(BlockAccessor accessor) {
if (!(accessor.getBlockEntity() instanceof Nameable nameable)) {
return null;
}
if (nameable instanceof ChestBlockEntity && accessor.getBlock() instanceof ChestBlock) {
if (nameable instanceof ChestBlockEntity && accessor.getBlock() instanceof ChestBlock && accessor.getBlockState().getValue(
ChestBlock.TYPE) != ChestType.SINGLE) {
MenuProvider menuProvider = accessor.getBlockState().getMenuProvider(accessor.getLevel(), accessor.getPosition());
if (menuProvider != null) {
return menuProvider.getDisplayName();
Component name = menuProvider.getDisplayName();
if (!(name.getContents() instanceof TranslatableContents contents) ||
!"container.chestDouble".equals(contents.getKey())) {
return name;
}
}
} else if (nameable.hasCustomName()) {
return nameable.getDisplayName();
Expand Down

0 comments on commit 18759d1

Please sign in to comment.