93 lines
2.5 KiB
Java
93 lines
2.5 KiB
Java
package net.minecraft.world.level;
|
|
|
|
import net.minecraft.world.entity.player.Abilities;
|
|
import net.minecraft.network.chat.TranslatableComponent;
|
|
import net.minecraft.network.chat.Component;
|
|
|
|
public enum GameType {
|
|
NOT_SET(-1, ""),
|
|
SURVIVAL(0, "survival"),
|
|
CREATIVE(1, "creative"),
|
|
ADVENTURE(2, "adventure"),
|
|
SPECTATOR(3, "spectator");
|
|
|
|
private final int id;
|
|
private final String name;
|
|
|
|
private GameType(final int integer3, final String string4) {
|
|
this.id = integer3;
|
|
this.name = string4;
|
|
}
|
|
|
|
public int getId() {
|
|
return this.id;
|
|
}
|
|
|
|
public String getName() {
|
|
return this.name;
|
|
}
|
|
|
|
public Component getDisplayName() {
|
|
return new TranslatableComponent("gameMode." + this.name, new Object[0]);
|
|
}
|
|
|
|
public void updatePlayerAbilities(final Abilities ayd) {
|
|
if (this == GameType.CREATIVE) {
|
|
ayd.mayfly = true;
|
|
ayd.instabuild = true;
|
|
ayd.invulnerable = true;
|
|
}
|
|
else if (this == GameType.SPECTATOR) {
|
|
ayd.mayfly = true;
|
|
ayd.instabuild = false;
|
|
ayd.invulnerable = true;
|
|
ayd.flying = true;
|
|
}
|
|
else {
|
|
ayd.mayfly = false;
|
|
ayd.instabuild = false;
|
|
ayd.invulnerable = false;
|
|
ayd.flying = false;
|
|
}
|
|
ayd.mayBuild = !this.isBlockPlacingRestricted();
|
|
}
|
|
|
|
public boolean isBlockPlacingRestricted() {
|
|
return this == GameType.ADVENTURE || this == GameType.SPECTATOR;
|
|
}
|
|
|
|
public boolean isCreative() {
|
|
return this == GameType.CREATIVE;
|
|
}
|
|
|
|
public boolean isSurvival() {
|
|
return this == GameType.SURVIVAL || this == GameType.ADVENTURE;
|
|
}
|
|
|
|
public static GameType byId(final int integer) {
|
|
return byId(integer, GameType.SURVIVAL);
|
|
}
|
|
|
|
public static GameType byId(final int integer, final GameType bjq) {
|
|
for (final GameType bjq2 : values()) {
|
|
if (bjq2.id == integer) {
|
|
return bjq2;
|
|
}
|
|
}
|
|
return bjq;
|
|
}
|
|
|
|
public static GameType byName(final String string) {
|
|
return byName(string, GameType.SURVIVAL);
|
|
}
|
|
|
|
public static GameType byName(final String string, final GameType bjq) {
|
|
for (final GameType bjq2 : values()) {
|
|
if (bjq2.name.equals(string)) {
|
|
return bjq2;
|
|
}
|
|
}
|
|
return bjq;
|
|
}
|
|
}
|