mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 10:43:14 +00:00
Object writing and whatnot
This commit is contained in:
parent
c158e74fb5
commit
4132c0552f
@ -15,12 +15,14 @@ import org.zeroturnaround.zip.ZipUtil;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.volmit.iris.gen.IrisChunkGenerator;
|
import com.volmit.iris.gen.IrisChunkGenerator;
|
||||||
import com.volmit.iris.object.IrisBiome;
|
import com.volmit.iris.object.IrisBiome;
|
||||||
|
import com.volmit.iris.object.IrisBiomeMutation;
|
||||||
import com.volmit.iris.object.IrisDimension;
|
import com.volmit.iris.object.IrisDimension;
|
||||||
import com.volmit.iris.object.IrisGenerator;
|
import com.volmit.iris.object.IrisGenerator;
|
||||||
import com.volmit.iris.object.IrisObjectPlacement;
|
import com.volmit.iris.object.IrisObjectPlacement;
|
||||||
import com.volmit.iris.object.IrisRegion;
|
import com.volmit.iris.object.IrisRegion;
|
||||||
import com.volmit.iris.object.IrisStructure;
|
import com.volmit.iris.object.IrisStructure;
|
||||||
import com.volmit.iris.object.IrisStructureTile;
|
import com.volmit.iris.object.IrisStructureTile;
|
||||||
|
import com.volmit.iris.util.ChronoLatch;
|
||||||
import com.volmit.iris.util.Form;
|
import com.volmit.iris.util.Form;
|
||||||
import com.volmit.iris.util.IO;
|
import com.volmit.iris.util.IO;
|
||||||
import com.volmit.iris.util.J;
|
import com.volmit.iris.util.J;
|
||||||
@ -184,6 +186,7 @@ public class ProjectManager
|
|||||||
String a = "";
|
String a = "";
|
||||||
StringBuilder b = new StringBuilder();
|
StringBuilder b = new StringBuilder();
|
||||||
StringBuilder c = new StringBuilder();
|
StringBuilder c = new StringBuilder();
|
||||||
|
sender.sendMessage("Serializing Objects");
|
||||||
|
|
||||||
for(IrisStructure i : structures)
|
for(IrisStructure i : structures)
|
||||||
{
|
{
|
||||||
@ -235,9 +238,36 @@ public class ProjectManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(IrisBiomeMutation i : dimension.getMutations())
|
||||||
|
{
|
||||||
|
for(IrisObjectPlacement j : i.getObjects())
|
||||||
|
{
|
||||||
|
b.append(j.hashCode());
|
||||||
|
KList<String> newNames = new KList<>();
|
||||||
|
|
||||||
|
for(String k : j.getPlace())
|
||||||
|
{
|
||||||
|
if(renameObjects.containsKey(k))
|
||||||
|
{
|
||||||
|
newNames.add(renameObjects.get(k));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String name = UUID.randomUUID().toString().replaceAll("-", "");
|
||||||
|
b.append(name);
|
||||||
|
newNames.add(name);
|
||||||
|
renameObjects.put(k, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
j.setPlace(newNames);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
KMap<String, KList<String>> lookupObjects = renameObjects.flip();
|
KMap<String, KList<String>> lookupObjects = renameObjects.flip();
|
||||||
StringBuilder gb = new StringBuilder();
|
StringBuilder gb = new StringBuilder();
|
||||||
|
ChronoLatch cl = new ChronoLatch(1000);
|
||||||
|
O<Integer> ggg = new O<Integer>();
|
||||||
|
ggg.set(0);
|
||||||
biomes.forEach((i) -> i.getObjects().forEach((j) -> j.getPlace().forEach((k) ->
|
biomes.forEach((i) -> i.getObjects().forEach((j) -> j.getPlace().forEach((k) ->
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -245,6 +275,14 @@ public class ProjectManager
|
|||||||
File f = Iris.globaldata.getObjectLoader().findFile(lookupObjects.get(k).get(0));
|
File f = Iris.globaldata.getObjectLoader().findFile(lookupObjects.get(k).get(0));
|
||||||
IO.copyFile(f, new File(folder, "objects/" + k + ".iob"));
|
IO.copyFile(f, new File(folder, "objects/" + k + ".iob"));
|
||||||
gb.append(IO.hash(f));
|
gb.append(IO.hash(f));
|
||||||
|
ggg.set(ggg.get() + 1);
|
||||||
|
|
||||||
|
if(cl.flip())
|
||||||
|
{
|
||||||
|
int g = ggg.get();
|
||||||
|
ggg.set(0);
|
||||||
|
sender.sendMessage("Wrote another " + g + " Objects");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
catch(Throwable e)
|
catch(Throwable e)
|
||||||
@ -260,6 +298,37 @@ public class ProjectManager
|
|||||||
File f = Iris.globaldata.getObjectLoader().findFile(lookupObjects.get(k).get(0));
|
File f = Iris.globaldata.getObjectLoader().findFile(lookupObjects.get(k).get(0));
|
||||||
IO.copyFile(f, new File(folder, "objects/" + k + ".iob"));
|
IO.copyFile(f, new File(folder, "objects/" + k + ".iob"));
|
||||||
gb.append(IO.hash(f));
|
gb.append(IO.hash(f));
|
||||||
|
ggg.set(ggg.get() + 1);
|
||||||
|
|
||||||
|
if(cl.flip())
|
||||||
|
{
|
||||||
|
int g = ggg.get();
|
||||||
|
ggg.set(0);
|
||||||
|
sender.sendMessage("Wrote another " + g + " Objects");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
catch(Throwable e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
})));
|
||||||
|
|
||||||
|
dimension.getMutations().forEach((i) -> i.getObjects().forEach((j) -> j.getPlace().forEach((k) ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File f = Iris.globaldata.getObjectLoader().findFile(lookupObjects.get(k).get(0));
|
||||||
|
IO.copyFile(f, new File(folder, "objects/" + k + ".iob"));
|
||||||
|
gb.append(IO.hash(f));
|
||||||
|
ggg.set(ggg.get() + 1);
|
||||||
|
|
||||||
|
if(cl.flip())
|
||||||
|
{
|
||||||
|
int g = ggg.get();
|
||||||
|
ggg.set(0);
|
||||||
|
sender.sendMessage("Wrote another " + g + " Objects");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
catch(Throwable e)
|
catch(Throwable e)
|
||||||
@ -272,6 +341,8 @@ public class ProjectManager
|
|||||||
c.append(IO.hash(b.toString()));
|
c.append(IO.hash(b.toString()));
|
||||||
b = new StringBuilder();
|
b = new StringBuilder();
|
||||||
|
|
||||||
|
Iris.info("Writing Dimensional Scaffold");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
a = new JSONObject(new Gson().toJson(dimension)).toString(0);
|
a = new JSONObject(new Gson().toJson(dimension)).toString(0);
|
||||||
@ -318,10 +389,11 @@ public class ProjectManager
|
|||||||
meta.put("version", dimension.getVersion());
|
meta.put("version", dimension.getVersion());
|
||||||
IO.writeAll(new File(folder, "package.json"), meta.toString(0));
|
IO.writeAll(new File(folder, "package.json"), meta.toString(0));
|
||||||
File p = new File(Iris.instance.getDataFolder(), "exports/" + dimension.getLoadKey() + ".iris");
|
File p = new File(Iris.instance.getDataFolder(), "exports/" + dimension.getLoadKey() + ".iris");
|
||||||
|
Iris.info("Compressing Package");
|
||||||
ZipUtil.pack(folder, p, 9);
|
ZipUtil.pack(folder, p, 9);
|
||||||
IO.delete(folder);
|
IO.delete(folder);
|
||||||
|
|
||||||
sender.sendMessage("Done!");
|
sender.sendMessage("Package Compiled!");
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.volmit.iris.command;
|
package com.volmit.iris.command;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -36,7 +35,7 @@ public class CommandIrisObjectPaste extends MortarCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
Player p = sender.player();
|
Player p = sender.player();
|
||||||
File file = new File(Iris.instance.getDataFolder(), "objects/" + args[0] + ".iob");
|
File file = Iris.globaldata.getObjectLoader().findFile(args[0]);
|
||||||
boolean intoWand = false;
|
boolean intoWand = false;
|
||||||
|
|
||||||
for(String i : args)
|
for(String i : args)
|
||||||
@ -47,17 +46,19 @@ public class CommandIrisObjectPaste extends MortarCommand
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!file.exists())
|
if(file == null || !file.exists())
|
||||||
{
|
{
|
||||||
sender.sendMessage("Can't find " + "objects/" + args[0] + ".iob");
|
sender.sendMessage("Can't find " + args[0] + " in the packs folder");
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack wand = sender.player().getInventory().getItemInMainHand();
|
ItemStack wand = sender.player().getInventory().getItemInMainHand();
|
||||||
IrisObject o = new IrisObject(0, 0, 0);
|
|
||||||
|
|
||||||
try
|
IrisObject o = Iris.globaldata.getObjectLoader().load(args[0]);
|
||||||
|
if(o == null)
|
||||||
{
|
{
|
||||||
o.read(new File(Iris.instance.getDataFolder(), "objects/" + args[0] + ".iob"));
|
sender.sendMessage("Error, cant find");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
sender.sendMessage("Loaded " + "objects/" + args[0] + ".iob");
|
sender.sendMessage("Loaded " + "objects/" + args[0] + ".iob");
|
||||||
|
|
||||||
sender.player().getWorld().playSound(sender.player().getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.5f);
|
sender.player().getWorld().playSound(sender.player().getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.5f);
|
||||||
@ -72,13 +73,6 @@ public class CommandIrisObjectPaste extends MortarCommand
|
|||||||
|
|
||||||
WandController.pasteSchematic(o, block);
|
WandController.pasteSchematic(o, block);
|
||||||
sender.sendMessage("Placed " + "objects/" + args[0] + ".iob");
|
sender.sendMessage("Placed " + "objects/" + args[0] + ".iob");
|
||||||
}
|
|
||||||
|
|
||||||
catch(IOException e)
|
|
||||||
{
|
|
||||||
sender.sendMessage("Failed to load " + "objects/" + args[0] + ".iob");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.volmit.iris.command;
|
package com.volmit.iris.command;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -32,20 +31,40 @@ public class CommandIrisObjectSave extends MortarCommand
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
boolean overwrite = false;
|
||||||
|
|
||||||
|
for(String i : args)
|
||||||
|
{
|
||||||
|
if(i.equals("-o"))
|
||||||
|
{
|
||||||
|
overwrite = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Player p = sender.player();
|
Player p = sender.player();
|
||||||
ItemStack wand = p.getInventory().getItemInMainHand();
|
ItemStack wand = p.getInventory().getItemInMainHand();
|
||||||
IrisObject o = WandController.createSchematic(wand);
|
IrisObject o = WandController.createSchematic(wand);
|
||||||
|
File file = Iris.instance.getDataFile("packs", args[0], "objects", args[1] + ".iob");
|
||||||
|
|
||||||
try
|
if(file.exists())
|
||||||
{
|
{
|
||||||
o.write(new File(Iris.instance.getDataFolder(), "objects/" + args[0] + ".iob"));
|
if(!overwrite)
|
||||||
sender.sendMessage("Saved " + "objects/" + args[0] + ".iob");
|
{
|
||||||
|
sender.sendMessage("File Exists. Overwrite by adding -o");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
o.write(file);
|
||||||
|
sender.sendMessage("Saved " + args[1]);
|
||||||
p.getWorld().playSound(p.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.5f);
|
p.getWorld().playSound(p.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
catch(IOException e)
|
catch(Throwable e)
|
||||||
{
|
{
|
||||||
sender.sendMessage("Failed to save " + "objects/" + args[0] + ".iob. Are you holding your wand?");
|
sender.sendMessage("Failed to save " + args[1] + ". Are you holding your wand?");
|
||||||
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -56,6 +75,6 @@ public class CommandIrisObjectSave extends MortarCommand
|
|||||||
@Override
|
@Override
|
||||||
protected String getArgsUsage()
|
protected String getArgsUsage()
|
||||||
{
|
{
|
||||||
return "[name]";
|
return "[project] [name]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user