use of net.minecraft.server.v1_14_R1.Block in project MechanicsMain by WeaponMechanics.
the class v1_11_R1 method getHitBox.
@Override
public HitBox getHitBox(org.bukkit.block.Block block) {
if (block.isEmpty() || block.isLiquid())
return null;
WorldServer worldServer = ((CraftWorld) block.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(block.getX(), block.getY(), block.getZ());
IBlockData blockData = worldServer.getType(blockPosition);
Block nmsBlock = blockData.getBlock();
// Passable block check -> false means passable (thats why !)
if (!(blockData.d(worldServer, blockPosition) != Block.k && nmsBlock.a(blockData, false)))
return null;
AxisAlignedBB aabb = blockData.d(worldServer, blockPosition);
// 1.12 -> e
// 1.11 -> d
// 1.9 - 1.10 -> c
int x = blockPosition.getX(), y = blockPosition.getY(), z = blockPosition.getZ();
HitBox hitBox = new HitBox(x + aabb.a, y + aabb.b, z + aabb.c, x + aabb.d, y + aabb.e, z + aabb.f);
hitBox.setBlockHitBox(block);
return hitBox;
}
use of net.minecraft.server.v1_14_R1.Block in project MechanicsMain by WeaponMechanics.
the class v1_12_R1 method getHitBox.
@Override
public HitBox getHitBox(org.bukkit.block.Block block) {
if (block.isEmpty() || block.isLiquid())
return null;
WorldServer worldServer = ((CraftWorld) block.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(block.getX(), block.getY(), block.getZ());
IBlockData blockData = worldServer.getType(blockPosition);
Block nmsBlock = blockData.getBlock();
// Passable block check -> false means passable (thats why !)
if (!(blockData.d(worldServer, blockPosition) != Block.k && nmsBlock.a(blockData, false)))
return null;
AxisAlignedBB aabb = blockData.e(worldServer, blockPosition);
// 1.12 -> e
// 1.11 -> d
// 1.9 - 1.10 -> c
int x = blockPosition.getX(), y = blockPosition.getY(), z = blockPosition.getZ();
HitBox hitBox = new HitBox(x + aabb.a, y + aabb.b, z + aabb.c, x + aabb.d, y + aabb.e, z + aabb.f);
hitBox.setBlockHitBox(block);
return hitBox;
}
use of net.minecraft.server.v1_14_R1.Block in project MechanicsMain by WeaponMechanics.
the class v1_14_R1 method getHitBox.
@Override
public HitBox getHitBox(Block block) {
if (block.isEmpty() || block.isLiquid() || block.isPassable())
return null;
BoundingBox boundingBox = block.getBoundingBox();
HitBox hitBox = new HitBox(boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ(), boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMaxZ());
hitBox.setBlockHitBox(block);
if (WeaponMechanics.getBasicConfigurations().getBool("Check_Accurate_Hitboxes", true)) {
CraftBlock craftBlock = (CraftBlock) block;
List<AxisAlignedBB> voxelShape = craftBlock.getNMS().getCollisionShape(craftBlock.getCraftWorld().getHandle(), craftBlock.getPosition()).d();
if (voxelShape.size() > 1) {
int x = block.getX();
int y = block.getY();
int z = block.getZ();
for (AxisAlignedBB boxPart : voxelShape) {
hitBox.addVoxelShapePart(new HitBox(x + boxPart.minX, y + boxPart.minY, z + boxPart.minZ, x + boxPart.maxX, y + boxPart.maxY, z + boxPart.maxZ));
}
}
}
return hitBox;
}
use of net.minecraft.server.v1_14_R1.Block in project Movecraft by APDevTeam.
the class IWorldHandler method setBlockFast.
private void setBlockFast(@NotNull World world, @NotNull BlockPosition position, @NotNull IBlockData data) {
Chunk chunk = world.getChunkAtWorldCoords(position);
ChunkSection chunkSection = chunk.getSections()[position.getY() >> 4];
if (chunkSection == null) {
// Put a GLASS block to initialize the section. It will be replaced next with the real block.
chunk.setType(position, Blocks.GLASS.getBlockData(), false);
chunkSection = chunk.getSections()[position.getY() >> 4];
}
if (chunkSection.getType(position.getX() & 15, position.getY() & 15, position.getZ() & 15).equals(data)) {
// Block is already of correct type and data, don't overwrite
return;
}
chunkSection.setType(position.getX() & 15, position.getY() & 15, position.getZ() & 15, data);
world.notify(position, data, data, 3);
var engine = chunk.e();
if (engine != null)
engine.a(position);
chunk.markDirty();
}
use of net.minecraft.server.v1_14_R1.Block 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());
}
}
Aggregations