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;
}
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);
}
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());
}
}
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;
}
}
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();
}
}
}
Aggregations