// This is called client side. public List<ClientScreenModule> getClientScreenModules() { if (clientScreenModules == null) { needsServerData = false; clientScreenModules = new ArrayList<ClientScreenModule>(); for (int i = 0; i < inventoryHelper.getCount(); i++) { ItemStack itemStack = inventoryHelper.getStackInSlot(i); if (itemStack != null && itemStack.getItem() instanceof ModuleProvider) { ModuleProvider moduleProvider = (ModuleProvider) itemStack.getItem(); ClientScreenModule clientScreenModule; try { clientScreenModule = moduleProvider.getClientScreenModule().newInstance(); } catch (InstantiationException e) { e.printStackTrace(); continue; } catch (IllegalAccessException e) { e.printStackTrace(); continue; } clientScreenModule.setupFromNBT( itemStack.getTagCompound(), worldObj.provider.dimensionId, xCoord, yCoord, zCoord); clientScreenModules.add(clientScreenModule); if (clientScreenModule.needsServerData()) { needsServerData = true; } } else { clientScreenModules.add( null); // To keep the indexing correct so that the modules correspond with there slot // number. } } } return clientScreenModules; }
private void writeBufferToNBT(NBTTagCompound tagCompound) { NBTTagList bufferTagList = new NBTTagList(); for (int i = ScreenContainer.SLOT_MODULES; i < inventoryHelper.getCount(); i++) { ItemStack stack = inventoryHelper.getStackInSlot(i); NBTTagCompound nbtTagCompound = new NBTTagCompound(); if (stack != null) { stack.writeToNBT(nbtTagCompound); } bufferTagList.appendTag(nbtTagCompound); } tagCompound.setTag("Items", bufferTagList); }
public void updateModuleData(int slot, NBTTagCompound tagCompound) { ItemStack stack = inventoryHelper.getStackInSlot(slot); stack.setTagCompound(tagCompound); screenModules = null; clientScreenModules = null; computerModules.clear(); markDirty(); }
private void readBufferFromNBT(NBTTagCompound tagCompound) { NBTTagList bufferTagList = tagCompound.getTagList("Items", Constants.NBT.TAG_COMPOUND); for (int i = 0; i < bufferTagList.tagCount(); i++) { NBTTagCompound nbtTagCompound = bufferTagList.getCompoundTagAt(i); inventoryHelper.setStackInSlot( i + ScreenContainer.SLOT_MODULES, ItemStack.loadItemStackFromNBT(nbtTagCompound)); } resetModules(); }
// This is called server side. public List<ScreenModule> getScreenModules() { if (screenModules == null) { totalRfPerTick = 0; screenModules = new ArrayList<ScreenModule>(); for (int i = 0; i < inventoryHelper.getCount(); i++) { ItemStack itemStack = inventoryHelper.getStackInSlot(i); if (itemStack != null && itemStack.getItem() instanceof ModuleProvider) { ModuleProvider moduleProvider = (ModuleProvider) itemStack.getItem(); ScreenModule screenModule; try { screenModule = moduleProvider.getServerScreenModule().newInstance(); } catch (InstantiationException e) { e.printStackTrace(); continue; } catch (IllegalAccessException e) { e.printStackTrace(); continue; } screenModule.setupFromNBT( itemStack.getTagCompound(), worldObj.provider.dimensionId, xCoord, yCoord, zCoord); screenModules.add(screenModule); totalRfPerTick += screenModule.getRfPerTick(); if (screenModule instanceof ComputerScreenModule) { ComputerScreenModule computerScreenModule = (ComputerScreenModule) screenModule; String tag = computerScreenModule.getTag(); if (!computerModules.containsKey(tag)) { computerModules.put(tag, new ArrayList<ComputerScreenModule>()); } computerModules.get(tag).add(computerScreenModule); } } else { screenModules.add( null); // To keep the indexing correct so that the modules correspond with there slot // number. } } } return screenModules; }
@Override public void setInventorySlotContents(int index, ItemStack stack) { inventoryHelper.setInventorySlotContents(getInventoryStackLimit(), index, stack); resetModules(); }
@Override public ItemStack decrStackSize(int index, int amount) { resetModules(); return inventoryHelper.decrStackSize(index, amount); }
@Override public ItemStack getStackInSlot(int index) { return inventoryHelper.getStackInSlot(index); }
@Override public int getSizeInventory() { return inventoryHelper.getCount(); }