use of net.minecraft.world.inventory.AnvilMenu in project SpongeCommon by SpongePowered.
the class AnvilMenuMixin_Inventory method impl$throwUpdateAnvilEvent.
@Inject(method = "createResult", at = @At(value = "RETURN"))
private void impl$throwUpdateAnvilEvent(final CallbackInfo ci) {
if (!ShouldFire.UPDATE_ANVIL_EVENT || !PhaseTracker.SERVER.onSidedThread()) {
return;
}
final ItemStack itemstack = this.inputSlots.getItem(0);
final ItemStack itemstack2 = this.inputSlots.getItem(1);
final ItemStack result = this.resultSlots.getItem(0);
final UpdateAnvilEvent event = InventoryEventFactory.callUpdateAnvilEvent((AnvilMenu) (Object) this, itemstack, itemstack2, result, this.itemName == null ? "" : this.itemName, this.cost.get(), this.repairItemCountCost);
final ItemStackSnapshot finalItem = event.result().finalReplacement();
if (event.isCancelled() || finalItem.isEmpty()) {
this.resultSlots.setItem(0, ItemStack.EMPTY);
this.cost.set(0);
this.repairItemCountCost = 0;
((AnvilMenu) (Object) this).broadcastChanges();
return;
}
this.resultSlots.setItem(0, ItemStackUtil.fromSnapshotToNative(event.result().finalReplacement()));
this.cost.set(event.costs().finalReplacement().levelCost());
this.repairItemCountCost = event.costs().finalReplacement().materialCost();
((AnvilMenu) (Object) this).broadcastChanges();
}
Aggregations