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