13
0
geforkt von Mirrors/Paper

SPIGOT-7201: Spawner ItemMeta not working as expected

By: md_5 <git@md-5.net>
Dieser Commit ist enthalten in:
CraftBukkit/Spigot 2022-12-11 08:40:57 +11:00
Ursprung 0cb9e6122e
Commit 1c2a27790b

Datei anzeigen

@ -2,7 +2,9 @@ package org.bukkit.craftbukkit.block;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import java.util.Optional; import java.util.Optional;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.EntityTypes; import net.minecraft.world.entity.EntityTypes;
import net.minecraft.world.level.MobSpawnerData;
import net.minecraft.world.level.block.entity.TileEntityMobSpawner; import net.minecraft.world.level.block.entity.TileEntityMobSpawner;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.CreatureSpawner; import org.bukkit.block.CreatureSpawner;
@ -16,7 +18,12 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<TileEntityMobSpa
@Override @Override
public EntityType getSpawnedType() { public EntityType getSpawnedType() {
Optional<EntityTypes<?>> type = EntityTypes.by(this.getSnapshot().getSpawner().nextSpawnData.getEntityToSpawn()); MobSpawnerData spawnData = this.getSnapshot().getSpawner().nextSpawnData;
if (spawnData == null) {
return EntityType.PIG; // TODO: Change API contract to nullable?
}
Optional<EntityTypes<?>> type = EntityTypes.by(spawnData.getEntityToSpawn());
return (type.isEmpty()) ? EntityType.PIG : EntityType.fromName(EntityTypes.getKey(type.get()).getPath()); return (type.isEmpty()) ? EntityType.PIG : EntityType.fromName(EntityTypes.getKey(type.get()).getPath());
} }
@ -26,12 +33,18 @@ public class CraftCreatureSpawner extends CraftBlockEntityState<TileEntityMobSpa
throw new IllegalArgumentException("Can't spawn EntityType " + entityType + " from mobspawners!"); throw new IllegalArgumentException("Can't spawn EntityType " + entityType + " from mobspawners!");
} }
this.getSnapshot().setEntityId(EntityTypes.byString(entityType.getName()).get(), this.getWorldHandle().getRandom()); RandomSource rand = (this.isPlaced()) ? this.getWorldHandle().getRandom() : RandomSource.create();
this.getSnapshot().setEntityId(EntityTypes.byString(entityType.getName()).get(), rand);
} }
@Override @Override
public String getCreatureTypeName() { public String getCreatureTypeName() {
Optional<EntityTypes<?>> type = EntityTypes.by(this.getSnapshot().getSpawner().nextSpawnData.getEntityToSpawn()); MobSpawnerData spawnData = this.getSnapshot().getSpawner().nextSpawnData;
if (spawnData == null) {
return ""; // TODO: Change API contract to nullable?
}
Optional<EntityTypes<?>> type = EntityTypes.by(spawnData.getEntityToSpawn());
return (type.isEmpty()) ? "" : EntityTypes.getKey(type.get()).getPath(); return (type.isEmpty()) ? "" : EntityTypes.getKey(type.get()).getPath();
} }