Search in sources :

Example 1 with SpawnerBlockEntity

use of net.minecraft.world.level.block.entity.SpawnerBlockEntity 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 SpawnerBlockEntity

use of net.minecraft.world.level.block.entity.SpawnerBlockEntity 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 SpawnerBlockEntity

use of net.minecraft.world.level.block.entity.SpawnerBlockEntity in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelperImpl method getMobSpawnerDisplayEntity.

@Override
public EntityTag getMobSpawnerDisplayEntity(CreatureSpawner spawner) {
    SpawnerBlockEntity nmsSpawner = BlockHelperImpl.getTE((CraftCreatureSpawner) spawner);
    net.minecraft.world.entity.Entity nmsEntity = nmsSpawner.getSpawner().getOrCreateDisplayEntity(((CraftWorld) spawner.getWorld()).getHandle());
    return new EntityTag(nmsEntity.getBukkitEntity());
}
Also used : SpawnerBlockEntity(net.minecraft.world.level.block.entity.SpawnerBlockEntity) EntityTag(com.denizenscript.denizen.objects.EntityTag) org.bukkit.entity(org.bukkit.entity) org.bukkit.craftbukkit.v1_18_R1.entity(org.bukkit.craftbukkit.v1_18_R1.entity) net.minecraft.world.entity(net.minecraft.world.entity)

Example 4 with SpawnerBlockEntity

use of net.minecraft.world.level.block.entity.SpawnerBlockEntity in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelperImpl method getMobSpawnerDisplayEntity.

@Override
public EntityTag getMobSpawnerDisplayEntity(CreatureSpawner spawner) {
    SpawnerBlockEntity nmsSpawner = BlockHelperImpl.getTE((CraftCreatureSpawner) spawner);
    net.minecraft.world.entity.Entity nmsEntity = nmsSpawner.getSpawner().getOrCreateDisplayEntity(((CraftWorld) spawner.getWorld()).getHandle());
    return new EntityTag(nmsEntity.getBukkitEntity());
}
Also used : SpawnerBlockEntity(net.minecraft.world.level.block.entity.SpawnerBlockEntity) EntityTag(com.denizenscript.denizen.objects.EntityTag) org.bukkit.craftbukkit.v1_17_R1.entity(org.bukkit.craftbukkit.v1_17_R1.entity) org.bukkit.entity(org.bukkit.entity) net.minecraft.world.entity(net.minecraft.world.entity)

Aggregations

SpawnerBlockEntity (net.minecraft.world.level.block.entity.SpawnerBlockEntity)4 EntityTag (com.denizenscript.denizen.objects.EntityTag)3 net.minecraft.world.entity (net.minecraft.world.entity)2 BaseSpawner (net.minecraft.world.level.BaseSpawner)2 SpawnData (net.minecraft.world.level.SpawnData)2 org.bukkit.entity (org.bukkit.entity)2 Mechanism (com.denizenscript.denizencore.objects.Mechanism)1 InclusiveRange (net.minecraft.util.InclusiveRange)1 Entity (net.minecraft.world.entity.Entity)1 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)1 org.bukkit.craftbukkit.v1_17_R1.entity (org.bukkit.craftbukkit.v1_17_R1.entity)1 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)1 org.bukkit.craftbukkit.v1_18_R1.entity (org.bukkit.craftbukkit.v1_18_R1.entity)1