Jump to content

Recommended Posts

Posted

Then how do you recommend I fix it?

To do what Choonster said you cant use a world Capability. Instead use just the events he suggested. Mainly the ChunkDataEvent ones. They will allow you to save specifically to a chunk. Through the usage of the ChunkDataEvent.Load/Save#getData which returns an NBTTagCompound. I didn't know these events existed and glossed over the ChunkDataEvent in Choonsters post.

 

You can use a

World

capability to store the

Map

at runtime, it just won't save the data to NBT itself; that will be handled with

ChunkDataEvent.Load

/

Save

.

Then what is the point of having the capability? You could just store it in the event then access the event through the instance of your mod.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Replies 59
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted

Then what is the point of having the capability? You could just store it in the event then access the event through the instance of your mod.

 

You need a way to store a per-dimension, per-side

Map<ChunkPos, YourData>

. There are other ways to do this, but capabilities are probably the easiest.

 

I made a system similar to this last night, it stores a single energy value for each chunk. You can see the implementation here.

 

To the OP: If you're going to use my code, please try to understand how it works and re-implement it yourself rather than copy/pasting it.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Okay, so great progress, however, I'm trying to setup a 'default value' of the energy inside the chunk, however, I'm having a hard time doing so, I've tried making another IVoidStorage and VoidStorage classes that closely replicates the Energy ones, but in the constructor have the energy set to the capacity.. However, when doing this it seems the chunks return null when looking for the energy attached to it.. Maybe there is another way than creating another energy handler?

 

Thanks.

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

Posted

Okay, so great progress, however, I'm trying to setup a 'default value' of the energy inside the chunk, however, I'm having a hard time doing so, I've tried making another IVoidStorage and VoidStorage classes that closely replicates the Energy ones, but in the constructor have the energy set to the capacity.. However, when doing this it seems the chunks return null when looking for the energy attached to it.. Maybe there is another way than creating another energy handler?

 

Thanks.

Show the code where you do that.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

Here is the IVoidStorage:

public interface IVoidStorage
{
    /**
     * Adds energy to the storage. Returns quantity of energy that was accepted.
     *
     * @param maxReceive
     *            Maximum amount of energy to be inserted.
     * @param simulate
     *            If TRUE, the insertion will only be simulated.
     * @return Amount of energy that was (or would have been, if simulated) accepted by the storage.
     */
    int receiveVoidEnergy(int maxReceive, boolean simulate);

    /**
     * Removes energy from the storage. Returns quantity of energy that was removed.
     *
     * @param maxExtract
     *            Maximum amount of energy to be extracted.
     * @param simulate
     *            If TRUE, the extraction will only be simulated.
     * @return Amount of energy that was (or would have been, if simulated) extracted from the storage.
     */
    int extractVoidEnergy(int maxExtract, boolean simulate);

    /**
     * Returns the amount of energy currently stored.
     */
    int getVoidEnergyStored();

    /**
     * Returns the maximum amount of energy that can be stored.
     */
    int getMaxVoidEnergyStored();

    /**
     * Returns if this storage can have energy extracted.
     * If this is false, then any calls to extractEnergy will return 0.
     */
    boolean canExtract();

    /**
     * Used to determine if this storage can receive energy.
     * If this is false, then any calls to receiveEnergy will return 0.
     */
    boolean canReceive();

}

 

The VoidStorage:

public class VoidStorage implements IVoidStorage
{
    protected int energy;
    protected int capacity;
    protected int maxReceive;
    protected int maxExtract;

    public VoidStorage(int capacity)
    {
        this(capacity, capacity, capacity);
    }

    public VoidStorage(int capacity, int maxTransfer)
    {
        this(capacity, maxTransfer, maxTransfer);
    }

    public VoidStorage(int capacity, int maxReceive, int maxExtract)
    {
        this.energy = capacity;
        this.capacity = capacity;
        this.maxReceive = maxReceive;
        this.maxExtract = maxExtract;
    }

    @Override
    public int receiveVoidEnergy(int maxReceive, boolean simulate)
    {
        if (!canReceive())
            return 0;

        int energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive));
        if (!simulate)
            energy += energyReceived;
        return energyReceived;
    }

    @Override
    public int extractVoidEnergy(int maxExtract, boolean simulate)
    {
        if (!canExtract())
            return 0;

        int energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract));
        if (!simulate)
            energy -= energyExtracted;
        return energyExtracted;
    }

    @Override
    public int getVoidEnergyStored()
    {
        return energy;
    }

    @Override
    public int getMaxVoidEnergyStored()
    {
        return capacity;
    }

    @Override
    public boolean canExtract()
    {
        return this.maxExtract > 0;
    }

    @Override
    public boolean canReceive()
    {
        return this.maxReceive > 0;
    }
}

With this code, the energy is not max out like I want it to be upon generation..

 

Also, when creating a new world, you have to relog for the energy values to assign...

You can view the github if you want the rest of the code

 

 

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

Posted

There's no need to create a separate parent interface (

IVoidStorage

) if you're copying

IEnergyStorage

instead of extending it. Just use the one interface with all the methods from

IEnergyStorage

in it.

 

If you want a default energy value for each chunk, change the NBT deserialisation method (the

ChunkDataEvent.Load

handler) to use that default value when a chunk doesn't have a stored value. My code uses 0 for the default value.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Anyways, would you know why the energy isnt assigned until a restart occurs (only when you make a new world)? Is it something I can fix or is that just Minecraft and I cant really do anything about it.

 

I don't know why that's happening, my code doesn't have that issue.

 

I suggest stepping through your code in the debugger to see what's going on.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.