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();
}
}
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);
}
Aggregations