Jump to content

[1.11.2] 'Conduit' Transferring Energy to multiple TEs


Recommended Posts

Posted (edited)

Hey there,

 

So I have this basic conduit that transfer RF, however it seems that if the line of conduits are connected to multiple energy acceptors, it only supplies the closet one.. Can someone point me to how to do this?

 

Here is the code I have so far:

 

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

        if(!world.isRemote) {
            int energyStored = getEnergyStored(EnumFacing.DOWN);

            for (EnumFacing facing : EnumFacing.values()) {
                BlockPos pos = getPos().offset(facing);
                TileEntity te = world.getTileEntity(pos);
                if (te instanceof IEnergyHandler || (te != null && te.hasCapability(CapabilityEnergy.ENERGY, null))) {
                    EnumFacing opposite = facing.getOpposite();
                    int rfToGive = SENDPERTICK <= energyStored ? SENDPERTICK : energyStored;
                    int received;

                    if (te instanceof IEnergyConnection) {
                        IEnergyConnection connection = (IEnergyConnection) te;
                        if (connection.canConnectEnergy(opposite)) {
                            received = receiveEnergy(te, opposite, rfToGive);
                        } else {
                            received = 0;
                        }
                    } else {
                        received = receiveEnergy(te, opposite, rfToGive);
                    }
                    energyStored -= storage.extractEnergy(received, false);
                    if (energyStored <= 0) {
                        break;
                    }
                }
            }
        }
    }

    public static int receiveEnergy(TileEntity tileEntity, EnumFacing from, int maxReceive) {
        if (tileEntity instanceof IEnergyReceiver) {
            return ((IEnergyReceiver) tileEntity).receiveEnergy(from, maxReceive, false);
        } else if (tileEntity != null && tileEntity.hasCapability(CapabilityEnergy.ENERGY, from)) {
            net.minecraftforge.energy.IEnergyStorage capability = tileEntity.getCapability(CapabilityEnergy.ENERGY, from);
            if (capability.canReceive()) {
                return capability.receiveEnergy(maxReceive, false);
            }
        }
        return 0;
    }

 

 

Thanks!

Edited by Lambda

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

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.