Search in sources :

Example 1 with IAnvilContainer

use of de.siphalor.nbtcrafting.util.IAnvilContainer in project nbt-crafting by Siphalor.

the class MixinAnvilContainerResultSlot method onItemTaken.

@Inject(method = "onTakeItem(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/item/ItemStack;)" + "Lnet/minecraft/item/ItemStack;", at = @At("RETURN"))
public void onItemTaken(PlayerEntity player, ItemStack stack, CallbackInfoReturnable<ItemStack> cir) {
    AnvilRecipe recipe = ((IAnvilContainer) container).nbtcrafting$getRecipe();
    if (recipe != null && originalBaseStack != null) {
        stack.onCraft(player.world, player, stack.getCount());
        if (!recipe.getBase().isEmpty()) {
            originalBaseStack.decrement(1);
            container.setStackInSlot(0, originalBaseStack);
        }
    }
    if (player instanceof ServerPlayerEntity) {
        if (!NbtCrafting.hasClientMod((ServerPlayerEntity) player)) {
            ((ServerPlayerEntity) player).networkHandler.sendPacket(new ContainerSlotUpdateS2CPacket(-1, 0, stack));
        }
    }
}
Also used : IAnvilContainer(de.siphalor.nbtcrafting.util.IAnvilContainer) AnvilRecipe(de.siphalor.nbtcrafting.recipe.AnvilRecipe) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ContainerSlotUpdateS2CPacket(net.minecraft.client.network.packet.ContainerSlotUpdateS2CPacket) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

AnvilRecipe (de.siphalor.nbtcrafting.recipe.AnvilRecipe)1 IAnvilContainer (de.siphalor.nbtcrafting.util.IAnvilContainer)1 ContainerSlotUpdateS2CPacket (net.minecraft.client.network.packet.ContainerSlotUpdateS2CPacket)1 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1