org.bukkit.advancement.Advancement#net.minecraft.util.JsonUtils源码实例Demo

下面列出了org.bukkit.advancement.Advancement#net.minecraft.util.JsonUtils 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: GregTech   文件: LootTableHelper.java
@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);
}
 
源代码2 项目: GregTech   文件: MetaItemShapelessRecipeFactory.java
@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);
}
 
源代码3 项目: GregTech   文件: LootEntryMetaItem.java
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);
}
 
源代码4 项目: GregTech   文件: LootEntryOreDict.java
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);
    }
 
源代码5 项目: GregTech   文件: MetaItemIngredientFactory.java
@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;
}
 
源代码6 项目: Kettle   文件: CraftMagicNumbers.java
@Override
public Advancement loadAdvancement(NamespacedKey key, String advancement) {
    if (Bukkit.getAdvancement(key) != null) {
        throw new IllegalArgumentException("Advancement " + key + " already exists.");
    }

    net.minecraft.advancements.Advancement.Builder nms = JsonUtils.gsonDeserialize(AdvancementManager.GSON, advancement, net.minecraft.advancements.Advancement.Builder.class);
    if (nms != null) {
        AdvancementManager.ADVANCEMENT_LIST.loadAdvancements(Maps.newHashMap(Collections.singletonMap(CraftNamespacedKey.toMinecraft(key), nms)));
        Advancement bukkit = Bukkit.getAdvancement(key);

        if (bukkit != null) {
            File file = new File(MinecraftServer.getServerCB().getAdvancementManager().advancementsDir, key.getNamespace() + File.separator + key.getKey() + ".json");
            file.getParentFile().mkdirs();

            try {
                Files.write(advancement, file, Charsets.UTF_8);
            } catch (IOException ex) {
                Bukkit.getLogger().log(Level.SEVERE, "Error saving advancement " + key, ex);
            }

            MinecraftServer.getServerCB().getPlayerList().reloadResources();

            return bukkit;
        }
    }

    return null;
}
 
@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);
}
 
源代码8 项目: Wizardry   文件: IngredientFluidStackFactory.java
@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);
}
 
源代码9 项目: Wizardry   文件: RecipeShapelessFluidFactory.java
@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;
}
 
源代码10 项目: AgriCraft   文件: CustomWoodShapedRecipe.java
@Override
public IRecipe parse(JsonContext context, JsonObject json) {
    ShapedOreRecipe fake = ShapedOreRecipe.factory(context, json);
    CraftingHelper.ShapedPrimer primer = new CraftingHelper.ShapedPrimer();
    primer.width = fake.getRecipeWidth();
    primer.height = fake.getRecipeHeight();
    primer.input = fake.getIngredients();
    primer.mirrored = JsonUtils.getBoolean(json, "mirrored", true); // Hack
    return new CustomWoodShapedRecipe(fake.getRegistryName(), fake.getRecipeOutput(), primer);
}
 
源代码11 项目: OpenModsLib   文件: ModelUpdater.java
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));
	};
}
 
源代码12 项目: OpenModsLib   文件: VariantSelectorData.java
private static Set<ResourceLocation> parseModels(String name, JsonElement value) {
	if (value.isJsonArray()) {
		return parseArrayOfLocations(name, value);
	} else if (value.isJsonPrimitive()) { return parseSingleLocation(value); }

	throw new JsonSyntaxException("Expected " + name + " to be a string, was " + JsonUtils.toString(value));
}
 
源代码13 项目: OpenModsLib   文件: VariantSelectorData.java
private static Set<ResourceLocation> parseArrayOfLocations(String name, JsonElement value) {
	final ImmutableSet.Builder<ResourceLocation> result = ImmutableSet.builder();

	for (JsonElement e : value.getAsJsonArray()) {
		if (e.isJsonPrimitive()) {
			final ResourceLocation loc = new ModelResourceLocation(value.getAsString());
			result.add(loc);
		} else {
			throw new JsonSyntaxException("Expected elements of " + name + " to be a string, was " + JsonUtils.toString(e));
		}
	}

	return result.build();
}
 
源代码14 项目: GregTech   文件: SurfaceBlockPopulator.java
@Override
public void loadFromConfig(JsonObject object) {
    this.blockState = PredicateConfigUtils.parseBlockStateDefinition(object.getAsJsonObject("block"));
    this.minIndicatorAmount = JsonUtils.getInt(object, "min_amount", 0);
    this.maxIndicatorAmount = JsonUtils.getInt(object, "max_amount", 2);
}
 
源代码15 项目: GokiStats   文件: LevelCondition.java
@Nonnull
@Override
public LevelCondition deserialize(JsonObject json, JsonDeserializationContext context) {
    return new LevelCondition(JsonUtils.getInt(json, "minLevel"));
}
 
源代码16 项目: OpenModsLib   文件: EnchantingRecipe.java
@Override
public BooleanSupplier parse(JsonContext context, JsonObject json) {
	final String enchId = JsonUtils.getString(json, "id");
	return () -> Enchantment.REGISTRY.containsKey(new ResourceLocation(enchId));
}