Deprecate old boolean constructor and move existing usages

This commit is contained in:
altrisi committed 2021-05-24 11:41:24 +02:00
1 parent 1b39feaab7
commit 9d9844fd5d
14 files changed
+59 -47

No files matched your search

@@ -452,7 +452,7 @@ public class Auxiliary {
if (lv.get(0).isNull()) return Value.FALSE;
Tag source = ((NBTSerializableValue)(NBTSerializableValue.fromValue(lv.get(0)))).getTag();
Tag match = ((NBTSerializableValue)(NBTSerializableValue.fromValue(lv.get(1)))).getTag();
return new NumericValue(NbtHelper.matches(match, source, numParam == 2 || lv.get(2).getBoolean()));
return BooleanValue.of(NbtHelper.matches(match, source, numParam == 2 || lv.get(2).getBoolean()));
});
expression.addFunction("encode_nbt", lv -> {
@@ -776,7 +776,7 @@ public class Auxiliary {
return;
if (what.equalsIgnoreCase("boulder")) // there might be more of those
WorldTools.forceChunkUpdate(locator.block.getPos(), ((CarpetContext) c).s.getWorld());
result[0] = new NumericValue(res);
result[0] = BooleanValue.of(res);
});
return result[0];
});
@@ -194,7 +194,7 @@ public class Inventories {
CarpetContext cc = (CarpetContext) c;
NBTSerializableValue.InventoryLocator inventoryLocator = NBTSerializableValue.locateInventory(cc, lv, 0);
if (inventoryLocator == null) return Value.NULL;
return new NumericValue(!inventoryLocator.inventory.isEmpty());
return BooleanValue.of(!inventoryLocator.inventory.isEmpty());
});
//inventory_get(<b, e>, <n>) -> item_triple
@@ -8,6 +8,7 @@ import carpet.script.LazyValue;
import carpet.script.exception.InternalExpressionException;
import carpet.script.exception.ThrowStatement;
import carpet.script.exception.Throwables;
import carpet.script.value.BooleanValue;
import carpet.script.value.EntityValue;
import carpet.script.value.ListValue;
import carpet.script.value.NullValue;
@@ -301,7 +302,7 @@ public class Scoreboards {
Value playerVal = lv.get(0);
String player = EntityValue.getPlayerNameByValue(playerVal);
if(player == null) return Value.NULL;
return new NumericValue(scoreboard.clearPlayerTeam(player));
return BooleanValue.of(scoreboard.clearPlayerTeam(player));
});
expression.addContextFunction("team_property", -1, (c, t, lv) ->
@@ -357,7 +358,7 @@ public class Scoreboards {
team.setDisplayName(displayName);
break;
case "friendlyFire":
if(!modifying) return new NumericValue(team.isFriendlyFireAllowed());
if(!modifying) return BooleanValue.of(team.isFriendlyFireAllowed());
if(!(settingVal instanceof NumericValue)) throw new InternalExpressionException("'team_property' requires a boolean as the third argument for the property " + propertyVal.getString());
boolean friendlyFire = settingVal.getBoolean();
team.setFriendlyFireAllowed(friendlyFire);
@@ -378,7 +379,7 @@ public class Scoreboards {
team.setPrefix(prefix);
break;
case "seeFriendlyInvisibles":
if(!modifying) return new NumericValue(team.shouldShowFriendlyInvisibles());
if(!modifying) return BooleanValue.of(team.shouldShowFriendlyInvisibles());
if(!(settingVal instanceof NumericValue)) throw new InternalExpressionException("'team_property' requires a boolean as the third argument for the property " + propertyVal.getString());
boolean seeFriendlyInvisibles = settingVal.getBoolean();
team.setShowFriendlyInvisibles(seeFriendlyInvisibles);
@@ -500,7 +501,7 @@ public class Scoreboards {
bossBar.setValue(((NumericValue) propertyValue).getInt());
return Value.TRUE;
case "visible":
if(propertyValue == null) return new NumericValue(bossBar.isVisible());
if(propertyValue == null) return BooleanValue.of(bossBar.isVisible());
bossBar.setVisible(propertyValue.getBoolean());
return Value.TRUE;
@@ -492,7 +492,7 @@ public class WorldAccess {
});
expression.addContextFunction("solid", -1, (c, t, lv) ->
genericStateTest(c, "solid", lv, (s, p, w) -> new NumericValue(s.isSolidBlock(w, p)))); // isSimpleFullBlock
genericStateTest(c, "solid", lv, (s, p, w) -> BooleanValue.of(s.isSolidBlock(w, p)))); // isSimpleFullBlock
expression.addContextFunction("air", -1, (c, t, lv) ->
booleanStateTest(c, "air", lv, (s, p) -> s.isAir()));
@@ -525,7 +525,7 @@ public class WorldAccess {
genericStateTest(c, "sky_light", lv, (s, p, w) -> new NumericValue(w.getLightLevel(LightType.SKY, p))));
expression.addContextFunction("see_sky", -1, (c, t, lv) ->
genericStateTest(c, "see_sky", lv, (s, p, w) -> new NumericValue(w.isSkyVisible(p))));
genericStateTest(c, "see_sky", lv, (s, p, w) -> BooleanValue.of(w.isSkyVisible(p))));
expression.addContextFunction("brightness", -1, (c, t, lv) ->
genericStateTest(c, "brightness", lv, (s, p, w) -> new NumericValue(w.getBrightness(p))));
@@ -540,7 +540,7 @@ public class WorldAccess {
{
BlockPos pos = BlockArgument.findIn((CarpetContext)c, lv, 0).block.getPos();
ChunkPos chunkPos = new ChunkPos(pos);
return new NumericValue(ChunkRandom.getSlimeRandom(
return BooleanValue.of(ChunkRandom.getSlimeRandom(
chunkPos.x, chunkPos.z,
((CarpetContext)c).s.getWorld().getSeed(),
987234911L
@@ -593,7 +593,7 @@ public class WorldAccess {
boolean force = false;
if (lv.size() > locator.offset)
force = lv.get(locator.offset).getBoolean();
return new NumericValue(canHasChunk(((CarpetContext)c).s.getWorld(), new ChunkPos(pos), null, force));
return BooleanValue.of(canHasChunk(((CarpetContext)c).s.getWorld(), new ChunkPos(pos), null, force));
});
expression.addContextFunction("generation_status", -1, (c, t, lv) ->
@@ -653,7 +653,7 @@ public class WorldAccess {
});
expression.addContextFunction("suffocates", -1, (c, t, lv) ->
genericStateTest(c, "suffocates", lv, (s, p, w) -> new NumericValue(s.shouldSuffocate(w, p)))); // canSuffocate
genericStateTest(c, "suffocates", lv, (s, p, w) -> BooleanValue.of(s.shouldSuffocate(w, p)))); // canSuffocate
expression.addContextFunction("power", -1, (c, t, lv) ->
genericStateTest(c, "power", lv, (s, p, w) -> new NumericValue(w.getReceivedRedstonePower(p))));