block_state can accept string block name as well.

This commit is contained in:
gnembon committed 2020-11-27 15:50:57 -04:00
1 parent 07dce7bc2e
commit 6206753198
2 files changed
+5 -2

No files matched your search

+4 -1
View File
@@ -248,15 +248,18 @@ Deprecated by `block_state(pos, name)`
If used with a `block` argument only, it returns a map of block properties and their values. If a block has no properties, returns an If used with a `block` argument only, it returns a map of block properties and their values. If a block has no properties, returns an
empty map. empty map.
If `property` is specified, returns value of that property, or `null` if property is not applicable. If `property` is specified, returns a string value of that property, or `null` if property is not applicable.
Returned values or properties are always strings. It is expected from the user to know what to expect and convert Returned values or properties are always strings. It is expected from the user to know what to expect and convert
values to numbers using `number()` function or booleans using `bool()` function. Returned string values can be directly used values to numbers using `number()` function or booleans using `bool()` function. Returned string values can be directly used
back in state definition in various applications where block properties are required. back in state definition in various applications where block properties are required.
`block_state` can also accept block names as input, returning block's default state.
<pre> <pre>
set(x,y,z,'iron_trapdoor','half','top'); block_state(x,y,z) => {waterlogged: false, half: top, open: false, ...} set(x,y,z,'iron_trapdoor','half','top'); block_state(x,y,z) => {waterlogged: false, half: top, open: false, ...}
set(x,y,z,'iron_trapdoor','half','top'); block_state(x,y,z,'half') => top set(x,y,z,'iron_trapdoor','half','top'); block_state(x,y,z,'half') => top
block_state('iron_trapdoor','half') => top
set(x,y,z,'air'); block_state(x,y,z,'half') => null set(x,y,z,'air'); block_state(x,y,z,'half') => null
block_state(block('iron_trapdoor[half=top]'),'half') => top block_state(block('iron_trapdoor[half=top]'),'half') => top
block_state(block('iron_trapdoor[half=top]'),'powered') => false block_state(block('iron_trapdoor[half=top]'),'powered') => false
@@ -997,7 +997,7 @@ public class WorldAccess {
// block_state(block, property) // block_state(block, property)
expression.addLazyFunction("block_state", -1, (c, t, lv) -> expression.addLazyFunction("block_state", -1, (c, t, lv) ->
{ {
BlockArgument locator = BlockArgument.findIn((CarpetContext) c, lv, 0); BlockArgument locator = BlockArgument.findIn((CarpetContext) c, lv, 0, true);
BlockState state = locator.block.getBlockState(); BlockState state = locator.block.getBlockState();
StateManager<Block, BlockState> states = state.getBlock().getStateManager(); StateManager<Block, BlockState> states = state.getBlock().getStateManager();
if (locator.offset == lv.size()) if (locator.offset == lv.size())