mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-05 02:10:24 +01:00
Add entity type to Material registry (for spawn eggs) (#2020)
* Add entity type to Material registry (for spawn eggs) * Rename to spawn entity type and add javadoc
This commit is contained in:
parent
dcbdad9a1b
commit
7e59603d5f
@ -9,6 +9,7 @@ import net.minestom.server.collision.BoundingBox;
|
||||
import net.minestom.server.collision.CollisionUtils;
|
||||
import net.minestom.server.collision.Shape;
|
||||
import net.minestom.server.entity.EntitySpawnType;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.entity.EquipmentSlot;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.item.Material;
|
||||
@ -461,6 +462,7 @@ public final class Registry {
|
||||
private final boolean isFood;
|
||||
private final Supplier<Block> blockSupplier;
|
||||
private final EquipmentSlot equipmentSlot;
|
||||
private final EntityType entityType;
|
||||
private final Properties custom;
|
||||
|
||||
private MaterialEntry(String namespace, Properties main, Properties custom) {
|
||||
@ -489,6 +491,14 @@ public final class Registry {
|
||||
this.equipmentSlot = null;
|
||||
}
|
||||
}
|
||||
{
|
||||
final Properties spawnEggProperties = main.section("spawnEggProperties");
|
||||
if (spawnEggProperties != null) {
|
||||
this.entityType = EntityType.fromNamespaceId(spawnEggProperties.getString("entityType"));
|
||||
} else {
|
||||
this.entityType = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public @NotNull NamespaceID namespace() {
|
||||
@ -527,6 +537,14 @@ public final class Registry {
|
||||
return equipmentSlot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the entity type this item can spawn. Only present for spawn eggs (e.g. wolf spawn egg, skeleton spawn egg)
|
||||
* @return The entity type it can spawn, or null if it is not a spawn egg
|
||||
*/
|
||||
public @Nullable EntityType spawnEntityType() {
|
||||
return entityType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Properties custom() {
|
||||
return custom;
|
||||
|
@ -2,6 +2,7 @@ package net.minestom.server.item;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBT;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@ -108,6 +109,15 @@ public class ItemTest {
|
||||
assertEquals(6, item1.withAmount(6).amount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEntityType() {
|
||||
var item1 = ItemStack.of(Material.DIAMOND, 1);
|
||||
assertNull(item1.material().registry().spawnEntityType());
|
||||
var item2 = ItemStack.of(Material.CAMEL_SPAWN_EGG, 1);
|
||||
assertNotNull(item2.material().registry().spawnEntityType());
|
||||
assertEquals(EntityType.CAMEL, item2.material().registry().spawnEntityType());
|
||||
}
|
||||
|
||||
static ItemStack createItem() {
|
||||
return ItemStack.builder(Material.STONE)
|
||||
.displayName(Component.text("Display name!", NamedTextColor.GREEN))
|
||||
|
Loading…
Reference in New Issue
Block a user