
/*
 * Copyright 2011-2022 Cuberite Contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include "RedstoneSimulatorChunkData.h"





class cChunk;
class ForEachSourceCallback;





namespace RedstoneHandler
{
	/** Asks a redstone component at the source position how much power it will deliver to the querying position.
	If IsLinked is true, QueryPosition should point to the intermediate conduit block.
	The Position and QueryPosition are both relative to Chunk. */
	PowerLevel GetPowerDeliveredToPosition(const cChunk & Chunk, Vector3i Position, BLOCKTYPE BlockType, Vector3i QueryPosition, BLOCKTYPE QueryBlockType, bool IsLinked);

	/** Tells a redstone component at this position to update itself.
	PowerLevel represents the maximum power level all of its source positions gave to it.
	Position is relative to Chunk, but if the component needs to queue neighbour updates, they are queued to CurrentlyTicking. */
	void Update(cChunk & Chunk, cChunk & CurrentlyTicking, Vector3i Position, BLOCKTYPE BlockType, NIBBLETYPE Meta, PowerLevel PowerLevel);

	/** Invokes Callback for each position this component can accept power from. */
	void ForValidSourcePositions(const cChunk & Chunk, Vector3i Position, BLOCKTYPE BlockType, NIBBLETYPE Meta, ForEachSourceCallback & Callback);

	/** Temporary: compute and set the block state of a redstone wire. */
	void SetWireState(const cChunk & Chunk, Vector3i Position);
}
