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
private CommandIrisJigsawSave save;
@Command
private CommandIrisJigsawPlace place;
public CommandIrisJigsaw()
{
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.IrisSettings;
import com.volmit.iris.manager.IrisDataManager;
import com.volmit.iris.manager.edit.JigsawEditor;
import com.volmit.iris.object.IrisJigsawPiece;
import com.volmit.iris.util.KList;
import com.volmit.iris.util.MortarCommand;
import com.volmit.iris.util.MortarSender;
import com.volmit.iris.object.IrisJigsawStructure;
import com.volmit.iris.object.IrisPosition;
import com.volmit.iris.scaffold.jigsaw.PlannedStructure;
import com.volmit.iris.util.*;
import java.io.File;
public class CommandIrisJigsawEdit extends MortarCommand
public class CommandIrisJigsawPlace extends MortarCommand
{
public CommandIrisJigsawEdit()
public CommandIrisJigsawPlace()
{
super("edit", "e", "*");
super("place", "paste");
requiresPermission(Iris.perm);
setCategory("Jigsaw");
setDescription("Create a new jigsaw piece");
setDescription("Place a jigsaw structure");
}
@Override
@ -41,13 +38,14 @@ public class CommandIrisJigsawEdit extends MortarCommand
return true;
}
IrisJigsawStructure str = IrisDataManager.loadAnyJigsawStructure(args[0]);
IrisJigsawPiece piece = IrisDataManager.loadAnyJigsawPiece(args[0]);
if(piece != null)
if(str != null)
{
File dest = piece.getLoadFile();
new JigsawEditor(sender.player(), piece, IrisDataManager.loadAnyObject(piece.getObject()), dest);
PrecisionStopwatch p = PrecisionStopwatch.start();
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;

View File

@ -73,7 +73,7 @@ public class JigsawEditor implements Listener {
{
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))
{
@ -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)
{
Vector v = l.clone().subtract(origin.clone()).subtract(object.getCenter()).toVector();
return new IrisPosition(v.getBlockX()+1, v.getBlockY()+1, v.getBlockZ()+1);
return new IrisPosition(l.clone().getBlock().getLocation()
.subtract(origin.clone())
.subtract(object.getCenter())
.add(1,1,1)
.toVector());
}
@EventHandler
public void on(PlayerInteractEvent e)
{
e.getPlayer().sendMessage("Center is " + object.getCenter().toString());
if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK))
{
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())
{
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();