use of net.minecraft.recipe.Ingredient in project nbt-crafting by Siphalor.
the class MixinIngredient method ofAdvancedEntries.
@Unique
private static Ingredient ofAdvancedEntries(Stream<? extends IngredientEntry> entries) {
if (entries == null)
NbtCrafting.logError("Internal error: can't construct ingredient from null entry stream!");
try {
Ingredient ingredient;
// noinspection ConstantConditions
ingredient = (Ingredient) ((ICloneable) (Object) Ingredient.EMPTY).clone();
((IIngredient) (Object) ingredient).nbtCrafting$setAdvancedEntries(entries);
return ingredient;
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return Ingredient.EMPTY;
}
use of net.minecraft.recipe.Ingredient in project MCDoom by AzureDoom.
the class GunTableScreenHandler method switchTo.
public void switchTo(int recipeIndex) {
// index out of bounds
if (this.getRecipes().size() > recipeIndex) {
GunTableRecipe gunTableRecipe = getRecipes().get(recipeIndex);
for (int i = 0; i < 5; i++) {
ItemStack slotStack = gunTableInventory.getStack(i);
if (!slotStack.isEmpty()) {
// if all positions can't be filled, transfer nothing
if (!this.insertItem(slotStack, 6, 39, false)) {
return;
}
gunTableInventory.setStack(i, slotStack);
}
}
for (int i = 0; i < 5; i++) {
Ingredient ingredient = gunTableRecipe.getIngredientForSlot(i);
if (!ingredient.isEmpty()) {
ItemStack[] possibleItems = ((IngredientAccess) (Object) ingredient).getMatchingStacksMod();
if (possibleItems != null) {
ItemStack first = new ItemStack(possibleItems[0].getItem(), gunTableRecipe.countRequired(i));
autofill(i, first);
}
}
}
}
}
use of net.minecraft.recipe.Ingredient in project MCDoom by AzureDoom.
the class GunTableRecipe method matches.
@Override
public boolean matches(GunTableInventory inv, World world) {
for (int i = 0; i < 5; i++) {
ItemStack slotStack = inv.getStack(i);
Pair<Ingredient, Integer> pair = ingredients[i];
Ingredient ingredient = pair.getLeft();
int count = pair.getRight();
if (slotStack.getCount() < count || !(ingredient.test(slotStack))) {
return false;
}
}
return true;
}
use of net.minecraft.recipe.Ingredient in project bewitchment by MoriyaShiine.
the class SmeltItemsRitualFunction method tick.
@Override
public void tick(World world, BlockPos glyphPos, BlockPos effectivePos, boolean catFamiliar) {
int radius = catFamiliar ? 9 : 3;
if (!world.isClient) {
if (world.getTime() % 20 == 0) {
for (ItemEntity itemEntity : world.getEntitiesByType(EntityType.ITEM, new Box(effectivePos).expand(radius, 0, radius), entity -> true)) {
if (world.random.nextFloat() < 1 / 4f) {
world.getRecipeManager().listAllOfType(RecipeType.SMELTING).forEach(smeltingRecipe -> {
for (Ingredient ingredient : smeltingRecipe.getIngredients()) {
if (ingredient.test(itemEntity.getStack())) {
world.playSound(null, itemEntity.getBlockPos(), SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, SoundCategory.BLOCKS, 1, 1);
ItemScatterer.spawn(world, itemEntity.getX(), itemEntity.getY(), itemEntity.getZ(), smeltingRecipe.getOutput().copy());
world.spawnEntity(new ExperienceOrbEntity(world, itemEntity.getX(), itemEntity.getY(), itemEntity.getZ(), 1));
itemEntity.getStack().decrement(1);
}
}
});
}
}
}
} else {
world.addParticle(ParticleTypes.FLAME, effectivePos.getX() + MathHelper.nextDouble(world.random, -radius, radius), effectivePos.getY() + 0.5, effectivePos.getZ() + MathHelper.nextDouble(world.random, -radius, radius), 0, 0, 0);
}
}
use of net.minecraft.recipe.Ingredient in project bewitchment by MoriyaShiine.
the class RitualRecipe method matches.
public static boolean matches(Inventory inv, DefaultedList<Ingredient> input) {
List<ItemStack> checklist = new ArrayList<>();
for (int i = 0; i < inv.size(); i++) {
ItemStack stack = inv.getStack(i);
if (!stack.isEmpty()) {
checklist.add(stack);
}
}
if (input.size() != checklist.size()) {
return false;
}
for (Ingredient ingredient : input) {
boolean found = false;
for (ItemStack stack : checklist) {
if (ingredient.test(stack)) {
found = true;
checklist.remove(stack);
break;
}
}
if (!found) {
return false;
}
}
return true;
}
Aggregations