Search in sources :

Example 1 with ArgumentBlock

use of net.minecraft.commands.arguments.blocks.ArgumentBlock 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 2 with ArgumentBlock

use of net.minecraft.commands.arguments.blocks.ArgumentBlock 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

StringReader (com.mojang.brigadier.StringReader)2 ArgumentBlock (net.minecraft.commands.arguments.blocks.ArgumentBlock)2 ArgumentTileLocation (net.minecraft.commands.arguments.blocks.ArgumentTileLocation)2 BlockPosition (net.minecraft.core.BlockPosition)2 WorldServer (net.minecraft.server.level.WorldServer)2 IBlockData (net.minecraft.world.level.block.state.IBlockData)1 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)1 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)1