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