Java Code Examples for net.minecraft.util.JsonUtils#getString()

The following examples show how to use net.minecraft.util.JsonUtils#getString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LootTableHelper.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public LootEntry deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject jsonobject = JsonUtils.getJsonObject(json, "loot item");
    String type = JsonUtils.getString(jsonobject, "type");
    if (serializerMap.containsKey(type)) {
        int weight = JsonUtils.getInt(jsonobject, "weight", 1);
        int quality = JsonUtils.getInt(jsonobject, "quality", 0);
        LootCondition[] lootConditions;
        if (jsonobject.has("conditions")) {
            lootConditions = JsonUtils.deserializeClass(jsonobject, "conditions", context, LootCondition[].class);
        } else {
            lootConditions = new LootCondition[0];
        }
        LootTableEntrySerializer serializer = serializerMap.get(type);
        return serializer.deserialize(jsonobject, context, weight, quality, lootConditions);
    }
    return delegatedDeserializer.deserialize(json, typeOfT, context);
}
 
Example 2
Source File: MetaItemShapelessRecipeFactory.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public IRecipe parse(JsonContext context, JsonObject json) {
    String group = JsonUtils.getString(json, "group", "");

    NonNullList<Ingredient> ings = NonNullList.create();
    for (JsonElement ele : JsonUtils.getJsonArray(json, "ingredients"))
        ings.add(CraftingHelper.getIngredient(ele, context));

    if (ings.isEmpty())
        throw new JsonParseException("No ingredients for shapeless recipe");

    JsonObject result = JsonUtils.getJsonObject(json, "result");
    String name = JsonUtils.getString(result, "name");
    int amount = JsonUtils.getInt(result, "amount", 1);
    ItemStack stack = ItemStack.EMPTY;
    for (MetaItem<?> item : MetaItems.ITEMS) {
        MetaItem<?>.MetaValueItem value = item.getItem(name);
        if (value != null) {
            stack = value.getStackForm(amount);
        }
    }
    return new ShapelessOreRecipe(group.isEmpty() ? null : new ResourceLocation(group), ings, stack);
}
 
Example 3
Source File: LootEntryMetaItem.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static LootEntryMetaItem deserialize(JsonObject object, JsonDeserializationContext context, int weight, int quality, LootCondition[] conditions) {
    String entryName = net.minecraftforge.common.ForgeHooks.readLootEntryName(object, "item");
    LootFunction[] lootFunctions;
    if (object.has("functions")) {
        lootFunctions = JsonUtils.deserializeClass(object, "functions", context, LootFunction[].class);
    } else {
        lootFunctions = new LootFunction[0];
    }
    String metaItemName = JsonUtils.getString(object, "name");
    MetaValueItem metaValueItem = getMetaItem(metaItemName);
    if (metaValueItem == null) {
        throw new IllegalArgumentException("Unknown meta item: '" + metaItemName + "'");
    }
    return new LootEntryMetaItem(metaValueItem, weight, quality, lootFunctions, conditions, entryName);
}
 
Example 4
Source File: LootEntryOreDict.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static LootEntryOreDict deserialize(JsonObject object, JsonDeserializationContext context, int weight, int quality, LootCondition[] conditions) {

        String entryName = net.minecraftforge.common.ForgeHooks.readLootEntryName(object, "item");
        LootFunction[] lootFunctions;
        if (object.has("functions")) {
            lootFunctions = JsonUtils.deserializeClass(object, "functions", context, LootFunction[].class);
        } else {
            lootFunctions = new LootFunction[0];
        }
        String oreDictName = JsonUtils.getString(object, "name");
        return new LootEntryOreDict(oreDictName, weight, quality, lootFunctions, conditions, entryName);
    }
 
Example 5
Source File: MetaItemIngredientFactory.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Ingredient parse(JsonContext context, JsonObject json) {
    String name = JsonUtils.getString(json, "name");
    int amount = JsonUtils.getInt(json, "amount", 1);
    for (MetaItem<?> item : MetaItems.ITEMS) {
        MetaItem<?>.MetaValueItem value = item.getItem(name);
        if (value != null) {
            return Ingredient.fromStacks(value.getStackForm(amount));
        }
    }
    return Ingredient.EMPTY;
}
 
Example 6
Source File: DamageableShapelessOreRecipe.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public IRecipe parse(JsonContext context, JsonObject json)
{
    String group = JsonUtils.getString(json, "group", "");

    NonNullList<Ingredient> ings = NonNullList.create();
    for (JsonElement ele : JsonUtils.getJsonArray(json, "ingredients"))
        ings.add(CraftingHelper.getIngredient(ele, context));

    if (ings.isEmpty())
        throw new JsonParseException("No ingredients for shapeless recipe");

    ItemStack itemstack = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context);

    int[] damage = new int[ings.size()];
    if (JsonUtils.hasField(json, "damage"))
    {
        JsonArray array = JsonUtils.getJsonArray(json, "damage");
        if (array.size() > damage.length)
            throw new JsonParseException("Too many values for damage array: got " + array.size() + ", expected " + damage.length);

        for (int i = 0; i < array.size(); i++)
        {
            JsonElement element = array.get(i);
            if (!element.isJsonPrimitive() || !element.getAsJsonPrimitive().isNumber())
                throw new JsonSyntaxException("Entry in damage array is not a number, got " + element);

            damage[i] = element.getAsJsonPrimitive().getAsInt();
        }
    }
    return new DamageableShapelessOreRecipe(group.isEmpty() ? null : new ResourceLocation(group), damage, ings, itemstack);
}
 
Example 7
Source File: IngredientFluidStackFactory.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Nonnull
@Override
public Ingredient parse(JsonContext context, JsonObject json) {
	String name = JsonUtils.getString(json, "fluid");
	int amount = JsonUtils.getInt(json, "amount", 1000);
	Fluid fluid = FluidRegistry.getFluid(name);
	if (fluid == null)
		throw new JsonSyntaxException("Fluid with name " + name + " could not be found");
	return new IngredientFluidStack(fluid, amount);
}
 
Example 8
Source File: RecipeShapelessFluidFactory.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public IRecipe parse(JsonContext context, JsonObject json) {
	String group = JsonUtils.getString(json, "group", "");
	NonNullList<Ingredient> ingredients = NonNullList.create();
	for (JsonElement element : JsonUtils.getJsonArray(json, "ingredients"))
		ingredients.add(CraftingHelper.getIngredient(element, context));

	if (ingredients.isEmpty())
		throw new JsonParseException("No ingredients in shapeless recipe");

	ItemStack result = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context);
	RecipeShapelessFluid recipe = new RecipeShapelessFluid(group.isEmpty() ? null : new ResourceLocation(group), result, ingredients);

	return recipe;
}
 
Example 9
Source File: ModelUpdater.java    From OpenModsLib with MIT License 5 votes vote down vote up
public static <T extends Enum<T>> ValueConverter<T> enumConverter(Class<T> enumCls) {
	final ImmutableMap.Builder<String, T> valuesBuilder = ImmutableMap.builder();
	for (T c : enumCls.getEnumConstants())
		valuesBuilder.put(c.name().toLowerCase(Locale.ROOT), c);

	final ImmutableMap<String, T> values = valuesBuilder.build();

	return (name, element) -> {
		final String enumName = JsonUtils.getString(element, name);
		return values.get(enumName.toLowerCase(Locale.ROOT));
	};
}
 
Example 10
Source File: EnchantingRecipe.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public BooleanSupplier parse(JsonContext context, JsonObject json) {
	final String enchId = JsonUtils.getString(json, "id");
	return () -> Enchantment.REGISTRY.containsKey(new ResourceLocation(enchId));
}