/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.brigadier.arguments.ArgumentType * com.mojang.brigadier.arguments.BoolArgumentType * com.mojang.brigadier.arguments.IntegerArgumentType * com.mojang.serialization.Codec * org.jspecify.annotations.Nullable */ package net.minecraft.world.level.gamerules; import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.arguments.BoolArgumentType; import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.serialization.Codec; import java.util.Objects; import java.util.function.ToIntFunction; import java.util.stream.Stream; import net.minecraft.SharedConstants; import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.server.MinecraftServer; import net.minecraft.world.flag.FeatureFlagSet; import net.minecraft.world.flag.FeatureFlags; import net.minecraft.world.level.gamerules.GameRule; import net.minecraft.world.level.gamerules.GameRuleCategory; import net.minecraft.world.level.gamerules.GameRuleMap; import net.minecraft.world.level.gamerules.GameRuleType; import net.minecraft.world.level.gamerules.GameRuleTypeVisitor; import org.jspecify.annotations.Nullable; public class GameRules { public static final GameRule ADVANCE_TIME = GameRules.registerBoolean("advance_time", GameRuleCategory.UPDATES, !SharedConstants.DEBUG_WORLD_RECREATE); public static final GameRule ADVANCE_WEATHER = GameRules.registerBoolean("advance_weather", GameRuleCategory.UPDATES, !SharedConstants.DEBUG_WORLD_RECREATE); public static final GameRule ALLOW_ENTERING_NETHER_USING_PORTALS = GameRules.registerBoolean("allow_entering_nether_using_portals", GameRuleCategory.MISC, true); public static final GameRule BLOCK_DROPS = GameRules.registerBoolean("block_drops", GameRuleCategory.DROPS, true); public static final GameRule BLOCK_EXPLOSION_DROP_DECAY = GameRules.registerBoolean("block_explosion_drop_decay", GameRuleCategory.DROPS, true); public static final GameRule COMMAND_BLOCKS_WORK = GameRules.registerBoolean("command_blocks_work", GameRuleCategory.MISC, true); public static final GameRule COMMAND_BLOCK_OUTPUT = GameRules.registerBoolean("command_block_output", GameRuleCategory.CHAT, true); public static final GameRule DROWNING_DAMAGE = GameRules.registerBoolean("drowning_damage", GameRuleCategory.PLAYER, true); public static final GameRule ELYTRA_MOVEMENT_CHECK = GameRules.registerBoolean("elytra_movement_check", GameRuleCategory.PLAYER, true); public static final GameRule ENDER_PEARLS_VANISH_ON_DEATH = GameRules.registerBoolean("ender_pearls_vanish_on_death", GameRuleCategory.PLAYER, true); public static final GameRule ENTITY_DROPS = GameRules.registerBoolean("entity_drops", GameRuleCategory.DROPS, true); public static final GameRule FALL_DAMAGE = GameRules.registerBoolean("fall_damage", GameRuleCategory.PLAYER, true); public static final GameRule FIRE_DAMAGE = GameRules.registerBoolean("fire_damage", GameRuleCategory.PLAYER, true); public static final GameRule FIRE_SPREAD_RADIUS_AROUND_PLAYER = GameRules.registerInteger("fire_spread_radius_around_player", GameRuleCategory.UPDATES, 128, -1); public static final GameRule FORGIVE_DEAD_PLAYERS = GameRules.registerBoolean("forgive_dead_players", GameRuleCategory.MOBS, true); public static final GameRule FREEZE_DAMAGE = GameRules.registerBoolean("freeze_damage", GameRuleCategory.PLAYER, true); public static final GameRule GLOBAL_SOUND_EVENTS = GameRules.registerBoolean("global_sound_events", GameRuleCategory.MISC, true); public static final GameRule IMMEDIATE_RESPAWN = GameRules.registerBoolean("immediate_respawn", GameRuleCategory.PLAYER, false); public static final GameRule KEEP_INVENTORY = GameRules.registerBoolean("keep_inventory", GameRuleCategory.PLAYER, false); public static final GameRule LAVA_SOURCE_CONVERSION = GameRules.registerBoolean("lava_source_conversion", GameRuleCategory.UPDATES, false); public static final GameRule LIMITED_CRAFTING = GameRules.registerBoolean("limited_crafting", GameRuleCategory.PLAYER, false); public static final GameRule LOCATOR_BAR = GameRules.registerBoolean("locator_bar", GameRuleCategory.PLAYER, true); public static final GameRule LOG_ADMIN_COMMANDS = GameRules.registerBoolean("log_admin_commands", GameRuleCategory.CHAT, true); public static final GameRule MAX_BLOCK_MODIFICATIONS = GameRules.registerInteger("max_block_modifications", GameRuleCategory.MISC, 32768, 1); public static final GameRule MAX_COMMAND_FORKS = GameRules.registerInteger("max_command_forks", GameRuleCategory.MISC, 65536, 0); public static final GameRule MAX_COMMAND_SEQUENCE_LENGTH = GameRules.registerInteger("max_command_sequence_length", GameRuleCategory.MISC, 65536, 0); public static final GameRule MAX_ENTITY_CRAMMING = GameRules.registerInteger("max_entity_cramming", GameRuleCategory.MOBS, 24, 0); public static final GameRule MAX_MINECART_SPEED = GameRules.registerInteger("max_minecart_speed", GameRuleCategory.MISC, 8, 1, 1000, FeatureFlagSet.of(FeatureFlags.MINECART_IMPROVEMENTS)); public static final GameRule MAX_SNOW_ACCUMULATION_HEIGHT = GameRules.registerInteger("max_snow_accumulation_height", GameRuleCategory.UPDATES, 1, 0, 8); public static final GameRule MOB_DROPS = GameRules.registerBoolean("mob_drops", GameRuleCategory.DROPS, true); public static final GameRule MOB_EXPLOSION_DROP_DECAY = GameRules.registerBoolean("mob_explosion_drop_decay", GameRuleCategory.DROPS, true); public static final GameRule MOB_GRIEFING = GameRules.registerBoolean("mob_griefing", GameRuleCategory.MOBS, true); public static final GameRule NATURAL_HEALTH_REGENERATION = GameRules.registerBoolean("natural_health_regeneration", GameRuleCategory.PLAYER, true); public static final GameRule PLAYER_MOVEMENT_CHECK = GameRules.registerBoolean("player_movement_check", GameRuleCategory.PLAYER, true); public static final GameRule PLAYERS_NETHER_PORTAL_CREATIVE_DELAY = GameRules.registerInteger("players_nether_portal_creative_delay", GameRuleCategory.PLAYER, 0, 0); public static final GameRule PLAYERS_NETHER_PORTAL_DEFAULT_DELAY = GameRules.registerInteger("players_nether_portal_default_delay", GameRuleCategory.PLAYER, 80, 0); public static final GameRule PLAYERS_SLEEPING_PERCENTAGE = GameRules.registerInteger("players_sleeping_percentage", GameRuleCategory.PLAYER, 100, 0); public static final GameRule PROJECTILES_CAN_BREAK_BLOCKS = GameRules.registerBoolean("projectiles_can_break_blocks", GameRuleCategory.DROPS, true); public static final GameRule PVP = GameRules.registerBoolean("pvp", GameRuleCategory.PLAYER, true); public static final GameRule RAIDS = GameRules.registerBoolean("raids", GameRuleCategory.MOBS, true); public static final GameRule RANDOM_TICK_SPEED = GameRules.registerInteger("random_tick_speed", GameRuleCategory.UPDATES, 3, 0); public static final GameRule REDUCED_DEBUG_INFO = GameRules.registerBoolean("reduced_debug_info", GameRuleCategory.MISC, false); public static final GameRule RESPAWN_RADIUS = GameRules.registerInteger("respawn_radius", GameRuleCategory.PLAYER, 10, 0); public static final GameRule SEND_COMMAND_FEEDBACK = GameRules.registerBoolean("send_command_feedback", GameRuleCategory.CHAT, true); public static final GameRule SHOW_ADVANCEMENT_MESSAGES = GameRules.registerBoolean("show_advancement_messages", GameRuleCategory.CHAT, true); public static final GameRule SHOW_DEATH_MESSAGES = GameRules.registerBoolean("show_death_messages", GameRuleCategory.CHAT, true); public static final GameRule SPAWNER_BLOCKS_WORK = GameRules.registerBoolean("spawner_blocks_work", GameRuleCategory.MISC, true); public static final GameRule SPAWN_MOBS = GameRules.registerBoolean("spawn_mobs", GameRuleCategory.SPAWNING, true); public static final GameRule SPAWN_MONSTERS = GameRules.registerBoolean("spawn_monsters", GameRuleCategory.SPAWNING, true); public static final GameRule SPAWN_PATROLS = GameRules.registerBoolean("spawn_patrols", GameRuleCategory.SPAWNING, true); public static final GameRule SPAWN_PHANTOMS = GameRules.registerBoolean("spawn_phantoms", GameRuleCategory.SPAWNING, true); public static final GameRule SPAWN_WANDERING_TRADERS = GameRules.registerBoolean("spawn_wandering_traders", GameRuleCategory.SPAWNING, true); public static final GameRule SPAWN_WARDENS = GameRules.registerBoolean("spawn_wardens", GameRuleCategory.SPAWNING, true); public static final GameRule SPECTATORS_GENERATE_CHUNKS = GameRules.registerBoolean("spectators_generate_chunks", GameRuleCategory.PLAYER, true); public static final GameRule SPREAD_VINES = GameRules.registerBoolean("spread_vines", GameRuleCategory.UPDATES, true); public static final GameRule TNT_EXPLODES = GameRules.registerBoolean("tnt_explodes", GameRuleCategory.MISC, true); public static final GameRule TNT_EXPLOSION_DROP_DECAY = GameRules.registerBoolean("tnt_explosion_drop_decay", GameRuleCategory.DROPS, false); public static final GameRule UNIVERSAL_ANGER = GameRules.registerBoolean("universal_anger", GameRuleCategory.MOBS, false); public static final GameRule WATER_SOURCE_CONVERSION = GameRules.registerBoolean("water_source_conversion", GameRuleCategory.UPDATES, true); private final GameRuleMap rules = GameRuleMap.of(BuiltInRegistries.GAME_RULE.stream().filter(gameRule -> gameRule.requiredFeatures().isSubsetOf(enabledFeatures))); public static Codec codec(FeatureFlagSet enabledFeatures) { return GameRuleMap.CODEC.xmap(map -> new GameRules(enabledFeatures, (GameRuleMap)map), gameRules -> gameRules.rules); } public GameRules(FeatureFlagSet enabledFeatures, GameRuleMap map) { this(enabledFeatures); this.rules.setFromIf(map, this.rules::has); } public GameRules(FeatureFlagSet enabledFeatures) { } public Stream> availableRules() { return this.rules.keySet().stream(); } public T get(GameRule gameRule) { T value = this.rules.get(gameRule); if (value == null) { throw new IllegalArgumentException("Tried to access invalid game rule"); } return value; } public void set(GameRule gameRule, T value, @Nullable MinecraftServer server) { if (!this.rules.has(gameRule)) { throw new IllegalArgumentException("Tried to set invalid game rule"); } this.rules.set(gameRule, value); if (server != null) { server.onGameRuleChanged(gameRule, value); } } public GameRules copy(FeatureFlagSet enabledFeatures) { return new GameRules(enabledFeatures, this.rules); } public void setAll(GameRules other, @Nullable MinecraftServer server) { this.setAll(other.rules, server); } public void setAll(GameRuleMap gameRulesMap, @Nullable MinecraftServer server) { gameRulesMap.keySet().forEach(gameRule -> this.setFromOther(gameRulesMap, (GameRule)gameRule, server)); } private void setFromOther(GameRuleMap gameRulesMap, GameRule gameRule, @Nullable MinecraftServer server) { this.set(gameRule, Objects.requireNonNull(gameRulesMap.get(gameRule)), server); } public void visitGameRuleTypes(GameRuleTypeVisitor visitor) { this.rules.keySet().forEach(gameRule -> { visitor.visit(gameRule); gameRule.callVisitor(visitor); }); } private static GameRule registerBoolean(String id, GameRuleCategory category, boolean defaultValue) { return GameRules.register(id, category, GameRuleType.BOOL, BoolArgumentType.bool(), Codec.BOOL, defaultValue, FeatureFlagSet.of(), GameRuleTypeVisitor::visitBoolean, b -> b != false ? 1 : 0); } private static GameRule registerInteger(String id, GameRuleCategory category, int defaultValue, int min) { return GameRules.registerInteger(id, category, defaultValue, min, Integer.MAX_VALUE, FeatureFlagSet.of()); } private static GameRule registerInteger(String id, GameRuleCategory category, int defaultValue, int min, int max) { return GameRules.registerInteger(id, category, defaultValue, min, max, FeatureFlagSet.of()); } private static GameRule registerInteger(String id, GameRuleCategory category, int defaultValue, int min, int max, FeatureFlagSet requiredFeatures) { return GameRules.register(id, category, GameRuleType.INT, IntegerArgumentType.integer((int)min, (int)max), Codec.intRange((int)min, (int)max), defaultValue, requiredFeatures, GameRuleTypeVisitor::visitInteger, i -> i); } private static GameRule register(String id, GameRuleCategory category, GameRuleType typeHint, ArgumentType argumentType, Codec codec, T defaultValue, FeatureFlagSet requiredFeatures, VisitorCaller visitorCaller, ToIntFunction commandResultFunction) { return Registry.register(BuiltInRegistries.GAME_RULE, id, new GameRule(category, typeHint, argumentType, visitorCaller, codec, commandResultFunction, defaultValue, requiredFeatures)); } public static GameRule bootstrap(Registry> registry) { return ADVANCE_TIME; } public String getAsString(GameRule gameRule) { return gameRule.serialize(this.get(gameRule)); } public static interface VisitorCaller { public void call(GameRuleTypeVisitor var1, GameRule var2); } }