Search in sources :

Example 1 with AnvilMenu

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();
}
Also used : UpdateAnvilEvent(org.spongepowered.api.event.item.inventory.UpdateAnvilEvent) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) ItemStack(net.minecraft.world.item.ItemStack) AnvilMenu(net.minecraft.world.inventory.AnvilMenu) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

AnvilMenu (net.minecraft.world.inventory.AnvilMenu)1 ItemStack (net.minecraft.world.item.ItemStack)1 UpdateAnvilEvent (org.spongepowered.api.event.item.inventory.UpdateAnvilEvent)1 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1