From 775e923252efc0e59855ca3af1d75a8ef7da7438 Mon Sep 17 00:00:00 2001 From: Gnottero <41308782+Gnottero@users.noreply.github.com> Date: Mon, 22 Nov 2021 22:46:02 +0100 Subject: [PATCH 1/2] Added player abilities actions to the entity API (#1160) * Added 'mayfly' and 'fly_speed' actions to the modify() function * Added 'mayfly' and 'fly_speed' actions to the modify() function * Added a query and a modify action for each of the abilities. Added the modify action. Modified the docs to include all the new actions and queries * Fixed an error with mod version * Saving changes * Modified the docs and fix an issue with float type variables * Modified the docs and fixed an issue with float type variables * Update src/main/java/carpet/script/value/EntityValue.java * Update gradle.properties Co-authored-by: gnembon <41132274+gnembon@users.noreply.github.com> --- docs/scarpet/api/Entities.md | 56 ++++++++- .../java/carpet/script/value/EntityValue.java | 115 +++++++++++++++++- 2 files changed, 168 insertions(+), 3 deletions(-) diff --git a/docs/scarpet/api/Entities.md b/docs/scarpet/api/Entities.md index 9e0be92b..a5de63be 100644 --- a/docs/scarpet/api/Entities.md +++ b/docs/scarpet/api/Entities.md @@ -400,6 +400,30 @@ query(p,'effect','resistance') => null Number indicating remaining entity health, or `null` if not applicable. +### `query(e, 'may_fly')` + +Returns a boolean indicating if the player can fly. + +### `query(e, 'flying')` + +Returns a boolean indicating if the player is flying. + +### `query(e, 'may_build')` + +Returns a boolean indicating if the player is allowed to place blocks. + +### `query(e, 'insta_build')` + +Returns a boolean indicating if the player can place blocks without consuming the item and if the player can shoot arrows without having them in the inventory. + +### `query(e, 'fly_speed')` + +Returns a number indicating the speed at which the player moves while flying. + +### `query(e, 'walk_speed')` + +Returns a number indicating the speed at which the player moves while walking. + ### `query(e, 'hunger')` ### `query(e, 'saturation')` ### `query(e, 'exhaustion')` @@ -408,7 +432,7 @@ Retrieves player hunger related information. For non-players, returns `null`. ### `query(e, 'absorption')` -Gets the absorption of the player (yellow hearts, e.g when having a golden apple.) +Gets the absorption of the player (yellow hearts, e.g. when having a golden apple.) ### `query(e,'xp')` ### `query(e,'xp_level')` @@ -420,7 +444,7 @@ Numbers related to player's xp. `xp` is the overall xp player has, `xp_level` is ### `query(e, 'air')` -Number indicating remaining entity health, or `null` if not applicable. +Number indicating remaining entity air, or `null` if not applicable. ### `query(e, 'language')` @@ -693,6 +717,34 @@ Applies status effect to the living entity. Takes several optional parameters, w `true` and `false`. If no duration is specified, or if it's null or 0, the effect is removed. If name is not specified, it clears all effects. +### `modify(e, 'may_fly', boolean)` + +Allows or denies the player the ability to fly. If the player is flying and the ability is removed, the player will stop flying. + +### `modify(e, 'flying', boolean)` + +Changes the flight status of the player (if it is flying or not). + +### `modify(e, 'may_build', boolean)` + +Allows or denies the player the ability to place blocks. + +### `modify(e, 'insta_build', boolean)` + +Allows or denies the player to place blocks without reducing the item count of the used stack and to shoot arrows without having them in the inventory. + +### `modify(e, 'fly_speed', float)` + +Modifies the value of the speed at which the player moves while flying. + +### `modify(e, 'walk_speed', float)` + +Modifies the value of the speed at which the player moves while walking. + +### `modify(e, 'selected_slot', int)` + +Changes player's selected slot. + ### `modify(e, 'home', null), modify(e, 'home', block, distance?), modify(e, 'home', x, y, z, distance?)` Sets AI to stay around the home position, within `distance` blocks from it. `distance` defaults to 16 blocks. diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index 3c0c59d7..33480c06 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -36,6 +36,7 @@ import net.minecraft.network.packet.s2c.play.EntityPassengersSetS2CPacket; import net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket; import net.minecraft.network.packet.s2c.play.ExperienceBarUpdateS2CPacket; import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket; +import net.minecraft.network.packet.s2c.play.UpdateSelectedSlotS2CPacket; import net.minecraft.command.EntitySelector; import net.minecraft.command.EntitySelectorReader; import net.minecraft.entity.Entity; @@ -740,6 +741,49 @@ public class EntityValue extends Value //} return Value.NULL; }); + + put("may_fly", (e, a) -> { + if (e instanceof ServerPlayerEntity player) { + return BooleanValue.of(player.getAbilities().allowFlying); + } + return Value.NULL; + }); + + put("flying", (e, v) -> { + if (e instanceof ServerPlayerEntity player) { + return BooleanValue.of(player.getAbilities().flying); + } + return Value.NULL; + }); + + put("may_build", (e, v) -> { + if (e instanceof ServerPlayerEntity player) { + return BooleanValue.of(player.getAbilities().allowModifyWorld); + } + return Value.NULL; + }); + + put("insta_build", (e, v) -> { + if (e instanceof ServerPlayerEntity player) { + return BooleanValue.of(player.getAbilities().creativeMode); + } + return Value.NULL; + }); + + put("fly_speed", (e, v) -> { + if (e instanceof ServerPlayerEntity player) { + return NumericValue.of(player.getAbilities().getFlySpeed()); + } + return Value.NULL; + }); + + put("walk_speed", (e, v) -> { + if (e instanceof ServerPlayerEntity player) { + return NumericValue.of(player.getAbilities().getWalkSpeed()); + } + return Value.NULL; + }); + put("holds", (e, a) -> { EquipmentSlot where = EquipmentSlot.MAINHAND; if (a != null) @@ -963,6 +1007,67 @@ public class EntityValue extends Value } if (e instanceof LivingEntity) ((LivingEntity) e).setHealth(health); }); + + put("may_fly", (e, v) -> { + boolean mayFly = v.getBoolean(); + if (e instanceof ServerPlayerEntity player) { + player.getAbilities().allowFlying = mayFly; + if (!mayFly && player.getAbilities().flying) { + player.getAbilities().flying = false; + } + player.sendAbilitiesUpdate(); + } + }); + + put("flying", (e, v) -> { + boolean flying = v.getBoolean(); + if (e instanceof ServerPlayerEntity player) { + player.getAbilities().flying = flying; + player.sendAbilitiesUpdate(); + } + }); + + put("may_build", (e, v) -> { + boolean mayBuild = v.getBoolean(); + if (e instanceof ServerPlayerEntity player) { + player.getAbilities().allowModifyWorld = mayBuild; + player.sendAbilitiesUpdate(); + } + }); + + put("insta_build", (e, v) -> { + boolean instaBuild = v.getBoolean(); + if (e instanceof ServerPlayerEntity player) { + player.getAbilities().creativeMode = instaBuild; + player.sendAbilitiesUpdate(); + } + }); + + put("fly_speed", (e, v) -> { + float flySpeed = NumericValue.asNumber(v).getFloat(); + if (e instanceof ServerPlayerEntity player) { + player.getAbilities().setFlySpeed(flySpeed); + player.sendAbilitiesUpdate(); + } + }); + + put("walk_speed", (e, v) -> { + float walkSpeed = NumericValue.asNumber(v).getFloat(); + if (e instanceof ServerPlayerEntity player) { + player.getAbilities().setWalkSpeed(walkSpeed); + player.sendAbilitiesUpdate(); + } + }); + + put("selected_slot", (e, v) -> + { + if (e instanceof ServerPlayerEntity player) + { + int slot = NumericValue.asNumber(v).getInt(); + player.networkHandler.sendPacket(new UpdateSelectedSlotS2CPacket(slot)); + } + }); + // todo add handling of the source for extra effects /*put("damage", (e, v) -> { float dmgPoints; @@ -1453,7 +1558,15 @@ public class EntityValue extends Value put("gravity",(e,v)-> e.setNoGravity(!v.getBoolean())); - put("invulnerable",(e,v)-> e.setInvulnerable(v.getBoolean())); + put("invulnerable",(e,v)-> { + boolean invulnerable = v.getBoolean(); + if (e instanceof ServerPlayerEntity player) { + player.getAbilities().invulnerable = invulnerable; + player.sendAbilitiesUpdate(); + } else { + e.setInvulnerable(invulnerable); + } + }); put("fire",(e,v)-> e.setFireTicks((int)NumericValue.asNumber(v).getLong())); put("frost",(e,v)-> e.setFrozenTicks((int)NumericValue.asNumber(v).getLong())); From 49dff77ebe3b1db53ec802b48e567b3b620ac87e Mon Sep 17 00:00:00 2001 From: Ghoulboy Date: Mon, 22 Nov 2021 22:47:32 +0100 Subject: [PATCH 2/2] Missing semicolon in draw_beta.sc (#1151) --- src/main/resources/assets/carpet/scripts/draw_beta.sc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/assets/carpet/scripts/draw_beta.sc b/src/main/resources/assets/carpet/scripts/draw_beta.sc index 0b8ba312..8e694924 100644 --- a/src/main/resources/assets/carpet/scripts/draw_beta.sc +++ b/src/main/resources/assets/carpet/scripts/draw_beta.sc @@ -28,7 +28,7 @@ __config() -> { 'pointing'->{'type'->'term','suggest'->['up','down']}, 'hollow'->{'type'->'term','suggest'->['hollow','solid']}, }, - 'scope'->'global'//todo decide whether it rly needs to be global or not... + 'scope'->'global }; _block_matches(existing, block_predicate) -> @@ -44,7 +44,7 @@ _block_matches(existing, block_predicate) -> draw(what, args, block, replacement)->(//custom setter cos it's easier positions = call(what,args); //returning blocks to be set - affected = 0 + affected = 0; for(positions, existing = block(_); @@ -52,5 +52,5 @@ draw(what, args, block, replacement)->(//custom setter cos it's easier affected += bool(set(existing,block)) ) ); - print(player,format('gi Filled ' + affected + ' blocks')); + print(format('gi Filled ' + affected + ' blocks')); );