Refactored the BaseActionSource (#3063)

* Refactored the BaseActionSource

It now uses an interface `IActionSource` instead of a concrete class and further
subclasses. 

Instead of relying on a specific class for a certain action type, it now
uses methods with Optional as return values to determine a player or
machine issuing an action. Refer to the JavaDocs for the exact behaviour.

* `IActionHost` no longer extends `IGridHost`

It never used the additional functionality and if needed the `IGridNode`
will also provide a reference to the corresponding `IGridHost`.

Due to most crafting related GUIs being hardcoded to `IGridHost`, 
they no longer work when `IActionHost` is not extending it. Actually
`IActionHost` is the better solution for it, as it prevents us from looking
the grid up via the `IGridHost` and potentially finding a wrong grid.

* Interfaces now only lock the currently worked slot.

This allows `DualityInterface#onChangeInventory` to update slots of the same interface, should they be the source for a requested item and therefore updating their working set accordingly to queue further crafting requests for unfulfilled stack requirements.
This commit is contained in:
yueh
2017-09-12 11:39:00 +02:00
committed by GitHub
parent 771a944058
commit 970630a90d
81 changed files with 572 additions and 465 deletions
@@ -51,10 +51,9 @@ import appeng.api.networking.IGrid;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.security.ISecurityGrid;
import appeng.api.networking.security.PlayerSource;
import appeng.api.parts.IPart;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.data.IAEItemStack;
@@ -77,6 +76,7 @@ import appeng.core.sync.packets.PacketPartialItem;
import appeng.core.sync.packets.PacketValueConfig;
import appeng.helpers.ICustomNameObject;
import appeng.helpers.InventoryAction;
import appeng.me.helpers.PlayerSource;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.inv.AdaptorItemHandler;
@@ -87,7 +87,7 @@ import appeng.util.item.AEItemStack;
public abstract class AEBaseContainer extends Container
{
private final InventoryPlayer invPlayer;
private final BaseActionSource mySrc;
private final IActionSource mySrc;
private final HashSet<Integer> locked = new HashSet<>();
private final TileEntity tileEntity;
private final IPart part;
@@ -280,7 +280,7 @@ public abstract class AEBaseContainer extends Container
this.clientRequestedTargetItem = stack == null ? null : stack.copy();
}
public BaseActionSource getActionSource()
public IActionSource getActionSource()
{
return this.mySrc;
}
@@ -27,13 +27,13 @@ import net.minecraft.world.World;
import appeng.api.config.SecurityPermissions;
import appeng.api.networking.IGrid;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.PlayerSource;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.container.AEBaseContainer;
import appeng.container.slot.SlotInaccessible;
import appeng.me.helpers.PlayerSource;
import appeng.tile.inventory.AppEngInternalInventory;
@@ -69,7 +69,7 @@ public class ContainerCraftAmount extends AEBaseContainer
return this.getPlayerInv().player.world;
}
public BaseActionSource getActionSrc()
public IActionSource getActionSrc()
{
return new PlayerSource( this.getPlayerInv().player, (IActionHost) this.getTarget() );
}
@@ -44,9 +44,8 @@ import appeng.api.networking.crafting.ICraftingCPU;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.crafting.ICraftingJob;
import appeng.api.networking.crafting.ICraftingLink;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.PlayerSource;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.ITerminalHost;
@@ -60,6 +59,7 @@ import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketMEInventoryUpdate;
import appeng.core.sync.packets.PacketSwitchGuis;
import appeng.helpers.WirelessTerminalGuiObject;
import appeng.me.helpers.PlayerSource;
import appeng.parts.reporting.PartCraftingTerminal;
import appeng.parts.reporting.PartPatternTerminal;
import appeng.parts.reporting.PartTerminal;
@@ -361,7 +361,7 @@ public class ContainerCraftConfirm extends AEBaseContainer
}
}
private BaseActionSource getActionSrc()
private IActionSource getActionSrc()
{
return new PlayerSource( this.getPlayerInv().player, (IActionHost) this.getTarget() );
}
@@ -28,16 +28,14 @@ import net.minecraft.inventory.IContainerListener;
import appeng.api.AEApi;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.CraftingItemList;
import appeng.api.networking.crafting.ICraftingCPU;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.api.util.AEPartLocation;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.core.AELog;
@@ -65,15 +63,11 @@ public class ContainerCraftingCPU extends AEBaseContainer implements IMEMonitorH
public ContainerCraftingCPU( final InventoryPlayer ip, final Object te )
{
super( ip, te );
final IGridHost host = (IGridHost) ( te instanceof IGridHost ? te : null );
final IActionHost host = (IActionHost) ( te instanceof IActionHost ? te : null );
if( host != null )
if( host != null && host.getActionableNode() != null )
{
this.findNode( host, AEPartLocation.INTERNAL );
for( final AEPartLocation d : AEPartLocation.SIDE_LOCATIONS )
{
this.findNode( host, d );
}
this.setNetwork( host.getActionableNode().getGrid() );
}
if( te instanceof TileCraftingTile )
@@ -87,18 +81,6 @@ public class ContainerCraftingCPU extends AEBaseContainer implements IMEMonitorH
}
}
private void findNode( final IGridHost host, final AEPartLocation d )
{
if( this.getNetwork() == null )
{
final IGridNode node = host.getGridNode( d );
if( node != null )
{
this.setNetwork( node.getGrid() );
}
}
}
protected void setCPU( final ICraftingCPU c )
{
if( c == this.getMonitor() )
@@ -238,7 +220,7 @@ public class ContainerCraftingCPU extends AEBaseContainer implements IMEMonitorH
}
@Override
public void postChange( final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> change, final BaseActionSource actionSource )
public void postChange( final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> change, final IActionSource actionSource )
{
for( IAEItemStack is : change )
{
@@ -47,7 +47,8 @@ import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.parts.IPart;
import appeng.api.storage.IMEMonitor;
@@ -122,9 +123,22 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa
{
this.setPowerSource( (IEnergySource) monitorable );
}
else if( monitorable instanceof IGridHost )
else if( monitorable instanceof IGridHost || monitorable instanceof IActionHost )
{
final IGridNode node = ( (IGridHost) monitorable ).getGridNode( AEPartLocation.INTERNAL );
final IGridNode node;
if( monitorable instanceof IGridHost )
{
node = ( (IGridHost) monitorable ).getGridNode( AEPartLocation.INTERNAL );
}
else if( monitorable instanceof IActionHost )
{
node = ( (IActionHost) monitorable ).getActionableNode();
}
else
{
node = null;
}
if( node != null )
{
this.networkNode = node;
@@ -374,7 +388,7 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa
}
@Override
public void postChange( final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> change, final BaseActionSource source )
public void postChange( final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> change, final IActionSource source )
{
for( final IAEItemStack is : change )
{
@@ -43,7 +43,6 @@ import net.minecraftforge.items.wrapper.PlayerInvWrapper;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.definitions.IDefinitions;
import appeng.api.networking.security.MachineSource;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
@@ -59,6 +58,7 @@ import appeng.container.slot.SlotRestrictedInput;
import appeng.core.sync.packets.PacketPatternSlot;
import appeng.helpers.IContainerCraftingPacket;
import appeng.items.storage.ItemViewCell;
import appeng.me.helpers.MachineSource;
import appeng.parts.reporting.PartPatternTerminal;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.util.InventoryAdaptor;
@@ -36,7 +36,7 @@ import net.minecraftforge.items.IItemHandler;
import appeng.api.config.Actionable;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IStorageMonitorable;
import appeng.api.storage.data.IAEItemStack;
@@ -61,12 +61,12 @@ public class SlotCraftingTerm extends AppEngCraftingSlot
private final IItemHandler craftInv;
private final IItemHandler pattern;
private final BaseActionSource mySrc;
private final IActionSource mySrc;
private final IEnergySource energySrc;
private final IStorageMonitorable storage;
private final IContainerCraftingPacket container;
public SlotCraftingTerm( final EntityPlayer player, final BaseActionSource mySrc, final IEnergySource energySrc, final IStorageMonitorable storage, final IItemHandler cMatrix, final IItemHandler secondMatrix, final IItemHandler output, final int x, final int y, final IContainerCraftingPacket ccp )
public SlotCraftingTerm( final EntityPlayer player, final IActionSource mySrc, final IEnergySource energySrc, final IStorageMonitorable storage, final IItemHandler cMatrix, final IItemHandler secondMatrix, final IItemHandler output, final int x, final int y, final IContainerCraftingPacket ccp )
{
super( player, cMatrix, output, 0, x, y );
this.energySrc = energySrc;
@@ -27,7 +27,7 @@ import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.IStorageMonitorable;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.packets.PacketPatternSlot;
@@ -40,7 +40,7 @@ public class SlotPatternTerm extends SlotCraftingTerm
private final int groupNum;
private final IOptionalSlotHost host;
public SlotPatternTerm( final EntityPlayer player, final BaseActionSource mySrc, final IEnergySource energySrc, final IStorageMonitorable storage, final IItemHandler cMatrix, final IItemHandler secondMatrix, final IItemHandler output, final int x, final int y, final IOptionalSlotHost h, final int groupNumber, final IContainerCraftingPacket c )
public SlotPatternTerm( final EntityPlayer player, final IActionSource mySrc, final IEnergySource energySrc, final IStorageMonitorable storage, final IItemHandler cMatrix, final IItemHandler secondMatrix, final IItemHandler output, final int x, final int y, final IOptionalSlotHost h, final int groupNumber, final IContainerCraftingPacket c )
{
super( player, mySrc, energySrc, storage, cMatrix, secondMatrix, output, x, y, c );