diff --git a/src/main/java/carpet/fakes/EntityInterface.java b/src/main/java/carpet/fakes/EntityInterface.java index e5936b36..3e4713b9 100644 --- a/src/main/java/carpet/fakes/EntityInterface.java +++ b/src/main/java/carpet/fakes/EntityInterface.java @@ -7,4 +7,8 @@ public interface EntityInterface float getMainYaw(float partialTicks); EntityEventsGroup getEventContainer(); + + boolean isPermanentVehicle(); + + void setPermanentVehicle(boolean permanent); } diff --git a/src/main/java/carpet/mixins/Entity_scarpetEventsMixin.java b/src/main/java/carpet/mixins/Entity_scarpetEventsMixin.java index ca6a4576..c4193054 100644 --- a/src/main/java/carpet/mixins/Entity_scarpetEventsMixin.java +++ b/src/main/java/carpet/mixins/Entity_scarpetEventsMixin.java @@ -14,6 +14,8 @@ public abstract class Entity_scarpetEventsMixin implements EntityInterface { @Shadow public boolean removed; + private boolean permanentVehicle; + private final EntityEventsGroup events = new EntityEventsGroup(); @Override @@ -22,6 +24,18 @@ public abstract class Entity_scarpetEventsMixin implements EntityInterface return events; } + @Override + public boolean isPermanentVehicle() + { + return permanentVehicle; + } + + @Override + public void setPermanentVehicle(boolean permanent) + { + permanentVehicle = permanent; + } + @Inject(method = "tick", at = @At("HEAD")) private void onTickCall(CallbackInfo ci) { @@ -34,4 +48,6 @@ public abstract class Entity_scarpetEventsMixin implements EntityInterface { if (!removed) events.onEvent(EntityEventsGroup.EntityEventType.ON_REMOVED, (Entity) (Object) this); } + + } diff --git a/src/main/java/carpet/mixins/ServerPlayerEntity_scarpetEventMixin.java b/src/main/java/carpet/mixins/ServerPlayerEntity_scarpetEventMixin.java index d7995b9e..7626b0c5 100644 --- a/src/main/java/carpet/mixins/ServerPlayerEntity_scarpetEventMixin.java +++ b/src/main/java/carpet/mixins/ServerPlayerEntity_scarpetEventMixin.java @@ -1,5 +1,6 @@ package carpet.mixins; +import carpet.fakes.EntityInterface; import com.mojang.authlib.GameProfile; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; @@ -53,4 +54,14 @@ public abstract class ServerPlayerEntity_scarpetEventMixin extends PlayerEntity { STATISTICS.onPlayerStatistic((ServerPlayerEntity) (Object)this, stat, amount); } + + @Redirect(method = "method_14218", at = @At( + value = "INVOKE", + target = "Lnet/minecraft/server/network/ServerPlayerEntity;setSneaking(Z)V" + )) + private void setSneakingConditionally(ServerPlayerEntity serverPlayerEntity, boolean sneaking) + { + if (!((EntityInterface)serverPlayerEntity.getVehicle()).isPermanentVehicle()) // won't since that method makes sure its not null + serverPlayerEntity.setSneaking(sneaking); + } } diff --git a/src/main/java/carpet/script/CarpetExpression.java b/src/main/java/carpet/script/CarpetExpression.java index 4990c1b4..e12fae08 100644 --- a/src/main/java/carpet/script/CarpetExpression.java +++ b/src/main/java/carpet/script/CarpetExpression.java @@ -2244,9 +2244,12 @@ public class CarpetExpression *

modify(e, 'accelerate', x, y, z), modify(e, 'accelerate', l(x, y, z) )

*

Adds a vector to the motion vector. Most realistic way to apply a force to an entity.

*

modify(e, 'custom_name'), modify(e, 'custom_name', name )

- *

modify(e, 'pickup_delay')

- *

modify(e, 'breeding_age')

- *

modify(e, 'despawn_timer')

+ *

modify(e, 'age', number)

+ *

Modifies entity's internal age counter. Fiddling with this will affect directly + * behaviours of complex entities, so use it with caution.

+ *

modify(e, 'pickup_delay', number)

+ *

modify(e, 'breeding_age', number)

+ *

modify(e, 'despawn_timer', number)

*

Sets a custom despawn timer value.

*

modify(e, 'dismount')

*

Dismounts riding entity.

diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index f3a39475..c97ad102 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -228,6 +228,7 @@ public class EntityValue extends Value put("is_ridden", (e, a) -> new NumericValue(e.hasPassengers())); put("passengers", (e, a) -> ListValue.wrap(e.getPassengerList().stream().map(EntityValue::new).collect(Collectors.toList()))); put("mount", (e, a) -> (e.getVehicle()!=null)?new EntityValue(e.getVehicle()):Value.NULL); + put("unmountable", (e, a) -> new NumericValue(((EntityInterface)e).isPermanentVehicle())); put("tags", (e, a) -> ListValue.wrap(e.getScoreboardTags().stream().map(StringValue::new).collect(Collectors.toList()))); put("has_tag", (e, a) -> new NumericValue(e.getScoreboardTags().contains(a.getString()))); put("yaw", (e, a)-> new NumericValue(e.yaw)); @@ -517,6 +518,7 @@ public class EntityValue extends Value private static final Map> featureModifiers = new HashMap>() {{ put("remove", (entity, value) -> entity.remove()); + put("age", (e, v) -> e.age = Math.abs((int)NumericValue.asNumber(v).getLong()) ); put("health", (e, v) -> { if (e instanceof LivingEntity) ((LivingEntity) e).setHealth((float) NumericValue.asNumber(v).getDouble()); }); put("kill", (e, v) -> e.kill()); put("location", (e, v) -> @@ -660,6 +662,11 @@ public class EntityValue extends Value //... } }); + put("unmountable", (e, v) ->{ + if (v == null) + v = Value.TRUE; + ((EntityInterface)e).setPermanentVehicle(v.getBoolean()); + }); put("drop_passengers", (e, v) -> e.removeAllPassengers()); put("mount_passengers", (e, v) -> { if (v==null)