Added 'Redstone Lamp' alternative using states. WIP.
This commit is contained in:
parent
5b77f61298
commit
d68e17a521
@ -208,7 +208,7 @@ To get the current state of a block:
|
||||
local block_param = world:get_data(pos.x, pos.y, pos.z)
|
||||
local current_state = block:param():get_param(BlockParamType.State, block_param)
|
||||
-- if you don't
|
||||
local current_state = world:get_block_state(pos.x, pos.y, pos.z)
|
||||
local current_state = world:get_block_state(pos.x, pos.y, pos.z):id()
|
||||
```
|
||||
|
||||
To set the current state of a block:
|
||||
|
@ -36,6 +36,12 @@
|
||||
- `BlockParamType.State`
|
||||
- `BlockParamType.Count`
|
||||
|
||||
## BlockState
|
||||
|
||||
- `u16 id()`
|
||||
- `std::string label()`
|
||||
- `ItemStack get_item_drop()`
|
||||
|
||||
## Chunk
|
||||
|
||||
- `u16 get_block(int x, int y, int z)`
|
||||
|
@ -306,6 +306,21 @@ mod:block {
|
||||
end,
|
||||
}
|
||||
|
||||
mod:block {
|
||||
id = "redstone_lamp",
|
||||
name = "Redstone Lamp (with states)",
|
||||
tiles = "redstone_lamp_off.png",
|
||||
|
||||
states = {
|
||||
{ is_light_source = true, tiles = "redstone_lamp_on.png" }
|
||||
},
|
||||
|
||||
on_block_activated = function(pos, block, player, world, client, server, screen_width, screen_height, gui_scale)
|
||||
local current_state = math.abs(world:get_block_state(pos.x, pos.y, pos.z):id() - 1)
|
||||
world:set_block_state(pos.x, pos.y, pos.z, current_state)
|
||||
end
|
||||
}
|
||||
|
||||
mod:block {
|
||||
id = "redstone_lamp_off",
|
||||
name = "Redstone Lamp",
|
||||
|
@ -57,6 +57,7 @@ bool BlockState::isOpaque() const {
|
||||
// Please update 'docs/lua-api-cpp.md' if you change this
|
||||
void BlockState::initUsertype(sol::state &lua) {
|
||||
lua.new_usertype<BlockState>("BlockState",
|
||||
"id", &BlockState::id,
|
||||
"label", (const std::string &(BlockState::*)() const)&BlockState::label,
|
||||
"get_item_drop", &BlockState::getItemDrop
|
||||
);
|
||||
|
@ -165,6 +165,21 @@ void Chunk::setBlockState(int x, int y, int z, u16 stateID) {
|
||||
u16 blockID = getBlock(x, y, z);
|
||||
u16 blockParam = getData(x, y, z);
|
||||
const Block &block = Registry::getInstance().getBlock(blockID);
|
||||
const BlockState &blockState = block.getState(block.param().hasParam(BlockParam::State)
|
||||
? block.param().getParam(BlockParam::State, blockParam) : 0);
|
||||
const BlockState &newBlockState = block.getState(block.param().hasParam(BlockParam::State)
|
||||
? stateID : 0);
|
||||
|
||||
if (!blockState.isLightSource() && newBlockState.isLightSource()) {
|
||||
m_lightmap.addTorchlight(x, y, z, 14);
|
||||
}
|
||||
else if (blockState.isLightSource() && !newBlockState.isLightSource()) {
|
||||
gkDebug() << block.stringID();
|
||||
|
||||
m_lightmap.removeTorchlight(x, y, z);
|
||||
m_lightmap.removeSunlight(x, y, z);
|
||||
}
|
||||
|
||||
if (block.param().hasParam(BlockParam::State))
|
||||
setData(x, y, z, block.param().setParam(BlockParam::State, blockParam, stateID));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user