Jump to content

How can I write a command into a newly spawned command block


Jessica04

Recommended Posts

Hello, I am spawning a command block into the world with the following:
 

mc.world.setBlockState(blockPos, blockState);

which works just fine.

if (blockState.getBlock() == Blocks.COMMAND_BLOCK){
                    System.out.println("String thats passed in: " + commandLine);
                    setCommandString(mc.world, blockPos, blockState, commandLine);
                }
private static void setCommandString(World world, BlockPos pos, BlockState state, String command){
        System.out.println("SetCommandString String: " + command);
        TileEntity tileentity = world.getTileEntity(pos);
        System.out.println("TileEntitySet: " + tileentity);
        if (tileentity instanceof CommandBlockTileEntity) {
            CommandBlockTileEntity commandblocktileentity = (CommandBlockTileEntity) tileentity;
            CommandBlockLogic commandblocklogic = commandblocktileentity.getCommandBlockLogic();
            System.out.println("Here!!!!!!!!!!!!!!!!!");

            commandblocklogic.setCommand(command);
            tileentity.markDirty();
            world.notifyBlockUpdate(pos, state, state, 3);
//            CompoundNBT nbt = new CompoundNBT();
//            nbt.putString("Command", command);
//            commandblocklogic.write(nbt);
//            commandblocktileentity.write(nbt);
        }
    }

As you can see here, I am trying to "setCommand", however when I check the newly spawned command block, it has nothing written inside of it. Any thoughts on this?

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.