use of net.minecraft.commands.arguments.blocks.BlockStateParser in project fabric-carpet by gnembon.
the class BlockValue method fromString.
public static BlockValue fromString(String str) {
try {
BlockValue bv = bvCache.get(str);
if (bv != null)
return bv;
BlockStateParser blockstateparser = (new BlockStateParser(new StringReader(str), false)).parse(true);
if (blockstateparser.getState() != null) {
CompoundTag bd = blockstateparser.getNbt();
if (bd == null)
bd = new CompoundTag();
bv = new BlockValue(blockstateparser.getState(), null, null, bd);
if (bvCache.size() > 10000)
bvCache.clear();
bvCache.put(str, bv);
return bv;
}
} catch (CommandSyntaxException ignored) {
}
throw new ThrowStatement(str, Throwables.UNKNOWN_BLOCK);
}
use of net.minecraft.commands.arguments.blocks.BlockStateParser in project RoyalGrenadier by BotulToxin.
the class BlockArgumentImpl method listSuggestions.
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder, boolean allowTag) {
StringReader reader = new StringReader(builder.getInput());
reader.setCursor(builder.getStart());
BlockStateParser parser = new BlockStateParser(reader, allowTag);
try {
parser.parse(true);
} catch (CommandSyntaxException ignored) {
}
return parser.fillSuggestions(builder, Registry.BLOCK);
}
use of net.minecraft.commands.arguments.blocks.BlockStateParser in project Patchouli by VazkiiMods.
the class StringStateMatcher method fromString.
public static IStateMatcher fromString(String s) throws CommandSyntaxException {
s = s.trim();
if (s.equals("ANY")) {
return StateMatcher.ANY;
}
if (s.equals("AIR")) {
return StateMatcher.AIR;
}
// c.f. BlockPredicateArgumentType. Similar, but doesn't use vanilla's weird caching class.
BlockStateParser parser = new BlockStateParser(new StringReader(s), true).parse(false);
BlockState state = parser.getState();
if (state != null) {
return new ExactMatcher(state, parser.getProperties());
} else {
return new TagMatcher(parser.getTag(), parser.getVagueProperties());
}
}
use of net.minecraft.commands.arguments.blocks.BlockStateParser in project Mohist by MohistMC.
the class CraftBlockData method newData.
public static CraftBlockData newData(Material material, String data) {
Preconditions.checkArgument(material == null || material.isBlock(), "Cannot get data for not block %s", material);
BlockState blockData;
Block block = CraftMagicNumbers.getBlock(material);
Map<net.minecraft.world.level.block.state.properties.Property<?>, Comparable<?>> parsed = null;
// Data provided, use it
if (data != null) {
try {
// Material provided, force that material in
if (block != null) {
data = net.minecraft.core.Registry.BLOCK.getKey(block) + data;
}
StringReader reader = new StringReader(data);
BlockStateParser arg = new BlockStateParser(reader, false).parse(false);
Preconditions.checkArgument(!reader.canRead(), "Spurious trailing data: " + data);
blockData = arg.getState();
parsed = arg.getProperties();
} catch (CommandSyntaxException ex) {
throw new IllegalArgumentException("Could not parse data: " + data, ex);
}
} else {
blockData = block.defaultBlockState();
}
CraftBlockData craft = fromData(blockData);
craft.parsedStates = parsed;
return craft;
}
Aggregations