GameRules .java

net.minecraft.world.GameRules (class): members: setOrCreateGameRule, addGameRule, areSameType, ValueType, getRules, hasRule, Value, theGameRules, getInt.

net.minecraft.worldclass191 linescommon5.6 KB

API Surface (15)

void addGameRule(String key, String value, GameRules.ValueType type)
void setOrCreateGameRule(String key, String ruleValue)
String getString(String name)
boolean getBoolean(String name)
int getInt(String name)
NBTTagCompound writeToNBT()
void readFromNBT(NBTTagCompound nbt)
String[] getRules()
boolean hasRule(String name)
boolean areSameType(String key, GameRules.ValueType otherValue)
void setValue(String value)
String getString()
boolean getBoolean()
int getInt()
GameRules.ValueType getType()

Fields & Constants (1)

theGameRules

String literals (15)

"doFireTick"
"mobGriefing"
"keepInventory"
"doMobSpawning"
"doMobLoot"
"doTileDrops"
"doEntityDrops"
"commandBlockOutput"
"naturalRegeneration"
"doDaylightCycle"
"logAdminCommands"
"showDeathMessages"
"randomTickSpeed"
"sendCommandFeedback"
"reducedDebugInfo"

Code Graph: Dependencies (1)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

GameRules.java191 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.world;
2
3
import java.util.Set;
4
import java.util.TreeMap;
5
import net.minecraft.nbt.NBTTagCompound;
6
7
public class GameRules
8
{
9
    private TreeMap<String, GameRules.Value> theGameRules = new TreeMap();
10
11
    public GameRules()
12
    {
13
        this.addGameRule("doFireTick", "true", GameRules.ValueType.BOOLEAN_VALUE);
14
        this.addGameRule("mobGriefing", "true", GameRules.ValueType.BOOLEAN_VALUE);
15
        this.addGameRule("keepInventory", "false", GameRules.ValueType.BOOLEAN_VALUE);
16
        this.addGameRule("doMobSpawning", "true", GameRules.ValueType.BOOLEAN_VALUE);
17
        this.addGameRule("doMobLoot", "true", GameRules.ValueType.BOOLEAN_VALUE);
18
        this.addGameRule("doTileDrops", "true", GameRules.ValueType.BOOLEAN_VALUE);
19
        this.addGameRule("doEntityDrops", "true", GameRules.ValueType.BOOLEAN_VALUE);
20
        this.addGameRule("commandBlockOutput", "true", GameRules.ValueType.BOOLEAN_VALUE);
21
        this.addGameRule("naturalRegeneration", "true", GameRules.ValueType.BOOLEAN_VALUE);
22
        this.addGameRule("doDaylightCycle", "true", GameRules.ValueType.BOOLEAN_VALUE);
23
        this.addGameRule("logAdminCommands", "true", GameRules.ValueType.BOOLEAN_VALUE);
24
        this.addGameRule("showDeathMessages", "true", GameRules.ValueType.BOOLEAN_VALUE);
25
        this.addGameRule("randomTickSpeed", "3", GameRules.ValueType.NUMERICAL_VALUE);
26
        this.addGameRule("sendCommandFeedback", "true", GameRules.ValueType.BOOLEAN_VALUE);
27
        this.addGameRule("reducedDebugInfo", "false", GameRules.ValueType.BOOLEAN_VALUE);
28
    }
29
30
    public void addGameRule(String key, String value, GameRules.ValueType type)
31
    {
32
        this.theGameRules.put(key, new GameRules.Value(value, type));
33
    }
34
35
    public void setOrCreateGameRule(String key, String ruleValue)
36
    {
37
        GameRules.Value gamerules$value = (GameRules.Value)this.theGameRules.get(key);
38
39
        if (gamerules$value != null)
40
        {
41
            gamerules$value.setValue(ruleValue);
42
        }
43
        else
44
        {
45
            this.addGameRule(key, ruleValue, GameRules.ValueType.ANY_VALUE);
46
        }
47
    }
48
49
    /**
50
     * Gets the string Game Rule value.
51
     */
52
    public String getString(String name)
53
    {
54
        GameRules.Value gamerules$value = (GameRules.Value)this.theGameRules.get(name);
55
        return gamerules$value != null ? gamerules$value.getString() : "";
56
    }
57
58
    /**
59
     * Gets the boolean Game Rule value.
60
     */
61
    public boolean getBoolean(String name)
62
    {
63
        GameRules.Value gamerules$value = (GameRules.Value)this.theGameRules.get(name);
64
        return gamerules$value != null ? gamerules$value.getBoolean() : false;
65
    }
66
67
    public int getInt(String name)
68
    {
69
        GameRules.Value gamerules$value = (GameRules.Value)this.theGameRules.get(name);
70
        return gamerules$value != null ? gamerules$value.getInt() : 0;
71
    }
72
73
    /**
74
     * Return the defined game rules as NBT.
75
     */
76
    public NBTTagCompound writeToNBT()
77
    {
78
        NBTTagCompound nbttagcompound = new NBTTagCompound();
79
80
        for (String s : this.theGameRules.keySet())
81
        {
82
            GameRules.Value gamerules$value = (GameRules.Value)this.theGameRules.get(s);
83
            nbttagcompound.setString(s, gamerules$value.getString());
84
        }
85
86
        return nbttagcompound;
87
    }
88
89
    /**
90
     * Set defined game rules from NBT.
91
     */
92
    public void readFromNBT(NBTTagCompound nbt)
93
    {
94
        for (String s : nbt.getKeySet())
95
        {
96
            String s1 = nbt.getString(s);
97
            this.setOrCreateGameRule(s, s1);
98
        }
99
    }
100
101
    /**
102
     * Return the defined game rules.
103
     */
104
    public String[] getRules()
105
    {
106
        Set<String> set = this.theGameRules.keySet();
107
        return (String[])set.toArray(new String[set.size()]);
108
    }
109
110
    /**
111
     * Return whether the specified game rule is defined.
112
     */
113
    public boolean hasRule(String name)
114
    {
115
        return this.theGameRules.containsKey(name);
116
    }
117
118
    public boolean areSameType(String key, GameRules.ValueType otherValue)
119
    {
120
        GameRules.Value gamerules$value = (GameRules.Value)this.theGameRules.get(key);
121
        return gamerules$value != null && (gamerules$value.getType() == otherValue || otherValue == GameRules.ValueType.ANY_VALUE);
122
    }
123
124
    static class Value
125
    {
126
        private String valueString;
127
        private boolean valueBoolean;
128
        private int valueInteger;
129
        private double valueDouble;
130
        private final GameRules.ValueType type;
131
132
        public Value(String value, GameRules.ValueType type)
133
        {
134
            this.type = type;
135
            this.setValue(value);
136
        }
137
138
        public void setValue(String value)
139
        {
140
            this.valueString = value;
141
            this.valueBoolean = Boolean.parseBoolean(value);
142
            this.valueInteger = this.valueBoolean ? 1 : 0;
143
144
            try
145
            {
146
                this.valueInteger = Integer.parseInt(value);
147
            }
148
            catch (NumberFormatException var4)
149
            {
150
                ;
151
            }
152
153
            try
154
            {
155
                this.valueDouble = Double.parseDouble(value);
156
            }
157
            catch (NumberFormatException var3)
158
            {
159
                ;
160
            }
161
        }
162
163
        public String getString()
164
        {
165
            return this.valueString;
166
        }
167
168
        public boolean getBoolean()
169
        {
170
            return this.valueBoolean;
171
        }
172
173
        public int getInt()
174
        {
175
            return this.valueInteger;
176
        }
177
178
        public GameRules.ValueType getType()
179
        {
180
            return this.type;
181
        }
182
    }
183
184
    public static enum ValueType
185
    {
186
        ANY_VALUE,
187
        BOOLEAN_VALUE,
188
        NUMERICAL_VALUE;
189
    }
190
}
191

Deobfuscated MCP 1.8.9 source of GameRules from Marcelektro/MavenMCP-1.8.9 (net/minecraft/world/GameRules.java), stored verbatim.