File tree Expand file tree Collapse file tree 2 files changed +33
-11
lines changed
src/main/java/net/wurstclient/settings Expand file tree Collapse file tree 2 files changed +33
-11
lines changed Original file line number Diff line number Diff line change 2121import com .google .gson .JsonPrimitive ;
2222
2323import net .minecraft .block .Block ;
24+ import net .minecraft .util .Identifier ;
2425import net .wurstclient .WurstClient ;
2526import net .wurstclient .clickgui .Component ;
2627import net .wurstclient .clickgui .components .BlockListEditButton ;
@@ -132,10 +133,27 @@ public void fromJson(JsonElement json)
132133 }
133134
134135 // otherwise, load the blocks in the JSON array
135- JsonUtils .getAsArray (json ).getAllStrings ().parallelStream ()
136- .map (BlockUtils ::getBlockFromNameOrID ).filter (Objects ::nonNull )
137- .map (BlockUtils ::getName ).distinct ().sorted ()
138- .forEachOrdered (s -> blockNames .add (s ));
136+ for (String rawName : JsonUtils .getAsArray (json ).getAllStrings ())
137+ {
138+ Identifier id = Identifier .tryParse (rawName );
139+ if (id == null )
140+ {
141+ System .out .println ("Discarding BlockList entry \" " + rawName
142+ + "\" as it is not a valid identifier" );
143+ continue ;
144+ }
145+
146+ String name = id .toString ();
147+ if (blockNames .contains (name ))
148+ {
149+ System .out .println ("Discarding BlockList entry \" " + rawName
150+ + "\" as \" " + name + "\" is already in the list" );
151+ continue ;
152+ }
153+
154+ blockNames .add (name );
155+ }
156+ blockNames .sort (null );
139157
140158 }catch (JsonException e )
141159 {
Original file line number Diff line number Diff line change 1717
1818import net .minecraft .block .AirBlock ;
1919import net .minecraft .block .Block ;
20+ import net .minecraft .util .Identifier ;
2021import net .wurstclient .WurstClient ;
2122import net .wurstclient .clickgui .Component ;
2223import net .wurstclient .clickgui .components .BlockComponent ;
@@ -116,16 +117,19 @@ public void fromJson(JsonElement json)
116117 {
117118 try
118119 {
119- String newName = JsonUtils .getAsString (json );
120+ String rawName = JsonUtils .getAsString (json );
120121
121- Block newBlock = BlockUtils .getBlockFromNameOrID (newName );
122- if (newBlock == null )
123- throw new JsonException ();
122+ Identifier id = Identifier .tryParse (rawName );
123+ if (id == null )
124+ throw new JsonException ("Discarding Block \" " + rawName
125+ + "\" as it is not a valid identifier" );
124126
125- if (!allowAir && newBlock instanceof AirBlock )
126- throw new JsonException ();
127+ String name = id .toString ();
128+ if (!allowAir && "minecraft:air" .equals (name ))
129+ throw new JsonException ("Discarding Block \" " + rawName
130+ + "\" as this setting does not allow air blocks" );
127131
128- blockName = BlockUtils . getName ( newBlock ) ;
132+ blockName = name ;
129133
130134 }catch (JsonException e )
131135 {
You can’t perform that action at this time.
0 commit comments