Search in sources :

Example 6 with BlockPosition

use of net.minecraft.core.BlockPosition in project SSB-OneBlock by BG-Software-LLC.

the class NMSAdapter_v1_18_R1 method simulateToolBreak.

@Override
public void simulateToolBreak(Player bukkitPlayer, org.bukkit.block.Block bukkitBlock) {
    EntityPlayer entityPlayer = ((CraftPlayer) bukkitPlayer).getHandle();
    ItemStack itemStack = entityPlayer.er();
    WorldServer worldServer = ((CraftWorld) bukkitBlock.getWorld()).getHandle();
    BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
    IBlockData blockData = worldServer.a_(blockPosition);
    itemStack.a(worldServer, blockData, blockPosition, entityPlayer);
}
Also used : IBlockData(net.minecraft.world.level.block.state.IBlockData) BlockPosition(net.minecraft.core.BlockPosition) EntityPlayer(net.minecraft.server.level.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) WorldServer(net.minecraft.server.level.WorldServer) ItemStack(net.minecraft.world.item.ItemStack) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld)

Example 7 with BlockPosition

use of net.minecraft.core.BlockPosition in project Atlas by funkemunky.

the class BlockBox1_17_R1 method getCollisionBox.

@Override
public CollisionBox getCollisionBox(org.bukkit.block.Block block) {
    final World world = ((org.bukkit.craftbukkit.v1_17_R1.CraftWorld) block.getWorld()).getHandle();
    final int x = block.getX(), y = block.getY(), z = block.getZ();
    IBlockData iblockData = ((CraftBlock) block).getNMS();
    Block vblock = iblockData.getBlock();
    BlockPosition blockPos = new BlockPosition(x, y, z);
    VoxelShape shape = vblock.a(iblockData, world, blockPos, VoxelShapeCollision.a());
    List<AxisAlignedBB> boxes = shape.toList();
    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_17_R1.block.CraftBlock) World(net.minecraft.world.level.World) CraftWorld(org.bukkit.craftbukkit.v1_17_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_17_R1.block.CraftBlock) Block(net.minecraft.world.level.block.Block) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld)

Example 8 with BlockPosition

use of net.minecraft.core.BlockPosition in project SSB-OneBlock by BG-Software-LLC.

the class NMSAdapter_v1_18_R1 method setChestName.

@Override
public void setChestName(Location chest, String name) {
    assert chest.getWorld() != null;
    World world = ((CraftWorld) chest.getWorld()).getHandle();
    BlockPosition blockPosition = new BlockPosition(chest.getBlockX(), chest.getBlockY(), chest.getBlockZ());
    TileEntityChest tileEntityChest = (TileEntityChest) world.c_(blockPosition);
    assert tileEntityChest != null;
    tileEntityChest.a(CraftChatMessage.fromString(name)[0]);
}
Also used : TileEntityChest(net.minecraft.world.level.block.entity.TileEntityChest) BlockPosition(net.minecraft.core.BlockPosition) World(net.minecraft.world.level.World) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld)

Example 9 with BlockPosition

use of net.minecraft.core.BlockPosition in project SSB-OneBlock by BG-Software-LLC.

the class NMSAdapter_v1_18_R1 method setBlock.

@Override
public void setBlock(Location location, Material type, byte data, String nbt) {
    assert location.getWorld() != null;
    WorldServer worldServer = ((CraftWorld) location.getWorld()).getHandle();
    BlockPosition blockPosition = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
    worldServer.m(blockPosition);
    location.getBlock().setType(type);
    if (nbt != null) {
        try {
            ArgumentBlock argumentBlock = new ArgumentBlock(new StringReader(nbt), false).a(true);
            IBlockData blockData = argumentBlock.b();
            if (blockData != null) {
                ArgumentTileLocation tileLocation = new ArgumentTileLocation(blockData, argumentBlock.a().keySet(), argumentBlock.c());
                tileLocation.a(worldServer, blockPosition, 2);
                worldServer.a(blockPosition, tileLocation.a().b());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
Also used : ArgumentTileLocation(net.minecraft.commands.arguments.blocks.ArgumentTileLocation) IBlockData(net.minecraft.world.level.block.state.IBlockData) ArgumentBlock(net.minecraft.commands.arguments.blocks.ArgumentBlock) BlockPosition(net.minecraft.core.BlockPosition) StringReader(com.mojang.brigadier.StringReader) WorldServer(net.minecraft.server.level.WorldServer) CraftWorld(org.bukkit.craftbukkit.v1_18_R1.CraftWorld)

Example 10 with BlockPosition

use of net.minecraft.core.BlockPosition in project SSB-OneBlock by BG-Software-LLC.

the class NMSAdapter_v1_17_R1 method setBlock.

@Override
public void setBlock(Location location, Material type, byte data, String nbt) {
    assert location.getWorld() != null;
    WorldServer worldServer = ((CraftWorld) location.getWorld()).getHandle();
    BlockPosition blockPosition = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
    worldServer.removeTileEntity(blockPosition);
    location.getBlock().setType(type);
    if (nbt != null) {
        try {
            ArgumentBlock argumentBlock = new ArgumentBlock(new StringReader(nbt), false).a(true);
            ArgumentTileLocation tileLocation = new ArgumentTileLocation(argumentBlock.getBlockData(), argumentBlock.getStateMap().keySet(), argumentBlock.c());
            tileLocation.a(worldServer, blockPosition, 2);
            worldServer.update(blockPosition, tileLocation.a().getBlock());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
Also used : ArgumentTileLocation(net.minecraft.commands.arguments.blocks.ArgumentTileLocation) ArgumentBlock(net.minecraft.commands.arguments.blocks.ArgumentBlock) BlockPosition(net.minecraft.core.BlockPosition) StringReader(com.mojang.brigadier.StringReader) WorldServer(net.minecraft.server.level.WorldServer) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld)

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