use of net.minecraft.item.crafting.Ingredient in project Wizardry by TeamWizardry.
the class RecipeShapedFluid method getRemainingItems.
@Override
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) {
NonNullList<ItemStack> remains = ForgeHooks.defaultRecipeGetRemainingItems(inv);
for (int i = 0; i < height * width; i++) {
ItemStack stack = inv.getStackInSlot(i);
NonNullList<Ingredient> matchedIngredients = this.input;
if (matchedIngredients.get(i) instanceof IngredientFluidStack) {
if (!stack.isEmpty()) {
ItemStack copy = stack.copy();
copy.setCount(1);
remains.set(i, copy);
}
IFluidHandlerItem handler = FluidUtil.getFluidHandler(remains.get(i));
if (handler != null) {
FluidStack fluid = ((IngredientFluidStack) matchedIngredients.get(i)).getFluid();
handler.drain(fluid.amount, true);
remains.set(i, handler.getContainer());
}
}
}
return remains;
}
use of net.minecraft.item.crafting.Ingredient in project Wizardry by TeamWizardry.
the class RecipeShapelessFluid method matches.
@Override
public boolean matches(InventoryCrafting matrix, World world) {
ArrayList<Ingredient> required = new ArrayList<>(getIngredients());
for (int i = 0; i < matrix.getSizeInventory(); i++) {
ItemStack slot = matrix.getStackInSlot(i);
if (!slot.isEmpty()) {
boolean inRecipe = false;
Iterator<Ingredient> iterator = required.iterator();
while (iterator.hasNext()) {
Ingredient next = iterator.next();
if (next.apply(slot)) {
inRecipe = true;
iterator.remove();
break;
}
}
if (!inRecipe)
return false;
}
}
return required.isEmpty();
}
use of net.minecraft.item.crafting.Ingredient in project Wizardry by TeamWizardry.
the class RecipeShapelessFluidFactory method parse.
@Override
public IRecipe parse(JsonContext context, JsonObject json) {
String group = JsonUtils.getString(json, "group", "");
NonNullList<Ingredient> ingredients = NonNullList.create();
for (JsonElement element : JsonUtils.getJsonArray(json, "ingredients")) ingredients.add(CraftingHelper.getIngredient(element, context));
if (ingredients.isEmpty())
throw new JsonParseException("No ingredients in shapeless recipe");
ItemStack result = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context);
RecipeShapelessFluid recipe = new RecipeShapelessFluid(group.isEmpty() ? null : new ResourceLocation(group), result, ingredients);
return recipe;
}
use of net.minecraft.item.crafting.Ingredient in project Wizardry by TeamWizardry.
the class FireRecipeLoader method processRecipes.
public void processRecipes(Map<Ingredient, FireRecipe> recipes) {
Wizardry.logger.info("<<========================================================================>>");
Wizardry.logger.info("> Starting fire recipe loading.");
JsonContext context = new JsonContext("minecraft");
LinkedList<File> recipeFiles = new LinkedList<>();
Stack<File> toProcess = new Stack<>();
toProcess.push(directory);
while (!toProcess.isEmpty()) {
File file = toProcess.pop();
if (file.isDirectory()) {
File[] children = file.listFiles();
if (children != null)
for (File child : children) toProcess.push(child);
} else if (file.isFile())
if (file.getName().endsWith(".json"))
recipeFiles.add(file);
}
for (File file : recipeFiles) {
try {
if (!file.exists()) {
Wizardry.logger.error(" > SOMETHING WENT WRONG! " + file.getPath() + " can NOT be found. Ignoring file...");
continue;
}
JsonElement element;
try {
element = new JsonParser().parse(new FileReader(file));
} catch (FileNotFoundException e) {
Wizardry.logger.error(" > SOMETHING WENT WRONG! " + file.getPath() + " can NOT be found. Ignoring file...");
continue;
}
if (element == null) {
Wizardry.logger.error(" > SOMETHING WENT WRONG! Could not parse " + file.getPath() + ". Ignoring file...");
continue;
}
if (!element.isJsonObject()) {
Wizardry.logger.error(" > WARNING! " + file.getPath() + " does NOT contain a JsonObject. Ignoring file...: " + element.toString());
continue;
}
JsonObject fileObject = element.getAsJsonObject();
int duration = 200;
if (!fileObject.has("input")) {
Wizardry.logger.error(" > WARNING! " + file.getPath() + " does NOT provide an initial input item. Ignoring file...: " + element.toString());
continue;
}
JsonElement inputObject = fileObject.get("input");
Ingredient input = CraftingHelper.getIngredient(inputObject, context);
if (input == Ingredient.EMPTY) {
Wizardry.logger.error(" > WARNING! " + file.getPath() + " does NOT provide a valid input. Ignoring file...: " + element.toString());
continue;
}
if (!fileObject.has("output")) {
Wizardry.logger.error(" > WARNING! " + file.getPath() + " does NOT specify a recipe output. Ignoring file...: " + element.toString());
continue;
}
if (!fileObject.get("output").isJsonObject()) {
Wizardry.logger.error(" > WARNING! " + file.getPath() + " does NOT provide a valid output. Ignoring file...: " + element.toString());
continue;
}
JsonObject outputObject = fileObject.get("output").getAsJsonObject();
ItemStack output = CraftingHelper.getItemStack(outputObject, context);
if (output.isEmpty()) {
Wizardry.logger.error(" > WARNING! " + file.getPath() + " does NOT provide a valid output. Ignoring file...: " + element.toString());
continue;
}
if (fileObject.has("duration")) {
if (!fileObject.get("duration").isJsonPrimitive() || !fileObject.getAsJsonPrimitive("duration").isNumber()) {
Wizardry.logger.error(" > WARNING! " + file.getPath() + " does NOT give duration as a number. Ignoring file...:" + element.toString());
continue;
}
duration = fileObject.get("duration").getAsInt();
}
recipes.put(input, new FireRecipe(output, duration));
} catch (JsonParseException jsonException) {
Wizardry.logger.error(" > WARNING! Skipping " + file.getPath() + " due to error: ", jsonException);
}
}
Wizardry.logger.info("> Finished fire recipe loading.");
Wizardry.logger.info("<<========================================================================>>");
}
use of net.minecraft.item.crafting.Ingredient in project Wizardry by TeamWizardry.
the class FluidRecipeLoader method buildFluidCrafter.
private FluidCrafter buildFluidCrafter(String identifier, ItemStack outputItem, Ingredient input, List<Ingredient> extraInputs, Fluid fluid, int duration, int required, boolean consume, boolean explode, boolean bubbling, boolean harp) {
Ingredient outputIngredient = Ingredient.fromStacks(outputItem);
List<Ingredient> inputs = Lists.newArrayList(extraInputs);
return new FluidCrafter((world, pos, items) -> {
if (allLiquidInPool(world, pos, required, fluid).size() < required)
return false;
List<ItemStack> list = items.stream().map(entity -> entity.getItem().copy()).collect(Collectors.toList());
List<Ingredient> inputList = new ArrayList<>(inputs);
inputList.add(input);
for (Ingredient itemIn : inputList) {
boolean foundMatch = false;
List<ItemStack> toRemove = new LinkedList<>();
for (ItemStack item : list) {
if (itemIn.apply(item) && !outputIngredient.apply(item)) {
foundMatch = true;
break;
}
}
if (!foundMatch)
return false;
list.removeAll(toRemove);
toRemove.clear();
}
return true;
}, (world, pos, items, currentDuration) -> {
EntityItem entityItem = items.stream().filter(entity -> input.apply(entity.getItem())).findFirst().orElse(null);
if (entityItem != null) {
if (world.isRemote)
LibParticles.CRAFTING_ALTAR_IDLE(world, entityItem.getPositionVector());
if (bubbling && currentDuration % 10 == 0)
world.playSound(null, entityItem.posX, entityItem.posY, entityItem.posZ, ModSounds.BUBBLING, SoundCategory.BLOCKS, 0.7F, (RandUtil.nextFloat() * 0.4F) + 0.8F);
}
}, (world, pos, items, currentDuration) -> {
if (consume) {
Block block = fluid.getBlock();
if (block != null) {
IBlockState defaultState = block.getDefaultState();
Iterator<IProperty<?>> properties = defaultState.getPropertyKeys().iterator();
IBlockState drainState = defaultState;
if (properties.hasNext())
drainState = drainState.cycleProperty(properties.next());
for (BlockPos position : allLiquidInPool(world, pos, required, fluid)) world.setBlockState(position, drainState);
}
}
List<Ingredient> inputList = new ArrayList<>(inputs);
inputList.add(input);
for (Ingredient itemIn : inputList) {
for (EntityItem entity : items) {
if (itemIn.apply(entity.getItem()) && !outputIngredient.apply(entity.getItem())) {
entity.getItem().shrink(1);
if (entity.getItem().isEmpty())
entity.setDead();
}
}
}
EntityItem output = new EntityItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, outputItem.copy());
output.motionX = 0;
output.motionY = 0;
output.motionZ = 0;
output.forceSpawn = true;
world.spawnEntity(output);
if (explode) {
PacketHandler.NETWORK.sendToAllAround(new PacketExplode(output.getPositionVector(), Color.CYAN, Color.BLUE, 0.9, 2, 500, 100, 50, true), new NetworkRegistry.TargetPoint(world.provider.getDimension(), output.posX, output.posY, output.posZ, 256));
PosUtils.boom(world, output.getPositionVector(), output, 3, false);
}
if (harp)
world.playSound(null, output.posX, output.posY, output.posZ, ModSounds.HARP1, SoundCategory.BLOCKS, 0.3F, 1.0F);
}, identifier, duration).setInputs(input, inputs).setOutput(outputItem).setDoesConsume(consume).setRequired(required).setFluid(fluid);
}
Aggregations