Make NEI Item Extraction and crafting obey view cells.
This commit is contained in:
parent
ce8a34617a
commit
40ace80204
7 changed files with 427 additions and 384 deletions
|
@ -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<IAEItemStack>
|
||||
{
|
||||
|
||||
final IMEMonitor<IAEItemStack> monitor;
|
||||
final IItemList<IAEItemStack> 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<IAEItemStack>
|
||||
{
|
||||
|
||||
final IMEMonitor<IAEItemStack> monitor;
|
||||
final IItemList<IAEItemStack> 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<IAEItemStack> 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<IAEItemStack> 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<IAEItemStack> monitor, Iterable<IAEItemStack> 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<IAEItemStack> 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<IAEItemStack> 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<IAEItemStack> monitor, Iterable<IAEItemStack> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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] );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<IAEItemStack> stor = inv.getItemInventory();
|
||||
IItemList all = stor.getStorageList();
|
||||
IPartitionList<IAEItemStack> 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();
|
||||
|
|
|
@ -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();
|
||||
|
||||
}
|
||||
|
|
|
@ -105,6 +105,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;
|
||||
|
@ -384,7 +385,8 @@ public class Platform
|
|||
{
|
||||
switch (id)
|
||||
{
|
||||
case 10: {
|
||||
case 10:
|
||||
{
|
||||
NBTTagCompound ctA = (NBTTagCompound) A;
|
||||
NBTTagCompound ctB = (NBTTagCompound) B;
|
||||
|
||||
|
@ -510,7 +512,8 @@ public class Platform
|
|||
hash += id;
|
||||
switch (id)
|
||||
{
|
||||
case 10: {
|
||||
case 10:
|
||||
{
|
||||
NBTTagCompound ctA = (NBTTagCompound) A;
|
||||
|
||||
Set<String> cA = ctA.func_150296_c();
|
||||
|
@ -1615,7 +1618,8 @@ public class Platform
|
|||
}
|
||||
|
||||
public static ItemStack extractItemsByRecipe(IEnergySource energySrc, BaseActionSource mySrc, IMEMonitor<IAEItemStack> src, World w, IRecipe r,
|
||||
ItemStack output, InventoryCrafting ci, ItemStack providedTemplate, int slot, IItemList<IAEItemStack> aitems, Actionable realForFake)
|
||||
ItemStack output, InventoryCrafting ci, ItemStack providedTemplate, int slot, IItemList<IAEItemStack> aitems, Actionable realForFake,
|
||||
IPartitionList<IAEItemStack> filter)
|
||||
{
|
||||
if ( energySrc.extractAEPower( 1, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > 0.9 )
|
||||
{
|
||||
|
@ -1625,14 +1629,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1653,11 +1660,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 );
|
||||
|
|
Loading…
Reference in a new issue