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.

[1.11.2] [SOLVED] Transfer Energy

Featured Replies

Posted

Hi,

 

I'm wondering how I can transfer energy from a producer to a consumer via a cable.

 

public class TileEntityCable extends TileEntity implements ITickable {
	
    // kind of wrapper for Tesla and ForgeEnergy, extends EnergyStorage from Forge, no methods added
	public final EnergyManager container;
	
	public TileEntityCable() {
		this.container = new EnergyManager(1, 1); // capacity 1, maxReceive and maxExtract 1
	}
	
	@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)); // TODO all other directions
			
			if(tileEntity != null && !tileEntity.isInvalid()) {
				this.container.extractEnergy(10, false);
				// TODO
			}
		}
		
		if(hasUpdated) {// save changes to disk
			IBlockState state = this.getWorld().getBlockState(this.getPos());
			this.getWorld().notifyBlockUpdate(this.getPos(), state, state, 3);
			this.markDirty();
		}
	}
  
  // TODO: getCapability & hasCapability
}

 

My problems:

  • searching for a better way to handle all directions
  • How can I transfer energy from a producer like a Solar Panel into cable a which links to cable b and c and from cable c into the consumer, for example an electric furnance.

 

Ok, found a solution: this.container.receiveEnergy(storage.extractEnergy(1, false), false);

 

Thx in advance.

Bektor

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