From a7fcaaddf1229f32dc9ed649326f60716e01aac3 Mon Sep 17 00:00:00 2001 From: gnembon Date: Mon, 7 Sep 2020 15:37:22 -0300 Subject: [PATCH] code fixes --- docs/scarpet/Full.md | 83 ++++++++++--------- .../java/carpet/script/CarpetExpression.java | 24 +++--- .../java/carpet/script/value/EntityValue.java | 4 +- 3 files changed, 60 insertions(+), 51 deletions(-) diff --git a/docs/scarpet/Full.md b/docs/scarpet/Full.md index a6c728bc..05eb2756 100644 --- a/docs/scarpet/Full.md +++ b/docs/scarpet/Full.md @@ -1920,15 +1920,20 @@ used to match specific information from it, or use it to copy to another block
    block_data(x,y,z) => '{TransferCooldown:0,x:450,y:68, ... }'
 
-### `poi(pos), poi(pos, radius), poi(pos, radius, status)` +### `poi(pos), poi(pos, radius?, type?, status?, column?)` Queries a POI (Point of Interest) at a given position, returning `null` if none is found, or tuple of poi type and its -occupancy load. With optional `radius` and `status`, returns a list of POIs around `pos` within a given `radius`. -If `status` is specified (either 'available', or 'occupied') returns only POIs with that status. The return format is -again, poi type, occupancy load, and extra tripple of coordinates. +occupancy load. With optional `type`, `radius` and `status`, returns a list of POIs around `pos` within a +given `radius`. If the `type` is specified, returns only poi types of that types, or everything if omitted or `'any'`. +If `status` is specified (either `'any'`, `'available'`, or `'occupied'`) returns only POIs with that status. +With `column` set to `true`, it will return all POIs in a cuboid with `radius` blocks away on x and z, in the entire +block column from 0 to 255. Default (`false`) returns POIs within a spherical area centered on `pos` and with `radius` +radius. -Querying for POIs using the radius is intended use of POI mechanics and ability of accessing individual POIs -via `poi(pos)` in only provided for completness. +The return format of the results is a list of poi type, occupancy load, and extra triple of coordinates. + +Querying for POIs using the radius is the intended use of POI mechanics, and the ability of accessing individual POIs +via `poi(pos)` in only provided for completeness.
 poi(x,y,z) => null  // nothing set at position
@@ -2625,14 +2630,14 @@ query(e,'type')  => villager
 Returns a valid string to be used in commands to address an entity. Its UUID for all entities except
 player, where its their name.
 
-### `query(e, 'persistence')`
-
-Returns if a mob has a persistence tag or not. Returns `null` for non-mob entities.
-
 
 run('/kill ' + e~'command_name');
 
+### `query(e, 'persistence')` + +Returns if a mob has a persistence tag or not. Returns `null` for non-mob entities. + ### `query(e, 'is_riding')` Boolean, true if the entity is riding another entity. @@ -2699,7 +2704,7 @@ Age of the entity in ticks, i.e. how long it existed. ### `query(e, 'breeding_age')` -Breeding age of passive entity, in ticks. If negative, time to adulthood, if positive, breeding cooldown +Breeding age of passive entity, in ticks. If negative, time to adulthood, if positive, breeding cooldown. ### `query(e, 'despawn_timer')` @@ -2715,15 +2720,15 @@ Number of ticks an entity sits in a portal. ### `query(e, 'item')` -The item triple (name, count, nbt) if its an item entity, `null` otherwise +The item triple (name, count, nbt) if its an item entity, `null` otherwise. ### `query(e, 'count')` -Number of items in a stack from item entity, `null` otherwise +Number of items in a stack from item entity, `null` otherwise. ### `query(e, 'pickup_delay')` -Retrieves pickup delay timeout for an item entity, `null` otherwise +Retrieves pickup delay timeout for an item entity, `null` otherwise. ### `query(e, 'is_baby')` @@ -2744,7 +2749,7 @@ of block value, node type, penalty, and a boolean indicated if the node has been ### `query(e, 'pose')` -Returns a pose of an entity, one of the following options +Returns a pose of an entity, one of the following options: * `'standing'` * `'fall_flying'` * `'sleeping'` @@ -2790,7 +2795,7 @@ Returns `null` if the argument is not a player, otherwise: * `realms`: ? ### `query(e, 'category')` -Returns a lowercase string containing the category of the entity (hostile, passive, water, ambient, misc) +Returns a lowercase string containing the category of the entity (hostile, passive, water, ambient, misc). ### `query(e, 'team')` @@ -2854,8 +2859,8 @@ Returns currently mined block by the player, as registered by the game server. ### `query(e, 'breaking_progress')` Returns current breaking progress of a current player mining block, or `null`, if no block is mined. -Breaking progress, it not null, is any number 0 or above, while 10 means that the block should already be -broken by the client. This value may tick above 10, if the client / connection is lagging +Breaking progress, if not null, is any number 0 or above, while 10 means that the block should already be +broken by the client. This value may tick above 10, if the client / connection is lagging. Example: @@ -2897,19 +2902,23 @@ _break(player, pos, name, step, lvl) -> ### `query(e, 'facing', order?)` Returns where the entity is facing. optional order (number from 0 to 5, and negative), indicating primary directions -where entity is looking at. From most prominent (order 0) to opposite (order 5, or -1) +where entity is looking at. From most prominent (order 0) to opposite (order 5, or -1). ### `query(e, 'trace', reach?, options?...)` Returns the result of ray tracing from entity perspective, indicating what it is looking at. Default reach is 4.5 blocks (5 for creative players), and by default it traces for blocks and entities, identical to player attack tracing -action. This can be customized with `options`, use 'blocks' to trace for blocks, 'liquids' to include liquid blocks -as possible results, and 'entities' to trace entities. Any combination of the above is possible. When tracing +action. This can be customized with `options`, use `'blocks'` to trace for blocks, `'liquids'` to include liquid blocks +as possible results, and `'entities'` to trace entities. You can also specify `'exact'` which returns the actual hit + coordinate as a triple, instead of a block or entity value. Any combination of the above is possible. When tracing entities and blocks, blocks will take over the priority even if transparent or non-colliding (aka fighting chickens in tall grass). -Regardless of the options selected, the result could be `null` if nothing is in reach, entity, if look targets an -entity, and block value if block is in reach. +Regardless of the options selected, the result could be: + - `null` if nothing is in reach + - an entity if look targets an entity + - block value if block is in reach, or + - a coordinate triple if `'exact'` option was used and hit was successful. ### `query(e, 'brain', memory)` @@ -2957,7 +2966,7 @@ type objects via `get, put, has, delete`, so try to use API calls first for that Like with entity querying, entity modifications happen through one function. Most position and movements modifications don't work currently on players as their position is controlled by clients. -Currently there is no ability to modify NBT directly, but you could always use `run('data modify entity ...')` +Currently there is no ability to modify NBT directly, but you could always use `run('data modify entity ...')`. ### `modify(e, 'remove')` @@ -2977,7 +2986,7 @@ Changes full location vector all at once. ### `modify(e, 'x', x), modify(e, 'y', y), modify(e, 'z', z)` -Moves the entity in one direction. +Changes entity's location in the specified direction. ### `modify(e, 'pitch', pitch), modify(e, 'yaw', yaw)` @@ -3099,7 +3108,7 @@ a permanent effect. Use `'jump'` to make an entity jump once for sure. Requires a living entity as an argument. -### `modify(e, 'jump'))` +### `modify(e, 'jump')` Will make the entity jump once. @@ -3127,23 +3136,23 @@ Modifies entity air ### `modify(e, 'add_exhaustion', value)` -adds exhaustion value to the current player exhaustion level - that's the method you probably want to use -to manipulate how much 'food' some action cost. +Adds exhaustion value to the current player exhaustion level - that's the method you probably want to use +to manipulate how much 'food' an action costs. ### `modify(e, 'breaking_progress', value)` -Modifies a breaking progress of a player currently mined block. Value of `null`, `-1` make it reset. +Modifies the breaking progress of a player currently mined block. Value of `null`, `-1` makes it reset. Values `0` to `10` will show respective animation of a breaking block. Check `query(e, 'breaking_progress')` for examples. ### `modify(e, 'nbt_merge', partial_tag)` -Merges a partial tag into the entity data and reloads the entity from its updated tag. Cannot be applied to players +Merges a partial tag into the entity data and reloads the entity from its updated tag. Cannot be applied to players. ### `modify(e, 'nbt', tag)` -Reloads the entity from a supplied tag. Better get a valid entity tag, what can go wrong. Wonder what would happen if -transplant rabbit's brain into a villager. Cannot be applied to players. +Reloads the entity from a supplied tag. Better use a valid entity tag, what can go wrong? Wonder what would happen if you +transplant rabbit's brain into a villager? Cannot be applied to players. ## Entity Events @@ -3151,18 +3160,18 @@ There is a number of events that happen to entities that you can attach your own The event handler is any function that runs in your package that accepts certain expected parameters, which you can expand with your own arguments. When it comes to the moment when the given command needs to be executed, it does so providing that number of arguments it accepts is equal number of event arguments, and extra arguments passed when -defining the callback with `entity_event` +defining the callback with `entity_event`. -The following events can be handled by entities. +The following events can be handled by entities: * `'on_tick'`: executes every tick right before the entity is ticked in the game. Required arguments: `entity` * `'on_death'`: executes once when a living entity dies. Required arguments: `entity, reason` * `'on_removed'`: execute once when an entity is removed. Required arguments: `entity` -* `'on_damaged'`: executed every time a living entity is about to receive damage. +* `'on_damaged'`: executed every time a living entity is about to receive damage. Required arguments: `entity, amount, source, attacking_entity` It doesn't mean that all entity types will have a chance to execute a given event, but entities will not error -when you attach inapplicable event to it. +when you attach an inapplicable event to it. ### `entity_event(e, event, call_name, args...)` @@ -3186,7 +3195,7 @@ __on_player_interacts_with_entity(player, entity, hand) -> )
-In this case this will protect a villager from entity damage (zombies, etc.) except players by granting all the +In this case this will protect a villager from entity damage (zombies, etc.) except from players by granting all the health back to the villager after being harmed. # Inventory and Items API diff --git a/src/main/java/carpet/script/CarpetExpression.java b/src/main/java/carpet/script/CarpetExpression.java index ebf5e69b..45af0217 100644 --- a/src/main/java/carpet/script/CarpetExpression.java +++ b/src/main/java/carpet/script/CarpetExpression.java @@ -3403,25 +3403,25 @@ public class CarpetExpression Value res; - if(lv.size()==1){ + if(lv.size()==1) + { res = lv.get(0).evalValue(c); CarpetSettings.LOG.info(res.getString()); } - else if(lv.size()==2){ - String level = lv.get(0).evalValue(c).toString(); + else if(lv.size()==2) + { + String level = lv.get(0).evalValue(c).getString().toLowerCase(Locale.ROOT); res = lv.get(1).evalValue(c); - switch(level){ - case "error":CarpetSettings.LOG.error(res.getString()); break; - case "warn":CarpetSettings.LOG.warn(res.getString()); break; - case "debug":CarpetSettings.LOG.debug(res.getString()); break; - case "fatal":CarpetSettings.LOG.fatal(res.getString()); break; - case "info":CarpetSettings.LOG.info(res.getString()); break; - default: throw new InternalExpressionException("Unknown error type: "+level); + case "error": CarpetSettings.LOG.error(res.getString()); break; + case "warn": CarpetSettings.LOG.warn(res.getString()); break; + case "debug": CarpetSettings.LOG.debug(res.getString()); break; + case "fatal": CarpetSettings.LOG.fatal(res.getString()); break; + case "info": CarpetSettings.LOG.info(res.getString()); break; + default: throw new InternalExpressionException("Unknown log level for 'logger': "+level); } } - - else throw new InternalExpressionException("logger only takes 1 or 2 arguments"); + else throw new InternalExpressionException("logger takes 1 or 2 arguments"); return (_c, _t) -> res; // pass through for variables }); diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index 3fcdbe19..c9e25556 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -343,7 +343,7 @@ public class EntityValue extends Value put("sneaking", (e, a) -> e.isSneaking()?Value.TRUE:Value.FALSE); put("sprinting", (e, a) -> e.isSprinting()?Value.TRUE:Value.FALSE); put("swimming", (e, a) -> e.isSwimming()?Value.TRUE:Value.FALSE); - put("air", (e, a) -> return new NumericValue(e.getAir())); + put("air", (e, a) -> new NumericValue(e.getAir())); put("persistence", (e, a) -> { if (e instanceof MobEntity) return new NumericValue(((MobEntity) e).isPersistent()); return Value.NULL; @@ -1108,7 +1108,7 @@ public class EntityValue extends Value if(e instanceof PlayerEntity) ((PlayerEntity) e).getHungerManager().setSaturationLevelClient((float)NumericValue.asNumber(v).getLong()); }); - put("air", (e, v) -> e.setAir(NumericValue.asNumber(v).getLong())); + put("air", (e, v) -> e.setAir(NumericValue.asNumber(v).getInt())); put("breaking_progress", (e, a) -> { if (e instanceof ServerPlayerEntity)