Search in sources :

Example 1 with BaseSpawner

use of net.minecraft.world.level.BaseSpawner 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);
    }
}
Also used : SpawnerBlockEntity(net.minecraft.world.level.block.entity.SpawnerBlockEntity) BaseSpawner(net.minecraft.world.level.BaseSpawner) SpawnData(net.minecraft.world.level.SpawnData) InclusiveRange(net.minecraft.util.InclusiveRange)

Example 2 with BaseSpawner

use of net.minecraft.world.level.BaseSpawner 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);
    }
}
Also used : SpawnerBlockEntity(net.minecraft.world.level.block.entity.SpawnerBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) Entity(net.minecraft.world.entity.Entity) SpawnerBlockEntity(net.minecraft.world.level.block.entity.SpawnerBlockEntity) BaseSpawner(net.minecraft.world.level.BaseSpawner) EntityTag(com.denizenscript.denizen.objects.EntityTag) SpawnData(net.minecraft.world.level.SpawnData) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld) Mechanism(com.denizenscript.denizencore.objects.Mechanism)

Example 3 with BaseSpawner

use of net.minecraft.world.level.BaseSpawner in project SpongeCommon by SpongePowered.

the class MobSpawnerData method register.

// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
    registrator.asMutable(SpawnerBlockEntityAccessor.class).create(Keys.MAX_NEARBY_ENTITIES).get(h -> ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$maxNearbyEntities()).set((h, v) -> ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$maxNearbyEntities(v)).create(Keys.MAX_SPAWN_DELAY).get(h -> new SpongeTicks(((BaseSpawnerAccessor) h.accessor$spawner()).accessor$maxSpawnDelay())).set((h, v) -> ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$maxSpawnDelay((int) v.ticks())).create(Keys.MIN_SPAWN_DELAY).get(h -> new SpongeTicks(((BaseSpawnerAccessor) h.accessor$spawner()).accessor$minSpawnDelay())).set((h, v) -> ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$minSpawnDelay((int) v.ticks())).create(Keys.NEXT_ENTITY_TO_SPAWN).get(h -> MobSpawnerData.getNextEntity((BaseSpawnerAccessor) h.accessor$spawner())).set((h, v) -> MobSpawnerData.setNextEntity(h.accessor$spawner(), v)).create(Keys.REMAINING_SPAWN_DELAY).get(h -> new SpongeTicks(((BaseSpawnerAccessor) h.accessor$spawner()).accessor$spawnDelay())).set((h, v) -> ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$spawnDelay((int) v.ticks())).create(Keys.REQUIRED_PLAYER_RANGE).get(h -> (double) ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$requiredPlayerRange()).set((h, v) -> ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$requiredPlayerRange(v.intValue())).create(Keys.SPAWN_COUNT).get(h -> ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$spawnCount()).set((h, v) -> ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$spawnCount(v)).create(Keys.SPAWN_RANGE).get(h -> (double) ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$spawnRange()).set((h, v) -> ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$spawnRange(v.intValue())).create(Keys.SPAWNABLE_ENTITIES).get(h -> MobSpawnerData.getEntities(h.accessor$spawner())).set((h, v) -> {
        final BaseSpawnerAccessor logic = (BaseSpawnerAccessor) h.accessor$spawner();
        MobSpawnerData.setEntities(logic, v);
        MobSpawnerData.setNextEntity((BaseSpawner) logic, MobSpawnerData.getNextEntity(logic));
    });
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) Constants(org.spongepowered.common.util.Constants) SpawnData(net.minecraft.world.level.SpawnData) TableEntry(org.spongepowered.api.util.weighted.TableEntry) SpongeEntityArchetypeBuilder(org.spongepowered.common.entity.SpongeEntityArchetypeBuilder) WeightedSerializableObject(org.spongepowered.api.util.weighted.WeightedSerializableObject) NBTTranslator(org.spongepowered.common.data.persistence.NBTTranslator) Registry(net.minecraft.core.Registry) WeighedRandom_WeighedRandomItemAccessor(org.spongepowered.common.accessor.util.WeighedRandom_WeighedRandomItemAccessor) Keys(org.spongepowered.api.data.Keys) CompoundTag(net.minecraft.nbt.CompoundTag) EntityTypes(org.spongepowered.api.entity.EntityTypes) WeightedObject(org.spongepowered.api.util.weighted.WeightedObject) BaseSpawnerAccessor(org.spongepowered.common.accessor.world.level.BaseSpawnerAccessor) BaseSpawner(net.minecraft.world.level.BaseSpawner) DataProviderRegistrator(org.spongepowered.common.data.provider.DataProviderRegistrator) WeightedTable(org.spongepowered.api.util.weighted.WeightedTable) ResourceKey(org.spongepowered.api.ResourceKey) EntityType(org.spongepowered.api.entity.EntityType) SpongeTicks(org.spongepowered.common.util.SpongeTicks) SpawnerBlockEntityAccessor(org.spongepowered.common.accessor.world.level.block.entity.SpawnerBlockEntityAccessor) EntityArchetype(org.spongepowered.api.entity.EntityArchetype) BaseSpawnerAccessor(org.spongepowered.common.accessor.world.level.BaseSpawnerAccessor) SpawnerBlockEntityAccessor(org.spongepowered.common.accessor.world.level.block.entity.SpawnerBlockEntityAccessor) SpongeTicks(org.spongepowered.common.util.SpongeTicks)

Aggregations

BaseSpawner (net.minecraft.world.level.BaseSpawner)3 SpawnData (net.minecraft.world.level.SpawnData)3 SpawnerBlockEntity (net.minecraft.world.level.block.entity.SpawnerBlockEntity)2 EntityTag (com.denizenscript.denizen.objects.EntityTag)1 Mechanism (com.denizenscript.denizencore.objects.Mechanism)1 Registry (net.minecraft.core.Registry)1 CompoundTag (net.minecraft.nbt.CompoundTag)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 InclusiveRange (net.minecraft.util.InclusiveRange)1 Entity (net.minecraft.world.entity.Entity)1 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)1 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)1 ResourceKey (org.spongepowered.api.ResourceKey)1 Keys (org.spongepowered.api.data.Keys)1 EntityArchetype (org.spongepowered.api.entity.EntityArchetype)1 EntityType (org.spongepowered.api.entity.EntityType)1 EntityTypes (org.spongepowered.api.entity.EntityTypes)1 TableEntry (org.spongepowered.api.util.weighted.TableEntry)1 WeightedObject (org.spongepowered.api.util.weighted.WeightedObject)1 WeightedSerializableObject (org.spongepowered.api.util.weighted.WeightedSerializableObject)1