35 lines
1.5 KiB
Java
35 lines
1.5 KiB
Java
package net.minecraft.world.level;
|
|
|
|
import java.util.function.Consumer;
|
|
import net.minecraft.ChatFormatting;
|
|
import net.minecraft.network.chat.CommonComponents;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.util.RandomSource;
|
|
import net.minecraft.world.entity.EntityType;
|
|
import net.minecraft.world.item.component.CustomData;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
public interface Spawner {
|
|
void setEntityId(EntityType<?> entityType, RandomSource random);
|
|
|
|
static void appendHoverText(CustomData customData, Consumer<Component> tooltipAdder, String spawnDataKey) {
|
|
Component component = getSpawnEntityDisplayName(customData, spawnDataKey);
|
|
if (component != null) {
|
|
tooltipAdder.accept(component);
|
|
} else {
|
|
tooltipAdder.accept(CommonComponents.EMPTY);
|
|
tooltipAdder.accept(Component.translatable("block.minecraft.spawner.desc1").withStyle(ChatFormatting.GRAY));
|
|
tooltipAdder.accept(CommonComponents.space().append(Component.translatable("block.minecraft.spawner.desc2").withStyle(ChatFormatting.BLUE)));
|
|
}
|
|
}
|
|
|
|
@Nullable
|
|
static Component getSpawnEntityDisplayName(CustomData customData, String spawnDataKey) {
|
|
return (Component)customData.getUnsafe()
|
|
.getCompound(spawnDataKey)
|
|
.flatMap(compoundTag -> compoundTag.getCompound("entity"))
|
|
.flatMap(compoundTag -> compoundTag.read("id", EntityType.CODEC))
|
|
.map(entityType -> Component.translatable(entityType.getDescriptionId()).withStyle(ChatFormatting.GRAY))
|
|
.orElse(null);
|
|
}
|
|
}
|