Search in sources :

Example 11 with BlockPosition

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;
    }
}
Also used : AxisAlignedBB(net.minecraft.world.phys.AxisAlignedBB) BlockPosition(net.minecraft.core.BlockPosition) ComplexCollisionBox(cc.funkemunky.api.utils.world.types.ComplexCollisionBox) CraftBlock(org.bukkit.craftbukkit.v1_18_R1.block.CraftBlock) World(net.minecraft.world.level.World) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld) SimpleCollisionBox(cc.funkemunky.api.utils.world.types.SimpleCollisionBox) IBlockData(net.minecraft.world.level.block.state.IBlockData) VoxelShape(net.minecraft.world.phys.shapes.VoxelShape) CraftBlock(org.bukkit.craftbukkit.v1_18_R1.block.CraftBlock) Block(net.minecraft.world.level.block.Block) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld)

Example 12 with BlockPosition

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);
}
Also used : Random(java.util.Random) BlockPosition(net.minecraft.core.BlockPosition) WorldServer(net.minecraft.server.level.WorldServer) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld) DefinedStructureInfo(net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructureInfo)

Example 13 with BlockPosition

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);
            }
        }
    }
}
Also used : Random(java.util.Random) BlockPosition(net.minecraft.core.BlockPosition) WorldServer(net.minecraft.server.level.WorldServer) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld) DefinedStructureInfo(net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructureInfo)

Example 14 with BlockPosition

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);
        }
    }
}
Also used : TileEntityChest(net.minecraft.world.level.block.entity.TileEntityChest) BlockPosition(net.minecraft.core.BlockPosition) Material(org.bukkit.Material) TileEntityEnderChest(net.minecraft.world.level.block.entity.TileEntityEnderChest) World(net.minecraft.world.level.World) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld)

Example 15 with BlockPosition

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;
}
Also used : DefinedStructure(net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructure) BlockPosition(net.minecraft.core.BlockPosition) WorldServer(net.minecraft.server.level.WorldServer) CraftWorld(org.bukkit.craftbukkit.v1_18_R2.CraftWorld) Location(org.bukkit.Location)

Aggregations

BlockPosition (net.minecraft.core.BlockPosition)18 World (net.minecraft.world.level.World)10 WorldServer (net.minecraft.server.level.WorldServer)8 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)7 TileEntityChest (net.minecraft.world.level.block.entity.TileEntityChest)6 CraftWorld (org.bukkit.craftbukkit.v1_18_R2.CraftWorld)6 IBlockData (net.minecraft.world.level.block.state.IBlockData)5 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)5 Location (org.bukkit.Location)4 ComplexCollisionBox (cc.funkemunky.api.utils.world.types.ComplexCollisionBox)2 SimpleCollisionBox (cc.funkemunky.api.utils.world.types.SimpleCollisionBox)2 StringReader (com.mojang.brigadier.StringReader)2 Random (java.util.Random)2 ArgumentBlock (net.minecraft.commands.arguments.blocks.ArgumentBlock)2 ArgumentTileLocation (net.minecraft.commands.arguments.blocks.ArgumentTileLocation)2 EntityPlayer (net.minecraft.server.level.EntityPlayer)2 ItemStack (net.minecraft.world.item.ItemStack)2 Block (net.minecraft.world.level.block.Block)2 TileEntity (net.minecraft.world.level.block.entity.TileEntity)2 DefinedStructure (net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructure)2