diff --git a/docs/scarpet/api/BlocksAndWorldAccess.md b/docs/scarpet/api/BlocksAndWorldAccess.md index 1cd183ec..36a706c1 100644 --- a/docs/scarpet/api/BlocksAndWorldAccess.md +++ b/docs/scarpet/api/BlocksAndWorldAccess.md @@ -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 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 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. +`block_state` can also accept block names as input, returning block's default state. +
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
+block_state('iron_trapdoor','half') => top
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]'),'powered') => false
diff --git a/src/main/java/carpet/script/api/WorldAccess.java b/src/main/java/carpet/script/api/WorldAccess.java
index 8c1417c5..ee1ac0b5 100644
--- a/src/main/java/carpet/script/api/WorldAccess.java
+++ b/src/main/java/carpet/script/api/WorldAccess.java
@@ -997,7 +997,7 @@ public class WorldAccess {
// block_state(block, property)
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();
StateManager states = state.getBlock().getStateManager();
if (locator.offset == lv.size())