Search in sources :

Example 1 with CookingRecipe

use of org.spongepowered.api.item.recipe.cooking.CookingRecipe 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 2 with CookingRecipe

use of org.spongepowered.api.item.recipe.cooking.CookingRecipe 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 3 with CookingRecipe

use of org.spongepowered.api.item.recipe.cooking.CookingRecipe in project SpongeCommon by SpongePowered.

the class CampfireBlockEntityMixin method impl$assembleCampfireResult.

@Surrogate
private void impl$assembleCampfireResult(final CallbackInfo ci, final int i, final ItemStack itemStack, final Container iInventory, final ItemStack itemStack1, final BlockPos blockPos) {
    final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
    final ItemStackSnapshot snapshot = ItemStackUtil.snapshotOf(itemStack1);
    final CookingEvent.Finish event = SpongeEventFactory.createCookingEventFinish(cause, (Campfire) this, Collections.singletonList(snapshot), Optional.empty(), Optional.ofNullable((CookingRecipe) this.impl$cookingRecipe[i]));
    SpongeCommon.post(event);
    this.impl$cookingRecipe[i] = null;
}
Also used : CampfireCookingRecipe(net.minecraft.world.item.crafting.CampfireCookingRecipe) CookingRecipe(org.spongepowered.api.item.recipe.cooking.CookingRecipe) Cause(org.spongepowered.api.event.Cause) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) CookingEvent(org.spongepowered.api.event.block.entity.CookingEvent) Surrogate(org.spongepowered.asm.mixin.injection.Surrogate)

Example 4 with CookingRecipe

use of org.spongepowered.api.item.recipe.cooking.CookingRecipe in project SpongeCommon by SpongePowered.

the class CampfireBlockEntityMixin method impl$canCook.

// Tick up
@Inject(method = "cook", locals = LocalCapture.CAPTURE_FAILEXCEPTION, at = @At(value = "FIELD", target = "Lnet/minecraft/world/level/block/entity/CampfireBlockEntity;cookingProgress:[I", ordinal = 1))
private void impl$canCook(final CallbackInfo ci, final int i, final ItemStack itemStack) {
    final boolean isEmpty = itemStack.isEmpty();
    if (!isEmpty) {
        final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
        final ItemStackSnapshot stack = ItemStackUtil.snapshotOf(this.items.get(i));
        final CookingEvent.Tick event = SpongeEventFactory.createCookingEventTick(cause, (Campfire) this, stack, Optional.empty(), Optional.ofNullable((CookingRecipe) impl$cookingRecipe[i]));
        SpongeCommon.post(event);
        if (event.isCancelled()) {
            this.cookingProgress[i]--;
        }
    }
}
Also used : CampfireCookingRecipe(net.minecraft.world.item.crafting.CampfireCookingRecipe) CookingRecipe(org.spongepowered.api.item.recipe.cooking.CookingRecipe) Cause(org.spongepowered.api.event.Cause) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) CookingEvent(org.spongepowered.api.event.block.entity.CookingEvent) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with CookingRecipe

use of org.spongepowered.api.item.recipe.cooking.CookingRecipe 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

Cause (org.spongepowered.api.event.Cause)7 CookingEvent (org.spongepowered.api.event.block.entity.CookingEvent)7 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)7 CookingRecipe (org.spongepowered.api.item.recipe.cooking.CookingRecipe)7 AbstractCookingRecipe (net.minecraft.world.item.crafting.AbstractCookingRecipe)5 Redirect (org.spongepowered.asm.mixin.injection.Redirect)3 CampfireCookingRecipe (net.minecraft.world.item.crafting.CampfireCookingRecipe)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 Transaction (org.spongepowered.api.data.Transaction)1 Surrogate (org.spongepowered.asm.mixin.injection.Surrogate)1