Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.