Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hi,

I'm looking to save ArrayLists, in the WorldSavedData class. I already have the following:

 
 
0
 Advanced issue found
 
 
Spoiler

package net.kidkoder.allergies.data;

import net.minecraft.nbt.CompoundNBT;
import net.minecraft.world.storage.WorldSavedData;

public class DataPlayerAllergies extends WorldSavedData {
    private boolean dirty;

    public DataPlayerAllergies() {
        super("playerDataAllergies");
    }

    @Override
    public void read(CompoundNBT nbt) {

    }

    @Override
    public CompoundNBT write(CompoundNBT compound) {
        return null;
    }

    @Override
    public boolean isDirty() {
        return dirty;
    }
}

 

How do I save an ArrayList in to the class in a diffrent class, then retrive it when I need it?

 

 

Thanks in advance,

Kid Koder

1 hour ago, KidKoderMod033109 said:

How do I save an ArrayList in to the class in a diffrent class, then retrive it when I need it?

Wait what? The ArrayList should be in your WorldSavedData class.

Use a ListNBT to store a "list" of Items.

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.

  • Author

I have a class that has the logic to decide what does into the ArrayList, and I want to save that ArrayList to data in the world, Then, when the World is loaded again, to read the data and use it. I am using WorldSavedData because it seemed like it would work. If you know any other way to do this, please tell me(Please avoid from file stuff such as creating a file for each world). 

Just do what @Animefan8888 said. Save the data in the list using a ListNBT with the write method, then read it back using the read method. Don't forget to call markDirty when the data changes in order to have it actually save.

I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.

8 minutes ago, KidKoderMod033109 said:

I have a class that has the logic to decide what does into the ArrayList, and I want to save that ArrayList to data in the world

Put the logic into the WorldSavedData class?

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.

10 minutes ago, KidKoderMod033109 said:

The whole mod is based upon the logic and requires the logic to be in that class.

Why? It's your code you can manipulate it any way you want.

 

10 minutes ago, KidKoderMod033109 said:

But, I have thought to create a "config" file for each world, would that work/how would I do that?

You can't do that using the forge config system.

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.

Just now, Animefan8888 said:

You can't do that using the forge config system.

Can't you? I believe the SERVER config type will do exactly what is desired, unless the javadocs are misleading me.

 

I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.

  • Author
5 minutes ago, Animefan8888 said:

You can't do that using the forge config system.

I mean't create a new "config file" in the world folder, then can be read back.

imacatlol said: 

Can't you? I believe the SERVER config type will do exactly what is desired, unless the javadocs are misleading me.

@imacatlololHow do I do that?

Edited by KidKoderMod033109

8 minutes ago, imacatlolol said:

Can't you? I believe the SERVER config type will do exactly what is desired, unless the javadocs are misleading me.

 

Honestly it might, but I'm not sure that's something worth testing. Maybe the OP can enlighten us when/if they try 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.

Just now, Animefan8888 said:

Honestly it might, but I'm not sure that's something worth testing. Maybe the OP can enlighten us when/if they try it.

Good point, it might be easier to go with the WorldSavedData, especially since that was what OP wanted in the first place.

It's at least still valuable to learn about Forge's config system in general I guess.

I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.

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...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.