/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.brigadier.StringReader * com.mojang.brigadier.arguments.ArgumentType * com.mojang.brigadier.exceptions.CommandSyntaxException * com.mojang.serialization.Codec * com.mojang.serialization.DataResult */ package net.minecraft.world.level.gamerules; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.serialization.Codec; import com.mojang.serialization.DataResult; import java.util.Objects; import java.util.function.ToIntFunction; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.Identifier; import net.minecraft.util.Util; import net.minecraft.world.flag.FeatureFlagSet; import net.minecraft.world.level.gamerules.GameRuleCategory; import net.minecraft.world.level.gamerules.GameRuleType; import net.minecraft.world.level.gamerules.GameRuleTypeVisitor; import net.minecraft.world.level.gamerules.GameRules; public final class GameRule { private final GameRuleCategory category; private final GameRuleType gameRuleType; private final ArgumentType argument; private final GameRules.VisitorCaller visitorCaller; private final Codec valueCodec; private final ToIntFunction commandResultFunction; private final T defaultValue; private final FeatureFlagSet requiredFeatures; public GameRule(GameRuleCategory category, GameRuleType gameRuleType, ArgumentType argument, GameRules.VisitorCaller visitorCaller, Codec valueCodec, ToIntFunction commandResultFunction, T defaultValue, FeatureFlagSet requiredFeatures) { this.category = category; this.gameRuleType = gameRuleType; this.argument = argument; this.visitorCaller = visitorCaller; this.valueCodec = valueCodec; this.commandResultFunction = commandResultFunction; this.defaultValue = defaultValue; this.requiredFeatures = requiredFeatures; } public String toString() { return this.id(); } public String id() { return this.getIdentifier().toShortString(); } public Identifier getIdentifier() { return Objects.requireNonNull(BuiltInRegistries.GAME_RULE.getKey(this)); } public String getDescriptionId() { return Util.makeDescriptionId("gamerule", this.getIdentifier()); } public String serialize(T value) { return value.toString(); } public DataResult deserialize(String value) { try { StringReader reader = new StringReader(value); Object result = this.argument.parse(reader); if (reader.canRead()) { return DataResult.error(() -> "Failed to deserialize; trailing characters", (Object)result); } return DataResult.success((Object)result); } catch (CommandSyntaxException ignored) { return DataResult.error(() -> "Failed to deserialize"); } } public Class valueClass() { return this.defaultValue.getClass(); } public void callVisitor(GameRuleTypeVisitor visitor) { this.visitorCaller.call(visitor, this); } public int getCommandResult(T value) { return this.commandResultFunction.applyAsInt(value); } public GameRuleCategory category() { return this.category; } public GameRuleType gameRuleType() { return this.gameRuleType; } public ArgumentType argument() { return this.argument; } public Codec valueCodec() { return this.valueCodec; } public T defaultValue() { return this.defaultValue; } public FeatureFlagSet requiredFeatures() { return this.requiredFeatures; } }