Jump to content

Recommended Posts

Posted

Hey there,

I'm trying to use the RF API (https://github.com/CoFH/RedstoneFlux-API) in my mod and currently I'm trying to create a power generator. I have successfully gotten power to generate, however it just sits there inside the generator. Cables (universal cables from Mekanism are what I'm using to test because TE crashes in my modding environment) connect to the generator but the power goes nowhere.

 

Specific generator class:

 

public class TileWindTurbine extends TileEntityBasicGenerator
{

public TileWindTurbine(int output, int generated)
{
	super(output, generated);
}

@Override
protected void generate()
{
	if (worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord) > 7)
	{
		storage.modifyEnergyStored(generated); //TODO Check in "generatable" conditions
	}
}

@Override
public boolean canConnectEnergy(ForgeDirection from)
{
	if (from != ForgeDirection.UP) return true;
	else return false;
}

}

 

 

Generator base code:

 

public abstract class TileEntityBasicGenerator extends TileEntity implements IEnergyHandler, IEnergyProvider
{
protected EnergyStorage storage = new EnergyStorage(10000);
public int output;
public int generated;

public TileEntityBasicGenerator(int output, int generated)
{
	this.output = output;
	this.generated = generated;
	storage.setMaxReceive(0);
	storage.setMaxExtract(output);
	storage.setMaxTransfer(output);
}

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

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

@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)
{
	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);
}

@Override
public void updateEntity()
{
	super.updateEntity();
	generate();
}

protected abstract void generate();
}

 

 

If you need to see any more code it's all here: https://github.com/Roboguy99/Food-Tech

 

Any help with the issue will be greatly appreciated and even a link to documentation, which I have been unable to find, would be nice. Thanks.

I have no idea what I'm doing.

Posted

Pipes wont extract energy from your tile your tile needs to send the energy to the pipes. Here is the code i use to output energy from my tiles.

@Override
public void updateEntity() {
if ((storage.getEnergyStored() > 0)) {
	for (int i = 0; i < 6; i++){
		TileEntity tile = worldObj.getTileEntity(xCoord + ForgeDirection.getOrientation(i).offsetX, yCoord + ForgeDirection.getOrientation(i).offsetY, zCoord + ForgeDirection.getOrientation(i).offsetZ);
		if (tile != null && tile instanceof IEnergyHandler) {
			storage.extractEnergy(((IEnergyHandler)tile).receiveEnergy(ForgeDirection.getOrientation(i).getOpposite(), storage.extractEnergy(storage.getMaxExtract(), true), false), false);
		}
	}
}
}

 

Hope this helps.

I am the author of Draconic Evolution

Posted

Pipes wont extract energy from your tile your tile needs to send the energy to the pipes. Here is the code i use to output energy from my tiles.

@Override
public void updateEntity() {
if ((storage.getEnergyStored() > 0)) {
	for (int i = 0; i < 6; i++){
		TileEntity tile = worldObj.getTileEntity(xCoord + ForgeDirection.getOrientation(i).offsetX, yCoord + ForgeDirection.getOrientation(i).offsetY, zCoord + ForgeDirection.getOrientation(i).offsetZ);
		if (tile != null && tile instanceof IEnergyHandler) {
			storage.extractEnergy(((IEnergyHandler)tile).receiveEnergy(ForgeDirection.getOrientation(i).getOpposite(), storage.extractEnergy(storage.getMaxExtract(), true), false), false);
		}
	}
}
}

 

Hope this helps.

 

Thanks! Could you run me through exactly what it does though please because I don't really want a bunch of code I don't get in my mod.

I have no idea what I'm doing.

Posted

It checks if the stored energy of your TE is not 0.

If it's true, then it will go to each side of your block (

for

loop), grabbing the TileEntity from the block of the current side (if it has one, else it'll be

null

) and checks if the TileEntity is an instance of

IEnergyHandler

(you can omit the null-check, it's automatically done by the

instanceof

keyword).

If that is true, it will extract energy from your TE and insert that into the other TE.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

This should also help you figure out how it works. Its exactly the same code just spread out a bit to make it easier to read.

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) {

		int maxExtract = storage.getMaxExtract(); //Gets the maximum amount of energy that can be extracted from this tile in one tick.
		int maxAvailable = storage.extractEnergy(maxExtract, true); //Simulates removing "maxExtract" to find out how much energy is actually available.
		int energyTransferred = ((IEnergyHandler) tile).receiveEnergy(ForgeDirection.getOrientation(i).getOpposite(), maxAvailable, false); //Sends "maxAvailable" to the target tile and records how much energy was accepted. 

		storage.extractEnergy(energyTransferred, false);//Extract the energy transferred from the internal storage.
	}
}
}

 

@SanAndreasP Thanks for letting me know about the redundant null check.

I am the author of Draconic Evolution

Posted

You could just use a

for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)

loop instead of the

for(int i = 0; i < 6; i++)

, and use

dir.*

instead of

ForgeDirection.getOrientation(i).*

.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

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.