From 2b6a1bf1c528b3cae367391bb425ef25d3af3a32 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Tue, 21 Apr 2020 11:07:00 +0200 Subject: [PATCH 01/22] added gamemode_id and jump modifications --- .../java/carpet/script/value/EntityValue.java | 62 ++++++++++++++----- 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index a0237460..e89d634a 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -4,6 +4,7 @@ import carpet.fakes.EntityInterface; import carpet.fakes.ItemEntityInterface; import carpet.fakes.MobEntityInterface; import carpet.helpers.Tracer; +import carpet.helpers.EntityPlayerActionPack; import carpet.patches.EntityPlayerMPFake; import carpet.script.CarpetContext; import carpet.script.EntityEventsGroup; @@ -45,6 +46,7 @@ import net.minecraft.util.math.Direction; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.util.registry.Registry; +import net.minecraft.world.GameMode; import org.apache.commons.lang3.tuple.Pair; import java.util.ArrayList; @@ -891,21 +893,51 @@ public class EntityValue extends Value throw new InternalExpressionException("'effect' needs either no arguments (clear) or effect name, duration, and optional amplifier, show particles and show icon"); }); - // gamemode - // spectate - // "fire" - // "extinguish" - // "silent" - // "gravity" - // "invulnerable" - // "dimension" - // "item" - // "count", - // "age", - // "effect_"name - // "hold" - // "hold_offhand" - // "jump" + put("gamemode", (e,v)->{ + if(!(e instanceof ServerPlayerEntity)){ + throw new InternalExpressionException("Cannot change the gamemode of non-player entities"); + } + if(v.readInteger()==0){ + ((ServerPlayerEntity) e).setGameMode(GameMode.SURVIVAL); + return; + } + if(v.getString()=="creative"){ + ((ServerPlayerEntity) e).setGameMode(GameMode.CREATIVE); + return; + } + if(v.getString()=="spectator"){ + ((ServerPlayerEntity) e).setGameMode(GameMode.SPECTATOR); + return; + } + if(v.getString()=="adventure"){ + ((ServerPlayerEntity) e).setGameMode(GameMode.ADVENTURE); + return; + } + throw new InternalExpressionException("s"+v.getString()+"s is an invalid gamemode type"); + }); + + put("jump",(e,v)->{ + if(!(e instanceof ServerPlayerEntity)){ + throw new InternalExpressionException("Non-player entities can't jump"); + } + ((PlayerEntity) e).jump(); + }); + + // gamemode_id [check](gamemode just wont read string) + // spectate [check] + // "fire" [] + // "extinguish" [] + // "silent" [] + // "gravity" [] + // "invulnerable" [] + // "dimension" [] + // "item" [] + // "count", [] + // "age", [] + // "effect_"name [] + // "hold" [inventory_set?] + // "hold_offhand" [inventory_set?] + // "jump" [check] // "nbt" <-big one, for now use run('data merge entity ... }}; From db48a5c0611bd93baf4f110699d22730ed02494a Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Tue, 21 Apr 2020 11:08:40 +0200 Subject: [PATCH 02/22] wait, I hadn't amde it to gamemode_id! oops --- src/main/java/carpet/script/value/EntityValue.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index e89d634a..d20c34f5 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -893,7 +893,7 @@ public class EntityValue extends Value throw new InternalExpressionException("'effect' needs either no arguments (clear) or effect name, duration, and optional amplifier, show particles and show icon"); }); - put("gamemode", (e,v)->{ + put("gamemode_id", (e,v)->{ if(!(e instanceof ServerPlayerEntity)){ throw new InternalExpressionException("Cannot change the gamemode of non-player entities"); } @@ -901,15 +901,15 @@ public class EntityValue extends Value ((ServerPlayerEntity) e).setGameMode(GameMode.SURVIVAL); return; } - if(v.getString()=="creative"){ + if(v.readInteger()==0){ ((ServerPlayerEntity) e).setGameMode(GameMode.CREATIVE); return; } - if(v.getString()=="spectator"){ + if(v.readInteger()==0){ ((ServerPlayerEntity) e).setGameMode(GameMode.SPECTATOR); return; } - if(v.getString()=="adventure"){ + if(v.readInteger()==0){ ((ServerPlayerEntity) e).setGameMode(GameMode.ADVENTURE); return; } From 786ce3116ae1307e9d6c738a6e2238d8567646ad Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Tue, 21 Apr 2020 11:10:26 +0200 Subject: [PATCH 03/22] added different gamemode ids cos i copypastad code and forgot to do that --- src/main/java/carpet/script/value/EntityValue.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index d20c34f5..423b88d0 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -901,15 +901,15 @@ public class EntityValue extends Value ((ServerPlayerEntity) e).setGameMode(GameMode.SURVIVAL); return; } - if(v.readInteger()==0){ + if(v.readInteger()==1){ ((ServerPlayerEntity) e).setGameMode(GameMode.CREATIVE); return; } - if(v.readInteger()==0){ + if(v.readInteger()==3){ ((ServerPlayerEntity) e).setGameMode(GameMode.SPECTATOR); return; } - if(v.readInteger()==0){ + if(v.readInteger()==2){ ((ServerPlayerEntity) e).setGameMode(GameMode.ADVENTURE); return; } From 6ca07597386b6b3d2444da5487509ed33706a79c Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Wed, 22 Apr 2020 12:45:28 +0200 Subject: [PATCH 04/22] made integer reading better --- src/main/java/carpet/script/value/EntityValue.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index 423b88d0..c67a5bdd 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -897,19 +897,17 @@ public class EntityValue extends Value if(!(e instanceof ServerPlayerEntity)){ throw new InternalExpressionException("Cannot change the gamemode of non-player entities"); } - if(v.readInteger()==0){ + + if(NumericValue.asNumber(v).getLong()==0){ ((ServerPlayerEntity) e).setGameMode(GameMode.SURVIVAL); return; - } - if(v.readInteger()==1){ + }else if(NumericValue.asNumber(v).getLong()==1){ ((ServerPlayerEntity) e).setGameMode(GameMode.CREATIVE); return; - } - if(v.readInteger()==3){ + }else if(NumericValue.asNumber(v).getLong()==3){ ((ServerPlayerEntity) e).setGameMode(GameMode.SPECTATOR); return; - } - if(v.readInteger()==2){ + }else if(NumericValue.asNumber(v).getLong()==2){ ((ServerPlayerEntity) e).setGameMode(GameMode.ADVENTURE); return; } From 7740f9dc7f5106aceb5868a9d46332d3a3007871 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Wed, 22 Apr 2020 12:48:27 +0200 Subject: [PATCH 05/22] removed unused import --- src/main/java/carpet/script/value/EntityValue.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index c67a5bdd..4d7d238c 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -4,7 +4,6 @@ import carpet.fakes.EntityInterface; import carpet.fakes.ItemEntityInterface; import carpet.fakes.MobEntityInterface; import carpet.helpers.Tracer; -import carpet.helpers.EntityPlayerActionPack; import carpet.patches.EntityPlayerMPFake; import carpet.script.CarpetContext; import carpet.script.EntityEventsGroup; From e6b4f496de6ae50bf29d4f700bbd88aa59f43afb Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Fri, 24 Apr 2020 12:08:03 +0200 Subject: [PATCH 06/22] took out testing stuff --- src/main/java/carpet/script/value/EntityValue.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index 4d7d238c..012c1647 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -892,7 +892,7 @@ public class EntityValue extends Value throw new InternalExpressionException("'effect' needs either no arguments (clear) or effect name, duration, and optional amplifier, show particles and show icon"); }); - put("gamemode_id", (e,v)->{ + put("gamemode", (e,v)->{ if(!(e instanceof ServerPlayerEntity)){ throw new InternalExpressionException("Cannot change the gamemode of non-player entities"); } @@ -910,7 +910,7 @@ public class EntityValue extends Value ((ServerPlayerEntity) e).setGameMode(GameMode.ADVENTURE); return; } - throw new InternalExpressionException("s"+v.getString()+"s is an invalid gamemode type"); + throw new InternalExpressionException(NumericValue.asNumber(v).getLong()+" is an invalid gamemode id"); }); put("jump",(e,v)->{ From e8946fe9d5c9069fa7d7f4301f6fd128686be3df Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Fri, 24 Apr 2020 12:10:49 +0200 Subject: [PATCH 07/22] changed to switch statement much shorter and less messier --- .../java/carpet/script/value/EntityValue.java | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index 012c1647..090d4402 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -897,18 +897,11 @@ public class EntityValue extends Value throw new InternalExpressionException("Cannot change the gamemode of non-player entities"); } - if(NumericValue.asNumber(v).getLong()==0){ - ((ServerPlayerEntity) e).setGameMode(GameMode.SURVIVAL); - return; - }else if(NumericValue.asNumber(v).getLong()==1){ - ((ServerPlayerEntity) e).setGameMode(GameMode.CREATIVE); - return; - }else if(NumericValue.asNumber(v).getLong()==3){ - ((ServerPlayerEntity) e).setGameMode(GameMode.SPECTATOR); - return; - }else if(NumericValue.asNumber(v).getLong()==2){ - ((ServerPlayerEntity) e).setGameMode(GameMode.ADVENTURE); - return; + switch((int)NumericValue.asNumber(v).getLong()){ + case 0:((ServerPlayerEntity) e).setGameMode(GameMode.SURVIVAL);return; + case 1:((ServerPlayerEntity) e).setGameMode(GameMode.CREATIVE);return; + case 2:((ServerPlayerEntity) e).setGameMode(GameMode.ADVENTURE);return; + case 3:((ServerPlayerEntity) e).setGameMode(GameMode.SPECTATOR);return; } throw new InternalExpressionException(NumericValue.asNumber(v).getLong()+" is an invalid gamemode id"); }); From 367e584e43e34cad8c29fbb3bfbdfa14d556ce95 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Fri, 24 Apr 2020 12:17:07 +0200 Subject: [PATCH 08/22] Now it just continues to jump --- src/main/java/carpet/script/value/EntityValue.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index 090d4402..583fd72d 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -907,10 +907,10 @@ public class EntityValue extends Value }); put("jump",(e,v)->{ - if(!(e instanceof ServerPlayerEntity)){ - throw new InternalExpressionException("Non-player entities can't jump"); + if(!(e instanceof LivingEntity)){ + throw new InternalExpressionException("Non-living entities can't jump"); } - ((PlayerEntity) e).jump(); + ((LivingEntity) e).setJumping(v.getBoolean()); }); // gamemode_id [check](gamemode just wont read string) From 182d34936a971386a8d7a75eba179fcd9f7e83fa Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Fri, 24 Apr 2020 12:26:39 +0200 Subject: [PATCH 09/22] rename to jumpingcm --- src/main/java/carpet/script/value/EntityValue.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index 583fd72d..b01489a4 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -906,7 +906,7 @@ public class EntityValue extends Value throw new InternalExpressionException(NumericValue.asNumber(v).getLong()+" is an invalid gamemode id"); }); - put("jump",(e,v)->{ + put("jumping",(e,v)->{ if(!(e instanceof LivingEntity)){ throw new InternalExpressionException("Non-living entities can't jump"); } From 64f760564dee36d5a2635cd0d879a249e92fc28d Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Fri, 24 Apr 2020 13:12:48 +0200 Subject: [PATCH 10/22] added string not case-sensitive --- src/main/java/carpet/script/value/EntityValue.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index b01489a4..82ef8219 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -897,6 +897,13 @@ public class EntityValue extends Value throw new InternalExpressionException("Cannot change the gamemode of non-player entities"); } + switch(v.getString().toLowerCase()){ + case "survival":((ServerPlayerEntity) e).setGameMode(GameMode.SURVIVAL);return; + case "creative":((ServerPlayerEntity) e).setGameMode(GameMode.CREATIVE);return; + case "adventure":((ServerPlayerEntity) e).setGameMode(GameMode.ADVENTURE);return; + case "spectator":((ServerPlayerEntity) e).setGameMode(GameMode.SPECTATOR);return; + } + switch((int)NumericValue.asNumber(v).getLong()){ case 0:((ServerPlayerEntity) e).setGameMode(GameMode.SURVIVAL);return; case 1:((ServerPlayerEntity) e).setGameMode(GameMode.CREATIVE);return; From c3fe3530cc269bd73abd49c82ad4fe895aaf97b3 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Fri, 24 Apr 2020 16:29:40 +0200 Subject: [PATCH 11/22] Updatd docs --- docs/scarpet/Full.md | 13 +++++++++++++ docs/scarpet/api/Entities.md | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/docs/scarpet/Full.md b/docs/scarpet/Full.md index 45d8eb9e..0290668a 100644 --- a/docs/scarpet/Full.md +++ b/docs/scarpet/Full.md @@ -2712,6 +2712,19 @@ and `true`. If no duration is specified, or it is null or 0, the effect is remov Sets AI to stay around the home position, within `distance` blocks from it. `distance` defaults to 16 blocks. `null` removes it. _May_ not work fully with mobs that have this AI built in, like Villagers. +### `modify(e, 'gamemode', gamemode?), modify(e, 'gamemode',gamemode_id?)` + +Modifies gamemode of player to whatever string (case-insensitive) or number you put in. + +* 0: survival +* 1: creative +* 2: adventure +* 3: spectator + +### `modify(e, 'jumping', true/false?)` + +Will make the entity constantly jump if set to true, and will stop the entity from jumping if set to false. No current way to make it jump once only. + ## Entity Events There is a number of events that happen to entities that you can attach your own code to in the form of event handlers. diff --git a/docs/scarpet/api/Entities.md b/docs/scarpet/api/Entities.md index 3bd7634f..a6555441 100644 --- a/docs/scarpet/api/Entities.md +++ b/docs/scarpet/api/Entities.md @@ -455,6 +455,19 @@ and `true`. If no duration is specified, or it is null or 0, the effect is remov Sets AI to stay around the home position, within `distance` blocks from it. `distance` defaults to 16 blocks. `null` removes it. _May_ not work fully with mobs that have this AI built in, like Villagers. +### `modify(e, 'gamemode', gamemode?), modify(e, 'gamemode',gamemode_id?)` + +Modifies gamemode of player to whatever string (case-insensitive) or number you put in. + +* 0: survival +* 1: creative +* 2: adventure +* 3: spectator + +### `modify(e, 'jumping', true/false?)` + +Will make the entity constantly jump if set to true, and will stop the entity from jumping if set to false. No current way to make it jump once only. + ## Entity Events There is a number of events that happen to entities that you can attach your own code to in the form of event handlers. From c255e6f33010951af17fe8a789985e896b7d2900 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Sun, 26 Apr 2020 11:25:22 +0200 Subject: [PATCH 12/22] changed to return null instead of throwing exception --- src/main/java/carpet/script/value/EntityValue.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index 82ef8219..a7f4fc29 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -894,7 +894,7 @@ public class EntityValue extends Value put("gamemode", (e,v)->{ if(!(e instanceof ServerPlayerEntity)){ - throw new InternalExpressionException("Cannot change the gamemode of non-player entities"); + return; } switch(v.getString().toLowerCase()){ @@ -910,7 +910,7 @@ public class EntityValue extends Value case 2:((ServerPlayerEntity) e).setGameMode(GameMode.ADVENTURE);return; case 3:((ServerPlayerEntity) e).setGameMode(GameMode.SPECTATOR);return; } - throw new InternalExpressionException(NumericValue.asNumber(v).getLong()+" is an invalid gamemode id"); + return; }); put("jumping",(e,v)->{ From 63a49f0386241132ae94b67a1e3f0780989298f0 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Sun, 26 Apr 2020 11:34:12 +0200 Subject: [PATCH 13/22] no need for that --- src/main/java/carpet/script/value/EntityValue.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index a7f4fc29..7e2cb392 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -920,7 +920,7 @@ public class EntityValue extends Value ((LivingEntity) e).setJumping(v.getBoolean()); }); - // gamemode_id [check](gamemode just wont read string) + // gamemode [check] // spectate [check] // "fire" [] // "extinguish" [] From cdfce6f0050abe0a41661bf02d0af19c7d74ec41 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Sun, 26 Apr 2020 11:34:49 +0200 Subject: [PATCH 14/22] not throwing exception --- src/main/java/carpet/script/value/EntityValue.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index 7e2cb392..59ebc428 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -914,9 +914,8 @@ public class EntityValue extends Value }); put("jumping",(e,v)->{ - if(!(e instanceof LivingEntity)){ - throw new InternalExpressionException("Non-living entities can't jump"); - } + if(!(e instanceof LivingEntity)) return; + ((LivingEntity) e).setJumping(v.getBoolean()); }); From 2873494f5c99c7cc1fc771f649762885f7f998b5 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Sun, 26 Apr 2020 12:03:14 +0200 Subject: [PATCH 15/22] Most convoluted way of doing things --- .../java/carpet/script/value/EntityValue.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index 59ebc428..38a9a86a 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -10,6 +10,7 @@ import carpet.script.EntityEventsGroup; import carpet.script.exception.InternalExpressionException; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.entity.effect.StatusEffects; import net.minecraft.network.packet.s2c.play.EntityPassengersSetS2CPacket; import net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket; import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket; @@ -875,7 +876,7 @@ public class EntityValue extends Value { le.removeStatusEffect(effect); return; - } + } int amplifier = 0; if (lv.size() > 2) amplifier = (int)NumericValue.asNumber(lv.get(2)).getLong(); @@ -896,7 +897,7 @@ public class EntityValue extends Value if(!(e instanceof ServerPlayerEntity)){ return; } - + switch(v.getString().toLowerCase()){ case "survival":((ServerPlayerEntity) e).setGameMode(GameMode.SURVIVAL);return; case "creative":((ServerPlayerEntity) e).setGameMode(GameMode.CREATIVE);return; @@ -919,6 +920,27 @@ public class EntityValue extends Value ((LivingEntity) e).setJumping(v.getBoolean()); }); + put("jump",(e,v)->{//Most *REDACTED* up code in the world + + float m = e.world.getBlockState(new BlockPos(e)).getBlock().getJumpVelocityMultiplier(); + float g = e.world.getBlockState(new BlockPos(e.getX(), e.getBoundingBox().y1 - 0.5000001D, e.getZ())).getBlock().getJumpVelocityMultiplier(); + float JumpVelocityMultiplier= (double)m == 1.0D ? g : m; + + float f = (0.42F * JumpVelocityMultiplier); + if (((LivingEntity)e).hasStatusEffect(StatusEffects.JUMP_BOOST)) { + f += 0.1F * (float)(((LivingEntity)e).getStatusEffect(StatusEffects.JUMP_BOOST).getAmplifier() + 1); + } + + Vec3d vec3d = e.getVelocity(); + e.setVelocity(vec3d.x, (double)f, vec3d.z); + if (e.isSprinting()) { + float u = e.yaw * 0.017453292F; + e.setVelocity(e.getVelocity().add((double)(-MathHelper.sin(g) * 0.2F), 0.0D, (double)(MathHelper.cos(u) * 0.2F))); + } + + e.velocityDirty = true; + }); + // gamemode [check] // spectate [check] // "fire" [] From 7c620a83bb110448c466b7b2d30a50fc31554fc9 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Sun, 26 Apr 2020 12:18:03 +0200 Subject: [PATCH 16/22] changed docs --- docs/scarpet/Full.md | 6 +++++- docs/scarpet/api/Entities.md | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/scarpet/Full.md b/docs/scarpet/Full.md index 0290668a..3b944c5d 100644 --- a/docs/scarpet/Full.md +++ b/docs/scarpet/Full.md @@ -2723,7 +2723,11 @@ Modifies gamemode of player to whatever string (case-insensitive) or number you ### `modify(e, 'jumping', true/false?)` -Will make the entity constantly jump if set to true, and will stop the entity from jumping if set to false. No current way to make it jump once only. +Will make the entity constantly jump if set to true, and will stop the entity from jumping if set to false. + +### `modify(e, 'jump'))` + +Will make the entity jump once only ## Entity Events diff --git a/docs/scarpet/api/Entities.md b/docs/scarpet/api/Entities.md index a6555441..65f69f51 100644 --- a/docs/scarpet/api/Entities.md +++ b/docs/scarpet/api/Entities.md @@ -466,7 +466,11 @@ Modifies gamemode of player to whatever string (case-insensitive) or number you ### `modify(e, 'jumping', true/false?)` -Will make the entity constantly jump if set to true, and will stop the entity from jumping if set to false. No current way to make it jump once only. +Will make the entity constantly jump if set to true, and will stop the entity from jumping if set to false. + +### `modify(e, 'jump'))` + +Will make the entity jump once only ## Entity Events From aba2d605c807a8b5f9351232b589e3a6eccbe851 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Sun, 26 Apr 2020 12:25:49 +0200 Subject: [PATCH 17/22] removing unnecessary stuff cos Idea told me to --- .../java/carpet/script/value/EntityValue.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index 38a9a86a..fbe5a8c4 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -899,19 +899,18 @@ public class EntityValue extends Value } switch(v.getString().toLowerCase()){ - case "survival":((ServerPlayerEntity) e).setGameMode(GameMode.SURVIVAL);return; - case "creative":((ServerPlayerEntity) e).setGameMode(GameMode.CREATIVE);return; - case "adventure":((ServerPlayerEntity) e).setGameMode(GameMode.ADVENTURE);return; - case "spectator":((ServerPlayerEntity) e).setGameMode(GameMode.SPECTATOR);return; + case "survival":((ServerPlayerEntity) e).setGameMode(GameMode.SURVIVAL);break; + case "creative":((ServerPlayerEntity) e).setGameMode(GameMode.CREATIVE);break; + case "adventure":((ServerPlayerEntity) e).setGameMode(GameMode.ADVENTURE);break; + case "spectator":((ServerPlayerEntity) e).setGameMode(GameMode.SPECTATOR);break; } switch((int)NumericValue.asNumber(v).getLong()){ - case 0:((ServerPlayerEntity) e).setGameMode(GameMode.SURVIVAL);return; - case 1:((ServerPlayerEntity) e).setGameMode(GameMode.CREATIVE);return; - case 2:((ServerPlayerEntity) e).setGameMode(GameMode.ADVENTURE);return; - case 3:((ServerPlayerEntity) e).setGameMode(GameMode.SPECTATOR);return; + case 0:((ServerPlayerEntity) e).setGameMode(GameMode.SURVIVAL);break; + case 1:((ServerPlayerEntity) e).setGameMode(GameMode.CREATIVE);break; + case 2:((ServerPlayerEntity) e).setGameMode(GameMode.ADVENTURE);break; + case 3:((ServerPlayerEntity) e).setGameMode(GameMode.SPECTATOR);break; } - return; }); put("jumping",(e,v)->{ @@ -932,10 +931,10 @@ public class EntityValue extends Value } Vec3d vec3d = e.getVelocity(); - e.setVelocity(vec3d.x, (double)f, vec3d.z); + e.setVelocity(vec3d.x, f, vec3d.z); if (e.isSprinting()) { float u = e.yaw * 0.017453292F; - e.setVelocity(e.getVelocity().add((double)(-MathHelper.sin(g) * 0.2F), 0.0D, (double)(MathHelper.cos(u) * 0.2F))); + e.setVelocity(e.getVelocity().add((-MathHelper.sin(g) * 0.2F), 0.0D, (MathHelper.cos(u) * 0.2F))); } e.velocityDirty = true; From e1c87126562c92020ad1e92b7f6931a616582a79 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Mon, 27 Apr 2020 09:07:44 +0200 Subject: [PATCH 18/22] best way I could think of doing this --- .../java/carpet/script/value/EntityValue.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index fbe5a8c4..32c9967e 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -897,19 +897,11 @@ public class EntityValue extends Value if(!(e instanceof ServerPlayerEntity)){ return; } - switch(v.getString().toLowerCase()){ - case "survival":((ServerPlayerEntity) e).setGameMode(GameMode.SURVIVAL);break; - case "creative":((ServerPlayerEntity) e).setGameMode(GameMode.CREATIVE);break; - case "adventure":((ServerPlayerEntity) e).setGameMode(GameMode.ADVENTURE);break; - case "spectator":((ServerPlayerEntity) e).setGameMode(GameMode.SPECTATOR);break; - } - - switch((int)NumericValue.asNumber(v).getLong()){ - case 0:((ServerPlayerEntity) e).setGameMode(GameMode.SURVIVAL);break; - case 1:((ServerPlayerEntity) e).setGameMode(GameMode.CREATIVE);break; - case 2:((ServerPlayerEntity) e).setGameMode(GameMode.ADVENTURE);break; - case 3:((ServerPlayerEntity) e).setGameMode(GameMode.SPECTATOR);break; + case "survival": case "0":((ServerPlayerEntity) e).setGameMode(GameMode.SURVIVAL);break; + case "creative": case "1":((ServerPlayerEntity) e).setGameMode(GameMode.CREATIVE);break; + case "adventure": case "2":((ServerPlayerEntity) e).setGameMode(GameMode.ADVENTURE);break; + case "spectator": case "3":((ServerPlayerEntity) e).setGameMode(GameMode.SPECTATOR);break; } }); From a19e759039cb5c5e680de9a30c30bc72a93abcd7 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Mon, 27 Apr 2020 09:30:31 +0200 Subject: [PATCH 19/22] added jump method to MobAi.java My justification: https://github.com/gnembon/fabric-carpet/pull/241#discussion_r415576459 --- .../java/carpet/script/value/EntityValue.java | 20 ++------------- src/main/java/carpet/utils/MobAI.java | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index 32c9967e..be53b844 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -62,6 +62,7 @@ import java.util.function.Predicate; import java.util.stream.Collectors; import static carpet.script.value.NBTSerializableValue.nameFromRegistryId; +import static carpet.utils.MobAI.jump; // TODO: decide whether copy(entity) should duplicate entity in the world. public class EntityValue extends Value @@ -912,24 +913,7 @@ public class EntityValue extends Value }); put("jump",(e,v)->{//Most *REDACTED* up code in the world - - float m = e.world.getBlockState(new BlockPos(e)).getBlock().getJumpVelocityMultiplier(); - float g = e.world.getBlockState(new BlockPos(e.getX(), e.getBoundingBox().y1 - 0.5000001D, e.getZ())).getBlock().getJumpVelocityMultiplier(); - float JumpVelocityMultiplier= (double)m == 1.0D ? g : m; - - float f = (0.42F * JumpVelocityMultiplier); - if (((LivingEntity)e).hasStatusEffect(StatusEffects.JUMP_BOOST)) { - f += 0.1F * (float)(((LivingEntity)e).getStatusEffect(StatusEffects.JUMP_BOOST).getAmplifier() + 1); - } - - Vec3d vec3d = e.getVelocity(); - e.setVelocity(vec3d.x, f, vec3d.z); - if (e.isSprinting()) { - float u = e.yaw * 0.017453292F; - e.setVelocity(e.getVelocity().add((-MathHelper.sin(g) * 0.2F), 0.0D, (MathHelper.cos(u) * 0.2F))); - } - - e.velocityDirty = true; + jump((LivingEntity)e); }); // gamemode [check] diff --git a/src/main/java/carpet/utils/MobAI.java b/src/main/java/carpet/utils/MobAI.java index 0a202b16..ff01c0e0 100644 --- a/src/main/java/carpet/utils/MobAI.java +++ b/src/main/java/carpet/utils/MobAI.java @@ -4,7 +4,12 @@ import carpet.CarpetServer; import com.google.common.collect.Sets; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.effect.StatusEffects; import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; import net.minecraft.util.registry.Registry; import java.util.HashMap; @@ -93,4 +98,24 @@ public class MobAI } } + public static void jump(LivingEntity e){ + float m = e.world.getBlockState(new BlockPos(e)).getBlock().getJumpVelocityMultiplier(); + float g = e.world.getBlockState(new BlockPos(e.getX(), e.getBoundingBox().y1 - 0.5000001D, e.getZ())).getBlock().getJumpVelocityMultiplier(); + float JumpVelocityMultiplier= (double)m == 1.0D ? g : m; + + float f = (0.42F * JumpVelocityMultiplier); + if (e.hasStatusEffect(StatusEffects.JUMP_BOOST)) { + f += 0.1F * (float)(e.getStatusEffect(StatusEffects.JUMP_BOOST).getAmplifier() + 1); + } + + Vec3d vec3d = e.getVelocity(); + e.setVelocity(vec3d.x, f, vec3d.z); + if (e.isSprinting()) { + float u = e.yaw * 0.017453292F; + e.setVelocity(e.getVelocity().add((-MathHelper.sin(g) * 0.2F), 0.0D, (MathHelper.cos(u) * 0.2F))); + } + + e.velocityDirty = true; + } + } From 8ea79b5837dadedcd0790584ab3bbc81d561ec0a Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Mon, 27 Apr 2020 09:41:24 +0200 Subject: [PATCH 20/22] moved the swearing very important business, swearing... --- src/main/java/carpet/utils/MobAI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/carpet/utils/MobAI.java b/src/main/java/carpet/utils/MobAI.java index ff01c0e0..77c4fd94 100644 --- a/src/main/java/carpet/utils/MobAI.java +++ b/src/main/java/carpet/utils/MobAI.java @@ -98,7 +98,7 @@ public class MobAI } } - public static void jump(LivingEntity e){ + public static void jump(LivingEntity e){//Most *REDACTED* up code in the world float m = e.world.getBlockState(new BlockPos(e)).getBlock().getJumpVelocityMultiplier(); float g = e.world.getBlockState(new BlockPos(e.getX(), e.getBoundingBox().y1 - 0.5000001D, e.getZ())).getBlock().getJumpVelocityMultiplier(); float JumpVelocityMultiplier= (double)m == 1.0D ? g : m; From 332c04dd934538ec86ef44efdc4cd828e8dda646 Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Mon, 27 Apr 2020 09:46:17 +0200 Subject: [PATCH 21/22] added silent, gravity, fire and age cos i was bored, and I also checked it off for u --- docs/scarpet/Full.md | 11 ++++++ docs/scarpet/api/Entities.md | 12 ++++++- .../java/carpet/script/value/EntityValue.java | 34 +++++++++++++++---- 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/docs/scarpet/Full.md b/docs/scarpet/Full.md index 3b944c5d..c6e69326 100644 --- a/docs/scarpet/Full.md +++ b/docs/scarpet/Full.md @@ -2729,6 +2729,17 @@ Will make the entity constantly jump if set to true, and will stop the entity fr Will make the entity jump once only +### `modify(e, 'silent', true/false)` + +### `modify(e, 'gravity', true/false)` + +### `modify(e, 'fire', ticks)` + +Will set mob on fire for `ticks` ticks. Set to 0 to extinguish. + +### `modify(e, 'age', age)` + + ## Entity Events There is a number of events that happen to entities that you can attach your own code to in the form of event handlers. diff --git a/docs/scarpet/api/Entities.md b/docs/scarpet/api/Entities.md index 65f69f51..659acc2a 100644 --- a/docs/scarpet/api/Entities.md +++ b/docs/scarpet/api/Entities.md @@ -464,7 +464,7 @@ Modifies gamemode of player to whatever string (case-insensitive) or number you * 2: adventure * 3: spectator -### `modify(e, 'jumping', true/false?)` +### `modify(e, 'jumping', true/false)` Will make the entity constantly jump if set to true, and will stop the entity from jumping if set to false. @@ -472,6 +472,16 @@ Will make the entity constantly jump if set to true, and will stop the entity fr Will make the entity jump once only +### `modify(e, 'silent', true/false)` + +### `modify(e, 'gravity', true/false)` + +### `modify(e, 'fire', ticks)` + +Will set mob on fire for `ticks` ticks. Set to 0 to extinguish. + +### `modify(e, 'age', age)` + ## Entity Events There is a number of events that happen to entities that you can attach your own code to in the form of event handlers. diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index be53b844..f09b6cd9 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -912,21 +912,41 @@ public class EntityValue extends Value ((LivingEntity) e).setJumping(v.getBoolean()); }); - put("jump",(e,v)->{//Most *REDACTED* up code in the world + put("jump",(e,v)->{ jump((LivingEntity)e); }); + put("silent",(e,v)->{ + e.setSilent(v.getBoolean()); + }); + + put("gravity",(e,v)->{ + e.setNoGravity(!v.getBoolean()); + }); + + put("invulnerable",(e,v)->{ + e.setInvulnerable(v.getBoolean()); + }); + + put("fire",(e,v)->{ + e.setFireTicks((int)NumericValue.asNumber(v).getLong()); + }); + + put("age",(e,v)->{ + e.age=(int)NumericValue.asNumber(v).getLong(); + }); + // gamemode [check] // spectate [check] - // "fire" [] - // "extinguish" [] - // "silent" [] - // "gravity" [] - // "invulnerable" [] + // "fire" [check] + // "extinguish" [set fire ticks to 0] + // "silent" [check] + // "gravity" [check] + // "invulnerable" [check] // "dimension" [] // "item" [] // "count", [] - // "age", [] + // "age", [check] // "effect_"name [] // "hold" [inventory_set?] // "hold_offhand" [inventory_set?] From 049e44887f7ebbbf7e8a73f5408537d2710ba0dd Mon Sep 17 00:00:00 2001 From: Nameless-123 <53367549+Nameless-123@users.noreply.github.com> Date: Mon, 27 Apr 2020 09:50:51 +0200 Subject: [PATCH 22/22] removed unused import --- src/main/java/carpet/script/value/EntityValue.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index f09b6cd9..840568c1 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -10,7 +10,6 @@ import carpet.script.EntityEventsGroup; import carpet.script.exception.InternalExpressionException; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.entity.effect.StatusEffects; import net.minecraft.network.packet.s2c.play.EntityPassengersSetS2CPacket; import net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket; import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket;