Search in sources :

Example 41 with TileEntity

use of net.minecraft.server.v1_15_R1.TileEntity in project TheAPI by TheDevTec.

the class v1_8_R1 method setBlock.

@SuppressWarnings("unchecked")
@Override
public void setBlock(Object chunk, int x, int y, int z, Object IblockData, int data) {
    net.minecraft.server.v1_8_R1.Chunk c = (net.minecraft.server.v1_8_R1.Chunk) chunk;
    ChunkSection sc = c.getSections()[y >> 4];
    if (sc == null) {
        c.getSections()[y >> 4] = sc = new ChunkSection(y >> 4 << 4, true);
    }
    BlockPosition pos = new BlockPosition(x, y, z);
    // REMOVE TILE ENTITY
    c.tileEntities.remove(pos);
    sc.setType(x & 15, y & 15, z & 15, (IBlockData) IblockData);
    // ADD TILE ENTITY
    if (IblockData instanceof IContainer) {
        TileEntity ent = ((IContainer) IblockData).a(c.world, 0);
        c.tileEntities.put(pos, ent);
        Object packet = ent.getUpdatePacket();
        Bukkit.getOnlinePlayers().forEach(player -> BukkitLoader.getPacketHandler().send(player, packet));
    }
}
Also used : TileEntity(net.minecraft.server.v1_8_R1.TileEntity) BlockPosition(net.minecraft.server.v1_8_R1.BlockPosition) Chunk(org.bukkit.Chunk) CraftChunk(org.bukkit.craftbukkit.v1_8_R1.CraftChunk) IContainer(net.minecraft.server.v1_8_R1.IContainer) ChunkSection(net.minecraft.server.v1_8_R1.ChunkSection)

Example 42 with TileEntity

use of net.minecraft.server.v1_15_R1.TileEntity in project TheAPI by TheDevTec.

the class v1_16_R3 method setBlock.

@Override
public void setBlock(Object chunk, int x, int y, int z, Object IblockData, int data) {
    net.minecraft.server.v1_16_R3.Chunk c = (net.minecraft.server.v1_16_R3.Chunk) chunk;
    ChunkSection sc = c.getSections()[y >> 4];
    if (sc == null) {
        c.getSections()[y >> 4] = sc = new ChunkSection(y >> 4 << 4);
    }
    BlockPosition pos = new BlockPosition(x, y, z);
    // REMOVE TILE ENTITY
    c.tileEntities.remove(pos);
    sc.getBlocks().b(x & 15, y & 15, z & 15, (IBlockData) IblockData);
    // ADD TILE ENTITY
    if (IblockData instanceof ITileEntity) {
        TileEntity ent = ((ITileEntity) IblockData).createTile(c);
        c.tileEntities.put(pos, ent);
        Object packet = ent.getUpdatePacket();
        Bukkit.getOnlinePlayers().forEach(player -> BukkitLoader.getPacketHandler().send(player, packet));
    }
}
Also used : TileEntity(net.minecraft.server.v1_16_R3.TileEntity) ITileEntity(net.minecraft.server.v1_16_R3.ITileEntity) ITileEntity(net.minecraft.server.v1_16_R3.ITileEntity) BlockPosition(net.minecraft.server.v1_16_R3.BlockPosition) Chunk(org.bukkit.Chunk) CraftChunk(org.bukkit.craftbukkit.v1_16_R3.CraftChunk) ChunkSection(net.minecraft.server.v1_16_R3.ChunkSection)

Example 43 with TileEntity

use of net.minecraft.server.v1_15_R1.TileEntity in project TheAPI by TheDevTec.

the class v1_9_R1 method setBlock.

@Override
public void setBlock(Object chunk, int x, int y, int z, Object IblockData, int data) {
    net.minecraft.server.v1_9_R1.Chunk c = (net.minecraft.server.v1_9_R1.Chunk) chunk;
    ChunkSection sc = c.getSections()[y >> 4];
    if (sc == null) {
        c.getSections()[y >> 4] = sc = new ChunkSection(y >> 4 << 4, true);
    }
    BlockPosition pos = new BlockPosition(x, y, z);
    // REMOVE TILE ENTITY
    c.tileEntities.remove(pos);
    sc.getBlocks().setBlock(x & 15, y & 15, z & 15, (IBlockData) IblockData);
    // ADD TILE ENTITY
    if (IblockData instanceof ITileEntity) {
        TileEntity ent = ((ITileEntity) IblockData).a(c.world, 0);
        c.tileEntities.put(pos, ent);
        Object packet = ent.getUpdatePacket();
        Bukkit.getOnlinePlayers().forEach(player -> BukkitLoader.getPacketHandler().send(player, packet));
    }
}
Also used : TileEntity(net.minecraft.server.v1_9_R1.TileEntity) ITileEntity(net.minecraft.server.v1_9_R1.ITileEntity) ITileEntity(net.minecraft.server.v1_9_R1.ITileEntity) BlockPosition(net.minecraft.server.v1_9_R1.BlockPosition) CraftChunk(org.bukkit.craftbukkit.v1_9_R1.CraftChunk) Chunk(org.bukkit.Chunk) ChunkSection(net.minecraft.server.v1_9_R1.ChunkSection)

Example 44 with TileEntity

use of net.minecraft.server.v1_15_R1.TileEntity in project PublicCrafters by BananaPuncher714.

the class ContainerManager_v1_15_R1 method openWorkbench.

@Override
public void openWorkbench(Player player, Location loc, InventoryType type) {
    TileInventory tileEntity = new TileInventory(new CustomTileEntityContainerWorkbench(this, loc), new ChatMessage("container.crafting", new Object[0]));
    ((CraftPlayer) player).getHandle().openContainer(tileEntity);
}
Also used : ChatMessage(net.minecraft.server.v1_15_R1.ChatMessage) TileInventory(net.minecraft.server.v1_15_R1.TileInventory)

Example 45 with TileEntity

use of net.minecraft.server.v1_15_R1.TileEntity 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     *
    // *******************************************
    BlockPosition translateVector = locationToPosition(displacement);
    List<BlockPosition> positions = new ArrayList<>(craft.getHitBox().size());
    craft.getHitBox().forEach((movecraftLocation) -> positions.add(locationToPosition((movecraftLocation)).b(translateVector)));
    WorldServer oldNativeWorld = ((CraftWorld) craft.getWorld()).getHandle();
    World 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++) {
        BlockPosition position = positions.get(i);
        if (oldNativeWorld.getType(position) == Blocks.AIR.getBlockData())
            continue;
        // TileEntity tile = nativeWorld.removeTileEntity(position);
        TileEntity tile = removeTileEntity(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<IBlockData> blockData = new ArrayList<>();
    List<BlockPosition> newPositions = new ArrayList<>();
    for (int i = 0, positionsSize = positions.size(); i < positionsSize; i++) {
        BlockPosition position = positions.get(i);
        blockData.add(oldNativeWorld.getType(position));
        newPositions.add(position.a(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);
        moveTileEntity(nativeWorld, tileHolder.getTilePosition().a(translateVector), tileHolder.getTile());
        if (tileHolder.getNextTick() == null)
            continue;
        final long currentTime = nativeWorld.worldData.getTime();
        nativeWorld.getBlockTickList().a(tileHolder.getNextTick().a.a(translateVector), (Block) tileHolder.getNextTick().b(), (int) (tileHolder.getNextTick().b - currentTime), tileHolder.getNextTick().c);
    }
    // *******************************************
    // *   Step five: Destroy the leftovers      *
    // *******************************************
    List<BlockPosition> deletePositions = positions;
    if (oldNativeWorld == nativeWorld)
        deletePositions = CollectionUtils.filter(positions, newPositions);
    for (int i = 0, deletePositionsSize = deletePositions.size(); i < deletePositionsSize; i++) {
        BlockPosition position = deletePositions.get(i);
        setBlockFast(oldNativeWorld, position, Blocks.AIR.getBlockData());
    }
}
Also used : BlockPosition(net.minecraft.server.v1_16_R3.BlockPosition) ArrayList(java.util.ArrayList) WorldServer(net.minecraft.server.v1_16_R3.WorldServer) World(net.minecraft.server.v1_16_R3.World) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) TileEntity(net.minecraft.server.v1_16_R3.TileEntity) IBlockData(net.minecraft.server.v1_16_R3.IBlockData) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld)

Aggregations

Chunk (org.bukkit.Chunk)15 Location (org.bukkit.Location)14 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)10 Map (java.util.Map)10 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 UUID (java.util.UUID)8 TileEntity (net.minecraft.server.v1_12_R1.TileEntity)8 BlockPosition (net.minecraft.server.v1_16_R3.BlockPosition)8 TileEntity (net.minecraft.server.v1_16_R3.TileEntity)8 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)7 List (java.util.List)6 BlockPosition (net.minecraft.server.v1_12_R1.BlockPosition)6