Object writing and whatnot

This commit is contained in:
Daniel Mills 2020-08-07 14:36:07 -04:00
parent c158e74fb5
commit 4132c0552f
3 changed files with 121 additions and 36 deletions

View File

@ -15,12 +15,14 @@ import org.zeroturnaround.zip.ZipUtil;
import com.google.gson.Gson;
import com.volmit.iris.gen.IrisChunkGenerator;
import com.volmit.iris.object.IrisBiome;
import com.volmit.iris.object.IrisBiomeMutation;
import com.volmit.iris.object.IrisDimension;
import com.volmit.iris.object.IrisGenerator;
import com.volmit.iris.object.IrisObjectPlacement;
import com.volmit.iris.object.IrisRegion;
import com.volmit.iris.object.IrisStructure;
import com.volmit.iris.object.IrisStructureTile;
import com.volmit.iris.util.ChronoLatch;
import com.volmit.iris.util.Form;
import com.volmit.iris.util.IO;
import com.volmit.iris.util.J;
@ -184,6 +186,7 @@ public class ProjectManager
String a = "";
StringBuilder b = new StringBuilder();
StringBuilder c = new StringBuilder();
sender.sendMessage("Serializing Objects");
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();
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) ->
{
try
@ -245,6 +275,14 @@ public class ProjectManager
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)
@ -260,6 +298,37 @@ public class ProjectManager
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)
{
}
})));
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)
@ -272,6 +341,8 @@ public class ProjectManager
c.append(IO.hash(b.toString()));
b = new StringBuilder();
Iris.info("Writing Dimensional Scaffold");
try
{
a = new JSONObject(new Gson().toJson(dimension)).toString(0);
@ -318,10 +389,11 @@ public class ProjectManager
meta.put("version", dimension.getVersion());
IO.writeAll(new File(folder, "package.json"), meta.toString(0));
File p = new File(Iris.instance.getDataFolder(), "exports/" + dimension.getLoadKey() + ".iris");
Iris.info("Compressing Package");
ZipUtil.pack(folder, p, 9);
IO.delete(folder);
sender.sendMessage("Done!");
sender.sendMessage("Package Compiled!");
return p;
}

View File

@ -1,7 +1,6 @@
package com.volmit.iris.command;
import java.io.File;
import java.io.IOException;
import java.util.Set;
import org.bukkit.Location;
@ -36,7 +35,7 @@ public class CommandIrisObjectPaste extends MortarCommand
}
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;
for(String i : args)
@ -47,38 +46,33 @@ 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();
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("Loaded " + "objects/" + args[0] + ".iob");
sender.sendMessage("Error, cant find");
return true;
}
sender.sendMessage("Loaded " + "objects/" + args[0] + ".iob");
sender.player().getWorld().playSound(sender.player().getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.5f);
Location block = sender.player().getTargetBlock((Set<Material>) null, 256).getLocation().clone().add(0, 1, 0);
sender.player().getWorld().playSound(sender.player().getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.5f);
Location block = sender.player().getTargetBlock((Set<Material>) null, 256).getLocation().clone().add(0, 1, 0);
if(intoWand && WandController.isWand(wand))
{
wand = WandController.createWand(block.clone().subtract(o.getCenter()).add(o.getW() - 1, o.getH(), o.getD() - 1), block.clone().subtract(o.getCenter()));
p.getInventory().setItemInMainHand(wand);
sender.sendMessage("Updated wand for " + "objects/" + args[0] + ".iob");
}
WandController.pasteSchematic(o, block);
sender.sendMessage("Placed " + "objects/" + args[0] + ".iob");
if(intoWand && WandController.isWand(wand))
{
wand = WandController.createWand(block.clone().subtract(o.getCenter()).add(o.getW() - 1, o.getH(), o.getD() - 1), block.clone().subtract(o.getCenter()));
p.getInventory().setItemInMainHand(wand);
sender.sendMessage("Updated wand for " + "objects/" + args[0] + ".iob");
}
catch(IOException e)
{
sender.sendMessage("Failed to load " + "objects/" + args[0] + ".iob");
e.printStackTrace();
}
WandController.pasteSchematic(o, block);
sender.sendMessage("Placed " + "objects/" + args[0] + ".iob");
return true;
}

View File

@ -1,7 +1,6 @@
package com.volmit.iris.command;
import java.io.File;
import java.io.IOException;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
@ -32,20 +31,40 @@ public class CommandIrisObjectSave extends MortarCommand
return true;
}
Player p = sender.player();
ItemStack wand = p.getInventory().getItemInMainHand();
IrisObject o = WandController.createSchematic(wand);
try
{
o.write(new File(Iris.instance.getDataFolder(), "objects/" + args[0] + ".iob"));
sender.sendMessage("Saved " + "objects/" + args[0] + ".iob");
boolean overwrite = false;
for(String i : args)
{
if(i.equals("-o"))
{
overwrite = true;
}
}
Player p = sender.player();
ItemStack wand = p.getInventory().getItemInMainHand();
IrisObject o = WandController.createSchematic(wand);
File file = Iris.instance.getDataFile("packs", args[0], "objects", args[1] + ".iob");
if(file.exists())
{
if(!overwrite)
{
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);
}
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();
}
@ -56,6 +75,6 @@ public class CommandIrisObjectSave extends MortarCommand
@Override
protected String getArgsUsage()
{
return "[name]";
return "[project] [name]";
}
}