use of mekanism.api.chemical.ChemicalType in project Mekanism by mekanism.
the class SerializerHelper method getBoxedChemicalStack.
/**
* Helper to get and deserialize a Chemical Stack from a specific sub-element in a Json Object.
*
* @param json Parent Json Object
* @param key Key in the Json Object that contains a Chemical Stack.
*
* @return Chemical Stack.
*/
public static ChemicalStack<?> getBoxedChemicalStack(@Nonnull JsonObject json, @Nonnull String key) {
validateKey(json, key);
JsonObject jsonObject = JSONUtils.getAsJsonObject(json, key);
ChemicalType chemicalType = getChemicalType(jsonObject);
if (chemicalType == ChemicalType.GAS) {
return deserializeGas(jsonObject);
} else if (chemicalType == ChemicalType.INFUSION) {
return deserializeInfuseType(jsonObject);
} else if (chemicalType == ChemicalType.PIGMENT) {
return deserializePigment(jsonObject);
} else if (chemicalType == ChemicalType.SLURRY) {
return deserializeSlurry(jsonObject);
} else {
throw new IllegalStateException("Unknown chemical type");
}
}
use of mekanism.api.chemical.ChemicalType in project Mekanism by mekanism.
the class BoxedChemicalNetwork method tickEmit.
private <CHEMICAL extends Chemical<CHEMICAL>, STACK extends ChemicalStack<CHEMICAL>> long tickEmit(@Nonnull STACK stack) {
ChemicalType chemicalType = ChemicalType.getTypeFor(stack);
Collection<Map<Direction, LazyOptional<BoxedChemicalHandler>>> acceptorValues = acceptorCache.getAcceptorValues();
ChemicalHandlerTarget<CHEMICAL, STACK, IChemicalHandler<CHEMICAL, STACK>> target = new ChemicalHandlerTarget<>(stack, acceptorValues.size() * 2);
for (Map<Direction, LazyOptional<BoxedChemicalHandler>> acceptors : acceptorValues) {
for (LazyOptional<BoxedChemicalHandler> lazyAcceptor : acceptors.values()) {
lazyAcceptor.ifPresent(acceptor -> {
IChemicalHandler<CHEMICAL, STACK> handler = acceptor.getHandlerFor(chemicalType);
if (handler != null && ChemicalUtil.canInsert(handler, stack)) {
target.addHandler(handler);
}
});
}
}
return EmitUtils.sendToAcceptors(target, stack.getAmount(), stack);
}
use of mekanism.api.chemical.ChemicalType in project Mekanism by mekanism.
the class ChemicalCrystallizerInputRecipeCache method findFirstRecipe.
@Nullable
private <CHEMICAL extends Chemical<CHEMICAL>, STACK extends ChemicalStack<CHEMICAL>> ChemicalCrystallizerRecipe findFirstRecipe(ChemicalType type, STACK stack) {
Predicate<ChemicalCrystallizerRecipe> matchPredicate = recipe -> ((IChemicalStackIngredient<CHEMICAL, STACK>) recipe.getInput()).test(stack);
ChemicalInputCache<CHEMICAL, STACK, ChemicalCrystallizerRecipe> cache = (ChemicalInputCache<CHEMICAL, STACK, ChemicalCrystallizerRecipe>) typeBasedCache.get(type);
ChemicalCrystallizerRecipe recipe = cache.findFirstRecipe(stack, matchPredicate);
return recipe == null ? findFirstRecipe(typeBasedComplexRecipes.get(type), matchPredicate) : recipe;
}
use of mekanism.api.chemical.ChemicalType in project Mekanism by mekanism.
the class ChemicalCrystallizerInputRecipeCache method containsInput.
/**
* Checks if there is a matching recipe that has the given input.
*
* @param world World.
* @param input Recipe input.
*
* @return {@code true} if there is a match, {@code false} if there isn't.
*/
public boolean containsInput(@Nullable World world, BoxedChemicalStack input) {
if (input.isEmpty()) {
// Don't allow empty inputs
return false;
}
initCacheIfNeeded(world);
ChemicalType type = input.getChemicalType();
return containsInput(type, input.getChemicalStack()) || typeBasedComplexRecipes.get(type).stream().anyMatch(recipe -> recipe.testType(input));
}
use of mekanism.api.chemical.ChemicalType in project Mekanism by mekanism.
the class ChemicalCrystallizerInputRecipeCache method containsInput.
/**
* Checks if there is a matching recipe that has the given input.
*
* @param world World.
* @param input Recipe input.
*
* @return {@code true} if there is a match, {@code false} if there isn't.
*/
public <CHEMICAL extends Chemical<CHEMICAL>, STACK extends ChemicalStack<CHEMICAL>> boolean containsInput(@Nullable World world, CHEMICAL input) {
if (input.isEmptyType()) {
// Don't allow empty inputs
return false;
}
initCacheIfNeeded(world);
ChemicalType type = ChemicalType.getTypeFor(input);
STACK stack = (STACK) input.getStack(1);
return containsInput(type, stack) || typeBasedComplexRecipes.get(type).stream().anyMatch(recipe -> recipe.testType(stack));
}
Aggregations