| 1 | package net.minecraft.world.entity.player;
|
| 2 |
|
| 3 | import com.mojang.serialization.Codec;
|
| 4 | import com.mojang.serialization.codecs.RecordCodecBuilder;
|
| 5 | import net.minecraft.util.ExtraCodecs;
|
| 6 |
|
| 7 | public class Abilities {
|
| 8 | private static final boolean DEFAULT_INVULNERABLE = false;
|
| 9 | private static final boolean DEFAULY_FLYING = false;
|
| 10 | private static final boolean DEFAULT_MAY_FLY = false;
|
| 11 | private static final boolean DEFAULT_INSTABUILD = false;
|
| 12 | private static final boolean DEFAULT_MAY_BUILD = true;
|
| 13 | private static final float DEFAULT_FLYING_SPEED = 0.05F;
|
| 14 | private static final float DEFAULT_WALKING_SPEED = 0.1F;
|
| 15 | public boolean invulnerable;
|
| 16 | public boolean flying;
|
| 17 | public boolean mayfly;
|
| 18 | public boolean instabuild;
|
| 19 | public boolean mayBuild = true;
|
| 20 | private float flyingSpeed = 0.05F;
|
| 21 | private float walkingSpeed = 0.1F;
|
| 22 |
|
| 23 | public float getFlyingSpeed() {
|
| 24 | return this.flyingSpeed;
|
| 25 | }
|
| 26 |
|
| 27 | public void setFlyingSpeed(final float value) {
|
| 28 | this.flyingSpeed = value;
|
| 29 | }
|
| 30 |
|
| 31 | public float getWalkingSpeed() {
|
| 32 | return this.walkingSpeed;
|
| 33 | }
|
| 34 |
|
| 35 | public void setWalkingSpeed(final float value) {
|
| 36 | this.walkingSpeed = value;
|
| 37 | }
|
| 38 |
|
| 39 | public Abilities.Packed pack() {
|
| 40 | return new Abilities.Packed(this.invulnerable, this.flying, this.mayfly, this.instabuild, this.mayBuild, this.flyingSpeed, this.walkingSpeed);
|
| 41 | }
|
| 42 |
|
| 43 | public void apply(final Abilities.Packed packed) {
|
| 44 | this.invulnerable = packed.invulnerable;
|
| 45 | this.flying = packed.flying;
|
| 46 | this.mayfly = packed.mayFly;
|
| 47 | this.instabuild = packed.instabuild;
|
| 48 | this.mayBuild = packed.mayBuild;
|
| 49 | this.flyingSpeed = packed.flyingSpeed;
|
| 50 | this.walkingSpeed = packed.walkingSpeed;
|
| 51 | }
|
| 52 |
|
| 53 | public record Packed(boolean invulnerable, boolean flying, boolean mayFly, boolean instabuild, boolean mayBuild, float flyingSpeed, float walkingSpeed) {
|
| 54 | public static final Codec<Abilities.Packed> CODEC = RecordCodecBuilder.create(
|
| 55 | i -> i.group(
|
| 56 | ExtraCodecs.optionalAlwaysPresentFieldOf(Codec.BOOL, "invulnerable", false).forGetter(Abilities.Packed::invulnerable),
|
| 57 | ExtraCodecs.optionalAlwaysPresentFieldOf(Codec.BOOL, "flying", false).forGetter(Abilities.Packed::flying),
|
| 58 | ExtraCodecs.optionalAlwaysPresentFieldOf(Codec.BOOL, "mayfly", false).forGetter(Abilities.Packed::mayFly),
|
| 59 | ExtraCodecs.optionalAlwaysPresentFieldOf(Codec.BOOL, "instabuild", false).forGetter(Abilities.Packed::instabuild),
|
| 60 | ExtraCodecs.optionalAlwaysPresentFieldOf(Codec.BOOL, "mayBuild", true).forGetter(Abilities.Packed::mayBuild),
|
| 61 | ExtraCodecs.optionalAlwaysPresentFieldOf(Codec.FLOAT, "flySpeed", 0.05F).forGetter(Abilities.Packed::flyingSpeed),
|
| 62 | ExtraCodecs.optionalAlwaysPresentFieldOf(Codec.FLOAT, "walkSpeed", 0.1F).forGetter(Abilities.Packed::walkingSpeed)
|
| 63 | )
|
| 64 | .apply(i, Abilities.Packed::new)
|
| 65 | );
|
| 66 | }
|
| 67 | }
|
| 68 |
|