Search in sources :

Example 1 with MCTag

use of com.blamejared.crafttweaker.impl.tag.MCTag in project Mekanism by mekanism.

the class MekanismRecipeHandler method convertIngredient.

private <CHEMICAL extends Chemical<CHEMICAL>, STACK extends ChemicalStack<CHEMICAL>> String convertIngredient(String crtClass, CrTChemicalTagManager<CHEMICAL> tagManager, ChemicalIngredientDeserializer<CHEMICAL, STACK, ?> deserializer, IChemicalStackIngredient<CHEMICAL, STACK> ingredient) {
    if (ingredient instanceof ChemicalStackIngredient.SingleIngredient) {
        // Serialize and deserialize to get easy access to the amount
        JsonObject serialized = ingredient.serialize().getAsJsonObject();
        // Note: Handled via implicit casts
        return convertParam(deserializer.deserializeStack(serialized));
    } else if (ingredient instanceof ChemicalStackIngredient.TaggedIngredient) {
        JsonObject serialized = ingredient.serialize().getAsJsonObject();
        MCTag<CHEMICAL> tag = tagManager.getTag(serialized.get(JsonConstants.TAG).getAsString());
        long amount = serialized.getAsJsonPrimitive(JsonConstants.AMOUNT).getAsLong();
        if (amount > 0 && amount <= Integer.MAX_VALUE) {
            // Note: Handled via implicit casts
            return getTagWithExplicitAmount(tag, (int) amount);
        }
        // Tag with amount can only handle up to max int, so we have to do it explicitly if we have more
        return crtClass + ".from(" + tag.getCommandString() + ", " + amount + ")";
    } else if (ingredient instanceof ChemicalStackIngredient.MultiIngredient) {
        ChemicalStackIngredient.MultiIngredient<CHEMICAL, STACK, ?> multiIngredient = (ChemicalStackIngredient.MultiIngredient<CHEMICAL, STACK, ?>) ingredient;
        StringBuilder builder = new StringBuilder(crtClass + ".createMulti(");
        multiIngredient.forEachIngredient(i -> {
            builder.append(convertIngredient(crtClass, tagManager, deserializer, i)).append(", ");
            return false;
        });
        // Remove trailing comma and space
        builder.setLength(builder.length() - 2);
        builder.append(")");
        return builder.toString();
    }
    // Shouldn't happen
    return "Unimplemented chemical stack ingredient: " + ingredient;
}
Also used : MCTag(com.blamejared.crafttweaker.impl.tag.MCTag) JsonObject(com.google.gson.JsonObject) IChemicalStackIngredient(mekanism.api.recipes.inputs.chemical.IChemicalStackIngredient) ChemicalStackIngredient(mekanism.api.recipes.inputs.chemical.ChemicalStackIngredient)

Aggregations

MCTag (com.blamejared.crafttweaker.impl.tag.MCTag)1 JsonObject (com.google.gson.JsonObject)1 ChemicalStackIngredient (mekanism.api.recipes.inputs.chemical.ChemicalStackIngredient)1 IChemicalStackIngredient (mekanism.api.recipes.inputs.chemical.IChemicalStackIngredient)1