Added routing nodes and a bit of infrastructure - not even working yet.
This commit is contained in:
parent
9950b32d53
commit
8b0756e9da
|
@ -0,0 +1,29 @@
|
|||
package WayofTime.bloodmagic.block;
|
||||
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import WayofTime.bloodmagic.api.Constants;
|
||||
import WayofTime.bloodmagic.routing.TileMasterRoutingNode;
|
||||
|
||||
public class BlockMasterRoutingNode extends BlockContainer
|
||||
{
|
||||
public BlockMasterRoutingNode()
|
||||
{
|
||||
super(Material.rock);
|
||||
|
||||
setUnlocalizedName(Constants.Mod.MODID + ".masterRouting");
|
||||
setCreativeTab(BloodMagic.tabBloodMagic);
|
||||
setHardness(2.0F);
|
||||
setResistance(5.0F);
|
||||
setHarvestLevel("pickaxe", 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World worldIn, int meta)
|
||||
{
|
||||
return new TileMasterRoutingNode();
|
||||
}
|
||||
}
|
|
@ -1,16 +1,45 @@
|
|||
package WayofTime.bloodmagic.registry;
|
||||
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import WayofTime.bloodmagic.ConfigHandler;
|
||||
import WayofTime.bloodmagic.api.Constants;
|
||||
import WayofTime.bloodmagic.block.*;
|
||||
import WayofTime.bloodmagic.item.block.*;
|
||||
import WayofTime.bloodmagic.tile.*;
|
||||
import WayofTime.bloodmagic.util.helper.InventoryRenderHelper;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import WayofTime.bloodmagic.BloodMagic;
|
||||
import WayofTime.bloodmagic.ConfigHandler;
|
||||
import WayofTime.bloodmagic.api.Constants;
|
||||
import WayofTime.bloodmagic.block.BlockAlchemyArray;
|
||||
import WayofTime.bloodmagic.block.BlockAltar;
|
||||
import WayofTime.bloodmagic.block.BlockBloodLight;
|
||||
import WayofTime.bloodmagic.block.BlockBloodRune;
|
||||
import WayofTime.bloodmagic.block.BlockBloodStoneBrick;
|
||||
import WayofTime.bloodmagic.block.BlockCrystal;
|
||||
import WayofTime.bloodmagic.block.BlockLifeEssence;
|
||||
import WayofTime.bloodmagic.block.BlockMasterRoutingNode;
|
||||
import WayofTime.bloodmagic.block.BlockPedestal;
|
||||
import WayofTime.bloodmagic.block.BlockPhantom;
|
||||
import WayofTime.bloodmagic.block.BlockRitualController;
|
||||
import WayofTime.bloodmagic.block.BlockRitualStone;
|
||||
import WayofTime.bloodmagic.block.BlockSoulForge;
|
||||
import WayofTime.bloodmagic.block.BlockSpectral;
|
||||
import WayofTime.bloodmagic.block.BlockTeleposer;
|
||||
import WayofTime.bloodmagic.block.BlockTestSpellBlock;
|
||||
import WayofTime.bloodmagic.item.block.ItemBlockBloodRune;
|
||||
import WayofTime.bloodmagic.item.block.ItemBlockBloodStoneBrick;
|
||||
import WayofTime.bloodmagic.item.block.ItemBlockCrystal;
|
||||
import WayofTime.bloodmagic.item.block.ItemBlockPedestal;
|
||||
import WayofTime.bloodmagic.item.block.ItemBlockRitualController;
|
||||
import WayofTime.bloodmagic.item.block.ItemBlockRitualStone;
|
||||
import WayofTime.bloodmagic.routing.TileMasterRoutingNode;
|
||||
import WayofTime.bloodmagic.tile.TileAlchemyArray;
|
||||
import WayofTime.bloodmagic.tile.TileAltar;
|
||||
import WayofTime.bloodmagic.tile.TileImperfectRitualStone;
|
||||
import WayofTime.bloodmagic.tile.TileMasterRitualStone;
|
||||
import WayofTime.bloodmagic.tile.TilePhantomBlock;
|
||||
import WayofTime.bloodmagic.tile.TilePlinth;
|
||||
import WayofTime.bloodmagic.tile.TileSoulForge;
|
||||
import WayofTime.bloodmagic.tile.TileSpectralBlock;
|
||||
import WayofTime.bloodmagic.tile.TileTeleposer;
|
||||
import WayofTime.bloodmagic.util.helper.InventoryRenderHelper;
|
||||
|
||||
public class ModBlocks
|
||||
{
|
||||
|
@ -32,6 +61,8 @@ public class ModBlocks
|
|||
public static Block crystal;
|
||||
public static Block bloodStoneBrick;
|
||||
|
||||
public static Block masterRoutingNode;
|
||||
|
||||
public static void init()
|
||||
{
|
||||
FluidRegistry.registerFluid(BlockLifeEssence.getLifeEssence());
|
||||
|
@ -51,6 +82,7 @@ public class ModBlocks
|
|||
soulForge = registerBlock(new BlockSoulForge());
|
||||
crystal = registerBlock(new BlockCrystal(), ItemBlockCrystal.class);
|
||||
bloodStoneBrick = registerBlock(new BlockBloodStoneBrick(), ItemBlockBloodStoneBrick.class);
|
||||
masterRoutingNode = registerBlock(new BlockMasterRoutingNode());
|
||||
|
||||
initTiles();
|
||||
}
|
||||
|
@ -66,6 +98,7 @@ public class ModBlocks
|
|||
GameRegistry.registerTileEntity(TilePhantomBlock.class, Constants.Mod.MODID + ":" + TilePhantomBlock.class.getSimpleName());
|
||||
GameRegistry.registerTileEntity(TileTeleposer.class, Constants.Mod.MODID + ":" + TileTeleposer.class.getSimpleName());
|
||||
GameRegistry.registerTileEntity(TileSoulForge.class, Constants.Mod.MODID + ":" + TileSoulForge.class.getSimpleName());
|
||||
GameRegistry.registerTileEntity(TileMasterRoutingNode.class, Constants.Mod.MODID + ":" + TileMasterRoutingNode.class.getSimpleName());
|
||||
}
|
||||
|
||||
public static void initRenders()
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package WayofTime.bloodmagic.routing;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.util.BlockPos;
|
||||
|
||||
public interface IMasterRoutingNode extends IRoutingNode
|
||||
{
|
||||
public boolean isConnected(List<BlockPos> path, BlockPos nodePos);
|
||||
|
||||
public void addNodeToList(IRoutingNode node);
|
||||
|
||||
public void addConnections(BlockPos pos, List<BlockPos> connectionList);
|
||||
|
||||
public void addConnection(BlockPos pos1, BlockPos pos2);
|
||||
|
||||
public void removeConnection(BlockPos pos1, BlockPos pos2);
|
||||
}
|
19
src/main/java/WayofTime/bloodmagic/routing/IRoutingNode.java
Normal file
19
src/main/java/WayofTime/bloodmagic/routing/IRoutingNode.java
Normal file
|
@ -0,0 +1,19 @@
|
|||
package WayofTime.bloodmagic.routing;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IRoutingNode
|
||||
{
|
||||
public void connectMasterToRemainingNode(World world, List<BlockPos> alreadyChecked, IMasterRoutingNode master);
|
||||
|
||||
public BlockPos getBlockPos();
|
||||
|
||||
public List<BlockPos> getConnected();
|
||||
|
||||
public BlockPos getMasterPos();
|
||||
|
||||
public boolean isConnectionEnabled(BlockPos testPos);
|
||||
}
|
25
src/main/java/WayofTime/bloodmagic/routing/NodeHelper.java
Normal file
25
src/main/java/WayofTime/bloodmagic/routing/NodeHelper.java
Normal file
|
@ -0,0 +1,25 @@
|
|||
package WayofTime.bloodmagic.routing;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class NodeHelper
|
||||
{
|
||||
public static boolean isNodeConnectionEnabled(World world, IRoutingNode node, BlockPos testPos)
|
||||
{
|
||||
if (!node.isConnectionEnabled(testPos))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
TileEntity tile = world.getTileEntity(testPos);
|
||||
if (!(tile instanceof IRoutingNode))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
IRoutingNode testNode = (IRoutingNode) tile;
|
||||
|
||||
return testNode.isConnectionEnabled(node.getBlockPos());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,159 @@
|
|||
package WayofTime.bloodmagic.routing;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class TileMasterRoutingNode extends TileEntity implements IMasterRoutingNode
|
||||
{
|
||||
// A list of connections
|
||||
private HashMap<BlockPos, List<BlockPos>> connectionMap = new HashMap<BlockPos, List<BlockPos>>();
|
||||
private List<BlockPos> generalNodeList = new LinkedList<BlockPos>();
|
||||
|
||||
@Override
|
||||
public boolean isConnected(List<BlockPos> path, BlockPos nodePos)
|
||||
{
|
||||
if (!connectionMap.containsKey(nodePos))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
TileEntity tile = worldObj.getTileEntity(nodePos);
|
||||
if (!(tile instanceof IRoutingNode))
|
||||
{
|
||||
connectionMap.remove(nodePos);
|
||||
return false;
|
||||
}
|
||||
|
||||
IRoutingNode node = (IRoutingNode) tile;
|
||||
List<BlockPos> connectionList = node.getConnected();
|
||||
List<BlockPos> testPath = path.subList(0, path.size());
|
||||
testPath.add(nodePos);
|
||||
for (BlockPos testPos : connectionList)
|
||||
{
|
||||
if (testPath.contains(testPos))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (testPos.equals(this.getPos()) && node.isConnectionEnabled(testPos))
|
||||
{
|
||||
path.clear();
|
||||
path.addAll(testPath);
|
||||
return true;
|
||||
} else if (NodeHelper.isNodeConnectionEnabled(worldObj, node, testPos))
|
||||
{
|
||||
if (isConnected(testPath, testPos))
|
||||
{
|
||||
path.clear();
|
||||
path.addAll(testPath);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnectionEnabled(BlockPos testPos)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNodeToList(IRoutingNode node)
|
||||
{
|
||||
BlockPos newPos = node.getBlockPos();
|
||||
if (!generalNodeList.contains(newPos))
|
||||
{
|
||||
generalNodeList.add(newPos);
|
||||
}
|
||||
|
||||
//TODO: make more node lists so that you can more easily differentiate the different types of nodes
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addConnections(BlockPos pos, List<BlockPos> connectionList)
|
||||
{
|
||||
for (BlockPos testPos : connectionList)
|
||||
{
|
||||
addConnection(pos, testPos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addConnection(BlockPos pos1, BlockPos pos2)
|
||||
{
|
||||
if (connectionMap.containsKey(pos1) && !connectionMap.get(pos1).contains(pos2))
|
||||
{
|
||||
connectionMap.get(pos1).add(pos2);
|
||||
} else
|
||||
{
|
||||
List<BlockPos> list = new LinkedList<BlockPos>();
|
||||
list.add(pos2);
|
||||
connectionMap.put(pos1, list);
|
||||
}
|
||||
|
||||
if (connectionMap.containsKey(pos2) && !connectionMap.get(pos2).contains(pos1))
|
||||
{
|
||||
connectionMap.get(pos2).add(pos1);
|
||||
} else
|
||||
{
|
||||
List<BlockPos> list = new LinkedList<BlockPos>();
|
||||
list.add(pos1);
|
||||
connectionMap.put(pos2, list);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeConnection(BlockPos pos1, BlockPos pos2)
|
||||
{
|
||||
if (connectionMap.containsKey(pos1))
|
||||
{
|
||||
List<BlockPos> posList = connectionMap.get(pos1);
|
||||
posList.remove(pos2);
|
||||
if (posList.isEmpty())
|
||||
{
|
||||
connectionMap.remove(pos1);
|
||||
}
|
||||
}
|
||||
|
||||
if (connectionMap.containsKey(pos2))
|
||||
{
|
||||
List<BlockPos> posList = connectionMap.get(pos2);
|
||||
posList.remove(pos1);
|
||||
if (posList.isEmpty())
|
||||
{
|
||||
connectionMap.remove(pos2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectMasterToRemainingNode(World world, List<BlockPos> alreadyChecked, IMasterRoutingNode master)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getBlockPos()
|
||||
{
|
||||
return this.getPos();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockPos> getConnected()
|
||||
{
|
||||
return new LinkedList<BlockPos>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getMasterPos()
|
||||
{
|
||||
return this.getPos();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package WayofTime.bloodmagic.tile.routing;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import WayofTime.bloodmagic.routing.IMasterRoutingNode;
|
||||
import WayofTime.bloodmagic.routing.IRoutingNode;
|
||||
|
||||
public class TileRoutingNode extends TileEntity implements IRoutingNode
|
||||
{
|
||||
private BlockPos masterPos = BlockPos.ORIGIN;
|
||||
private List<BlockPos> connectionList = new LinkedList<BlockPos>();
|
||||
|
||||
@Override
|
||||
public void connectMasterToRemainingNode(World world, List<BlockPos> alreadyChecked, IMasterRoutingNode master)
|
||||
{
|
||||
List<BlockPos> connectedList = this.getConnected();
|
||||
for (BlockPos testPos : connectedList)
|
||||
{
|
||||
if (alreadyChecked.contains(testPos))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
alreadyChecked.add(testPos);
|
||||
TileEntity tile = world.getTileEntity(testPos);
|
||||
if (!(tile instanceof IRoutingNode))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
IRoutingNode node = (IRoutingNode) tile;
|
||||
if (node.getMasterPos().equals(BlockPos.ORIGIN)) //If getMasterPos() returns the origin, the node is not connected to any master.
|
||||
{
|
||||
master.addNodeToList(node);
|
||||
node.connectMasterToRemainingNode(world, alreadyChecked, master);
|
||||
}
|
||||
}
|
||||
|
||||
master.addConnections(this.getBlockPos(), connectedList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getBlockPos()
|
||||
{
|
||||
return this.getPos();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockPos> getConnected()
|
||||
{
|
||||
return connectionList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getMasterPos()
|
||||
{
|
||||
return masterPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnectionEnabled(BlockPos testPos)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue