Updated Grid API (#3399)

* Updated Grid API

Added Nonull/Nullable/Nonnegative where applicable.
Deprecated unused methods
Changed concrete classes with interfaces (HashMap -> Map)
IGridTickable will no longer accept null as TickingRequest. Do not
implement it, if it should not tick.

* Renamed parameter to match conventions
This commit is contained in:
yueh
2018-05-27 21:16:01 +02:00
committed by GitHub
parent d7b97fa7b8
commit 044e639827
29 changed files with 193 additions and 75 deletions
+13 -4
View File
@@ -24,6 +24,8 @@
package appeng.api.networking; package appeng.api.networking;
import javax.annotation.Nonnull;
import appeng.api.networking.events.MENetworkEvent; import appeng.api.networking.events.MENetworkEvent;
import appeng.api.util.IReadOnlyCollection; import appeng.api.util.IReadOnlyCollection;
@@ -43,7 +45,8 @@ public interface IGrid
* *
* @return the IGridCache you requested. * @return the IGridCache you requested.
*/ */
<C extends IGridCache> C getCache( Class<? extends IGridCache> iface ); @Nonnull
<C extends IGridCache> C getCache( @Nonnull Class<? extends IGridCache> iface );
/** /**
* Post an event into the network event bus. * Post an event into the network event bus.
@@ -52,7 +55,8 @@ public interface IGrid
* *
* @return returns ev back to original poster * @return returns ev back to original poster
*/ */
MENetworkEvent postEvent( MENetworkEvent ev ); @Nonnull
MENetworkEvent postEvent( @Nonnull MENetworkEvent ev );
/** /**
* Post an event into the network event bus, but direct it at a single node. * Post an event into the network event bus, but direct it at a single node.
@@ -61,7 +65,8 @@ public interface IGrid
* *
* @return returns ev back to original poster * @return returns ev back to original poster
*/ */
MENetworkEvent postEventTo( IGridNode node, MENetworkEvent ev ); @Nonnull
MENetworkEvent postEventTo( @Nonnull IGridNode node, @Nonnull MENetworkEvent ev );
/** /**
* get a list of the diversity of classes, you can use this to better detect which machines your interested in, * get a list of the diversity of classes, you can use this to better detect which machines your interested in,
@@ -69,6 +74,7 @@ public interface IGrid
* *
* @return IReadOnlyCollection of all available host types (Of Type IGridHost). * @return IReadOnlyCollection of all available host types (Of Type IGridHost).
*/ */
@Nonnull
IReadOnlyCollection<Class<? extends IGridHost>> getMachinesClasses(); IReadOnlyCollection<Class<? extends IGridHost>> getMachinesClasses();
/** /**
@@ -78,11 +84,13 @@ public interface IGrid
* *
* @return IMachineSet of all nodes belonging to hosts of specified class. * @return IMachineSet of all nodes belonging to hosts of specified class.
*/ */
IMachineSet getMachines( Class<? extends IGridHost> gridHostClass ); @Nonnull
IMachineSet getMachines( @Nonnull Class<? extends IGridHost> gridHostClass );
/** /**
* @return IReadOnlyCollection for all nodes on the network, node visitors are preferred. * @return IReadOnlyCollection for all nodes on the network, node visitors are preferred.
*/ */
@Nonnull
IReadOnlyCollection<IGridNode> getNodes(); IReadOnlyCollection<IGridNode> getNodes();
/** /**
@@ -93,5 +101,6 @@ public interface IGrid
/** /**
* @return the node considered the pivot point of the grid. * @return the node considered the pivot point of the grid.
*/ */
@Nonnull
IGridNode getPivot(); IGridNode getPivot();
} }
@@ -26,6 +26,10 @@ package appeng.api.networking;
import java.util.EnumSet; import java.util.EnumSet;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
@@ -49,6 +53,7 @@ public interface IGridBlock
* *
* @return ae/t to use. * @return ae/t to use.
*/ */
@Nonnegative
double getIdlePowerUsage(); double getIdlePowerUsage();
/** /**
@@ -56,10 +61,11 @@ public interface IGridBlock
* *
* @return Set of flags for this IGridBlock * @return Set of flags for this IGridBlock
*/ */
@Nonnull
EnumSet<GridFlags> getFlags(); EnumSet<GridFlags> getFlags();
/** /**
* generally speaking you will return true for this, the one exception is buses, or worm holes where the node * Generally speaking you will return true for this, the one exception is buses, or worm holes where the node
* represents something that isn't a real connection in the world, but rather one represented internally to the * represents something that isn't a real connection in the world, but rather one represented internally to the
* block. * block.
* *
@@ -68,37 +74,46 @@ public interface IGridBlock
boolean isWorldAccessible(); boolean isWorldAccessible();
/** /**
* Must not return when {@link #isWorldAccessible()} is true.
* Otherwise the behavior is unspecified.
*
* @return current location of this node * @return current location of this node
*/ */
@Nonnull
DimensionalCoord getLocation(); DimensionalCoord getLocation();
/** /**
* @return Transparent, or a valid color, NULL IS NOT A VALID RETURN * @return Transparent, or a valid color, NULL IS NOT A VALID RETURN
*/ */
@Nonnull
AEColor getGridColor(); AEColor getGridColor();
/** /**
* Notifies your IGridBlock that changes were made to your connections * Notifies your IGridBlock that changes were made to your connections
*/ */
void onGridNotification( GridNotification notification ); void onGridNotification( @Nonnull GridNotification notification );
/** /**
* Update Blocks network/connection/booting status. grid, * Update Blocks network/connection/booting status. grid,
* *
* @param grid grid * @param grid grid
* @param channelsInUse used channels * @param channelsInUse used channels
* @deprecated to be removed in rv7
*/ */
@Deprecated
void setNetworkStatus( IGrid grid, int channelsInUse ); void setNetworkStatus( IGrid grid, int channelsInUse );
/** /**
* Determine which sides of the block can be connected too, only used when isWorldAccessible returns true, not used * Determine which sides of the block can be connected too, only used when isWorldAccessible returns true, not used
* for {@link IPart} implementations. * for {@link IPart} implementations.
*/ */
@Nonnull
EnumSet<EnumFacing> getConnectableSides(); EnumSet<EnumFacing> getConnectableSides();
/** /**
* @return the IGridHost for the node, this will be an IGridPart or a TileEntity generally speaking. * @return the IGridHost for the node, this will be an IGridPart or a TileEntity generally speaking.
*/ */
@Nonnull
IGridHost getMachine(); IGridHost getMachine();
/** /**
@@ -111,5 +126,6 @@ public interface IGridBlock
* *
* @return the render item stack to use to render this node, null is valid, and will not show this node. * @return the render item stack to use to render this node, null is valid, and will not show this node.
*/ */
@Nullable
ItemStack getMachineRepresentation(); ItemStack getMachineRepresentation();
} }
@@ -24,6 +24,9 @@
package appeng.api.networking; package appeng.api.networking;
import javax.annotation.Nonnull;
/** /**
* Allows you to create a network wise service, AE2 uses these for providing * Allows you to create a network wise service, AE2 uses these for providing
* item, spatial, and tunnel services. * item, spatial, and tunnel services.
@@ -50,7 +53,7 @@ public interface IGridCache
* @param gridNode removed from that grid * @param gridNode removed from that grid
* @param machine to be removed machine * @param machine to be removed machine
*/ */
void removeNode( IGridNode gridNode, IGridHost machine ); void removeNode( @Nonnull IGridNode gridNode, @Nonnull IGridHost machine );
/** /**
* informs you cache that a machine was added to the grid. * informs you cache that a machine was added to the grid.
@@ -62,7 +65,7 @@ public interface IGridCache
* @param gridNode added to grid node * @param gridNode added to grid node
* @param machine to be added machine * @param machine to be added machine
*/ */
void addNode( IGridNode gridNode, IGridHost machine ); void addNode( @Nonnull IGridNode gridNode, @Nonnull IGridHost machine );
/** /**
* Called when a grid splits into two grids, AE will call a split as it * Called when a grid splits into two grids, AE will call a split as it
@@ -71,7 +74,7 @@ public interface IGridCache
* *
* @param destinationStorage storage which receives half of old grid * @param destinationStorage storage which receives half of old grid
*/ */
void onSplit( IGridStorage destinationStorage ); void onSplit( @Nonnull IGridStorage destinationStorage );
/** /**
* Called when two grids merge into one, AE will call a join as it * Called when two grids merge into one, AE will call a join as it
@@ -80,12 +83,12 @@ public interface IGridCache
* *
* @param sourceStorage old storage * @param sourceStorage old storage
*/ */
void onJoin( IGridStorage sourceStorage ); void onJoin( @Nonnull IGridStorage sourceStorage );
/** /**
* Called when saving changes, * Called when saving changes,
* *
* @param destinationStorage storage * @param destinationStorage storage
*/ */
void populateGridStorage( IGridStorage destinationStorage ); void populateGridStorage( @Nonnull IGridStorage destinationStorage );
} }
@@ -24,7 +24,9 @@
package appeng.api.networking; package appeng.api.networking;
import java.util.HashMap; import java.util.Map;
import javax.annotation.Nonnull;
/** /**
@@ -38,14 +40,14 @@ public interface IGridCacheRegistry
* *
* @param iface grid cache class * @param iface grid cache class
*/ */
void registerGridCache( Class<? extends IGridCache> iface, Class<? extends IGridCache> implementation ); void registerGridCache( @Nonnull Class<? extends IGridCache> iface, @Nonnull Class<? extends IGridCache> implementation );
/** /**
* requests a new INSTANCE of a grid cache for use, used internally * requests a new INSTANCE of a grid cache for use, used internally
* *
* @param grid grid * @param grid grid
* *
* @return a new HashMap of IGridCaches from the registry, called from IGrid when constructing a new grid. * @return a new Map of IGridCaches from the registry, called from IGrid when constructing a new grid.
*/ */
HashMap<Class<? extends IGridCache>, IGridCache> createCacheInstance( IGrid grid ); Map<Class<? extends IGridCache>, IGridCache> createCacheInstance( IGrid grid );
} }
@@ -24,6 +24,8 @@
package appeng.api.networking; package appeng.api.networking;
import javax.annotation.Nonnull;
import appeng.api.util.AEPartLocation; import appeng.api.util.AEPartLocation;
@@ -45,6 +47,7 @@ public interface IGridConnection
* *
* @return the IGridNode which represents the opposite side of the connection. * @return the IGridNode which represents the opposite side of the connection.
*/ */
@Nonnull
IGridNode getOtherSide( IGridNode gridNode ); IGridNode getOtherSide( IGridNode gridNode );
/** /**
@@ -54,6 +57,7 @@ public interface IGridConnection
* *
* @return the direction of the connection, only valid for in world connections. * @return the direction of the connection, only valid for in world connections.
*/ */
@Nonnull
AEPartLocation getDirection( IGridNode gridNode ); AEPartLocation getDirection( IGridNode gridNode );
/** /**
@@ -65,11 +69,13 @@ public interface IGridConnection
/** /**
* @return node A * @return node A
*/ */
@Nonnull
IGridNode a(); IGridNode a();
/** /**
* @return node B * @return node B
*/ */
@Nonnull
IGridNode b(); IGridNode b();
/** /**
@@ -24,6 +24,9 @@
package appeng.api.networking; package appeng.api.networking;
import javax.annotation.Nonnull;
public interface IGridConnectionVisitor extends IGridVisitor public interface IGridConnectionVisitor extends IGridVisitor
{ {
@@ -32,5 +35,5 @@ public interface IGridConnectionVisitor extends IGridVisitor
* *
* @param n the connection. * @param n the connection.
*/ */
void visitConnection( IGridConnection n ); void visitConnection( @Nonnull IGridConnection n );
} }
@@ -24,6 +24,8 @@
package appeng.api.networking; package appeng.api.networking;
import javax.annotation.Nonnull;
import appeng.api.exceptions.FailedConnectionException; import appeng.api.exceptions.FailedConnectionException;
@@ -47,7 +49,8 @@ public interface IGridHelper
* *
* @return grid node of block * @return grid node of block
*/ */
IGridNode createGridNode( IGridBlock block ); @Nonnull
IGridNode createGridNode( @Nonnull IGridBlock block );
/** /**
* Create a direct connection between two {@link IGridNode}. * Create a direct connection between two {@link IGridNode}.
@@ -59,6 +62,7 @@ public interface IGridHelper
* *
* @throws appeng.api.exceptions.FailedConnectionException * @throws appeng.api.exceptions.FailedConnectionException
*/ */
IGridConnection createGridConnection( IGridNode a, IGridNode b ) throws FailedConnectionException; @Nonnull
IGridConnection createGridConnection( @Nonnull IGridNode a, @Nonnull IGridNode b ) throws FailedConnectionException;
} }
@@ -24,6 +24,9 @@
package appeng.api.networking; package appeng.api.networking;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import appeng.api.parts.IPart; import appeng.api.parts.IPart;
@@ -49,7 +52,8 @@ public interface IGridHost
* @return a new IGridNode, create these with * @return a new IGridNode, create these with
* AEApi.INSTANCE().createGridNode( MyIGridBlock ) * AEApi.INSTANCE().createGridNode( MyIGridBlock )
*/ */
IGridNode getGridNode( AEPartLocation dir ); @Nullable
IGridNode getGridNode( @Nonnull AEPartLocation dir );
/** /**
* Determines how cables render when they connect to this block. Priority is * Determines how cables render when they connect to this block. Priority is
@@ -57,7 +61,8 @@ public interface IGridHost
* *
* @param dir direction * @param dir direction
*/ */
AECableType getCableConnectionType( AEPartLocation dir ); @Nonnull
AECableType getCableConnectionType( @Nonnull AEPartLocation dir );
/** /**
* break this host, its violating security rules, just break your block, or part. * break this host, its violating security rules, just break your block, or part.
@@ -26,6 +26,8 @@ package appeng.api.networking;
import java.util.Iterator; import java.util.Iterator;
import javax.annotation.Nonnull;
/** /**
* An extension of IGridBlock, only means something when your getFlags() contains REQUIRE_CHANNEL, when done properly it * An extension of IGridBlock, only means something when your getFlags() contains REQUIRE_CHANNEL, when done properly it
@@ -40,5 +42,6 @@ public interface IGridMultiblock extends IGridBlock
* *
* @return an iterator that will iterate all the nodes for the multiblock. ( read-only iterator expected. ) * @return an iterator that will iterate all the nodes for the multiblock. ( read-only iterator expected. )
*/ */
@Nonnull
Iterator<IGridNode> getMultiblockNodes(); Iterator<IGridNode> getMultiblockNodes();
} }
@@ -26,6 +26,8 @@ package appeng.api.networking;
import java.util.EnumSet; import java.util.EnumSet;
import javax.annotation.Nonnull;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World; import net.minecraft.world.World;
@@ -50,7 +52,7 @@ public interface IGridNode
* *
* @param visitor visitor * @param visitor visitor
*/ */
void beginVisit( IGridVisitor visitor ); void beginVisit( @Nonnull IGridVisitor visitor );
/** /**
* inform the node that your IGridBlock has changed its internal state, and force the node to update. * inform the node that your IGridBlock has changed its internal state, and force the node to update.
@@ -68,6 +70,7 @@ public interface IGridNode
* *
* @return grid host * @return grid host
*/ */
@Nonnull
IGridHost getMachine(); IGridHost getMachine();
/** /**
@@ -75,6 +78,7 @@ public interface IGridNode
* *
* @return grid * @return grid
*/ */
@Nonnull
IGrid getGrid(); IGrid getGrid();
/** /**
@@ -86,11 +90,13 @@ public interface IGridNode
/** /**
* @return the world the node is located in * @return the world the node is located in
*/ */
@Nonnull
World getWorld(); World getWorld();
/** /**
* @return a set of the connected sides, INTERNAL represents an invisible connection * @return a set of the connected sides, INTERNAL represents an invisible connection
*/ */
@Nonnull
EnumSet<AEPartLocation> getConnectedSides(); EnumSet<AEPartLocation> getConnectedSides();
/** /**
@@ -98,11 +104,13 @@ public interface IGridNode
* *
* @return grid connections * @return grid connections
*/ */
@Nonnull
IReadOnlyCollection<IGridConnection> getConnections(); IReadOnlyCollection<IGridConnection> getConnections();
/** /**
* @return the IGridBlock for this node * @return the IGridBlock for this node
*/ */
@Nonnull
IGridBlock getGridBlock(); IGridBlock getGridBlock();
/** /**
@@ -122,7 +130,7 @@ public interface IGridNode
* @param name nbt name * @param name nbt name
* @param nodeData to be loaded data * @param nodeData to be loaded data
*/ */
void loadFromNBT( String name, NBTTagCompound nodeData ); void loadFromNBT( @Nonnull String name, @Nonnull NBTTagCompound nodeData );
/** /**
* this should be called for each node you maintain, you can save all your nodes to the same tag with different * this should be called for each node you maintain, you can save all your nodes to the same tag with different
@@ -131,7 +139,7 @@ public interface IGridNode
* @param name nbt name * @param name nbt name
* @param nodeData to be saved data * @param nodeData to be saved data
*/ */
void saveToNBT( String name, NBTTagCompound nodeData ); void saveToNBT( @Nonnull String name, @Nonnull NBTTagCompound nodeData );
/** /**
* @return if the node's channel requirements are currently met, use this for display purposes, use isActive for * @return if the node's channel requirements are currently met, use this for display purposes, use isActive for
@@ -146,7 +154,7 @@ public interface IGridNode
* *
* @return true if has flag * @return true if has flag
*/ */
boolean hasFlag( GridFlags flag ); boolean hasFlag( @Nonnull GridFlags flag );
/** /**
* @return the ownerID this represents the person who placed the node. * @return the ownerID this represents the person who placed the node.
@@ -24,6 +24,8 @@
package appeng.api.networking; package appeng.api.networking;
import javax.annotation.Nonnull;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@@ -33,6 +35,7 @@ public interface IGridStorage
/** /**
* @return an NBTTagCompound that can be read, and written too. * @return an NBTTagCompound that can be read, and written too.
*/ */
@Nonnull
NBTTagCompound dataObject(); NBTTagCompound dataObject();
/** /**
@@ -24,6 +24,9 @@
package appeng.api.networking; package appeng.api.networking;
import javax.annotation.Nonnull;
/** /**
* Simple Visitor pattern access to network nodes. * Simple Visitor pattern access to network nodes.
*/ */
@@ -39,5 +42,5 @@ public interface IGridVisitor
* *
* @return true to continue visiting nodes beyond this node. * @return true to continue visiting nodes beyond this node.
*/ */
boolean visitNode( IGridNode n ); boolean visitNode( @Nonnull IGridNode n );
} }
@@ -24,6 +24,8 @@
package appeng.api.networking; package appeng.api.networking;
import javax.annotation.Nonnull;
import appeng.api.util.IReadOnlyCollection; import appeng.api.util.IReadOnlyCollection;
@@ -33,5 +35,6 @@ public interface IMachineSet extends IReadOnlyCollection<IGridNode>
/** /**
* @return the machine class for this set. * @return the machine class for this set.
*/ */
@Nonnull
Class<? extends IGridHost> getMachineClass(); Class<? extends IGridHost> getMachineClass();
} }
@@ -24,6 +24,9 @@
package appeng.api.networking.crafting; package appeng.api.networking.crafting;
import javax.annotation.Nonnull;
public interface ICraftingCallback public interface ICraftingCallback
{ {
@@ -32,5 +35,5 @@ public interface ICraftingCallback
* *
* @param job - final job * @param job - final job
*/ */
void calculationComplete( ICraftingJob job ); void calculationComplete( @Nonnull ICraftingJob job );
} }
@@ -24,6 +24,8 @@
package appeng.api.networking.energy; package appeng.api.networking.energy;
import javax.annotation.Nonnull;
import appeng.api.config.AccessRestriction; import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable; import appeng.api.config.Actionable;
@@ -42,7 +44,7 @@ public interface IAEPowerStorage extends IEnergySource
* *
* @return amount of power which was unable to be stored * @return amount of power which was unable to be stored
*/ */
double injectAEPower( double amt, Actionable mode ); double injectAEPower( double amt, @Nonnull Actionable mode );
/** /**
* @return the current maximum power ( this can change :P ) * @return the current maximum power ( this can change :P )
@@ -67,5 +69,6 @@ public interface IAEPowerStorage extends IEnergySource
* *
* @return access restriction what the network can do * @return access restriction what the network can do
*/ */
@Nonnull
AccessRestriction getPowerFlow(); AccessRestriction getPowerFlow();
} }
@@ -24,6 +24,9 @@
package appeng.api.networking.energy; package appeng.api.networking.energy;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import appeng.api.config.Actionable; import appeng.api.config.Actionable;
import appeng.api.networking.IGridCache; import appeng.api.networking.IGridCache;
import appeng.api.networking.events.MENetworkPowerStatusChange; import appeng.api.networking.events.MENetworkPowerStatusChange;
@@ -38,17 +41,20 @@ public interface IEnergyGrid extends IGridCache, IEnergySource, IEnergyGridProvi
/** /**
* @return the current calculated idle energy drain each tick, is used internally to drain power for each tick. * @return the current calculated idle energy drain each tick, is used internally to drain power for each tick.
*/ */
@Nonnegative
double getIdlePowerUsage(); double getIdlePowerUsage();
/** /**
* @return the average power drain over the past 10 ticks, includes idle usage during this time, and all use of * @return the average power drain over the past 10 ticks, includes idle usage during this time, and all use of
* extractPower. * extractPower.
*/ */
@Nonnegative
double getAvgPowerUsage(); double getAvgPowerUsage();
/** /**
* @return the average energy injected into the system per tick, for the last 10 ticks. * @return the average energy injected into the system per tick, for the last 10 ticks.
*/ */
@Nonnegative
double getAvgPowerInjection(); double getAvgPowerInjection();
/** /**
@@ -79,13 +85,15 @@ public interface IEnergyGrid extends IGridCache, IEnergySource, IEnergyGridProvi
* *
* @return the amount of power that the network has OVER the limit. * @return the amount of power that the network has OVER the limit.
*/ */
double injectPower( double amt, Actionable mode ); @Nonnegative
double injectPower( @Nonnegative double amt, @Nonnull Actionable mode );
/** /**
* this is should be considered an estimate, and not relied upon for real calculations. * this is should be considered an estimate, and not relied upon for real calculations.
* *
* @return estimated available power. * @return estimated available power.
*/ */
@Nonnegative
double getStoredPower(); double getStoredPower();
/** /**
@@ -93,6 +101,7 @@ public interface IEnergyGrid extends IGridCache, IEnergySource, IEnergyGridProvi
* *
* @return estimated available power. * @return estimated available power.
*/ */
@Nonnegative
double getMaxStoredPower(); double getMaxStoredPower();
/** /**
@@ -101,5 +110,6 @@ public interface IEnergyGrid extends IGridCache, IEnergySource, IEnergyGridProvi
* *
* @return Amount of power required to charge the grid, in AE. * @return Amount of power required to charge the grid, in AE.
*/ */
double getEnergyDemand( double maxRequired ); @Nonnegative
double getEnergyDemand( @Nonnegative double maxRequired );
} }
@@ -24,6 +24,9 @@
package appeng.api.networking.energy; package appeng.api.networking.energy;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import appeng.api.config.Actionable; import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier; import appeng.api.config.PowerMultiplier;
@@ -39,5 +42,6 @@ public interface IEnergySource
* *
* @return returns extracted power. * @return returns extracted power.
*/ */
double extractAEPower( double amt, Actionable mode, PowerMultiplier usePowerMultiplier ); @Nonnegative
double extractAEPower( @Nonnegative double amt, @Nonnull Actionable mode, @Nonnull PowerMultiplier usePowerMultiplier );
} }
@@ -24,6 +24,9 @@
package appeng.api.networking.energy; package appeng.api.networking.energy;
import javax.annotation.Nonnegative;
/** /**
* DO NOT IMPLEMENT. * DO NOT IMPLEMENT.
* *
@@ -39,7 +42,7 @@ public interface IEnergyWatcher
* @param amount * @param amount
* @return true, if successfully added. * @return true, if successfully added.
*/ */
boolean add( double amount ); boolean add( @Nonnegative double amount );
/** /**
* Remove a specific threshold from the watcher. * Remove a specific threshold from the watcher.
@@ -47,7 +50,7 @@ public interface IEnergyWatcher
* @param amount * @param amount
* @return true, if successfully removed. * @return true, if successfully removed.
*/ */
boolean remove( double amount ); boolean remove( @Nonnegative double amount );
/** /**
* Removes all thresholds and resets the watcher to a clean state. * Removes all thresholds and resets the watcher to a clean state.
@@ -24,6 +24,9 @@
package appeng.api.networking.energy; package appeng.api.networking.energy;
import javax.annotation.Nonnull;
public interface IEnergyWatcherHost public interface IEnergyWatcherHost
{ {
@@ -33,12 +36,12 @@ public interface IEnergyWatcherHost
* *
* @param newWatcher new watcher * @param newWatcher new watcher
*/ */
void updateWatcher( IEnergyWatcher newWatcher ); void updateWatcher( @Nonnull IEnergyWatcher newWatcher );
/** /**
* Called when a threshold is crossed. * Called when a threshold is crossed.
* *
* @param energyGrid grid * @param energyGrid grid
*/ */
void onThresholdPass( IEnergyGrid energyGrid ); void onThresholdPass( @Nonnull IEnergyGrid energyGrid );
} }
@@ -24,6 +24,8 @@
package appeng.api.networking.pathing; package appeng.api.networking.pathing;
import javax.annotation.Nonnull;
import appeng.api.networking.IGridCache; import appeng.api.networking.IGridCache;
@@ -39,6 +41,7 @@ public interface IPathingGrid extends IGridCache
* @return the controller state of the network, useful if you want to * @return the controller state of the network, useful if you want to
* require a controller for a feature. * require a controller for a feature.
*/ */
@Nonnull
ControllerState getControllerState(); ControllerState getControllerState();
/** /**
@@ -24,6 +24,8 @@
package appeng.api.networking.security; package appeng.api.networking.security;
import javax.annotation.Nonnull;
import appeng.api.networking.IGridNode; import appeng.api.networking.IGridNode;
@@ -38,5 +40,6 @@ public interface IActionHost
* @return the the gridnode that actions from this IGridHost are preformed * @return the the gridnode that actions from this IGridHost are preformed
* by. * by.
*/ */
@Nonnull
IGridNode getActionableNode(); IGridNode getActionableNode();
} }
@@ -24,6 +24,9 @@
package appeng.api.networking.security; package appeng.api.networking.security;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import appeng.api.config.SecurityPermissions; import appeng.api.config.SecurityPermissions;
@@ -46,7 +49,7 @@ public interface ISecurityGrid extends IGridCache
* *
* @return true if the player has permissions. * @return true if the player has permissions.
*/ */
boolean hasPermission( EntityPlayer player, SecurityPermissions perm ); boolean hasPermission( @Nonnull EntityPlayer player, @Nonnull SecurityPermissions perm );
/** /**
* Check if a player has permissions. * Check if a player has permissions.
@@ -56,7 +59,7 @@ public interface ISecurityGrid extends IGridCache
* *
* @return true if the player has permissions. * @return true if the player has permissions.
*/ */
boolean hasPermission( int playerID, SecurityPermissions perm ); boolean hasPermission( @Nonnegative int playerID, @Nonnull SecurityPermissions perm );
/** /**
* @return PlayerID of the admin, or owner, this is the person who placed the security block. * @return PlayerID of the admin, or owner, this is the person who placed the security block.
@@ -25,7 +25,7 @@ package appeng.api.networking.security;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap; import java.util.Map;
import appeng.api.config.SecurityPermissions; import appeng.api.config.SecurityPermissions;
@@ -48,7 +48,7 @@ public interface ISecurityProvider
* *
* @param playerPerms player permissions * @param playerPerms player permissions
*/ */
void readPermissions( HashMap<Integer, EnumSet<SecurityPermissions>> playerPerms ); void readPermissions( Map<Integer, EnumSet<SecurityPermissions>> playerPerms );
/** /**
* @return is security on or off? * @return is security on or off?
@@ -26,6 +26,8 @@ package appeng.api.networking.security;
import java.util.EnumSet; import java.util.EnumSet;
import javax.annotation.Nonnull;
import appeng.api.config.SecurityPermissions; import appeng.api.config.SecurityPermissions;
@@ -41,5 +43,5 @@ public interface ISecurityRegistry
* @param playerID player id * @param playerID player id
* @param permissions permissions of player * @param permissions permissions of player
*/ */
void addPlayer( int playerID, EnumSet<SecurityPermissions> permissions ); void addPlayer( int playerID, @Nonnull EnumSet<SecurityPermissions> permissions );
} }
@@ -24,6 +24,8 @@
package appeng.api.networking.ticking; package appeng.api.networking.ticking;
import javax.annotation.Nonnull;
import appeng.api.networking.IGridNode; import appeng.api.networking.IGridNode;
@@ -45,18 +47,18 @@ public interface IGridTickable
*/ */
/** /**
* You can return null, if you wish to tick using MC's ticking mechanism, or * Return a valid TickingRequest to tell AE a guide for which type of
* you can return a valid TickingRequest to tell AE a guide for which type * responsiveness your device wants.
* of responsiveness your device wants.
* *
* this will be called for your tile any time your tile changes grids, this * This will be called for your tile any time your tile changes grids, this
* can happen at any time, so if your using the sleep feature you may wish * can happen at any time, so if your using the sleep feature you may wish
* to preserve your sleep, in the result of this method. or you can simply * to preserve your sleep, in the result of this method. or you can simply
* reset it. * reset it.
* *
* @return null or a valid new TickingRequest * @return a valid new TickingRequest
*/ */
TickingRequest getTickingRequest( IGridNode node ); @Nonnull
TickingRequest getTickingRequest( @Nonnull IGridNode node );
/** /**
* AE lets you adjust your tick rate based on the results of your tick, if * AE lets you adjust your tick rate based on the results of your tick, if
@@ -67,11 +69,12 @@ public interface IGridTickable
* *
* Note: this is never called if you return null from getTickingRequest. * Note: this is never called if you return null from getTickingRequest.
* *
* @param TicksSinceLastCall the number of world ticks that were skipped since your last * @param ticksSinceLastCall the number of world ticks that were skipped since your last
* tick, you can use this to adjust speed of processing or adjust * tick, you can use this to adjust speed of processing or adjust
* your tick rate. * your tick rate.
* *
* @return tick rate adjustment. * @return tick rate adjustment.
*/ */
TickRateModulation tickingRequest( IGridNode node, int TicksSinceLastCall ); @Nonnull
TickRateModulation tickingRequest( @Nonnull IGridNode node, int ticksSinceLastCall );
} }
@@ -24,6 +24,8 @@
package appeng.api.networking.ticking; package appeng.api.networking.ticking;
import javax.annotation.Nonnull;
import appeng.api.networking.IGridCache; import appeng.api.networking.IGridCache;
import appeng.api.networking.IGridNode; import appeng.api.networking.IGridNode;
@@ -42,7 +44,7 @@ public interface ITickManager extends IGridCache
* *
* @param node gridnode * @param node gridnode
*/ */
boolean alertDevice( IGridNode node ); boolean alertDevice( @Nonnull IGridNode node );
/** /**
* disables ticking for your device. * disables ticking for your device.
@@ -51,7 +53,7 @@ public interface ITickManager extends IGridCache
* *
* @return if the call was successful. * @return if the call was successful.
*/ */
boolean sleepDevice( IGridNode node ); boolean sleepDevice( @Nonnull IGridNode node );
/** /**
* enables ticking for your device, undoes a sleepDevice call. * enables ticking for your device, undoes a sleepDevice call.
@@ -60,5 +62,5 @@ public interface ITickManager extends IGridCache
* *
* @return if the call was successful. * @return if the call was successful.
*/ */
boolean wakeDevice( IGridNode node ); boolean wakeDevice( @Nonnull IGridNode node );
} }
@@ -20,7 +20,6 @@ package appeng.helpers;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import appeng.api.config.SecurityPermissions; import appeng.api.config.SecurityPermissions;
@@ -32,7 +31,7 @@ public class PlayerSecurityWrapper implements ISecurityRegistry
private final Map<Integer, EnumSet<SecurityPermissions>> target; private final Map<Integer, EnumSet<SecurityPermissions>> target;
public PlayerSecurityWrapper( final HashMap<Integer, EnumSet<SecurityPermissions>> playerPerms ) public PlayerSecurityWrapper( final Map<Integer, EnumSet<SecurityPermissions>> playerPerms )
{ {
this.target = playerPerms; this.target = playerPerms;
} }
+26 -17
View File
@@ -22,6 +22,8 @@ package appeng.me.cache;
import java.util.HashMap; import java.util.HashMap;
import java.util.PriorityQueue; import java.util.PriorityQueue;
import com.google.common.base.Preconditions;
import net.minecraft.crash.CrashReport; import net.minecraft.crash.CrashReport;
import net.minecraft.crash.CrashReportCategory; import net.minecraft.crash.CrashReportCategory;
import net.minecraft.util.ReportedException; import net.minecraft.util.ReportedException;
@@ -156,25 +158,26 @@ public class TickManagerCache implements ITickManager
{ {
if( machine instanceof IGridTickable ) if( machine instanceof IGridTickable )
{ {
final TickingRequest tr = ( (IGridTickable) machine ).getTickingRequest( gridNode ); final IGridTickable tickable = ( (IGridTickable) machine );
if( tr != null ) final TickingRequest tr = tickable.getTickingRequest( gridNode );
Preconditions.checkNotNull( tr );
final TickTracker tt = new TickTracker( tr, gridNode, (IGridTickable) machine, this.currentTick, this );
if( tr.canBeAlerted )
{ {
final TickTracker tt = new TickTracker( tr, gridNode, (IGridTickable) machine, this.currentTick, this ); this.alertable.put( gridNode, tt );
}
if( tr.canBeAlerted ) if( tr.isSleeping )
{ {
this.alertable.put( gridNode, tt ); this.sleeping.put( gridNode, tt );
} }
else
if( tr.isSleeping ) {
{ this.awake.put( gridNode, tt );
this.sleeping.put( gridNode, tt ); this.addToQueue( tt );
}
else
{
this.awake.put( gridNode, tt );
this.addToQueue( tt );
}
} }
} }
} }
@@ -200,6 +203,8 @@ public class TickManagerCache implements ITickManager
@Override @Override
public boolean alertDevice( final IGridNode node ) public boolean alertDevice( final IGridNode node )
{ {
Preconditions.checkNotNull( node );
final TickTracker tt = this.alertable.get( node ); final TickTracker tt = this.alertable.get( node );
if( tt == null ) if( tt == null )
{ {
@@ -226,6 +231,8 @@ public class TickManagerCache implements ITickManager
@Override @Override
public boolean sleepDevice( final IGridNode node ) public boolean sleepDevice( final IGridNode node )
{ {
Preconditions.checkNotNull( node );
if( this.awake.containsKey( node ) ) if( this.awake.containsKey( node ) )
{ {
final TickTracker gt = this.awake.get( node ); final TickTracker gt = this.awake.get( node );
@@ -241,6 +248,8 @@ public class TickManagerCache implements ITickManager
@Override @Override
public boolean wakeDevice( final IGridNode node ) public boolean wakeDevice( final IGridNode node )
{ {
Preconditions.checkNotNull( node );
if( this.sleeping.containsKey( node ) ) if( this.sleeping.containsKey( node ) )
{ {
final TickTracker gt = this.sleeping.get( node ); final TickTracker gt = this.sleeping.get( node );
@@ -21,8 +21,8 @@ package appeng.tile.misc;
import java.io.IOException; import java.io.IOException;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@@ -316,7 +316,7 @@ public class TileSecurityStation extends AENetworkTile implements ITerminalHost,
} }
@Override @Override
public void readPermissions( final HashMap<Integer, EnumSet<SecurityPermissions>> playerPerms ) public void readPermissions( final Map<Integer, EnumSet<SecurityPermissions>> playerPerms )
{ {
final IPlayerRegistry pr = AEApi.instance().registries().players(); final IPlayerRegistry pr = AEApi.instance().registries().players();