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.

Intensuwwe

Members
  • Joined

  • Last visited

  1. Solved Here is how I did it (Thanks to bedrock_miner and diesiben07) http://www.minecraftforge.net/forum/index.php?topic=10567.0
  2. package duke_Frans.Isis; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraft.world.WorldSavedData; public class FavorEventHandler extends WorldSavedData{ private static final String IDENTIFIER = "GaiaFavor"; public FavorEventHandler(String identifier) { super(identifier); } public FavorEventHandler(){ super(IDENTIFIER); } @Override public void readFromNBT(NBTTagCompound nbt) { FavorMeter.favor = nbt.getFloat("GaiaFavor"); } @Override public void writeToNBT(NBTTagCompound nbt) { nbt.setFloat("GaiaFavor", FavorMeter.favor); } public static FavorEventHandler get(World world) { FavorEventHandler data = (FavorEventHandler)world.loadItemData(FavorEventHandler.class, IDENTIFIER); if (data == null) { data = new FavorEventHandler(); world.setItemData(IDENTIFIER, data); } return data; } } How would I get the favor amount in my gui rendering class? with: this.mc.renderEngine.bindTexture(texture_Green); renderFarquad(res.getScaledWidth()/2-182/2, 5, 182*favor, 5);
  3. Where/how did you register it? I used the defualt forge method ( MinecraftForge.EVENT_BUS.register) I printed out lines but they didnt show up in console, so obviously its not running
  4. Hi I need to save a float(Favor) to the world save. I have tried basically every tutorial, and approach to solve this. I eventually came across some tutorial to save NBT data, which works, but it is attatched/tied to the player, eg across all worlds This is the code: package duke_Frans.Isis; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraftforge.common.IExtendedEntityProperties; public class ExtendedPlayer implements IExtendedEntityProperties { public final static String EXT_PROP_NAME = "ExtendedPlayer"; private final EntityPlayer player; public static final int FAVOR_WATCHER = 20; public ExtendedPlayer(EntityPlayer player) { this.player = player; this.player.getDataWatcher().addObject(FAVOR_WATCHER, FavorMeter.favor); } public static final void register(EntityPlayer player) { player.registerExtendedProperties(ExtendedPlayer.EXT_PROP_NAME, new ExtendedPlayer(player)); } public static final ExtendedPlayer get(EntityPlayer player) { return (ExtendedPlayer) player.getExtendedProperties(EXT_PROP_NAME); } @Override public final void saveNBTData(NBTTagCompound compound) { NBTTagCompound properties = new NBTTagCompound(); properties.setInteger("FavorValue", player.getDataWatcher().getWatchableObjectInt(FAVOR_WATCHER)); compound.setTag(EXT_PROP_NAME, properties); } @Override public final void loadNBTData(NBTTagCompound compound) { NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME); player.getDataWatcher().updateObject(FAVOR_WATCHER, properties.getInteger("FavorValue")); } @Override public void init(Entity entity, World world) {} public final int getFavor() { return player.getDataWatcher().getWatchableObjectInt(FAVOR_WATCHER); } private static final String getSaveKey(EntityPlayer player) { return player.getCommandSenderName() + ":" + EXT_PROP_NAME; } } package duke_Frans.Isis; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.event.entity.EntityEvent.EntityConstructing; class FavorEventHandler { @SubscribeEvent public void onEntityConstructing(EntityConstructing event) { if (event.entity instanceof EntityPlayer && ExtendedPlayer.get((EntityPlayer) event.entity) == null) ExtendedPlayer.register((EntityPlayer) event.entity); if (event.entity instanceof EntityPlayer && event.entity.getExtendedProperties(ExtendedPlayer.EXT_PROP_NAME) == null) event.entity.registerExtendedProperties(ExtendedPlayer.EXT_PROP_NAME, new ExtendedPlayer((EntityPlayer) event.entity)); } } Again as I said, this is basically copy pasted from a tutorial after my own ways of doing it failed, so I could be missing something obvious Any way to alter this to be saved per world? Or any way I can save data per world? Thanks

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.