Search in sources :

Example 16 with TileEntityMobSpawner

use of net.minecraft.server.v1_7_R4.TileEntityMobSpawner in project SilkSpawners by timbru31.

the class NMSHandler method getMobNameOfSpawner.

@Override
public String getMobNameOfSpawner(final BlockState blockState) {
    final CraftCreatureSpawner spawner = (CraftCreatureSpawner) blockState;
    try {
        final TileEntityMobSpawner tile = (TileEntityMobSpawner) tileField.get(spawner);
        final MinecraftKey minecraftKey = tile.getSpawner().getMobName();
        return minecraftKey != null ? minecraftKey.getKey() : "";
    } catch (IllegalArgumentException | IllegalAccessException e) {
        Bukkit.getLogger().warning("[SilkSpawners] Reflection failed: " + e.getMessage());
        e.printStackTrace();
    }
    return "";
}
Also used : CraftCreatureSpawner(org.bukkit.craftbukkit.v1_16_R1.block.CraftCreatureSpawner) TileEntityMobSpawner(net.minecraft.server.v1_16_R1.TileEntityMobSpawner) MinecraftKey(net.minecraft.server.v1_16_R1.MinecraftKey)

Example 17 with TileEntityMobSpawner

use of net.minecraft.server.v1_7_R4.TileEntityMobSpawner in project SilkSpawners by timbru31.

the class NMSHandler method setMobNameOfSpawner.

@Override
public boolean setMobNameOfSpawner(final BlockState blockState, final String mobID) {
    // Prevent ResourceKeyInvalidException: Non [a-z0-9/._-] character in path of location
    final String safeMobID = caseFormatOf(mobID.replace(" ", "_")).to(CaseFormat.UPPER_CAMEL, mobID.replace(" ", "_"));
    final CraftCreatureSpawner spawner = (CraftCreatureSpawner) blockState;
    try {
        final TileEntityMobSpawner tile = (TileEntityMobSpawner) tileField.get(spawner);
        tile.getSpawner().setMobName(safeMobID);
        return true;
    } catch (IllegalArgumentException | IllegalAccessException e) {
        Bukkit.getLogger().warning("[SilkSpawners] Reflection failed: " + e.getMessage());
        e.printStackTrace();
    }
    return false;
}
Also used : CraftCreatureSpawner(org.bukkit.craftbukkit.v1_10_R1.block.CraftCreatureSpawner) TileEntityMobSpawner(net.minecraft.server.v1_10_R1.TileEntityMobSpawner)

Example 18 with TileEntityMobSpawner

use of net.minecraft.server.v1_7_R4.TileEntityMobSpawner in project RoseStacker by Rosewood-Development.

the class NMSHandlerImpl method injectStackedSpawnerTile.

@Override
public StackedSpawnerTile injectStackedSpawnerTile(Object stackedSpawnerObj) {
    StackedSpawner stackedSpawner = (StackedSpawner) stackedSpawnerObj;
    Block block = stackedSpawner.getBlock();
    WorldServer level = ((CraftWorld) block.getWorld()).getHandle();
    TileEntity blockEntity = level.getTileEntity(new BlockPosition(block.getX(), block.getY(), block.getZ()));
    if (blockEntity instanceof TileEntityMobSpawner) {
        TileEntityMobSpawner spawnerBlockEntity = (TileEntityMobSpawner) blockEntity;
        if (!(spawnerBlockEntity.getSpawner() instanceof StackedSpawnerTileImpl)) {
            StackedSpawnerTile stackedSpawnerTile = new StackedSpawnerTileImpl(spawnerBlockEntity.getSpawner(), spawnerBlockEntity, stackedSpawner);
            unsafe.putObject(spawnerBlockEntity, field_SpawnerBlockEntity_spawner_offset, stackedSpawnerTile);
            return stackedSpawnerTile;
        } else {
            StackedSpawnerTileImpl spawnerTile = (StackedSpawnerTileImpl) spawnerBlockEntity.getSpawner();
            spawnerTile.updateStackedSpawner(stackedSpawner);
            return spawnerTile;
        }
    }
    return null;
}
Also used : TileEntity(net.minecraft.server.v1_16_R3.TileEntity) StackedSpawner(dev.rosewood.rosestacker.stack.StackedSpawner) BlockPosition(net.minecraft.server.v1_16_R3.BlockPosition) Block(org.bukkit.block.Block) WorldServer(net.minecraft.server.v1_16_R3.WorldServer) TileEntityMobSpawner(net.minecraft.server.v1_16_R3.TileEntityMobSpawner) StackedSpawnerTileImpl(dev.rosewood.rosestacker.nms.v1_16_R3.spawner.StackedSpawnerTileImpl) StackedSpawnerTile(dev.rosewood.rosestacker.nms.spawner.StackedSpawnerTile) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld)

Example 19 with TileEntityMobSpawner

use of net.minecraft.server.v1_7_R4.TileEntityMobSpawner in project WildLoaders by BG-Software-LLC.

the class NMSAdapter_v1_8_R3 method updateSpawner.

@Override
public void updateSpawner(Location location, boolean reset) {
    World world = ((CraftWorld) location.getWorld()).getHandle();
    BlockPosition blockPosition = new BlockPosition(location.getX(), location.getY(), location.getZ());
    TileEntityMobSpawner mobSpawner = (TileEntityMobSpawner) world.getTileEntity(blockPosition);
    NBTTagCompound nbtTagCompound = new NBTTagCompound();
    mobSpawner.b(nbtTagCompound);
    nbtTagCompound.setShort("RequiredPlayerRange", (short) (reset ? 16 : -1));
    mobSpawner.a(nbtTagCompound);
}
Also used : BlockPosition(net.minecraft.server.v1_8_R3.BlockPosition) NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound) TileEntityMobSpawner(net.minecraft.server.v1_8_R3.TileEntityMobSpawner) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld) World(net.minecraft.server.v1_8_R3.World) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld)

Example 20 with TileEntityMobSpawner

use of net.minecraft.server.v1_7_R4.TileEntityMobSpawner in project WildLoaders by BG-Software-LLC.

the class NMSAdapter_v1_8_R3 method removeLoader.

@Override
public void removeLoader(ChunkLoader chunkLoader, boolean spawnParticle) {
    Location loaderLoc = chunkLoader.getLocation();
    World world = ((CraftWorld) loaderLoc.getWorld()).getHandle();
    BlockPosition blockPosition = new BlockPosition(loaderLoc.getX(), loaderLoc.getY(), loaderLoc.getZ());
    long tileEntityLong = LongHash.toLong(blockPosition.getX() >> 4, blockPosition.getZ() >> 4);
    TileEntityChunkLoader tileEntityChunkLoader = TileEntityChunkLoader.tileEntityChunkLoaderMap.remove(tileEntityLong);
    if (tileEntityChunkLoader != null) {
        tileEntityChunkLoader.holograms.forEach(EntityHolograms_v1_8_R3::removeHologram);
        tileEntityChunkLoader.removed = true;
        world.tileEntityList.remove(tileEntityChunkLoader);
    }
    if (spawnParticle)
        world.a(null, 2001, blockPosition, Block.getCombinedId(world.getType(blockPosition)));
    for (org.bukkit.Chunk bukkitChunk : chunkLoader.getLoadedChunks()) {
        Chunk chunk = ((CraftChunk) bukkitChunk).getHandle();
        chunk.tileEntities.values().stream().filter(tileEntity -> tileEntity instanceof TileEntityMobSpawner).forEach(tileEntity -> {
            NBTTagCompound nbtTagCompound = new NBTTagCompound();
            tileEntity.b(nbtTagCompound);
            nbtTagCompound.setShort("RequiredPlayerRange", (short) 16);
            tileEntity.a(nbtTagCompound);
        });
    }
}
Also used : ChunkLoader(com.bgsoftware.wildloaders.api.loaders.ChunkLoader) NBTTagList(net.minecraft.server.v1_8_R3.NBTTagList) NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound) HashMap(java.util.HashMap) IUpdatePlayerListBox(net.minecraft.server.v1_8_R3.IUpdatePlayerListBox) ArrayList(java.util.ArrayList) WChunkLoader(com.bgsoftware.wildloaders.loaders.WChunkLoader) Location(org.bukkit.Location) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld) Map(java.util.Map) TileEntityMobSpawner(net.minecraft.server.v1_8_R3.TileEntityMobSpawner) WildLoadersPlugin(com.bgsoftware.wildloaders.WildLoadersPlugin) LongHash(org.bukkit.craftbukkit.v1_8_R3.util.LongHash) ITileEntityChunkLoader(com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader) ItemStack(net.minecraft.server.v1_8_R3.ItemStack) TileEntity(net.minecraft.server.v1_8_R3.TileEntity) Hologram(com.bgsoftware.wildloaders.api.holograms.Hologram) CraftItemStack(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack) NBTTagLong(net.minecraft.server.v1_8_R3.NBTTagLong) CraftChunk(org.bukkit.craftbukkit.v1_8_R3.CraftChunk) Collection(java.util.Collection) UUID(java.util.UUID) Block(net.minecraft.server.v1_8_R3.Block) World(net.minecraft.server.v1_8_R3.World) List(java.util.List) Chunk(net.minecraft.server.v1_8_R3.Chunk) ChunkLoaderNPC(com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC) BlockPosition(net.minecraft.server.v1_8_R3.BlockPosition) Collections(java.util.Collections) NBTTagString(net.minecraft.server.v1_8_R3.NBTTagString) BlockPosition(net.minecraft.server.v1_8_R3.BlockPosition) NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld) World(net.minecraft.server.v1_8_R3.World) CraftChunk(org.bukkit.craftbukkit.v1_8_R3.CraftChunk) Chunk(net.minecraft.server.v1_8_R3.Chunk) ITileEntityChunkLoader(com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader) TileEntityMobSpawner(net.minecraft.server.v1_8_R3.TileEntityMobSpawner) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld) CraftChunk(org.bukkit.craftbukkit.v1_8_R3.CraftChunk) Location(org.bukkit.Location)

Aggregations

WildLoadersPlugin (com.bgsoftware.wildloaders.WildLoadersPlugin)8 Hologram (com.bgsoftware.wildloaders.api.holograms.Hologram)8 ChunkLoader (com.bgsoftware.wildloaders.api.loaders.ChunkLoader)8 ChunkLoaderNPC (com.bgsoftware.wildloaders.api.npc.ChunkLoaderNPC)8 ITileEntityChunkLoader (com.bgsoftware.wildloaders.loaders.ITileEntityChunkLoader)8 WChunkLoader (com.bgsoftware.wildloaders.loaders.WChunkLoader)8 Collection (java.util.Collection)8 Collections (java.util.Collections)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 UUID (java.util.UUID)8 Location (org.bukkit.Location)8 ArrayList (java.util.ArrayList)6 List (java.util.List)6 TileEntityMobSpawner (net.minecraft.server.v1_16_R3.TileEntityMobSpawner)6 TileEntityMobSpawner (net.minecraft.server.v1_12_R1.TileEntityMobSpawner)5 BlockPosition (net.minecraft.server.v1_16_R3.BlockPosition)4 BlockPosition (net.minecraft.server.v1_12_R1.BlockPosition)3 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)3 TileEntityMobSpawner (net.minecraft.server.v1_16_R2.TileEntityMobSpawner)3