Jump to content

[1.11] World Capabilities.


Lambda

Recommended Posts

Okay, so why does modifying the values of the keys have to do with my 'energy'? I know I'm doing something wrong here:

 

                        cap.chunkData.put(cap.chunkData.get(new ChunkPos(this.getPos()), /* new value */);

 

Is this correct?

 

If I'm getting this right, then when we assigned the map, ChuckPos is our key, which contains our x,y, and the integer part stores the x,y values? Correct?

No the integer is your energy... the x and y values are in the ChunkPos...

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.

Link to comment
Share on other sites

  • Replies 59
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Should I be accessing that map somewhere in my capability? Right now I have this:

 

public class CapabilityVoidEnergyData implements IVoidStorage {

    protected int capacity;
    protected int voidStorage;
    protected int regen;

    public Map<ChunkPos, Integer> chunkData = new HashMap<ChunkPos, Integer>();


    public CapabilityVoidEnergyData(int capacity, int voidStorage, int regen) {
        this.capacity = capacity;
        this.voidStorage = voidStorage;
        this.regen = regen;
    }

    @Override
    public void receiveVoidEnergy(int receive) {
        if(canReceiveVoidEnergy(receive)) {
            this.setVoidStorage(this.getVoidEnergyStored() + receive);
        }
    }

    @Override
    public void extractVoidEnergy(int extract) {
        if(canExtractVoidEnergy(extract)) {
            this.setVoidStorage(this.getVoidEnergyStored() - extract);
        }
    }

    public boolean canExtractVoidEnergy(float amount) {
        if((this.getVoidEnergyStored() - amount) >= 0) {
            return true;
        }else {
            return false;
        }
    }

    public boolean canReceiveVoidEnergy(float amount) {
        if((this.getVoidEnergyStored() + amount) <= this.getMaxVoidEnergyStored()) {
            return true;
        }else {
            return false;
        }
    }

    public NBTBase writeData() {
        NBTTagCompound tag = new NBTTagCompound();
        return tag;
    }

    public void readData(NBTBase nbt) {

    }

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

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

    public void setVoidStorage(int amount) {
        this.voidStorage = amount;
    }

    @Override
    public boolean canExtract() {
        return false;
    }

    @Override
    public boolean canReceive() {
        return false;
    }
}

 

And I'm not accessing the map value anywhere, should I just remove the 'voidenergy' integer, and just return the map value?

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

Link to comment
Share on other sites

Is this correct?

 

No, for several reasons.

For one, the return of

this.getPos()

is a ChunkPos, you don't need to construct a new ChunkPos with it.

Second, the return of

cap.chunkData.get()

is your value, which cannot be used as the key to put new data in.

 

cap.chunkData.put(this.getPos(), /*new value*/);

If you want to modify the value (not replace it), then

cap.chunkData.put(this.getPos(), cap.chunkData.get(this.getPos()) + /*some modifier*/);

 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Okay for something like this:

    @Override
    public int getVoidEnergyStored() {
        return chunkData.get();
    }

 

What would I get?

You should get an error because there is no key for the get method.

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.

Link to comment
Share on other sites

Yes I know, Thats the question, what should I be getting.

You will be getting an Integer.

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.

Link to comment
Share on other sites

Is this correct?

 

No, for several reasons.

For one, the return of

this.getPos()

is a ChunkPos, you don't need to construct a new ChunkPos with it.

Second, the return of

cap.chunkData.get()

is your value, which cannot be used as the key to put new data in.

 

cap.chunkData.put(this.getPos(), /*new value*/);

If you want to modify the value (not replace it), then

cap.chunkData.put(this.getPos(), cap.chunkData.get(this.getPos()) + /*some modifier*/);

 

Thanks for your detailed repose, however

this.getPos()

is a BlockPos not a ChuckPos, so I'll need to do construct it (this is inside a TE).

 

 

Yes I know, Thats the question, what should I be getting.

You will be getting an Integer.

 

Yes I know that, but what would I put into the get method ( What obj )

 

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

Link to comment
Share on other sites

Yes I know, Thats the question, what should I be getting.

You will be getting an Integer.

 

Yes I know that, but what would I put into the get method ( What obj )

A ChunkPos(your key). Did you read that link I sent you?

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.

Link to comment
Share on other sites

Thanks for your detailed repose, however
this.getPos()

is a BlockPos not a ChuckPos, so I'll need to do construct it (this is inside a TE).

 

Point.  That's what I get for not having Eclipse open.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Yes I know, Thats the question, what should I be getting.

You will be getting an Integer.

 

Yes I know that, but what would I put into the get method ( What obj )

A ChunkPos(your key). Did you read that link I sent you?

 

Yes but I dont have access to a chunkPos.. Should include that in the parameters?

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

Link to comment
Share on other sites

Yes I know, Thats the question, what should I be getting.

You will be getting an Integer.

 

Yes I know that, but what would I put into the get method ( What obj )

A ChunkPos(your key). Did you read that link I sent you?

 

Yes but I dont have access to a chunkPos.. Should include that in the parameters?

Yes

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.

Link to comment
Share on other sites

So this:

    @Override
    public int getVoidEnergyStored(ChunkPos pos) {
        return chunkData.get(pos);
    }

Does it error?

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.

Link to comment
Share on other sites

No, seems I get a nullpointer there:

---- Minecraft Crash Report ----
// Who set us up the TNT?

Time: 12/31/16 4:23 PM
Description: Exception in server tick loop

java.lang.NullPointerException: Exception in server tick loop
at com.lambda.plentifulutilities.world.CapabilityVoidEnergyData.getVoidEnergyStored(CapabilityVoidEnergyData.java:76)
at com.lambda.plentifulutilities.event.CommonSideEvents.onChuckLoadEvent(CommonSideEvents.java:40)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_9_CommonSideEvents_onChuckLoadEvent_Load.invoke(.dynamic)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:185)
at net.minecraftforge.common.chunkio.ChunkIOProvider.syncCallback(ChunkIOProvider.java:98)
at net.minecraftforge.common.chunkio.ChunkIOExecutor.syncChunkLoad(ChunkIOExecutor.java:94)
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:125)
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:96)
at net.minecraft.world.gen.ChunkProviderServer.provideChunk(ChunkProviderServer.java:142)
at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:340)
at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:107)
at net.minecraft.server.integrated.IntegratedServer.init(IntegratedServer.java:124)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:507)
at java.lang.Thread.run(Thread.java:745)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- System Details --
Details:
Minecraft Version: 1.11.2
Operating System: Windows 10 (amd64) version 10.0
Java Version: 1.8.0_91, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 1303337144 bytes (1242 MB) / 1724383232 bytes (1644 MB) up to 3814195200 bytes (3637 MB)
JVM Flags: 0 total; 
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP 9.38 Powered by Forge 13.20.0.2201 5 mods loaded, 5 mods active
States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
UCHIJAA	minecraft{1.11.2} [Minecraft] (minecraft.jar) 
UCHIJAA	mcp{9.19} [Minecraft Coder Pack] (minecraft.jar) 
UCHIJAA	FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.11.2-13.20.0.2201.jar) 
UCHIJAA	forge{13.20.0.2201} [Minecraft Forge] (forgeSrc-1.11.2-13.20.0.2201.jar) 
UCHIJAA	plentifulutilities{${version}} [Plentiful Utilities] (PlentifulUtilities_main) 
Loaded coremods (and transformers): 
GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.
Profiler Position: N/A (disabled)
Player Count: 0 / 8; []
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'

 

at

    @Override
    public int getVoidEnergyStored(ChunkPos pos) {
        return chunkData.get(pos);
    }

 

Here is the entire class converted, I dont know if it will work :/

public class CapabilityVoidEnergyData implements IVoidStorage {

    protected int capacity;
    protected int regen;

    public Map<ChunkPos, Integer> chunkData = new HashMap<ChunkPos, Integer>();


    public CapabilityVoidEnergyData(int capacity, int regen) {
        this.capacity = capacity;
        this.regen = regen;
    }

    @Override
    public int receiveVoidEnergy(int receive, ChunkPos pos) {
        if(canReceiveVoidEnergy(receive, pos)) {
            this.setVoidStorage(this.getVoidEnergyStored(pos) + receive, pos);
            return this.getMaxVoidEnergyStored() + receive;
        }else {
            return 0;
        }
    }

    @Override
    public int extractVoidEnergy(int extract, ChunkPos pos) {
        if(canExtractVoidEnergy(extract, pos)) {
            this.setVoidStorage(this.getVoidEnergyStored(pos) - extract, pos);
            return this.getMaxVoidEnergyStored() - extract;
        }else {
            return 0;
        }
    }

    public boolean canExtractVoidEnergy(float amount, ChunkPos pos) {
        if((this.getVoidEnergyStored(pos) - amount) >= 0) {
            return true;
        }else {
            return false;
        }
    }

    public boolean canReceiveVoidEnergy(float amount, ChunkPos pos) {
        if((this.getVoidEnergyStored(pos) + amount) <= this.getMaxVoidEnergyStored()) {
            return true;
        }else {
            return false;
        }
    }

    public NBTBase writeData() {
        NBTTagCompound tag = new NBTTagCompound();
        return tag;
    }

    public void readData(NBTBase nbt) {

    }

    @Override
    public int getVoidEnergyStored(ChunkPos pos) {
        return chunkData.get(pos);
    }

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

    public void setVoidStorage(int amount, ChunkPos pos) {
        chunkData.put(pos, amount);
    }

    @Override
    public boolean canExtract() {
        return false;
    }

    @Override
    public boolean canReceive() {
        return false;
    }
}

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

Link to comment
Share on other sites

No, seems I get a nullpointer there:

---- Minecraft Crash Report ----
// Who set us up the TNT?

Time: 12/31/16 4:23 PM
Description: Exception in server tick loop

java.lang.NullPointerException: Exception in server tick loop
at com.lambda.plentifulutilities.world.CapabilityVoidEnergyData.getVoidEnergyStored(CapabilityVoidEnergyData.java:76)
at com.lambda.plentifulutilities.event.CommonSideEvents.onChuckLoadEvent(CommonSideEvents.java:40)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_9_CommonSideEvents_onChuckLoadEvent_Load.invoke(.dynamic)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:185)
at net.minecraftforge.common.chunkio.ChunkIOProvider.syncCallback(ChunkIOProvider.java:98)
at net.minecraftforge.common.chunkio.ChunkIOExecutor.syncChunkLoad(ChunkIOExecutor.java:94)
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:125)
at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:96)
at net.minecraft.world.gen.ChunkProviderServer.provideChunk(ChunkProviderServer.java:142)
at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:340)
at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:107)
at net.minecraft.server.integrated.IntegratedServer.init(IntegratedServer.java:124)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:507)
at java.lang.Thread.run(Thread.java:745)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- System Details --
Details:
Minecraft Version: 1.11.2
Operating System: Windows 10 (amd64) version 10.0
Java Version: 1.8.0_91, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 1303337144 bytes (1242 MB) / 1724383232 bytes (1644 MB) up to 3814195200 bytes (3637 MB)
JVM Flags: 0 total; 
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP 9.38 Powered by Forge 13.20.0.2201 5 mods loaded, 5 mods active
States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
UCHIJAA	minecraft{1.11.2} [Minecraft] (minecraft.jar) 
UCHIJAA	mcp{9.19} [Minecraft Coder Pack] (minecraft.jar) 
UCHIJAA	FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.11.2-13.20.0.2201.jar) 
UCHIJAA	forge{13.20.0.2201} [Minecraft Forge] (forgeSrc-1.11.2-13.20.0.2201.jar) 
UCHIJAA	plentifulutilities{${version}} [Plentiful Utilities] (PlentifulUtilities_main) 
Loaded coremods (and transformers): 
GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.
Profiler Position: N/A (disabled)
Player Count: 0 / 8; []
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'

 

at

    @Override
    public int getVoidEnergyStored(ChunkPos pos) {
        return chunkData.get(pos);
    }

 

Here is the entire class converted, I dont know if it will work :/

public class CapabilityVoidEnergyData implements IVoidStorage {

    protected int capacity;
    protected int regen;

    public Map<ChunkPos, Integer> chunkData = new HashMap<ChunkPos, Integer>();


    public CapabilityVoidEnergyData(int capacity, int regen) {
        this.capacity = capacity;
        this.regen = regen;
    }

    @Override
    public int receiveVoidEnergy(int receive, ChunkPos pos) {
        if(canReceiveVoidEnergy(receive, pos)) {
            this.setVoidStorage(this.getVoidEnergyStored(pos) + receive, pos);
            return this.getMaxVoidEnergyStored() + receive;
        }else {
            return 0;
        }
    }

    @Override
    public int extractVoidEnergy(int extract, ChunkPos pos) {
        if(canExtractVoidEnergy(extract, pos)) {
            this.setVoidStorage(this.getVoidEnergyStored(pos) - extract, pos);
            return this.getMaxVoidEnergyStored() - extract;
        }else {
            return 0;
        }
    }

    public boolean canExtractVoidEnergy(float amount, ChunkPos pos) {
        if((this.getVoidEnergyStored(pos) - amount) >= 0) {
            return true;
        }else {
            return false;
        }
    }

    public boolean canReceiveVoidEnergy(float amount, ChunkPos pos) {
        if((this.getVoidEnergyStored(pos) + amount) <= this.getMaxVoidEnergyStored()) {
            return true;
        }else {
            return false;
        }
    }

    public NBTBase writeData() {
        NBTTagCompound tag = new NBTTagCompound();
        return tag;
    }

    public void readData(NBTBase nbt) {

    }

    @Override
    public int getVoidEnergyStored(ChunkPos pos) {
        return chunkData.get(pos);
    }

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

    public void setVoidStorage(int amount, ChunkPos pos) {
        chunkData.put(pos, amount);
    }

    @Override
    public boolean canExtract() {
        return false;
    }

    @Override
    public boolean canReceive() {
        return false;
    }
}

Well then the value is null. Post your ChunkLoad Event

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.

Link to comment
Share on other sites

    @SubscribeEvent
    public void onChuckLoadEvent(ChunkDataEvent.Load event) {
        if(event.getWorld().hasCapability(CapabilityVoidEnergy.VOID, null)) {
            CapabilityVoidEnergyData cap = event.getWorld().getCapability(CapabilityVoidEnergy.VOID, null);
            cap.chunkData.put(event.getChunk().getPos(), cap.getVoidEnergyStored(event.getChunk().getPos()));
        }
    }

Relatively new to modding.

Currently developing:

https://github.com/LambdaXV/DynamicGenerators

Link to comment
Share on other sites

This is not going to work.

cap.chunkData.put(event.getChunk().getPos(), cap.getVoidEnergyStored(event.getChunk().getPos()));

Think about it.

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.

Link to comment
Share on other sites

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.

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.

Link to comment
Share on other sites

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

.

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.

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.