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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user