use of net.countercraft.movecraft.MovecraftLocation in project Movecraft by APDevTeam.
the class AtomicLocationSet method contains.
@Override
public boolean contains(Object o) {
if (o instanceof MovecraftLocation) {
MovecraftLocation location = (MovecraftLocation) o;
long packed = location.pack();
var suffix = this.getPrefixLeafIfPresent(packed);
if (suffix == null)
return false;
return suffix.get((int) (packed & LOW_MASK));
}
return false;
}
use of net.countercraft.movecraft.MovecraftLocation in project Movecraft by APDevTeam.
the class CollectionUtils method filter.
@NotNull
@Contract(pure = true)
@Deprecated
public static BitmapHitBox filter(@NotNull final HitBox collection, @NotNull final HitBox filter) {
final BitmapHitBox returnList = new BitmapHitBox();
int counter = filter.size();
for (MovecraftLocation object : collection) {
if (counter <= 0 || !filter.contains(object)) {
returnList.add(object);
} else {
counter--;
}
}
return returnList;
}
use of net.countercraft.movecraft.MovecraftLocation in project Movecraft by APDevTeam.
the class CollectionUtils method filter.
@NotNull
@Contract(pure = true)
@Deprecated
public static Collection<MovecraftLocation> filter(@NotNull final HitBox collection, @NotNull final Collection<MovecraftLocation> filter) {
final Collection<MovecraftLocation> returnList = new HashSet<>();
final HashSet<MovecraftLocation> filterSet = new HashSet<>(filter);
for (MovecraftLocation object : collection) {
if (!filterSet.contains(object)) {
returnList.add(object);
}
}
return returnList;
}
use of net.countercraft.movecraft.MovecraftLocation 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.countercraft.movecraft.MovecraftLocation in project Movecraft by APDevTeam.
the class LocationTrieSet method contains.
@Override
public boolean contains(Object o) {
if (o instanceof MovecraftLocation) {
MovecraftLocation location = (MovecraftLocation) o;
long packed = location.pack();
return contains(packed);
}
return false;
}
Aggregations