Jump to content

1.7.10 Save Data per World


Gaprosys

Recommended Posts

Hi,

thanks for the reply.

My current code looks like so:

 

IndustriousMageWorldSaveData:

[embed=425,349]

package de.gaprosys.industriousmage.handler_network;

 

import java.util.ArrayList;

import java.util.HashMap;

import java.util.Iterator;

import java.io.IOException;

import java.util.Map;

import java.util.Set;

 

import de.gaprosys.industriousmage.IndustriousMage;

import net.minecraft.item.ItemStack;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.nbt.NBTTagList;

import net.minecraft.world.World;

import net.minecraft.world.WorldSavedData;

import net.minecraft.world.storage.MapStorage;

 

public class IndustriousMageWorldSaveData extends WorldSavedData {

 

final static String key = "IndustriousMageSaveData";

 

public IndustriousMageWorldSaveData(String key) {

super(key);

}

 

public IndustriousMageWorldSaveData() {

super(key);

}

 

public static IndustriousMageWorldSaveData get(World world) {

MapStorage storage = world.mapStorage;

IndustriousMageWorldSaveData result;

try {

result = (IndustriousMageWorldSaveData)storage.loadData(IndustriousMageWorldSaveData.class, key);

} catch(NullPointerException ex) {

result = new IndustriousMageWorldSaveData();

storage.setData(key, result);

}

return result;

}

 

public static void saveData(World world) {

try {

world.mapStorage.loadData(IndustriousMageWorldSaveData.class, key).setDirty(true);

} catch(Exception ex) {}

}

 

@Override

public void readFromNBT(NBTTagCompound nbt) {

 

long maxIMP;

long currentIMP;

int id;

String s;

NBTTagList tagList = nbt.getTagList("Player", 10);

 

for(int i = 0; i < tagList.tagCount(); i++) {

NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i);

s = tag.getString("playerName");

id = tag.getInteger("playerID");

currentIMP = tag.getLong("playerCurrentIMP");

maxIMP = tag.getLong("playerMaxIMP");

IndustriousMage.impTransfer.addPlayerToNetworks(s);

IndustriousMage.impTransfer.setPlayerIMPNetworkId(s, id);

IndustriousMage.impTransfer.addMaxIMPtoPlayer(s, maxIMP);

IndustriousMage.impTransfer.addCurrentIMPtoPlayer(s, currentIMP);

 

System.out.println();

System.out.println(s);

System.out.println(id);

System.out.println(currentIMP);

System.out.println(maxIMP);

 

}

}

 

@Override

public void writeToNBT(NBTTagCompound nbt) {

 

NBTTagList tagList = new NBTTagList();

ArrayList<String> network = new ArrayList<String>();

network = IndustriousMage.impTransfer.getPlayerIds();

String s;

 

for(int i = 0; i <= network.size(); i++) {

s = (String)network.get(i);

NBTTagCompound tag = new NBTTagCompound();

 

tag.setString("playerName", s);

tag.setInteger("playerID", i);

tag.setLong("playerCurrentIMP", IndustriousMage.impTransfer.getPlayerCurrentIMPNetwork(s));

tag.setLong("playerMaxIMP", IndustriousMage.impTransfer.getPlayerMaxIMPNetwork(s));

 

System.out.println();

System.out.println(s);

System.out.println(i);

System.out.println(IndustriousMage.impTransfer.getPlayerCurrentIMPNetwork(s));

System.out.println(IndustriousMage.impTransfer.getPlayerMaxIMPNetwork(s));

 

tagList.appendTag(tag);

}

nbt.setTag("Player", tagList);

 

}

 

}

[/embed]

 

the System.out.println is for me, To look, what they read. I use just a try to initialize the WorldSavedData Class from me, because, they throw often an NullPointerException by loading a world.

 

The used Events to load and save the datas:

[embed=425,349]

@SubscribeEvent

public void LoadPlayerList(WorldEvent.Load event) {

if(!event.world.isRemote) {

 

IndustriousMageWorldSaveData worldsave;

 

worldsave = IndustriousMageWorldSaveData.get(event.world);

}

}

 

@SubscribeEvent

public void UnloadPlayerList(WorldEvent.Unload event) {

if(!event.world.isRemote) {

IndustriousMageWorldSaveData.saveData(event.world);

}

}

 

@SubscribeEvent

public void SavePlayerList(WorldEvent.Save event) {

if(!event.world.isRemote) {

IndustriousMageWorldSaveData.saveData(event.world);

}

}

 

[/embed]

 

with the LoadPlayer- function I try to load the player list. what they actually not do. With the UnloadPlayerList and SavePlayerList I saved the lists.

 

- Gaprosys

Link to comment
Share on other sites

I habe tried it, and it doesn't worked. I need this to save the content of an internal net. By the player can I does this not saved, because this should work on servers to. If i try to use your solve, they doesn't add new player or save the content for a world unload and world load. My current way work to save the data for a world re log in in the same session, but if I start the Minecraft client new, they set all values to 0.

Link to comment
Share on other sites

I want to make a magic mod for automation. But i does now think, i should now use packets to handle my networks. The idee behind my mod is the use of an kind of network like blood magic. Now i should overwrite my handle class for the networks and sahe then the datas of the network by the player.

But anyway, thanks for your help and sorry for my bad englisch.

 

- Gaprosys

Link to comment
Share on other sites

I have tried to save datas per world. This datas are in an array and in maps. Now I didn't now, how to use the the WorldSavedData class. If I want to access the data, must I then not call the get- method? And if I want to access the data by the world load, must I then not use the WorldEvent? My data where I wanted to save was in an other class.

 

I have said, I save the datas per player to have the data stored somewhere times. I try it then again with the World Saved Data.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I am not using hardcoded recipes, I'm using Vanilla's already existing code for leather armor dying. (via extending and implementing DyeableArmorItem / DyeableLeatherItem respectively) I have actually figured out that it's something to do with registering item colors to the ItemColors instance, but I'm trying to figure out where exactly in my mod's code I would be placing a call to the required event handler. Unfortunately the tutorial is criminally undescriptive. The most I've found is that it has to be done during client initialization. I'm currently trying to do the necessary setup via hijacking the item registry since trying to modify the item classes directly (via using SubscribeEvent in the item's constructor didn't work. Class so far: // mrrp mrow - mcmod item painter v1.0 - catzrule ch package catzadvitems.init; import net.minecraft.client.color.item.ItemColors; import net.minecraft.world.item.Item; import net.minecraftforge.registries.ObjectHolder; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.client.event.ColorHandlerEvent; import catzadvitems.item.DyeableWoolArmorItem; @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) public class Painter { @ObjectHolder("cai:dyeable_wool_chestplate") public static final Item W_CHEST = null; @ObjectHolder("cai:dyeable_wool_leggings") public static final Item W_LEGS = null; @ObjectHolder("cai:dyeable_wool_boots") public static final Item W_SOCKS = null; public Painter() { // left blank, idk if forge throws a fit if constructors are missing, not taking the chance of it happening. } @SubscribeEvent public static void init(FMLClientSetupEvent event) { new Painter(); } @Mod.EventBusSubscriber private static class ForgeBusEvents { @SubscribeEvent public static void registerItemColors(ColorHandlerEvent.Item event) { ItemColors col = event.getItemColors(); col.register(DyeableUnderArmorItem::getItemDyedColor, W_CHEST, W_LEGS, W_SOCKS); //placeholder for other dye-able items here later.. } } } (for those wondering, i couldn't think of a creative wool helmet name)
    • nvm found out it was because i had create h and not f
    • Maybe there's something happening in the 'leather armor + dye' recipe itself that would be updating the held item texture?
    • @SubscribeEvent public static void onRenderPlayer(RenderPlayerEvent.Pre e) { e.setCanceled(true); model.renderToBuffer(e.getPoseStack(), pBuffer, e.getPackedLight(), 0f, 0f, 0f, 0f, 0f); //ToaPlayerRenderer.render(); } Since getting the render method from a separate class is proving to be bit of a brick wall for me (but seems to be the solution in older versions of minecraft/forge) I've decided to try and pursue using the renderToBuffer method directly from the model itself. I've tried this route before but can't figure out what variables to feed it for the vertexConsumer and still can't seem to figure it out; if this is even a path to pursue.  The vanilla model files do not include any form of render methods, and seem to be fully constructed from their layer definitions? Their renderer files seem to take their layers which are used by the render method in the vanilla MobRenderer class. But for modded entities we @Override this function and don't have to feed the method variables because of that? I assume that the render method in the extended renderer takes the layer definitions from the renderer classes which take those from the model files. Or maybe instead of trying to use a render method I should be calling the super from the renderer like   new ToaPlayerRenderer(context, false); Except I'm not sure what I would provide for context? There's a context method in the vanilla EntityRendererProvider class which doesn't look especially helpful. I've been trying something like <e.getEntity(), model<e.getEntity()>> since that generally seems to be what is provided to the renderers for context, but I don't know if it's THE context I'm looking for? Especially since the method being called doesn't want to take this or variations of this.   In short; I feel like I'm super super close but I have to be missing something obvious? Maybe this insane inane ramble post will provide some insight into this puzzle?
  • Topics

×
×
  • Create New...

Important Information

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