Jump to content

[1.12.2]Accepting energy from Thermal Expansion and Ender IO


GloriousAlpaca

Recommended Posts

Hello,

I'm trying to make a block that can accept energy, however I have run into some weird behaviour.

First of all this is my code:

	@Override
	public void update(){
		if ((energy.getEnergyStored() != energy.getMaxEnergyStored())) {
			for(EnumFacing face : EnumFacing.values()) {
				BlockPos a = getPos().offset(face);
				TileEntity tile = world.getTileEntity(a);	
					if (tile != null && tile.hasCapability(CapabilityEnergy.ENERGY,face.getOpposite())) {
						int push = tile.getCapability(CapabilityEnergy.ENERGY,face.getOpposite()).extractEnergy(energy.getMaxRec(),false);
						energy.receiveEnergy(push, false);
						System.out.println("ENERGIEZUFUHR: "+energy.getEnergyStored()+" gesendet: "+push);
					}
			}
		}
	}

My block can accept energy from Thermal Expansion energy cells with no problem, on the contrary fluxducts do not work.

It also does not work with Ender IO as it does not detect the energy conduits and, while detecting it, cannot drain an energy bank.

Thank you for your Help!

Link to comment
Share on other sites

As long as you expose the energy capability in your tile the pipes/conduits will be able to push FE into your tile by themsemves and you won't need to manually drain anything. It is not always possible - some mods might not even have their wires have a TileEntity/expose the energy capability but instead treat pipes/conduits as valid "paths" for the energy produced by generators to traverse(aka a simple pathing algorythm). This way a pipe/conduit is but a connector that doesn't have any properties on it's own and it's the power providers that do all the work. As an example here is my TileEntity that has an internal energy storage and can use that energy for specific operations. Note that the only thing it does is expose the energy capability. It doesn't drain any ajacent energy storages or anything. And as far as I am aware it works perfectly fine with TE and EIO and many other mods.

TL;DR: You don't need to drain from pipes/conduits as they tend to eject energy by themselves as long as you expose the FE capability.

 

1 hour ago, GloriousAlpaca said:

cannot drain an energy bank.

It might be the case that the energy bank returns false at IEnergyStorage#canExtract if it is not configured to push to that side.

  • Like 1
Link to comment
Share on other sites

First of all thanks for your time!

I tried completely removing the code in my update method and it still does not work.

The energy cell is being drained however it is just not showing up in my machine.

This is my capability code by the way maybe the error lies in there:

@Override
	public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) {
		if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
		{
			return true;
		}
		if(capability == CapabilityEnergy.ENERGY)
		{
			return true;
		}
		return super.hasCapability(capability, facing);
		
	}
	
	@Nullable
	@Override
	public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) {
		if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
		{
			return (T)inventory;
		}
		if(capability == CapabilityEnergy.ENERGY)
		{
			return (T)energy;
		}
		return super.getCapability(capability, facing);
	}
	

 

Link to comment
Share on other sites

15 minutes ago, V0idWa1k3r said:

How do you know it's not there?

You were right, it is there it is just not showing up in my Gui.

15 minutes ago, V0idWa1k3r said:

are you sure you are properly syncing the energy to the client?

Which is why this is probably the Problem. How would I sync it to the client?

Edit: I am definitely not syncing it correctly as the console shows me the correct amount of energy on the server and 0 on the client.

Edited by GloriousAlpaca
Link to comment
Share on other sites

11 minutes ago, GloriousAlpaca said:

How would I sync it to the client?

Depends on what behaviour do you need. If you only need the energy to be visible in the GUI use the vanilla container listener system:

  • Have a local field storing the last energy value in the container.
  • In Container#detectAndSendChanges compare the local value to the actual energy value. If they differ send the actual value to all listeners using IContainerListener#sendWindowProperty. You can use the second argument to differentiate between different data you need to send to the clients.
  • In Container#updateProgressBar(client-side only!) you will get the data alongside with the ID you've assigned to it. Compare the IDs and if it maches set the tile's energy to data you got.
  • Send the initial data values to new listeners in Container#addListener using the same IContainerListener#sendWindowProperty

This method ensures that every player who has the container opened will see the correct values. You can see an example of me using this to sync the energy in my container here.

 

However if you need more than that(for example your rendering depends on the amount of energy you have) the container isn't the best solution since it will only work while the player has the container opened. In this case you will have to use packets.

  • Like 1
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.