Search in sources :

Example 41 with CraftWorld

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);
}
Also used : Entity(net.minecraft.server.v1_9_R2.Entity) NBTTagCompound(net.minecraft.server.v1_9_R2.NBTTagCompound) PacketPlayOutEntityHeadRotation(net.minecraft.server.v1_9_R2.PacketPlayOutEntityHeadRotation) CraftPlayer(org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer) CraftWorld(org.bukkit.craftbukkit.v1_9_R2.CraftWorld) World(net.minecraft.server.v1_9_R2.World) CraftWorld(org.bukkit.craftbukkit.v1_9_R2.CraftWorld)

Example 42 with CraftWorld

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);
}
Also used : Entity(net.minecraft.server.v1_10_R1.Entity) NBTTagCompound(net.minecraft.server.v1_10_R1.NBTTagCompound) PacketPlayOutEntityHeadRotation(net.minecraft.server.v1_10_R1.PacketPlayOutEntityHeadRotation) CraftPlayer(org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer) CraftWorld(org.bukkit.craftbukkit.v1_10_R1.CraftWorld) World(net.minecraft.server.v1_10_R1.World) CraftWorld(org.bukkit.craftbukkit.v1_10_R1.CraftWorld)

Example 43 with CraftWorld

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);
}
Also used : Entity(net.minecraft.server.v1_11_R1.Entity) NBTTagCompound(net.minecraft.server.v1_11_R1.NBTTagCompound) PacketPlayOutEntityHeadRotation(net.minecraft.server.v1_11_R1.PacketPlayOutEntityHeadRotation) CraftPlayer(org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer) World(net.minecraft.server.v1_11_R1.World) CraftWorld(org.bukkit.craftbukkit.v1_11_R1.CraftWorld) CraftWorld(org.bukkit.craftbukkit.v1_11_R1.CraftWorld)

Example 44 with CraftWorld

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());
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) ArrayList(java.util.ArrayList) BlockState(net.minecraft.world.level.block.state.BlockState) Block(net.minecraft.world.level.block.Block) BlockPos(net.minecraft.core.BlockPos) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 45 with CraftWorld

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);
}
Also used : CraftBlockData(org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData) BlockState(net.minecraft.world.level.block.state.BlockState) ServerLevel(net.minecraft.server.level.ServerLevel) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld)

Aggregations

ServerLevel (net.minecraft.server.level.ServerLevel)147 Location (org.bukkit.Location)131 CraftWorld (org.bukkit.craftbukkit.v1_18_R2.CraftWorld)111 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)103 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)95 BlockPos (net.minecraft.core.BlockPos)83 CraftWorld (org.bukkit.craftbukkit.v1_12_R1.CraftWorld)74 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)66 ItemStack (org.bukkit.inventory.ItemStack)61 Block (org.bukkit.block.Block)57 LivingEntity (org.bukkit.entity.LivingEntity)54 CraftWorld (org.bukkit.craftbukkit.v1_8_R3.CraftWorld)53 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)47 ArrayList (java.util.ArrayList)43 World (org.bukkit.World)41 CraftWorld (org.bukkit.craftbukkit.v1_11_R1.CraftWorld)39 Entity (org.bukkit.entity.Entity)39 Level (net.minecraft.world.level.Level)38 List (java.util.List)34 GameProfile (com.mojang.authlib.GameProfile)32