use of net.cr24.primeval.recipe.MeltingRecipe in project Primeval by devs-immortal.
the class VesselItem method processItems.
//
// VESSEL-SPECIFIC METHODS
//
public static ItemStack processItems(ItemStack vessel, World world) {
NbtCompound nbt = vessel.getOrCreateNbt();
NbtList nbtList = nbt.getList("Items", 10);
// Create new hashmap to store fluids that will be inserted
HashMap<FluidVariant, Integer> fluids = new HashMap<>();
// Item being melted
ItemStack itemStack;
// Resulting fluid from melted item, being <type, quantity>
Pair<FluidVariant, Integer> fluidResult;
// Type of fluid result
FluidVariant fluidType;
// Amonut of fluid from melting
int fluidAmount;
for (NbtElement nbtC : nbtList) {
// Get itemstack from item to melted
itemStack = ItemStack.fromNbt((NbtCompound) nbtC);
// Check if meltable recipe for the item
Optional<MeltingRecipe> option = world.getRecipeManager().getFirstMatch(PrimevalRecipes.MELTING, new SimpleInventory(itemStack), world);
if (option.isPresent()) {
// if can be melted
fluidResult = option.get().getFluidResult();
fluidType = fluidResult.getLeft();
fluidAmount = fluidResult.getRight();
if (fluids.containsKey(fluidType)) {
fluids.put(fluidType, fluids.get(fluidType) + fluidAmount * itemStack.getCount());
} else {
fluids.put(fluidType, fluidAmount * itemStack.getCount());
}
}
}
Pair<FluidVariant, Integer> alloyResult = PrimevalFluids.combineFluids(fluids);
if (alloyResult.getRight() > 0) {
NbtCompound nbtF = alloyResult.getLeft().toNbt();
nbtF.putInt("Amount", alloyResult.getRight());
nbt.put("Fluid", nbtF);
}
// Clear out items
nbt.put("Items", new NbtList());
vessel.setNbt(nbt);
return vessel;
}
Aggregations