A load of work on the system, seams a lot is broken.
This commit is contained in:
parent
d8e6e88797
commit
598badc375
17 changed files with 268 additions and 53 deletions
src/main/java/techreborn/tiles
|
@ -0,0 +1,19 @@
|
|||
package techreborn.tiles.idsu;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.EventPriority;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ClientSideIDSUManager {
|
||||
|
||||
public static IDSUManager CLIENT = new IDSUManager();
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
public void worldLoad(WorldEvent.Load event){
|
||||
CLIENT = new IDSUManager();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,14 +1,17 @@
|
|||
package techreborn.tiles.iesu;
|
||||
package techreborn.tiles.idsu;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import cpw.mods.fml.common.eventhandler.EventPriority;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.storage.ISaveHandler;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import techreborn.util.LogHelper;
|
||||
import techreborn.packets.PacketSendIDSUManager;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
|
@ -16,9 +19,7 @@ import java.io.FileReader;
|
|||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
|
||||
|
@ -29,6 +30,7 @@ public class IDSUManager {
|
|||
|
||||
public HashMap<World, IDSUWorldSaveData> worldData = new HashMap<World, IDSUWorldSaveData>();
|
||||
|
||||
//@SideOnly(Side.SERVER)
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
public void worldSave(WorldEvent.Save event){
|
||||
if(event.world != null && event.world.getSaveHandler() != null && event.world.getSaveHandler().getWorldDirectory() != null){
|
||||
|
@ -38,6 +40,7 @@ public class IDSUManager {
|
|||
}
|
||||
}
|
||||
|
||||
//@SideOnly(Side.SERVER)
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||
public void worldLoad(WorldEvent.Load event){
|
||||
if(event.world != null && event.world.getSaveHandler() != null && event.world.getSaveHandler().getWorldDirectory() != null){
|
||||
|
@ -51,6 +54,7 @@ public class IDSUManager {
|
|||
}
|
||||
}
|
||||
|
||||
//@SideOnly(Side.SERVER)
|
||||
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||
public void worldClosed(WorldEvent.Unload event){
|
||||
if(event.world != null && event.world.getSaveHandler() != null && event.world.getSaveHandler().getWorldDirectory() != null){
|
||||
|
@ -76,6 +80,48 @@ public class IDSUManager {
|
|||
}
|
||||
|
||||
|
||||
public IDSUWorldSaveData getWorldDataFormWorld(World world){
|
||||
//System.out.println(world);
|
||||
if(worldData.containsKey(world)){
|
||||
return worldData.get(world);
|
||||
} else {
|
||||
IDSUWorldSaveData worldSaveData = new IDSUWorldSaveData(world);
|
||||
worldData.put(world ,worldSaveData);
|
||||
worldSaveData.load();
|
||||
return worldSaveData;
|
||||
}
|
||||
}
|
||||
|
||||
//@SideOnly(Side.SERVER)
|
||||
public PacketSendIDSUManager getPacket(World world, EntityPlayer player){
|
||||
Gson gson = new Gson();
|
||||
String json = gson.toJson(getWorldDataFormWorld(world).idsuValues);
|
||||
if(getWorldDataFormWorld(world).idsuValues.isEmpty()){
|
||||
json = "EMPTY";
|
||||
}
|
||||
return new PacketSendIDSUManager(json, player);
|
||||
}
|
||||
|
||||
//@SideOnly(Side.CLIENT)
|
||||
public void loadFromString(String json, World world){
|
||||
if(json.equals("EMPTY")){
|
||||
return;
|
||||
}
|
||||
IDSUWorldSaveData worldSaveData;
|
||||
if(worldData.containsKey(world)){
|
||||
worldSaveData = worldData.get(world);
|
||||
} else {
|
||||
worldSaveData = new IDSUWorldSaveData(world);
|
||||
worldData.put(world ,worldSaveData);
|
||||
}
|
||||
Gson gson = new Gson();
|
||||
Type typeOfHashMap = new TypeToken<TreeMap<Integer, IDSUValueSaveData>>() { }.getType();
|
||||
worldSaveData.idsuValues.clear();
|
||||
worldSaveData.idsuValues = gson.fromJson(json, typeOfHashMap);
|
||||
//System.out.println(world);
|
||||
}
|
||||
|
||||
|
||||
public class IDSUWorldSaveData {
|
||||
|
||||
public TreeMap<Integer, IDSUValueSaveData> idsuValues = new TreeMap<Integer, IDSUValueSaveData>();
|
||||
|
@ -105,6 +151,7 @@ public class IDSUManager {
|
|||
}
|
||||
}
|
||||
|
||||
//@SideOnly(Side.SERVER)
|
||||
public void load(){
|
||||
if(!file.exists()){
|
||||
return;
|
||||
|
@ -120,6 +167,7 @@ public class IDSUManager {
|
|||
}
|
||||
}
|
||||
|
||||
//@SideOnly(Side.SERVER)
|
||||
public void save(){
|
||||
if(idsuValues.isEmpty()){
|
||||
return;
|
23
src/main/java/techreborn/tiles/idsu/TileIDSU.java
Normal file
23
src/main/java/techreborn/tiles/idsu/TileIDSU.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
package techreborn.tiles.idsu;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import techreborn.packets.PacketHandler;
|
||||
import techreborn.tiles.TileMachineBase;
|
||||
|
||||
public class TileIDSU extends TileMachineBase {
|
||||
|
||||
public int channelID = 0;
|
||||
|
||||
public void handleGuiInputFromClient(int buttonID, int channel, EntityPlayer player, String name) {
|
||||
if(buttonID == 4){
|
||||
channelID = channel;
|
||||
IDSUManager.INSTANCE.getSaveDataForWorld(worldObj, channel);//Do this to init the save data :)
|
||||
if(name != "BLANK!!!"){
|
||||
IDSUManager.INSTANCE.getSaveDataForWorld(worldObj, channel).name = name;
|
||||
}
|
||||
if(worldObj.isRemote){
|
||||
PacketHandler.sendPacketToPlayer(IDSUManager.INSTANCE.getPacket(worldObj, player), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package techreborn.tiles.iesu;
|
||||
|
||||
import techreborn.tiles.TileMachineBase;
|
||||
|
||||
public class TileIDSU extends TileMachineBase {
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue