From 0d55473e45449c296dda79adc920caa445c6e5d5 Mon Sep 17 00:00:00 2001 From: AlexProgrammerDE <40795980+AlexProgrammerDE@users.noreply.github.com> Date: Thu, 12 Dec 2024 20:08:53 +0100 Subject: [PATCH] Implement some more values --- .../server/protocol/bot/state/entity/Mob.java | 22 +++++++++++++++++++ .../protocol/bot/state/entity/Player.java | 18 ++++++++++----- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/com/soulfiremc/server/protocol/bot/state/entity/Mob.java b/server/src/main/java/com/soulfiremc/server/protocol/bot/state/entity/Mob.java index 1257f125..233a0d0d 100644 --- a/server/src/main/java/com/soulfiremc/server/protocol/bot/state/entity/Mob.java +++ b/server/src/main/java/com/soulfiremc/server/protocol/bot/state/entity/Mob.java @@ -19,8 +19,10 @@ import com.soulfiremc.server.data.EntityType; import com.soulfiremc.server.data.EquipmentSlot; +import com.soulfiremc.server.data.NamedEntityData; import com.soulfiremc.server.protocol.bot.container.SFItemStack; import com.soulfiremc.server.protocol.bot.state.Level; +import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.MetadataType; import org.jetbrains.annotations.Nullable; import java.util.EnumMap; @@ -28,6 +30,9 @@ import java.util.Optional; public class Mob extends LivingEntity { + private static final int MOB_FLAG_NO_AI = 1; + private static final int MOB_FLAG_LEFTHANDED = 2; + private static final int MOB_FLAG_AGGRESSIVE = 4; private final Map slots = new EnumMap<>(EquipmentSlot.class); public Mob(EntityType entityType, Level level) { @@ -43,4 +48,21 @@ public Optional getItemBySlot(EquipmentSlot slot) { public void setItemSlot(EquipmentSlot slot, @Nullable SFItemStack item) { slots.put(slot, item); } + + @Override + public boolean isEffectiveAi() { + return super.isEffectiveAi() && !this.isNoAi(); + } + + public boolean isNoAi() { + return (this.metadataState.getMetadata(NamedEntityData.MOB__MOB_FLAGS, MetadataType.BYTE) & MOB_FLAG_NO_AI) != 0; + } + + public boolean isLeftHanded() { + return (this.metadataState.getMetadata(NamedEntityData.MOB__MOB_FLAGS, MetadataType.BYTE) & MOB_FLAG_LEFTHANDED) != 0; + } + + public boolean isAggressive() { + return (this.metadataState.getMetadata(NamedEntityData.MOB__MOB_FLAGS, MetadataType.BYTE) & MOB_FLAG_AGGRESSIVE) != 0; + } } diff --git a/server/src/main/java/com/soulfiremc/server/protocol/bot/state/entity/Player.java b/server/src/main/java/com/soulfiremc/server/protocol/bot/state/entity/Player.java index b17eed42..c4e08405 100644 --- a/server/src/main/java/com/soulfiremc/server/protocol/bot/state/entity/Player.java +++ b/server/src/main/java/com/soulfiremc/server/protocol/bot/state/entity/Player.java @@ -46,21 +46,27 @@ public abstract class Player extends LivingEntity { private final PlayerInventoryContainer inventory = new PlayerInventoryContainer(); private final AbilitiesData abilitiesData = new AbilitiesData(); + public static final float CROUCH_BB_HEIGHT = 1.5F; + public static final float SWIMMING_BB_WIDTH = 0.6F; + public static final float SWIMMING_BB_HEIGHT = 0.6F; + public static final float DEFAULT_EYE_HEIGHT = 1.62F; public static final EntityDimensions STANDING_DIMENSIONS = EntityDimensions.scalable(0.6F, 1.8F) - .withEyeHeight(1.62F); + .withEyeHeight(DEFAULT_EYE_HEIGHT); private static final Map POSES = ImmutableMap.builder() .put(Pose.STANDING, STANDING_DIMENSIONS) .put(Pose.SLEEPING, SLEEPING_DIMENSIONS) .put(Pose.FALL_FLYING, EntityDimensions.scalable(0.6F, 0.6F).withEyeHeight(0.4F)) - .put(Pose.SWIMMING, EntityDimensions.scalable(0.6F, 0.6F).withEyeHeight(0.4F)) + .put(Pose.SWIMMING, EntityDimensions.scalable(SWIMMING_BB_WIDTH, SWIMMING_BB_HEIGHT).withEyeHeight(0.4F)) .put(Pose.SPIN_ATTACK, EntityDimensions.scalable(0.6F, 0.6F).withEyeHeight(0.4F)) - .put(Pose.SNEAKING, EntityDimensions.scalable(0.6F, 1.5F).withEyeHeight(1.27F)) - .put(Pose.DYING, EntityDimensions.fixed(0.2F, 0.2F).withEyeHeight(1.62F)) + .put(Pose.SNEAKING, EntityDimensions.scalable(0.6F, CROUCH_BB_HEIGHT).withEyeHeight(1.27F)) + .put(Pose.DYING, EntityDimensions.fixed(0.2F, 0.2F).withEyeHeight(DEFAULT_EYE_HEIGHT)) .build(); + public static final int CLIENT_LOADED_TIMEOUT_TIME = 60; protected final GameProfile gameProfile; protected boolean wasUnderwater = false; private boolean reducedDebugInfo; - protected int clientLoadedTimeoutTimer = 60; + protected final float defaultFlySpeed = 0.02F; + protected int clientLoadedTimeoutTimer = CLIENT_LOADED_TIMEOUT_TIME; private boolean clientLoaded = false; public Player(Level level, GameProfile gameProfile) { @@ -256,7 +262,7 @@ protected float getFlyingSpeed() { if (this.abilitiesData.flying) { return this.isSprinting() ? this.abilitiesData.flySpeed() * 2.0F : this.abilitiesData.flySpeed(); } else { - return this.isSprinting() ? 0.025999999F : 0.02F; + return this.isSprinting() ? 0.025999999F : defaultFlySpeed; } }