Search in sources :

Example 11 with CraftItemStack

use of org.bukkit.craftbukkit.v.inventory.CraftItemStack in project Arclight by IzzelAliz.

the class AbstractFurnaceTileEntityMixin method arclight$furnaceBurn.

@Inject(method = "tick", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/tileentity/AbstractFurnaceTileEntity;getBurnTime(Lnet/minecraft/item/ItemStack;)I"))
public void arclight$furnaceBurn(CallbackInfo ci) {
    ItemStack itemStack = this.items.get(1);
    CraftItemStack fuel = CraftItemStack.asCraftMirror(itemStack);
    arclight$burnEvent = new FurnaceBurnEvent(CraftBlock.at(this.world, this.pos), fuel, getBurnTime(itemStack));
    Bukkit.getPluginManager().callEvent(arclight$burnEvent);
    if (arclight$burnEvent.isCancelled()) {
        ci.cancel();
        arclight$burnEvent = null;
    }
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v.inventory.CraftItemStack) FurnaceBurnEvent(org.bukkit.event.inventory.FurnaceBurnEvent) CraftItemStack(org.bukkit.craftbukkit.v.inventory.CraftItemStack) ItemStack(net.minecraft.item.ItemStack) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 12 with CraftItemStack

use of org.bukkit.craftbukkit.v.inventory.CraftItemStack in project Arclight by IzzelAliz.

the class AbstractFurnaceTileEntityMixin method smelt.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
private void smelt(@Nullable IRecipe<?> p_214007_1_) {
    if (p_214007_1_ != null && this.canSmelt(p_214007_1_)) {
        ItemStack itemstack = this.items.get(0);
        ItemStack itemstack1 = p_214007_1_.getRecipeOutput();
        ItemStack itemstack2 = this.items.get(2);
        CraftItemStack source = CraftItemStack.asCraftMirror(itemstack);
        org.bukkit.inventory.ItemStack result = CraftItemStack.asBukkitCopy(itemstack1);
        FurnaceSmeltEvent event = new FurnaceSmeltEvent(CraftBlock.at(world, pos), source, result);
        Bukkit.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return;
        }
        result = event.getResult();
        itemstack1 = CraftItemStack.asNMSCopy(result);
        if (!itemstack1.isEmpty()) {
            if (itemstack2.isEmpty()) {
                this.items.set(2, itemstack1.copy());
            } else if (CraftItemStack.asCraftMirror(itemstack2).isSimilar(result)) {
                itemstack2.grow(itemstack1.getCount());
            } else {
                return;
            }
        }
        if (!this.world.isRemote) {
            this.setRecipeUsed(p_214007_1_);
        }
        if (itemstack.getItem() == Blocks.WET_SPONGE.asItem() && !this.items.get(1).isEmpty() && this.items.get(1).getItem() == Items.BUCKET) {
            this.items.set(1, new ItemStack(Items.WATER_BUCKET));
        }
        itemstack.shrink(1);
    }
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v.inventory.CraftItemStack) CraftItemStack(org.bukkit.craftbukkit.v.inventory.CraftItemStack) ItemStack(net.minecraft.item.ItemStack) FurnaceSmeltEvent(org.bukkit.event.inventory.FurnaceSmeltEvent) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 13 with CraftItemStack

use of org.bukkit.craftbukkit.v.inventory.CraftItemStack in project Arclight by IzzelAliz.

the class HopperTileEntityMixin method arclight$moveItem.

@Redirect(method = "transferItemsOut", at = @At(value = "INVOKE", target = "Lnet/minecraft/tileentity/HopperTileEntity;putStackInInventoryAllSlots(Lnet/minecraft/inventory/IInventory;Lnet/minecraft/inventory/IInventory;Lnet/minecraft/item/ItemStack;Lnet/minecraft/util/Direction;)Lnet/minecraft/item/ItemStack;"))
public ItemStack arclight$moveItem(IInventory source, IInventory destination, ItemStack stack, Direction direction) {
    CraftItemStack original = CraftItemStack.asCraftMirror(stack);
    Inventory destinationInventory;
    // Have to special case large chests as they work oddly
    if (destination instanceof DoubleSidedInventory) {
        destinationInventory = new CraftInventoryDoubleChest(((DoubleSidedInventory) destination));
    } else {
        destinationInventory = ((IInventoryBridge) destination).getOwner().getInventory();
    }
    InventoryMoveItemEvent event = new InventoryMoveItemEvent(this.getOwner().getInventory(), original.clone(), destinationInventory, true);
    Bukkit.getPluginManager().callEvent(event);
    if (arclight$moveItem = event.isCancelled()) {
        // Delay hopper checks
        this.setTransferCooldown(8);
        return null;
    }
    return HopperTileEntity.putStackInInventoryAllSlots(source, destination, CraftItemStack.asNMSCopy(event.getItem()), direction);
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v.inventory.CraftItemStack) DoubleSidedInventory(net.minecraft.inventory.DoubleSidedInventory) IInventoryBridge(io.izzel.arclight.common.bridge.inventory.IInventoryBridge) CraftInventoryDoubleChest(org.bukkit.craftbukkit.v.inventory.CraftInventoryDoubleChest) InventoryMoveItemEvent(org.bukkit.event.inventory.InventoryMoveItemEvent) DoubleSidedInventory(net.minecraft.inventory.DoubleSidedInventory) Inventory(org.bukkit.inventory.Inventory) IInventory(net.minecraft.inventory.IInventory) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 14 with CraftItemStack

use of org.bukkit.craftbukkit.v.inventory.CraftItemStack in project Arclight by IzzelAliz.

the class HopperTileEntityMixin method arclight$pullItem.

@Redirect(method = "pullItemFromSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/tileentity/HopperTileEntity;putStackInInventoryAllSlots(Lnet/minecraft/inventory/IInventory;Lnet/minecraft/inventory/IInventory;Lnet/minecraft/item/ItemStack;Lnet/minecraft/util/Direction;)Lnet/minecraft/item/ItemStack;"))
private static ItemStack arclight$pullItem(IInventory source, IInventory destination, ItemStack stack, Direction direction) {
    CraftItemStack original = CraftItemStack.asCraftMirror(stack);
    Inventory sourceInventory;
    // Have to special case large chests as they work oddly
    if (source instanceof DoubleSidedInventory) {
        sourceInventory = new CraftInventoryDoubleChest(((DoubleSidedInventory) source));
    } else {
        sourceInventory = ((IInventoryBridge) source).getOwner().getInventory();
    }
    InventoryMoveItemEvent event = new InventoryMoveItemEvent(sourceInventory, original.clone(), ((IInventoryBridge) destination).getOwner().getInventory(), false);
    Bukkit.getPluginManager().callEvent(event);
    if (arclight$moveItem = event.isCancelled()) {
        if (destination instanceof HopperTileEntity) {
            // Delay hopper checks
            ((HopperTileEntity) destination).setTransferCooldown(8);
        } else if (destination instanceof HopperMinecartEntity) {
            // Delay hopper minecart checks
            ((HopperMinecartEntity) destination).setTransferTicker(4);
        }
        return null;
    }
    return HopperTileEntity.putStackInInventoryAllSlots(source, destination, CraftItemStack.asNMSCopy(event.getItem()), direction);
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v.inventory.CraftItemStack) HopperTileEntity(net.minecraft.tileentity.HopperTileEntity) DoubleSidedInventory(net.minecraft.inventory.DoubleSidedInventory) IInventoryBridge(io.izzel.arclight.common.bridge.inventory.IInventoryBridge) HopperMinecartEntity(net.minecraft.entity.item.minecart.HopperMinecartEntity) CraftInventoryDoubleChest(org.bukkit.craftbukkit.v.inventory.CraftInventoryDoubleChest) InventoryMoveItemEvent(org.bukkit.event.inventory.InventoryMoveItemEvent) DoubleSidedInventory(net.minecraft.inventory.DoubleSidedInventory) Inventory(org.bukkit.inventory.Inventory) IInventory(net.minecraft.inventory.IInventory) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 15 with CraftItemStack

use of org.bukkit.craftbukkit.v.inventory.CraftItemStack in project Arclight by IzzelAliz.

the class SmokingRecipeMixin method bridge$toBukkitRecipe.

@Override
public Recipe bridge$toBukkitRecipe() {
    CraftItemStack result = CraftItemStack.asCraftMirror(this.result);
    CraftSmokingRecipe recipe = new CraftSmokingRecipe(CraftNamespacedKey.fromMinecraft(this.getId()), result, CraftRecipe.toBukkit(this.ingredient), this.experience, this.cookTime);
    recipe.setGroup(this.group);
    return recipe;
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v.inventory.CraftItemStack) CraftSmokingRecipe(org.bukkit.craftbukkit.v.inventory.CraftSmokingRecipe)

Aggregations

CraftItemStack (org.bukkit.craftbukkit.v.inventory.CraftItemStack)17 ItemStack (net.minecraft.item.ItemStack)8 Overwrite (org.spongepowered.asm.mixin.Overwrite)6 IInventory (net.minecraft.inventory.IInventory)5 IInventoryBridge (io.izzel.arclight.common.bridge.inventory.IInventoryBridge)3 DoubleSidedInventory (net.minecraft.inventory.DoubleSidedInventory)3 BlockPos (net.minecraft.util.math.BlockPos)3 CraftInventoryDoubleChest (org.bukkit.craftbukkit.v.inventory.CraftInventoryDoubleChest)3 InventoryMoveItemEvent (org.bukkit.event.inventory.InventoryMoveItemEvent)3 Inventory (org.bukkit.inventory.Inventory)3 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)2 IWorldPosCallableBridge (io.izzel.arclight.common.bridge.util.IWorldPosCallableBridge)2 Random (java.util.Random)2 EnchantmentData (net.minecraft.enchantment.EnchantmentData)2 Ingredient (net.minecraft.item.crafting.Ingredient)2 Bukkit (org.bukkit.Bukkit)2 Final (org.spongepowered.asm.mixin.Final)2 Mixin (org.spongepowered.asm.mixin.Mixin)2 Shadow (org.spongepowered.asm.mixin.Shadow)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2