-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the default implementation of wired networks
- Loading branch information
Showing
9 changed files
with
1,326 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/dan200/computercraft/shared/wired/DefaultWiredProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package dan200.computercraft.shared.wired; | ||
|
||
import dan200.computercraft.api.network.wired.IWiredElement; | ||
import dan200.computercraft.api.network.wired.IWiredElementTile; | ||
import dan200.computercraft.api.network.wired.IWiredProvider; | ||
import net.minecraft.tileentity.TileEntity; | ||
import net.minecraft.util.EnumFacing; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.IBlockAccess; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
public class DefaultWiredProvider implements IWiredProvider | ||
{ | ||
@Nullable | ||
@Override | ||
public IWiredElement getElement( @Nonnull IBlockAccess world, @Nonnull BlockPos pos, @Nonnull EnumFacing side ) | ||
{ | ||
TileEntity te = world.getTileEntity( pos ); | ||
return te instanceof IWiredElementTile ? ((IWiredElementTile) te).getWiredElement( side ) : null; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/dan200/computercraft/shared/wired/InvariantChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package dan200.computercraft.shared.wired; | ||
|
||
import dan200.computercraft.ComputerCraft; | ||
|
||
/** | ||
* Verifies certain elements of a network are "well formed". | ||
* | ||
* This adds substantial overhead to network modification, and so should only be enabled | ||
* in a development environment. | ||
*/ | ||
public class InvariantChecker | ||
{ | ||
private static final boolean ENABLED = false; | ||
|
||
public static void checkNode( WiredNode node ) | ||
{ | ||
if( !ENABLED ) return; | ||
|
||
WiredNetwork network = node.network; | ||
if( network == null ) | ||
{ | ||
ComputerCraft.log.error( "Node's network is null", new Exception() ); | ||
return; | ||
} | ||
|
||
if( network.nodes == null || !network.nodes.contains( node ) ) | ||
{ | ||
ComputerCraft.log.error( "Node's network does not contain node", new Exception() ); | ||
} | ||
|
||
for( WiredNode neighbour : node.neighbours ) | ||
{ | ||
if( !neighbour.neighbours.contains( node ) ) | ||
{ | ||
ComputerCraft.log.error( "Neighbour is missing node", new Exception() ); | ||
} | ||
} | ||
} | ||
|
||
public static void checkNetwork( WiredNetwork network ) | ||
{ | ||
if( !ENABLED ) return; | ||
|
||
for( WiredNode node : network.nodes ) checkNode( node ); | ||
} | ||
} |
Oops, something went wrong.