use of net.minecraft.server.v1_15_R1.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);
}
use of net.minecraft.server.v1_15_R1.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());
}
}
use of net.minecraft.server.v1_15_R1.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);
}
use of net.minecraft.server.v1_15_R1.IBlockData in project acidisland by tastybento.
the class NMSHandler method setBlockSuperFast.
@Override
public void setBlockSuperFast(Block b, int blockId, byte data, boolean applyPhysics) {
net.minecraft.server.v1_9_R1.World w = ((CraftWorld) b.getWorld()).getHandle();
net.minecraft.server.v1_9_R1.Chunk chunk = w.getChunkAt(b.getX() >> 4, b.getZ() >> 4);
BlockPosition bp = new BlockPosition(b.getX(), b.getY(), b.getZ());
int combined = blockId + (data << 12);
IBlockData ibd = net.minecraft.server.v1_9_R1.Block.getByCombinedId(combined);
if (applyPhysics) {
w.setTypeAndData(bp, ibd, 3);
} else {
w.setTypeAndData(bp, ibd, 2);
}
chunk.a(bp, ibd);
}
use of net.minecraft.server.v1_15_R1.IBlockData in project acidisland by tastybento.
the class NMSHandler method setBlockSuperFast.
@Override
public void setBlockSuperFast(Block b, int blockId, byte data, boolean applyPhysics) {
net.minecraft.server.v1_11_R1.World w = ((CraftWorld) b.getWorld()).getHandle();
net.minecraft.server.v1_11_R1.Chunk chunk = w.getChunkAt(b.getX() >> 4, b.getZ() >> 4);
BlockPosition bp = new BlockPosition(b.getX(), b.getY(), b.getZ());
int combined = blockId + (data << 12);
IBlockData ibd = net.minecraft.server.v1_11_R1.Block.getByCombinedId(combined);
if (applyPhysics) {
w.setTypeAndData(bp, ibd, 3);
} else {
w.setTypeAndData(bp, ibd, 2);
}
chunk.a(bp, ibd);
}
Aggregations