use of com.witchworks.api.recipe.ItemValidator in project Witchworks by Um-Mitternacht.
the class TileKettle method processingLogic.
//------------------------------------Crafting Logic------------------------------------//
@SuppressWarnings("ConstantConditions")
public boolean processingLogic(ItemStack stack) {
if (!isBoiling() || hasIngredients() || stack.getCount() > 64)
return false;
Map<Item, ItemValidator<ItemStack>> processing = KettleRegistry.getKettleProcessing(inv.getInnerFluid());
if (processing != null && processing.containsKey(stack.getItem())) {
ItemValidator<ItemStack> validator = processing.get(stack.getItem());
Optional<ItemStack> optional = validator.getMatchFor(stack);
if (optional.isPresent()) {
ItemStack out = optional.get().copy();
if (stack.isItemDamaged() && out.isItemStackDamageable())
out.setItemDamage(stack.getItemDamage());
int fluidAmount = inv.getFluidAmount();
int fluidTaken = 250;
out.setCount(0);
if (stack.getCount() <= 16) {
out.setCount(stack.getCount());
stack.setCount(0);
} else {
while (stack.getCount() > 0 && fluidTaken <= fluidAmount) {
stack.shrink(1);
out.grow(1);
if (out.getCount() % 16 == 0) {
if (fluidTaken >= fluidAmount) {
fluidTaken = fluidAmount;
break;
}
fluidTaken += 250;
}
}
}
if (out.getCount() > 0) {
final double x = getPos().getX();
final double y = getPos().getY() + 1D;
final double z = getPos().getZ();
final EntityItem item = new EntityItem(world, x + 0.5D, y, z + 0.5D, out);
item.motionX = world.rand.nextDouble() * 2 - 1;
item.motionZ = world.rand.nextDouble() * 2 - 1;
item.motionY = 0.1D;
item.setPickupDelay(0);
world.spawnEntity(item);
play(SoundEvents.BLOCK_FIRE_EXTINGUISH, 1F, 1F);
for (int i = 0; i < 4; i++) {
PacketHandler.spawnParticle(ParticleF.STEAM, world, x + world.rand.nextFloat(), getParticleLevel(), z + world.rand.nextFloat(), 5, 0, 0, 0);
}
inv.drain(fluidTaken, true);
return true;
}
}
}
return false;
}
use of com.witchworks.api.recipe.ItemValidator in project Witchworks by Um-Mitternacht.
the class TileKettle method getBrewData.
@Nullable
public NBTTagCompound getBrewData() {
final Map<Item, ItemValidator<Object>> brewEffect = KettleRegistry.getBrewEffect();
final Map<Item, ItemValidator<BrewModifier>> brewModifier = KettleRegistry.getBrewModifier();
List<Object> effects = new ArrayList<>();
for (int i = 0; i < ingredients.length; i++) {
ItemStack ingredient = ingredients[i];
if (ingredient.isEmpty())
break;
Item effect = ingredient.getItem();
boolean add = true;
if (!brewEffect.containsKey(effect)) {
failHorribly();
return null;
}
ItemValidator<Object> validator = brewEffect.get(effect);
Optional<Object> optional = validator.getMatchFor(ingredient);
if (!optional.isPresent()) {
failHorribly();
return null;
}
Object brew = copyBrew(optional.get());
if (i + 1 < ingredients.length) {
while (i + 1 < ingredients.length) {
ItemStack modifier = ingredients[i + 1];
if (!brewModifier.containsKey(modifier.getItem())) {
if (brewEffect.containsKey(modifier.getItem()) || modifier.isEmpty())
break;
failHorribly();
return null;
}
ItemValidator<BrewModifier> val = brewModifier.get(modifier.getItem());
Optional<BrewModifier> opt = val.getMatchFor(modifier);
if (opt.isPresent()) {
for (int j = 0, size = modifier.getCount(); j < size; j++) {
add = opt.get().apply(effects, brew);
}
} else {
failHorribly();
return null;
}
++i;
}
}
if (add)
effects.add(brew);
}
return BrewUtils.serialize(effects);
}
use of com.witchworks.api.recipe.ItemValidator in project Witchworks by Um-Mitternacht.
the class KettleRegistry method addKettleProcessing.
/**
* Register an Item to the Processing factory.
*
* @param fluid The fluid this Item needs
* @param in The Item you throw in
* @param out The Item that comes out
* @param strict If the Item must be identical
*/
public static void addKettleProcessing(Fluid fluid, ItemStack in, ItemStack out, boolean strict) {
if (KETTLE_PROCESSING.containsKey(fluid)) {
Map<Item, ItemValidator<ItemStack>> map = KETTLE_PROCESSING.get(fluid);
Item item = in.getItem();
if (map.containsKey(item)) {
map.get(item).add(in, out, strict);
} else {
map.put(item, new ItemValidator<ItemStack>().add(in, out, strict));
}
} else {
Map<Item, ItemValidator<ItemStack>> map = new HashMap<>();
map.put(in.getItem(), new ItemValidator<ItemStack>().add(in, out, strict));
KETTLE_PROCESSING.put(fluid, map);
}
}
Aggregations