use of net.minecraft.nbt.StringNbtReader in project nbt-crafting by Siphalor.
the class MixinIngredient method loadIngredientEntryCondition.
@Unique
private static IngredientEntryCondition loadIngredientEntryCondition(JsonObject jsonObject) {
if (jsonObject.has("data")) {
if (JsonHelper.hasString(jsonObject, "data")) {
try {
CompoundTag compoundTag = new StringNbtReader(new StringReader(jsonObject.get("data").getAsString())).parseCompoundTag();
IngredientEntryCondition condition = new IngredientEntryCondition();
if (compoundTag.contains("require") || compoundTag.contains("deny")) {
if (compoundTag.contains("require"))
condition.requiredElements = compoundTag.getCompound("require");
if (compoundTag.contains("deny"))
condition.deniedElements = compoundTag.getCompound("deny");
} else {
condition.requiredElements = compoundTag;
}
return condition;
} catch (CommandSyntaxException e) {
e.printStackTrace();
}
} else if (jsonObject.get("data").isJsonObject()) {
return IngredientEntryCondition.fromJson((JsonObject) JsonPreprocessor.process(jsonObject.get("data").getAsJsonObject()));
}
}
return new IngredientEntryCondition();
}
use of net.minecraft.nbt.StringNbtReader in project numismatic-overhaul by wisp-forest.
the class VillagerJsonHelper method getItemStackFromJson.
public static ItemStack getItemStackFromJson(JsonObject json) {
if (!json.has("item"))
throw new DeserializationException("ItemStack missing item ID " + json);
Item item = getItemFromID(json.get("item").getAsString());
int count = json.has("count") ? json.get("count").getAsInt() : 1;
ItemStack stack = new ItemStack(item, count);
if (json.has("tag")) {
String toParse = json.get("tag").getAsJsonObject().toString();
CompoundTag stackTag = null;
try {
stackTag = new StringNbtReader(new StringReader(toParse)).parseCompoundTag();
} catch (CommandSyntaxException e) {
VillagerTradesHandler.addLoadingException(new DeserializationException("Tag parsing error: " + e.getMessage()));
}
if (stackTag != null)
stack.setTag(stackTag);
}
return stack;
}
use of net.minecraft.nbt.StringNbtReader in project Pehkui by Virtuoel.
the class PehkuiEntitySelectorOptions method register.
public static void register() {
EntitySelectorOptionsInvoker.callPutOption(Pehkui.id("scale").toString().replace(':', '.'), r -> cast(r).pehkui_setScaleRange(FloatRange.parse(r.getReader())), r -> cast(r).pehkui_getScaleRange().isDummy(), SCALE_RANGE_DESCRIPTION);
EntitySelectorOptionsInvoker.callPutOption(Pehkui.id("scale_type").toString().replace(':', '.'), r -> cast(r).pehkui_setScaleType(parseScaleType(r)), r -> cast(r).pehkui_getScaleType() == ScaleTypes.INVALID, SCALE_TYPE_DESCRIPTION);
EntitySelectorOptionsInvoker.callPutOption(Pehkui.id("computed_scale").toString().replace(':', '.'), r -> cast(r).pehkui_setComputedScaleRange(FloatRange.parse(r.getReader())), r -> cast(r).pehkui_getComputedScaleRange().isDummy(), SCALE_RANGE_DESCRIPTION);
EntitySelectorOptionsInvoker.callPutOption(Pehkui.id("computed_scale_type").toString().replace(':', '.'), r -> cast(r).pehkui_setComputedScaleType(parseScaleType(r)), r -> cast(r).pehkui_getComputedScaleType() == ScaleTypes.INVALID, SCALE_TYPE_DESCRIPTION);
EntitySelectorOptionsInvoker.callPutOption(Pehkui.id("scale_nbt").toString().replace(':', '.'), r -> {
final boolean negated = r.readNegationCharacter();
final NbtCompound parsed = (new StringNbtReader(r.getReader())).parseCompound();
r.setPredicate(entity -> {
final NbtCompound nbt = ((PehkuiEntityExtensions) entity).pehkui_writeScaleNbt(new NbtCompound());
return NbtHelper.matches(parsed, nbt, true) != negated;
});
}, reader -> true, SCALE_NBT_DESCRIPTION);
}
Aggregations