| 1 | package net.minecraft.world.entity;
|
| 2 |
|
| 3 | import com.google.common.collect.ImmutableMap;
|
| 4 | import java.util.Map;
|
| 5 | import net.minecraft.network.syncher.EntityDataAccessor;
|
| 6 | import net.minecraft.network.syncher.EntityDataSerializers;
|
| 7 | import net.minecraft.network.syncher.SynchedEntityData;
|
| 8 | import net.minecraft.world.entity.player.PlayerModelPart;
|
| 9 | import net.minecraft.world.item.component.ResolvableProfile;
|
| 10 | import net.minecraft.world.level.Level;
|
| 11 | import net.minecraft.world.phys.Vec3;
|
| 12 |
|
| 13 | public abstract class Avatar extends LivingEntity {
|
| 14 | public static final HumanoidArm DEFAULT_MAIN_HAND = HumanoidArm.RIGHT;
|
| 15 | public static final int DEFAULT_MODEL_CUSTOMIZATION = 0;
|
| 16 | public static final float DEFAULT_EYE_HEIGHT = 1.62F;
|
| 17 | public static final Vec3 DEFAULT_VEHICLE_ATTACHMENT = new Vec3(0.0, 0.6, 0.0);
|
| 18 | private static final float CROUCH_BB_HEIGHT = 1.5F;
|
| 19 | private static final float SWIMMING_BB_WIDTH = 0.6F;
|
| 20 | public static final float SWIMMING_BB_HEIGHT = 0.6F;
|
| 21 | protected static final EntityDimensions STANDING_DIMENSIONS = EntityDimensions.scalable(0.6F, 1.8F)
|
| 22 | .withEyeHeight(1.62F)
|
| 23 | .withAttachments(EntityAttachments.builder().attach(EntityAttachment.VEHICLE, DEFAULT_VEHICLE_ATTACHMENT));
|
| 24 | protected static final Map<Pose, EntityDimensions> POSES = ImmutableMap.<Pose, EntityDimensions>builder()
|
| 25 | .put(Pose.STANDING, STANDING_DIMENSIONS)
|
| 26 | .put(Pose.SLEEPING, SLEEPING_DIMENSIONS)
|
| 27 | .put(Pose.FALL_FLYING, EntityDimensions.scalable(0.6F, 0.6F).withEyeHeight(0.4F))
|
| 28 | .put(Pose.SWIMMING, EntityDimensions.scalable(0.6F, 0.6F).withEyeHeight(0.4F))
|
| 29 | .put(Pose.SPIN_ATTACK, EntityDimensions.scalable(0.6F, 0.6F).withEyeHeight(0.4F))
|
| 30 | .put(
|
| 31 | Pose.CROUCHING,
|
| 32 | EntityDimensions.scalable(0.6F, 1.5F)
|
| 33 | .withEyeHeight(1.27F)
|
| 34 | .withAttachments(EntityAttachments.builder().attach(EntityAttachment.VEHICLE, DEFAULT_VEHICLE_ATTACHMENT))
|
| 35 | )
|
| 36 | .put(Pose.DYING, EntityDimensions.fixed(0.2F, 0.2F).withEyeHeight(1.62F))
|
| 37 | .build();
|
| 38 | protected static final EntityDataAccessor<HumanoidArm> DATA_PLAYER_MAIN_HAND = SynchedEntityData.defineId(Avatar.class, EntityDataSerializers.HUMANOID_ARM);
|
| 39 | protected static final EntityDataAccessor<Byte> DATA_PLAYER_MODE_CUSTOMISATION = SynchedEntityData.defineId(Avatar.class, EntityDataSerializers.BYTE);
|
| 40 |
|
| 41 | protected Avatar(final EntityType<? extends LivingEntity> type, final Level level) {
|
| 42 | super(type, level);
|
| 43 | }
|
| 44 |
|
| 45 | @Override
|
| 46 | protected void defineSynchedData(final SynchedEntityData.Builder entityData) {
|
| 47 | super.defineSynchedData(entityData);
|
| 48 | entityData.define(DATA_PLAYER_MAIN_HAND, DEFAULT_MAIN_HAND);
|
| 49 | entityData.define(DATA_PLAYER_MODE_CUSTOMISATION, (byte)0);
|
| 50 | }
|
| 51 |
|
| 52 | @Override
|
| 53 | public HumanoidArm getMainArm() {
|
| 54 | return this.entityData.get(DATA_PLAYER_MAIN_HAND);
|
| 55 | }
|
| 56 |
|
| 57 | public void setMainArm(final HumanoidArm mainArm) {
|
| 58 | this.entityData.set(DATA_PLAYER_MAIN_HAND, mainArm);
|
| 59 | }
|
| 60 |
|
| 61 | public boolean isModelPartShown(final PlayerModelPart part) {
|
| 62 | return (this.getEntityData().get(DATA_PLAYER_MODE_CUSTOMISATION) & part.getMask()) == part.getMask();
|
| 63 | }
|
| 64 |
|
| 65 | @Override
|
| 66 | public EntityDimensions getDefaultDimensions(final Pose pose) {
|
| 67 | return POSES.getOrDefault(pose, STANDING_DIMENSIONS);
|
| 68 | }
|
| 69 |
|
| 70 | public abstract ResolvableProfile getProfile();
|
| 71 | }
|
| 72 |
|