protected int parseTintIndex( JsonObject object ) { return JsonUtils.getInt( object, "tintindex", -1 ); }
@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() ); } } }
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 + "'." ); } }
public static ICrop parse(BlockStateMatcher stateMatcher, JsonObject properties) { return new CropTall(stateMatcher, JsonUtils.getInt(properties, "height")); } }
@Override public SetItemBloodCharge deserialize(JsonObject object, JsonDeserializationContext deserializationContext, LootCondition[] conditionsIn) { if (object.has("charge")) { int value = JsonUtils.getInt(object, "charge"); return new SetItemBloodCharge(conditionsIn, Math.max(0, value), -1, -1); } else if (object.has("min_charge") && object.has("max_charge")) { int l = JsonUtils.getInt(object, "min_charge"); int u = JsonUtils.getInt(object, "max_charge"); return new SetItemBloodCharge(conditionsIn, -1, Math.max(0, l), Math.max(0, u)); } else { throw new JsonSyntaxException("Need charge property for vampirism:set_item_blood_charge"); } }
public RodStrength deserialize(JsonObject json, JsonDeserializationContext context) { return new RodStrength(JsonUtils.getInt(json, "strength", 1)); } }
@Override public Instance deserializeInstance(JsonObject json, JsonDeserializationContext context) { JsonElement jsonElement = json.get("min_entities"); int minEntities = 0; if (jsonElement != null && !jsonElement.isJsonNull()) { minEntities = JsonUtils.getInt(json, "min_entities"); } return new Instance(getId(), minEntities, EntityPredicate.deserialize(json.get("entity"))); }
public static void parse(JsonObject treeScanner) { Predicate<IBlockState> trunkMatcher = JsonHelper.getBlockStateMatcher(treeScanner, "trunks", "trunk"); Predicate<IBlockState> leafMatcher = JsonHelper.getBlockStateMatcher(treeScanner, "leaves", "leaf"); int maxLeafDistance = JsonUtils.getInt(treeScanner, "max_leaf_distance"); DefaultTreeScanner.INextPositionGetter nextPosGetter = parseNextPositionGetter(treeScanner); Optional<DefaultTreeScanner> currentScanner = treeScanners.stream().filter(m -> m instanceof DefaultTreeScanner && ((DefaultTreeScanner) m).getTrunkMatcher().hashCode() == trunkMatcher.hashCode()).map(m -> (DefaultTreeScanner) m).findFirst(); if (currentScanner.isPresent()) { currentScanner.get().addLeafMatcher(leafMatcher); } else { registerTreeScanner(new DefaultTreeScanner(trunkMatcher, leafMatcher, nextPosGetter, maxLeafDistance)); } }
public MultipleOf deserialize(JsonObject json, JsonDeserializationContext context) { return new MultipleOf(JsonUtils.getInt(json, "of", 0), JsonUtils.getBoolean(json, "reverse", false)); } }
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; } }
@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); } }
@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 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; } }
@Nonnull @Override public Ingredient parse(JsonContext context, JsonObject json) { ResourceLocation enchantmentId = new ResourceLocation(JsonUtils.getString(json, "id")); int level = JsonUtils.getInt(json, "level", 1); if (!Enchantment.REGISTRY.containsKey(enchantmentId)) { throw new JsonSyntaxException("Unknown enchantment '" + enchantmentId + "'"); } Enchantment enchantment = Enchantment.REGISTRY.getObject(enchantmentId); return new IngredientEnchanted(enchantment, level); } }
public static void registerIngredients() { CraftingHelper.register(new ResourceLocation(AncientWarfareCore.MOD_ID, "item_count"), (IIngredientFactory) (c, j) -> new IngredientCount(CraftingHelper.getItemStack(j, c))); CraftingHelper.register(new ResourceLocation(AncientWarfareCore.MOD_ID, "ore_dict_count"), (IIngredientFactory) (c, j) -> new IngredientOreCount(JsonUtils.getString(j, "ore"), JsonUtils.getInt(j, "count", 1))); CraftingHelper.register(new ResourceLocation(AncientWarfareCore.MOD_ID, "item_nbt_relaxed"), (IIngredientFactory) (c, j) -> new IngredientNBTRelaxed(CraftingHelper.getItemStack(j, c))); }