/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.serialization.Codec * it.unimi.dsi.fastutil.objects.Reference2ObjectMap * it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap * org.jspecify.annotations.Nullable */ package net.minecraft.world.level.gamerules; import com.mojang.serialization.Codec; import it.unimi.dsi.fastutil.objects.Reference2ObjectMap; import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap; import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.function.Predicate; import java.util.stream.Stream; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.level.gamerules.GameRule; import org.jspecify.annotations.Nullable; public final class GameRuleMap { public static final Codec CODEC = Codec.dispatchedMap(BuiltInRegistries.GAME_RULE.byNameCodec(), GameRule::valueCodec).xmap(GameRuleMap::ofTrusted, GameRuleMap::map); private final Reference2ObjectMap, Object> map; private GameRuleMap(Reference2ObjectMap, Object> map) { this.map = map; } private static GameRuleMap ofTrusted(Map, Object> map) { return new GameRuleMap((Reference2ObjectMap, Object>)new Reference2ObjectOpenHashMap(map)); } public static GameRuleMap of() { return new GameRuleMap((Reference2ObjectMap, Object>)new Reference2ObjectOpenHashMap()); } public static GameRuleMap of(Stream> gameRuleTypeStream) { Reference2ObjectOpenHashMap map = new Reference2ObjectOpenHashMap(); gameRuleTypeStream.forEach(gameRule -> map.put(gameRule, gameRule.defaultValue())); return new GameRuleMap((Reference2ObjectMap, Object>)map); } public static GameRuleMap copyOf(GameRuleMap gameRuleMap) { return new GameRuleMap((Reference2ObjectMap, Object>)new Reference2ObjectOpenHashMap(gameRuleMap.map)); } public boolean has(GameRule gameRule) { return this.map.containsKey(gameRule); } public @Nullable T get(GameRule gameRule) { return (T)this.map.get(gameRule); } public void set(GameRule gameRule, T value) { this.map.put(gameRule, value); } public @Nullable T remove(GameRule gameRule) { return (T)this.map.remove(gameRule); } public Set> keySet() { return this.map.keySet(); } public int size() { return this.map.size(); } public String toString() { return this.map.toString(); } public GameRuleMap withOther(GameRuleMap other) { GameRuleMap result = GameRuleMap.copyOf(this); result.setFromIf(other, r -> true); return result; } public void setFromIf(GameRuleMap other, Predicate> predicate) { for (GameRule gameRule : other.keySet()) { if (!predicate.test(gameRule)) continue; GameRuleMap.setGameRule(other, gameRule, this); } } private static void setGameRule(GameRuleMap other, GameRule gameRule, GameRuleMap result) { result.set(gameRule, Objects.requireNonNull(other.get(gameRule))); } private Reference2ObjectMap, Object> map() { return this.map; } public boolean equals(Object obj) { if (obj == this) { return true; } if (obj == null || obj.getClass() != this.getClass()) { return false; } GameRuleMap that = (GameRuleMap)obj; return Objects.equals(this.map, that.map); } public int hashCode() { return Objects.hash(this.map); } public static class Builder { final Reference2ObjectMap, Object> map = new Reference2ObjectOpenHashMap(); public Builder set(GameRule gameRule, T value) { this.map.put(gameRule, value); return this; } public GameRuleMap build() { return new GameRuleMap(this.map); } } }