Skip to content

Commit

Permalink
Fix recipe events
Browse files Browse the repository at this point in the history
  • Loading branch information
aromaa committed Nov 6, 2024
1 parent e47e871 commit 8e39e2b
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private void handleCrafting(final Player player, final ClickContainerEvent event
SpongeEventFactory.createCraftItemEventCraft(PhaseTracker.getCauseStackManager().currentCause(),
ContainerUtil.fromNative(this.menu), craftedItem, this.craftingInventory, event.cursorTransaction(),
Optional.ofNullable(this.onTakeRecipe).map(r -> (CraftingRecipe) r.value()),
Optional.ofNullable(this.onTakeRecipe).map(r -> (ResourceKey) (Object) r.id()),
Optional.ofNullable(this.onTakeRecipe).map(r -> (ResourceKey) (Object) r.id().location()),
Optional.of(this.craftingInventory.result()), event.transactions());
SpongeCommon.post(craftEvent);
this.handleEventResults(player, craftEvent);
Expand All @@ -290,7 +290,7 @@ private void handleCraftingPreview(final Player player, final ClickContainerEven
final SlotTransaction previewTransaction = this.getPreviewTransaction(this.craftingInventory.result(), event.transactions());
final var recipe = sp.serverLevel().recipeAccess().getRecipeFor(RecipeType.CRAFTING, this.craftingContainer.asCraftInput(), player.level());
final CraftItemEvent.Preview previewEvent = SpongeEventFactory.createCraftItemEventPreview(event.cause(), (Container) this.menu, this.craftingInventory, event.cursorTransaction(), previewTransaction,
recipe.map(RecipeHolder::value).map(CraftingRecipe.class::cast), recipe.map(h -> h.id()).map(ResourceKey.class::cast), Optional.empty(), event.transactions());
recipe.map(RecipeHolder::value).map(CraftingRecipe.class::cast), recipe.map(r -> (ResourceKey) (Object) r.id().location()), Optional.empty(), event.transactions());
SpongeCommon.post(previewEvent);
this.handleEventResults(player, previewEvent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Optional<ClickContainerEvent> createInventoryEvent(final List<SlotTransaction> s
final CraftItemEvent.Preview event = SpongeEventFactory.createCraftItemEventPreview(currentCause,
ContainerUtil.fromNative(this.menu), this.craftingInventory, new Transaction<>(cursor, cursor), previewTransaction,
recipe.map(RecipeHolder::value).map(CraftingRecipe.class::cast),
recipe.map(RecipeHolder::id).map(ResourceKey.class::cast),
recipe.map(r -> (ResourceKey) (Object) r.id().location()),
Optional.empty(), slotTransactions);
return Optional.of(event);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ Optional<ClickContainerEvent> createInventoryEvent(
event = SpongeEventFactory.createClickContainerEventRecipeAll(cause, (Container) this.menu,
this.craftingInventory, cursorTransaction, preview,
Optional.of(this.recipe).map(RecipeHolder::value).map(CraftingRecipe.class::cast),
Optional.of(this.recipe).map(RecipeHolder::id).map(ResourceKey.class::cast),
Optional.of(this.recipe).map(r -> (ResourceKey) (Object) r.id().location()),
Optional.empty(), slotTransactions);
} else {
event = SpongeEventFactory.createClickContainerEventRecipeSingle(cause, (Container) this.menu,
this.craftingInventory, cursorTransaction, preview,
Optional.of(this.recipe).map(RecipeHolder::value).map(CraftingRecipe.class::cast),
Optional.of(this.recipe).map(RecipeHolder::id).map(ResourceKey.class::cast),
Optional.of(this.recipe).map(r -> (ResourceKey) (Object) r.id().location()),
Optional.empty(), slotTransactions);
}
return Optional.of(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public abstract class AbstractFurnaceBlockEntityMixin extends BaseContainerBlock
final SlotTransaction transaction = new SlotTransaction(((FurnaceBlockEntity) entity).inventory().slot(1).get(), fuel, shrinkedFuel);
final var recipe = ((AbstractFurnaceBlockEntityMixin) (Object) entity).bridge$getCurrentRecipe();
final CookingEvent.ConsumeFuel event = SpongeEventFactory.createCookingEventConsumeFuel(cause, (FurnaceBlockEntity) entity, Optional.of(fuel),
recipe.map(r -> (CookingRecipe) r.value()), recipe.map(r -> (ResourceKey) (Object) r.id()), Collections.singletonList(transaction));
recipe.map(r -> (CookingRecipe) r.value()), recipe.map(r -> (ResourceKey) (Object) r.id().location()), Collections.singletonList(transaction));
SpongeCommon.post(event);
if (event.isCancelled()) {
((AbstractFurnaceBlockEntityMixin) (Object) entity).cookingTotalTime = 0;
Expand Down Expand Up @@ -154,7 +154,7 @@ public abstract class AbstractFurnaceBlockEntityMixin extends BaseContainerBlock
final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
final var recipe = this.bridge$getCurrentRecipe();
final CookingEvent.Interrupt event = SpongeEventFactory.createCookingEventInterrupt(cause, (FurnaceBlockEntity) this, Optional.of(fuel),
recipe.map(r -> (CookingRecipe) r.value()), recipe.map(r -> (ResourceKey) (Object) r.id()));
recipe.map(r -> (CookingRecipe) r.value()), recipe.map(r -> (ResourceKey) (Object) r.id().location()));
SpongeCommon.post(event);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public abstract class CampfireBlockEntityMixin {
final ItemStackSnapshot stack = ItemStackUtil.snapshotOf(mixinSelf.items.get(i));
final RecipeHolder<?> recipe = mixinSelf.impl$cookingRecipe[i];
final CookingEvent.Tick event = SpongeEventFactory.createCookingEventTick(cause, (Campfire) self, stack, Optional.empty(),
Optional.ofNullable(recipe).map(r -> (CookingRecipe) r.value()), Optional.ofNullable(recipe).map(r -> (ResourceKey) (Object) r.id()));
Optional.ofNullable(recipe).map(r -> (CookingRecipe) r.value()), Optional.ofNullable(recipe).map(r -> (ResourceKey) (Object) r.id().location()));
SpongeCommon.post(event);
if (event.isCancelled()) {
mixinSelf.cookingProgress[i]--;
Expand All @@ -109,7 +109,7 @@ public abstract class CampfireBlockEntityMixin {
final SlotTransaction transaction = new SlotTransaction(((Campfire) self).inventory().slot(i).get(), ItemStackUtil.snapshotOf(itemStack1), ItemStackSnapshot.empty());
final RecipeHolder<?> recipe = mixinSelf.impl$cookingRecipe[i];
final CookingEvent.Finish event = SpongeEventFactory.createCookingEventFinish(cause, (Campfire) self,
Optional.empty(), Optional.ofNullable(recipe).map(r -> (CookingRecipe) r.value()), Optional.ofNullable(recipe).map(r -> (ResourceKey) (Object) r.id()),
Optional.empty(), Optional.ofNullable(recipe).map(r -> (CookingRecipe) r.value()), Optional.ofNullable(recipe).map(r -> (ResourceKey) (Object) r.id().location()),
Collections.singletonList(transaction));
SpongeCommon.post(event);
mixinSelf.impl$cookingRecipe[i] = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ public abstract class AbstractFurnaceBlockEntityMixin_Vanilla extends BaseContai
final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
if (entity.cookingProgress == 0) { // Start
final CookingEvent.Start event = SpongeEventFactory.createCookingEventStart(cause, (FurnaceBlockEntity) entityIn, Optional.of(fuel),
Optional.of((CookingRecipe) recipe.value()), Optional.of((ResourceKey) (Object) recipe.id()));
Optional.of((CookingRecipe) recipe.value()), Optional.of((ResourceKey) (Object) recipe.id().location()));
SpongeCommon.post(event);
return !event.isCancelled();
} else { // Tick up
final ItemStackSnapshot cooking = ItemStackUtil.snapshotOf(entity.items.get(0));
final CookingEvent.Tick event = SpongeEventFactory.createCookingEventTick(cause, (FurnaceBlockEntity) entityIn, cooking, Optional.of(fuel),
Optional.of((CookingRecipe) recipe.value()), Optional.of((ResourceKey) (Object) recipe.id()));
Optional.of((CookingRecipe) recipe.value()), Optional.of((ResourceKey) (Object) recipe.id().location()));
SpongeCommon.post(event);
return !event.isCancelled();
}
Expand All @@ -119,7 +119,7 @@ public abstract class AbstractFurnaceBlockEntityMixin_Vanilla extends BaseContai
final var recipe = entity.bridge$getCurrentRecipe();
final ItemStackSnapshot cooking = ItemStackUtil.snapshotOf(entity.items.get(0));
final CookingEvent.Tick event = SpongeEventFactory.createCookingEventTick(cause, (FurnaceBlockEntity) entityIn, cooking, Optional.of(fuel),
recipe.map(r -> (CookingRecipe) r.value()), recipe.map(r -> (ResourceKey) (Object) r.id()));
recipe.map(r -> (CookingRecipe) r.value()), recipe.map(r -> (ResourceKey) (Object) r.id().location()));
SpongeCommon.post(event);
if (event.isCancelled()) {
return entity.cookingProgress; // dont tick down
Expand Down Expand Up @@ -179,7 +179,7 @@ public abstract class AbstractFurnaceBlockEntityMixin_Vanilla extends BaseContai
}
final Optional<ItemStackSnapshot> fuel = hasFuel && !slots.get(1).isEmpty() ? Optional.of(ItemStackUtil.snapshotOf(slots.get(1))) : Optional.empty();
final CookingEvent.Finish event = SpongeEventFactory.createCookingEventFinish(cause, entity,
fuel, Optional.of((CookingRecipe) recipe.value()), Optional.of((ResourceKey) (Object) recipe.id()), Collections.unmodifiableList(transactions));
fuel, Optional.of((CookingRecipe) recipe.value()), Optional.of((ResourceKey) (Object) recipe.id().location()), Collections.unmodifiableList(transactions));
SpongeCommon.post(event);

for (final SlotTransaction transaction : transactions) {
Expand Down

0 comments on commit 8e39e2b

Please sign in to comment.