From b4482214c91bc717334d63050c44ec872960b1b2 Mon Sep 17 00:00:00 2001 From: gnembon Date: Fri, 10 Jan 2020 21:48:09 -0400 Subject: [PATCH 1/3] customizable forceload limit --- src/main/java/carpet/CarpetSettings.java | 10 ++++++++ .../ForceLoadCommand_forceLoadLimitMixin.java | 23 +++++++++++++++++++ src/main/resources/carpet.mixins.json | 1 + 3 files changed, 34 insertions(+) create mode 100644 src/main/java/carpet/mixins/ForceLoadCommand_forceLoadLimitMixin.java diff --git a/src/main/java/carpet/CarpetSettings.java b/src/main/java/carpet/CarpetSettings.java index c6cb9f4d..63acd0e1 100644 --- a/src/main/java/carpet/CarpetSettings.java +++ b/src/main/java/carpet/CarpetSettings.java @@ -353,6 +353,16 @@ public class CarpetSettings ) public static int fillLimit = 32768; + + @Rule( + desc = "Customizable forceload chunk limit", + options = {"256"}, + category = CREATIVE, + strict = false, + validate = FillLimitLimits.class + ) + public static int forceloadLimit = 256; + @Rule( desc = "Customizable maximal entity collision limits, 0 for no limits", options = {"0", "1", "20"}, diff --git a/src/main/java/carpet/mixins/ForceLoadCommand_forceLoadLimitMixin.java b/src/main/java/carpet/mixins/ForceLoadCommand_forceLoadLimitMixin.java new file mode 100644 index 00000000..57e2afdc --- /dev/null +++ b/src/main/java/carpet/mixins/ForceLoadCommand_forceLoadLimitMixin.java @@ -0,0 +1,23 @@ +package carpet.mixins; + +import carpet.CarpetSettings; +import net.minecraft.server.command.ForceLoadCommand; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.Constant; +import org.spongepowered.asm.mixin.injection.ModifyConstant; + +@Mixin(ForceLoadCommand.class) +public class ForceLoadCommand_forceLoadLimitMixin +{ + @ModifyConstant(method = "executeChange", constant = @Constant(longValue = 256L)) + private static long forceloadLimit(long original) + { + return CarpetSettings.forceloadLimit; + } + + @ModifyConstant(method = "executeChange", constant = @Constant(intValue = 256)) + private static int forceloadLimitError(int original) + { + return CarpetSettings.forceloadLimit; + } +} diff --git a/src/main/resources/carpet.mixins.json b/src/main/resources/carpet.mixins.json index 53dbbe21..cad267bf 100644 --- a/src/main/resources/carpet.mixins.json +++ b/src/main/resources/carpet.mixins.json @@ -9,6 +9,7 @@ "FillCommandMixin", "CloneCommandMixin", "SetBlockCommandMixin", + "ForceLoadCommand_forceLoadLimitMixin", "World_fillUpdatesMixin", "WorldChunk_fillUpdatesMixin", "StructureBlockBlockEntity_fillUpdatesMixin", From e44cf0d79b8d84d731d7a2c52b82763f5bdb4f70 Mon Sep 17 00:00:00 2001 From: gnembon Date: Fri, 10 Jan 2020 21:48:55 -0400 Subject: [PATCH 2/3] action pack improvements --- .../java/carpet/commands/PlayerCommand.java | 7 ++-- .../helpers/EntityPlayerActionPack.java | 38 ++++++++++++++----- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/main/java/carpet/commands/PlayerCommand.java b/src/main/java/carpet/commands/PlayerCommand.java index 1607bcd2..47c63e59 100644 --- a/src/main/java/carpet/commands/PlayerCommand.java +++ b/src/main/java/carpet/commands/PlayerCommand.java @@ -57,7 +57,8 @@ public class PlayerCommand .then(makeActionCommand("swapHands", EntityPlayerActionPack.ActionType.SWAP_HANDS)) .then(literal("kill").executes(PlayerCommand::kill)) .then(literal("shadow"). executes(PlayerCommand::shadow)) - .then(literal("mount").executes(manipulation(EntityPlayerActionPack::mount))) + .then(literal("mount").executes(manipulation(ap -> ap.mount(true))) + .then(literal("anything").executes(manipulation(ap -> ap.mount(false))))) .then(literal("dismount").executes(manipulation(EntityPlayerActionPack::dismount))) .then(literal("sneak").executes(manipulation(ap -> ap.setSneaking(true)))) .then(literal("unsneak").executes(manipulation(ap -> ap.setSneaking(false)))) @@ -78,7 +79,7 @@ public class PlayerCommand .then(literal("back").executes(c -> manipulate(c, ap -> ap.turn(180, 0)))) .then(argument("rotation", RotationArgumentType.rotation()) .executes(c -> manipulate(c, ap -> ap.turn(RotationArgumentType.getRotation(c, "rotation").toAbsoluteRotation(c.getSource()))))) - ).then(literal("move") + ).then(literal("move").executes(c -> manipulate(c, EntityPlayerActionPack::stopMovement)) .then(literal("forward").executes(c -> manipulate(c, ap -> ap.setForward(1)))) .then(literal("backward").executes(c -> manipulate(c, ap -> ap.setForward(-1)))) .then(literal("left").executes(c -> manipulate(c, ap -> ap.setStrafing(1)))) @@ -244,7 +245,7 @@ public class PlayerCommand { if (cantManipulate(context)) return 0; ServerPlayerEntity player = getPlayer(context); - ((ServerPlayerEntityInterface) player).getActionPack().stop(); + ((ServerPlayerEntityInterface) player).getActionPack().stopAll(); return 1; } diff --git a/src/main/java/carpet/helpers/EntityPlayerActionPack.java b/src/main/java/carpet/helpers/EntityPlayerActionPack.java index 346de1f4..f49a9fb0 100644 --- a/src/main/java/carpet/helpers/EntityPlayerActionPack.java +++ b/src/main/java/carpet/helpers/EntityPlayerActionPack.java @@ -1,9 +1,11 @@ package carpet.helpers; import carpet.fakes.ServerPlayerEntityInterface; -import carpet.mixins.PlayerActionC2SPacketMixin; import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; +import net.minecraft.entity.passive.HorseBaseEntity; +import net.minecraft.entity.vehicle.BoatEntity; +import net.minecraft.entity.vehicle.MinecartEntity; import net.minecraft.item.ItemStack; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.packet.PlayerActionC2SPacket; @@ -42,7 +44,7 @@ public class EntityPlayerActionPack public EntityPlayerActionPack(ServerPlayerEntity playerIn) { player = playerIn; - stop(); + stopAll(); } public void copyFrom(EntityPlayerActionPack other) { @@ -133,11 +135,8 @@ public class EntityPlayerActionPack return turn(rotation.x, rotation.y); } - - public EntityPlayerActionPack stop() + public EntityPlayerActionPack stopMovement() { - for (ActionType type : actions.keySet()) type.stop(player, actions.get(type)); - actions.clear(); setSneaking(false); setSprinting(false); forward = 0.0F; @@ -145,10 +144,27 @@ public class EntityPlayerActionPack return this; } - public EntityPlayerActionPack mount() + + public EntityPlayerActionPack stopAll() + { + for (ActionType type : actions.keySet()) type.stop(player, actions.get(type)); + actions.clear(); + return stopMovement(); + } + + public EntityPlayerActionPack mount(boolean onlyRideables) { //test what happens - List entities = player.world.getEntities(player,player.getBoundingBox().expand(3.0D, 1.0D, 3.0D)); + List entities; + if (onlyRideables) + { + entities = player.world.getEntities(player, player.getBoundingBox().expand(3.0D, 1.0D, 3.0D), + e -> e instanceof MinecartEntity || e instanceof BoatEntity || e instanceof HorseBaseEntity); + } + else + { + entities = player.world.getEntities(player, player.getBoundingBox().expand(3.0D, 1.0D, 3.0D)); + } if (entities.size()==0) return this; Entity closest = null; @@ -165,7 +181,11 @@ public class EntityPlayerActionPack closest = e; } } - if (closest != null) player.startRiding(closest,true); + if (closest == null) return this; + if (closest instanceof HorseBaseEntity && onlyRideables) + ((HorseBaseEntity) closest).interactMob(player, Hand.MAIN_HAND); + else + player.startRiding(closest,true); return this; } public EntityPlayerActionPack dismount() From f8c8296f29bad631c873f6d98a30cb68b4b11193 Mon Sep 17 00:00:00 2001 From: gnembon Date: Fri, 10 Jan 2020 21:50:03 -0400 Subject: [PATCH 3/3] added breeding age, so there is no need to messup with data command for that. --- src/main/java/carpet/script/CarpetExpression.java | 4 +++- src/main/java/carpet/script/value/EntityValue.java | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/carpet/script/CarpetExpression.java b/src/main/java/carpet/script/CarpetExpression.java index 7cf338b0..0dbfa1fe 100644 --- a/src/main/java/carpet/script/CarpetExpression.java +++ b/src/main/java/carpet/script/CarpetExpression.java @@ -1724,6 +1724,8 @@ public class CarpetExpression *

Eye height of the entity.

*

query(e,'age')

*

Age, in ticks, of the entity, i.e. how long it existed.

+ *

query(e,'breeding_age')

+ *

Breeding age of passive entity, in ticks. If negative it it time to adulthood, if positive, breeding cooldown

*

query(e,'despawn_timer')

*

For living entities - the number of ticks they fall outside of immediate player presence.

*

query(e,'item')

@@ -1825,7 +1827,7 @@ public class CarpetExpression *

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')

- *

Sets a custom pickup delay if the entity argument is an item entity

+ *

modify(e, 'breeding_age')

*

modify(e, 'despawn_timer')

*

Sets a custom despawn timer value.

*

modify(e, 'dismount')

diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index e88c4900..f81e6f3d 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -26,6 +26,7 @@ import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.mob.MobEntityWithAi; +import net.minecraft.entity.passive.PassiveEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.CompoundTag; import net.minecraft.predicate.entity.EntityPredicates; @@ -245,6 +246,7 @@ public class EntityValue extends Value put("width", (e, a) -> new NumericValue(e.getDimensions(EntityPose.STANDING).width)); put("eye_height", (e, a) -> new NumericValue(e.getStandingEyeHeight())); put("age", (e, a) -> new NumericValue(e.age)); + put("breeding_age", (e, a) -> e instanceof PassiveEntity?new NumericValue(((PassiveEntity) e).getBreedingAge()):Value.NULL); put("despawn_timer", (e, a) -> e instanceof LivingEntity?new NumericValue(((LivingEntity) e).getDespawnCounter()):Value.NULL); put("item", (e, a) -> (e instanceof ItemEntity)?ListValue.fromItemStack(((ItemEntity) e).getStack()):Value.NULL); put("count", (e, a) -> (e instanceof ItemEntity)?new NumericValue(((ItemEntity) e).getStack().getCount()):Value.NULL); @@ -681,6 +683,13 @@ public class EntityValue extends Value // ((MobEntity) e).setTarget(elb); // } //}); + put("breeding_age", (e, v) -> + { + if (e instanceof PassiveEntity) + { + ((PassiveEntity) e).setBreedingAge((int)NumericValue.asNumber(v).getLong()); + } + }); put("talk", (e, v) -> { // attacks indefinitely if (e instanceof MobEntity) @@ -790,8 +799,6 @@ public class EntityValue extends Value if (lv.size() >= 2 && lv.size() <= 5) { String effectName = lv.get(0).getString(); - if (effectName.startsWith("minecraft:")) - effectName = "minecraft:"+effectName; StatusEffect effect = Registry.STATUS_EFFECT.get(new Identifier(effectName)); if (effect == null) throw new InternalExpressionException("Wrong effect name: "+effectName);