When a neighbour block changes and the block is powered and it isn't triggered (powered:1b) it will set its state to triggered and schedule a block update. If it isn't powered and triggered then it will be set itself as not triggered.
boolean isPowered = worldIn.isBlockPowered(pos);
boolean triggeredState = ((Boolean)state.getValue(TRIGGERED_PROP)).booleanValue();
if (isPowered && !triggeredState)
{
worldIn.setBlockState(pos, state.withProperty(TRIGGERED_PROP, Boolean.valueOf(true)), 4);
worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn));
}
else if (!isPowered && triggeredState)
{
worldIn.setBlockState(pos, state.withProperty(TRIGGERED_PROP, Boolean.valueOf(false)), 4);
}
When the block update happens the command will execute:
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
TileEntity blockTileEntity = worldIn.getTileEntity(pos);
if (blockTileEntity instanceof TileEntityCommandBlock)
{
((TileEntityCommandBlock)blockTileEntity).getCommandBlockLogic().trigger(worldIn);
worldIn.updateComparatorOutputLevel(pos, this);
}
}
"CommandBlockLogic.java":
public void trigger(World worldIn)
{
MinecraftServer server = MinecraftServer.getServer();
if (server.isCommandBlocksEnabled())
{
ICommandManager commandManager = server.getCommandManager();
this.lastOutput = null;
this.successCount = commandManager.executeCommand(this, this.commandStored);
}
else
{
this.successCount = 0;
}
}
In 1.9 I'm guessing they've added an if-statement to the trigger function to check what kind of command block it is executing from and if the block is powered. Why can't they just add a !
there? Please explain.