Jump to content

[1.7.10] EnergyStorage


jtmnf

Recommended Posts

Hi! I'm using Redstone Flux API to make my blocks (TileEntities) store some energy! Everything worked fine here!

 

But, I'm having some problems... If I have 2 or more blocks placed (they can be far away for each other) they share the same energy, even if they aren't charging... Imagine that I have 3 blocks placed, the X, the Y and the Z... Y and Z are far away from the X... I open the GUI of the 3 of them and the energy is 0... But, if I charge the X, all three blocks start to have energy... The energy is shared , but the GUI don't...

 

I have this in the TileEntity: public static EnergyStorage energyStorage = new EnergyStorage(1000000);

With this, I thought I could separate each block with is own energystorage and not share with others... But that's what's happening... If I'm charging one block, the others are charged too :\

 

What am I doing wrong?

 

Thanks,

João Fernandes

Thanks :)

João Fernandes

Link to comment
Share on other sites

You are right on that, my bad! But now, it doesn't charge!

 

    /* ====================================================================================== */
    /* =================================== IEnergyHandler =================================== */
    /* ====================================================================================== */

    @Override
    public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) {
        return energyStorage.receiveEnergy(maxReceive, simulate);
    }

    @Override
    public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) {
        return 0;
    }

    @Override
    public int getEnergyStored(ForgeDirection from) {
        return energyStorage.getEnergyStored();
    }

    @Override
    public int getMaxEnergyStored(ForgeDirection from) {
        return energyStorage.getMaxEnergyStored();
    }

    @Override
    public boolean canConnectEnergy(ForgeDirection from) {
        return true;
    }

 

I know I'm missing something, but I'm not sure what is it...

Thanks :)

João Fernandes

Link to comment
Share on other sites

But this is the only code that matters... I implemented IEnergyHandler and implemented those methods... I created an EnergyStorage on my TileEntity and then, the receiveEnergy() method should work if energy is received...

Thanks :)

João Fernandes

Link to comment
Share on other sites

What are you using to charge the blocks?

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

aaaaah i got it. u arent syncing the values between client and server, which isnt an issue when it was static, because client and server was in the same machine. but now the values arent static, so u need to manually sync the values between client and server side if u want to display them, which means that u will need to use packets

 

EDIT: http://www.minecraftforge.net/forum/index.php?topic=20135.0

Link to comment
Share on other sites

i just realized that there are better ways to do that, sorry.

Whenever you open a guicontainer u already got a pipeline to send informations, so no need to use packets, my bad.

u should take a look how the furnace is syncing the values, should be GuiFurnace there is some stuff about updating the variables

Link to comment
Share on other sites

I saw the GuiFurnace and I opened the Container... There are some things diferent, and that might be the case of this not working...

 

public class CentrifugeContainer extends Container {
    private CentrifugeTileEntity machine;

    public CentrifugeContainer(InventoryPlayer inventoryPlayer, CentrifugeTileEntity centrifugeTileEntity) {
        this.machine = centrifugeTileEntity;

        for(int i = 0; i < 9; ++i){
            addSlotToContainer(new Slot(inventoryPlayer, i, 20 + 18*i, 107));
        }

        for(int i = 0; i < 3; ++i){
            for(int j = 0; j < 9; ++j){
                addSlotToContainer(new Slot(inventoryPlayer, j + i*9 + 9, 20 + 18*j, 49 + i*18));
            }
        }

        addSlotToContainer(new Slot(machine, 0, 20, 18));

        addSlotToContainer(new SlotZero(machine, 1, 56, );
        addSlotToContainer(new SlotZero(machine, 2, 75, );
        addSlotToContainer(new SlotZero(machine, 3, 94, );

        addSlotToContainer(new SlotZero(machine, 4, 56, 27));
        addSlotToContainer(new SlotZero(machine, 5, 75, 27));
        addSlotToContainer(new SlotZero(machine, 6, 94, 27));

        addSlotToContainer(new Slot(machine, 7, 164, );
    }

    @Override
    public boolean canInteractWith(EntityPlayer player) {
        return machine.isUseableByPlayer(player);
    }

    @Override
    public ItemStack transferStackInSlot(EntityPlayer player, int i) {
        return null;
    }
}

Thanks :)

João Fernandes

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.