public static ItemStack getResult( JsonObject json, JsonContext context, String name ) { JsonObject resultObject = JsonUtils.getJsonObject( json, name ); if( resultObject.has( "part" ) ) { return getPart( resultObject ); } else if( resultObject.has( "item" ) ) { return CraftingHelper.getItemStack( resultObject, context ); } else { throw new JsonSyntaxException( "Result has no 'part' or 'item' property." ); } }
for( Map.Entry<String, JsonElement> entry : JsonUtils.getJsonObject( json, "key" ).entrySet() )
String mode = JsonUtils.getString( json, "mode" ); JsonObject ingredients = JsonUtils.getJsonObject( json, "ingredients" ); if( ingredients.has( "top" ) ) top = CraftingHelper.getIngredient( JsonUtils.getJsonObject( ingredients, "top" ), ctx ).getMatchingStacks(); if( ingredients.has( "bottom" ) ) bottom = CraftingHelper.getIngredient( JsonUtils.getJsonObject( ingredients, "bottom" ), ctx ).getMatchingStacks();
@Override public void register( JsonObject json, JsonContext ctx ) { // TODO only primary for now JsonObject result = JsonUtils.getJsonObject( json, "result" ); ItemStack primary = PartRecipeFactory.getResult( result, ctx, "primary" ); ItemStack[] input = CraftingHelper.getIngredient( json.get( "input" ), ctx ).getMatchingStacks(); int turns = 5; if( json.has( "turns" ) ) { turns = JsonUtils.getInt( json, "turns" ); } final IGrinderRegistry reg = AEApi.instance().registries().grinder(); for( int i = 0; i < input.length; ++i ) { final IGrinderRecipeBuilder builder = reg.builder(); builder.withOutput( primary ); builder.withInput( input[i] ); builder.withTurns( turns ); reg.addRecipe( builder.build() ); } } }
public static <K, V> Map<K, V> mapFromObjectArray(JsonArray jsonArray, String keyName, String valueName, Function<JsonElement, K> parseKey, Function<JsonElement, V> parseValue) { Map<K, V> ret = new HashMap<>(); for (JsonElement element : jsonArray) { JsonObject entry = JsonUtils.getJsonObject(element, ""); ret.put(parseKey.apply(entry.get(keyName)), parseValue.apply(entry.get(valueName))); } return ret; }
private static Tuple<String, Map<String, String>> getBlockNameAndProperties(JsonObject stateJson) { Map<String, String> properties = new HashMap<>(); if (JsonUtils.hasField(stateJson, "properties")) { JsonUtils.getJsonObject(stateJson, "properties").entrySet().forEach(p -> properties.put(p.getKey(), p.getValue().getAsString())); } return new Tuple<>(JsonUtils.getString(stateJson, "name"), properties); }
public static PropertyState getPropertyState(IBlockState state, JsonObject parent, String elementName) { JsonObject jsonProperty = JsonUtils.getJsonObject(parent, elementName); if (jsonProperty.entrySet().isEmpty()) { throw new JsonParseException("Expected at least one property defined for " + elementName + " in " + parent.toString()); } Entry<String, JsonElement> propJson = jsonProperty.entrySet().iterator().next(); String propName = propJson.getKey(); String propValue = propJson.getValue().getAsString(); return BlockTools.getPropertyState(state.getBlock(), state.getBlock().getBlockState(), propName, propValue); }
@Override public void parse(JsonObject json) { JsonArray plantables = JsonUtils.getJsonArray(json, "soils"); for (JsonElement t : plantables) { soilBlocks.add(JsonHelper.getBlockStateMatcher(JsonUtils.getJsonObject(t, ""))); } } }
@Override public void parse(JsonObject json) { JsonArray saplings = JsonUtils.getJsonArray(json, "saplings"); for (JsonElement e : saplings) { JsonObject saplingDefinition = JsonUtils.getJsonObject(e, ""); TreeFarmRegistry.saplings.add(new Sapling(JsonHelper.getItemStackMatcher(JsonUtils.getJsonObject(saplingDefinition, "sapling")), saplingDefinition.has("right_click") && JsonUtils.getBoolean(saplingDefinition, "right_click"))); } } }
@Override public void parse(JsonObject json) { JsonArray soils = JsonUtils.getJsonArray(json, "soils"); for (JsonElement t : soils) { soilBlocks.add(JsonHelper.getBlockStateMatcher(JsonUtils.getJsonObject(t, ""))); } } }
private Map<String, FactionTradeListTemplate> parseTradeLists(JsonArray tradeLists) { Map<String, FactionTradeListTemplate> ret = new HashMap<>(); for (JsonElement tradeListElement : tradeLists) { JsonObject tradeList = JsonUtils.getJsonObject(tradeListElement, "trade_list"); String name = JsonUtils.getString(tradeList, "name"); JsonArray tradesArray = JsonUtils.getJsonArray(tradeList, "trades"); List<FactionTradeTemplate> trades = parseTrades(tradesArray); ret.put(name, new FactionTradeListTemplate(name, trades)); } return ret; }
@Override public void parse(JsonObject json) { JsonArray tillables = JsonUtils.getJsonArray(json, "tillable_mapping"); for (JsonElement t : tillables) { JsonObject tillableMapping = JsonUtils.getJsonObject(t, ""); BlockStateMatcher tillableState = JsonHelper.getBlockStateMatcher(tillableMapping, "tillable"); IBlockState tilledState = JsonHelper.getBlockState(tillableMapping, "tilled"); tillableBlocks.put(tillableState, tilledState); soilBlocks.add(JsonHelper.getBlockStateMatcher(tillableMapping, "tilled")); } } }
@Override public void parse(JsonObject json) { JsonArray treeScanners = JsonUtils.getJsonArray(json, "tree_scanners"); for (JsonElement ts : treeScanners) { JsonObject treeScanner = JsonUtils.getJsonObject(ts, ""); switch (JsonUtils.getString(treeScanner, "type")) { case "default": default: DefaultSearchParser.parse(treeScanner); } } }
@Override public BookCategory deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { JsonObject object = json.getAsJsonObject(); String name = JsonUtils.getString(object, "name"); ItemStack stack = JsonUtil.deserializeItemStack(JsonUtils.getJsonObject(object, "icon"), ItemStack.EMPTY); BookCategory category = new BookCategory(name); category.setStack(stack); return category; } }
public static TableOfContentsElement parse(JsonObject elementJson) { JsonArray contents = JsonUtils.getJsonArray(elementJson, "items"); ArrayList<TableOfContentsItem> tocItems = new ArrayList<>(); for (JsonElement e : contents) { JsonObject contentItem = JsonUtils.getJsonObject(e, ""); tocItems.add(new TableOfContentsItem(JsonUtils.getString(contentItem, "text"), JsonUtils.getString(contentItem, "category_link"))); } return new TableOfContentsElement(tocItems); }
private FactionNpcDefault parseDefaults(JsonObject json) { JsonObject defaults = JsonUtils.getJsonObject(json, "defaults"); return new FactionNpcDefault(getAttributes(defaults), getExperienceDrop(defaults).orElse(0), getCanSwim(defaults).orElse(true), getCanBreakDoors(defaults).orElse(true), getEquipment(defaults), getAdditionalAttributes(defaults), getEnabled(defaults).orElse(true)); }
private OwnedNpcDefault parseDefaults(JsonObject json) { JsonObject defaults = JsonUtils.getJsonObject(json, "defaults"); return new OwnedNpcDefault(getTargetList(defaults), getAttributes(defaults), getExperienceDrop(defaults).orElse(0), getCanSwim(defaults).orElse(true), getCanBreakDoors(defaults).orElse(true), getEquipment(defaults)); }
private List<FactionTradeTemplate> parseTrades(JsonArray trades) { List<FactionTradeTemplate> ret = new ArrayList<>(); for (JsonElement tradeElement : trades) { JsonObject trade = JsonUtils.getJsonObject(tradeElement, "trade"); int refillFrequency = JsonUtils.getInt(trade, "refill_frequency"); int maxTrades = JsonUtils.getInt(trade, "max_trades"); List<ItemStack> input = JsonHelper.getItemStacks(JsonUtils.getJsonArray(trade, "input")); List<ItemStack> output = JsonHelper.getItemStacks(JsonUtils.getJsonArray(trade, "output")); ret.add(new FactionTradeTemplate(input, output, refillFrequency, maxTrades)); } return ret; } }
@Override public IRecipe parse(final JsonContext context, final JsonObject json) { final String group = JsonUtils.getString(json, "group", ""); final CraftingHelper.ShapedPrimer primer = parseShaped(context, json); final ItemStack result = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context); return new ConstructionPasteRecipeHandler(group.isEmpty() ? null : new ResourceLocation(group), result, primer); }
@Override public IRecipe parse(final JsonContext context, final JsonObject json) { final String group = JsonUtils.getString(json, "group", ""); final NonNullList<Ingredient> ingredients = RecipeUtil.parseShapeless(context, json); final ItemStack result = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context); return new RecipeCuttingShapeless(group.isEmpty() ? null : new ResourceLocation(group), ingredients, result); } }