Jump to content

Recommended Posts

Posted

Hi everyone.

 

Okay, this time, I have been working on cables for my mod, I have them connecting, the block bounds updating, them rendering the connections, but, now I would like to know how to make them send packets of energy down the line. I don't even know where to start with this. I want it to send packets of power if it finds a place to take it from, a place to put it, and if the place to put it has a block that is requesting power.

 

Any help?

 

Thanks.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

There is two ways to do this, first you could have each cable store a buffer in their nbt(this requires packets+nbt), secondly you could have a device that stores/ uses the energy to scan along the cable until it reaches a power source(this is a bit tedious). If the cables don't use metadata you could use that but it would only be able to store 15 units of energy.

The proud(ish) developer of Ancients

Posted

But I want the cable to send packets to a block that is requesting power, So i dont want the cables to have buffers, and the second idea seems really complicated, and not very practical. By packets I dont mean that the cable actually stores energy, and passes energy onto the next cable, I mean that the cable mearly acts as a graphical connection, and the only physical thing it does it "network" the blocks connected to it. By network, I mean that it allows the blocks connected to the cable to talk to each other, and they pretty much teleport the power to each other. And the block sending can also calculate the distance the receiving block is, and from that, can deduct a certain amount of power, as if there is some energy loss in the cables.

 

So I would like to know How I could set up this network.

 

Sorry, I probably should have been more specific as to what I wanted to do in my main post, Im also sorry for replying late.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

Sorry, but you seem to be asking others tell you exactly how to do this. Personally I believe that part of the fun of making a mod is to overcome this obstacles and figure it out for your self. Also, you basically repeated what memcallen said when he said to scan along the cable until you find a block that accepts energy. Basically, you need to figure this out your self, because it is not that difficult and no one is going to give you the answer.

 

PS:

Sorry if I should a little harsh, but its the truth.

Don't be afraid to ask question when modding, there are no stupid question! Unless you don't know java then all your questions are stupid!

Posted

Okay, thanks for your help. I understand, I guess I should have worded it a bit differently, I wasn't asking for someone to give me the code, I was asking for advice on how to do this. I am not sure where to even start with this. But I guess I can also look on github at mods like mekanism or buildcraft to see how they do it.

 

Thanks anyway.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

Sounds to me you need to have your tileEntity "look" for the cable block creating a list as it goes. IE

public void lookForPowerSource()

{

in here it will start around itself xCoord - 1 and xCoord + 1, same with zCoord

If it finds a cable, save it in a list and look around that cable for other cables, and if it finds one make sure it checks that new cable against the list to make sure it hasn't found it before so you don't have a unlimited loop (like if you had 4 cables in a square and one is attached to the machine)

 

keep going until a cable is connected to a source of power.

 

you should now have a list, of hopefully all connected power sources. Now you can make the lists better (smaller) so getting power is less time consuming by doing some sort of weighted equation for each power source. Kindof how network routing works, it creates a map of the fastest route to the source (by less amount of hops)

}

 

then you toss some catches in to make sure that the stored source in the list is still there "someone removed it" and if all the stored lists are missing try looking for more sources again.

 

There are so many ways to do this, some better some just the worst and everything in between.

Posted

Okay, thanks very much, this was very helpful, very detailed to. I'll update here how this goes, but that'll wait till tomorrow, as I am off to bed.

 

Thanks.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

I believe the easiest way to do this is that each cable block should have int field distanceFromPower that indicates how "close" (in terms of cable length) it is from a power source.  Then each tick each block will check all surrounding neighbor blocks for other cable blocks and update its distanceToPower to be one more than the smallest non-zero distanceToPower field of its neighbors.  Then it checks for any neighboring power source block and if there is then set distanceToPower to 1.  If there is no powered cable or power source neighboring set the distanceToPower to be -1 (represents)  unpowered.

 

If you think through the above logic, within a few ticks of adding a cable or power source the whole power network will be up to date.  You can configure the cables in any pattern,  a mesh, 3d, a spiral, and it will work without needing complicated pathfinding or nested loops.

 

Hope you understand what I mean.

 

The trick then is only in the int field.  You could use metadata but then you probably just need to make it a single bit to indicate "powered".  You could also use TileEntity. I'd probably do that unless you planned to have a lot.  Lastly you can just make a public int 3d array in your main class to store it.  Note it is not important to save this data as it will recalculate next time the game runs.  But if you want to animate you need to sync client and server.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Okay, what sort of list should I use to store the nodes (anything that can accept or send power that isn't a cable) Should I use a LinkedList, or an ArrayList? Or should I even use a HashMap?

 

Also, how do I store the x, y and z coords in the list or map without having 3 seperate lists for each?

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

I have made a class called Network, and this is it so far:

 

 

public class Network {

public ArrayList<TileEntity> networkNodes = new ArrayList<TileEntity>();
public ArrayList<Integer> nodeXpos = new ArrayList<Integer>();
public ArrayList<Integer> nodeYpos = new ArrayList<Integer>();
public ArrayList<Integer> nodeZpos = new ArrayList<Integer>();

public int xPos;
public int yPos;
public int zPos;

public boolean exists = false;

public Network(int x, int y, int z) {

	this.xPos = x;
	this.yPos = y;
	this.zPos = z;

}

public void search(World world, int x, int y, int z) {
	TileEntity tileN = null;
	TileEntity tileS = null;
	TileEntity tileU = null;
	TileEntity tileD = null;
	TileEntity tileE = null;
	TileEntity tileW = null;

	if (world.getTileEntity(x+1, y, z) != null) tileE = world.getTileEntity(x+1, y, z);
	if (world.getTileEntity(x-1, y, z) != null) tileW = world.getTileEntity(x-1, y, z);
	if (world.getTileEntity(x, y+1, z) != null) tileU = world.getTileEntity(x, y+1, z);
	if (world.getTileEntity(x, y-1, z) != null) tileD = world.getTileEntity(x, y-1, z);
	if (world.getTileEntity(x, y, z+1) != null) tileS = world.getTileEntity(x, y, z+1);
	if (world.getTileEntity(x, y, z-1) != null) tileN = world.getTileEntity(x, y, z-1);

	if (tileN != null) this.checkNorth(world, tileN, x+1, y, z);
	if (tileS != null) this.checkSouth(world, tileS, x-1, y, z);
	if (tileU != null) this.checkUp(world, tileU, x, y+1, z);
	if (tileD != null) this.checkDown(world, tileD, x, y-1, z);
	if (tileE != null) this.checkEast(world, tileE, x, y, z+1);
	if (tileW != null) this.checkWest(world, tileW, x, y, z-1);
}

public void checkNorth(World world, TileEntity tile, int x, int y, int z) {
	if (!(tile instanceof IEnergyHandler)) {
		this.search(world, x, y, z);
	} else {
		if (tile instanceof IEnergyHandler) {
			if ((!nodeXpos.contains(x)) && (!nodeYpos.contains(y)) && (!nodeZpos.contains(z))) {
				networkNodes.add(tile);
				nodeXpos.add(x);
				nodeYpos.add(y);
				nodeZpos.add(z);
			}
		}
	}
}

public void checkSouth(World world, TileEntity tile, int x, int y, int z) {
	if (!(tile instanceof IEnergyHandler)) {
		this.search(world, x, y, z);
	} else {
		if (tile instanceof IEnergyHandler) {
			if ((!nodeXpos.contains(x)) && (!nodeYpos.contains(y)) && (!nodeZpos.contains(z))) {
				networkNodes.add(tile);
				nodeXpos.add(x);
				nodeYpos.add(y);
				nodeZpos.add(z);
			}
		}
	}
}

public void checkEast(World world, TileEntity tile, int x, int y, int z) {
	if (!(tile instanceof IEnergyHandler)) {
		this.search(world, x, y, z);
	} else {
		if (tile instanceof IEnergyHandler) {
			if ((!nodeXpos.contains(x)) && (!nodeYpos.contains(y)) && (!nodeZpos.contains(z))) {
				networkNodes.add(tile);
				nodeXpos.add(x);
				nodeYpos.add(y);
				nodeZpos.add(z);
			}
		}
	}
}

public void checkWest(World world, TileEntity tile, int x, int y, int z) {
	if (!(tile instanceof IEnergyHandler)) {
		this.search(world, x, y, z);
	} else {
		if (tile instanceof IEnergyHandler) {
			if ((!nodeXpos.contains(x)) && (!nodeYpos.contains(y)) && (!nodeZpos.contains(z))) {
				networkNodes.add(tile);
				nodeXpos.add(x);
				nodeYpos.add(y);
				nodeZpos.add(z);
			}
		}
	}
}

public void checkUp(World world, TileEntity tile, int x, int y, int z) {
	if (!(tile instanceof IEnergyHandler)) {
		this.search(world, x, y, z);
	} else {
		if (tile instanceof IEnergyHandler) {
			if ((!nodeXpos.contains(x)) && (!nodeYpos.contains(y)) && (!nodeZpos.contains(z))) {
				networkNodes.add(tile);
				nodeXpos.add(x);
				nodeYpos.add(y);
				nodeZpos.add(z);
			}
		}
	}
}

public void checkDown(World world, TileEntity tile, int x, int y, int z) {
	if (!(tile instanceof IEnergyHandler)) {
		this.search(world, x, y, z);
	} else {
		if (tile instanceof IEnergyHandler) {
			if ((!nodeXpos.contains(x)) && (!nodeYpos.contains(y)) && (!nodeZpos.contains(z))) {
				networkNodes.add(tile);
				nodeXpos.add(x);
				nodeYpos.add(y);
				nodeZpos.add(z);
			}
		}
	}
}
}

This class will get called in the tile of the machine sending power.

 

 

 

Now I am not sure if I am missing anything here, I do know that I dont have, and need to have a way to check if a block has been removed from the network, but this is my basic idea on how to do this, also, I am not sure how I could do that. Any suggestions on what I need to add, remove or change?

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

woops... I have already noticed one mistake; I have fixed it by changing:

        if ((!nodeXpos.contains(x)) && (!nodeYpos.contains(y)) && (!nodeZpos.contains(z))) {
	networkNodes.add(tile);
	nodeXpos.add(x);
	nodeYpos.add(y);
	nodeZpos.add(z);
}

to:

        if ((!nodeXpos.contains(x))) {
	nodeXpos.add(x);
} if ((!nodeXpos.contains(y))) {
	nodeXpos.add(z);
} if ((!nodeXpos.contains(z))) {
	nodeXpos.add(z);
}

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

in your posted code you have some copyPasta errors

if ((!nodeXpos.contains(x))) {

nodeXpos.add(x);

} if ((!nodeXpos.contains(y))) {

nodeXpos.add(z);

} if ((!nodeXpos.contains(z))) {

nodeXpos.add(z);

}

they all add into the same array list.

Also you will probably run into an issue since a cable or a line of cables can share all the same x/z locations and a column y locations

 

I made my own class object for a base building system

public class UtilityBlockLocationType 
{
public int x,y,z,meta = 0;
public Block block;
public UtilityBlockLocationType(int x, int y, int z, Block block)
{
	this.x = x;
	this.y = y;
	this.z = z;
	this.block = block;
}

public UtilityBlockLocationType(int x, int y, int z, Block block, int meta)
{
	this.x = x;
	this.y = y;
	this.z = z;
	this.block = block;
	this.meta = meta;
}
}

you might be able to do the same so you would only need one arrayList

ArrayList<CableLocations> cables = new ArrayList<CableLocations>();

 

then your tileEntity that needs power will collect all nearby cables. But I have a better logic Idea.

 

Your tileEntity will look for all powerSources a certain radius away (15 blocks?) in all directions, when it find a tileEntity it checks to see if it is an instanceof PowerSource, and saves those coords (x,y,z)

 

once that is done it should have all powerSoruces in a 15x15x15 zone now it will go through the list, 1st PowerSource before anything, check to see the distance between them disX = (this.xCoord - powerSource.xCoord) disY = ....

 

you should have all the distances now. We all know the fastest way to point A to B is a line. So you can probably make an algorithm or something that will check all the "fastest routes" to the power source making sure that there is a cable block there if not try another fast method until idk 4 times if that fails use the go down all cable blocks route?.

 

if it finds a route that is all cables, it will save the route and reference it to the power source as a list or array.

 

reason for saving the list of cables is so when Machine needs to draw power, check 1st powerSource, has power good, check each cable in the cable route list, if one is missing try to reroute and resave the list. If can't find a route cancel and move to next power source. maybe strike the first powerSource off this list or something.

 

oh and each time a cable block is attached to the machine it will recheck all connections and look for new powerSources.

 

Now my logic is most definitely flawed but some aspects can be used. I just hope it can inspire you or help you figure this out.

Posted

Okay, two questions, one, how would I go about the shortest route calculator? I have found this. would this code work?

 

two, the main bit I am getting stuck on is scanning down the line of cables. That is what I was trying to do in the code I posted above. but apparently...

I am not going to comment on this code. It is horrible in so many ways.

 

it is really bad. :/

 

ps: diesieben07, I am new to ArrarLists, and this is what my code looks like when I am trying to learn something new, It is really bad, and generally doesnt work, I search on google for answers, and if nothing ask for help, and then learn what I have done wrong, and improve.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

Actually I told you how to get started on it, if you get the disX,Y, and Z (these 3 variables are the result of This.xCoord - Source.xCoord, etc.)

 

if the disX is 6 and disZ is 1 the fastest way there is over 6 up 1 (if the cables were in straight lines. Also since those are global coords the fastest route would be 6)

 

now if we say the fastest way to the source is 6 hops if you are wondering where I got the idea of 6 is because it's (horizontal -1 + vertical) this is cables i'm talking about

like I said before the fastest way from A to B is a line so imagin this layout

 

+

------X

 

this is the -6 disX and -1disZ lets just say disY is 0 for simplicity sake. Since cables can connect to any adjacent cable/machine/source we can go over 6 because it will still touch the source. but even if the layout was:

 

+--

  ----X

that is still 6 cables, or 6 hops. Essentially you can use for loops to try and find a correct route or maybe a single While loop that has counters. Something that can run a scan for each possible route (Is 6 in a line left reach the source? no, does 5 over 1 up work? no, does 4 over, 1 up, 1 over work? etc. etc.) untill it exausts it's final attempt of what about I try a line from the disZ

 

+------

        X

 

if that fails try the cable crawler method with a direction to help it along the way with my example it knows it is -- (-x and -z upper left) this will go the slower route of here's a cable, is it connected to the left (-x is greater so that is a preferred start) or connected to the top to another cable.

 

If all this is all too much or you take about a week or more and want to give up. Just have the machines "magically" connect to the power sources and make a visual rendering of cables (like how the lead or fishing rod makes a rope/line)

Posted

Okay, two questions, one, how would I go about the shortest route calculator? I have found this. would this code work?

 

two, the main bit I am getting stuck on is scanning down the line of cables. That is what I was trying to do in the code I posted above. but apparently...

 

Did you read through my suggestion on how to do the scanning?  It is really simple as each cable block can figure out for itself whether it is connected and how long the shortest route is to power source, all without any complicated path finding!

 

Basically each block should only have to scan its neighbors.  Just like real energy, electricity, water, whatever, it will quickly within a few ticks adjust to any added block.  You shouldn't need any loops (because technically Minecraft is already looping through all the block update code).

 

Suggestions like Hugo's don't work well for complicated paths.  Imagine if you made a spiral of cable -- the distance along the cable might be very long even if the power source and final piece of cable are very close to each other.

 

Read my suggestion above again.  I guarantee it is the simplest way to code power distribution networks.

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

jabelar, thanks, I'll have a look into that tomorrow though, as I have to go now unfortunately (I am an hour and a half ahead of the time it says the reply was posted.)

 

and this is what I have so far:

 

 

 

EnergyNetwork.class

package generator.net.theepictekkit.generator.common.energy;

import generator.api.energy.IEnergyHandler;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

public class EnergyNetwork {

public TileEntity tile;
public int x;
public int y;
public int z;
public int searchRange;

public List<NodeLocation> nodePos = new ArrayList<NodeLocation>();

public EnergyNetwork(int searchRange, int x, int y, int z, TileEntity tile) {
	this.x = x;
	this.y = y;
	this.z = z;
	this.tile = tile;
	this.searchRange = searchRange;
}

public void scan(int x, int y, int z, World world) {

	for (int i = x - searchRange; i < x + searchRange; i++) {
		for (int j = y - searchRange; j < y + searchRange; j++) {
			for (int k = z - searchRange; k < z + searchRange; k++) {
				Block block = world.getBlock(i, j, k);
				TileEntity tile = world.getTileEntity(i, j, k);

				if (tile != null && block != null) {
					if (tile instanceof IEnergyHandler) {
						NodeLocation node = new NodeLocation(i, j, k, block);
						if (!nodePos.contains(node)) {
							nodePos.add(node);
						}
						this.getNearestNode(x, y, z, i, j, k, world);
					}
				}
			}
		}
	}
}

public void getNearestNode(int xOrigin, int yOrigin, int zOrigin, int xDest, int yDest, int zDest, World world) {
	double distDirect = this.calcDist(xOrigin, yOrigin, zOrigin, xDest, yDest, zDest);
	int distCable; //Not done yet, but will scan down the cable to find the rout to the nearest node
}

/**
 * 
 * @param xOrigin The X position of this node
 * @param yOrigin The Y position of this node
 * @param zOrigin The Z position of this node
 * @param xDest The X position of the sending node
 * @param yDest The Y position of the sending node
 * @param zDest The Z position of the sending node
 * @return The shortest distance between the two nodes.
 */
public double calcDist(int xOrigin, int yOrigin, int zOrigin, int xDest, int yDest, int zDest) {
	return Math.sqrt((Math.pow((xOrigin - xDest), 2)) + (Math.pow((yOrigin - yDest), 2)) + (Math.pow((zOrigin - zDest), 2)));
}
}

For the calcDist method, it calculates a distance that can be diagonally between blocks, it doesn't have to follow the blocks. I got the formula for the calculation from: http://www.calculatorsoup.com/calculators/geometry-solids/distance-two-points.php

 

Also, this is far from finished.

 

NodeLocation.java

package generator.net.theepictekkit.generator.common.energy;

import net.minecraft.block.Block;
import net.minecraft.tileentity.TileEntity;

public class NodeLocation {

public int x;
public int y;
public int z;
public Block block;
public TileEntity tile;

public NodeLocation(int x, int y, int z, Block block) {
	this.x = x;
	this.y = y;
	this.z = z;
	this.block = block;
}

public int getX() {
	return this.x;
}

public int getY() {
	return this.y;
}

public int getZ() {
	return this.z;
}

@Override
public String toString() {
	return "X:" + x + "Y:" + y + "Z:" + z + "_" + block.getUnlocalizedName();
}
}

 

 

 

Think I am on the right tracks now? defiantly way better than the other class I posted.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

I'm just saying that doing any type of scanning like the way you're coding will drive you crazy if you want to be able to handle any type of configuration.  Imagine a big loop of cable, or a spiral of cable, or cables that cross near each other but are connected to different sources -- those will not be easy to handle the way you're going.  Definitely check out my way of doing it -- no big loops needed (except simple one to scan the directly neighboring blocks).

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

some how I missed your first reply about this jabelar, but now I have a question, just thinking about the worse. What if he has one cable line that connects to two sources? one source has power the other is empty, what does it do if it finds the empty one first?

 

Well, just write the code to handle it, but it is pretty easy.  You just look at each neighbor and if ANY is a power source you can consider your cable powered.  Just set the distance to -1 then loop through all neighbors and if you find a power source set distance to 1.  Then, whether you encounter one or many power sources, you'll still get same answer, and you won't clear it again if you don't find a power source (if you get what I mean).

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

What happens if I have multiple power sources each with energy available? should it just drain the nearest one? say for example I have two blocks that can emit power, and both have power available, ideally I would like it to drain equally from both, and not just from one, so if a machine is requesting 32 Watts/t (my energy) the two blocks that can give power will each send 16 watts/t

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

Okay, I have wrote this method in the EnergyNetwork class:

 

 

        public void scanAlongCable(TileEntity tile, World world, int x, int y, int z) {

	if (world.getTileEntity(x, y, z) != null) { //If this is not null (as this is in a completely different class to the tile, it is entirely possible to be null.

		if (world.getTileEntity(x, y, z-1) != null) { //North - Check if the tile at north side is not null
			if (world.getTileEntity(x, y, z-1) == tile) { //Check if the tile at north side is the same as the tile, if so, it should be another cable
				TileEntityCable tileCable = (TileEntityCable)world.getTileEntity(x, y, z-1); //casting the tileentity at the new coords to TileEntityCable
				tileCable.triggerSearch(x, y, z-1); //Re-Trigger the search on the cable at the new coords as the tile at this position is just another cable
			} else if (world.getTileEntity(x, y, z-1) instanceof IEnergyHandler) { //If the tileentity implements IEnergyHandler, it isnt a cable, and can accept energy
				NodeLocation node = new NodeLocation(x, y, z-1, tile); //Saving this tileentity as a new NodeLocation
				if (!nodePos.contains(node)) { //Checking if nodePos already contains this NodeLocation
					nodePos.add(node); //If not, adding this NodeLocation to nodePos
				}
			} //Do the same as above but for the other 5 directions.
		} if (world.getTileEntity(x, y, z+1) != null) { //South
			if (world.getTileEntity(x, y, z+1) == tile) {
				TileEntityCable tileCable = (TileEntityCable)world.getTileEntity(x, y, z+1);
				tileCable.triggerSearch(x, y, z+1);
			} else if (world.getTileEntity(x, y, z+1) instanceof IEnergyHandler) {
				NodeLocation node = new NodeLocation(x, y, z+1, tile);
				if (!nodePos.contains(node)) {
					nodePos.add(node);
				}
			}
		} if (world.getTileEntity(x+1, y, z) != null) { //East
			if (world.getTileEntity(x+1, y, z) == tile) {
				TileEntityCable tileCable = (TileEntityCable)world.getTileEntity(x+1, y, z);
				tileCable.triggerSearch(x+1, y, z);
			} else if (world.getTileEntity(x+1, y, z) instanceof IEnergyHandler) {
				NodeLocation node = new NodeLocation(x+1, y, z, tile);
				if (!nodePos.contains(node)) {
					nodePos.add(node);
				}
			}
		} if (world.getTileEntity(x-1, y, z) != null) { //West
			if (world.getTileEntity(x-1, y, z) == tile) {
				TileEntityCable tileCable = (TileEntityCable)world.getTileEntity(x-1, y, z);
				tileCable.triggerSearch(x-1, y, z);
			} else if (world.getTileEntity(x-1, y, z) instanceof IEnergyHandler) {
				NodeLocation node = new NodeLocation(x-1, y, z, tile);
				if (!nodePos.contains(node)) {
					nodePos.add(node);
				}
			}
		} if (world.getTileEntity(x, y+1, z) != null) { //Up
			if (world.getTileEntity(x, y+1, z) == tile) {
				TileEntityCable tileCable = (TileEntityCable)world.getTileEntity(x, y+1, z);
				tileCable.triggerSearch(x, y+1, z);
			} else if (world.getTileEntity(x, y+1, z) instanceof IEnergyHandler) {
				NodeLocation node = new NodeLocation(x, y+1, z, tile);
				if (!nodePos.contains(node)) {
					nodePos.add(node);
				}
			}
		} if (world.getTileEntity(x, y-1, z) != null) { //Down
			if (world.getTileEntity(x, y-1, z) == tile) {
				TileEntityCable tileCable = (TileEntityCable)world.getTileEntity(x, y-1, z);
				tileCable.triggerSearch(x, y-1, z);
			} else if (world.getTileEntity(x, y-1, z) instanceof IEnergyHandler) {
				NodeLocation node = new NodeLocation(x, y-1, z, tile);
				if (!nodePos.contains(node)) {
					nodePos.add(node);
				}
			}
		}
	}
}

 

 

 

This method gets called from the tileentity as so:

 

 

EnergyNetwork network = new EnergyNetwork(xCoord, yCoord, zCoord, this);

// alot of connection code between here and the method....

        public void triggerSearch(int x, int y, int z) {
	network.scanAlongCable(this, worldObj, xCoord, yCoord, zCoord);
}

 

 

 

So this is designed to scan down the cable, and if it finds a tileentity that implements IEnergyHandler, it will add it to the list of nodes.

 

Now I have noticed that the x, y, z parameters in the "tileCable.triggerSearch(x, y, z); are redundant, they arent used, because from the tileentity, it uses xCoord, yCoord zCoord instead of x, y, z. So just ignore those parameters, because I have changed it to triggerSearch();

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

Oh, I just found something useful in looking for open source mods on github that do the same thing I am trying to achieve, I had a look at steves factory manager, (modjam mod) for the way vswe made the inventory cables.

 

This is what I have found.

https://github.com/Vswe/ModJam3/blob/master/src/main/java/vswe/stevesfactory/blocks/BlockCable.java

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

Okay, so I have got my network to a point where it can find all nodes connected (I have tested this by making it so that when it finds a node, it sets it to stone.) Now how do I make it so that it can detect when the player removes a node?

 

And of course, by node, I mean a block that can receive, or send energy.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.