Reformatted all the code using the default intelji formatting options.

This commit is contained in:
modmuss50 2015-08-09 11:05:32 +01:00
parent 2f63a24070
commit e0ab0af822
363 changed files with 20524 additions and 23016 deletions

View file

@ -17,182 +17,182 @@ import java.util.TreeMap;
public class IDSUManager {
public static IDSUManager INSTANCE;
public static IDSUManager INSTANCE;
public static final String savename = "idsu.json";
public static final String savename = "idsu.json";
public HashMap<World, IDSUWorldSaveData> worldData = new HashMap<World, IDSUWorldSaveData>();
public HashMap<World, IDSUWorldSaveData> worldData = new HashMap<World, IDSUWorldSaveData>();
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void worldSave(WorldEvent.Save event) {
if (event.world != null && event.world.getSaveHandler() != null && event.world.getSaveHandler().getWorldDirectory() != null) {
if (worldData.containsKey(event.world)) {
worldData.get(event.world).save();
}
}
}
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void worldSave(WorldEvent.Save event) {
if (event.world != null && event.world.getSaveHandler() != null && event.world.getSaveHandler().getWorldDirectory() != null) {
if (worldData.containsKey(event.world)) {
worldData.get(event.world).save();
}
}
}
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void worldLoad(WorldEvent.Load event) {
if (event.world != null && event.world.getSaveHandler() != null && event.world.getSaveHandler().getWorldDirectory() != null) {
if (worldData.containsKey(event.world)) {
worldData.get(event.world).load();
} else {
IDSUWorldSaveData worldSaveData = new IDSUWorldSaveData(event.world);
worldData.put(event.world, worldSaveData);
worldSaveData.load();
}
}
}
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void worldLoad(WorldEvent.Load event) {
if (event.world != null && event.world.getSaveHandler() != null && event.world.getSaveHandler().getWorldDirectory() != null) {
if (worldData.containsKey(event.world)) {
worldData.get(event.world).load();
} else {
IDSUWorldSaveData worldSaveData = new IDSUWorldSaveData(event.world);
worldData.put(event.world, worldSaveData);
worldSaveData.load();
}
}
}
@SubscribeEvent(priority = EventPriority.LOWEST)
public void worldClosed(WorldEvent.Unload event) {
if (event.world != null && event.world.getSaveHandler() != null && event.world.getSaveHandler().getWorldDirectory() != null) {
if (worldData.containsKey(event.world)) {
worldData.get(event.world).save();
}
}
//this clears the data ready for a new world
worldData.clear();
}
@SubscribeEvent(priority = EventPriority.LOWEST)
public void worldClosed(WorldEvent.Unload event) {
if (event.world != null && event.world.getSaveHandler() != null && event.world.getSaveHandler().getWorldDirectory() != null) {
if (worldData.containsKey(event.world)) {
worldData.get(event.world).save();
}
}
//this clears the data ready for a new world
worldData.clear();
}
public IDSUValueSaveData getSaveDataForWorld(World world, String channel) {
if (worldData.containsKey(world)) {
return worldData.get(world).getSaves(channel);
} else {
IDSUWorldSaveData worldSaveData = new IDSUWorldSaveData(world);
worldData.put(world, worldSaveData);
worldSaveData.load();
return worldSaveData.getSaves(channel);
}
}
public IDSUValueSaveData getSaveDataForWorld(World world, String channel) {
if (worldData.containsKey(world)) {
return worldData.get(world).getSaves(channel);
} else {
IDSUWorldSaveData worldSaveData = new IDSUWorldSaveData(world);
worldData.put(world, worldSaveData);
worldSaveData.load();
return worldSaveData.getSaves(channel);
}
}
public IDSUWorldSaveData getWorldDataFormWorld(World world) {
if (worldData.containsKey(world)) {
return worldData.get(world);
} else {
IDSUWorldSaveData worldSaveData = new IDSUWorldSaveData(world);
worldData.put(world, worldSaveData);
worldSaveData.load();
return worldSaveData;
}
}
public IDSUWorldSaveData getWorldDataFormWorld(World world) {
if (worldData.containsKey(world)) {
return worldData.get(world);
} else {
IDSUWorldSaveData worldSaveData = new IDSUWorldSaveData(world);
worldData.put(world, worldSaveData);
worldSaveData.load();
return worldSaveData;
}
}
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);
}
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);
}
public class IDSUWorldSaveData {
public class IDSUWorldSaveData {
public TreeMap<String, IDSUValueSaveData> idsuValues = new TreeMap<String, IDSUValueSaveData>();
public TreeMap<String, IDSUValueSaveData> idsuValues = new TreeMap<String, IDSUValueSaveData>();
public World world;
public World world;
ISaveHandler saveHandler;
ISaveHandler saveHandler;
File folder;
File folder;
File file;
File file;
public IDSUWorldSaveData(World world) {
this.world = world;
this.saveHandler = world.getSaveHandler();
folder = new File(saveHandler.getWorldDirectory(), "idsuData");
file = new File(folder, savename);
}
public IDSUWorldSaveData(World world) {
this.world = world;
this.saveHandler = world.getSaveHandler();
folder = new File(saveHandler.getWorldDirectory(), "idsuData");
file = new File(folder, savename);
}
public IDSUValueSaveData getSaves(String udid) {
if (idsuValues.containsKey(udid)) {
return idsuValues.get(udid);
} else {
IDSUValueSaveData data = new IDSUValueSaveData();
idsuValues.put(udid, data);
return data;
}
}
public IDSUValueSaveData getSaves(String udid) {
if (idsuValues.containsKey(udid)) {
return idsuValues.get(udid);
} else {
IDSUValueSaveData data = new IDSUValueSaveData();
idsuValues.put(udid, data);
return data;
}
}
public void load() {
if (!file.exists()) {
return;
}
try {
Gson gson = new Gson();
BufferedReader reader = new BufferedReader(new FileReader(file));
Type typeOfHashMap = new TypeToken<TreeMap<String, IDSUValueSaveData>>() {
}.getType();
idsuValues.clear();
idsuValues = gson.fromJson(reader, typeOfHashMap);
} catch (Exception e) {
e.printStackTrace();
}
}
public void load() {
if (!file.exists()) {
return;
}
try {
Gson gson = new Gson();
BufferedReader reader = new BufferedReader(new FileReader(file));
Type typeOfHashMap = new TypeToken<TreeMap<String, IDSUValueSaveData>>() {
}.getType();
idsuValues.clear();
idsuValues = gson.fromJson(reader, typeOfHashMap);
} catch (Exception e) {
e.printStackTrace();
}
}
public void save() {
if (idsuValues.isEmpty()) {
return;
}
if (!file.exists()) {
if (!folder.exists()) {
folder.mkdirs();
}
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
public void save() {
if (idsuValues.isEmpty()) {
return;
}
if (!file.exists()) {
if (!folder.exists()) {
folder.mkdirs();
}
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(idsuValues);
try {
FileWriter writer = new FileWriter(file);
writer.write(json);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(idsuValues);
try {
FileWriter writer = new FileWriter(file);
writer.write(json);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public class IDSUValueSaveData {
public class IDSUValueSaveData {
public double storedPower = 0;
public double storedPower = 0;
public IDSUValueSaveData(double storedPower) {
this.storedPower = storedPower;
}
public IDSUValueSaveData(double storedPower) {
this.storedPower = storedPower;
}
public IDSUValueSaveData() {
}
public IDSUValueSaveData() {
}
public double getStoredPower() {
return storedPower;
}
public double getStoredPower() {
return storedPower;
}
public void setStoredPower(double storedPower) {
this.storedPower = storedPower;
}
public void setStoredPower(double storedPower) {
this.storedPower = storedPower;
}
public void addEnergy(double storedPower) {
this.storedPower += storedPower;
}
}
public void addEnergy(double storedPower) {
this.storedPower += storedPower;
}
}
}

View file

@ -1,12 +1,9 @@
package techreborn.tiles.idsu;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import techreborn.Core;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;
import techreborn.lib.Functions;
@ -14,17 +11,17 @@ import techreborn.powerSystem.TilePowerAcceptor;
public class TileIDSU extends TilePowerAcceptor {
public String ownerUdid;
public String ownerUdid;
@Override
public double getEnergy() {
return IDSUManager.INSTANCE.getSaveDataForWorld(worldObj, ownerUdid).storedPower;
}
public double getEnergy() {
return IDSUManager.INSTANCE.getSaveDataForWorld(worldObj, ownerUdid).storedPower;
}
@Override
public void setEnergy(double energy) {
IDSUManager.INSTANCE.getSaveDataForWorld(worldObj, ownerUdid).storedPower = energy;
}
public void setEnergy(double energy) {
IDSUManager.INSTANCE.getSaveDataForWorld(worldObj, ownerUdid).storedPower = energy;
}
@Override
public void readFromNBTWithoutCoords(NBTTagCompound tag) {
@ -62,107 +59,107 @@ public class TileIDSU extends TilePowerAcceptor {
}
public int tier;
public int output;
public double maxStorage;
private double euLastTick = 0;
private double euChange;
private int ticks;
public int output;
public double maxStorage;
private double euLastTick = 0;
private double euChange;
private int ticks;
public TileIDSU(int tier1, int output1, int maxStorage1) {
public TileIDSU(int tier1, int output1, int maxStorage1) {
super(tier1);
this.tier = tier1;
this.output = output1;
this.maxStorage = maxStorage1;
}
this.tier = tier1;
this.output = output1;
this.maxStorage = maxStorage1;
}
public TileIDSU(){
public TileIDSU() {
this(5, 2048, 100000000);
}
public float getChargeLevel() {
float ret = (float) this.getEnergy() / (float) this.maxStorage;
if (ret > 1.0F) {
ret = 1.0F;
}
public float getChargeLevel() {
float ret = (float) this.getEnergy() / (float) this.maxStorage;
if (ret > 1.0F) {
ret = 1.0F;
}
return ret;
}
return ret;
}
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
this.ownerUdid = nbttagcompound.getString("ownerUdid");
}
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
this.ownerUdid = nbttagcompound.getString("ownerUdid");
}
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
nbttagcompound.setString("ownerUdid", this.ownerUdid);
}
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
nbttagcompound.setString("ownerUdid", this.ownerUdid);
}
public void updateEntity() {
super.updateEntity();
public void updateEntity() {
super.updateEntity();
if (ticks == ConfigTechReborn.aveargeEuOutTickTime) {
euChange = -1;
ticks = 0;
if (ticks == ConfigTechReborn.aveargeEuOutTickTime) {
euChange = -1;
ticks = 0;
} else {
ticks++;
euChange += getEnergy() - euLastTick;
if (euLastTick == getEnergy()) {
euChange = 0;
}
}
} else {
ticks++;
euChange += getEnergy() - euLastTick;
if (euLastTick == getEnergy()) {
euChange = 0;
}
}
euLastTick = getEnergy();
euLastTick = getEnergy();
boolean needsInvUpdate = false;
boolean needsInvUpdate = false;
if (needsInvUpdate) {
this.markDirty();
}
if (needsInvUpdate) {
this.markDirty();
}
}
}
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
return false;
}
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
return false;
}
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
NBTTagCompound tileEntity = new NBTTagCompound();
ItemStack dropStack = new ItemStack(ModBlocks.Idsu, 1);
writeToNBT(tileEntity);
dropStack.setTagCompound(new NBTTagCompound());
dropStack.stackTagCompound.setTag("tileEntity", tileEntity);
return dropStack;
}
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
NBTTagCompound tileEntity = new NBTTagCompound();
ItemStack dropStack = new ItemStack(ModBlocks.Idsu, 1);
writeToNBT(tileEntity);
dropStack.setTagCompound(new NBTTagCompound());
dropStack.stackTagCompound.setTag("tileEntity", tileEntity);
return dropStack;
}
public double getEuChange() {
if (euChange == -1) {
return -1;
}
return (euChange / ticks);
}
public double getEuChange() {
if (euChange == -1) {
return -1;
}
return (euChange / ticks);
}
public void handleGuiInputFromClient(int id){
if(id == 0){
public void handleGuiInputFromClient(int id) {
if (id == 0) {
output += 256;
}
if(id == 1){
if (id == 1) {
output += 64;
}
if(id == 2){
if (id == 2) {
output -= 64;
}
if(id == 3){
if (id == 3) {
output -= 256;
}
if(output > 4096){
if (output > 4096) {
output = 4096;
}
if(output <= -1){
if (output <= -1) {
output = 0;
}
}