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

How can i make a structure generate only once?

i want to make a structure which generates only once and not everytime a new chunk is beeing generated.

i got the code to work but the problem is i used a variable to check if the structure is already generated.

but when i exit the game it resets the variable and the structure is beeing generated again.

so can i write the variable to NBT or something?

or is there another way to save variables in for example in my baseclass or CommonProxy?

  • Author

i did that but it wont save.

i set my variable to true and when i restart the game it is false again.

if(world.loadItemData(WorldSaveData.class, "LegendzWorldSaveData") == null){
		WorldSavedData data = new WorldSaveData("LegendzWorldSaveData");
		world.setItemData("LegendzWorldSaveData", data);
	}

	WorldSaveData worldSaveData = (WorldSaveData) world.loadItemData(WorldSaveData.class, "LegendzWorldSaveData");


	System.out.println(worldSaveData.alreadyGenerated[0]);

i put this in the generate method in my WorldGenerator.

and here is my WorldSaveData Class

package legendz.common;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraft.world.WorldSavedData;
import net.minecraft.world.storage.MapStorage;

public class WorldSaveData extends WorldSavedData {

public static boolean[] alreadyGenerated = new boolean[8];

public WorldSaveData(String par1Str) {
	super(par1Str);
}

@Override
public void readFromNBT(NBTTagCompound nbt) {
	for(int i = 0; i < alreadyGenerated.length; i++){
		alreadyGenerated[i] = nbt.getBoolean("generated"+i);
	}
}

@Override
public void writeToNBT(NBTTagCompound nbt) {
	for(int i = 0; i < alreadyGenerated.length; i++){
		nbt.setBoolean("generated"+i, alreadyGenerated[i]);
	}
}

}

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.