Search in sources :

Example 1 with StorageScannerTileEntity

use of mcjty.rftools.blocks.storagemonitor.StorageScannerTileEntity in project RFTools by McJty.

the class LevelEmitterTileEntity method getCurrentCount.

public int getCurrentCount() {
    ItemStack module = inventoryHelper.getStackInSlot(LevelEmitterContainer.SLOT_MODULE);
    int count = -1;
    if (!module.isEmpty()) {
        ItemStack matcher = inventoryHelper.getStackInSlot(LevelEmitterContainer.SLOT_ITEMMATCH);
        if (matcher.isEmpty()) {
            return count;
        }
        int dimension = RFToolsTools.getDimensionFromModule(module);
        BlockPos scannerPos = RFToolsTools.getPositionFromModule(module);
        WorldServer world = DimensionManager.getWorld(dimension);
        if (RFToolsTools.chunkLoaded(world, scannerPos)) {
            TileEntity te = world.getTileEntity(scannerPos);
            if (te instanceof StorageScannerTileEntity) {
                StorageScannerTileEntity scannerTE = (StorageScannerTileEntity) te;
                count = scannerTE.countItems(matcher, starred, oreDict);
            }
        }
    }
    return count;
}
Also used : SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity) StorageScannerTileEntity(mcjty.rftools.blocks.storagemonitor.StorageScannerTileEntity) LogicTileEntity(mcjty.rftools.blocks.logic.generic.LogicTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) WorldServer(net.minecraft.world.WorldServer) ItemStack(net.minecraft.item.ItemStack) StorageScannerTileEntity(mcjty.rftools.blocks.storagemonitor.StorageScannerTileEntity)

Example 2 with StorageScannerTileEntity

use of mcjty.rftools.blocks.storagemonitor.StorageScannerTileEntity in project RFTools by McJty.

the class StorageTerminalBlock method createServerContainer.

@Override
public Container createServerContainer(EntityPlayer entityPlayer, TileEntity tileEntity) {
    if (!entityPlayer.isSneaking()) {
        if (tileEntity instanceof StorageTerminalTileEntity) {
            StorageTerminalTileEntity terminalTileEntity = (StorageTerminalTileEntity) tileEntity;
            ItemStack module = terminalTileEntity.getStackInSlot(StorageTerminalContainer.SLOT_MODULE);
            if (!module.isEmpty()) {
                int dimension = RFToolsTools.getDimensionFromModule(module);
                BlockPos pos = RFToolsTools.getPositionFromModule(module);
                WorldServer world = DimensionManager.getWorld(dimension);
                if (!RFToolsTools.chunkLoaded(world, pos)) {
                    entityPlayer.sendStatusMessage(new TextComponentString(TextFormatting.YELLOW + "Storage scanner out of range!"), false);
                    return null;
                }
                TileEntity scannerTE = world.getTileEntity(pos);
                if (!(scannerTE instanceof StorageScannerTileEntity)) {
                    entityPlayer.sendStatusMessage(new TextComponentString(TextFormatting.YELLOW + "Storage scanner is missing!"), false);
                    return null;
                }
                return new StorageScannerContainer(entityPlayer, (IInventory) scannerTE, terminalTileEntity);
            }
        }
    }
    return super.createServerContainer(entityPlayer, tileEntity);
}
Also used : StorageScannerTileEntity(mcjty.rftools.blocks.storagemonitor.StorageScannerTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) StorageScannerContainer(mcjty.rftools.blocks.storagemonitor.StorageScannerContainer) BlockPos(net.minecraft.util.math.BlockPos) WorldServer(net.minecraft.world.WorldServer) ItemStack(net.minecraft.item.ItemStack) StorageScannerTileEntity(mcjty.rftools.blocks.storagemonitor.StorageScannerTileEntity) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 3 with StorageScannerTileEntity

use of mcjty.rftools.blocks.storagemonitor.StorageScannerTileEntity in project RFTools by McJty.

the class StorageTerminalTileEntity method craft.

@Override
@Nonnull
public int[] craft(EntityPlayer player, int n, boolean test) {
    ItemStack module = inventoryHelper.getStackInSlot(StorageTerminalContainer.SLOT_MODULE);
    if (module.isEmpty()) {
        // No module. Should not be possible
        return new int[0];
    }
    int dimension = RFToolsTools.getDimensionFromModule(module);
    BlockPos scannerPos = RFToolsTools.getPositionFromModule(module);
    WorldServer world = DimensionManager.getWorld(dimension);
    StorageScannerTileEntity scannerTE = null;
    if (RFToolsTools.chunkLoaded(world, scannerPos)) {
        TileEntity te = world.getTileEntity(scannerPos);
        if (te instanceof StorageScannerTileEntity) {
            scannerTE = (StorageScannerTileEntity) te;
        }
    }
    if (scannerTE == null) {
        // Scanner is not chunkloaded or not valid. Only use player inventory
        IItemSource itemSource = new InventoriesItemSource().add(player.inventory, 0);
        if (test) {
            return StorageCraftingTools.testCraftItems(player, n, craftingGrid.getActiveRecipe(), itemSource);
        } else {
            StorageCraftingTools.craftItems(player, n, craftingGrid.getActiveRecipe(), itemSource);
            return new int[0];
        }
    } else {
        // Delegate crafting to scanner
        return scannerTE.craft(player, n, test, craftingGrid.getActiveRecipe());
    }
}
Also used : SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity) StorageScannerTileEntity(mcjty.rftools.blocks.storagemonitor.StorageScannerTileEntity) LogicTileEntity(mcjty.rftools.blocks.logic.generic.LogicTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) WorldServer(net.minecraft.world.WorldServer) ItemStack(net.minecraft.item.ItemStack) StorageScannerTileEntity(mcjty.rftools.blocks.storagemonitor.StorageScannerTileEntity) Nonnull(javax.annotation.Nonnull)

Example 4 with StorageScannerTileEntity

use of mcjty.rftools.blocks.storagemonitor.StorageScannerTileEntity in project RFTools by McJty.

the class DumpScreenModule method mouseClick.

@Override
public void mouseClick(World world, int x, int y, boolean clicked, EntityPlayer player) {
    if ((!clicked) || player == null) {
        return;
    }
    if (BlockPosTools.INVALID.equals(coordinate)) {
        player.sendStatusMessage(new TextComponentString(TextFormatting.RED + "Module is not linked to storage scanner!"), false);
        return;
    }
    StorageScannerTileEntity scannerTileEntity = StorageControlScreenModule.getStorageScanner(dim, coordinate);
    if (scannerTileEntity == null) {
        return;
    }
    int xoffset = 5;
    if (x >= xoffset) {
        for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
            if (isShown(player.inventory.getStackInSlot(i))) {
                ItemStack stack = scannerTileEntity.injectStackFromScreen(player.inventory.getStackInSlot(i), player);
                player.inventory.setInventorySlotContents(i, stack);
            }
        }
        player.openContainer.detectAndSendChanges();
        return;
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) StorageScannerTileEntity(mcjty.rftools.blocks.storagemonitor.StorageScannerTileEntity) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 5 with StorageScannerTileEntity

use of mcjty.rftools.blocks.storagemonitor.StorageScannerTileEntity in project RFTools by McJty.

the class FindBlockAction method performServer.

@Override
public void performServer(EntityPlayer player, World world, @Nullable BlockPos pos, boolean extended) {
    if (pos != null) {
        // If we come here we know that on client side we couldn't find a suitable block in the players inventory.
        List<ItemStack> inventory = Collections.unmodifiableList(player.inventory.mainInventory);
        IBlockState state = world.getBlockState(pos);
        ItemStack result = state.getBlock().getItem(world, pos, state);
        if (result == null || result.isEmpty()) {
            return;
        }
        ItemStack storage = ItemStack.EMPTY;
        for (ItemStack stack : inventory) {
            if (!stack.isEmpty()) {
                if (stack.getItem() == ModularStorageSetup.storageModuleTabletItem) {
                    // Found!
                    storage = stack;
                    break;
                }
            }
        }
        if (storage.isEmpty()) {
            player.sendStatusMessage(new TextComponentString(TextFormatting.RED + "No storage tablet in inventory!"), false);
            return;
        }
        NBTTagCompound tagCompound = storage.getTagCompound();
        if (tagCompound == null || !tagCompound.hasKey("childDamage")) {
            player.sendStatusMessage(new TextComponentString(TextFormatting.RED + "No storage module in tablet!"), false);
            return;
        }
        int firstEmptyStack = player.inventory.getFirstEmptyStack();
        if (firstEmptyStack < 0) {
            player.sendStatusMessage(new TextComponentString(TextFormatting.RED + "No room in inventory for block!"), false);
            return;
        }
        int moduleDamage = tagCompound.getInteger("childDamage");
        ItemStack extracted = ItemStack.EMPTY;
        if (moduleDamage == META_FOR_SCANNER) {
            if (tagCompound.hasKey("monitorx")) {
                int monitordim = tagCompound.getInteger("monitordim");
                int monitorx = tagCompound.getInteger("monitorx");
                int monitory = tagCompound.getInteger("monitory");
                int monitorz = tagCompound.getInteger("monitorz");
                BlockPos mpos = new BlockPos(monitorx, monitory, monitorz);
                WorldServer w = DimensionManager.getWorld(monitordim);
                if (w == null || !RFToolsTools.chunkLoaded(w, mpos)) {
                    player.sendStatusMessage(new TextComponentString(TextFormatting.RED + "Storage scanner is out of range!"), false);
                } else {
                    TileEntity te = w.getTileEntity(mpos);
                    if (te instanceof StorageScannerTileEntity) {
                        StorageScannerTileEntity scanner = (StorageScannerTileEntity) te;
                        extracted = scanner.requestItem(result, result.getMaxStackSize(), true, false);
                        if (extracted.isEmpty()) {
                            extracted = scanner.requestItem(result, result.getMaxStackSize(), true, true);
                        }
                    }
                }
            } else {
                player.sendStatusMessage(new TextComponentString(TextFormatting.RED + "Storage module is not linked to a storage scanner!"), false);
            }
        } else if (moduleDamage == StorageModuleItem.STORAGE_REMOTE) {
            if (!tagCompound.hasKey("id")) {
                Logging.message(player, TextFormatting.YELLOW + "This remote storage module is not linked!");
            } else {
                RemoteStorageItemInventory storageInv = new RemoteStorageItemInventory(player, storage);
                for (int i = 0; i < storageInv.getSizeInventory(); i++) {
                    ItemStack s = storageInv.getStackInSlot(i);
                    if (!s.isEmpty() && stackEqualExact(result, s)) {
                        extracted = s;
                        storageInv.setInventorySlotContents(i, ItemStack.EMPTY);
                        break;
                    }
                }
            }
        } else {
            ModularStorageItemInventory storageInv = new ModularStorageItemInventory(player, storage);
            for (int i = 0; i < storageInv.getSizeInventory(); i++) {
                ItemStack s = storageInv.getStackInSlot(i);
                if (!s.isEmpty() && stackEqualExact(result, s)) {
                    extracted = s;
                    storageInv.setInventorySlotContents(i, ItemStack.EMPTY);
                    break;
                }
            }
        }
        if (!extracted.isEmpty()) {
            int currentItem = player.inventory.currentItem;
            if (currentItem == firstEmptyStack) {
                player.inventory.setInventorySlotContents(currentItem, extracted);
            } else {
                player.inventory.setInventorySlotContents(firstEmptyStack, inventory.get(currentItem));
                player.inventory.setInventorySlotContents(currentItem, extracted);
            }
            player.openContainer.detectAndSendChanges();
        }
    }
}
Also used : StorageScannerTileEntity(mcjty.rftools.blocks.storagemonitor.StorageScannerTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) RemoteStorageItemInventory(mcjty.rftools.blocks.storage.RemoteStorageItemInventory) IBlockState(net.minecraft.block.state.IBlockState) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockPos(net.minecraft.util.math.BlockPos) WorldServer(net.minecraft.world.WorldServer) ItemStack(net.minecraft.item.ItemStack) ModularStorageItemInventory(mcjty.rftools.blocks.storage.ModularStorageItemInventory) StorageScannerTileEntity(mcjty.rftools.blocks.storagemonitor.StorageScannerTileEntity) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

StorageScannerTileEntity (mcjty.rftools.blocks.storagemonitor.StorageScannerTileEntity)15 ItemStack (net.minecraft.item.ItemStack)12 TileEntity (net.minecraft.tileentity.TileEntity)11 BlockPos (net.minecraft.util.math.BlockPos)9 WorldServer (net.minecraft.world.WorldServer)5 StorageScannerContainer (mcjty.rftools.blocks.storagemonitor.StorageScannerContainer)4 Block (net.minecraft.block.Block)4 TextComponentString (net.minecraft.util.text.TextComponentString)4 IBlockState (net.minecraft.block.state.IBlockState)3 GenericBlock (mcjty.lib.container.GenericBlock)2 LogicTileEntity (mcjty.rftools.blocks.logic.generic.LogicTileEntity)2 ModularStorageItemContainer (mcjty.rftools.blocks.storage.ModularStorageItemContainer)2 RemoteStorageItemContainer (mcjty.rftools.blocks.storage.RemoteStorageItemContainer)2 GuiStorageScanner (mcjty.rftools.blocks.storagemonitor.GuiStorageScanner)2 ModifierContainer (mcjty.rftools.items.modifier.ModifierContainer)2 StorageFilterContainer (mcjty.rftools.items.storage.StorageFilterContainer)2 SPacketUpdateTileEntity (net.minecraft.network.play.server.SPacketUpdateTileEntity)2 World (net.minecraft.world.World)2 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1