Search in sources :

Example 1 with AbstractCookingRecipe

use of net.minecraft.world.item.crafting.AbstractCookingRecipe in project SpongeCommon by SpongePowered.

the class RecipeManagerMixin_API method findMatchingRecipe.

@Override
@SuppressWarnings("unchecked")
public Optional<Recipe> findMatchingRecipe(final Inventory inventory, final ServerWorld world) {
    Preconditions.checkNotNull(inventory);
    Preconditions.checkNotNull(world);
    if (inventory instanceof AbstractFurnaceBlockEntity) {
        final net.minecraft.world.item.crafting.RecipeType<? extends AbstractCookingRecipe> type = ((AbstractFurnaceBlockEntityAccessor) inventory).accessor$recipeType();
        return this.<Container, AbstractCookingRecipe>shadow$getRecipeFor((net.minecraft.world.item.crafting.RecipeType<AbstractCookingRecipe>) type, (Container) inventory, (net.minecraft.world.level.Level) world).map(Recipe.class::cast);
    }
    if (inventory instanceof CampfireBlockEntity) {
        return this.shadow$getRecipeFor(net.minecraft.world.item.crafting.RecipeType.CAMPFIRE_COOKING, (Container) inventory, (net.minecraft.world.level.Level) world).map(Recipe.class::cast);
    }
    if (inventory instanceof CraftingMenu) {
        final CraftingContainer craftingInventory = ((CraftingMenuAccessor) inventory).accessor$craftSlots();
        return this.shadow$getRecipeFor(net.minecraft.world.item.crafting.RecipeType.CRAFTING, craftingInventory, (net.minecraft.world.level.Level) world).map(Recipe.class::cast);
    }
    if (inventory instanceof InventoryMenu) {
        final CraftingContainer craftingInventory = ((InventoryMenuAccessor) inventory).accessor$craftSlots();
        return this.shadow$getRecipeFor(net.minecraft.world.item.crafting.RecipeType.CRAFTING, craftingInventory, (net.minecraft.world.level.Level) world).map(Recipe.class::cast);
    }
    if (inventory instanceof StonecutterMenu) {
        final Container stonecutterInventory = ((StonecutterMenu) inventory).container;
        return this.shadow$getRecipeFor(net.minecraft.world.item.crafting.RecipeType.STONECUTTING, stonecutterInventory, (net.minecraft.world.level.Level) world).map(Recipe.class::cast);
    }
    return Optional.empty();
}
Also used : Recipe(org.spongepowered.api.item.recipe.Recipe) CookingRecipe(org.spongepowered.api.item.recipe.cooking.CookingRecipe) AbstractCookingRecipe(net.minecraft.world.item.crafting.AbstractCookingRecipe) CraftingMenu(net.minecraft.world.inventory.CraftingMenu) StonecutterMenu(net.minecraft.world.inventory.StonecutterMenu) InventoryMenuAccessor(org.spongepowered.common.accessor.world.inventory.InventoryMenuAccessor) Container(net.minecraft.world.Container) CraftingContainer(net.minecraft.world.inventory.CraftingContainer) CraftingContainer(net.minecraft.world.inventory.CraftingContainer) InventoryMenu(net.minecraft.world.inventory.InventoryMenu) RecipeType(org.spongepowered.api.item.recipe.RecipeType) AbstractFurnaceBlockEntity(net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity) CampfireBlockEntity(net.minecraft.world.level.block.entity.CampfireBlockEntity) CraftingMenuAccessor(org.spongepowered.common.accessor.world.inventory.CraftingMenuAccessor) AbstractFurnaceBlockEntityAccessor(org.spongepowered.common.accessor.world.level.block.entity.AbstractFurnaceBlockEntityAccessor)

Example 2 with AbstractCookingRecipe

use of net.minecraft.world.item.crafting.AbstractCookingRecipe in project SpongeCommon by SpongePowered.

the class AbstractFurnaceBlockEntityMixin method impl$callInteruptSmeltEvent.

private void impl$callInteruptSmeltEvent() {
    if (this.cookingProgress > 0) {
        final ItemStackSnapshot fuel = ItemStackUtil.snapshotOf(this.items.get(1));
        final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
        final AbstractCookingRecipe recipe = this.impl$getCurrentRecipe();
        final CookingEvent.Interrupt event = SpongeEventFactory.createCookingEventInterrupt(cause, (FurnaceBlockEntity) this, Optional.of(fuel), Optional.ofNullable((CookingRecipe) recipe));
        SpongeCommon.post(event);
    }
}
Also used : CookingRecipe(org.spongepowered.api.item.recipe.cooking.CookingRecipe) AbstractCookingRecipe(net.minecraft.world.item.crafting.AbstractCookingRecipe) Cause(org.spongepowered.api.event.Cause) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) AbstractCookingRecipe(net.minecraft.world.item.crafting.AbstractCookingRecipe) CookingEvent(org.spongepowered.api.event.block.entity.CookingEvent)

Example 3 with AbstractCookingRecipe

use of net.minecraft.world.item.crafting.AbstractCookingRecipe in project SpongeCommon by SpongePowered.

the class AbstractFurnaceBlockEntityMixin method impl$throwFuelEventIfOrShrink.

// @Formatter:on
// Shrink Fuel
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;shrink(I)V"))
private void impl$throwFuelEventIfOrShrink(final ItemStack itemStack, final int quantity) {
    final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
    final ItemStackSnapshot fuel = ItemStackUtil.snapshotOf(itemStack);
    final ItemStackSnapshot shrinkedFuel = ItemStackUtil.snapshotOf(ItemStackUtil.cloneDefensive(itemStack, itemStack.getCount() - 1));
    final Transaction<ItemStackSnapshot> transaction = new Transaction<>(fuel, shrinkedFuel);
    final AbstractCookingRecipe recipe = this.impl$getCurrentRecipe();
    final CookingEvent.ConsumeFuel event = SpongeEventFactory.createCookingEventConsumeFuel(cause, (FurnaceBlockEntity) this, Optional.of(fuel), Optional.of((CookingRecipe) recipe), Collections.singletonList(transaction));
    SpongeCommon.post(event);
    if (event.isCancelled()) {
        this.cookingTotalTime = 0;
        return;
    }
    if (!transaction.isValid()) {
        return;
    }
    if (transaction.custom().isPresent()) {
        this.items.set(1, ItemStackUtil.fromSnapshotToNative(transaction.finalReplacement()));
    } else {
        // vanilla
        itemStack.shrink(quantity);
    }
}
Also used : Transaction(org.spongepowered.api.data.Transaction) CookingRecipe(org.spongepowered.api.item.recipe.cooking.CookingRecipe) AbstractCookingRecipe(net.minecraft.world.item.crafting.AbstractCookingRecipe) Cause(org.spongepowered.api.event.Cause) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) AbstractCookingRecipe(net.minecraft.world.item.crafting.AbstractCookingRecipe) CookingEvent(org.spongepowered.api.event.block.entity.CookingEvent) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 4 with AbstractCookingRecipe

use of net.minecraft.world.item.crafting.AbstractCookingRecipe in project SpongeCommon by SpongePowered.

the class AbstractFurnaceBlockEntityMixin method impl$resetCookTimeIfCancelled.

// Tick down
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Mth;clamp(III)I"))
private int impl$resetCookTimeIfCancelled(final int newCookTime, final int zero, final int totalCookTime) {
    final int clampedCookTime = Mth.clamp(newCookTime, zero, totalCookTime);
    final ItemStackSnapshot fuel = ItemStackUtil.snapshotOf(this.items.get(1));
    final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
    final AbstractCookingRecipe recipe = this.impl$getCurrentRecipe();
    final ItemStackSnapshot stack = ItemStackUtil.snapshotOf(this.items.get(0));
    final CookingEvent.Tick event = SpongeEventFactory.createCookingEventTick(cause, (FurnaceBlockEntity) this, stack, Optional.of(fuel), Optional.of((CookingRecipe) recipe));
    SpongeCommon.post(event);
    if (event.isCancelled()) {
        // dont tick down
        return this.cookingProgress;
    }
    return clampedCookTime;
}
Also used : CookingRecipe(org.spongepowered.api.item.recipe.cooking.CookingRecipe) AbstractCookingRecipe(net.minecraft.world.item.crafting.AbstractCookingRecipe) Cause(org.spongepowered.api.event.Cause) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) AbstractCookingRecipe(net.minecraft.world.item.crafting.AbstractCookingRecipe) CookingEvent(org.spongepowered.api.event.block.entity.CookingEvent) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

AbstractCookingRecipe (net.minecraft.world.item.crafting.AbstractCookingRecipe)4 CookingRecipe (org.spongepowered.api.item.recipe.cooking.CookingRecipe)4 Cause (org.spongepowered.api.event.Cause)3 CookingEvent (org.spongepowered.api.event.block.entity.CookingEvent)3 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)3 Redirect (org.spongepowered.asm.mixin.injection.Redirect)2 Container (net.minecraft.world.Container)1 CraftingContainer (net.minecraft.world.inventory.CraftingContainer)1 CraftingMenu (net.minecraft.world.inventory.CraftingMenu)1 InventoryMenu (net.minecraft.world.inventory.InventoryMenu)1 StonecutterMenu (net.minecraft.world.inventory.StonecutterMenu)1 AbstractFurnaceBlockEntity (net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity)1 CampfireBlockEntity (net.minecraft.world.level.block.entity.CampfireBlockEntity)1 Transaction (org.spongepowered.api.data.Transaction)1 Recipe (org.spongepowered.api.item.recipe.Recipe)1 RecipeType (org.spongepowered.api.item.recipe.RecipeType)1 CraftingMenuAccessor (org.spongepowered.common.accessor.world.inventory.CraftingMenuAccessor)1 InventoryMenuAccessor (org.spongepowered.common.accessor.world.inventory.InventoryMenuAccessor)1 AbstractFurnaceBlockEntityAccessor (org.spongepowered.common.accessor.world.level.block.entity.AbstractFurnaceBlockEntityAccessor)1