Skip to content

Commit 18a3460

Browse files
Fix Block/BlockList validation of modded blocks
Fixes https://wurstforum.net/d/1289
1 parent b6c176b commit 18a3460

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

src/main/java/net/wurstclient/settings/BlockListSetting.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.google.gson.JsonPrimitive;
2222

2323
import net.minecraft.block.Block;
24+
import net.minecraft.util.Identifier;
2425
import net.wurstclient.WurstClient;
2526
import net.wurstclient.clickgui.Component;
2627
import 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
{

src/main/java/net/wurstclient/settings/BlockSetting.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import net.minecraft.block.AirBlock;
1919
import net.minecraft.block.Block;
20+
import net.minecraft.util.Identifier;
2021
import net.wurstclient.WurstClient;
2122
import net.wurstclient.clickgui.Component;
2223
import 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
{

0 commit comments

Comments
 (0)