use of net.minecraft.server.v1_8_R3.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 "";
}
use of net.minecraft.server.v1_8_R3.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;
}
use of net.minecraft.server.v1_8_R3.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;
}
use of net.minecraft.server.v1_8_R3.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);
}
use of net.minecraft.server.v1_8_R3.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);
});
}
}
Aggregations