use of net.minecraft.item.crafting.Ingredient in project Wizardry by TeamWizardry.
the class FluidRecipeLoader method buildFluidCrafter.
private FluidCrafter buildFluidCrafter(String identifier, IBlockState outputBlock, Ingredient input, List<Ingredient> extraInputs, Fluid fluid, int duration, int required, boolean consume, boolean explode, boolean bubbling, boolean harp) {
List<Ingredient> inputs = Lists.newArrayList(extraInputs);
FluidCrafter builder = 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)) {
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())) {
entity.getItem().shrink(1);
if (entity.getItem().isEmpty())
entity.setDead();
}
}
}
world.setBlockState(pos, outputBlock);
Vec3d output = new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
if (explode) {
PacketHandler.NETWORK.sendToAllAround(new PacketExplode(output, Color.CYAN, Color.BLUE, 0.9, 2, 500, 100, 50, true), new NetworkRegistry.TargetPoint(world.provider.getDimension(), output.x, output.y, output.z, 256));
PosUtils.boom(world, output, null, 3, false);
}
if (harp)
world.playSound(null, output.x, output.y, output.z, ModSounds.HARP1, SoundCategory.BLOCKS, 0.3F, 1.0F);
}, identifier, duration).setInputs(input, inputs).setIsBlock(true).setDoesConsume(true).setRequired(required).setFluid(fluid);
Fluid fluidOutput = FluidRegistry.lookupFluidForBlock(outputBlock.getBlock());
if (fluidOutput != null)
builder.setOutput(new FluidStack(fluidOutput, 1000));
else
builder.setOutput(new ItemStack(outputBlock.getBlock(), 1, outputBlock.getBlock().damageDropped(outputBlock)));
return builder;
}
use of net.minecraft.item.crafting.Ingredient in project BaseMetals by MinecraftModDevelopmentMods.
the class ConfigVariedOutput method parse.
@Override
public IRecipe parse(final JsonContext context, final JsonObject json) {
String confKey = JsonUtils.getString(json, "config_key");
int resAmount = 0;
switch(confKey) {
case "gear":
resAmount = Options.gearQuantity();
break;
case "plate":
resAmount = Options.plateQuantity();
break;
default:
BaseMetals.logger.error("Unknown quantity config value {}, setting to 1", confKey);
resAmount = 1;
}
// load the data here, map the ingredients, setup the primer and return the ShapedOreRecipe :)
final Map<Character, Ingredient> ingMap = Maps.newHashMap();
JsonUtils.getJsonObject(json, "key").entrySet().stream().filter(ent -> ent.getKey().length() == 1 && !ent.getKey().isEmpty()).forEach(ent -> ingMap.put(ent.getKey().toCharArray()[0], CraftingHelper.getIngredient(ent.getValue(), context)));
ingMap.put(' ', Ingredient.EMPTY);
JsonArray patternJ = JsonUtils.getJsonArray(json, "pattern");
if (patternJ.size() == 0) {
throw new JsonSyntaxException("Invalid pattern: empty pattern not allows");
}
final String[] pattern = new String[patternJ.size()];
for (int x = 0; x < pattern.length; ++x) {
final String line = JsonUtils.getString(patternJ.get(x), "pattern[" + x + "]");
if (x > 0 && pattern[0].length() != line.length()) {
throw new JsonSyntaxException("Invalid pattern: each row must be the same width");
}
pattern[x] = line;
}
final ShapedPrimer primer = new ShapedPrimer();
primer.width = pattern[0].length();
primer.height = pattern.length;
primer.mirrored = true;
primer.input = NonNullList.withSize(primer.width * primer.height, Ingredient.EMPTY);
final Set<Character> keys = Sets.newHashSet(ingMap.keySet());
keys.remove(' ');
int x = 0;
for (final String line : pattern) {
for (final char chr : line.toCharArray()) {
final Ingredient ing = ingMap.get(chr);
if (ing == null) {
throw new JsonSyntaxException("Pattern references symbol '" + chr + "' but it's not defined in the key");
}
primer.input.set(x++, ing);
keys.remove(chr);
}
}
if (!keys.isEmpty()) {
throw new JsonSyntaxException("Key defines symbols that aren't used in pattern: " + keys);
}
final String group = JsonUtils.getString(json, "group", "");
final ItemStack result = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context);
result.setCount(resAmount);
return new ShapedOreRecipe(group.isEmpty() ? null : new ResourceLocation(group), result, primer);
}
use of net.minecraft.item.crafting.Ingredient in project TechReborn by TechReborn.
the class RollingMachineRecipe method addShapelessRecipe.
public void addShapelessRecipe(ResourceLocation resourceLocation, ItemStack output, Object... components) {
NonNullList<Ingredient> ingredients = NonNullList.create();
for (int j = 0; j < components.length; j++) {
ingredients.add(CraftingHelper.getIngredient(components[j]));
}
recipes.put(resourceLocation, new ShapelessRecipes("", output, ingredients));
}
use of net.minecraft.item.crafting.Ingredient in project TechReborn by TechReborn.
the class TileAutoCraftingTable method findBestSlotForStack.
public int findBestSlotForStack(IRecipe recipe, ItemStack stack) {
if (recipe == null) {
return -1;
}
List<Integer> possibleSlots = new ArrayList<>();
for (int i = 0; i < recipe.getIngredients().size(); i++) {
ItemStack stackInSlot = inventory.getStackInSlot(i);
Ingredient ingredient = recipe.getIngredients().get(i);
if (ingredient != Ingredient.EMPTY && ingredient.apply(stack)) {
if (stackInSlot.isEmpty()) {
possibleSlots.add(i);
} else if (stackInSlot.getItem() == stack.getItem() && stackInSlot.getItemDamage() == stack.getItemDamage()) {
if (stackInSlot.getMaxStackSize() >= stackInSlot.getCount() + stack.getCount()) {
possibleSlots.add(i);
}
}
}
}
// Slot, count
Pair<Integer, Integer> smallestCount = null;
for (Integer slot : possibleSlots) {
ItemStack slotStack = inventory.getStackInSlot(slot);
if (slotStack.isEmpty()) {
return slot;
}
if (smallestCount == null) {
smallestCount = Pair.of(slot, slotStack.getCount());
} else if (smallestCount.getRight() >= slotStack.getCount()) {
smallestCount = Pair.of(slot, slotStack.getCount());
}
}
if (smallestCount != null) {
return smallestCount.getLeft();
}
return -1;
}
use of net.minecraft.item.crafting.Ingredient in project TechReborn by TechReborn.
the class TileAutoCraftingTable method canMake.
public boolean canMake(IRecipe recipe) {
if (customRecipe) {
recipe = getIRecipe();
}
if (recipe != null && recipe.canFit(3, 3)) {
boolean missingOutput = false;
int[] stacksInSlots = new int[9];
for (int i = 0; i < 9; i++) {
stacksInSlots[i] = inventory.getStackInSlot(i).getCount();
}
for (Ingredient ingredient : recipe.getIngredients()) {
if (ingredient != Ingredient.EMPTY) {
boolean foundIngredient = false;
for (int i = 0; i < 9; i++) {
ItemStack stack = inventory.getStackInSlot(i);
int requiredSize = customRecipe ? 1 : 0;
if (stack.getMaxStackSize() == 1) {
requiredSize = 0;
}
if (stacksInSlots[i] > requiredSize) {
if (ingredient.apply(stack)) {
if (stack.getItem().getContainerItem() != null) {
if (!hasRoomForExtraItem(stack.getItem().getContainerItem(stack))) {
continue;
}
}
foundIngredient = true;
stacksInSlots[i]--;
break;
}
}
}
if (!foundIngredient) {
missingOutput = true;
}
}
}
if (!missingOutput) {
if (hasOutputSpace(recipe.getRecipeOutput(), 9)) {
return true;
}
}
return false;
}
return false;
}
Aggregations