private String parseTexture( JsonObject object ) { return JsonUtils.getString( object, "texture" ); }
@Nullable private EnumFacing parseCullFace( JsonObject object ) { String s = JsonUtils.getString( object, "cullface", "" ); return EnumFacing.byName( s ); }
public static ItemPredicate deserialize( JsonObject jsonobject ) { if( jsonobject.has( "part" ) ) { return new PartItemPredicate( JsonUtils.getString( jsonobject, "part" ) ); } else { return ItemPredicate.ANY; } }
@Override public IRecipe parse( JsonContext context, JsonObject json ) { String type = JsonUtils.getString( json, "type" ); if( type.contains( "shaped" ) ) { return shapedFactory( context, json ); } else if( type.contains( "shapeless" ) ) { return shapelessFactory( context, json ); } else { throw new JsonSyntaxException( "Applied Energistics 2 was given a custom recipe that it does not know how to handle!\n" + "Type should either be '" + AppEng.MOD_ID + ":shapeless' or '" + AppEng.MOD_ID + ":shaped', got '" + type + "'!" ); } }
private static ShapedOreRecipe shapedFactory( JsonContext context, JsonObject json ) String group = JsonUtils.getString( json, "group", "" ); for( int x = 0; x < pattern.length; ++x ) String line = JsonUtils.getString( patternJ.get( x ), "pattern[" + x + "]" ); if( x > 0 && pattern[0].length() != line.length() )
private void register( JsonObject json ) { if( json == null || json.isJsonNull() ) { throw new JsonSyntaxException( "Json cannot be null" ); } String type = this.ctx.appendModId( JsonUtils.getString( json, "type" ) ); if( type.isEmpty() ) { throw new JsonSyntaxException( "Recipe type can not be an empty string" ); } IAERecipeFactory factory = this.factories.get( new ResourceLocation( type ) ); if( factory == null ) { throw new JsonSyntaxException( "Unknown recipe type: " + type ); } factory.register( json, this.ctx ); }
@Override public BooleanSupplier parse( JsonContext jsonContext, JsonObject jsonObject ) { final boolean result; if( JsonUtils.isString( jsonObject, JSON_MATERIAL_KEY ) ) { final String material = JsonUtils.getString( jsonObject, JSON_MATERIAL_KEY ); final Object item = Api.INSTANCE.registries().recipes().resolveItem( AppEng.MOD_ID, material ); result = item != null; } else { result = false; } return () -> result; } }
@Override public BooleanSupplier parse( JsonContext jsonContext, JsonObject jsonObject ) { final boolean result; if( JsonUtils.isJsonArray( jsonObject, JSON_FEATURES_KEY ) ) { final JsonArray features = JsonUtils.getJsonArray( jsonObject, JSON_FEATURES_KEY ); result = Stream.of( features ) .allMatch( p -> AEConfig.instance().isFeatureEnabled( AEFeature.valueOf( p.getAsString().toUpperCase( Locale.ENGLISH ) ) ) ); } else if( JsonUtils.isString( jsonObject, JSON_FEATURES_KEY ) ) { final String featureName = JsonUtils.getString( jsonObject, JSON_FEATURES_KEY ).toUpperCase( Locale.ENGLISH ); final AEFeature feature = AEFeature.valueOf( featureName ); result = AEConfig.instance().isFeatureEnabled( feature ); } else { result = false; } return () -> result; } }
private static ShapelessOreRecipe shapelessFactory( 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" ); } return new ShapelessOreRecipe( group.isEmpty() ? null : new ResourceLocation( group ), ings, getResult( json, context ) ); } }
String mode = JsonUtils.getString( json, "mode" );
private static ItemStack getPart( JsonObject resultObject ) { String ingredient = JsonUtils.getString( resultObject, "part" ); Object result = AEApi.instance().registries().recipes().resolveItem( AppEng.MOD_ID, ingredient ); if( result instanceof ResolverResult ) { ResolverResult resolverResult = (ResolverResult) result; Item item = Item.getByNameOrId( AppEng.MOD_ID + ":" + resolverResult.itemName ); if( item == null ) { AELog.warn( "item was null for " + resolverResult.itemName + " ( " + ingredient + " )!" ); throw new JsonSyntaxException( "Got a null item for " + resolverResult.itemName + " ( " + ingredient + " ). This should never happen!" ); } return new ItemStack( item, JsonUtils.getInt( resultObject, "count", 1 ), resolverResult.damageValue, resolverResult.compound ); } else { throw new JsonSyntaxException( "Couldn't find the resulting item in AE. This means AE was provided a recipe that it shouldn't be handling.\n" + "Was looking for : '" + ingredient + "'." ); } }
@Override public @Nonnull UseThings deserialize(@Nonnull JsonObject object, @Nonnull JsonDeserializationContext deserializationContext, @Nonnull LootCondition[] conditionsIn) { return new UseThings(conditionsIn, JsonUtils.getString(object, "name")); }
@Override public SetSpeciesNBT deserialize(JsonObject object, JsonDeserializationContext deserializationContext, LootCondition[] conditionsIn) { String speciesUid = JsonUtils.getString(object, "speciesUid"); return new SetSpeciesNBT(conditionsIn, speciesUid); } }
@Nonnull @Override public Ingredient parse(JsonContext context, JsonObject json) { String fluidName = JsonUtils.getString(json, "fluid"); return new FluidIngredient(fluidName); }
@Override public @Nonnull Potion deserialize(@Nonnull JsonObject object, @Nonnull JsonDeserializationContext deserializationContext, @Nonnull LootCondition[] conditionsIn) { return new Potion(conditionsIn, JsonUtils.getString(object, "name"), JsonUtils.getBoolean(object, "splash")); }
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 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); }
public Instance deserializeInstance(JsonObject json, JsonDeserializationContext context) { String uid = JsonUtils.getString(json, "uid"); IAllele allele = AlleleManager.alleleRegistry.getAllele(uid); if (allele == null) { throw new JsonSyntaxException("Unknown allele '" + uid + "'"); } else { return new Instance(allele); } }
@Override public void parse(JsonObject json) { String name = JsonUtils.getString(json, "name"); int time = JsonUtils.getInt(json, "time"); Set<String> dependencies = getDependencies(json); Set<Ingredient> resources = getResources(json); researchGoals.put(name, new ResearchGoal(name, dependencies, resources, time)); }
@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); } }