Search in sources :

Example 1 with ISeedStorageControllable

use of com.infinityraider.agricraft.tiles.storage.ISeedStorageControllable in project AgriCraft by AgriCraft.

the class MessageGuiSeedStorageClearSeed method processMessage.

@Override
protected void processMessage(MessageContext ctx) {
    final Container container = this.player.openContainer;
    if (container instanceof ContainerSeedStorageBase) {
        final ContainerSeedStorageBase storage = ((ContainerSeedStorageBase) container);
        final TileEntity tileEntity = storage.getTile();
        if (tileEntity instanceof ISeedStorageControllable) {
            ((ISeedStorageControllable) tileEntity).clearLockedSeed();
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Container(net.minecraft.inventory.Container) ISeedStorageControllable(com.infinityraider.agricraft.tiles.storage.ISeedStorageControllable) ContainerSeedStorageBase(com.infinityraider.agricraft.container.ContainerSeedStorageBase)

Example 2 with ISeedStorageControllable

use of com.infinityraider.agricraft.tiles.storage.ISeedStorageControllable in project AgriCraft by AgriCraft.

the class ContainerSeedStorageBase method transferStackInSlot.

/**
     * Handles shift clicking in the inventory, return the stack that was
     * transferred
     */
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int clickedSlot) {
    ItemStack originalStackInSlot = null;
    Slot slot = this.inventorySlots.get(clickedSlot);
    if (slot != null && slot.getHasStack()) {
        ItemStack notMergedStack = slot.getStack();
        originalStackInSlot = notMergedStack.copy();
        //try to move item from the player's inventory into the container
        AgriSeed seed = AgriApi.getSeedRegistry().valueOf(notMergedStack).orElse(null);
        if (seed != null && seed.getStat().isAnalyzed()) {
            ISeedStorageControllable controllable = this.getControllable(notMergedStack).orElse(null);
            if (controllable != null && controllable.hasLockedSeed()) {
                ItemStack locked = controllable.getLockedSeed().map(s -> s.toStack()).orElse(null);
                if (notMergedStack.getItem() != locked.getItem() || notMergedStack.getItemDamage() != locked.getItemDamage()) {
                    return null;
                }
            }
            if (this.addSeedToStorage(notMergedStack)) {
                notMergedStack.stackSize = 0;
            } else {
                return null;
            }
        }
        if (notMergedStack.stackSize == 0) {
            slot.putStack(null);
        } else {
            slot.onSlotChanged();
        }
        if (notMergedStack.stackSize == originalStackInSlot.stackSize) {
            return null;
        }
        slot.onPickupFromSlot(player, notMergedStack);
    }
    return originalStackInSlot;
}
Also used : MessageContainerSeedStorage(com.infinityraider.agricraft.network.MessageContainerSeedStorage) ISeedStorageControllable(com.infinityraider.agricraft.tiles.storage.ISeedStorageControllable) AgriApi(com.infinityraider.agricraft.api.v1.AgriApi) ContainerBase(com.infinityraider.infinitylib.container.ContainerBase) SeedStorageSlot(com.infinityraider.agricraft.tiles.storage.SeedStorageSlot) FMLCommonHandler(net.minecraftforge.fml.common.FMLCommonHandler) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) Side(net.minecraftforge.fml.relauncher.Side) EntityPlayer(net.minecraft.entity.player.EntityPlayer) AgriSeed(com.infinityraider.agricraft.api.v1.seed.AgriSeed) ISeedStorageController(com.infinityraider.agricraft.tiles.storage.ISeedStorageController) Slot(net.minecraft.inventory.Slot) Optional(java.util.Optional) TileEntity(net.minecraft.tileentity.TileEntity) ISeedStorageControllable(com.infinityraider.agricraft.tiles.storage.ISeedStorageControllable) SeedStorageSlot(com.infinityraider.agricraft.tiles.storage.SeedStorageSlot) Slot(net.minecraft.inventory.Slot) AgriSeed(com.infinityraider.agricraft.api.v1.seed.AgriSeed) ItemStack(net.minecraft.item.ItemStack)

Example 3 with ISeedStorageControllable

use of com.infinityraider.agricraft.tiles.storage.ISeedStorageControllable in project AgriCraft by AgriCraft.

the class ContainerSeedStorageBase method moveStackFromTileEntityToPlayer.

/**
     * Tries to move an item stack form the correct tile entity to the player's
     * inventory
     */
public void moveStackFromTileEntityToPlayer(int slotId, ItemStack stack) {
    ISeedStorageControllable controllable = this.getControllable(stack).orElse(null);
    if (controllable == null) {
        return;
    }
    ItemStack stackToMove = controllable.getStackForSlotId(slotId);
    if (stack == null) {
        return;
    }
    if (stackToMove == null || stackToMove.getItem() == null) {
        return;
    }
    stackToMove.stackSize = stack.stackSize > stackToMove.stackSize ? stackToMove.stackSize : stack.stackSize;
    stackToMove.setTagCompound(controllable.getStackForSlotId(slotId).getTagCompound());
    if (this.mergeItemStack(stackToMove, 0, PLAYER_INVENTORY_SIZE, false)) {
        if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
            //this method is only called form the gui client side, so we need to manually tell the server to execute it there
            new MessageContainerSeedStorage(stack, slotId).sendToServer();
        } else {
            //on the server decrease the size of the stack, where it is synced to the client
            controllable.decreaseStackSizeInSlot(slotId, stack.stackSize - stackToMove.stackSize);
        }
    }
}
Also used : ISeedStorageControllable(com.infinityraider.agricraft.tiles.storage.ISeedStorageControllable) MessageContainerSeedStorage(com.infinityraider.agricraft.network.MessageContainerSeedStorage) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ISeedStorageControllable (com.infinityraider.agricraft.tiles.storage.ISeedStorageControllable)3 MessageContainerSeedStorage (com.infinityraider.agricraft.network.MessageContainerSeedStorage)2 ItemStack (net.minecraft.item.ItemStack)2 TileEntity (net.minecraft.tileentity.TileEntity)2 AgriApi (com.infinityraider.agricraft.api.v1.AgriApi)1 AgriSeed (com.infinityraider.agricraft.api.v1.seed.AgriSeed)1 ContainerSeedStorageBase (com.infinityraider.agricraft.container.ContainerSeedStorageBase)1 ISeedStorageController (com.infinityraider.agricraft.tiles.storage.ISeedStorageController)1 SeedStorageSlot (com.infinityraider.agricraft.tiles.storage.SeedStorageSlot)1 ContainerBase (com.infinityraider.infinitylib.container.ContainerBase)1 List (java.util.List)1 Optional (java.util.Optional)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)1 Container (net.minecraft.inventory.Container)1 Slot (net.minecraft.inventory.Slot)1 FMLCommonHandler (net.minecraftforge.fml.common.FMLCommonHandler)1 Side (net.minecraftforge.fml.relauncher.Side)1