From 7b77fb08531ca3858ecfeaa296d6e983a0e943ec Mon Sep 17 00:00:00 2001 From: altrisi Date: Mon, 14 Dec 2020 18:36:24 +0100 Subject: [PATCH 1/7] Add FormattedText addition --- .../carpet/script/value/FormattedTextValue.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/carpet/script/value/FormattedTextValue.java b/src/main/java/carpet/script/value/FormattedTextValue.java index 218575ca..529c340a 100644 --- a/src/main/java/carpet/script/value/FormattedTextValue.java +++ b/src/main/java/carpet/script/value/FormattedTextValue.java @@ -48,10 +48,25 @@ public class FormattedTextValue extends StringValue return StringTag.of(Text.Serializer.toJson(text)); } + @Override + public Value add(Value o) { + if (o instanceof FormattedTextValue) + { + Text mergedText = ((BaseText) text).shallowCopy().append(((FormattedTextValue) o).getText()); + return new FormattedTextValue(mergedText); + } + else + { + Text mergedText = ((BaseText) text).shallowCopy().append(o.getString()); + return new FormattedTextValue(mergedText); + } + } + public String serialize() { return Text.Serializer.toJson(text); } + public static FormattedTextValue deserialize(String serialized) { return new FormattedTextValue(Text.Serializer.fromJson(serialized)); From 6dfd64027d78dd9affd9502ac1e217ed203ab936 Mon Sep 17 00:00:00 2001 From: altrisi Date: Mon, 14 Dec 2020 19:20:21 +0100 Subject: [PATCH 2/7] Add FormattedText functionality to the right of the operand --- .../java/carpet/script/value/FormattedTextValue.java | 2 +- src/main/java/carpet/script/value/Value.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/carpet/script/value/FormattedTextValue.java b/src/main/java/carpet/script/value/FormattedTextValue.java index 529c340a..70546d71 100644 --- a/src/main/java/carpet/script/value/FormattedTextValue.java +++ b/src/main/java/carpet/script/value/FormattedTextValue.java @@ -27,7 +27,7 @@ public class FormattedTextValue extends StringValue @Override public Value clone() { - return new FormattedTextValue(text); + return new FormattedTextValue(text.shallowCopy()); } @Override diff --git a/src/main/java/carpet/script/value/Value.java b/src/main/java/carpet/script/value/Value.java index 679a9263..93e32183 100644 --- a/src/main/java/carpet/script/value/Value.java +++ b/src/main/java/carpet/script/value/Value.java @@ -4,6 +4,8 @@ import carpet.script.exception.InternalExpressionException; import com.google.gson.JsonElement; import com.google.gson.JsonPrimitive; import net.minecraft.nbt.Tag; +import net.minecraft.text.BaseText; +import net.minecraft.text.LiteralText; import java.util.ArrayList; import java.util.List; @@ -79,6 +81,14 @@ public abstract class Value implements Comparable, Cloneable public Value add(Value o) { String lstr = this.getString(); + if (o instanceof FormattedTextValue) + { + if (lstr == null) + return ((FormattedTextValue) o).clone(); + BaseText newText = new LiteralText(lstr); + newText.append(((FormattedTextValue) o).getText().shallowCopy()); + return new FormattedTextValue(newText); + } if (lstr == null) // null return new StringValue(o.getString()); String rstr = o.getString(); From a81b549360bbab7fb23a47dcf252e081d19328e1 Mon Sep 17 00:00:00 2001 From: altrisi Date: Tue, 15 Dec 2020 10:00:09 +0100 Subject: [PATCH 3/7] Move FormattedText addition into a combined function --- .../script/value/FormattedTextValue.java | 41 ++++++++++++++----- src/main/java/carpet/script/value/Value.java | 8 +--- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/main/java/carpet/script/value/FormattedTextValue.java b/src/main/java/carpet/script/value/FormattedTextValue.java index 70546d71..25e45bf0 100644 --- a/src/main/java/carpet/script/value/FormattedTextValue.java +++ b/src/main/java/carpet/script/value/FormattedTextValue.java @@ -3,6 +3,7 @@ package carpet.script.value; import net.minecraft.nbt.StringTag; import net.minecraft.nbt.Tag; import net.minecraft.text.BaseText; +import net.minecraft.text.LiteralText; import net.minecraft.text.Text; public class FormattedTextValue extends StringValue @@ -14,6 +15,33 @@ public class FormattedTextValue extends StringValue this.text = text; } + public static Value combine(Value left, Value right) { + BaseText text; + if (left instanceof FormattedTextValue) + { + text = (BaseText) ((FormattedTextValue) left).getText().shallowCopy(); + } + else + { + if (left instanceof NullValue) + return right; + text = new LiteralText(left.getString()); + } + + if (right instanceof FormattedTextValue) + { + text.append(((FormattedTextValue) right).getText().shallowCopy()); + return new FormattedTextValue(text); + } + else + { + if (right instanceof NullValue) + return left; + text.append(right.getString()); + return new FormattedTextValue(text); + } + } + @Override public String getString() { return text.getString(); @@ -27,7 +55,7 @@ public class FormattedTextValue extends StringValue @Override public Value clone() { - return new FormattedTextValue(text.shallowCopy()); + return new FormattedTextValue(text); } @Override @@ -50,16 +78,7 @@ public class FormattedTextValue extends StringValue @Override public Value add(Value o) { - if (o instanceof FormattedTextValue) - { - Text mergedText = ((BaseText) text).shallowCopy().append(((FormattedTextValue) o).getText()); - return new FormattedTextValue(mergedText); - } - else - { - Text mergedText = ((BaseText) text).shallowCopy().append(o.getString()); - return new FormattedTextValue(mergedText); - } + return combine(this, o); } public String serialize() diff --git a/src/main/java/carpet/script/value/Value.java b/src/main/java/carpet/script/value/Value.java index 93e32183..c2f188e7 100644 --- a/src/main/java/carpet/script/value/Value.java +++ b/src/main/java/carpet/script/value/Value.java @@ -4,8 +4,6 @@ import carpet.script.exception.InternalExpressionException; import com.google.gson.JsonElement; import com.google.gson.JsonPrimitive; import net.minecraft.nbt.Tag; -import net.minecraft.text.BaseText; -import net.minecraft.text.LiteralText; import java.util.ArrayList; import java.util.List; @@ -83,11 +81,7 @@ public abstract class Value implements Comparable, Cloneable String lstr = this.getString(); if (o instanceof FormattedTextValue) { - if (lstr == null) - return ((FormattedTextValue) o).clone(); - BaseText newText = new LiteralText(lstr); - newText.append(((FormattedTextValue) o).getText().shallowCopy()); - return new FormattedTextValue(newText); + return FormattedTextValue.combine(this, o); } if (lstr == null) // null return new StringValue(o.getString()); From 4466f9e8bb9652c14df921c2a37085b113f8ad24 Mon Sep 17 00:00:00 2001 From: gnembon Date: Wed, 16 Dec 2020 01:37:00 -0400 Subject: [PATCH 4/7] set vanishes block data on unsuccessful replace. Fixes #629 --- src/main/java/carpet/script/api/WorldAccess.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/carpet/script/api/WorldAccess.java b/src/main/java/carpet/script/api/WorldAccess.java index a9f8e780..82221c84 100644 --- a/src/main/java/carpet/script/api/WorldAccess.java +++ b/src/main/java/carpet/script/api/WorldAccess.java @@ -812,7 +812,7 @@ public class WorldAccess { { Clearable.clear(world.getBlockEntity(targetPos)); boolean success = world.setBlockState(targetPos, finalSourceBlockState, 2); - if (success && finalData != null) + if (finalData != null) { BlockEntity be = world.getBlockEntity(targetPos); if (be != null) @@ -823,6 +823,7 @@ public class WorldAccess { destTag.putInt("z", targetPos.getZ()); be.fromTag(finalSourceBlockState, destTag); be.markDirty(); + success = true; } } result[0] = success; From 5280cda3ee1ec89ce52d3e9af29fe5f1e71d3f2e Mon Sep 17 00:00:00 2001 From: gnembon Date: Wed, 16 Dec 2020 02:05:05 -0400 Subject: [PATCH 5/7] set can now accept map of properties. --- docs/scarpet/api/BlocksAndWorldAccess.md | 25 +++++++++++-------- .../java/carpet/script/api/WorldAccess.java | 15 +++++++++++ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/docs/scarpet/api/BlocksAndWorldAccess.md b/docs/scarpet/api/BlocksAndWorldAccess.md index 990ae027..a7419d0f 100644 --- a/docs/scarpet/api/BlocksAndWorldAccess.md +++ b/docs/scarpet/api/BlocksAndWorldAccess.md @@ -36,18 +36,19 @@ print(b); // 'stone', block was evaluated 'eagerly' but call to `block` All the functions below can be used with block value, queried with coord triple, or 3-long list. All `pos` in the functions referenced below refer to either method of passing block position. -### `set(pos, block, property?, value?, ..., block_data?)`, `set(pos, block, l(property?, value?, ...), block_data?)` +### `set(pos, block, property?, value?, ..., block_data?)`, `set(pos, block, [property?, value?, ...], block_data?)`, `set(pos, block, {property? -> value?, ...}, block_data?)` -First part of the `set` function is either a coord triple, list of three numbers, or other block with coordinates. -Second part, `block` is either block value as a result of `block()` function string value indicating the block name, -and optional `property - value` pairs for extra block properties. Optional `block_data` include the block data to +First argument for the `set` function is either a coord triple, list of three numbers, or a world localized block value. +Second argument, `block`, is either an existing block value, a result of `block()` function, or a string value indicating the block name +with optional state and block data. It is then followed by an optional +`property - value` pairs for extra block state (which can also be provided in a list or a map). Optional `block_data` include the block data to be set for the target block. If `block` is specified only by name, then if a destination block is the same the `set` operation is skipped, otherwise is executed, for other potential extra -properties. +properties that the original source block may have contained. -The returned value is either the block state that has been set, or `false` if block setting was skipped +The returned value is either the block state that has been set, or `false` if block setting was skipped, or failed
 set(0,5,0,'bedrock')  => bedrock
@@ -63,11 +64,15 @@ scan(0,100,0,20,20,20,set(_,block('glass')))
 b = block('glass'); scan(0,100,0,20,20,20,set(_,b))
     // yet another option, skips all parsing
 set(x,y,z,'iron_trapdoor')  // sets bottom iron trapdoor
-set(x,y,z,'iron_trapdoor[half=top]')  // Incorrect. sets bottom iron trapdoor - no parsing of properties
-set(x,y,z,'iron_trapdoor','half','top') // correct - top trapdoor
-set(x,y,z, block('iron_trapdoor[half=top]')) // also correct, block() provides extra parsing
+
+set(x,y,z,'iron_trapdoor[half=top]')  // sets the top trapdoor
+set(x,y,z,'iron_trapdoor','half','top') // also correct - top trapdoor
+set(x,y,z,'iron_trapdoor', ['half','top']) // same
+set(x,y,z,'iron_trapdoor', {'half' -> 'top'}) // same
+set(x,y,z, block('iron_trapdoor[half=top]')) // also correct, block() provides extra parsing of block state
+
 set(x,y,z,'hopper[facing=north]{Items:[{Slot:1b,id:"minecraft:slime_ball",Count:16b}]}') // extra block data
-set(x,y,z,'hopper', l('facing', 'north'), nbt('{Items:[{Slot:1b,id:"minecraft:slime_ball",Count:16b}]}') ) // same
+set(x,y,z,'hopper', {'facing' -> 'north'}, nbt('{Items:[{Slot:1b,id:"minecraft:slime_ball",Count:16b}]}') ) // same
 
### `without_updates(expr)` diff --git a/src/main/java/carpet/script/api/WorldAccess.java b/src/main/java/carpet/script/api/WorldAccess.java index 82221c84..d15da361 100644 --- a/src/main/java/carpet/script/api/WorldAccess.java +++ b/src/main/java/carpet/script/api/WorldAccess.java @@ -777,6 +777,21 @@ public class WorldAccess { } args = ((ListValue) args.get(0)).getItems(); } + else if (args.get(0) instanceof MapValue) + { + if (args.size() == 2) + { + Value dataValue = NBTSerializableValue.fromValue( args.get(1)); + if (dataValue instanceof NBTSerializableValue) + { + data = ((NBTSerializableValue) dataValue).getCompoundTag(); + } + } + Map state = ((MapValue) args.get(0)).getMap(); + List mapargs = new ArrayList<>(); + state.forEach( (k, v) -> {mapargs.add(k); mapargs.add(v);}); + args = mapargs; + } else { if ((args.size() & 1) == 1) From 67c41025b115b52cd3976e0a90d069ef4fdfa4c0 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 16 Dec 2020 06:05:32 +0000 Subject: [PATCH 6/7] Merge docs for 'set can now accept map of properties.' --- docs/scarpet/Full.md | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/docs/scarpet/Full.md b/docs/scarpet/Full.md index 248dbd24..f1823eb3 100644 --- a/docs/scarpet/Full.md +++ b/docs/scarpet/Full.md @@ -2072,18 +2072,19 @@ print(b); // 'stone', block was evaluated 'eagerly' but call to `block` All the functions below can be used with block value, queried with coord triple, or 3-long list. All `pos` in the functions referenced below refer to either method of passing block position. -### `set(pos, block, property?, value?, ..., block_data?)`, `set(pos, block, l(property?, value?, ...), block_data?)` +### `set(pos, block, property?, value?, ..., block_data?)`, `set(pos, block, [property?, value?, ...], block_data?)`, `set(pos, block, {property? -> value?, ...}, block_data?)` -First part of the `set` function is either a coord triple, list of three numbers, or other block with coordinates. -Second part, `block` is either block value as a result of `block()` function string value indicating the block name, -and optional `property - value` pairs for extra block properties. Optional `block_data` include the block data to +First argument for the `set` function is either a coord triple, list of three numbers, or a world localized block value. +Second argument, `block`, is either an existing block value, a result of `block()` function, or a string value indicating the block name +with optional state and block data. It is then followed by an optional +`property - value` pairs for extra block state (which can also be provided in a list or a map). Optional `block_data` include the block data to be set for the target block. If `block` is specified only by name, then if a destination block is the same the `set` operation is skipped, otherwise is executed, for other potential extra -properties. +properties that the original source block may have contained. -The returned value is either the block state that has been set, or `false` if block setting was skipped +The returned value is either the block state that has been set, or `false` if block setting was skipped, or failed
 set(0,5,0,'bedrock')  => bedrock
@@ -2099,11 +2100,15 @@ scan(0,100,0,20,20,20,set(_,block('glass')))
 b = block('glass'); scan(0,100,0,20,20,20,set(_,b))
     // yet another option, skips all parsing
 set(x,y,z,'iron_trapdoor')  // sets bottom iron trapdoor
-set(x,y,z,'iron_trapdoor[half=top]')  // Incorrect. sets bottom iron trapdoor - no parsing of properties
-set(x,y,z,'iron_trapdoor','half','top') // correct - top trapdoor
-set(x,y,z, block('iron_trapdoor[half=top]')) // also correct, block() provides extra parsing
+
+set(x,y,z,'iron_trapdoor[half=top]')  // sets the top trapdoor
+set(x,y,z,'iron_trapdoor','half','top') // also correct - top trapdoor
+set(x,y,z,'iron_trapdoor', ['half','top']) // same
+set(x,y,z,'iron_trapdoor', {'half' -> 'top'}) // same
+set(x,y,z, block('iron_trapdoor[half=top]')) // also correct, block() provides extra parsing of block state
+
 set(x,y,z,'hopper[facing=north]{Items:[{Slot:1b,id:"minecraft:slime_ball",Count:16b}]}') // extra block data
-set(x,y,z,'hopper', l('facing', 'north'), nbt('{Items:[{Slot:1b,id:"minecraft:slime_ball",Count:16b}]}') ) // same
+set(x,y,z,'hopper', {'facing' -> 'north'}, nbt('{Items:[{Slot:1b,id:"minecraft:slime_ball",Count:16b}]}') ) // same
 
### `without_updates(expr)` From c6529c3d3c0366dc6a50677f4acc61a71a558e00 Mon Sep 17 00:00:00 2001 From: gnembon Date: Wed, 16 Dec 2020 18:03:04 -0400 Subject: [PATCH 7/7] 1.4.21 --- gradle.properties | 2 +- src/main/java/carpet/CarpetSettings.java | 2 +- src/main/resources/fabric.mod.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 6080a184..9551a36d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ org.gradle.jvmargs=-Xmx1G loader_version=0.10.8 # Mod Properties - mod_version = 1.4.20+v201202 + mod_version = 1.4.21+v201216 maven_group = carpet archives_base_name = fabric-carpet diff --git a/src/main/java/carpet/CarpetSettings.java b/src/main/java/carpet/CarpetSettings.java index 78257a10..172a3cb8 100644 --- a/src/main/java/carpet/CarpetSettings.java +++ b/src/main/java/carpet/CarpetSettings.java @@ -36,7 +36,7 @@ import static carpet.settings.RuleCategory.CLIENT; @SuppressWarnings("CanBeFinal") public class CarpetSettings { - public static final String carpetVersion = "1.4.20+v201202"; + public static final String carpetVersion = "1.4.21+v201216"; public static final Logger LOG = LogManager.getLogger("carpet"); public static boolean skipGenerationChecks = false; public static boolean impendingFillSkipUpdates = false; diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index c8144ace..be2c43ff 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, "id": "carpet", - "version": "1.4.20", + "version": "1.4.21", "name": "Carpet Mod in Fabric", "description": "Carpet made out of fabric",