Jigsaw command & editor fixes

This commit is contained in:
Daniel Mills 2021-01-09 02:02:07 -05:00
parent c0df132c93
commit 36b3521b2a
3 changed files with 33 additions and 22 deletions

View File

@ -18,6 +18,9 @@ public class CommandIrisJigsaw extends MortarCommand
@Command @Command
private CommandIrisJigsawSave save; private CommandIrisJigsawSave save;
@Command
private CommandIrisJigsawPlace place;
public CommandIrisJigsaw() public CommandIrisJigsaw()
{ {
super("jigsaw", "jig", "jsw"); super("jigsaw", "jig", "jsw");

View File

@ -3,22 +3,19 @@ package com.volmit.iris.manager.command;
import com.volmit.iris.Iris; import com.volmit.iris.Iris;
import com.volmit.iris.IrisSettings; import com.volmit.iris.IrisSettings;
import com.volmit.iris.manager.IrisDataManager; import com.volmit.iris.manager.IrisDataManager;
import com.volmit.iris.manager.edit.JigsawEditor; import com.volmit.iris.object.IrisJigsawStructure;
import com.volmit.iris.object.IrisJigsawPiece; import com.volmit.iris.object.IrisPosition;
import com.volmit.iris.util.KList; import com.volmit.iris.scaffold.jigsaw.PlannedStructure;
import com.volmit.iris.util.MortarCommand; import com.volmit.iris.util.*;
import com.volmit.iris.util.MortarSender;
import java.io.File; public class CommandIrisJigsawPlace extends MortarCommand
public class CommandIrisJigsawEdit extends MortarCommand
{ {
public CommandIrisJigsawEdit() public CommandIrisJigsawPlace()
{ {
super("edit", "e", "*"); super("place", "paste");
requiresPermission(Iris.perm); requiresPermission(Iris.perm);
setCategory("Jigsaw"); setCategory("Jigsaw");
setDescription("Create a new jigsaw piece"); setDescription("Place a jigsaw structure");
} }
@Override @Override
@ -41,13 +38,14 @@ public class CommandIrisJigsawEdit extends MortarCommand
return true; return true;
} }
IrisJigsawStructure str = IrisDataManager.loadAnyJigsawStructure(args[0]);
IrisJigsawPiece piece = IrisDataManager.loadAnyJigsawPiece(args[0]); if(str != null)
if(piece != null)
{ {
File dest = piece.getLoadFile(); PrecisionStopwatch p = PrecisionStopwatch.start();
new JigsawEditor(sender.player(), piece, IrisDataManager.loadAnyObject(piece.getObject()), dest); PlannedStructure ps = new PlannedStructure(str, new IrisPosition(sender.player().getLocation()), new RNG());
sender.sendMessage("Generated " + ps.getPieces().size() + " pieces in " + Form.duration(p.getMilliseconds(), 2));
ps.place(sender.player().getWorld());
} }
return true; return true;

View File

@ -73,7 +73,7 @@ public class JigsawEditor implements Listener {
{ {
for(IrisPosition i : falling.k()) for(IrisPosition i : falling.k())
{ {
Location at = origin.clone().add(new Vector(i.getX()+1, i.getY()+1, i.getZ()+1)).getBlock().getLocation(); Location at = toLocation(i);
if(at.equals(target)) if(at.equals(target))
{ {
@ -84,17 +84,27 @@ public class JigsawEditor implements Listener {
} }
} }
public Location toLocation(IrisPosition i)
{
return origin.clone()
.add(new Vector(i.getX(), i.getY(), i.getZ()))
.add(object.getCenter())
.getBlock()
.getLocation();
}
public IrisPosition toPosition(Location l) public IrisPosition toPosition(Location l)
{ {
Vector v = l.clone().subtract(origin.clone()).subtract(object.getCenter()).toVector(); return new IrisPosition(l.clone().getBlock().getLocation()
.subtract(origin.clone())
return new IrisPosition(v.getBlockX()+1, v.getBlockY()+1, v.getBlockZ()+1); .subtract(object.getCenter())
.add(1,1,1)
.toVector());
} }
@EventHandler @EventHandler
public void on(PlayerInteractEvent e) public void on(PlayerInteractEvent e)
{ {
e.getPlayer().sendMessage("Center is " + object.getCenter().toString());
if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK))
{ {
if(e.getClickedBlock() != null && cuboid.contains(e.getClickedBlock().getLocation()) && e.getPlayer().equals(player)) if(e.getClickedBlock() != null && cuboid.contains(e.getClickedBlock().getLocation()) && e.getPlayer().equals(player))
@ -170,7 +180,7 @@ public class JigsawEditor implements Listener {
for(IrisJigsawPieceConnector i : piece.getConnectors()) for(IrisJigsawPieceConnector i : piece.getConnectors())
{ {
IrisPosition pos = i.getPosition(); IrisPosition pos = i.getPosition();
Location at = origin.clone().add(object.getCenter()).add(new Vector(pos.getX(), pos.getY(), pos.getZ())); Location at = toLocation(pos);
Vector dir = i.getDirection().toVector().clone(); Vector dir = i.getDirection().toVector().clone();