| 1 | package net.minecraft.world.entity.player;
|
| 2 |
|
| 3 | import com.google.common.base.MoreObjects;
|
| 4 | import com.google.common.collect.ImmutableList;
|
| 5 | import com.google.common.collect.Lists;
|
| 6 | import com.google.common.math.IntMath;
|
| 7 | import com.mojang.authlib.GameProfile;
|
| 8 | import com.mojang.datafixers.util.Either;
|
| 9 | import java.util.ArrayList;
|
| 10 | import java.util.Collection;
|
| 11 | import java.util.List;
|
| 12 | import java.util.Optional;
|
| 13 | import java.util.OptionalInt;
|
| 14 | import java.util.function.Predicate;
|
| 15 | import net.minecraft.core.BlockPos;
|
| 16 | import net.minecraft.core.Direction;
|
| 17 | import net.minecraft.core.GlobalPos;
|
| 18 | import net.minecraft.core.Holder;
|
| 19 | import net.minecraft.core.component.DataComponents;
|
| 20 | import net.minecraft.core.particles.ParticleTypes;
|
| 21 | import net.minecraft.nbt.CompoundTag;
|
| 22 | import net.minecraft.nbt.NbtUtils;
|
| 23 | import net.minecraft.network.chat.ClickEvent;
|
| 24 | import net.minecraft.network.chat.Component;
|
| 25 | import net.minecraft.network.chat.MutableComponent;
|
| 26 | import net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket;
|
| 27 | import net.minecraft.network.syncher.EntityDataAccessor;
|
| 28 | import net.minecraft.network.syncher.EntityDataSerializers;
|
| 29 | import net.minecraft.network.syncher.SynchedEntityData;
|
| 30 | import net.minecraft.resources.Identifier;
|
| 31 | import net.minecraft.server.dialog.Dialog;
|
| 32 | import net.minecraft.server.level.ServerLevel;
|
| 33 | import net.minecraft.server.level.ServerPlayer;
|
| 34 | import net.minecraft.server.permissions.PermissionSet;
|
| 35 | import net.minecraft.server.permissions.Permissions;
|
| 36 | import net.minecraft.server.players.NameAndId;
|
| 37 | import net.minecraft.sounds.SoundEvent;
|
| 38 | import net.minecraft.sounds.SoundEvents;
|
| 39 | import net.minecraft.sounds.SoundSource;
|
| 40 | import net.minecraft.stats.Stat;
|
| 41 | import net.minecraft.stats.Stats;
|
| 42 | import net.minecraft.tags.BlockTags;
|
| 43 | import net.minecraft.tags.DamageTypeTags;
|
| 44 | import net.minecraft.tags.EntityTypeTags;
|
| 45 | import net.minecraft.tags.FluidTags;
|
| 46 | import net.minecraft.tags.ItemTags;
|
| 47 | import net.minecraft.util.Mth;
|
| 48 | import net.minecraft.util.Unit;
|
| 49 | import net.minecraft.util.Util;
|
| 50 | import net.minecraft.world.Container;
|
| 51 | import net.minecraft.world.Difficulty;
|
| 52 | import net.minecraft.world.InteractionHand;
|
| 53 | import net.minecraft.world.InteractionResult;
|
| 54 | import net.minecraft.world.ItemStackWithSlot;
|
| 55 | import net.minecraft.world.MenuProvider;
|
| 56 | import net.minecraft.world.attribute.BedRule;
|
| 57 | import net.minecraft.world.damagesource.DamageSource;
|
| 58 | import net.minecraft.world.effect.MobEffectInstance;
|
| 59 | import net.minecraft.world.effect.MobEffectUtil;
|
| 60 | import net.minecraft.world.effect.MobEffects;
|
| 61 | import net.minecraft.world.entity.Avatar;
|
| 62 | import net.minecraft.world.entity.ContainerUser;
|
| 63 | import net.minecraft.world.entity.Entity;
|
| 64 | import net.minecraft.world.entity.EntityEquipment;
|
| 65 | import net.minecraft.world.entity.EntityEvent;
|
| 66 | import net.minecraft.world.entity.EntityReference;
|
| 67 | import net.minecraft.world.entity.EntityType;
|
| 68 | import net.minecraft.world.entity.EntityTypes;
|
| 69 | import net.minecraft.world.entity.EquipmentSlot;
|
| 70 | import net.minecraft.world.entity.HumanoidArm;
|
| 71 | import net.minecraft.world.entity.LivingEntity;
|
| 72 | import net.minecraft.world.entity.MoveSimulationType;
|
| 73 | import net.minecraft.world.entity.MoverType;
|
| 74 | import net.minecraft.world.entity.Pose;
|
| 75 | import net.minecraft.world.entity.SlotAccess;
|
| 76 | import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
|
| 77 | import net.minecraft.world.entity.ai.attributes.Attributes;
|
| 78 | import net.minecraft.world.entity.animal.equine.AbstractHorse;
|
| 79 | import net.minecraft.world.entity.animal.nautilus.AbstractNautilus;
|
| 80 | import net.minecraft.world.entity.animal.parrot.Parrot;
|
| 81 | import net.minecraft.world.entity.boss.enderdragon.EnderDragonPart;
|
| 82 | import net.minecraft.world.entity.decoration.ArmorStand;
|
| 83 | import net.minecraft.world.entity.projectile.FishingHook;
|
| 84 | import net.minecraft.world.entity.projectile.Projectile;
|
| 85 | import net.minecraft.world.entity.projectile.ProjectileDeflection;
|
| 86 | import net.minecraft.world.entity.vehicle.minecart.MinecartCommandBlock;
|
| 87 | import net.minecraft.world.food.FoodData;
|
| 88 | import net.minecraft.world.inventory.AbstractContainerMenu;
|
| 89 | import net.minecraft.world.inventory.ClickAction;
|
| 90 | import net.minecraft.world.inventory.InventoryMenu;
|
| 91 | import net.minecraft.world.inventory.PlayerEnderChestContainer;
|
| 92 | import net.minecraft.world.item.Item;
|
| 93 | import net.minecraft.world.item.ItemCooldowns;
|
| 94 | import net.minecraft.world.item.ItemStack;
|
| 95 | import net.minecraft.world.item.Items;
|
| 96 | import net.minecraft.world.item.ProjectileWeaponItem;
|
| 97 | import net.minecraft.world.item.component.BlocksAttacks;
|
| 98 | import net.minecraft.world.item.component.ResolvableProfile;
|
| 99 | import net.minecraft.world.item.crafting.RecipeHolder;
|
| 100 | import net.minecraft.world.item.enchantment.EnchantmentEffectComponents;
|
| 101 | import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
| 102 | import net.minecraft.world.item.equipment.Equippable;
|
| 103 | import net.minecraft.world.item.trading.MerchantOffers;
|
| 104 | import net.minecraft.world.level.GameType;
|
| 105 | import net.minecraft.world.level.Level;
|
| 106 | import net.minecraft.world.level.block.AbstractBedBlock;
|
| 107 | import net.minecraft.world.level.block.entity.CommandBlockEntity;
|
| 108 | import net.minecraft.world.level.block.entity.ContainerOpenersCounter;
|
| 109 | import net.minecraft.world.level.block.entity.JigsawBlockEntity;
|
| 110 | import net.minecraft.world.level.block.entity.SignBlockEntity;
|
| 111 | import net.minecraft.world.level.block.entity.SignTextSlot;
|
| 112 | import net.minecraft.world.level.block.entity.StructureBlockEntity;
|
| 113 | import net.minecraft.world.level.block.entity.TestBlockEntity;
|
| 114 | import net.minecraft.world.level.block.entity.TestInstanceBlockEntity;
|
| 115 | import net.minecraft.world.level.block.state.BlockState;
|
| 116 | import net.minecraft.world.level.block.state.pattern.BlockInWorld;
|
| 117 | import net.minecraft.world.level.gameevent.GameEvent;
|
| 118 | import net.minecraft.world.level.gamerules.GameRules;
|
| 119 | import net.minecraft.world.level.storage.ValueInput;
|
| 120 | import net.minecraft.world.level.storage.ValueOutput;
|
| 121 | import net.minecraft.world.phys.AABB;
|
| 122 | import net.minecraft.world.phys.Vec3;
|
| 123 | import net.minecraft.world.scores.PlayerTeam;
|
| 124 | import org.jspecify.annotations.Nullable;
|
| 125 |
|
| 126 | public abstract class Player extends Avatar implements ContainerUser {
|
| 127 | public static final int MAX_HEALTH = 20;
|
| 128 | public static final int SLEEP_DURATION = 100;
|
| 129 | public static final int WAKE_UP_DURATION = 10;
|
| 130 | public static final int ENDER_SLOT_OFFSET = 200;
|
| 131 | public static final int HELD_ITEM_SLOT = 499;
|
| 132 | public static final int CRAFTING_SLOT_OFFSET = 500;
|
| 133 | public static final float DEFAULT_BLOCK_INTERACTION_RANGE = 4.5F;
|
| 134 | public static final float DEFAULT_ENTITY_INTERACTION_RANGE = 3.0F;
|
| 135 | private static final EntityDataAccessor<Float> DATA_PLAYER_ABSORPTION_ID = SynchedEntityData.defineId(Player.class, EntityDataSerializers.FLOAT);
|
| 136 | private static final EntityDataAccessor<Integer> DATA_SCORE_ID = SynchedEntityData.defineId(Player.class, EntityDataSerializers.INT);
|
| 137 | private static final EntityDataAccessor<OptionalInt> DATA_SHOULDER_PARROT_LEFT = SynchedEntityData.defineId(
|
| 138 | Player.class, EntityDataSerializers.OPTIONAL_UNSIGNED_INT
|
| 139 | );
|
| 140 | private static final EntityDataAccessor<OptionalInt> DATA_SHOULDER_PARROT_RIGHT = SynchedEntityData.defineId(
|
| 141 | Player.class, EntityDataSerializers.OPTIONAL_UNSIGNED_INT
|
| 142 | );
|
| 143 | private static final short DEFAULT_SLEEP_TIMER = 0;
|
| 144 | private static final float DEFAULT_EXPERIENCE_PROGRESS = 0.0F;
|
| 145 | private static final int DEFAULT_EXPERIENCE_LEVEL = 0;
|
| 146 | private static final int DEFAULT_TOTAL_EXPERIENCE = 0;
|
| 147 | private static final int NO_ENCHANTMENT_SEED = 0;
|
| 148 | private static final int DEFAULT_SELECTED_SLOT = 0;
|
| 149 | private static final int DEFAULT_SCORE = 0;
|
| 150 | public static final float CREATIVE_ENTITY_INTERACTION_RANGE_MODIFIER_VALUE = 2.0F;
|
| 151 | private final Inventory inventory;
|
| 152 | protected PlayerEnderChestContainer enderChestInventory = new PlayerEnderChestContainer();
|
| 153 | public final InventoryMenu inventoryMenu;
|
| 154 | public AbstractContainerMenu containerMenu;
|
| 155 | protected FoodData foodData = new FoodData();
|
| 156 | protected int jumpTriggerTime;
|
| 157 | public int takeXpDelay;
|
| 158 | private int sleepCounter = 0;
|
| 159 | protected boolean wasUnderwater;
|
| 160 | private final Abilities abilities = new Abilities();
|
| 161 | public int experienceLevel = 0;
|
| 162 | public int totalExperience = 0;
|
| 163 | public float experienceProgress = 0.0F;
|
| 164 | protected int enchantmentSeed = 0;
|
| 165 | protected final float defaultFlySpeed = 0.02F;
|
| 166 | private int lastLevelUpTime;
|
| 167 | private final GameProfile gameProfile;
|
| 168 | private boolean reducedDebugInfo;
|
| 169 | private ItemStack lastItemInMainHand = ItemStack.EMPTY;
|
| 170 | private final ItemCooldowns cooldowns = this.createItemCooldowns();
|
| 171 | private Optional<GlobalPos> lastDeathLocation = Optional.empty();
|
| 172 | protected final List<Identifier> postEffects = new ArrayList<>();
|
| 173 | public @Nullable FishingHook fishing;
|
| 174 | protected float hurtDir;
|
| 175 |
|
| 176 | public Player(final Level level, final GameProfile gameProfile) {
|
| 177 | super(EntityTypes.PLAYER, level);
|
| 178 | this.setUUID(gameProfile.id());
|
| 179 | this.gameProfile = gameProfile;
|
| 180 | this.inventory = new Inventory(this, this.equipment);
|
| 181 | this.inventoryMenu = new InventoryMenu(this.inventory, !level.isClientSide(), this);
|
| 182 | this.containerMenu = this.inventoryMenu;
|
| 183 | }
|
| 184 |
|
| 185 | @Override
|
| 186 | protected EntityEquipment createEquipment() {
|
| 187 | return new PlayerEquipment(this);
|
| 188 | }
|
| 189 |
|
| 190 | public boolean blockActionRestricted(final Level level, final BlockPos pos, final GameType gameType) {
|
| 191 | if (!gameType.isBlockPlacingRestricted()) {
|
| 192 | return false;
|
| 193 | }
|
| 194 |
|
| 195 | if (gameType == GameType.SPECTATOR) {
|
| 196 | return true;
|
| 197 | }
|
| 198 |
|
| 199 | if (this.mayBuild()) {
|
| 200 | return false;
|
| 201 | }
|
| 202 |
|
| 203 | ItemStack itemStack = this.getMainHandItem();
|
| 204 | return itemStack.isEmpty() || !itemStack.canBreakBlockInAdventureMode(new BlockInWorld(level, pos, false));
|
| 205 | }
|
| 206 |
|
| 207 | public static AttributeSupplier.Builder createAttributes() {
|
| 208 | return LivingEntity.createLivingAttributes()
|
| 209 | .add(Attributes.ATTACK_DAMAGE, 1.0)
|
| 210 | .add(Attributes.MOVEMENT_SPEED, 0.1F)
|
| 211 | .add(Attributes.ATTACK_SPEED)
|
| 212 | .add(Attributes.LUCK)
|
| 213 | .add(Attributes.BLOCK_INTERACTION_RANGE)
|
| 214 | .add(Attributes.BLOCK_BREAK_SPEED)
|
| 215 | .add(Attributes.SUBMERGED_MINING_SPEED)
|
| 216 | .add(Attributes.SNEAKING_SPEED)
|
| 217 | .add(Attributes.MINING_EFFICIENCY)
|
| 218 | .add(Attributes.SWEEPING_DAMAGE_RATIO)
|
| 219 | .add(Attributes.WAYPOINT_TRANSMIT_RANGE, 6.0E7)
|
| 220 | .add(Attributes.WAYPOINT_RECEIVE_RANGE, 6.0E7);
|
| 221 | }
|
| 222 |
|
| 223 | @Override
|
| 224 | protected void defineSynchedData(final SynchedEntityData.Builder entityData) {
|
| 225 | super.defineSynchedData(entityData);
|
| 226 | entityData.define(DATA_PLAYER_ABSORPTION_ID, 0.0F);
|
| 227 | entityData.define(DATA_SCORE_ID, 0);
|
| 228 | entityData.define(DATA_SHOULDER_PARROT_LEFT, OptionalInt.empty());
|
| 229 | entityData.define(DATA_SHOULDER_PARROT_RIGHT, OptionalInt.empty());
|
| 230 | }
|
| 231 |
|
| 232 | @Override
|
| 233 | public void tick() {
|
| 234 | this.noPhysics = this.isSpectator();
|
| 235 | if (this.isSpectator() || this.isPassenger()) {
|
| 236 | this.setOnGround(false);
|
| 237 | }
|
| 238 |
|
| 239 | if (this.takeXpDelay > 0) {
|
| 240 | this.takeXpDelay--;
|
| 241 | }
|
| 242 |
|
| 243 | if (this.isSleeping()) {
|
| 244 | this.sleepCounter++;
|
| 245 | if (this.sleepCounter > 100) {
|
| 246 | this.sleepCounter = 100;
|
| 247 | }
|
| 248 |
|
| 249 | if (!this.level().isClientSide()
|
| 250 | && this.getInBlockState().getBlock() instanceof AbstractBedBlock abstractBedBlock
|
| 251 | && !abstractBedBlock.getBedRule(this.level(), this.blockPosition()).canSleep(this.level())) {
|
| 252 | this.stopSleepInBed(false, true);
|
| 253 | }
|
| 254 | } else if (this.sleepCounter > 0) {
|
| 255 | this.sleepCounter++;
|
| 256 | if (this.sleepCounter >= 110) {
|
| 257 | this.sleepCounter = 0;
|
| 258 | }
|
| 259 | }
|
| 260 |
|
| 261 | this.updateIsUnderwater();
|
| 262 | super.tick();
|
| 263 | int maxPositionOffset = 29999999;
|
| 264 | double nx = Mth.clamp(this.getX(), -2.9999999E7, 2.9999999E7);
|
| 265 | double nz = Mth.clamp(this.getZ(), -2.9999999E7, 2.9999999E7);
|
| 266 | if (nx != this.getX() || nz != this.getZ()) {
|
| 267 | this.setPos(nx, this.getY(), nz);
|
| 268 | }
|
| 269 |
|
| 270 | this.attackStrengthTicker++;
|
| 271 | this.itemSwapTicker++;
|
| 272 | ItemStack mainHandItemStack = this.getMainHandItem();
|
| 273 | if (!ItemStack.matches(this.lastItemInMainHand, mainHandItemStack)) {
|
| 274 | if (!ItemStack.isSameItem(this.lastItemInMainHand, mainHandItemStack)) {
|
| 275 | this.resetAttackStrengthTicker();
|
| 276 | }
|
| 277 |
|
| 278 | this.lastItemInMainHand = mainHandItemStack.copy();
|
| 279 | }
|
| 280 |
|
| 281 | if (!this.isEyeInFluid(FluidTags.WATER) && this.isEquipped(Items.TURTLE_HELMET)) {
|
| 282 | this.turtleHelmetTick();
|
| 283 | }
|
| 284 |
|
| 285 | this.cooldowns.tick();
|
| 286 | this.updatePlayerPose();
|
| 287 | }
|
| 288 |
|
| 289 | @Override
|
| 290 | protected float getMaxHeadRotationRelativeToBody() {
|
| 291 | return this.isBlocking() ? 15.0F : super.getMaxHeadRotationRelativeToBody();
|
| 292 | }
|
| 293 |
|
| 294 | public boolean isSecondaryUseActive() {
|
| 295 | return this.isShiftKeyDown();
|
| 296 | }
|
| 297 |
|
| 298 | protected boolean wantsToStopRiding() {
|
| 299 | return this.isShiftKeyDown();
|
| 300 | }
|
| 301 |
|
| 302 | protected boolean isStayingOnGroundSurface() {
|
| 303 | return this.isShiftKeyDown();
|
| 304 | }
|
| 305 |
|
| 306 | protected boolean updateIsUnderwater() {
|
| 307 | this.wasUnderwater = this.isEyeInFluid(FluidTags.WATER);
|
| 308 | return this.wasUnderwater;
|
| 309 | }
|
| 310 |
|
| 311 | @Override
|
| 312 | public void onAboveBubbleColumn(final boolean dragDown, final BlockPos pos) {
|
| 313 | if (!this.getAbilities().flying) {
|
| 314 | super.onAboveBubbleColumn(dragDown, pos);
|
| 315 | }
|
| 316 | }
|
| 317 |
|
| 318 | @Override
|
| 319 | public void onInsideBubbleColumn(final boolean dragDown) {
|
| 320 | if (!this.getAbilities().flying) {
|
| 321 | super.onInsideBubbleColumn(dragDown);
|
| 322 | }
|
| 323 | }
|
| 324 |
|
| 325 | private void turtleHelmetTick() {
|
| 326 | this.addEffect(new MobEffectInstance(MobEffects.WATER_BREATHING, 200, 0, false, false, true));
|
| 327 | }
|
| 328 |
|
| 329 | private boolean isEquipped(final Item item) {
|
| 330 | for (EquipmentSlot slot : EquipmentSlot.VALUES) {
|
| 331 | ItemStack itemStack = this.getItemBySlot(slot);
|
| 332 | Equippable equippable = itemStack.get(DataComponents.EQUIPPABLE);
|
| 333 | if (itemStack.is(item) && equippable != null && equippable.slot() == slot) {
|
| 334 | return true;
|
| 335 | }
|
| 336 | }
|
| 337 |
|
| 338 | return false;
|
| 339 | }
|
| 340 |
|
| 341 | protected ItemCooldowns createItemCooldowns() {
|
| 342 | return new ItemCooldowns();
|
| 343 | }
|
| 344 |
|
| 345 | protected void updatePlayerPose() {
|
| 346 | if (this.canPlayerFitWithinBlocksAndEntitiesWhen(Pose.SWIMMING)) {
|
| 347 | Pose desiredPose = this.getDesiredPose();
|
| 348 | Pose actualPose;
|
| 349 | if (this.isSpectator() || this.isPassenger() || this.canPlayerFitWithinBlocksAndEntitiesWhen(desiredPose)) {
|
| 350 | actualPose = desiredPose;
|
| 351 | } else if (this.canPlayerFitWithinBlocksAndEntitiesWhen(Pose.CROUCHING)) {
|
| 352 | actualPose = Pose.CROUCHING;
|
| 353 | } else {
|
| 354 | actualPose = Pose.SWIMMING;
|
| 355 | }
|
| 356 |
|
| 357 | this.setPose(actualPose);
|
| 358 | }
|
| 359 | }
|
| 360 |
|
| 361 | private Pose getDesiredPose() {
|
| 362 | if (this.isSleeping()) {
|
| 363 | return Pose.SLEEPING;
|
| 364 | } else if (this.isSwimming()) {
|
| 365 | return Pose.SWIMMING;
|
| 366 | } else if (this.isFallFlying()) {
|
| 367 | return Pose.FALL_FLYING;
|
| 368 | } else if (this.isAutoSpinAttack()) {
|
| 369 | return Pose.SPIN_ATTACK;
|
| 370 | } else {
|
| 371 | return this.isShiftKeyDown() && !this.abilities.flying ? Pose.CROUCHING : Pose.STANDING;
|
| 372 | }
|
| 373 | }
|
| 374 |
|
| 375 | protected boolean canPlayerFitWithinBlocksAndEntitiesWhen(final Pose newPose) {
|
| 376 | return this.level().noCollision(this, this.getDimensions(newPose).makeBoundingBox(this.position()).deflate(1.0E-7));
|
| 377 | }
|
| 378 |
|
| 379 | @Override
|
| 380 | protected SoundEvent getSwimSound() {
|
| 381 | return SoundEvents.PLAYER_SWIM;
|
| 382 | }
|
| 383 |
|
| 384 | @Override
|
| 385 | protected SoundEvent getSwimSplashSound() {
|
| 386 | return SoundEvents.PLAYER_SPLASH;
|
| 387 | }
|
| 388 |
|
| 389 | @Override
|
| 390 | protected SoundEvent getSwimHighSpeedSplashSound() {
|
| 391 | return SoundEvents.PLAYER_SPLASH_HIGH_SPEED;
|
| 392 | }
|
| 393 |
|
| 394 | @Override
|
| 395 | public int getDimensionChangingDelay() {
|
| 396 | return 10;
|
| 397 | }
|
| 398 |
|
| 399 | @Override
|
| 400 | public void playSound(final SoundEvent sound, final float volume, final float pitch) {
|
| 401 | this.level().playSound(this, this.getX(), this.getY(), this.getZ(), sound, this.getSoundSource(), volume, pitch);
|
| 402 | }
|
| 403 |
|
| 404 | @Override
|
| 405 | public SoundSource getSoundSource() {
|
| 406 | return SoundSource.PLAYERS;
|
| 407 | }
|
| 408 |
|
| 409 | @Override
|
| 410 | protected int getFireImmuneTicks() {
|
| 411 | return 20;
|
| 412 | }
|
| 413 |
|
| 414 | @Override
|
| 415 | public void handleEntityEvent(final @EntityEvent.Value byte id) {
|
| 416 | if (id == 9) {
|
| 417 | this.completeUsingItem();
|
| 418 | } else if (id == 23) {
|
| 419 | this.setReducedDebugInfo(false);
|
| 420 | } else if (id == 22) {
|
| 421 | this.setReducedDebugInfo(true);
|
| 422 | } else {
|
| 423 | super.handleEntityEvent(id);
|
| 424 | }
|
| 425 | }
|
| 426 |
|
| 427 | protected void closeContainer() {
|
| 428 | this.containerMenu = this.inventoryMenu;
|
| 429 | }
|
| 430 |
|
| 431 | protected void doCloseContainer() {
|
| 432 | }
|
| 433 |
|
| 434 | @Override
|
| 435 | public void rideTick() {
|
| 436 | if (!this.level().isClientSide() && this.wantsToStopRiding() && this.isPassenger()) {
|
| 437 | this.stopRiding();
|
| 438 | } else {
|
| 439 | super.rideTick();
|
| 440 | }
|
| 441 | }
|
| 442 |
|
| 443 | @Override
|
| 444 | public void aiStep() {
|
| 445 | if (this.jumpTriggerTime > 0) {
|
| 446 | this.jumpTriggerTime--;
|
| 447 | }
|
| 448 |
|
| 449 | this.tickRegeneration();
|
| 450 | this.inventory.tick();
|
| 451 | if (this.abilities.flying && !this.isPassenger()) {
|
| 452 | this.resetFallDistance();
|
| 453 | }
|
| 454 |
|
| 455 | super.aiStep();
|
| 456 | this.yHeadRot = this.getYRot();
|
| 457 | this.setSpeed((float)this.getAttributeValue(Attributes.MOVEMENT_SPEED));
|
| 458 | if (this.getHealth() > 0.0F && !this.isSpectator()) {
|
| 459 | AABB pickupArea;
|
| 460 | if (this.isPassenger() && !this.getVehicle().isRemoved()) {
|
| 461 | pickupArea = this.getBoundingBox().minmax(this.getVehicle().getBoundingBox()).inflate(1.0, 0.0, 1.0);
|
| 462 | } else {
|
| 463 | pickupArea = this.getBoundingBox().inflate(1.0, 0.5, 1.0);
|
| 464 | }
|
| 465 |
|
| 466 | List<Entity> entities = this.level().getEntities(this, pickupArea);
|
| 467 | List<Entity> orbs = Lists.newArrayList();
|
| 468 |
|
| 469 | for (Entity entity : entities) {
|
| 470 | if (entity.is(EntityTypes.EXPERIENCE_ORB)) {
|
| 471 | orbs.add(entity);
|
| 472 | } else if (!entity.isRemoved()) {
|
| 473 | this.touch(entity);
|
| 474 | }
|
| 475 | }
|
| 476 |
|
| 477 | if (!orbs.isEmpty()) {
|
| 478 | this.touch(Util.getRandom(orbs, this.random));
|
| 479 | }
|
| 480 | }
|
| 481 |
|
| 482 | this.handleShoulderEntities();
|
| 483 | }
|
| 484 |
|
| 485 | protected void tickRegeneration() {
|
| 486 | }
|
| 487 |
|
| 488 | public void handleShoulderEntities() {
|
| 489 | }
|
| 490 |
|
| 491 | protected void removeEntitiesOnShoulder() {
|
| 492 | }
|
| 493 |
|
| 494 | private void touch(final Entity entity) {
|
| 495 | entity.playerTouch(this);
|
| 496 | }
|
| 497 |
|
| 498 | public int getScore() {
|
| 499 | return this.entityData.get(DATA_SCORE_ID);
|
| 500 | }
|
| 501 |
|
| 502 | public void setScore(final int value) {
|
| 503 | this.entityData.set(DATA_SCORE_ID, value);
|
| 504 | }
|
| 505 |
|
| 506 | public void increaseScore(final int amount) {
|
| 507 | int score = this.getScore();
|
| 508 | this.entityData.set(DATA_SCORE_ID, score + amount);
|
| 509 | }
|
| 510 |
|
| 511 | public void startAutoSpinAttack(final int activationTicks, final float dmg, final ItemStack itemStackUsed) {
|
| 512 | this.autoSpinAttackTicks = activationTicks;
|
| 513 | this.autoSpinAttackDmg = dmg;
|
| 514 | this.autoSpinAttackItemStack = itemStackUsed;
|
| 515 | if (!this.level().isClientSide()) {
|
| 516 | this.removeEntitiesOnShoulder();
|
| 517 | this.setLivingEntityFlag(4, true);
|
| 518 | }
|
| 519 | }
|
| 520 |
|
| 521 | @Override
|
| 522 | public ItemStack getWeaponItem() {
|
| 523 | return this.isAutoSpinAttack() && this.autoSpinAttackItemStack != null ? this.autoSpinAttackItemStack : super.getWeaponItem();
|
| 524 | }
|
| 525 |
|
| 526 | @Override
|
| 527 | public void die(final DamageSource source) {
|
| 528 | super.die(source);
|
| 529 | this.reapplyPosition();
|
| 530 | if (!this.isSpectator() && this.level() instanceof ServerLevel level) {
|
| 531 | this.dropAllDeathLoot(level, source);
|
| 532 | }
|
| 533 |
|
| 534 | if (source != null) {
|
| 535 | this.setDeltaMovement(
|
| 536 | -Mth.cos((this.getHurtDir() + this.getYRot()) * (float) (Math.PI / 180.0)) * 0.1F,
|
| 537 | 0.1F,
|
| 538 | -Mth.sin((this.getHurtDir() + this.getYRot()) * (float) (Math.PI / 180.0)) * 0.1F
|
| 539 | );
|
| 540 | } else {
|
| 541 | this.setDeltaMovement(0.0, 0.1, 0.0);
|
| 542 | }
|
| 543 |
|
| 544 | this.awardStat(Stats.DEATHS);
|
| 545 | this.resetStat(Stats.CUSTOM.get(Stats.TIME_SINCE_DEATH));
|
| 546 | this.resetStat(Stats.CUSTOM.get(Stats.TIME_SINCE_REST));
|
| 547 | this.clearFire();
|
| 548 | this.setSharedFlagOnFire(false);
|
| 549 | this.setLastDeathLocation(Optional.of(GlobalPos.of(this.level().dimension(), this.blockPosition())));
|
| 550 | }
|
| 551 |
|
| 552 | @Override
|
| 553 | protected void dropEquipment(final ServerLevel level) {
|
| 554 | super.dropEquipment(level);
|
| 555 | if (!level.getGameRules().get(GameRules.KEEP_INVENTORY)) {
|
| 556 | this.destroyVanishingCursedItems();
|
| 557 | this.inventory.dropAll();
|
| 558 | }
|
| 559 | }
|
| 560 |
|
| 561 | protected void destroyVanishingCursedItems() {
|
| 562 | for (int i = 0; i < this.inventory.getContainerSize(); i++) {
|
| 563 | ItemStack itemStack = this.inventory.getItem(i);
|
| 564 | if (!itemStack.isEmpty() && EnchantmentHelper.has(itemStack, EnchantmentEffectComponents.PREVENT_EQUIPMENT_DROP)) {
|
| 565 | this.inventory.removeItemNoUpdate(i);
|
| 566 | }
|
| 567 | }
|
| 568 | }
|
| 569 |
|
| 570 | @Override
|
| 571 | protected SoundEvent getHurtSound(final DamageSource source) {
|
| 572 | return source.type().effects().sound();
|
| 573 | }
|
| 574 |
|
| 575 | @Override
|
| 576 | protected SoundEvent getDeathSound() {
|
| 577 | return SoundEvents.PLAYER_DEATH;
|
| 578 | }
|
| 579 |
|
| 580 | public void handleCreativeModeItemDrop(final ItemStack stack) {
|
| 581 | }
|
| 582 |
|
| 583 | public float getDestroySpeed(final BlockState state) {
|
| 584 | float speed = this.inventory.getSelectedItem().getDestroySpeed(state);
|
| 585 | if (speed > 1.0F) {
|
| 586 | speed += (float)this.getAttributeValue(Attributes.MINING_EFFICIENCY);
|
| 587 | }
|
| 588 |
|
| 589 | if (MobEffectUtil.hasDigSpeed(this)) {
|
| 590 | speed *= 1.0F + (MobEffectUtil.getDigSpeedAmplification(this) + 1) * 0.2F;
|
| 591 | }
|
| 592 |
|
| 593 | if (this.hasEffect(MobEffects.MINING_FATIGUE)) {
|
| 594 | int amplifier = this.getEffect(MobEffects.MINING_FATIGUE).getAmplifier();
|
| 595 | float scale = (float)Math.pow(0.3, amplifier + 1);
|
| 596 | speed *= scale;
|
| 597 | }
|
| 598 |
|
| 599 | speed *= (float)this.getAttributeValue(Attributes.BLOCK_BREAK_SPEED);
|
| 600 | if (this.isEyeInFluid(FluidTags.WATER)) {
|
| 601 | speed *= (float)this.getAttribute(Attributes.SUBMERGED_MINING_SPEED).getValue();
|
| 602 | }
|
| 603 |
|
| 604 | if (!this.onGround()) {
|
| 605 | speed /= 5.0F;
|
| 606 | }
|
| 607 |
|
| 608 | return speed;
|
| 609 | }
|
| 610 |
|
| 611 | public boolean hasCorrectToolForDrops(final BlockState state) {
|
| 612 | return !state.requiresCorrectToolForDrops() || this.inventory.getSelectedItem().isCorrectToolForDrops(state);
|
| 613 | }
|
| 614 |
|
| 615 | @Override
|
| 616 | protected void readAdditionalSaveData(final ValueInput input) {
|
| 617 | super.readAdditionalSaveData(input);
|
| 618 | this.setUUID(this.gameProfile.id());
|
| 619 | this.inventory.load(input.listOrEmpty("Inventory", ItemStackWithSlot.CODEC));
|
| 620 | this.inventory.setSelectedSlot(input.getIntOr("SelectedItemSlot", 0));
|
| 621 | this.sleepCounter = input.getShortOr("SleepTimer", (short)0);
|
| 622 | this.experienceProgress = input.getFloatOr("XpP", 0.0F);
|
| 623 | this.experienceLevel = input.getIntOr("XpLevel", 0);
|
| 624 | this.totalExperience = input.getIntOr("XpTotal", 0);
|
| 625 | this.enchantmentSeed = input.getIntOr("XpSeed", 0);
|
| 626 | if (this.enchantmentSeed == 0) {
|
| 627 | this.enchantmentSeed = this.random.nextInt();
|
| 628 | }
|
| 629 |
|
| 630 | this.setScore(input.getIntOr("Score", 0));
|
| 631 | this.foodData.readAdditionalSaveData(input);
|
| 632 | input.read("abilities", Abilities.Packed.CODEC).ifPresent(this.abilities::apply);
|
| 633 | this.getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(this.abilities.getWalkingSpeed());
|
| 634 | this.enderChestInventory.fromSlots(input.listOrEmpty("EnderItems", ItemStackWithSlot.CODEC));
|
| 635 | this.setLastDeathLocation(input.read("LastDeathLocation", GlobalPos.CODEC));
|
| 636 | }
|
| 637 |
|
| 638 | @Override
|
| 639 | protected void addAdditionalSaveData(final ValueOutput output) {
|
| 640 | super.addAdditionalSaveData(output);
|
| 641 | NbtUtils.addCurrentDataVersion(output);
|
| 642 | this.inventory.save(output.list("Inventory", ItemStackWithSlot.CODEC));
|
| 643 | output.putInt("SelectedItemSlot", this.inventory.getSelectedSlot());
|
| 644 | output.putShort("SleepTimer", (short)this.sleepCounter);
|
| 645 | output.putFloat("XpP", this.experienceProgress);
|
| 646 | output.putInt("XpLevel", this.experienceLevel);
|
| 647 | output.putInt("XpTotal", this.totalExperience);
|
| 648 | output.putInt("XpSeed", this.enchantmentSeed);
|
| 649 | output.putInt("Score", this.getScore());
|
| 650 | this.foodData.addAdditionalSaveData(output);
|
| 651 | output.store("abilities", Abilities.Packed.CODEC, this.abilities.pack());
|
| 652 | this.enderChestInventory.storeAsSlots(output.list("EnderItems", ItemStackWithSlot.CODEC));
|
| 653 | this.lastDeathLocation.ifPresent(pos -> output.store("LastDeathLocation", GlobalPos.CODEC, pos));
|
| 654 | }
|
| 655 |
|
| 656 | @Override
|
| 657 | public boolean isInvulnerableTo(final ServerLevel level, final DamageSource source) {
|
| 658 | if (super.isInvulnerableTo(level, source)) {
|
| 659 | return true;
|
| 660 | } else if (source.is(DamageTypeTags.IS_DROWNING)) {
|
| 661 | return !level.getGameRules().get(GameRules.DROWNING_DAMAGE);
|
| 662 | } else if (source.is(DamageTypeTags.IS_FALL)) {
|
| 663 | return !level.getGameRules().get(GameRules.FALL_DAMAGE);
|
| 664 | } else if (source.is(DamageTypeTags.IS_FIRE)) {
|
| 665 | return !level.getGameRules().get(GameRules.FIRE_DAMAGE);
|
| 666 | } else {
|
| 667 | return source.is(DamageTypeTags.IS_FREEZING) ? !level.getGameRules().get(GameRules.FREEZE_DAMAGE) : false;
|
| 668 | }
|
| 669 | }
|
| 670 |
|
| 671 | @Override
|
| 672 | public boolean hurtServer(final ServerLevel level, final DamageSource source, float damage) {
|
| 673 | if (this.isInvulnerableTo(level, source)) {
|
| 674 | return false;
|
| 675 | }
|
| 676 |
|
| 677 | if (this.abilities.invulnerable && !source.is(DamageTypeTags.BYPASSES_INVULNERABILITY)) {
|
| 678 | return false;
|
| 679 | }
|
| 680 |
|
| 681 | this.noActionTime = 0;
|
| 682 | if (this.isDeadOrDying()) {
|
| 683 | return false;
|
| 684 | }
|
| 685 |
|
| 686 | this.removeEntitiesOnShoulder();
|
| 687 | if (source.scalesWithDifficulty()) {
|
| 688 | if (level.getDifficulty() == Difficulty.PEACEFUL) {
|
| 689 | damage = 0.0F;
|
| 690 | }
|
| 691 |
|
| 692 | if (level.getDifficulty() == Difficulty.EASY) {
|
| 693 | damage = Math.min(damage / 2.0F + 1.0F, damage);
|
| 694 | }
|
| 695 |
|
| 696 | if (level.getDifficulty() == Difficulty.HARD) {
|
| 697 | damage = damage * 3.0F / 2.0F;
|
| 698 | }
|
| 699 | }
|
| 700 |
|
| 701 | return damage == 0.0F ? false : super.hurtServer(level, source, damage);
|
| 702 | }
|
| 703 |
|
| 704 | @Override
|
| 705 | protected void blockUsingItem(final ServerLevel level, final LivingEntity attacker, final DamageSource source, final float damage, final boolean fullyBlocked) {
|
| 706 | super.blockUsingItem(level, attacker, source, damage, fullyBlocked);
|
| 707 | ItemStack itemBlockingWith = this.getItemBlockingWith();
|
| 708 | BlocksAttacks blocksAttacks = itemBlockingWith != null ? itemBlockingWith.get(DataComponents.BLOCKS_ATTACKS) : null;
|
| 709 | float secondsToDisableBlocking = attacker.getSecondsToDisableBlocking();
|
| 710 | if (secondsToDisableBlocking > 0.0F && blocksAttacks != null) {
|
| 711 | blocksAttacks.disable(level, this, secondsToDisableBlocking, itemBlockingWith);
|
| 712 | }
|
| 713 | }
|
| 714 |
|
| 715 | @Override
|
| 716 | public boolean canBeSeenAsEnemy() {
|
| 717 | return !this.getAbilities().invulnerable && super.canBeSeenAsEnemy();
|
| 718 | }
|
| 719 |
|
| 720 | public boolean canHarmPlayer(final Player target) {
|
| 721 | return this.doTeamsAllowDamage(target);
|
| 722 | }
|
| 723 |
|
| 724 | @Override
|
| 725 | protected void hurtArmor(final DamageSource damageSource, final float damage) {
|
| 726 | this.doHurtEquipment(damageSource, damage, EquipmentSlot.FEET, EquipmentSlot.LEGS, EquipmentSlot.CHEST, EquipmentSlot.HEAD);
|
| 727 | }
|
| 728 |
|
| 729 | @Override
|
| 730 | protected void hurtHelmet(final DamageSource damageSource, final float damage) {
|
| 731 | this.doHurtEquipment(damageSource, damage, EquipmentSlot.HEAD);
|
| 732 | }
|
| 733 |
|
| 734 | @Override
|
| 735 | protected void actuallyHurt(final ServerLevel level, final DamageSource source, float dmg) {
|
| 736 | if (!this.isInvulnerableTo(level, source)) {
|
| 737 | dmg = this.getDamageAfterArmorAbsorb(source, dmg);
|
| 738 | dmg = this.getDamageAfterMagicAbsorb(source, dmg);
|
| 739 | float originalDamage = dmg;
|
| 740 | dmg = Math.max(dmg - this.getAbsorptionAmount(), 0.0F);
|
| 741 | this.setAbsorptionAmount(this.getAbsorptionAmount() - (originalDamage - dmg));
|
| 742 | float absorbedDamage = originalDamage - dmg;
|
| 743 | if (absorbedDamage > 0.0F && absorbedDamage < 3.4028235E37F) {
|
| 744 | this.awardStat(Stats.DAMAGE_ABSORBED, Math.round(absorbedDamage * 10.0F));
|
| 745 | }
|
| 746 |
|
| 747 | if (dmg != 0.0F) {
|
| 748 | this.causeFoodExhaustion(source.getFoodExhaustion());
|
| 749 | this.getCombatTracker().recordDamage(source, dmg);
|
| 750 | this.setHealth(this.getHealth() - dmg);
|
| 751 | if (dmg < 3.4028235E37F) {
|
| 752 | this.awardStat(Stats.DAMAGE_TAKEN, Math.round(dmg * 10.0F));
|
| 753 | }
|
| 754 |
|
| 755 | this.gameEvent(GameEvent.ENTITY_DAMAGE);
|
| 756 | }
|
| 757 | }
|
| 758 | }
|
| 759 |
|
| 760 | public boolean isTextFilteringEnabled() {
|
| 761 | return false;
|
| 762 | }
|
| 763 |
|
| 764 | public void openTextEdit(final SignBlockEntity sign, final SignTextSlot slot) {
|
| 765 | }
|
| 766 |
|
| 767 | public void openMinecartCommandBlock(final MinecartCommandBlock commandBlock) {
|
| 768 | }
|
| 769 |
|
| 770 | public void openCommandBlock(final CommandBlockEntity commandBlock) {
|
| 771 | }
|
| 772 |
|
| 773 | public void openStructureBlock(final StructureBlockEntity structureBlock) {
|
| 774 | }
|
| 775 |
|
| 776 | public void openTestBlock(final TestBlockEntity testBlock) {
|
| 777 | }
|
| 778 |
|
| 779 | public void openTestInstanceBlock(final TestInstanceBlockEntity testInstanceBlock) {
|
| 780 | }
|
| 781 |
|
| 782 | public void openJigsawBlock(final JigsawBlockEntity jigsawBlock) {
|
| 783 | }
|
| 784 |
|
| 785 | public void openHorseInventory(final AbstractHorse horse, final Container container) {
|
| 786 | }
|
| 787 |
|
| 788 | public void openNautilusInventory(final AbstractNautilus nautilus, final Container container) {
|
| 789 | }
|
| 790 |
|
| 791 | public OptionalInt openMenu(final @Nullable MenuProvider provider) {
|
| 792 | return OptionalInt.empty();
|
| 793 | }
|
| 794 |
|
| 795 | public void openDialog(final Holder<Dialog> dialog) {
|
| 796 | }
|
| 797 |
|
| 798 | public void sendMerchantOffers(
|
| 799 | final int containerId, final MerchantOffers offers, final int merchantLevel, final int merchantXp, final boolean showProgressBar, final boolean canRestock
|
| 800 | ) {
|
| 801 | }
|
| 802 |
|
| 803 | public void openItemGui(final ItemStack itemStack, final InteractionHand hand) {
|
| 804 | }
|
| 805 |
|
| 806 | public InteractionResult interactOn(final Entity entity, final InteractionHand hand, final Vec3 location) {
|
| 807 | if (this.isSpectator()) {
|
| 808 | if (entity instanceof MenuProvider menuProvider) {
|
| 809 | this.openMenu(menuProvider);
|
| 810 | }
|
| 811 |
|
| 812 | return InteractionResult.PASS;
|
| 813 | } else {
|
| 814 | ItemStack itemStack = this.getItemInHand(hand);
|
| 815 | ItemStack itemStackClone = itemStack.copy();
|
| 816 | InteractionResult interact = entity.interact(this, hand, location);
|
| 817 | if (interact.consumesAction()) {
|
| 818 | if (this.hasInfiniteMaterials() && itemStack == this.getItemInHand(hand) && itemStack.getCount() < itemStackClone.getCount()) {
|
| 819 | itemStack.setCount(itemStackClone.getCount());
|
| 820 | }
|
| 821 |
|
| 822 | return interact;
|
| 823 | } else {
|
| 824 | if (!itemStack.isEmpty() && entity instanceof LivingEntity livingEntity) {
|
| 825 | if (this.hasInfiniteMaterials()) {
|
| 826 | itemStack = itemStackClone;
|
| 827 | }
|
| 828 |
|
| 829 | InteractionResult interactionResult = itemStack.interactLivingEntity(this, livingEntity, hand);
|
| 830 | if (interactionResult.consumesAction()) {
|
| 831 | this.level().gameEvent(GameEvent.ENTITY_INTERACT, entity.position(), GameEvent.Context.of(this));
|
| 832 | if (itemStack.isEmpty() && !this.hasInfiniteMaterials()) {
|
| 833 | this.setItemInHand(hand, ItemStack.EMPTY);
|
| 834 | }
|
| 835 |
|
| 836 | return interactionResult;
|
| 837 | }
|
| 838 | }
|
| 839 |
|
| 840 | return InteractionResult.PASS;
|
| 841 | }
|
| 842 | }
|
| 843 | }
|
| 844 |
|
| 845 | @Override
|
| 846 | public void removeVehicle() {
|
| 847 | super.removeVehicle();
|
| 848 | this.boardingCooldown = 0;
|
| 849 | }
|
| 850 |
|
| 851 | @Override
|
| 852 | protected boolean isImmobile() {
|
| 853 | return super.isImmobile() || this.isSleeping();
|
| 854 | }
|
| 855 |
|
| 856 | @Override
|
| 857 | public boolean isAffectedByFluids() {
|
| 858 | return !this.abilities.flying;
|
| 859 | }
|
| 860 |
|
| 861 | @Override
|
| 862 | protected Vec3 maybeBackOffFromEdge(final Vec3 delta, final MoverType moverType) {
|
| 863 | float maxDownStep = this.maxUpStep();
|
| 864 | if (!this.abilities.flying
|
| 865 | && !(delta.y > 0.0)
|
| 866 | && (moverType == MoverType.SELF || moverType == MoverType.PLAYER)
|
| 867 | && this.isStayingOnGroundSurface()
|
| 868 | && this.isAboveGround(maxDownStep)) {
|
| 869 | double deltaX = delta.x;
|
| 870 | double deltaZ = delta.z;
|
| 871 | double step = 0.05;
|
| 872 | double stepX = Math.signum(deltaX) * 0.05;
|
| 873 | double stepZ = Math.signum(deltaZ) * 0.05;
|
| 874 |
|
| 875 | while (deltaX != 0.0 && this.canFallAtLeast(deltaX, 0.0, maxDownStep)) {
|
| 876 | if (Math.abs(deltaX) <= 0.05) {
|
| 877 | deltaX = 0.0;
|
| 878 | break;
|
| 879 | }
|
| 880 |
|
| 881 | deltaX -= stepX;
|
| 882 | }
|
| 883 |
|
| 884 | while (deltaZ != 0.0 && this.canFallAtLeast(0.0, deltaZ, maxDownStep)) {
|
| 885 | if (Math.abs(deltaZ) <= 0.05) {
|
| 886 | deltaZ = 0.0;
|
| 887 | break;
|
| 888 | }
|
| 889 |
|
| 890 | deltaZ -= stepZ;
|
| 891 | }
|
| 892 |
|
| 893 | while (deltaX != 0.0 && deltaZ != 0.0 && this.canFallAtLeast(deltaX, deltaZ, maxDownStep)) {
|
| 894 | if (Math.abs(deltaX) <= 0.05) {
|
| 895 | deltaX = 0.0;
|
| 896 | } else {
|
| 897 | deltaX -= stepX;
|
| 898 | }
|
| 899 |
|
| 900 | if (Math.abs(deltaZ) <= 0.05) {
|
| 901 | deltaZ = 0.0;
|
| 902 | } else {
|
| 903 | deltaZ -= stepZ;
|
| 904 | }
|
| 905 | }
|
| 906 |
|
| 907 | return new Vec3(deltaX, delta.y, deltaZ);
|
| 908 | } else {
|
| 909 | return delta;
|
| 910 | }
|
| 911 | }
|
| 912 |
|
| 913 | private boolean isAboveGround(final float maxDownStep) {
|
| 914 | return this.onGround() || this.fallDistance < maxDownStep && !this.canFallAtLeast(0.0, 0.0, maxDownStep - this.fallDistance);
|
| 915 | }
|
| 916 |
|
| 917 | private boolean canFallAtLeast(final double deltaX, final double deltaZ, final double minHeight) {
|
| 918 | AABB boundingBox = this.getBoundingBox();
|
| 919 | return this.level()
|
| 920 | .noCollision(
|
| 921 | this,
|
| 922 | new AABB(
|
| 923 | boundingBox.minX + 1.0E-7 + deltaX,
|
| 924 | boundingBox.minY - minHeight - 1.0E-7,
|
| 925 | boundingBox.minZ + 1.0E-7 + deltaZ,
|
| 926 | boundingBox.maxX - 1.0E-7 + deltaX,
|
| 927 | boundingBox.minY,
|
| 928 | boundingBox.maxZ - 1.0E-7 + deltaZ
|
| 929 | )
|
| 930 | );
|
| 931 | }
|
| 932 |
|
| 933 | public void attack(final Entity entity) {
|
| 934 | if (!this.cannotAttack(entity)) {
|
| 935 | float baseDamage = this.isAutoSpinAttack() ? this.autoSpinAttackDmg : (float)this.getAttributeValue(Attributes.ATTACK_DAMAGE);
|
| 936 | ItemStack attackingItemStack = this.getWeaponItem();
|
| 937 | DamageSource damageSource = this.createAttackSource(attackingItemStack);
|
| 938 | float attackStrengthScale = this.getAttackStrengthScale(0.5F);
|
| 939 | float magicBoost = attackStrengthScale * (this.getEnchantedDamage(entity, baseDamage, damageSource) - baseDamage);
|
| 940 | baseDamage *= this.baseDamageScaleFactor();
|
| 941 | this.onAttack();
|
| 942 | if (!this.deflectProjectile(entity)) {
|
| 943 | if (baseDamage > 0.0F || magicBoost > 0.0F) {
|
| 944 | boolean fullStrengthAttack = attackStrengthScale > 0.9F;
|
| 945 | boolean knockbackAttack;
|
| 946 | if (this.isSprinting() && fullStrengthAttack) {
|
| 947 | this.playServerSideSound(SoundEvents.PLAYER_ATTACK_KNOCKBACK);
|
| 948 | knockbackAttack = true;
|
| 949 | } else {
|
| 950 | knockbackAttack = false;
|
| 951 | }
|
| 952 |
|
| 953 | baseDamage += attackingItemStack.getItem().getAttackDamageBonus(entity, baseDamage, damageSource);
|
| 954 | boolean criticalAttack = fullStrengthAttack && this.canCriticalAttack(entity);
|
| 955 | if (criticalAttack) {
|
| 956 | baseDamage *= 1.5F;
|
| 957 | }
|
| 958 |
|
| 959 | float totalDamage = baseDamage + magicBoost;
|
| 960 | boolean sweepAttack = this.isSweepAttack(fullStrengthAttack, criticalAttack, knockbackAttack);
|
| 961 | float oldLivingEntityHealth = 0.0F;
|
| 962 | if (entity instanceof LivingEntity livingTarget) {
|
| 963 | oldLivingEntityHealth = livingTarget.getHealth();
|
| 964 | }
|
| 965 |
|
| 966 | Vec3 oldMovement = entity.getDeltaMovement();
|
| 967 | boolean wasHurt = entity.hurtOrSimulate(damageSource, totalDamage);
|
| 968 | if (wasHurt) {
|
| 969 | this.causeExtraKnockback(entity, this.getKnockback(entity, damageSource) + (knockbackAttack ? 0.5F : 0.0F), oldMovement, damageSource, totalDamage, true);
|
| 970 | if (sweepAttack) {
|
| 971 | this.doSweepAttack(entity, baseDamage, damageSource, attackStrengthScale);
|
| 972 | }
|
| 973 |
|
| 974 | this.attackVisualEffects(entity, criticalAttack, sweepAttack, fullStrengthAttack, false, magicBoost);
|
| 975 | this.setLastHurtMob(entity);
|
| 976 | this.itemAttackInteraction(entity, attackingItemStack, damageSource, true);
|
| 977 | this.damageStatsAndHearts(entity, oldLivingEntityHealth);
|
| 978 | this.causeFoodExhaustion(0.1F);
|
| 979 | } else {
|
| 980 | this.playServerSideSound(SoundEvents.PLAYER_ATTACK_NODAMAGE);
|
| 981 | }
|
| 982 | }
|
| 983 |
|
| 984 | this.postPiercingAttack();
|
| 985 | }
|
| 986 | }
|
| 987 | }
|
| 988 |
|
| 989 | private void playServerSideSound(final SoundEvent sound) {
|
| 990 | this.level().playSound(null, this.getX(), this.getY(), this.getZ(), sound, this.getSoundSource(), 1.0F, 1.0F);
|
| 991 | }
|
| 992 |
|
| 993 | private DamageSource createAttackSource(final ItemStack attackingItemStack) {
|
| 994 | return attackingItemStack.getDamageSource(this);
|
| 995 | }
|
| 996 |
|
| 997 | private boolean cannotAttack(final Entity entity) {
|
| 998 | return !entity.isAttackable() ? true : entity.skipAttackInteraction(this);
|
| 999 | }
|
| 1000 |
|
| 1001 | private boolean deflectProjectile(final Entity entity) {
|
| 1002 | if (entity.is(EntityTypeTags.REDIRECTABLE_PROJECTILE)
|
| 1003 | && entity instanceof Projectile projectile
|
| 1004 | && projectile.deflect(ProjectileDeflection.AIM_DEFLECT, this, EntityReference.of(this), true, 1.0)) {
|
| 1005 | this.level().playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_NODAMAGE, this.getSoundSource());
|
| 1006 | return true;
|
| 1007 | } else {
|
| 1008 | return false;
|
| 1009 | }
|
| 1010 | }
|
| 1011 |
|
| 1012 | private boolean canCriticalAttack(final Entity entity) {
|
| 1013 | return this.fallDistance > 0.0
|
| 1014 | && !this.onGround()
|
| 1015 | && !this.onClimbable()
|
| 1016 | && !this.isInWater()
|
| 1017 | && !this.isMobilityRestricted()
|
| 1018 | && !this.isPassenger()
|
| 1019 | && entity instanceof LivingEntity
|
| 1020 | && !this.isSprinting();
|
| 1021 | }
|
| 1022 |
|
| 1023 | private boolean isSweepAttack(final boolean fullStrengthAttack, final boolean criticalAttack, final boolean knockbackAttack) {
|
| 1024 | if (fullStrengthAttack && !criticalAttack && !knockbackAttack && this.onGround()) {
|
| 1025 | double approximateSpeedSq = this.getKnownMovement().horizontalDistanceSqr();
|
| 1026 | double maxSpeedForSweepAttack = this.getSpeed() * 2.5;
|
| 1027 | if (approximateSpeedSq < Mth.square(maxSpeedForSweepAttack)) {
|
| 1028 | return this.getItemInHand(InteractionHand.MAIN_HAND).is(ItemTags.SWORDS);
|
| 1029 | }
|
| 1030 | }
|
| 1031 |
|
| 1032 | return false;
|
| 1033 | }
|
| 1034 |
|
| 1035 | private void attackVisualEffects(
|
| 1036 | final Entity entity,
|
| 1037 | final boolean criticalAttack,
|
| 1038 | final boolean sweepAttack,
|
| 1039 | final boolean fullStrengthAttack,
|
| 1040 | final boolean stabAttack,
|
| 1041 | final float magicBoost
|
| 1042 | ) {
|
| 1043 | if (criticalAttack) {
|
| 1044 | this.playServerSideSound(SoundEvents.PLAYER_ATTACK_CRIT);
|
| 1045 | this.crit(entity);
|
| 1046 | }
|
| 1047 |
|
| 1048 | if (!criticalAttack && !sweepAttack && !stabAttack) {
|
| 1049 | this.playServerSideSound(fullStrengthAttack ? SoundEvents.PLAYER_ATTACK_STRONG : SoundEvents.PLAYER_ATTACK_WEAK);
|
| 1050 | }
|
| 1051 |
|
| 1052 | if (magicBoost > 0.0F) {
|
| 1053 | this.magicCrit(entity);
|
| 1054 | }
|
| 1055 | }
|
| 1056 |
|
| 1057 | private void damageStatsAndHearts(final Entity entity, final float oldLivingEntityHealth) {
|
| 1058 | if (entity instanceof LivingEntity livingEntity) {
|
| 1059 | float actualDamage = oldLivingEntityHealth - livingEntity.getHealth();
|
| 1060 | this.awardStat(Stats.DAMAGE_DEALT, Math.round(actualDamage * 10.0F));
|
| 1061 | if (this.level() instanceof ServerLevel && actualDamage > 2.0F) {
|
| 1062 | int count = (int)(actualDamage * 0.5);
|
| 1063 | ((ServerLevel)this.level()).sendParticles(ParticleTypes.DAMAGE_INDICATOR, entity.getX(), entity.getY(0.5), entity.getZ(), count, 0.1, 0.0, 0.1, 0.2);
|
| 1064 | }
|
| 1065 | }
|
| 1066 | }
|
| 1067 |
|
| 1068 | private void itemAttackInteraction(final Entity entity, final ItemStack attackingItemStack, final DamageSource damageSource, final boolean applyToTarget) {
|
| 1069 | Entity hurtTarget = entity;
|
| 1070 | if (entity instanceof EnderDragonPart enderDragonPart) {
|
| 1071 | hurtTarget = enderDragonPart.parentMob;
|
| 1072 | }
|
| 1073 |
|
| 1074 | boolean itemHurtEnemy = false;
|
| 1075 | if (this.level() instanceof ServerLevel serverLevel) {
|
| 1076 | if (hurtTarget instanceof LivingEntity livingTarget) {
|
| 1077 | itemHurtEnemy = attackingItemStack.hurtEnemy(livingTarget, this);
|
| 1078 | }
|
| 1079 |
|
| 1080 | if (applyToTarget) {
|
| 1081 | EnchantmentHelper.doPostAttackEffectsWithItemSource(serverLevel, entity, damageSource, attackingItemStack);
|
| 1082 | }
|
| 1083 | }
|
| 1084 |
|
| 1085 | if (!this.level().isClientSide() && !attackingItemStack.isEmpty() && hurtTarget instanceof LivingEntity) {
|
| 1086 | if (itemHurtEnemy) {
|
| 1087 | attackingItemStack.postHurtEnemy((LivingEntity)hurtTarget, this);
|
| 1088 | }
|
| 1089 |
|
| 1090 | if (attackingItemStack.isEmpty()) {
|
| 1091 | if (attackingItemStack == this.getMainHandItem()) {
|
| 1092 | this.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY);
|
| 1093 | } else {
|
| 1094 | this.setItemInHand(InteractionHand.OFF_HAND, ItemStack.EMPTY);
|
| 1095 | }
|
| 1096 | }
|
| 1097 | }
|
| 1098 | }
|
| 1099 |
|
| 1100 | @Override
|
| 1101 | public void causeExtraKnockback(
|
| 1102 | final Entity entity, final float knockbackAmount, final Vec3 oldMovement, final DamageSource damageSource, final float damage, final boolean comesFromEffect
|
| 1103 | ) {
|
| 1104 | if (knockbackAmount > 0.0F) {
|
| 1105 | if (entity instanceof LivingEntity livingTarget) {
|
| 1106 | livingTarget.knockback(
|
| 1107 | knockbackAmount,
|
| 1108 | Mth.sin(this.getYRot() * (float) (Math.PI / 180.0)),
|
| 1109 | -Mth.cos(this.getYRot() * (float) (Math.PI / 180.0)),
|
| 1110 | damageSource,
|
| 1111 | damage,
|
| 1112 | comesFromEffect
|
| 1113 | );
|
| 1114 | } else {
|
| 1115 | entity.push(
|
| 1116 | -Mth.sin(this.getYRot() * (float) (Math.PI / 180.0)) * knockbackAmount, 0.1, Mth.cos(this.getYRot() * (float) (Math.PI / 180.0)) * knockbackAmount
|
| 1117 | );
|
| 1118 | }
|
| 1119 |
|
| 1120 | this.setDeltaMovement(this.getDeltaMovement().multiply(0.6, 1.0, 0.6));
|
| 1121 | this.setSprinting(false);
|
| 1122 | }
|
| 1123 |
|
| 1124 | if (entity instanceof ServerPlayer serverPlayer && entity.syncVelocity) {
|
| 1125 | serverPlayer.connection.send(new ClientboundSetEntityMotionPacket(entity));
|
| 1126 | entity.syncVelocity = false;
|
| 1127 | entity.setDeltaMovement(oldMovement);
|
| 1128 | }
|
| 1129 | }
|
| 1130 |
|
| 1131 | @Override
|
| 1132 | public float getVoicePitch() {
|
| 1133 | return 1.0F;
|
| 1134 | }
|
| 1135 |
|
| 1136 | private void doSweepAttack(final Entity entity, final float baseDamage, final DamageSource damageSource, final float attackStrengthScale) {
|
| 1137 | this.playServerSideSound(SoundEvents.PLAYER_ATTACK_SWEEP);
|
| 1138 | if (this.level() instanceof ServerLevel serverLevel) {
|
| 1139 | float var12 = 1.0F + (float)this.getAttributeValue(Attributes.SWEEPING_DAMAGE_RATIO) * baseDamage;
|
| 1140 |
|
| 1141 | for (LivingEntity nearby : this.level().getEntitiesOfClass(LivingEntity.class, entity.getBoundingBox().inflate(1.0, 0.25, 1.0))) {
|
| 1142 | if (nearby != this
|
| 1143 | && nearby != entity
|
| 1144 | && !this.isAlliedTo(nearby)
|
| 1145 | && !(nearby instanceof ArmorStand armorStand && armorStand.isMarker())
|
| 1146 | && this.distanceToSqr(nearby) < 9.0) {
|
| 1147 | float enchantedDamage = this.getEnchantedDamage(nearby, var12, damageSource) * attackStrengthScale;
|
| 1148 | if (nearby.hurtServer(serverLevel, damageSource, enchantedDamage)) {
|
| 1149 | nearby.knockback(
|
| 1150 | 0.4F, Mth.sin(this.getYRot() * (float) (Math.PI / 180.0)), -Mth.cos(this.getYRot() * (float) (Math.PI / 180.0)), damageSource, enchantedDamage
|
| 1151 | );
|
| 1152 | EnchantmentHelper.doPostAttackEffects(serverLevel, nearby, damageSource);
|
| 1153 | }
|
| 1154 | }
|
| 1155 | }
|
| 1156 |
|
| 1157 | double dx = -Mth.sin(this.getYRot() * (float) (Math.PI / 180.0));
|
| 1158 | double dz = Mth.cos(this.getYRot() * (float) (Math.PI / 180.0));
|
| 1159 | serverLevel.sendParticles(ParticleTypes.SWEEP_ATTACK, this.getX() + dx, this.getY(0.5), this.getZ() + dz, 0, dx, 0.0, dz, 0.0);
|
| 1160 | }
|
| 1161 | }
|
| 1162 |
|
| 1163 | protected float getEnchantedDamage(final Entity entity, final float dmg, final DamageSource damageSource) {
|
| 1164 | return dmg;
|
| 1165 | }
|
| 1166 |
|
| 1167 | @Override
|
| 1168 | protected void doAutoAttackOnTouch(final LivingEntity entity) {
|
| 1169 | this.attack(entity);
|
| 1170 | }
|
| 1171 |
|
| 1172 | public void crit(final Entity entity) {
|
| 1173 | }
|
| 1174 |
|
| 1175 | private float baseDamageScaleFactor() {
|
| 1176 | float attackStrengthScale = this.getAttackStrengthScale(0.5F);
|
| 1177 | return 0.2F + attackStrengthScale * attackStrengthScale * 0.8F;
|
| 1178 | }
|
| 1179 |
|
| 1180 | @Override
|
| 1181 | public boolean stabAttack(
|
| 1182 | final EquipmentSlot slot, final Entity target, float baseDamage, final boolean dealsDamage, final boolean dealsKnockback, final boolean dismounts
|
| 1183 | ) {
|
| 1184 | if (this.cannotAttack(target)) {
|
| 1185 | return false;
|
| 1186 | }
|
| 1187 |
|
| 1188 | ItemStack weaponItem = this.getItemBySlot(slot);
|
| 1189 | DamageSource damageSource = this.createAttackSource(weaponItem);
|
| 1190 | float magicBoost = this.getEnchantedDamage(target, baseDamage, damageSource) - baseDamage;
|
| 1191 | if (!this.isUsingItem() || this.getUsedItemHand().asEquipmentSlot() != slot) {
|
| 1192 | magicBoost *= this.getAttackStrengthScale(0.5F);
|
| 1193 | baseDamage *= this.baseDamageScaleFactor();
|
| 1194 | }
|
| 1195 |
|
| 1196 | if (dealsKnockback && this.deflectProjectile(target)) {
|
| 1197 | return true;
|
| 1198 | }
|
| 1199 |
|
| 1200 | float totalDamage = dealsDamage ? baseDamage + magicBoost : 0.0F;
|
| 1201 | float oldLivingEntityHealth = 0.0F;
|
| 1202 | if (target instanceof LivingEntity livingTarget) {
|
| 1203 | oldLivingEntityHealth = livingTarget.getHealth();
|
| 1204 | }
|
| 1205 |
|
| 1206 | Vec3 oldMovement = target.getDeltaMovement();
|
| 1207 | boolean wasHurt = dealsDamage && target.hurtOrSimulate(damageSource, totalDamage);
|
| 1208 | if (dealsKnockback) {
|
| 1209 | this.causeExtraKnockback(target, 0.4F, oldMovement, damageSource, totalDamage, false);
|
| 1210 | this.causeExtraKnockback(target, this.getKnockback(target, damageSource), oldMovement, damageSource, totalDamage, true);
|
| 1211 | }
|
| 1212 |
|
| 1213 | boolean dismounted = false;
|
| 1214 | if (dismounts && target.isPassenger() && !target.is(EntityTypeTags.CANNOT_BE_DISMOUNTED_BY_ITEM_USAGE)) {
|
| 1215 | dismounted = true;
|
| 1216 | target.stopRiding();
|
| 1217 | }
|
| 1218 |
|
| 1219 | if (!wasHurt && !dealsKnockback && !dismounted) {
|
| 1220 | return false;
|
| 1221 | }
|
| 1222 |
|
| 1223 | this.attackVisualEffects(target, false, false, dealsDamage, true, magicBoost);
|
| 1224 | this.setLastHurtMob(target);
|
| 1225 | this.itemAttackInteraction(target, weaponItem, damageSource, wasHurt);
|
| 1226 | this.damageStatsAndHearts(target, oldLivingEntityHealth);
|
| 1227 | this.causeFoodExhaustion(0.1F);
|
| 1228 | return true;
|
| 1229 | }
|
| 1230 |
|
| 1231 | public void magicCrit(final Entity entity) {
|
| 1232 | }
|
| 1233 |
|
| 1234 | @Override
|
| 1235 | public void remove(final Entity.RemovalReason reason) {
|
| 1236 | super.remove(reason);
|
| 1237 | this.inventoryMenu.removed(this);
|
| 1238 | if (this.hasContainerOpen()) {
|
| 1239 | this.doCloseContainer();
|
| 1240 | }
|
| 1241 | }
|
| 1242 |
|
| 1243 | @Override
|
| 1244 | public boolean isClientAuthoritative() {
|
| 1245 | return true;
|
| 1246 | }
|
| 1247 |
|
| 1248 | @Override
|
| 1249 | protected boolean isLocalClientAuthoritative() {
|
| 1250 | return this.isLocalPlayer();
|
| 1251 | }
|
| 1252 |
|
| 1253 | public boolean isLocalPlayer() {
|
| 1254 | return false;
|
| 1255 | }
|
| 1256 |
|
| 1257 | @Override
|
| 1258 | public MoveSimulationType getMoveSimulationType() {
|
| 1259 | return MoveSimulationType.AUTHORITATIVE_SIDE_AND_SERVER;
|
| 1260 | }
|
| 1261 |
|
| 1262 | @Override
|
| 1263 | public boolean isEffectiveAi() {
|
| 1264 | return !this.level().isClientSide() || this.isLocalPlayer();
|
| 1265 | }
|
| 1266 |
|
| 1267 | public GameProfile getGameProfile() {
|
| 1268 | return this.gameProfile;
|
| 1269 | }
|
| 1270 |
|
| 1271 | public NameAndId nameAndId() {
|
| 1272 | return new NameAndId(this.gameProfile);
|
| 1273 | }
|
| 1274 |
|
| 1275 | public Inventory getInventory() {
|
| 1276 | return this.inventory;
|
| 1277 | }
|
| 1278 |
|
| 1279 | public Abilities getAbilities() {
|
| 1280 | return this.abilities;
|
| 1281 | }
|
| 1282 |
|
| 1283 | @Override
|
| 1284 | public boolean hasInfiniteMaterials() {
|
| 1285 | return this.abilities.instabuild;
|
| 1286 | }
|
| 1287 |
|
| 1288 | public boolean preventsBlockDrops() {
|
| 1289 | return this.abilities.instabuild;
|
| 1290 | }
|
| 1291 |
|
| 1292 | public void updateTutorialInventoryAction(final ItemStack itemCarried, final ItemStack itemInSlot, final ClickAction clickAction) {
|
| 1293 | }
|
| 1294 |
|
| 1295 | public boolean hasContainerOpen() {
|
| 1296 | return this.containerMenu != this.inventoryMenu;
|
| 1297 | }
|
| 1298 |
|
| 1299 | public boolean canDropItems() {
|
| 1300 | return true;
|
| 1301 | }
|
| 1302 |
|
| 1303 | public Either<Player.BedSleepingProblem, Unit> startSleepInBed(
|
| 1304 | final AbstractBedBlock bedBlock, final BlockState bedBlockState, final BedRule rule, final BlockPos pos
|
| 1305 | ) {
|
| 1306 | if (!this.startSleeping(pos)) {
|
| 1307 | return Either.left(Player.BedSleepingProblem.OTHER_PROBLEM);
|
| 1308 | }
|
| 1309 |
|
| 1310 | this.sleepCounter = 0;
|
| 1311 | return Either.right(Unit.INSTANCE);
|
| 1312 | }
|
| 1313 |
|
| 1314 | public void stopSleepInBed(final boolean forcefulWakeUp, final boolean updateLevelList) {
|
| 1315 | super.stopSleeping();
|
| 1316 | if (this.level() instanceof ServerLevel && updateLevelList) {
|
| 1317 | ((ServerLevel)this.level()).updateSleepingPlayerList();
|
| 1318 | }
|
| 1319 |
|
| 1320 | this.sleepCounter = forcefulWakeUp ? 0 : 100;
|
| 1321 | }
|
| 1322 |
|
| 1323 | @Override
|
| 1324 | public void stopSleeping() {
|
| 1325 | this.stopSleepInBed(true, true);
|
| 1326 | }
|
| 1327 |
|
| 1328 | public boolean isSleepingLongEnough() {
|
| 1329 | return this.isSleeping() && this.sleepCounter >= 100;
|
| 1330 | }
|
| 1331 |
|
| 1332 | public int getSleepTimer() {
|
| 1333 | return this.sleepCounter;
|
| 1334 | }
|
| 1335 |
|
| 1336 | public void sendSystemMessage(final Component message) {
|
| 1337 | }
|
| 1338 |
|
| 1339 | public void sendOverlayMessage(final Component message) {
|
| 1340 | }
|
| 1341 |
|
| 1342 | public void awardStat(final Identifier location) {
|
| 1343 | this.awardStat(Stats.CUSTOM.get(location));
|
| 1344 | }
|
| 1345 |
|
| 1346 | public void awardStat(final Identifier location, final int count) {
|
| 1347 | this.awardStat(Stats.CUSTOM.get(location), count);
|
| 1348 | }
|
| 1349 |
|
| 1350 | public void awardStat(final Stat<?> stat) {
|
| 1351 | this.awardStat(stat, 1);
|
| 1352 | }
|
| 1353 |
|
| 1354 | public void awardStat(final Stat<?> stat, final int count) {
|
| 1355 | }
|
| 1356 |
|
| 1357 | public void resetStat(final Stat<?> stat) {
|
| 1358 | }
|
| 1359 |
|
| 1360 | public int awardRecipes(final Collection<RecipeHolder<?>> recipes) {
|
| 1361 | return 0;
|
| 1362 | }
|
| 1363 |
|
| 1364 | public void triggerRecipeCrafted(final RecipeHolder<?> recipe, final List<ItemStack> itemStacks) {
|
| 1365 | }
|
| 1366 |
|
| 1367 | @Override
|
| 1368 | public void travel(final Vec3 input) {
|
| 1369 | if (this.isPassenger()) {
|
| 1370 | super.travel(input);
|
| 1371 | } else {
|
| 1372 | if (this.isSwimming()) {
|
| 1373 | double lookAngleY = this.getLookAngle().y;
|
| 1374 | double multiplier = lookAngleY < -0.2 ? 0.085 : 0.06;
|
| 1375 | if (lookAngleY <= 0.0 || this.jumping || !this.level().getFluidState(BlockPos.containing(this.getX(), this.getY() + 1.0 - 0.1, this.getZ())).isEmpty()) {
|
| 1376 | Vec3 movement = this.getDeltaMovement();
|
| 1377 | this.setDeltaMovement(movement.add(0.0, (lookAngleY - movement.y) * multiplier, 0.0));
|
| 1378 | }
|
| 1379 | }
|
| 1380 |
|
| 1381 | if (this.getAbilities().flying) {
|
| 1382 | double originalMovementY = this.getDeltaMovement().y;
|
| 1383 | super.travel(input);
|
| 1384 | this.setDeltaMovement(this.getDeltaMovement().with(Direction.Axis.Y, originalMovementY * 0.6));
|
| 1385 | } else {
|
| 1386 | super.travel(input);
|
| 1387 | }
|
| 1388 | }
|
| 1389 | }
|
| 1390 |
|
| 1391 | @Override
|
| 1392 | protected boolean canGlide() {
|
| 1393 | return !this.abilities.flying && super.canGlide();
|
| 1394 | }
|
| 1395 |
|
| 1396 | @Override
|
| 1397 | public void updateSwimming() {
|
| 1398 | if (this.abilities.flying) {
|
| 1399 | this.setSwimming(false);
|
| 1400 | } else {
|
| 1401 | super.updateSwimming();
|
| 1402 | }
|
| 1403 | }
|
| 1404 |
|
| 1405 | protected boolean freeAt(final BlockPos pos) {
|
| 1406 | return !this.level().getBlockState(pos).isSuffocating(this.level(), pos);
|
| 1407 | }
|
| 1408 |
|
| 1409 | @Override
|
| 1410 | public float getSpeed() {
|
| 1411 | return (float)this.getAttributeValue(Attributes.MOVEMENT_SPEED);
|
| 1412 | }
|
| 1413 |
|
| 1414 | @Override
|
| 1415 | public boolean causeFallDamage(final double fallDistance, final float damageModifier, final DamageSource damageSource) {
|
| 1416 | if (this.abilities.mayfly) {
|
| 1417 | return false;
|
| 1418 | }
|
| 1419 |
|
| 1420 | if (fallDistance >= 2.0) {
|
| 1421 | this.awardStat(Stats.FALL_ONE_CM, (int)Math.round(fallDistance * 100.0));
|
| 1422 | }
|
| 1423 |
|
| 1424 | return super.causeFallDamage(fallDistance, damageModifier, damageSource);
|
| 1425 | }
|
| 1426 |
|
| 1427 | public boolean tryToStartFallFlying() {
|
| 1428 | if (!this.isFallFlying() && this.canGlide() && !this.isInLiquid()) {
|
| 1429 | this.startFallFlying();
|
| 1430 | return true;
|
| 1431 | } else {
|
| 1432 | return false;
|
| 1433 | }
|
| 1434 | }
|
| 1435 |
|
| 1436 | public void startFallFlying() {
|
| 1437 | this.setSharedFlag(7, true);
|
| 1438 | }
|
| 1439 |
|
| 1440 | @Override
|
| 1441 | protected void doWaterSplashEffect() {
|
| 1442 | if (!this.isSpectator()) {
|
| 1443 | super.doWaterSplashEffect();
|
| 1444 | }
|
| 1445 | }
|
| 1446 |
|
| 1447 | @Override
|
| 1448 | protected void playStepSound(final BlockPos onPos, final BlockState onState) {
|
| 1449 | if (this.isInWater()) {
|
| 1450 | this.waterSwimSound();
|
| 1451 | this.playMuffledStepSound(onState);
|
| 1452 | } else {
|
| 1453 | BlockPos primaryStepSoundPos = this.getPrimaryStepSoundBlockPos(onPos);
|
| 1454 | if (!onPos.equals(primaryStepSoundPos)) {
|
| 1455 | BlockState primaryStepState = this.level().getBlockState(primaryStepSoundPos);
|
| 1456 | if (primaryStepState.is(BlockTags.COMBINATION_STEP_SOUND_BLOCKS)) {
|
| 1457 | this.playCombinationStepSounds(primaryStepState, onState);
|
| 1458 | } else {
|
| 1459 | super.playStepSound(primaryStepSoundPos, primaryStepState);
|
| 1460 | }
|
| 1461 | } else {
|
| 1462 | super.playStepSound(onPos, onState);
|
| 1463 | }
|
| 1464 | }
|
| 1465 | }
|
| 1466 |
|
| 1467 | @Override
|
| 1468 | public LivingEntity.Fallsounds getFallSounds() {
|
| 1469 | return new LivingEntity.Fallsounds(SoundEvents.PLAYER_SMALL_FALL, SoundEvents.PLAYER_BIG_FALL);
|
| 1470 | }
|
| 1471 |
|
| 1472 | @Override
|
| 1473 | public boolean killedEntity(final ServerLevel level, final LivingEntity entity, final DamageSource source) {
|
| 1474 | this.awardStat(Stats.ENTITY_KILLED.get(entity.getType()));
|
| 1475 | return true;
|
| 1476 | }
|
| 1477 |
|
| 1478 | @Override
|
| 1479 | public void makeStuckInBlock(final BlockState blockState, final Vec3 speedMultiplier) {
|
| 1480 | if (!this.abilities.flying) {
|
| 1481 | super.makeStuckInBlock(blockState, speedMultiplier);
|
| 1482 | }
|
| 1483 |
|
| 1484 | this.tryResetCurrentImpulseContext();
|
| 1485 | }
|
| 1486 |
|
| 1487 | public void giveExperiencePoints(final int i) {
|
| 1488 | this.increaseScore(i);
|
| 1489 | this.experienceProgress = this.experienceProgress + (float)i / this.getXpNeededForNextLevel();
|
| 1490 | this.totalExperience = Mth.clamp(this.totalExperience + i, 0, Integer.MAX_VALUE);
|
| 1491 |
|
| 1492 | while (this.experienceProgress < 0.0F) {
|
| 1493 | float remaining = this.experienceProgress * this.getXpNeededForNextLevel();
|
| 1494 | if (this.experienceLevel > 0) {
|
| 1495 | this.giveExperienceLevels(-1);
|
| 1496 | this.experienceProgress = 1.0F + remaining / this.getXpNeededForNextLevel();
|
| 1497 | } else {
|
| 1498 | this.giveExperienceLevels(-1);
|
| 1499 | this.experienceProgress = 0.0F;
|
| 1500 | }
|
| 1501 | }
|
| 1502 |
|
| 1503 | while (this.experienceProgress >= 1.0F) {
|
| 1504 | this.experienceProgress = (this.experienceProgress - 1.0F) * this.getXpNeededForNextLevel();
|
| 1505 | this.giveExperienceLevels(1);
|
| 1506 | this.experienceProgress = this.experienceProgress / this.getXpNeededForNextLevel();
|
| 1507 | }
|
| 1508 | }
|
| 1509 |
|
| 1510 | public int getEnchantmentSeed() {
|
| 1511 | return this.enchantmentSeed;
|
| 1512 | }
|
| 1513 |
|
| 1514 | public void onEnchantmentPerformed(final ItemStack itemStack, final int enchantmentCost) {
|
| 1515 | this.experienceLevel -= enchantmentCost;
|
| 1516 | if (this.experienceLevel < 0) {
|
| 1517 | this.experienceLevel = 0;
|
| 1518 | this.experienceProgress = 0.0F;
|
| 1519 | this.totalExperience = 0;
|
| 1520 | }
|
| 1521 |
|
| 1522 | this.enchantmentSeed = this.random.nextInt();
|
| 1523 | }
|
| 1524 |
|
| 1525 | public void giveExperienceLevels(final int amount) {
|
| 1526 | this.experienceLevel = IntMath.saturatedAdd(this.experienceLevel, amount);
|
| 1527 | if (this.experienceLevel < 0) {
|
| 1528 | this.experienceLevel = 0;
|
| 1529 | this.experienceProgress = 0.0F;
|
| 1530 | this.totalExperience = 0;
|
| 1531 | }
|
| 1532 |
|
| 1533 | if (amount > 0 && this.experienceLevel % 5 == 0 && this.lastLevelUpTime < this.tickCount - 100.0F) {
|
| 1534 | float vol = this.experienceLevel > 30 ? 1.0F : this.experienceLevel / 30.0F;
|
| 1535 | this.level().playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_LEVELUP, this.getSoundSource(), vol * 0.75F, 1.0F);
|
| 1536 | this.lastLevelUpTime = this.tickCount;
|
| 1537 | }
|
| 1538 | }
|
| 1539 |
|
| 1540 | public int getXpNeededForNextLevel() {
|
| 1541 | if (this.experienceLevel >= 30) {
|
| 1542 | return 112 + (this.experienceLevel - 30) * 9;
|
| 1543 | } else {
|
| 1544 | return this.experienceLevel >= 15 ? 37 + (this.experienceLevel - 15) * 5 : 7 + this.experienceLevel * 2;
|
| 1545 | }
|
| 1546 | }
|
| 1547 |
|
| 1548 | public void causeFoodExhaustion(final float amount) {
|
| 1549 | if (!this.abilities.invulnerable) {
|
| 1550 | if (!this.level().isClientSide()) {
|
| 1551 | this.foodData.addExhaustion(amount);
|
| 1552 | }
|
| 1553 | }
|
| 1554 | }
|
| 1555 |
|
| 1556 | protected boolean hasEnoughFoodToDoExhaustiveManoeuvres() {
|
| 1557 | return this.getFoodData().hasEnoughFood() || this.getAbilities().mayfly;
|
| 1558 | }
|
| 1559 |
|
| 1560 | public FoodData getFoodData() {
|
| 1561 | return this.foodData;
|
| 1562 | }
|
| 1563 |
|
| 1564 | public boolean canEat(final boolean canAlwaysEat) {
|
| 1565 | return this.abilities.invulnerable || canAlwaysEat || this.foodData.needsFood();
|
| 1566 | }
|
| 1567 |
|
| 1568 | public boolean isHurt() {
|
| 1569 | return this.getHealth() > 0.0F && this.getHealth() < this.getMaxHealth();
|
| 1570 | }
|
| 1571 |
|
| 1572 | public boolean mayBuild() {
|
| 1573 | return this.abilities.mayBuild;
|
| 1574 | }
|
| 1575 |
|
| 1576 | public boolean mayUseItemAt(final BlockPos pos, final Direction direction, final ItemStack itemStack) {
|
| 1577 | if (this.abilities.mayBuild) {
|
| 1578 | return true;
|
| 1579 | }
|
| 1580 |
|
| 1581 | BlockPos target = pos.relative(direction.getOpposite());
|
| 1582 | BlockInWorld block = new BlockInWorld(this.level(), target, false);
|
| 1583 | return itemStack.canPlaceOnBlockInAdventureMode(block);
|
| 1584 | }
|
| 1585 |
|
| 1586 | @Override
|
| 1587 | protected int getBaseExperienceReward(final ServerLevel level) {
|
| 1588 | return !level.getGameRules().get(GameRules.KEEP_INVENTORY) && !this.isSpectator() ? Math.min(this.experienceLevel * 7, 100) : 0;
|
| 1589 | }
|
| 1590 |
|
| 1591 | @Override
|
| 1592 | protected boolean isAlwaysExperienceDropper() {
|
| 1593 | return true;
|
| 1594 | }
|
| 1595 |
|
| 1596 | @Override
|
| 1597 | public boolean shouldShowName() {
|
| 1598 | return true;
|
| 1599 | }
|
| 1600 |
|
| 1601 | @Override
|
| 1602 | protected Entity.MovementEmission getMovementEmission() {
|
| 1603 | return this.abilities.flying || this.onGround() && this.isDiscrete() ? Entity.MovementEmission.NONE : Entity.MovementEmission.ALL;
|
| 1604 | }
|
| 1605 |
|
| 1606 | public void onUpdateAbilities() {
|
| 1607 | }
|
| 1608 |
|
| 1609 | @Override
|
| 1610 | public Component getName() {
|
| 1611 | return Component.literal(this.gameProfile.name());
|
| 1612 | }
|
| 1613 |
|
| 1614 | @Override
|
| 1615 | public String getPlainTextName() {
|
| 1616 | return this.gameProfile.name();
|
| 1617 | }
|
| 1618 |
|
| 1619 | public PlayerEnderChestContainer getEnderChestInventory() {
|
| 1620 | return this.enderChestInventory;
|
| 1621 | }
|
| 1622 |
|
| 1623 | @Override
|
| 1624 | protected boolean doesEmitEquipEvent(final EquipmentSlot slot) {
|
| 1625 | return slot.getType() == EquipmentSlot.Type.HUMANOID_ARMOR;
|
| 1626 | }
|
| 1627 |
|
| 1628 | public boolean addItem(final ItemStack itemStack) {
|
| 1629 | return this.inventory.add(itemStack);
|
| 1630 | }
|
| 1631 |
|
| 1632 | public abstract @Nullable GameType gameMode();
|
| 1633 |
|
| 1634 | @Override
|
| 1635 | public boolean isSpectator() {
|
| 1636 | return this.gameMode() == GameType.SPECTATOR;
|
| 1637 | }
|
| 1638 |
|
| 1639 | @Override
|
| 1640 | public boolean isPickable() {
|
| 1641 | return !this.isSpectator() && super.isPickable();
|
| 1642 | }
|
| 1643 |
|
| 1644 | @Override
|
| 1645 | public boolean isSwimming() {
|
| 1646 | return !this.abilities.flying && !this.isSpectator() && super.isSwimming();
|
| 1647 | }
|
| 1648 |
|
| 1649 | public boolean isCreative() {
|
| 1650 | return this.gameMode() == GameType.CREATIVE;
|
| 1651 | }
|
| 1652 |
|
| 1653 | @Override
|
| 1654 | public boolean isPushedByFluid() {
|
| 1655 | return !this.abilities.flying;
|
| 1656 | }
|
| 1657 |
|
| 1658 | @Override
|
| 1659 | public Component getDisplayName() {
|
| 1660 | MutableComponent result = PlayerTeam.formatNameForTeam(this.getTeam(), this.getName());
|
| 1661 | return this.decorateDisplayNameComponent(result);
|
| 1662 | }
|
| 1663 |
|
| 1664 | private MutableComponent decorateDisplayNameComponent(final MutableComponent nameComponent) {
|
| 1665 | String name = this.getGameProfile().name();
|
| 1666 | return nameComponent.withStyle(
|
| 1667 | s -> s.withClickEvent(new ClickEvent.SuggestCommand("/tell " + name + " ")).withHoverEvent(this.createHoverEvent()).withInsertion(name)
|
| 1668 | );
|
| 1669 | }
|
| 1670 |
|
| 1671 | @Override
|
| 1672 | public String getScoreboardName() {
|
| 1673 | return this.getGameProfile().name();
|
| 1674 | }
|
| 1675 |
|
| 1676 | @Override
|
| 1677 | protected void internalSetAbsorptionAmount(final float absorptionAmount) {
|
| 1678 | this.getEntityData().set(DATA_PLAYER_ABSORPTION_ID, absorptionAmount);
|
| 1679 | }
|
| 1680 |
|
| 1681 | @Override
|
| 1682 | public float getAbsorptionAmount() {
|
| 1683 | return this.getEntityData().get(DATA_PLAYER_ABSORPTION_ID);
|
| 1684 | }
|
| 1685 |
|
| 1686 | @Override
|
| 1687 | public @Nullable SlotAccess getSlot(final int slot) {
|
| 1688 | if (slot == 499) {
|
| 1689 | return new SlotAccess() {
|
| 1690 | @Override
|
| 1691 | public ItemStack get() {
|
| 1692 | return Player.this.containerMenu.getCarried();
|
| 1693 | }
|
| 1694 |
|
| 1695 | @Override
|
| 1696 | public boolean set(final ItemStack itemStack) {
|
| 1697 | Player.this.containerMenu.setCarried(itemStack);
|
| 1698 | return true;
|
| 1699 | }
|
| 1700 | };
|
| 1701 | }
|
| 1702 |
|
| 1703 | final int craftSlot = slot - 500;
|
| 1704 | if (craftSlot >= 0 && craftSlot < 4) {
|
| 1705 | return new SlotAccess() {
|
| 1706 | @Override
|
| 1707 | public ItemStack get() {
|
| 1708 | return Player.this.inventoryMenu.getCraftSlots().getItem(craftSlot);
|
| 1709 | }
|
| 1710 |
|
| 1711 | @Override
|
| 1712 | public boolean set(final ItemStack itemStack) {
|
| 1713 | Player.this.inventoryMenu.getCraftSlots().setItem(craftSlot, itemStack);
|
| 1714 | Player.this.inventoryMenu.slotsChanged(Player.this.inventory);
|
| 1715 | return true;
|
| 1716 | }
|
| 1717 | };
|
| 1718 | }
|
| 1719 |
|
| 1720 | if (slot >= 0 && slot < this.inventory.getNonEquipmentItems().size()) {
|
| 1721 | return this.inventory.getSlot(slot);
|
| 1722 | }
|
| 1723 |
|
| 1724 | int enderSlot = slot - 200;
|
| 1725 | return enderSlot >= 0 && enderSlot < this.enderChestInventory.getContainerSize() ? this.enderChestInventory.getSlot(enderSlot) : super.getSlot(slot);
|
| 1726 | }
|
| 1727 |
|
| 1728 | public boolean isReducedDebugInfo() {
|
| 1729 | return this.reducedDebugInfo;
|
| 1730 | }
|
| 1731 |
|
| 1732 | public void setReducedDebugInfo(final boolean reducedDebugInfo) {
|
| 1733 | this.reducedDebugInfo = reducedDebugInfo;
|
| 1734 | }
|
| 1735 |
|
| 1736 | @Override
|
| 1737 | public void setRemainingFireTicks(final int remainingTicks) {
|
| 1738 | super.setRemainingFireTicks(this.abilities.invulnerable ? Math.min(remainingTicks, 1) : remainingTicks);
|
| 1739 | }
|
| 1740 |
|
| 1741 | protected static Optional<Parrot.Variant> extractParrotVariant(final CompoundTag tag) {
|
| 1742 | if (!tag.isEmpty()) {
|
| 1743 | EntityType<?> entityType = tag.read("id", EntityType.CODEC).orElse(null);
|
| 1744 | if (entityType == EntityTypes.PARROT) {
|
| 1745 | return tag.read("Variant", Parrot.Variant.LEGACY_CODEC);
|
| 1746 | }
|
| 1747 | }
|
| 1748 |
|
| 1749 | return Optional.empty();
|
| 1750 | }
|
| 1751 |
|
| 1752 | protected static OptionalInt convertParrotVariant(final Optional<Parrot.Variant> variant) {
|
| 1753 | return variant.<OptionalInt>map(v -> OptionalInt.of(v.getId())).orElse(OptionalInt.empty());
|
| 1754 | }
|
| 1755 |
|
| 1756 | private static Optional<Parrot.Variant> convertParrotVariant(final OptionalInt variant) {
|
| 1757 | return variant.isPresent() ? Optional.of(Parrot.Variant.byId(variant.getAsInt())) : Optional.empty();
|
| 1758 | }
|
| 1759 |
|
| 1760 | public void setShoulderParrotLeft(final Optional<Parrot.Variant> variant) {
|
| 1761 | this.entityData.set(DATA_SHOULDER_PARROT_LEFT, convertParrotVariant(variant));
|
| 1762 | }
|
| 1763 |
|
| 1764 | public Optional<Parrot.Variant> getShoulderParrotLeft() {
|
| 1765 | return convertParrotVariant(this.entityData.get(DATA_SHOULDER_PARROT_LEFT));
|
| 1766 | }
|
| 1767 |
|
| 1768 | public void setShoulderParrotRight(final Optional<Parrot.Variant> variant) {
|
| 1769 | this.entityData.set(DATA_SHOULDER_PARROT_RIGHT, convertParrotVariant(variant));
|
| 1770 | }
|
| 1771 |
|
| 1772 | public Optional<Parrot.Variant> getShoulderParrotRight() {
|
| 1773 | return convertParrotVariant(this.entityData.get(DATA_SHOULDER_PARROT_RIGHT));
|
| 1774 | }
|
| 1775 |
|
| 1776 | public float getCurrentItemAttackStrengthDelay() {
|
| 1777 | return (float)(1.0 / this.getAttributeValue(Attributes.ATTACK_SPEED) * 20.0);
|
| 1778 | }
|
| 1779 |
|
| 1780 | public boolean cannotAttackWithItem(final ItemStack itemStack, final int tolerance) {
|
| 1781 | float requiredStrength = itemStack.getOrDefault(DataComponents.MINIMUM_ATTACK_CHARGE, 0.0F);
|
| 1782 | float optimisticStrength = (this.attackStrengthTicker + tolerance) / this.getCurrentItemAttackStrengthDelay();
|
| 1783 | return requiredStrength > 0.0F && optimisticStrength < requiredStrength;
|
| 1784 | }
|
| 1785 |
|
| 1786 | public float getAttackStrengthScale(final float a) {
|
| 1787 | return Mth.clamp((this.attackStrengthTicker + a) / this.getCurrentItemAttackStrengthDelay(), 0.0F, 1.0F);
|
| 1788 | }
|
| 1789 |
|
| 1790 | public float getItemSwapScale(final float a) {
|
| 1791 | return Mth.clamp((this.itemSwapTicker + a) / this.getCurrentItemAttackStrengthDelay(), 0.0F, 1.0F);
|
| 1792 | }
|
| 1793 |
|
| 1794 | public void resetAttackStrengthTicker() {
|
| 1795 | this.attackStrengthTicker = 0;
|
| 1796 | this.itemSwapTicker = 0;
|
| 1797 | }
|
| 1798 |
|
| 1799 | @Override
|
| 1800 | public void onAttack() {
|
| 1801 | this.resetOnlyAttackStrengthTicker();
|
| 1802 | super.onAttack();
|
| 1803 | }
|
| 1804 |
|
| 1805 | public void resetOnlyAttackStrengthTicker() {
|
| 1806 | this.attackStrengthTicker = 0;
|
| 1807 | }
|
| 1808 |
|
| 1809 | public ItemCooldowns getCooldowns() {
|
| 1810 | return this.cooldowns;
|
| 1811 | }
|
| 1812 |
|
| 1813 | @Override
|
| 1814 | protected float getBlockSpeedFactor() {
|
| 1815 | return !this.abilities.flying && !this.isFallFlying() ? super.getBlockSpeedFactor() : 1.0F;
|
| 1816 | }
|
| 1817 |
|
| 1818 | @Override
|
| 1819 | public float getLuck() {
|
| 1820 | return (float)this.getAttributeValue(Attributes.LUCK);
|
| 1821 | }
|
| 1822 |
|
| 1823 | public boolean canUseGameMasterBlocks() {
|
| 1824 | return this.abilities.instabuild && this.permissions().hasPermission(Permissions.COMMANDS_GAMEMASTER);
|
| 1825 | }
|
| 1826 |
|
| 1827 | public PermissionSet permissions() {
|
| 1828 | return PermissionSet.NO_PERMISSIONS;
|
| 1829 | }
|
| 1830 |
|
| 1831 | @Override
|
| 1832 | public ImmutableList<Pose> getDismountPoses() {
|
| 1833 | return ImmutableList.of(Pose.STANDING, Pose.CROUCHING, Pose.SWIMMING);
|
| 1834 | }
|
| 1835 |
|
| 1836 | @Override
|
| 1837 | public ItemStack getProjectile(final ItemStack heldWeapon) {
|
| 1838 | if (!(heldWeapon.getItem() instanceof ProjectileWeaponItem)) {
|
| 1839 | return ItemStack.EMPTY;
|
| 1840 | }
|
| 1841 |
|
| 1842 | Predicate<ItemStack> supportedProjectiles = ((ProjectileWeaponItem)heldWeapon.getItem()).getSupportedHeldProjectiles();
|
| 1843 | ItemStack heldProjectile = ProjectileWeaponItem.getHeldProjectile(this, supportedProjectiles);
|
| 1844 | if (!heldProjectile.isEmpty()) {
|
| 1845 | return heldProjectile;
|
| 1846 | }
|
| 1847 |
|
| 1848 | supportedProjectiles = ((ProjectileWeaponItem)heldWeapon.getItem()).getAllSupportedProjectiles();
|
| 1849 |
|
| 1850 | for (int i = 0; i < this.inventory.getContainerSize(); i++) {
|
| 1851 | ItemStack itemStack = this.inventory.getItem(i);
|
| 1852 | if (supportedProjectiles.test(itemStack)) {
|
| 1853 | return itemStack;
|
| 1854 | }
|
| 1855 | }
|
| 1856 |
|
| 1857 | return this.hasInfiniteMaterials() ? new ItemStack(Items.ARROW) : ItemStack.EMPTY;
|
| 1858 | }
|
| 1859 |
|
| 1860 | @Override
|
| 1861 | public Vec3 getRopeHoldPosition(final float partialTickTime) {
|
| 1862 | double xOff = 0.22 * (this.getMainArm() == HumanoidArm.RIGHT ? -1.0 : 1.0);
|
| 1863 | float xRot = Mth.lerp(partialTickTime * 0.5F, this.getXRot(), this.xRotO) * (float) (Math.PI / 180.0);
|
| 1864 | float yRot = Mth.lerp(partialTickTime, this.yBodyRotO, this.yBodyRot) * (float) (Math.PI / 180.0);
|
| 1865 | if (this.isFallFlying() || this.isAutoSpinAttack()) {
|
| 1866 | Vec3 lookAngle = this.getViewVector(partialTickTime);
|
| 1867 | Vec3 movement = this.getDeltaMovement();
|
| 1868 | double speedLen = movement.horizontalDistanceSqr();
|
| 1869 | double lookLen = lookAngle.horizontalDistanceSqr();
|
| 1870 | float zRot;
|
| 1871 | if (speedLen > 0.0 && lookLen > 0.0) {
|
| 1872 | double dot = (movement.x * lookAngle.x + movement.z * lookAngle.z) / Math.sqrt(speedLen * lookLen);
|
| 1873 | double sign = movement.x * lookAngle.z - movement.z * lookAngle.x;
|
| 1874 | zRot = (float)(Math.signum(sign) * Math.acos(dot));
|
| 1875 | } else {
|
| 1876 | zRot = 0.0F;
|
| 1877 | }
|
| 1878 |
|
| 1879 | return this.getPosition(partialTickTime).add(new Vec3(xOff, -0.11, 0.85).zRot(-zRot).xRot(-xRot).yRot(-yRot));
|
| 1880 | } else {
|
| 1881 | if (this.isVisuallySwimming()) {
|
| 1882 | return this.getPosition(partialTickTime).add(new Vec3(xOff, 0.2, -0.15).xRot(-xRot).yRot(-yRot));
|
| 1883 | }
|
| 1884 |
|
| 1885 | double yOff = this.getBoundingBox().getYsize() - 1.0;
|
| 1886 | double zOff = this.isCrouching() ? -0.2 : 0.07;
|
| 1887 | return this.getPosition(partialTickTime).add(new Vec3(xOff, yOff, zOff).yRot(-yRot));
|
| 1888 | }
|
| 1889 | }
|
| 1890 |
|
| 1891 | @Override
|
| 1892 | public boolean isAlwaysTicking() {
|
| 1893 | return true;
|
| 1894 | }
|
| 1895 |
|
| 1896 | public boolean isScoping() {
|
| 1897 | return this.isUsingItem() && this.getUseItem().is(Items.SPYGLASS);
|
| 1898 | }
|
| 1899 |
|
| 1900 | @Override
|
| 1901 | public boolean shouldBeSaved() {
|
| 1902 | return false;
|
| 1903 | }
|
| 1904 |
|
| 1905 | public Optional<GlobalPos> getLastDeathLocation() {
|
| 1906 | return this.lastDeathLocation;
|
| 1907 | }
|
| 1908 |
|
| 1909 | public void setLastDeathLocation(final Optional<GlobalPos> pos) {
|
| 1910 | this.lastDeathLocation = pos;
|
| 1911 | }
|
| 1912 |
|
| 1913 | @Override
|
| 1914 | public float getHurtDir() {
|
| 1915 | return this.hurtDir;
|
| 1916 | }
|
| 1917 |
|
| 1918 | @Override
|
| 1919 | public void animateHurt(final float yaw) {
|
| 1920 | super.animateHurt(yaw);
|
| 1921 | this.hurtDir = yaw;
|
| 1922 | }
|
| 1923 |
|
| 1924 | public boolean isMobilityRestricted() {
|
| 1925 | return this.hasEffect(MobEffects.BLINDNESS);
|
| 1926 | }
|
| 1927 |
|
| 1928 | @Override
|
| 1929 | public boolean canSprint() {
|
| 1930 | return true;
|
| 1931 | }
|
| 1932 |
|
| 1933 | @Override
|
| 1934 | protected float getFlyingSpeed() {
|
| 1935 | if (this.abilities.flying && !this.isPassenger()) {
|
| 1936 | return this.isSprinting() ? this.abilities.getFlyingSpeed() * 2.0F : this.abilities.getFlyingSpeed();
|
| 1937 | } else {
|
| 1938 | return this.isSprinting() ? 0.025999999F : 0.02F;
|
| 1939 | }
|
| 1940 | }
|
| 1941 |
|
| 1942 | @Override
|
| 1943 | public boolean hasContainerOpen(final ContainerOpenersCounter container, final BlockPos blockPos) {
|
| 1944 | return container.isOwnContainer(this);
|
| 1945 | }
|
| 1946 |
|
| 1947 | @Override
|
| 1948 | public double getContainerInteractionRange() {
|
| 1949 | return this.blockInteractionRange();
|
| 1950 | }
|
| 1951 |
|
| 1952 | public double blockInteractionRange() {
|
| 1953 | return this.getAttributeValue(Attributes.BLOCK_INTERACTION_RANGE);
|
| 1954 | }
|
| 1955 |
|
| 1956 | public double entityInteractionRange() {
|
| 1957 | return this.getAttributeValue(Attributes.ENTITY_INTERACTION_RANGE);
|
| 1958 | }
|
| 1959 |
|
| 1960 | public boolean isWithinEntityInteractionRange(final Entity entity, final double buffer) {
|
| 1961 | return entity.isRemoved() ? false : this.isWithinEntityInteractionRange(entity.getBoundingBox(), buffer);
|
| 1962 | }
|
| 1963 |
|
| 1964 | public boolean isWithinEntityInteractionRange(final AABB aabb, final double buffer) {
|
| 1965 | double maxRange = this.entityInteractionRange() + buffer;
|
| 1966 | double distanceToSq = aabb.distanceToSqr(this.getEyePosition());
|
| 1967 | return distanceToSq < maxRange * maxRange;
|
| 1968 | }
|
| 1969 |
|
| 1970 | public boolean isWithinAttackRange(final ItemStack weaponItem, final AABB aabb, final double buffer) {
|
| 1971 | return this.getAttackRangeWith(weaponItem).isInRange(this, aabb, buffer);
|
| 1972 | }
|
| 1973 |
|
| 1974 | public boolean isWithinBlockInteractionRange(final BlockPos pos, final double buffer) {
|
| 1975 | double maxRange = this.blockInteractionRange() + buffer;
|
| 1976 | return new AABB(pos).distanceToSqr(this.getEyePosition()) < maxRange * maxRange;
|
| 1977 | }
|
| 1978 |
|
| 1979 | public boolean shouldRotateWithMinecart() {
|
| 1980 | return false;
|
| 1981 | }
|
| 1982 |
|
| 1983 | @Override
|
| 1984 | public boolean onClimbable() {
|
| 1985 | return this.abilities.flying ? false : super.onClimbable();
|
| 1986 | }
|
| 1987 |
|
| 1988 | public String debugInfo() {
|
| 1989 | return MoreObjects.toStringHelper(this)
|
| 1990 | .add("name", this.getPlainTextName())
|
| 1991 | .add("id", this.getId())
|
| 1992 | .add("pos", this.position())
|
| 1993 | .add("mode", this.gameMode())
|
| 1994 | .add("permission", printPlayerPermissions(this.permissions()))
|
| 1995 | .toString();
|
| 1996 | }
|
| 1997 |
|
| 1998 | private static String printPlayerPermissions(final PermissionSet permissions) {
|
| 1999 | if (permissions.hasPermission(Permissions.COMMANDS_OWNER)) {
|
| 2000 | return "owner";
|
| 2001 | } else if (permissions.hasPermission(Permissions.COMMANDS_ADMIN)) {
|
| 2002 | return "admin";
|
| 2003 | } else if (permissions.hasPermission(Permissions.COMMANDS_GAMEMASTER)) {
|
| 2004 | return "gamemaster";
|
| 2005 | } else {
|
| 2006 | return permissions.hasPermission(Permissions.COMMANDS_MODERATOR) ? "moderator" : "none";
|
| 2007 | }
|
| 2008 | }
|
| 2009 |
|
| 2010 | @Override
|
| 2011 | public ResolvableProfile getProfile() {
|
| 2012 | return ResolvableProfile.createResolved(this.gameProfile);
|
| 2013 | }
|
| 2014 |
|
| 2015 | @Override
|
| 2016 | public DamageSource createDamageSource() {
|
| 2017 | return this.damageSources().playerAttack(this);
|
| 2018 | }
|
| 2019 |
|
| 2020 | public record BedSleepingProblem(@Nullable Component message) {
|
| 2021 | public static final Player.BedSleepingProblem TOO_FAR_AWAY = new Player.BedSleepingProblem(Component.translatable("block.minecraft.bed.too_far_away"));
|
| 2022 | public static final Player.BedSleepingProblem OBSTRUCTED = new Player.BedSleepingProblem(Component.translatable("block.minecraft.bed.obstructed"));
|
| 2023 | public static final Player.BedSleepingProblem OTHER_PROBLEM = new Player.BedSleepingProblem(null);
|
| 2024 | public static final Player.BedSleepingProblem NOT_SAFE = new Player.BedSleepingProblem(Component.translatable("block.minecraft.bed.not_safe"));
|
| 2025 | }
|
| 2026 | }
|
| 2027 |
|