diff --git a/client/me/ItemRepo.java b/client/me/ItemRepo.java index 497e1180..1549d330 100644 --- a/client/me/ItemRepo.java +++ b/client/me/ItemRepo.java @@ -6,17 +6,13 @@ import java.util.ArrayList; import java.util.Collections; import java.util.regex.Pattern; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import appeng.api.AEApi; -import appeng.api.config.FuzzyMode; import appeng.api.config.SearchBoxMode; import appeng.api.config.Settings; import appeng.api.config.SortOrder; -import appeng.api.config.Upgrades; import appeng.api.config.ViewItems; import appeng.api.config.YesNo; -import appeng.api.implementations.items.IUpgradeModule; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; import appeng.client.gui.widgets.IScrollSource; @@ -25,11 +21,7 @@ import appeng.core.AEConfig; import appeng.items.storage.ItemViewCell; import appeng.util.ItemSorters; import appeng.util.Platform; -import appeng.util.item.AEItemStack; -import appeng.util.prioitylist.FuzzyPriorityList; import appeng.util.prioitylist.IPartitionList; -import appeng.util.prioitylist.MergedPriorityList; -import appeng.util.prioitylist.PrecisePriorityList; import cpw.mods.fml.relauncher.ReflectionHelper; public class ItemRepo @@ -46,7 +38,8 @@ public class ItemRepo public String searchString = ""; private String innerSearch = ""; - public ItemRepo(IScrollSource src, ISortSource sortSrc) { + public ItemRepo(IScrollSource src, ISortSource sortSrc) + { this.src = src; this.sortSrc = sortSrc; } @@ -91,69 +84,7 @@ public class ItemRepo public void setViewCell(ItemStack[] list) { - myPartitionList = null; - MergedPriorityList myMergedList = new MergedPriorityList(); - - for (ItemStack currentViewCell : list) - { - if ( currentViewCell == null ) - continue; - - if ( (currentViewCell.getItem() instanceof ItemViewCell) ) - { - boolean hasInverter = false; - boolean hasFuzzy = false; - IItemList priorityList = AEApi.instance().storage().createItemList(); - - ItemViewCell vc = (ItemViewCell) currentViewCell.getItem(); - IInventory upgrades = vc.getUpgradesInventory( currentViewCell ); - IInventory config = vc.getConfigInventory( currentViewCell ); - FuzzyMode fzMode = vc.getFuzzyMode( currentViewCell ); - - hasInverter = false; - hasFuzzy = false; - - for (int x = 0; x < upgrades.getSizeInventory(); x++) - { - ItemStack is = upgrades.getStackInSlot( x ); - if ( is != null && is.getItem() instanceof IUpgradeModule ) - { - Upgrades u = ((IUpgradeModule) is.getItem()).getType( is ); - if ( u != null ) - { - switch (u) - { - case FUZZY: - hasFuzzy = true; - break; - case INVERTER: - hasInverter = true; - break; - default: - } - } - } - } - - for (int x = 0; x < config.getSizeInventory(); x++) - { - ItemStack is = config.getStackInSlot( x ); - if ( is != null ) - priorityList.add( AEItemStack.create( is ) ); - } - - if ( !priorityList.isEmpty() ) - { - if ( hasFuzzy ) - myMergedList.addNewList( new FuzzyPriorityList( priorityList, fzMode ), !hasInverter ); - else - myMergedList.addNewList( new PrecisePriorityList( priorityList ), !hasInverter ); - - myPartitionList = myMergedList; - } - } - } - + myPartitionList = ItemViewCell.createFilter( list ); updateView(); } diff --git a/container/implementations/ContainerCraftingTerm.java b/container/implementations/ContainerCraftingTerm.java index 41836cc2..c07ae362 100644 --- a/container/implementations/ContainerCraftingTerm.java +++ b/container/implementations/ContainerCraftingTerm.java @@ -49,7 +49,7 @@ public class ContainerCraftingTerm extends ContainerMEMonitorable implements IAE for (int x = 0; x < 3; x++) addSlotToContainer( craftingSlots[x + y * 3] = new SlotCraftingMatrix( this, crafting, x + y * 3, 37 + x * 18, -72 + y * 18 ) ); - addSlotToContainer( outputSlot = new SlotCraftingTerm( getPlayerInv().player, mySrc, powerSrc, montiorable, crafting, crafting, output, 131, -72 + 18 ) ); + addSlotToContainer( outputSlot = new SlotCraftingTerm( getPlayerInv().player, mySrc, powerSrc, montiorable, crafting, crafting, output, 131, -72 + 18, this ) ); bindPlayerInventory( ip, 0, 0 ); diff --git a/container/implementations/ContainerMEMonitorable.java b/container/implementations/ContainerMEMonitorable.java index bb3e2fc9..fefbb483 100644 --- a/container/implementations/ContainerMEMonitorable.java +++ b/container/implementations/ContainerMEMonitorable.java @@ -1,347 +1,357 @@ -package appeng.container.implementations; - -import java.io.IOException; -import java.nio.BufferOverflowException; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.ICrafting; -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.AEApi; -import appeng.api.config.Actionable; -import appeng.api.config.PowerMultiplier; -import appeng.api.config.SecurityPermissions; -import appeng.api.config.Settings; -import appeng.api.config.SortDir; -import appeng.api.config.SortOrder; -import appeng.api.config.ViewItems; -import appeng.api.implementations.guiobjects.IPortableCell; -import appeng.api.implementations.tiles.IMEChest; -import appeng.api.implementations.tiles.IViewCellStorage; -import appeng.api.networking.IGrid; -import appeng.api.networking.IGridHost; -import appeng.api.networking.IGridNode; -import appeng.api.networking.energy.IEnergyGrid; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.networking.storage.IBaseMonitor; -import appeng.api.parts.IPart; -import appeng.api.storage.IMEMonitor; -import appeng.api.storage.IMEMonitorHandlerReceiver; -import appeng.api.storage.ITerminalHost; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IItemList; -import appeng.api.util.IConfigManager; -import appeng.api.util.IConfigureableObject; -import appeng.container.AEBaseContainer; -import appeng.container.guisync.GuiSync; -import appeng.container.slot.SlotRestrictedInput; -import appeng.container.slot.SlotRestrictedInput.PlaceableItemType; -import appeng.core.AELog; -import appeng.core.sync.network.NetworkHandler; -import appeng.core.sync.packets.PacketMEInventoryUpdate; -import appeng.core.sync.packets.PacketValueConfig; -import appeng.me.helpers.ChannelPowerSrc; -import appeng.util.ConfigManager; -import appeng.util.IConfigManagerHost; -import appeng.util.Platform; - -public class ContainerMEMonitorable extends AEBaseContainer implements IConfigManagerHost, IConfigureableObject, IMEMonitorHandlerReceiver -{ - - final IMEMonitor monitor; - final IItemList items = AEApi.instance().storage().createItemList(); - - IConfigManager serverCM; - IConfigManager clientCM; - - @GuiSync(99) - public boolean canAccessViewCells = false; - - @GuiSync(98) - public boolean hasPower = false; - - public SlotRestrictedInput cellView[] = new SlotRestrictedInput[5]; - - public IConfigManagerHost gui; - private IGridNode networkNode; - - public IGridNode getNetworkNode() - { - return networkNode; - } - +package appeng.container.implementations; + +import java.io.IOException; +import java.nio.BufferOverflowException; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.ICrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.AEApi; +import appeng.api.config.Actionable; +import appeng.api.config.PowerMultiplier; +import appeng.api.config.SecurityPermissions; +import appeng.api.config.Settings; +import appeng.api.config.SortDir; +import appeng.api.config.SortOrder; +import appeng.api.config.ViewItems; +import appeng.api.implementations.guiobjects.IPortableCell; +import appeng.api.implementations.tiles.IMEChest; +import appeng.api.implementations.tiles.IViewCellStorage; +import appeng.api.networking.IGrid; +import appeng.api.networking.IGridHost; +import appeng.api.networking.IGridNode; +import appeng.api.networking.energy.IEnergyGrid; +import appeng.api.networking.security.BaseActionSource; +import appeng.api.networking.storage.IBaseMonitor; +import appeng.api.parts.IPart; +import appeng.api.storage.IMEMonitor; +import appeng.api.storage.IMEMonitorHandlerReceiver; +import appeng.api.storage.ITerminalHost; +import appeng.api.storage.data.IAEItemStack; +import appeng.api.storage.data.IItemList; +import appeng.api.util.IConfigManager; +import appeng.api.util.IConfigureableObject; +import appeng.container.AEBaseContainer; +import appeng.container.guisync.GuiSync; +import appeng.container.slot.SlotRestrictedInput; +import appeng.container.slot.SlotRestrictedInput.PlaceableItemType; +import appeng.core.AELog; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketMEInventoryUpdate; +import appeng.core.sync.packets.PacketValueConfig; +import appeng.me.helpers.ChannelPowerSrc; +import appeng.util.ConfigManager; +import appeng.util.IConfigManagerHost; +import appeng.util.Platform; + +public class ContainerMEMonitorable extends AEBaseContainer implements IConfigManagerHost, IConfigureableObject, IMEMonitorHandlerReceiver +{ + + final IMEMonitor monitor; + final IItemList items = AEApi.instance().storage().createItemList(); + + IConfigManager serverCM; + IConfigManager clientCM; + + @GuiSync(99) + public boolean canAccessViewCells = false; + + @GuiSync(98) + public boolean hasPower = false; + + public SlotRestrictedInput cellView[] = new SlotRestrictedInput[5]; + + public IConfigManagerHost gui; + private IGridNode networkNode; + + public IGridNode getNetworkNode() + { + return networkNode; + } + protected ContainerMEMonitorable(InventoryPlayer ip, ITerminalHost montiorable, boolean bindInventory) { - super( ip, montiorable instanceof TileEntity ? (TileEntity) montiorable : null, montiorable instanceof IPart ? (IPart) montiorable : null ); - - clientCM = new ConfigManager( this ); - - clientCM.registerSetting( Settings.SORT_BY, SortOrder.NAME ); - clientCM.registerSetting( Settings.VIEW_MODE, ViewItems.ALL ); - clientCM.registerSetting( Settings.SORT_DIRECTION, SortDir.ASCENDING ); - - if ( Platform.isServer() ) - { - serverCM = montiorable.getConfigManager(); - - monitor = montiorable.getItemInventory(); - if ( monitor != null ) - { - monitor.addListener( this, null ); - - cellInv = monitor; - - if ( montiorable instanceof IPortableCell ) - powerSrc = (IPortableCell) montiorable; - else if ( montiorable instanceof IMEChest ) - powerSrc = (IMEChest) montiorable; - else if ( montiorable instanceof IGridHost ) - { - IGridNode node = ((IGridHost) montiorable).getGridNode( ForgeDirection.UNKNOWN ); - if ( node != null ) - { - networkNode = node; - IGrid g = node.getGrid(); - if ( g != null ) - powerSrc = new ChannelPowerSrc( networkNode, (IEnergyGrid) g.getCache( IEnergyGrid.class ) ); - } - } - } - else - isContainerValid = false; - } - else - monitor = null; - - canAccessViewCells = false; - if ( montiorable instanceof IViewCellStorage ) - { - for (int y = 0; y < 5; y++) - { - cellView[y] = new SlotRestrictedInput( PlaceableItemType.VIEWCELL, ((IViewCellStorage) montiorable).getViewCellStorage(), y, 206, y * 18 + 8, - invPlayer ); - cellView[y].allowEdit = canAccessViewCells; - addSlotToContainer( cellView[y] ); - } - } - - if ( bindInventory ) - bindPlayerInventory( ip, 0, 0 ); - } - - public ContainerMEMonitorable(InventoryPlayer ip, ITerminalHost montiorable) { - this( ip, montiorable, true ); - } - - @Override - public void detectAndSendChanges() - { - if ( Platform.isServer() ) - { - for (Enum set : serverCM.getSettings()) - { - Enum sideLocal = serverCM.getSetting( set ); - Enum sideRemote = clientCM.getSetting( set ); - - if ( sideLocal != sideRemote ) - { - clientCM.putSetting( set, sideLocal ); - for (int j = 0; j < this.crafters.size(); ++j) - { - try - { - NetworkHandler.instance.sendTo( new PacketValueConfig( set.name(), sideLocal.name() ), (EntityPlayerMP) this.crafters.get( j ) ); - } - catch (IOException e) - { - AELog.error( e ); - } - } - } - } - - if ( !items.isEmpty() ) - { - try - { - IItemList monitorCache = monitor.getStorageList(); - - PacketMEInventoryUpdate piu = new PacketMEInventoryUpdate(); - - for (IAEItemStack is : items) - { - IAEItemStack send = monitorCache.findPrecise( is ); - if ( send == null ) - { - is.setStackSize( 0 ); - piu.appendItem( is ); - } - else - piu.appendItem( send ); - } - - if ( !piu.isEmpty() ) - { - items.resetStatus(); - - for (Object c : this.crafters) - { - if ( c instanceof EntityPlayer ) - NetworkHandler.instance.sendTo( piu, (EntityPlayerMP) c ); - } - } - } - catch (IOException e) - { - AELog.error( e ); - } - } - - updatePowerStatus(); - - boolean oldCanAccessViewCells = canAccessViewCells; - canAccessViewCells = hasAccess( SecurityPermissions.BUILD, false ); - if ( canAccessViewCells != oldCanAccessViewCells ) - { - for (int y = 0; y < 5; y++) - { - if ( cellView[y] != null ) - cellView[y].allowEdit = canAccessViewCells; - } - } - - super.detectAndSendChanges(); - } - } - - protected void updatePowerStatus() - { - try - { - if ( networkNode != null ) - hasPower = networkNode.isActive(); - else if ( powerSrc instanceof IEnergyGrid ) - hasPower = ((IEnergyGrid) powerSrc).isNetworkPowered(); - else - hasPower = powerSrc.extractAEPower( 1, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > 0.8; - } - catch (Throwable t) - { - // :P - } - } - - @Override - public void addCraftingToCrafters(ICrafting c) - { - super.addCraftingToCrafters( c ); - queueInventory( c ); - } - - public void queueInventory(ICrafting c) - { - if ( Platform.isServer() && c instanceof EntityPlayer && monitor != null ) - { - try - { - PacketMEInventoryUpdate piu = new PacketMEInventoryUpdate(); - IItemList monitorCache = monitor.getStorageList(); - - for (IAEItemStack send : monitorCache) - { - try - { - piu.appendItem( send ); - } - catch (BufferOverflowException boe) - { - NetworkHandler.instance.sendTo( piu, (EntityPlayerMP) c ); - - piu = new PacketMEInventoryUpdate(); - piu.appendItem( send ); - } - } - - NetworkHandler.instance.sendTo( piu, (EntityPlayerMP) c ); - } - catch (IOException e) - { - AELog.error( e ); - } - - } - } - - @Override - public void onListUpdate() - { - for (Object c : this.crafters) - { - if ( c instanceof ICrafting ) - { - ICrafting cr = (ICrafting) c; - queueInventory( cr ); - } - } - } - - @Override - public void onUpdate(String field, Object oldValue, Object newValue) - { - if ( field.equals( "canAccessViewCells" ) ) - { - for (int y = 0; y < 5; y++) - if ( cellView[y] != null ) - cellView[y].allowEdit = canAccessViewCells; - } - - super.onUpdate( field, oldValue, newValue ); - } - - @Override - public void onContainerClosed(EntityPlayer player) - { - super.onContainerClosed( player ); - if ( monitor != null ) - monitor.removeListener( this ); - } - - @Override - public void removeCraftingFromCrafters(ICrafting c) - { - super.removeCraftingFromCrafters( c ); - - if ( this.crafters.isEmpty() && monitor != null ) - monitor.removeListener( this ); - } - - @Override - public void postChange(IBaseMonitor monitor, Iterable change, BaseActionSource source) - { - for (IAEItemStack is : change) - items.add( is ); - } - - @Override - public boolean isValid(Object verificationToken) - { - return true; - } - - @Override - public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue) - { - if ( gui != null ) - gui.updateSetting( manager, settingName, newValue ); - } - - @Override - public IConfigManager getConfigManager() - { - if ( Platform.isServer() ) - return serverCM; - return clientCM; - } - -} + super( ip, montiorable instanceof TileEntity ? (TileEntity) montiorable : null, montiorable instanceof IPart ? (IPart) montiorable : null ); + + clientCM = new ConfigManager( this ); + + clientCM.registerSetting( Settings.SORT_BY, SortOrder.NAME ); + clientCM.registerSetting( Settings.VIEW_MODE, ViewItems.ALL ); + clientCM.registerSetting( Settings.SORT_DIRECTION, SortDir.ASCENDING ); + + if ( Platform.isServer() ) + { + serverCM = montiorable.getConfigManager(); + + monitor = montiorable.getItemInventory(); + if ( monitor != null ) + { + monitor.addListener( this, null ); + + cellInv = monitor; + + if ( montiorable instanceof IPortableCell ) + powerSrc = (IPortableCell) montiorable; + else if ( montiorable instanceof IMEChest ) + powerSrc = (IMEChest) montiorable; + else if ( montiorable instanceof IGridHost ) + { + IGridNode node = ((IGridHost) montiorable).getGridNode( ForgeDirection.UNKNOWN ); + if ( node != null ) + { + networkNode = node; + IGrid g = node.getGrid(); + if ( g != null ) + powerSrc = new ChannelPowerSrc( networkNode, (IEnergyGrid) g.getCache( IEnergyGrid.class ) ); + } + } + } + else + isContainerValid = false; + } + else + monitor = null; + + canAccessViewCells = false; + if ( montiorable instanceof IViewCellStorage ) + { + for (int y = 0; y < 5; y++) + { + cellView[y] = new SlotRestrictedInput( PlaceableItemType.VIEWCELL, ((IViewCellStorage) montiorable).getViewCellStorage(), y, 206, y * 18 + 8, + invPlayer ); + cellView[y].allowEdit = canAccessViewCells; + addSlotToContainer( cellView[y] ); + } + } + + if ( bindInventory ) + bindPlayerInventory( ip, 0, 0 ); + } + + public ContainerMEMonitorable(InventoryPlayer ip, ITerminalHost montiorable) { + this( ip, montiorable, true ); + } + + @Override + public void detectAndSendChanges() + { + if ( Platform.isServer() ) + { + for (Enum set : serverCM.getSettings()) + { + Enum sideLocal = serverCM.getSetting( set ); + Enum sideRemote = clientCM.getSetting( set ); + + if ( sideLocal != sideRemote ) + { + clientCM.putSetting( set, sideLocal ); + for (int j = 0; j < this.crafters.size(); ++j) + { + try + { + NetworkHandler.instance.sendTo( new PacketValueConfig( set.name(), sideLocal.name() ), (EntityPlayerMP) this.crafters.get( j ) ); + } + catch (IOException e) + { + AELog.error( e ); + } + } + } + } + + if ( !items.isEmpty() ) + { + try + { + IItemList monitorCache = monitor.getStorageList(); + + PacketMEInventoryUpdate piu = new PacketMEInventoryUpdate(); + + for (IAEItemStack is : items) + { + IAEItemStack send = monitorCache.findPrecise( is ); + if ( send == null ) + { + is.setStackSize( 0 ); + piu.appendItem( is ); + } + else + piu.appendItem( send ); + } + + if ( !piu.isEmpty() ) + { + items.resetStatus(); + + for (Object c : this.crafters) + { + if ( c instanceof EntityPlayer ) + NetworkHandler.instance.sendTo( piu, (EntityPlayerMP) c ); + } + } + } + catch (IOException e) + { + AELog.error( e ); + } + } + + updatePowerStatus(); + + boolean oldCanAccessViewCells = canAccessViewCells; + canAccessViewCells = hasAccess( SecurityPermissions.BUILD, false ); + if ( canAccessViewCells != oldCanAccessViewCells ) + { + for (int y = 0; y < 5; y++) + { + if ( cellView[y] != null ) + cellView[y].allowEdit = canAccessViewCells; + } + } + + super.detectAndSendChanges(); + } + } + + protected void updatePowerStatus() + { + try + { + if ( networkNode != null ) + hasPower = networkNode.isActive(); + else if ( powerSrc instanceof IEnergyGrid ) + hasPower = ((IEnergyGrid) powerSrc).isNetworkPowered(); + else + hasPower = powerSrc.extractAEPower( 1, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > 0.8; + } + catch (Throwable t) + { + // :P + } + } + + @Override + public void addCraftingToCrafters(ICrafting c) + { + super.addCraftingToCrafters( c ); + queueInventory( c ); + } + + public void queueInventory(ICrafting c) + { + if ( Platform.isServer() && c instanceof EntityPlayer && monitor != null ) + { + try + { + PacketMEInventoryUpdate piu = new PacketMEInventoryUpdate(); + IItemList monitorCache = monitor.getStorageList(); + + for (IAEItemStack send : monitorCache) + { + try + { + piu.appendItem( send ); + } + catch (BufferOverflowException boe) + { + NetworkHandler.instance.sendTo( piu, (EntityPlayerMP) c ); + + piu = new PacketMEInventoryUpdate(); + piu.appendItem( send ); + } + } + + NetworkHandler.instance.sendTo( piu, (EntityPlayerMP) c ); + } + catch (IOException e) + { + AELog.error( e ); + } + + } + } + + @Override + public void onListUpdate() + { + for (Object c : this.crafters) + { + if ( c instanceof ICrafting ) + { + ICrafting cr = (ICrafting) c; + queueInventory( cr ); + } + } + } + + @Override + public void onUpdate(String field, Object oldValue, Object newValue) + { + if ( field.equals( "canAccessViewCells" ) ) + { + for (int y = 0; y < 5; y++) + if ( cellView[y] != null ) + cellView[y].allowEdit = canAccessViewCells; + } + + super.onUpdate( field, oldValue, newValue ); + } + + @Override + public void onContainerClosed(EntityPlayer player) + { + super.onContainerClosed( player ); + if ( monitor != null ) + monitor.removeListener( this ); + } + + @Override + public void removeCraftingFromCrafters(ICrafting c) + { + super.removeCraftingFromCrafters( c ); + + if ( this.crafters.isEmpty() && monitor != null ) + monitor.removeListener( this ); + } + + @Override + public void postChange(IBaseMonitor monitor, Iterable change, BaseActionSource source) + { + for (IAEItemStack is : change) + items.add( is ); + } + + @Override + public boolean isValid(Object verificationToken) + { + return true; + } + + @Override + public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue) + { + if ( gui != null ) + gui.updateSetting( manager, settingName, newValue ); + } + + @Override + public IConfigManager getConfigManager() + { + if ( Platform.isServer() ) + return serverCM; + return clientCM; + } + + public ItemStack[] getViewCells() + { + ItemStack[] list = new ItemStack[cellView.length]; + + for (int x = 0; x < cellView.length; x++) + list[x] = cellView[x].getStack(); + + return list; + } +} diff --git a/container/implementations/ContainerPatternTerm.java b/container/implementations/ContainerPatternTerm.java index 6175d52b..4811fb36 100644 --- a/container/implementations/ContainerPatternTerm.java +++ b/container/implementations/ContainerPatternTerm.java @@ -36,6 +36,7 @@ import appeng.container.slot.SlotRestrictedInput; import appeng.container.slot.SlotRestrictedInput.PlaceableItemType; import appeng.core.sync.packets.PacketPatternSlot; import appeng.helpers.IContainerCraftingPacket; +import appeng.items.storage.ItemViewCell; import appeng.parts.reporting.PartPatternTerminal; import appeng.tile.inventory.AppEngInternalInventory; import appeng.tile.inventory.IAEAppEngInventory; @@ -61,7 +62,8 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA public PartPatternTerminal ct; - public ContainerPatternTerm(InventoryPlayer ip, ITerminalHost montiorable) { + public ContainerPatternTerm(InventoryPlayer ip, ITerminalHost montiorable) + { super( ip, montiorable, false ); ct = (PartPatternTerminal) montiorable; @@ -73,7 +75,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA for (int x = 0; x < 3; x++) addSlotToContainer( craftingSlots[x + y * 3] = new SlotFakeCraftingMatrix( crafting, x + y * 3, 18 + x * 18, -76 + y * 18 ) ); - addSlotToContainer( craftSlot = new SlotPatternTerm( ip.player, mySrc, powerSrc, montiorable, crafting, patternInv, cOut, 110, -76 + 18, this, 2 ) ); + addSlotToContainer( craftSlot = new SlotPatternTerm( ip.player, mySrc, powerSrc, montiorable, crafting, patternInv, cOut, 110, -76 + 18, this, 2, this ) ); craftSlot.IIcon = -1; for (int y = 0; y < 3; y++) @@ -352,7 +354,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA if ( ic.getStackInSlot( x ) != null ) { ItemStack pulled = Platform.extractItemsByRecipe( powerSrc, mySrc, storage, p.worldObj, r, is, ic, ic.getStackInSlot( x ), x, all, - Actionable.MODULATE ); + Actionable.MODULATE, ItemViewCell.createFilter( getViewCells() ) ); real.setInventorySlotContents( x, pulled ); } } diff --git a/container/slot/SlotCraftingTerm.java b/container/slot/SlotCraftingTerm.java index b775dbc8..bef86f18 100644 --- a/container/slot/SlotCraftingTerm.java +++ b/container/slot/SlotCraftingTerm.java @@ -17,7 +17,9 @@ import appeng.api.storage.IStorageMonitorable; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; import appeng.container.ContainerNull; +import appeng.helpers.IContainerCraftingPacket; import appeng.helpers.InventoryAction; +import appeng.items.storage.ItemViewCell; import appeng.util.InventoryAdaptor; import appeng.util.Platform; import appeng.util.inv.AdaptorPlayerHand; @@ -32,15 +34,18 @@ public class SlotCraftingTerm extends AppEngCraftingSlot private final BaseActionSource mySrc; private final IEnergySource energySrc; private final IStorageMonitorable storage; + private final IContainerCraftingPacket container; public SlotCraftingTerm(EntityPlayer player, BaseActionSource mySrc, IEnergySource energySrc, IStorageMonitorable storage, IInventory cMatrix, - IInventory secondMatrix, IInventory output, int x, int y) { + IInventory secondMatrix, IInventory output, int x, int y, IContainerCraftingPacket ccp) + { super( player, cMatrix, output, 0, x, y ); this.energySrc = energySrc; this.storage = storage; this.mySrc = mySrc; pattern = cMatrix; craftInv = secondMatrix; + container = ccp; } public IInventory getCraftingMatrix() @@ -114,7 +119,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot if ( pattern.getStackInSlot( x ) != null ) { set[x] = Platform.extractItemsByRecipe( energySrc, mySrc, inv, p.worldObj, r, is, ic, pattern.getStackInSlot( x ), x, all, - Actionable.MODULATE ); + Actionable.MODULATE, ItemViewCell.createFilter( container.getViewCells() ) ); ic.setInventorySlotContents( x, set[x] ); } } diff --git a/container/slot/SlotPatternTerm.java b/container/slot/SlotPatternTerm.java index d8f0e16a..83cb9c01 100644 --- a/container/slot/SlotPatternTerm.java +++ b/container/slot/SlotPatternTerm.java @@ -11,6 +11,7 @@ import appeng.api.networking.security.BaseActionSource; import appeng.api.storage.IStorageMonitorable; import appeng.core.sync.AppEngPacket; import appeng.core.sync.packets.PacketPatternSlot; +import appeng.helpers.IContainerCraftingPacket; public class SlotPatternTerm extends SlotCraftingTerm { @@ -19,8 +20,9 @@ public class SlotPatternTerm extends SlotCraftingTerm IOptionalSlotHost host; public SlotPatternTerm(EntityPlayer player, BaseActionSource mySrc, IEnergySource energySrc, IStorageMonitorable storage, IInventory cMatrix, - IInventory secondMatrix, IInventory output, int x, int y, IOptionalSlotHost h, int grpnum) { - super( player, mySrc, energySrc, storage, cMatrix, secondMatrix, output, x, y ); + IInventory secondMatrix, IInventory output, int x, int y, IOptionalSlotHost h, int grpnum, IContainerCraftingPacket c) + { + super( player, mySrc, energySrc, storage, cMatrix, secondMatrix, output, x, y, c ); host = h; groupNum = grpnum; diff --git a/core/features/ColoredItemDefinition.java b/core/features/ColoredItemDefinition.java index 65bd9fd7..5a2b1521 100644 --- a/core/features/ColoredItemDefinition.java +++ b/core/features/ColoredItemDefinition.java @@ -39,7 +39,7 @@ public class ColoredItemDefinition implements AEColoredItemDefinition { ItemStackSrc is = colors[color.ordinal()]; - if ( comparableItem == null ) + if ( comparableItem == null || is == null ) return false; return comparableItem.getItem() == is.item && comparableItem.getItemDamage() == is.damage; diff --git a/core/sync/packets/PacketNEIRecipe.java b/core/sync/packets/PacketNEIRecipe.java index 783339d4..bf81588b 100644 --- a/core/sync/packets/PacketNEIRecipe.java +++ b/core/sync/packets/PacketNEIRecipe.java @@ -32,8 +32,10 @@ import appeng.container.ContainerNull; import appeng.core.sync.AppEngPacket; import appeng.core.sync.network.INetworkInfo; import appeng.helpers.IContainerCraftingPacket; +import appeng.items.storage.ItemViewCell; import appeng.util.Platform; import appeng.util.item.AEItemStack; +import appeng.util.prioitylist.IPartitionList; public class PacketNEIRecipe extends AppEngPacket { @@ -41,7 +43,8 @@ public class PacketNEIRecipe extends AppEngPacket ItemStack[][] recipe; // automatic. - public PacketNEIRecipe(ByteBuf stream) throws IOException { + public PacketNEIRecipe(ByteBuf stream) throws IOException + { ByteArrayInputStream bytes = new ByteArrayInputStream( stream.array() ); bytes.skip( stream.readerIndex() ); NBTTagCompound comp = CompressedStreamTools.readCompressed( bytes ); @@ -50,13 +53,13 @@ public class PacketNEIRecipe extends AppEngPacket recipe = new ItemStack[9][]; for (int x = 0; x < recipe.length; x++) { - NBTTagList list = comp.getTagList( "#"+x, 10 ); + NBTTagList list = comp.getTagList( "#" + x, 10 ); if ( list.tagCount() > 0 ) { - recipe[x] = new ItemStack[ list.tagCount() ]; - for ( int y = 0; y < list.tagCount(); y++ ) + recipe[x] = new ItemStack[list.tagCount()]; + for (int y = 0; y < list.tagCount(); y++) { - recipe[x][y] = ItemStack.loadItemStackFromNBT( list.getCompoundTagAt(y) ); + recipe[x][y] = ItemStack.loadItemStackFromNBT( list.getCompoundTagAt( y ) ); } } } @@ -91,12 +94,12 @@ public class PacketNEIRecipe extends AppEngPacket InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 ); for (int x = 0; x < 9; x++) { - if ( recipe[x] != null && recipe[x].length > 0 ) + if ( recipe[x] != null && recipe[x].length > 0 ) { ic.setInventorySlotContents( x, recipe[x][0] ); } } - + IRecipe r = Platform.findMatchingRecipe( ic, pmp.worldObj ); if ( r != null && security.hasPermission( player, SecurityPermissions.EXTRACT ) ) @@ -107,6 +110,7 @@ public class PacketNEIRecipe extends AppEngPacket { IMEMonitor stor = inv.getItemInventory(); IItemList all = stor.getStorageList(); + IPartitionList filter = ItemViewCell.createFilter( cct.getViewCells() ); for (int x = 0; x < craftMatrix.getSizeInventory(); x++) { @@ -138,27 +142,30 @@ public class PacketNEIRecipe extends AppEngPacket if ( PatternItem != null && currentItem == null ) { - ItemStack whichItem = Platform.extractItemsByRecipe( energy, cct.getSource(), stor, player.worldObj, r, - is, ic, PatternItem, x, all, realForFake ); - + ItemStack whichItem = Platform.extractItemsByRecipe( energy, cct.getSource(), stor, player.worldObj, r, is, ic, + PatternItem, x, all, realForFake, filter ); + if ( whichItem == null ) { - for ( int y = 0; y < recipe[x].length; y++ ) + for (int y = 0; y < recipe[x].length; y++) { IAEItemStack request = AEItemStack.create( recipe[x][y] ); if ( request != null ) { - request.setStackSize( 1 ); - IAEItemStack out = Platform.poweredExtraction( energy, stor, request, cct.getSource() ); - if ( out != null ) + if ( filter == null || filter.isListed( request ) ) { - whichItem = out.getItemStack(); - break; + request.setStackSize( 1 ); + IAEItemStack out = Platform.poweredExtraction( energy, stor, request, cct.getSource() ); + if ( out != null ) + { + whichItem = out.getItemStack(); + break; + } } } } } - + craftMatrix.setInventorySlotContents( x, whichItem ); } } @@ -171,7 +178,8 @@ public class PacketNEIRecipe extends AppEngPacket } // api - public PacketNEIRecipe(NBTTagCompound recipe) throws IOException { + public PacketNEIRecipe(NBTTagCompound recipe) throws IOException + { ByteBuf data = Unpooled.buffer(); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); diff --git a/crafting/CraftingTreeProcess.java b/crafting/CraftingTreeProcess.java index 1ae2c7e8..1de6b5f9 100644 --- a/crafting/CraftingTreeProcess.java +++ b/crafting/CraftingTreeProcess.java @@ -64,26 +64,22 @@ public class CraftingTreeProcess fullsimulation = true; } - for (int x = 0; x < list.length; x++) + for ( IAEItemStack part : details.getCondencedInputs() ) { - IAEItemStack part = list[x]; - if ( part != null ) + ItemStack g = part.getItemStack(); + + boolean isAnInput = false; + for ( IAEItemStack a : details.getCondencedOutputs() ) { - ItemStack g = part.getItemStack(); - - boolean isAnInput = false; - for (IAEItemStack a : is) - { - if ( g != null && a != null && a.equals( g ) ) - isAnInput = true; - } - - if ( isAnInput ) - limitQty = true; - - if ( g.getItem().hasContainerItem( g ) ) - limitQty = containerItems = true; + if ( g != null && a != null && a.equals( g ) ) + isAnInput = true; } + + if ( isAnInput ) + limitQty = true; + + if ( g.getItem().hasContainerItem( g ) ) + limitQty = containerItems = true; } boolean complicated = false; @@ -117,26 +113,19 @@ public class CraftingTreeProcess } else { - IAEItemStack list[] = details.getInputs(); - IAEItemStack[] is = details.getInputs(); - - for (int x = 0; x < list.length; x++) + for ( IAEItemStack part : details.getCondencedInputs() ) { - IAEItemStack part = list[x]; - if ( part != null ) + ItemStack g = part.getItemStack(); + + boolean isAnInput = false; + for (IAEItemStack a : details.getCondencedOutputs()) { - ItemStack g = part.getItemStack(); - - boolean isAnInput = false; - for (IAEItemStack a : is) - { - if ( g != null && a != null && a.equals( g ) ) - isAnInput = true; - } - - if ( isAnInput ) - limitQty = true; + if ( g != null && a != null && a.equals( g ) ) + isAnInput = true; } + + if ( isAnInput ) + limitQty = true; } for (IAEItemStack part : details.getCondencedInputs()) diff --git a/helpers/IContainerCraftingPacket.java b/helpers/IContainerCraftingPacket.java index 602cf268..ecb2cb6f 100644 --- a/helpers/IContainerCraftingPacket.java +++ b/helpers/IContainerCraftingPacket.java @@ -1,6 +1,7 @@ package appeng.helpers; import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; import appeng.api.networking.IGridNode; import appeng.api.networking.security.BaseActionSource; @@ -28,4 +29,9 @@ public interface IContainerCraftingPacket */ boolean useRealItems(); + /** + * @return array of view cells + */ + ItemStack[] getViewCells(); + } diff --git a/integration/modules/NEIHelpers/NEICraftingHandler.java b/integration/modules/NEIHelpers/NEICraftingHandler.java index 5b2121b2..166f7bb7 100644 --- a/integration/modules/NEIHelpers/NEICraftingHandler.java +++ b/integration/modules/NEIHelpers/NEICraftingHandler.java @@ -1,9 +1,11 @@ package appeng.integration.modules.NEIHelpers; +import java.util.LinkedList; import java.util.List; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import appeng.client.gui.implementations.GuiCraftingTerm; @@ -12,6 +14,7 @@ import appeng.container.slot.SlotCraftingMatrix; import appeng.container.slot.SlotFakeCraftingMatrix; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketNEIRecipe; +import appeng.util.Platform; import codechicken.nei.PositionedStack; import codechicken.nei.api.IOverlayHandler; import codechicken.nei.recipe.IRecipeHandler; @@ -19,7 +22,8 @@ import codechicken.nei.recipe.IRecipeHandler; public class NEICraftingHandler implements IOverlayHandler { - public NEICraftingHandler(int x, int y) { + public NEICraftingHandler(int x, int y) + { offsetx = x; offsety = y; } @@ -66,12 +70,24 @@ public class NEICraftingHandler implements IOverlayHandler if ( ctSlot.getSlotIndex() == col + row * 3 ) { NBTTagList ilist = new NBTTagList(); + List list = new LinkedList(); + + // prefer pure crystals. for (int x = 0; x < pstack.items.length; x++) + { + if ( Platform.isRecipePrioritized( pstack.items[x] ) ) + list.add( 0, pstack.items[x] ); + else + list.add( pstack.items[x] ); + } + + for (ItemStack is : list) { NBTTagCompound inbt = new NBTTagCompound(); - pstack.items[x].writeToNBT( inbt ); + is.writeToNBT( inbt ); ilist.appendTag( inbt ); } + recipe.setTag( "#" + ctSlot.getSlotIndex(), ilist ); break; } diff --git a/integration/modules/dead/Forestry.java b/integration/modules/dead/Forestry.java deleted file mode 100644 index d195f0ea..00000000 --- a/integration/modules/dead/Forestry.java +++ /dev/null @@ -1,24 +0,0 @@ -package appeng.integration.modules.dead; - -import appeng.integration.IIntegrationModule; - -public class Forestry implements IIntegrationModule -{ - - public static Forestry instance; - - @Override - public void Init() - { - // TODO Auto-generated method stub - - } - - @Override - public void PostInit() - { - // TODO Auto-generated method stub - - } - -} diff --git a/integration/modules/dead/GT.java b/integration/modules/dead/GT.java deleted file mode 100644 index f977b685..00000000 --- a/integration/modules/dead/GT.java +++ /dev/null @@ -1,46 +0,0 @@ -package appeng.integration.modules; - -import gregtech.api.interfaces.tileentity.IDigitalChest; -import net.minecraft.inventory.IInventory; -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.AEApi; -import appeng.api.storage.IMEInventory; -import appeng.integration.IIntegrationModule; -import appeng.integration.abstraction.IGT; -import appeng.integration.modules.helpers.GregTechHandler; -import appeng.integration.modules.helpers.GregTechQuantumChest; -import appeng.util.InventoryAdaptor; - -public class GT implements IGT, IIntegrationModule -{ - - public static GT instance; - - @Override - public IMEInventory getQuantumChest(TileEntity te) - { - return new GregTechQuantumChest( (IInventory) te, InventoryAdaptor.getAdaptor( te, ForgeDirection.NORTH ) ); - } - - @Override - public boolean isQuantumChest(TileEntity te) - { - if ( te instanceof IDigitalChest ) - return ((IDigitalChest) te).isDigitalChest(); - return false; - } - - @Override - public void Init() - { - - } - - @Override - public void PostInit() - { - AEApi.instance().registries().externalStorage().addExternalStorageInterface( new GregTechHandler() ); - } - -} diff --git a/integration/modules/dead/LP.java b/integration/modules/dead/LP.java deleted file mode 100644 index 6b64de18..00000000 --- a/integration/modules/dead/LP.java +++ /dev/null @@ -1,24 +0,0 @@ -package appeng.integration.modules.dead; - -import appeng.integration.IIntegrationModule; - -public class LP implements IIntegrationModule -{ - - public static LP instance; - - @Override - public void Init() - { - // TODO Auto-generated method stub - - } - - @Override - public void PostInit() - { - // TODO Auto-generated method stub - - } - -} diff --git a/integration/modules/dead/Mystcraft.java b/integration/modules/dead/Mystcraft.java deleted file mode 100644 index 9262c596..00000000 --- a/integration/modules/dead/Mystcraft.java +++ /dev/null @@ -1,24 +0,0 @@ -package appeng.integration.modules.dead; - -import appeng.integration.IIntegrationModule; - -public class Mystcraft implements IIntegrationModule -{ - - public static Mystcraft instance; - - @Override - public void Init() - { - // TODO Auto-generated method stub - - } - - @Override - public void PostInit() - { - // TODO Auto-generated method stub - - } - -} diff --git a/integration/modules/helpers/dead/ForestryGeneticsComparison.java b/integration/modules/helpers/dead/ForestryGeneticsComparison.java deleted file mode 100644 index fdc5fb3c..00000000 --- a/integration/modules/helpers/dead/ForestryGeneticsComparison.java +++ /dev/null @@ -1,47 +0,0 @@ -package appeng.integration.modules.helpers.dead; - -import appeng.api.features.IItemComparison; -import appeng.api.integration.IBeeComparison; -import forestry.api.arboriculture.EnumTreeChromosome; -import forestry.api.genetics.IIndividual; - -public class ForestryGeneticsComparison implements IItemComparison, IBeeComparison -{ - - IIndividual idiv; - String Species; - - @Override - public IIndividual getIndividual() - { - return idiv; - } - - public ForestryGeneticsComparison(IIndividual _idiv) { - idiv = _idiv; - Species = _idiv.getGenome().getActiveAllele( EnumTreeChromosome.SPECIES.ordinal() ).getUID(); - } - - @Override - public boolean sameAsPrecise(IItemComparison comp) - { - if ( comp instanceof ForestryGeneticsComparison ) - { - IIndividual op = ((ForestryGeneticsComparison) comp).idiv; - if ( idiv.isAnalyzed() == op.isAnalyzed() ) - return idiv.isGeneticEqual( op ); - } - - return false; - } - - @Override - public boolean sameAsFuzzy(IItemComparison comp) - { - if ( comp instanceof ForestryGeneticsComparison ) - return Species.equals( ((ForestryGeneticsComparison) comp).Species ); - - return false; - } - -} diff --git a/integration/modules/helpers/dead/ForestryGeneticsProvider.java b/integration/modules/helpers/dead/ForestryGeneticsProvider.java deleted file mode 100644 index 84890cec..00000000 --- a/integration/modules/helpers/dead/ForestryGeneticsProvider.java +++ /dev/null @@ -1,32 +0,0 @@ -package appeng.integration.modules.helpers.dead; - -import net.minecraft.item.ItemStack; -import appeng.api.features.IItemComparisionProvider; -import appeng.api.features.IItemComparison; -import forestry.api.genetics.IIndividual; - -public class ForestryGeneticsProvider implements IItemComparisionProvider -{ - - @Override - public IItemComparison getComparison(ItemStack is) - { - if ( forestry.api.genetics.AlleleManager.alleleRegistry != null ) - { - IIndividual idiv = forestry.api.genetics.AlleleManager.alleleRegistry.getIndividual( is ); - if ( idiv == null ) - return null; - return new ForestryGeneticsComparison( idiv ); - } - return null; - } - - @Override - public boolean canHandle(ItemStack stack) - { - if ( forestry.api.genetics.AlleleManager.alleleRegistry != null ) - return forestry.api.genetics.AlleleManager.alleleRegistry.isIndividual( stack ); - return false; - } - -} diff --git a/integration/modules/helpers/dead/GregTechHandler.java b/integration/modules/helpers/dead/GregTechHandler.java deleted file mode 100644 index 1dab71fc..00000000 --- a/integration/modules/helpers/dead/GregTechHandler.java +++ /dev/null @@ -1,30 +0,0 @@ -package appeng.integration.modules.helpers; - -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.util.ForgeDirection; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.storage.IExternalStorageHandler; -import appeng.api.storage.IMEInventory; -import appeng.api.storage.StorageChannel; -import appeng.integration.modules.GT; -import appeng.me.storage.MEMonitorIInventory; -import appeng.util.inv.IMEAdaptor; - -public class GregTechHandler implements IExternalStorageHandler -{ - - @Override - public boolean canHandle(TileEntity te, ForgeDirection d, StorageChannel chan) - { - return chan == StorageChannel.ITEMS && GT.instance.isQuantumChest( te ); - } - - @Override - public IMEInventory getInventory(TileEntity te, ForgeDirection d, StorageChannel channel, BaseActionSource src) - { - if ( channel == StorageChannel.ITEMS ) - return new MEMonitorIInventory( new IMEAdaptor( GT.instance.getQuantumChest( te ) ) ); - return null; - } - -} diff --git a/integration/modules/helpers/dead/GregTechQuantumChest.java b/integration/modules/helpers/dead/GregTechQuantumChest.java deleted file mode 100644 index 14635e72..00000000 --- a/integration/modules/helpers/dead/GregTechQuantumChest.java +++ /dev/null @@ -1,104 +0,0 @@ -package appeng.integration.modules.helpers; - -import gregtech.api.interfaces.tileentity.IDigitalChest; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import appeng.api.config.Actionable; -import appeng.api.networking.security.BaseActionSource; -import appeng.api.storage.data.IAEItemStack; -import appeng.api.storage.data.IItemList; -import appeng.me.storage.MEIInventoryWrapper; -import appeng.util.InventoryAdaptor; -import appeng.util.item.AEItemStack; - -public class GregTechQuantumChest extends MEIInventoryWrapper -{ - - IDigitalChest qc; - - public GregTechQuantumChest(IInventory m, InventoryAdaptor ia) { - super( m, ia ); - qc = (IDigitalChest) m; - } - - private ItemStack getType() - { - ItemStack[] array = qc.getStoredItemData(); - if ( array.length > 0 && array[0].getItem() != null ) - return array[0]; - return null; - } - - @Override - public IAEItemStack injectItems(IAEItemStack input, Actionable mode, BaseActionSource src) - { - ItemStack type = getType(); - if ( input.hasTagCompound() ) - return input; - - if ( type == null ) - { - return input; - } - - if ( (type.getItem() == input.getItem() && type.getItemDamage() == input.getItemDamage()) ) - { - if ( type.stackSize < qc.getMaxItemCount() ) - { - int room = (int) ((long) qc.getMaxItemCount() - (long) type.stackSize); - if ( input.getStackSize() > room ) - { - IAEItemStack is = input.copy(); - is.setStackSize( is.getStackSize() - room ); - if ( mode == Actionable.MODULATE ) - qc.setItemCount( type.stackSize + room ); - - return super.injectItems( is, mode, src ); - } - - if ( mode == Actionable.MODULATE ) - qc.setItemCount( type.stackSize + (int) input.getStackSize() ); - - return null; - } - - return super.injectItems( input, mode, src ); - } - - return input; - } - - @Override - public IAEItemStack extractItems(IAEItemStack i, Actionable mode, BaseActionSource src) - { - ItemStack type = getType(); - if ( type != null ) - { - if ( type.getItem() == i.getItem() && type.getItemDamage() == i.getItemDamage() ) - { - if ( type.stackSize > i.getStackSize() ) - { - IAEItemStack output = AEItemStack.create( type ); - output.setStackSize( (int) i.getStackSize() ); - if ( mode == Actionable.MODULATE ) - qc.setItemCount( type.stackSize - (int) output.getStackSize() ); - return output; - } - } - } - return super.extractItems( i, mode, src ); - } - - @Override - public IItemList getAvailableItems(IItemList out) - { - ItemStack type = getType(); - if ( type != null ) - { - super.getAvailableItems( out ); - if ( type != null && type.stackSize > 0 ) - out.addStorage( AEItemStack.create( type ) ); - } - return out; - } -} \ No newline at end of file diff --git a/items/storage/ItemBasicStorageCell.java b/items/storage/ItemBasicStorageCell.java index 75483212..50771e96 100644 --- a/items/storage/ItemBasicStorageCell.java +++ b/items/storage/ItemBasicStorageCell.java @@ -28,7 +28,6 @@ import appeng.items.AEBaseItem; import appeng.items.contents.CellConfig; import appeng.items.contents.CellUpgrades; import appeng.items.materials.MaterialType; -import appeng.me.storage.CellInventoryHandler; import appeng.util.InventoryAdaptor; import appeng.util.Platform; diff --git a/items/storage/ItemViewCell.java b/items/storage/ItemViewCell.java index 7090e2cd..63c0bb16 100644 --- a/items/storage/ItemViewCell.java +++ b/items/storage/ItemViewCell.java @@ -4,18 +4,29 @@ import java.util.EnumSet; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import appeng.api.AEApi; import appeng.api.config.FuzzyMode; +import appeng.api.config.Upgrades; +import appeng.api.implementations.items.IUpgradeModule; import appeng.api.storage.ICellWorkbenchItem; +import appeng.api.storage.data.IAEItemStack; +import appeng.api.storage.data.IItemList; import appeng.core.features.AEFeature; import appeng.items.AEBaseItem; import appeng.items.contents.CellConfig; import appeng.items.contents.CellUpgrades; import appeng.util.Platform; +import appeng.util.item.AEItemStack; +import appeng.util.prioitylist.FuzzyPriorityList; +import appeng.util.prioitylist.IPartitionList; +import appeng.util.prioitylist.MergedPriorityList; +import appeng.util.prioitylist.PrecisePriorityList; public class ItemViewCell extends AEBaseItem implements ICellWorkbenchItem { - public ItemViewCell() { + public ItemViewCell() + { super( ItemViewCell.class ); setfeature( EnumSet.of( AEFeature.Core ) ); setMaxStackSize( 1 ); @@ -58,4 +69,73 @@ public class ItemViewCell extends AEBaseItem implements ICellWorkbenchItem { Platform.openNbtData( is ).setString( "FuzzyMode", fzMode.name() ); } + + public static IPartitionList createFilter(ItemStack[] list) + { + IPartitionList myPartitionList = null; + + MergedPriorityList myMergedList = new MergedPriorityList(); + + for (ItemStack currentViewCell : list) + { + if ( currentViewCell == null ) + continue; + + if ( (currentViewCell.getItem() instanceof ItemViewCell) ) + { + boolean hasInverter = false; + boolean hasFuzzy = false; + IItemList priorityList = AEApi.instance().storage().createItemList(); + + ItemViewCell vc = (ItemViewCell) currentViewCell.getItem(); + IInventory upgrades = vc.getUpgradesInventory( currentViewCell ); + IInventory config = vc.getConfigInventory( currentViewCell ); + FuzzyMode fzMode = vc.getFuzzyMode( currentViewCell ); + + hasInverter = false; + hasFuzzy = false; + + for (int x = 0; x < upgrades.getSizeInventory(); x++) + { + ItemStack is = upgrades.getStackInSlot( x ); + if ( is != null && is.getItem() instanceof IUpgradeModule ) + { + Upgrades u = ((IUpgradeModule) is.getItem()).getType( is ); + if ( u != null ) + { + switch (u) + { + case FUZZY: + hasFuzzy = true; + break; + case INVERTER: + hasInverter = true; + break; + default: + } + } + } + } + + for (int x = 0; x < config.getSizeInventory(); x++) + { + ItemStack is = config.getStackInSlot( x ); + if ( is != null ) + priorityList.add( AEItemStack.create( is ) ); + } + + if ( !priorityList.isEmpty() ) + { + if ( hasFuzzy ) + myMergedList.addNewList( new FuzzyPriorityList( priorityList, fzMode ), !hasInverter ); + else + myMergedList.addNewList( new PrecisePriorityList( priorityList ), !hasInverter ); + + myPartitionList = myMergedList; + } + } + } + + return myPartitionList; + } } diff --git a/me/cache/CraftingGridCache.java b/me/cache/CraftingGridCache.java index 075bf13b..cc490f15 100644 --- a/me/cache/CraftingGridCache.java +++ b/me/cache/CraftingGridCache.java @@ -62,7 +62,6 @@ import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.SetMultimap; public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper, ICellProvider, IMEInventoryHandler @@ -78,7 +77,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper IEnergyGrid eg; HashMap> craftingMethods = new HashMap(); - HashMap> craftableItems = new HashMap(); + HashMap> craftableItems = new HashMap(); HashSet emitableItems = new HashSet(); HashMap links = new HashMap(); @@ -92,7 +91,8 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper final Iterator i; CraftingCPUCluster c = null; - public ActiveCpuIterator(Collection o) { + public ActiveCpuIterator(Collection o) + { i = o.iterator(); } @@ -135,7 +135,8 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper return ImmutableSet.copyOf( new ActiveCpuIterator( cpuClusters ) ); } - public CraftingGridCache(IGrid g) { + public CraftingGridCache(IGrid g) + { grid = g; } @@ -287,7 +288,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper private void updatePatterns() { - HashMap> oldItems = craftableItems; + HashMap> oldItems = craftableItems; // erase list. craftingMethods.clear(); @@ -323,7 +324,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper // make them immutable for (Entry> e : tmpCraft.entrySet()) - craftableItems.put( e.getKey(), ImmutableSortedSet.copyOf( e.getValue() ) ); + craftableItems.put( e.getKey(), ImmutableList.copyOf( e.getValue() ) ); sg.postAlterationOfStoredItems( StorageChannel.ITEMS, craftableItems.keySet(), new BaseActionSource() ); } @@ -481,7 +482,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper @Override public ImmutableCollection getCraftingFor(IAEItemStack whatToCraft, ICraftingPatternDetails details, int slotIndex, World world) { - ImmutableSet res = craftableItems.get( whatToCraft ); + ImmutableList res = craftableItems.get( whatToCraft ); if ( res == null ) { diff --git a/me/storage/MEMonitorIInventory.java b/me/storage/MEMonitorIInventory.java index 93144f15..981738eb 100644 --- a/me/storage/MEMonitorIInventory.java +++ b/me/storage/MEMonitorIInventory.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.Map.Entry; +import java.util.NavigableMap; import java.util.TreeMap; import net.minecraft.item.ItemStack; @@ -29,7 +30,8 @@ public class MEMonitorIInventory implements IMEInventory, IMEMonit class CachedItemStack { - public CachedItemStack(ItemStack is) { + public CachedItemStack(ItemStack is) + { if ( is == null ) { itemStack = null; @@ -67,7 +69,8 @@ public class MEMonitorIInventory implements IMEInventory, IMEMonit listeners.remove( l ); } - public MEMonitorIInventory(InventoryAdaptor adaptor) { + public MEMonitorIInventory(InventoryAdaptor adaptor) + { this.adaptor = adaptor; memory = new TreeMap(); } @@ -166,10 +169,13 @@ public class MEMonitorIInventory implements IMEInventory, IMEMonit LinkedList changes = new LinkedList(); + int high = 0; list.resetStatus(); for (ItemSlot is : adaptor) { CachedItemStack old = memory.get( is.slot ); + high = Math.max( high, is.slot ); + ItemStack newIS = is == null || is.isExtractable == false && mode == StorageFilter.EXTACTABLE_ONLY ? null : is.getItemStack(); ItemStack oldIS = old == null ? null : old.itemStack; @@ -217,6 +223,23 @@ public class MEMonitorIInventory implements IMEInventory, IMEMonit } } + // detect dropped items; should fix non IISided Inventory Changes. + NavigableMap end = memory.tailMap( high, false ); + if ( !end.isEmpty() ) + { + for (CachedItemStack cis : end.values()) + { + if ( cis != null ) + { + IAEItemStack a = cis.aeStack.copy(); + a.setStackSize( -a.getStackSize() ); + changes.add( a ); + changed = true; + } + } + end.clear(); + } + if ( !changes.isEmpty() ) postDiffrence( changes ); diff --git a/parts/p2p/PartP2PTunnel.java b/parts/p2p/PartP2PTunnel.java index b77f9ade..7a5c32c2 100644 --- a/parts/p2p/PartP2PTunnel.java +++ b/parts/p2p/PartP2PTunnel.java @@ -156,6 +156,9 @@ public class PartP2PTunnel extends PartBasicState newType = AEApi.instance().parts().partP2PTunnelRedstone.stack( 1 ); break; + default: + break; + } if ( newType != null && !Platform.isSameItem( newType, this.is ) ) diff --git a/tile/powersink/RotaryCraft.java b/tile/powersink/RotaryCraft.java index d0a15786..b206723a 100644 --- a/tile/powersink/RotaryCraft.java +++ b/tile/powersink/RotaryCraft.java @@ -62,19 +62,17 @@ public abstract class RotaryCraft extends IC2 implements ShaftPowerReceiver alpha = io; } - @Override + final public int getMachineX() { return xCoord; } - @Override final public int getMachineY() { return yCoord; } - @Override final public int getMachineZ() { return zCoord; @@ -101,7 +99,6 @@ public abstract class RotaryCraft extends IC2 implements ShaftPowerReceiver power = p; } - @Override final public boolean canReadFromBlock(int x, int y, int z) { ForgeDirection side = ForgeDirection.UNKNOWN; @@ -136,4 +133,16 @@ public abstract class RotaryCraft extends IC2 implements ShaftPowerReceiver omega = 0; } + @Override + final public boolean canReadFrom(ForgeDirection side) + { + return internalCanAcceptPower && getPowerSides().contains( side ); + } + + @Override + final public int getMinTorque(int available) + { + return 0; + } + } diff --git a/util/Platform.java b/util/Platform.java index 02731a64..4a1ecd4a 100644 --- a/util/Platform.java +++ b/util/Platform.java @@ -108,6 +108,7 @@ import appeng.util.item.AEItemStack; import appeng.util.item.AESharedNBT; import appeng.util.item.OreHelper; import appeng.util.item.OreRefrence; +import appeng.util.prioitylist.IPartitionList; import buildcraft.api.tools.IToolWrench; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Loader; @@ -1639,7 +1640,8 @@ public class Platform } public static ItemStack extractItemsByRecipe(IEnergySource energySrc, BaseActionSource mySrc, IMEMonitor src, World w, IRecipe r, - ItemStack output, InventoryCrafting ci, ItemStack providedTemplate, int slot, IItemList aitems, Actionable realForFake) + ItemStack output, InventoryCrafting ci, ItemStack providedTemplate, int slot, IItemList aitems, Actionable realForFake, + IPartitionList filter) { if ( energySrc.extractAEPower( 1, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > 0.9 ) { @@ -1649,14 +1651,17 @@ public class Platform AEItemStack ae_req = AEItemStack.create( providedTemplate ); ae_req.setStackSize( 1 ); - IAEItemStack ae_ext = src.extractItems( ae_req, realForFake, mySrc ); - if ( ae_ext != null ) + if ( filter == null || filter.isListed( ae_req ) ) { - ItemStack extracted = ae_ext.getItemStack(); - if ( extracted != null ) + IAEItemStack ae_ext = src.extractItems( ae_req, realForFake, mySrc ); + if ( ae_ext != null ) { - energySrc.extractAEPower( 1, realForFake, PowerMultiplier.CONFIG ); - return extracted; + ItemStack extracted = ae_ext.getItemStack(); + if ( extracted != null ) + { + energySrc.extractAEPower( 1, realForFake, PowerMultiplier.CONFIG ); + return extracted; + } } } @@ -1677,11 +1682,14 @@ public class Platform { IAEItemStack ax = x.copy(); ax.setStackSize( 1 ); - IAEItemStack ex = src.extractItems( ax, realForFake, mySrc ); - if ( ex != null ) + if ( filter == null || filter.isListed( ax ) ) { - energySrc.extractAEPower( 1, realForFake, PowerMultiplier.CONFIG ); - return ex.getItemStack(); + IAEItemStack ex = src.extractItems( ax, realForFake, mySrc ); + if ( ex != null ) + { + energySrc.extractAEPower( 1, realForFake, PowerMultiplier.CONFIG ); + return ex.getItemStack(); + } } } ci.setInventorySlotContents( slot, providedTemplate ); @@ -1836,4 +1844,11 @@ public class Platform // p.addStat( achivement, 1 ); } } + + public static boolean isRecipePrioritized(ItemStack what) + { + return AEApi.instance().materials().materialPureifiedCertusQuartzCrystal.sameAsStack( what ) + || AEApi.instance().materials().materialPureifiedFluixCrystal.sameAsStack( what ) + || AEApi.instance().materials().materialPureifiedNetherQuartzCrystal.sameAsStack( what ); + } }