use of org.bukkit.craftbukkit.v1_16_R2.CraftWorld in project SilkSpawners by timbru31.
the class NMSHandler method spawnEntity.
@Override
public void spawnEntity(final org.bukkit.World w, final String entityID, final double x, final double y, final double z, final Player player) {
final NBTTagCompound tag = new NBTTagCompound();
tag.setString("id", entityID);
final World world = ((CraftWorld) w).getHandle();
final Entity entity = EntityTypes.a(tag, world);
if (entity == null) {
Bukkit.getLogger().warning("[SilkSpawners] Failed to spawn, falling through. You should report this (entity == null)!");
return;
}
final float yaw = world.random.nextFloat() * (-180 - 180) + 180;
entity.setPositionRotation(x, y, z, yaw, 0);
world.addEntity(entity, SpawnReason.SPAWNER_EGG);
final PacketPlayOutEntityHeadRotation rotation = new PacketPlayOutEntityHeadRotation(entity, (byte) yaw);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(rotation);
}
use of org.bukkit.craftbukkit.v1_16_R2.CraftWorld in project SilkSpawners by timbru31.
the class NMSHandler method spawnEntity.
@Override
public void spawnEntity(final org.bukkit.World w, final String entityID, final double x, final double y, final double z, final Player player) {
final NBTTagCompound tag = new NBTTagCompound();
tag.setString("id", entityID);
final World world = ((CraftWorld) w).getHandle();
final Entity entity = EntityTypes.a(tag, world);
if (entity == null) {
Bukkit.getLogger().warning("[SilkSpawners] Failed to spawn, falling through. You should report this (entity == null)!");
return;
}
final float yaw = world.random.nextFloat() * (-180 - 180) + 180;
entity.setPositionRotation(x, y, z, yaw, 0);
world.addEntity(entity, SpawnReason.SPAWNER_EGG);
final PacketPlayOutEntityHeadRotation rotation = new PacketPlayOutEntityHeadRotation(entity, (byte) yaw);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(rotation);
}
use of org.bukkit.craftbukkit.v1_16_R2.CraftWorld in project SilkSpawners by timbru31.
the class NMSHandler method spawnEntity.
@Override
public void spawnEntity(final org.bukkit.World w, final String entityID, final double x, final double y, final double z, final Player player) {
final NBTTagCompound tag = new NBTTagCompound();
tag.setString("id", entityID);
final World world = ((CraftWorld) w).getHandle();
final Entity entity = EntityTypes.a(tag, world);
if (entity == null) {
Bukkit.getLogger().warning("[SilkSpawners] Failed to spawn, falling through. You should report this (entity == null)!");
return;
}
final float yaw = world.random.nextFloat() * (-180 - 180) + 180;
entity.setPositionRotation(x, y, z, yaw, 0);
world.addEntity(entity, SpawnReason.SPAWNER_EGG);
final PacketPlayOutEntityHeadRotation rotation = new PacketPlayOutEntityHeadRotation(entity, (byte) yaw);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(rotation);
}
use of org.bukkit.craftbukkit.v1_16_R2.CraftWorld in project Movecraft by APDevTeam.
the class IWorldHandler method translateCraft.
@Override
public void translateCraft(@NotNull Craft craft, @NotNull MovecraftLocation displacement, @NotNull org.bukkit.World world) {
// TODO: Add support for rotations
// A craftTranslateCommand should only occur if the craft is moving to a valid position
// *******************************************
// * Step one: Convert to Positions *
// *******************************************
BlockPos translateVector = locationToPosition(displacement);
List<BlockPos> positions = new ArrayList<>(craft.getHitBox().size());
craft.getHitBox().forEach((movecraftLocation) -> positions.add(locationToPosition((movecraftLocation)).subtract(translateVector)));
ServerLevel oldNativeWorld = ((CraftWorld) craft.getWorld()).getHandle();
ServerLevel nativeWorld = ((CraftWorld) world).getHandle();
// *******************************************
// * Step two: Get the tiles *
// *******************************************
List<TileHolder> tiles = new ArrayList<>();
// get the tiles
for (int i = 0, positionsSize = positions.size(); i < positionsSize; i++) {
BlockPos position = positions.get(i);
if (oldNativeWorld.getBlockState(position) == Blocks.AIR.defaultBlockState())
continue;
// BlockEntity tile = nativeWorld.removeBlockEntity(position);
BlockEntity tile = removeBlockEntity(oldNativeWorld, position);
if (tile == null)
continue;
// get the nextTick to move with the tile
// nativeWorld.capturedTileEntities.remove(position);
// nativeWorld.getChunkAtWorldCoords(position).getTileEntities().remove(position);
tiles.add(new TileHolder(tile, tickProvider.getNextTick(oldNativeWorld, position), position));
}
// *******************************************
// * Step three: Translate all the blocks *
// *******************************************
// blockedByWater=false means an ocean-going vessel
// TODO: Simplify
// TODO: go by chunks
// TODO: Don't move unnecessary blocks
// get the blocks and translate the positions
List<BlockState> blockData = new ArrayList<>();
List<BlockPos> newPositions = new ArrayList<>();
for (int i = 0, positionsSize = positions.size(); i < positionsSize; i++) {
BlockPos position = positions.get(i);
blockData.add(oldNativeWorld.getBlockState(position));
newPositions.add(position.offset(translateVector));
}
// create the new block
for (int i = 0, positionSize = newPositions.size(); i < positionSize; i++) {
setBlockFast(nativeWorld, newPositions.get(i), blockData.get(i));
}
// TODO: go by chunks
for (int i = 0, tilesSize = tiles.size(); i < tilesSize; i++) {
TileHolder tileHolder = tiles.get(i);
moveBlockEntity(nativeWorld, tileHolder.getTilePosition().offset(translateVector), tileHolder.getTile());
if (tileHolder.getNextTick() == null)
continue;
final long currentTime = nativeWorld.getGameTime();
nativeWorld.getBlockTicks().schedule(new ScheduledTick<>((Block) tileHolder.getNextTick().type(), tileHolder.getTilePosition().offset(translateVector), tileHolder.getNextTick().triggerTick() - currentTime, tileHolder.getNextTick().priority(), tileHolder.getNextTick().subTickOrder()));
}
// *******************************************
// * Step five: Destroy the leftovers *
// *******************************************
List<BlockPos> deletePositions = positions;
if (oldNativeWorld == nativeWorld)
deletePositions = CollectionUtils.filter(positions, newPositions);
for (int i = 0, deletePositionsSize = deletePositions.size(); i < deletePositionsSize; i++) {
BlockPos position = deletePositions.get(i);
setBlockFast(oldNativeWorld, position, Blocks.AIR.defaultBlockState());
}
}
use of org.bukkit.craftbukkit.v1_16_R2.CraftWorld in project Movecraft by APDevTeam.
the class IWorldHandler method setBlockFast.
@Override
public void setBlockFast(@NotNull Location location, @NotNull MovecraftRotation rotation, @NotNull BlockData data) {
BlockState blockData;
if (data instanceof CraftBlockData) {
blockData = ((CraftBlockData) data).getState();
} else {
blockData = (BlockState) data;
}
blockData = blockData.rotate(ROTATION[rotation.ordinal()]);
Level world = ((CraftWorld) (location.getWorld())).getHandle();
BlockPos BlockPos = locationToPosition(MathUtils.bukkit2MovecraftLoc(location));
setBlockFast(world, BlockPos, blockData);
}
Aggregations