added block_state, deprecated block_properties and property
This commit is contained in:
1 parent
b997fa0f9f
commit
b8ca302d33
5 files changed
+65
-14
No files matched your search
@@ -958,6 +958,8 @@ public class WorldAccess {
|
||||
stateStringQuery(c, "map_colour", lv, (s, p) ->
|
||||
BlockInfo.mapColourName.get(s.getTopMaterialColor(((CarpetContext)c).s.getWorld(), p))));
|
||||
|
||||
|
||||
// Deprecated for block_state()
|
||||
expression.addLazyFunction("property", -1, (c, t, lv) ->
|
||||
{
|
||||
BlockArgument locator = BlockArgument.findIn((CarpetContext) c, lv, 0);
|
||||
@@ -973,6 +975,7 @@ public class WorldAccess {
|
||||
return (_c, _t) -> retval;
|
||||
});
|
||||
|
||||
// Deprecated for block_state()
|
||||
expression.addLazyFunction("block_properties", -1, (c, t, lv) ->
|
||||
{
|
||||
BlockArgument locator = BlockArgument.findIn((CarpetContext) c, lv, 0);
|
||||
@@ -984,6 +987,31 @@ public class WorldAccess {
|
||||
return (_c, _t) -> res;
|
||||
});
|
||||
|
||||
// block_state(block)
|
||||
// block_state(block, property)
|
||||
expression.addLazyFunction("block_state", -1, (c, t, lv) ->
|
||||
{
|
||||
BlockArgument locator = BlockArgument.findIn((CarpetContext) c, lv, 0);
|
||||
BlockState state = locator.block.getBlockState();
|
||||
StateManager<Block, BlockState> states = state.getBlock().getStateManager();
|
||||
if (locator.offset == lv.size())
|
||||
{
|
||||
Map<Value,Value> properties = new HashMap<>();
|
||||
for(Property<?> p : states.getProperties())
|
||||
{
|
||||
properties.put(StringValue.of(p.getName()), ValueConversions.fromProperty(state, p));// ValueConversions.fromObject(state.get(p), false));
|
||||
}
|
||||
Value ret = MapValue.wrap(properties);
|
||||
return (_c, _t) -> ret;
|
||||
}
|
||||
String tag = lv.get(locator.offset).evalValue(c).getString();
|
||||
Property<?> property = states.getProperty(tag);
|
||||
if (property == null)
|
||||
return LazyValue.NULL;
|
||||
Value retval = ValueConversions.fromProperty(state, property);
|
||||
return (_c, _t) -> retval;
|
||||
});
|
||||
|
||||
expression.addLazyFunction("biome", -1, (c, t, lv) -> {
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
BlockArgument locator = BlockArgument.findIn(cc, lv, 0);
|
||||
|
||||
@@ -2,6 +2,7 @@ package carpet.script.value;
|
||||
|
||||
import carpet.script.exception.InternalExpressionException;
|
||||
import carpet.utils.BlockInfo;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.MaterialColor;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.ai.brain.LookTarget;
|
||||
@@ -17,10 +18,12 @@ import net.minecraft.scoreboard.ScoreboardObjective;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
|
||||
import net.minecraft.state.property.Property;
|
||||
import net.minecraft.structure.StructurePiece;
|
||||
import net.minecraft.structure.StructureStart;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import net.minecraft.util.StringIdentifiable;
|
||||
import net.minecraft.util.dynamic.GlobalPos;
|
||||
import net.minecraft.util.math.BlockBox;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -316,4 +319,15 @@ public class ValueConversions
|
||||
ret.put(new StringValue("pieces"), ListValue.wrap(pieces));
|
||||
return MapValue.wrap(ret);
|
||||
}
|
||||
|
||||
public static Value fromProperty(BlockState state, Property<?> p)
|
||||
{
|
||||
Comparable<?> object = state.get(p);
|
||||
if (object instanceof Boolean || object instanceof Number) return StringValue.of(object.toString());
|
||||
if (object instanceof StringIdentifiable)
|
||||
{
|
||||
return StringValue.of(((StringIdentifiable) object).asString());
|
||||
}
|
||||
throw new InternalExpressionException("Unknown property type: "+p.getName());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user