use of net.countercraft.movecraft.MovecraftRotation in project Movecraft by APDevTeam.
the class IWorldHandler method rotateCraft.
// @Override
// public void addPlayerLocation(Player player, double x, double y, double z, float yaw, float pitch){
// ServerPlayer ePlayer = ((CraftPlayer) player).getHandle();
// ePlayer.connection.teleport(x, y, z, yaw, pitch, EnumSet.allOf(ClientboundPlayerPositionPacket.RelativeArgument.class));
// }
@Override
public void rotateCraft(@NotNull Craft craft, @NotNull MovecraftLocation originPoint, @NotNull MovecraftRotation rotation) {
// *******************************************
// * Step one: Convert to Positions *
// *******************************************
HashMap<BlockPos, BlockPos> 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 *
// *******************************************
ServerLevel nativeWorld = ((CraftWorld) craft.getWorld()).getHandle();
List<TileHolder> tiles = new ArrayList<>();
// get the tiles
for (BlockPos position : rotatedPositions.keySet()) {
// BlockEntity tile = nativeWorld.removeBlockEntity(position);
BlockEntity tile = removeBlockEntity(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<BlockPos, BlockState> blockData = new HashMap<>();
for (BlockPos position : rotatedPositions.keySet()) {
blockData.put(position, nativeWorld.getBlockState(position).rotate(ROTATION[rotation.ordinal()]));
}
// create the new block
for (Map.Entry<BlockPos, BlockState> entry : blockData.entrySet()) {
setBlockFast(nativeWorld, rotatedPositions.get(entry.getKey()), entry.getValue());
}
// TODO: go by chunks
for (TileHolder tileHolder : tiles) {
moveBlockEntity(nativeWorld, rotatedPositions.get(tileHolder.getTilePosition()), tileHolder.getTile());
if (tileHolder.getNextTick() == null)
continue;
final long currentTime = nativeWorld.E.getGameTime();
nativeWorld.getBlockTickList().scheduleTick(rotatedPositions.get(tileHolder.getNextTick().pos), (Block) tileHolder.getNextTick().getType(), (int) (tileHolder.getNextTick().triggerTick - currentTime), tileHolder.getNextTick().priority);
}
// *******************************************
// * Step five: Destroy the leftovers *
// *******************************************
// TODO: add support for pass-through
Collection<BlockPos> deletePositions = CollectionUtils.filter(rotatedPositions.keySet(), rotatedPositions.values());
for (BlockPos position : deletePositions) {
setBlockFast(nativeWorld, position, Blocks.AIR.defaultBlockState());
}
}
use of net.countercraft.movecraft.MovecraftRotation in project Movecraft by APDevTeam.
the class IWorldHandler method rotateCraft.
// @Override
// public void addPlayerLocation(Player player, double x, double y, double z, float yaw, float pitch){
// ServerPlayer ePlayer = ((CraftPlayer) player).getHandle();
// ePlayer.connection.teleport(x, y, z, yaw, pitch, EnumSet.allOf(ClientboundPlayerPositionPacket.RelativeArgument.class));
// }
@Override
public void rotateCraft(@NotNull Craft craft, @NotNull MovecraftLocation originPoint, @NotNull MovecraftRotation rotation) {
// *******************************************
// * Step one: Convert to Positions *
// *******************************************
HashMap<BlockPos, BlockPos> 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 *
// *******************************************
ServerLevel nativeWorld = ((CraftWorld) craft.getWorld()).getHandle();
List<TileHolder> tiles = new ArrayList<>();
// get the tiles
for (BlockPos position : rotatedPositions.keySet()) {
// BlockEntity tile = nativeWorld.removeBlockEntity(position);
BlockEntity tile = removeBlockEntity(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<BlockPos, BlockState> blockData = new HashMap<>();
for (BlockPos position : rotatedPositions.keySet()) {
blockData.put(position, nativeWorld.getBlockState(position).rotate(ROTATION[rotation.ordinal()]));
}
// create the new block
for (Map.Entry<BlockPos, BlockState> entry : blockData.entrySet()) {
setBlockFast(nativeWorld, rotatedPositions.get(entry.getKey()), entry.getValue());
}
// TODO: go by chunks
for (TileHolder tileHolder : tiles) {
moveBlockEntity(nativeWorld, rotatedPositions.get(tileHolder.getTilePosition()), tileHolder.getTile());
if (tileHolder.getNextTick() == null)
continue;
final long currentTime = nativeWorld.M.getGameTime();
nativeWorld.getBlockTicks().schedule(new ScheduledTick<>((Block) tileHolder.getNextTick().type(), rotatedPositions.get(tileHolder.getNextTick().pos()), tileHolder.getNextTick().triggerTick() - currentTime, tileHolder.getNextTick().priority(), tileHolder.getNextTick().subTickOrder()));
}
// *******************************************
// * Step five: Destroy the leftovers *
// *******************************************
// TODO: add support for pass-through
Collection<BlockPos> deletePositions = CollectionUtils.filter(rotatedPositions.keySet(), rotatedPositions.values());
for (BlockPos position : deletePositions) {
setBlockFast(nativeWorld, position, Blocks.AIR.defaultBlockState());
}
}
Aggregations