Jump to content

RF Pipes


SiriusWolf

Recommended Posts

So, I've been trying to create an RF cable/pipe. So far I can get them to render in the right directions based off connections (thanks btw to Draco for help with that)

and I'm trying to get my TE to move the power. When I test it in normal mc not the test environment it connects to machines and other pipes, but the power isn't moving.

I was under the impression I didn't have to pull power as machines and pipes all generally send it. Here's my current TE, which is started by my block class; this current one

is a cap of 960 and the storage max is 1000.

 

 

 

package net.siriusmc.mod;

import cofh.api.energy.EnergyStorage;
import cofh.api.energy.IEnergyProvider;
import cofh.api.energy.IEnergyConnection;
import cofh.api.energy.IEnergyHandler;
import cofh.api.energy.IEnergyContainerItem;
import cofh.api.energy.IEnergyReceiver;
import cofh.api.energy.IEnergyStorage;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;

public class TileEntitySPipe extends TileEntity implements IEnergyHandler, IEnergyProvider, IEnergyReceiver{

public ForgeDirection[] connections = new ForgeDirection[6];

protected EnergyStorage storage;
public int output;

World world;


public TileEntitySPipe(int output, World world) {
	this.output = output;
	this.storage = new EnergyStorage(1000);
	storage.setMaxReceive(output);
	storage.setMaxExtract(output);
	storage.setMaxTransfer(output);
}

public void updateEntity() {
	this.updateConnections();


	if (storage.getEnergyStored() > 0)
	{
		for (int i = 0; i < 6; i++)
		{

			//ForgeDirection is a useful helper class for handling directions.
			int targetX = xCoord + ForgeDirection.getOrientation(i).offsetX;
			int targetY = yCoord + ForgeDirection.getOrientation(i).offsetY;
			int targetZ = zCoord + ForgeDirection.getOrientation(i).offsetZ;

			TileEntity tile = worldObj.getTileEntity(targetX, targetY, targetZ);
			if (tile instanceof IEnergyHandler) {
				System.out.println("YOLOOOOO -- instanceof IEnergyHandler");
				int maxExtract = storage.getMaxExtract();
				int maxAvailable = storage.extractEnergy(maxExtract, true);
				int energyTransferred = ((IEnergyHandler) tile).receiveEnergy(ForgeDirection.getOrientation(i).getOpposite(), maxAvailable, false);
                                        System.out.println(String.format("ME {0}, MA {1}, ET {2}", maxExtract, maxAvailable, energyTransferred));
				storage.extractEnergy(energyTransferred, false);
			}
		}
	}


}

public void updateConnections() {
	if(this.worldObj.getTileEntity(xCoord, yCoord + 1, zCoord) instanceof IEnergyHandler) connections[0] = ForgeDirection.UP;
	else connections[0] = null;

	if(this.worldObj.getTileEntity(xCoord, yCoord - 1, zCoord) instanceof IEnergyHandler) connections[1] = ForgeDirection.DOWN;
	else connections[1] = null;

	if(this.worldObj.getTileEntity(xCoord, yCoord, zCoord - 1) instanceof IEnergyHandler) connections[2] = ForgeDirection.NORTH;
	else connections[2] = null;

	if(this.worldObj.getTileEntity(xCoord, yCoord, zCoord + 1) instanceof IEnergyHandler) connections[3] = ForgeDirection.SOUTH;
	else connections[3] = null;

	if(this.worldObj.getTileEntity(xCoord + 1, yCoord, zCoord) instanceof IEnergyHandler) connections[4] = ForgeDirection.EAST;
	else connections[4] = null;

	if(this.worldObj.getTileEntity(xCoord - 1, yCoord, zCoord) instanceof IEnergyHandler) connections[5] = ForgeDirection.WEST;
	else connections[5] = null;
}

public boolean onlyOneOpposite(ForgeDirection[] directions) {
	ForgeDirection mainDirection = null;
	boolean isOpposite = false;

	for(int i = 0; i < directions.length; i++) {

		if(mainDirection == null && directions[i] != null) mainDirection = directions[i];

		if(directions[i] != null && mainDirection != directions[i]) {
			if(!isOpposite(mainDirection, directions[i])) return false;
			else isOpposite = true;
		}
	}

	return isOpposite;
}

public boolean isOpposite(ForgeDirection firstDirection, ForgeDirection secondDirection) {

	if((firstDirection.equals(ForgeDirection.NORTH) && secondDirection.equals(ForgeDirection.SOUTH)) || 
			firstDirection.equals(ForgeDirection.SOUTH) && secondDirection.equals(ForgeDirection.NORTH)) return true;

	if((firstDirection.equals(ForgeDirection.EAST) && secondDirection.equals(ForgeDirection.WEST)) || 
			firstDirection.equals(ForgeDirection.WEST) && secondDirection.equals(ForgeDirection.EAST)) return true;

	if((firstDirection.equals(ForgeDirection.UP) && secondDirection.equals(ForgeDirection.DOWN)) || 
			firstDirection.equals(ForgeDirection.DOWN) && secondDirection.equals(ForgeDirection.UP)) return true;

	return false;
}

@Override
public boolean canConnectEnergy(ForgeDirection from) {
	return true;
}

@Override
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate)
{
	return this.storage.receiveEnergy(maxReceive, simulate);
}

@Override
public int extractEnergy(ForgeDirection from, int maxExtract,
		boolean simulate) {

	return storage.extractEnergy(storage.getMaxExtract(), simulate);
}

@Override
public int getEnergyStored(ForgeDirection from) {
	return storage.getEnergyStored();
}

@Override
public int getMaxEnergyStored(ForgeDirection from) {
	// TODO Auto-generated method stub
	return storage.getMaxEnergyStored();
}

//	@Override
//	public void readFromNBT(NBTTagCompound nbt) {
//
//		super.readFromNBT(nbt);
//		storage.readFromNBT(nbt);
//	}
//
//	@Override
//	public void writeToNBT(NBTTagCompound nbt) {
//
//		super.writeToNBT(nbt);
//		storage.writeToNBT(nbt);
//	}


}

 

 

I'm using storage.extractEnergy because I thought it needs to simulate the run to see what the proper amount to move is first.

I also have the NBT commented out cus I'm not sure if I need them.

When I run that the debug print I get is 0, 1, 2. When I change those 3 variables above all 2 960 it still doesn't move anything. No idea what I'm doing wrong.

a.k.a. Sirius

width=400 height=82http://i.imgur.com/QRtYi6e.png[/img]

Link to comment
Share on other sites

Will take a closer look later today but at a glance

@Override
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) {	
return storage.extractEnergy(storage.getMaxExtract(), simulate);
}

needs to be

@Override
public int extractEnergy(ForgeDirection from, int maxExtract,	boolean simulate) {
return storage.extractEnergy(maxExtract, simulate);
}

I am the author of Draconic Evolution

Link to comment
Share on other sites

You will need the nbt in order to save the storage value but it is not required for it to work.

 

Try with just one of your conduits between the energy source and the energy receiver you may have an energy loop (energy is sent from conduit A to conduit B then from conduit B back to conduit A etc. )

I am the author of Draconic Evolution

Link to comment
Share on other sites

Ok so I made that adjustment you mentioned, and that fixed the energy issue. Thank You!

But I'm still noticing that it's only connecting to certain machines. BC machines are fine,

but it doesn't recognize MFR machines as anything that it can connect to, and it only accepts power

if the pipe is going straight. Is that a fault in my code?

 

Visual Explination:

 

 

Working...bWa2V4P.png

Not Working...zqlAowh.png

 

 

 

a.k.a. Sirius

width=400 height=82http://i.imgur.com/QRtYi6e.png[/img]

Link to comment
Share on other sites

Oook, so for anyone having these same issues, lemme tell you that I added IEnergyHandler & IEnergyConnection to my connection

checks. So far I can pull, move, and pass power to about 3 different mods but sometimes it doesn't grab unless it's straight on

from the source. Not sure if that's me or the other mod yet. Minefactory Reloaded also isn't accepting power from these yet;

not sure if it's something I'm doing. But hopefully what I have figured out will help others.

a.k.a. Sirius

width=400 height=82http://i.imgur.com/QRtYi6e.png[/img]

Link to comment
Share on other sites

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.