Search in sources :

Example 46 with IBlockData

use of net.minecraft.server.v1_16_R3.IBlockData in project Movecraft by APDevTeam.

the class IWorldHandler method rotateCraft.

@Override
public void rotateCraft(@NotNull Craft craft, @NotNull MovecraftLocation originPoint, @NotNull MovecraftRotation rotation) {
    // *******************************************
    // *      Step one: Convert to Positions     *
    // *******************************************
    HashMap<BlockPosition, BlockPosition> rotatedPositions = new HashMap<>();
    MovecraftRotation counterRotation = rotation == MovecraftRotation.CLOCKWISE ? MovecraftRotation.ANTICLOCKWISE : MovecraftRotation.CLOCKWISE;
    for (MovecraftLocation newLocation : craft.getHitBox()) {
        rotatedPositions.put(locationToPosition(MathUtils.rotateVec(counterRotation, newLocation.subtract(originPoint)).add(originPoint)), locationToPosition(newLocation));
    }
    // *******************************************
    // *         Step two: Get the tiles         *
    // *******************************************
    WorldServer nativeWorld = ((CraftWorld) craft.getWorld()).getHandle();
    List<TileHolder> tiles = new ArrayList<>();
    // get the tiles
    for (BlockPosition position : rotatedPositions.keySet()) {
        // TileEntity tile = nativeWorld.removeTileEntity(position);
        TileEntity tile = removeTileEntity(nativeWorld, position);
        if (tile == null)
            continue;
        tile.a(ROTATION[rotation.ordinal()]);
        // get the nextTick to move with the tile
        tiles.add(new TileHolder(tile, tickProvider.getNextTick(nativeWorld, 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 rotate them
    HashMap<BlockPosition, IBlockData> blockData = new HashMap<>();
    for (BlockPosition position : rotatedPositions.keySet()) {
        blockData.put(position, nativeWorld.getType(position).a(ROTATION[rotation.ordinal()]));
    }
    // create the new block
    for (Map.Entry<BlockPosition, IBlockData> entry : blockData.entrySet()) {
        setBlockFast(nativeWorld, rotatedPositions.get(entry.getKey()), entry.getValue());
    }
    // TODO: go by chunks
    for (TileHolder tileHolder : tiles) {
        moveTileEntity(nativeWorld, rotatedPositions.get(tileHolder.getTilePosition()), tileHolder.getTile());
        if (tileHolder.getNextTick() == null)
            continue;
        final long currentTime = nativeWorld.worldData.getTime();
        nativeWorld.getBlockTickList().a(rotatedPositions.get(tileHolder.getNextTick().a), (Block) tileHolder.getNextTick().b(), (int) (tileHolder.getNextTick().b - currentTime), tileHolder.getNextTick().c);
    }
    // *******************************************
    // *   Step five: Destroy the leftovers      *
    // *******************************************
    // TODO: add support for pass-through
    Collection<BlockPosition> deletePositions = CollectionUtils.filter(rotatedPositions.keySet(), rotatedPositions.values());
    for (BlockPosition position : deletePositions) {
        setBlockFast(nativeWorld, position, Blocks.AIR.getBlockData());
    }
}
Also used : HashMap(java.util.HashMap) BlockPosition(net.minecraft.server.v1_16_R3.BlockPosition) ArrayList(java.util.ArrayList) WorldServer(net.minecraft.server.v1_16_R3.WorldServer) MovecraftRotation(net.countercraft.movecraft.MovecraftRotation) TileEntity(net.minecraft.server.v1_16_R3.TileEntity) IBlockData(net.minecraft.server.v1_16_R3.IBlockData) MovecraftLocation(net.countercraft.movecraft.MovecraftLocation) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) HashMap(java.util.HashMap) Map(java.util.Map)

Example 47 with IBlockData

use of net.minecraft.server.v1_16_R3.IBlockData in project Movecraft by APDevTeam.

the class IWorldHandler method setBlockFast.

@Override
public void setBlockFast(@NotNull Location location, @NotNull MovecraftRotation rotation, @NotNull BlockData data) {
    IBlockData blockData;
    if (data instanceof CraftBlockData) {
        blockData = ((CraftBlockData) data).getState();
    } else {
        blockData = (IBlockData) data;
    }
    blockData = blockData.a(ROTATION[rotation.ordinal()]);
    World world = ((CraftWorld) (location.getWorld())).getHandle();
    BlockPosition blockPosition = locationToPosition(bukkit2MovecraftLoc(location));
    setBlockFast(world, blockPosition, blockData);
}
Also used : CraftBlockData(org.bukkit.craftbukkit.v1_16_R3.block.data.CraftBlockData) IBlockData(net.minecraft.server.v1_16_R3.IBlockData) BlockPosition(net.minecraft.server.v1_16_R3.BlockPosition) World(net.minecraft.server.v1_16_R3.World) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld)

Example 48 with IBlockData

use of net.minecraft.server.v1_16_R3.IBlockData in project Movecraft by APDevTeam.

the class IWorldHandler method setBlockFast.

@Override
public void setBlockFast(@NotNull Location location, @NotNull MovecraftRotation rotation, @NotNull BlockData data) {
    IBlockData blockData;
    if (data instanceof CraftBlockData) {
        blockData = ((CraftBlockData) data).getState();
    } else {
        blockData = (IBlockData) data;
    }
    blockData = blockData.a(ROTATION[rotation.ordinal()]);
    World world = ((CraftWorld) (location.getWorld())).getHandle();
    BlockPosition blockPosition = locationToPosition(bukkit2MovecraftLoc(location));
    setBlockFast(world, blockPosition, blockData);
}
Also used : CraftBlockData(org.bukkit.craftbukkit.v1_14_R1.block.data.CraftBlockData) IBlockData(net.minecraft.server.v1_14_R1.IBlockData) BlockPosition(net.minecraft.server.v1_14_R1.BlockPosition) World(net.minecraft.server.v1_14_R1.World) CraftWorld(org.bukkit.craftbukkit.v1_14_R1.CraftWorld) CraftWorld(org.bukkit.craftbukkit.v1_14_R1.CraftWorld)

Example 49 with IBlockData

use of net.minecraft.server.v1_16_R3.IBlockData in project TheAPI by TheDevTec.

the class v1_13_R1 method setBlock.

@Override
public void setBlock(Object chunk, int x, int y, int z, Object IblockData, int data) {
    net.minecraft.server.v1_13_R1.Chunk c = (net.minecraft.server.v1_13_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);
    try {
        DataBits bits = (DataBits) dataBits.get(sc.getBlocks());
        @SuppressWarnings("unchecked") DataPalette<IBlockData> pallete = (DataPalette<IBlockData>) dataPallete.get(sc.getBlocks());
        bits.a(b(x & 15, y & 15, z & 15), pallete.a((IBlockData) IblockData));
    } catch (Exception er) {
    }
    // ADD TILE ENTITY
    if (IblockData instanceof ITileEntity) {
        TileEntity ent = ((ITileEntity) IblockData).a(c);
        c.tileEntities.put(pos, ent);
        Object packet = ent.getUpdatePacket();
        Bukkit.getOnlinePlayers().forEach(player -> BukkitLoader.getPacketHandler().send(player, packet));
    }
}
Also used : ITileEntity(net.minecraft.server.v1_13_R1.ITileEntity) DataBits(net.minecraft.server.v1_13_R1.DataBits) BlockPosition(net.minecraft.server.v1_13_R1.BlockPosition) Chunk(org.bukkit.Chunk) CraftChunk(org.bukkit.craftbukkit.v1_13_R1.CraftChunk) DataPalette(net.minecraft.server.v1_13_R1.DataPalette) TileEntity(net.minecraft.server.v1_13_R1.TileEntity) ITileEntity(net.minecraft.server.v1_13_R1.ITileEntity) IBlockData(net.minecraft.server.v1_13_R1.IBlockData) ChunkSection(net.minecraft.server.v1_13_R1.ChunkSection)

Example 50 with IBlockData

use of net.minecraft.server.v1_16_R3.IBlockData in project TheAPI by TheDevTec.

the class v1_13_R2 method setBlock.

@Override
public void setBlock(Object chunk, int x, int y, int z, Object IblockData, int data) {
    net.minecraft.server.v1_13_R2.Chunk c = (net.minecraft.server.v1_13_R2.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);
    try {
        DataBits bits = (DataBits) dataBits.get(sc.getBlocks());
        @SuppressWarnings("unchecked") DataPalette<IBlockData> pallete = (DataPalette<IBlockData>) dataPallete.get(sc.getBlocks());
        bits.a(b(x & 15, y & 15, z & 15), pallete.a((IBlockData) IblockData));
    } catch (Exception er) {
    }
    // ADD TILE ENTITY
    if (IblockData instanceof ITileEntity) {
        TileEntity ent = ((ITileEntity) IblockData).a(c);
        c.tileEntities.put(pos, ent);
        Object packet = ent.getUpdatePacket();
        Bukkit.getOnlinePlayers().forEach(player -> BukkitLoader.getPacketHandler().send(player, packet));
    }
}
Also used : ITileEntity(net.minecraft.server.v1_13_R2.ITileEntity) DataBits(net.minecraft.server.v1_13_R2.DataBits) BlockPosition(net.minecraft.server.v1_13_R2.BlockPosition) CraftChunk(org.bukkit.craftbukkit.v1_13_R2.CraftChunk) Chunk(org.bukkit.Chunk) DataPalette(net.minecraft.server.v1_13_R2.DataPalette) ITileEntity(net.minecraft.server.v1_13_R2.ITileEntity) TileEntity(net.minecraft.server.v1_13_R2.TileEntity) IBlockData(net.minecraft.server.v1_13_R2.IBlockData) ChunkSection(net.minecraft.server.v1_13_R2.ChunkSection)

Aggregations

HashMap (java.util.HashMap)25 ArrayList (java.util.ArrayList)20 Block (org.bukkit.block.Block)17 List (java.util.List)16 IBlockData (net.minecraft.server.v1_16_R3.IBlockData)16 NotNull (org.jetbrains.annotations.NotNull)16 Chunk (org.bukkit.Chunk)15 IBlockData (net.minecraft.server.v1_14_R1.IBlockData)10 BlockPosition (net.minecraft.server.v1_16_R3.BlockPosition)10 IBlockData (net.minecraft.server.v1_12_R1.IBlockData)9 IBlockData (net.minecraft.server.v1_10_R1.IBlockData)8 BlockPosition (net.minecraft.server.v1_12_R1.BlockPosition)8 IBlockData (net.minecraft.server.v1_15_R1.IBlockData)8 IdentityHashMap (java.util.IdentityHashMap)7 BlockPosition (net.minecraft.server.v1_10_R1.BlockPosition)7 IBlockData (net.minecraft.server.v1_11_R1.IBlockData)7 BlockPosition (net.minecraft.server.v1_11_R1.BlockPosition)6 BlockPosition (net.minecraft.server.v1_14_R1.BlockPosition)6 IBlockData (net.minecraft.server.v1_16_R2.IBlockData)6 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)6