Jump to content

[1.10.2 | 1.11.2] [UNSOLVED] Transport Energy from A to B


Recommended Posts

Posted

Hi,

 

I'm currently trying to implement a energy system and I'm now wondering how I can transport energy from

a point A to a point B.

 

That's my current code:

 

public class TileEntityCable extends TileEntity implements ITickable {

public final BaseEnergyContainer container;

public TileEntityCable() {
	this.container = new BaseEnergyContainer ();
}

@Override
public void update() {
	boolean hasUpdated = false;

	if(this.hasWorld() && !this.world.isRemote) {
		hasUpdated = true;
		final TileEntity tileEntity = this.getWorld().getTileEntity(this.getPos().offset(EnumFacing.DOWN));

		if(tileEntity != null && !tileEntity.isInvalid()) {
			if(tileEntity.hasCapability(CapabilityEnergy.ENERGY, EnumFacing.UP)) {
				IEnergyStorage consumer = tileEntity.getCapability(CapabilityEnergy.ENERGY, EnumFacing.UP);

				if(consumer != null) {
					hasUpdated = true;
					this.container.extractEnergy(consumer.receiveEnergy(this.container.getEnergyStored(), false), false);
				}
			}
		}
	}

	if(hasUpdated) // save changes to disk
		this.markDirty();
}

@Override
public void readFromNBT(NBTTagCompound compound) {
	super.readFromNBT(compound);
	this.container.deserializeNBT(compound.getCompoundTag("Energy"));
}

@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
	compound.setTag("Energy", this.container.serializeNBT());
	return super.writeToNBT(compound);
}

@Override
public SPacketUpdateTileEntity getUpdatePacket() {
	return super.getUpdatePacket();
}

@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
	super.onDataPacket(net, pkt);
	this.readFromNBT(pkt.getNbtCompound());
}

@Override
@SuppressWarnings("unchecked")
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) {
	if(facing == EnumFacing.DOWN && capability == CapabilityEnergy.ENERGY)
		return (T) this.container;

	return super.getCapability(capability, facing);
}

@Override
public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) {
	if(facing == EnumFacing.DOWN && capability == CapabilityEnergy.ENERGY)
		return true;

	return super.hasCapability(capability, facing);
}
}

 

 

When now putting one of my solar panels (from a thread before) on the top of those cables and one under those cables (cause who needs a battery :P)

there is no energy transferred between them, or atleast no energy gets into the solar panel under those cables. Only in the moment I connect the solar panel with the cables about 16 energy units go into the solar panel at the bottom, but after this first connection... nothing.

 

It would also be nice to know how to transfer energy between two blocks which aren't direclty connected. ;)

 

Thx in advance.

Bektor

Developer of Primeval Forest.

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.