Search in sources :

Example 6 with CookingRecipe

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

the class AbstractFurnaceBlockEntityMixin method impl$checkIfCanSmelt.

// Tick up and Start
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity;canBurn(Lnet/minecraft/world/item/crafting/Recipe;)Z", ordinal = 1))
private boolean impl$checkIfCanSmelt(final AbstractFurnaceBlockEntity furnace, final Recipe<?> recipe) {
    if (!this.shadow$canBurn(recipe)) {
        return false;
    }
    final ItemStackSnapshot fuel = ItemStackUtil.snapshotOf(this.items.get(1));
    final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
    if (this.cookingProgress == 0) {
        // Start
        final CookingEvent.Start event = SpongeEventFactory.createCookingEventStart(cause, (FurnaceBlockEntity) this, Optional.of(fuel), Optional.of((CookingRecipe) recipe));
        SpongeCommon.post(event);
        return !event.isCancelled();
    } else {
        // Tick up
        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);
        return !event.isCancelled();
    }
}
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) CookingEvent(org.spongepowered.api.event.block.entity.CookingEvent) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 7 with CookingRecipe

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

the class AbstractFurnaceBlockEntityMixin method impl$afterSmeltItem.

// Finish
@Inject(method = "burn", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;shrink(I)V"))
private void impl$afterSmeltItem(final Recipe<?> recipe, final CallbackInfo ci) {
    final ItemStackSnapshot fuel = ItemStackUtil.snapshotOf(this.items.get(1));
    final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
    final ItemStackSnapshot snapshot = ItemStackUtil.snapshotOf(recipe.getResultItem());
    final CookingEvent.Finish event = SpongeEventFactory.createCookingEventFinish(cause, (FurnaceBlockEntity) this, Collections.singletonList(snapshot), 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) CookingEvent(org.spongepowered.api.event.block.entity.CookingEvent) Inject(org.spongepowered.asm.mixin.injection.Inject)

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