use of net.minecraft.world.level.SpawnData in project Denizen-For-Bukkit by DenizenScript.
the class BlockHelperImpl method setSpawnerCustomRules.
@Override
public void setSpawnerCustomRules(CreatureSpawner spawner, int skyMin, int skyMax, int blockMin, int blockMax) {
try {
CraftCreatureSpawner bukkitSpawner = (CraftCreatureSpawner) spawner;
SpawnerBlockEntity nmsSnapshot = (SpawnerBlockEntity) craftBlockEntityState_snapshot.get(bukkitSpawner);
BaseSpawner nmsSpawner = nmsSnapshot.getSpawner();
SpawnData toSpawn = nmsSpawner.nextSpawnData;
SpawnData.CustomSpawnRules rules = skyMin == -1 ? null : new SpawnData.CustomSpawnRules(new InclusiveRange<>(skyMin, skyMax), new InclusiveRange<>(blockMin, blockMax));
nmsSpawner.nextSpawnData = new SpawnData(toSpawn.entityToSpawn(), Optional.ofNullable(rules));
nmsSpawner.spawnPotentials = SimpleWeightedRandomList.empty();
} catch (Throwable ex) {
Debug.echoError(ex);
}
}
use of net.minecraft.world.level.SpawnData in project Denizen-For-Bukkit by DenizenScript.
the class BlockHelperImpl method setSpawnerSpawnedType.
@Override
public void setSpawnerSpawnedType(CreatureSpawner spawner, EntityTag entity) {
spawner.setSpawnedType(entity.getBukkitEntityType());
if (entity.getWaitingMechanisms() == null || entity.getWaitingMechanisms().size() == 0) {
return;
}
try {
// Wrangle a fake entity
Entity nmsEntity = ((CraftWorld) spawner.getWorld()).createEntity(spawner.getLocation(), entity.getBukkitEntityType().getEntityClass());
EntityTag entityTag = new EntityTag(nmsEntity.getBukkitEntity());
entityTag.isFake = true;
entityTag.isFakeValid = true;
for (Mechanism mechanism : entity.getWaitingMechanisms()) {
entityTag.safeAdjustDuplicate(mechanism);
}
nmsEntity.unsetRemoved();
// Store it into the spawner
CraftCreatureSpawner bukkitSpawner = (CraftCreatureSpawner) spawner;
SpawnerBlockEntity nmsSnapshot = (SpawnerBlockEntity) craftBlockEntityState_snapshot.get(bukkitSpawner);
BaseSpawner nmsSpawner = nmsSnapshot.getSpawner();
SpawnData toSpawn = nmsSpawner.nextSpawnData;
net.minecraft.nbt.CompoundTag tag = toSpawn.getEntityToSpawn();
nmsEntity.saveWithoutId(tag);
} catch (Throwable ex) {
Debug.echoError(ex);
}
}
use of net.minecraft.world.level.SpawnData in project SpongeCommon by SpongePowered.
the class MobSpawnerData method setEntities.
private static void setEntities(final BaseSpawnerAccessor logic, final WeightedTable<EntityArchetype> table) {
logic.accessor$spawnPotentials().clear();
for (final TableEntry<EntityArchetype> entry : table) {
if (!(entry instanceof WeightedObject)) {
continue;
}
final WeightedObject<EntityArchetype> object = (WeightedObject<EntityArchetype>) entry;
final CompoundTag compound = NBTTranslator.INSTANCE.translate(object.get().entityData());
if (!compound.contains(Constants.Entity.ENTITY_TYPE_ID)) {
final ResourceKey key = (ResourceKey) (Object) net.minecraft.world.entity.EntityType.getKey((net.minecraft.world.entity.EntityType<?>) object.get().type());
compound.putString(Constants.Entity.ENTITY_TYPE_ID, key.toString());
}
logic.accessor$spawnPotentials().add(new SpawnData((int) entry.weight(), compound));
}
}
use of net.minecraft.world.level.SpawnData in project SpongeCommon by SpongePowered.
the class MobSpawnerData method setNextEntity.
private static void setNextEntity(final BaseSpawner logic, final WeightedSerializableObject<EntityArchetype> value) {
final CompoundTag compound = NBTTranslator.INSTANCE.translate(value.get().entityData());
if (!compound.contains(Constants.Entity.ENTITY_TYPE_ID)) {
final ResourceKey key = (ResourceKey) (Object) net.minecraft.world.entity.EntityType.getKey((net.minecraft.world.entity.EntityType<?>) value.get().type());
compound.putString(Constants.Entity.ENTITY_TYPE_ID, key.toString());
}
logic.setNextSpawnData(new SpawnData((int) value.weight(), compound));
}
use of net.minecraft.world.level.SpawnData in project SpongeCommon by SpongePowered.
the class MobSpawnerData method getEntities.
private static WeightedTable<EntityArchetype> getEntities(final BaseSpawner logic) {
final WeightedTable<EntityArchetype> possibleEntities = new WeightedTable<>();
for (final SpawnData weightedEntity : ((BaseSpawnerAccessor) logic).accessor$spawnPotentials()) {
final CompoundTag nbt = weightedEntity.getTag();
final String resourceLocation = nbt.getString(Constants.Entity.ENTITY_TYPE_ID);
final EntityType<?> type = Registry.ENTITY_TYPE.getOptional(new ResourceLocation(resourceLocation)).map(EntityType.class::cast).orElse(EntityTypes.PIG.get());
final EntityArchetype archetype = SpongeEntityArchetypeBuilder.pooled().type(type).entityData(NBTTranslator.INSTANCE.translateFrom(nbt)).build();
possibleEntities.add(new WeightedSerializableObject<>(archetype, ((WeighedRandom_WeighedRandomItemAccessor) weightedEntity).accessor$weight()));
}
return possibleEntities;
}
Aggregations