Spawner .java

net.minecraft.world.level.Spawner (interface): members: getSpawnEntityDisplayName, setEntityData, setEntityId, appendHoverText. strings: "entity".

net.minecraft.world.levelinterface40 linescommon1.7 KB

API Surface (0)

No public/protected methods detected (fields or constants only).

String literals (3)

"block.minecraft.spawner.desc1"
"block.minecraft.spawner.desc2"
"entity"

Full Source

Spawner.java40 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level;
2
3
import java.util.function.Consumer;
4
import net.minecraft.ChatFormatting;
5
import net.minecraft.network.chat.CommonComponents;
6
import net.minecraft.network.chat.Component;
7
import net.minecraft.util.RandomSource;
8
import net.minecraft.world.entity.EntityType;
9
import net.minecraft.world.item.component.TypedEntityData;
10
import net.minecraft.world.level.block.entity.BlockEntityType;
11
import org.jspecify.annotations.Nullable;
12
13
public interface Spawner {
14
	void setEntityId(final EntityType<?> type, final RandomSource random);
15
16
	void setEntityData(final TypedEntityData<EntityType<?>> entityData, final RandomSource random);
17
18
	static void appendHoverText(final @Nullable TypedEntityData<BlockEntityType<?>> data, final Consumer<Component> consumer, final String nextSpawnDataTagKey) {
19
		Component displayName = getSpawnEntityDisplayName(data, nextSpawnDataTagKey);
20
		if (displayName != null) {
21
			consumer.accept(displayName);
22
		} else {
23
			consumer.accept(CommonComponents.EMPTY);
24
			consumer.accept(Component.translatable("block.minecraft.spawner.desc1").withStyle(ChatFormatting.GRAY));
25
			consumer.accept(CommonComponents.space().append(Component.translatable("block.minecraft.spawner.desc2").withStyle(ChatFormatting.BLUE)));
26
		}
27
	}
28
29
	static @Nullable Component getSpawnEntityDisplayName(final @Nullable TypedEntityData<BlockEntityType<?>> data, final String nextSpawnDataTagKey) {
30
		return data == null
31
			? null
32
			: data.getUnsafe()
33
				.getCompound(nextSpawnDataTagKey)
34
				.flatMap(nextSpawnData -> nextSpawnData.getCompound("entity"))
35
				.flatMap(entityTag -> entityTag.read("id", EntityType.CODEC))
36
				.map(entityType -> Component.translatable(entityType.getDescriptionId()).withStyle(ChatFormatting.GRAY))
37
				.orElse(null);
38
	}
39
}
40

Decompiled Minecraft 26.3 source of Spawner (net/minecraft/world/level/Spawner.java) with Mojang official mappings, stored verbatim on the site.