use of net.minecraft.core.BlockPosition in project Atlas by funkemunky.
the class BlockBox1_18_R1 method getCollisionBox.
@Override
public CollisionBox getCollisionBox(org.bukkit.block.Block block) {
final World world = ((org.bukkit.craftbukkit.v1_18_R1.CraftWorld) block.getWorld()).getHandle();
final int x = block.getX(), y = block.getY(), z = block.getZ();
IBlockData iblockData = ((CraftBlock) block).getNMS();
Block vblock = iblockData.b();
BlockPosition blockPos = new BlockPosition(x, y, z);
VoxelShape shape = vblock.a(iblockData, world, blockPos, VoxelShapeCollision.a());
List<AxisAlignedBB> boxes = shape.d();
if (boxes.size() == 0) {
return BlockData.getData(block.getType()).getBox(block, ProtocolVersion.getGameVersion());
} else if (boxes.size() == 1) {
AxisAlignedBB box = boxes.get(0);
return new SimpleCollisionBox(box.a, box.b, box.c, box.d, box.e, box.f);
} else {
ComplexCollisionBox complexBox = new ComplexCollisionBox();
for (AxisAlignedBB box : boxes) {
complexBox.add(new SimpleCollisionBox(box.a, box.b, box.c, box.d, box.e, box.f));
}
return complexBox;
}
}
use of net.minecraft.core.BlockPosition in project Crazy-Crates by Crazy-Crew.
the class StructureService method insertSingleStructure.
/**
* Pastes a single structure into the world
* @param structure - The structure to be pasted
* @param startEdge - The starting corner with the lowest x, y, z coordinates
* @param rotation - You may rotate the structure by 90 degrees steps
*/
public static void insertSingleStructure(DefinedStructure structure, Location startEdge, EnumBlockRotation rotation) {
WorldServer world = ((CraftWorld) startEdge.getWorld()).getHandle();
DefinedStructureInfo structInfo = new DefinedStructureInfo().a(EnumBlockMirror.a).a(rotation).a(false).a().c(false).a(new Random());
BlockPosition blockPosition = new BlockPosition(startEdge.getBlockX(), startEdge.getBlockY(), startEdge.getBlockZ());
structure.a(world, blockPosition, blockPosition, structInfo, random, 0);
}
use of net.minecraft.core.BlockPosition in project Crazy-Crates by Crazy-Crew.
the class StructureService method insertStructuresArray.
/**
* Pastes an array of structures into the world
* @param structures - A one dimensional array of structures, sorted by y, z, x (iterates along x, then z, then y)
* @param dimensions - The width, height, length of the complete resulting area
* @param startEdge - The starting edge with the lowest x, y, z coordinates
* @param rotation - You may rotate the structure by 90 degrees steps
*/
public static void insertStructuresArray(DefinedStructure[] structures, int[] dimensions, Location startEdge, EnumBlockRotation rotation) {
int[] areas = getAreaSections(dimensions);
WorldServer world = ((CraftWorld) startEdge.getWorld()).getHandle();
for (int x = 0; x < areas[0]; x++) {
for (int y = 0; y < areas[1]; y++) {
for (int z = 0; z < areas[2]; z++) {
DefinedStructureInfo structInfo = new DefinedStructureInfo().a(EnumBlockMirror.a).a(rotation).a(false).a().c(false).a(new Random());
BlockPosition pos = new BlockPosition((x * 32) + startEdge.getBlockX(), (y * 32) + startEdge.getBlockY(), (z * 32) + startEdge.getBlockZ());
structures[getYzxIndex(x, y, z, areas[0], areas[2])].a(world, pos, pos, structInfo, random, z);
}
}
}
}
use of net.minecraft.core.BlockPosition in project Crazy-Crates by Crazy-Crew.
the class NMS_Support method openChest.
@Override
public void openChest(Block block, boolean open) {
Material type = block.getType();
if (type == Material.CHEST || type == Material.TRAPPED_CHEST || type == Material.ENDER_CHEST) {
World world = ((CraftWorld) block.getWorld()).getHandle();
BlockPosition position = new BlockPosition(block.getX(), block.getY(), block.getZ());
if (block.getType() == Material.ENDER_CHEST) {
TileEntityEnderChest tileChest = (TileEntityEnderChest) world.getBlockEntity(position, false);
world.a(position, tileChest.q(), 1, open ? 1 : 0);
} else {
TileEntityChest tileChest = (TileEntityChest) world.getBlockEntity(position, false);
world.a(position, tileChest.q(), 1, open ? 1 : 0);
}
}
}
use of net.minecraft.core.BlockPosition in project Crazy-Crates by Crazy-Crew.
the class StructureService method createStructuresArray.
/**
* Splits up an area in 32x32x32 structures, creates those and fills an array with them
* @param corners - 2 Edges of the area (order doesn't matter)
* @param author - The listed author of the structure
* @return DefinedStructure[] - The structures in a one dimensional array, sorted by y, z, x (iterates along x, then z, then y)
*/
public static DefinedStructure[] createStructuresArray(Location[] corners, String author) {
if (corners.length != 2)
throw new IllegalArgumentException("An area needs to be set up by exactly 2 opposite edges!");
Location[] normalized = normalizeEdges(corners[0], corners[1]);
WorldServer world = ((CraftWorld) normalized[0].getWorld()).getHandle();
int[] dimensions = getDimensions(normalized);
int[] areas = getAreaSections(dimensions);
DefinedStructure[] structures = new DefinedStructure[areas[0] * areas[1] * areas[2]];
for (int x = 0; x < areas[0]; x++) {
for (int y = 0; y < areas[1]; y++) {
for (int z = 0; z < areas[2]; z++) {
DefinedStructure structure = new DefinedStructure();
int width, height, length;
if (x == areas[0] - 1 && dimensions[0] % 32 != 0)
width = dimensions[0] % 32;
else
width = 32;
if (y == areas[1] - 1 && dimensions[1] % 32 != 0)
height = dimensions[1] % 32;
else
height = 32;
if (z == areas[2] - 1 && dimensions[2] % 32 != 0)
length = dimensions[2] % 32;
else
length = 32;
structure.a(world, new BlockPosition((x * 32) + normalized[0].getBlockX(), (y * 32) + normalized[0].getBlockY(), (z * 32) + normalized[0].getBlockZ()), new BlockPosition(width, height, length), true, Blocks.jb);
structure.a(author);
structures[getYzxIndex(x, y, z, areas[0], areas[2])] = structure;
}
}
}
return structures;
}
Aggregations