mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-29 12:09:07 +00:00
f
This commit is contained in:
@@ -14,6 +14,9 @@ public class CommandIris extends MortarCommand
|
||||
@Command
|
||||
private CommandIrisStudio studio;
|
||||
|
||||
@Command
|
||||
private CommandIrisJigsaw jigsaw;
|
||||
|
||||
@Command
|
||||
private CommandIrisStructure structure;
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.volmit.iris.manager.command;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.IrisSettings;
|
||||
import com.volmit.iris.util.Command;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
|
||||
public class CommandIrisJigsaw extends MortarCommand
|
||||
{
|
||||
@Command
|
||||
private CommandIrisJigsawNew create;
|
||||
|
||||
@Command
|
||||
private CommandIrisJigsawEdit edit;
|
||||
|
||||
@Command
|
||||
private CommandIrisJigsawSave save;
|
||||
|
||||
public CommandIrisJigsaw()
|
||||
{
|
||||
super("jigsaw", "jig", "jsw");
|
||||
requiresPermission(Iris.perm);
|
||||
setCategory("Jigsaw");
|
||||
setDescription("Iris jigsaw commands");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTabOptions(MortarSender sender, String[] args, KList<String> list) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(MortarSender sender, String[] args)
|
||||
{
|
||||
if(!IrisSettings.get().isStudio())
|
||||
{
|
||||
sender.sendMessage("To use Iris Studio Jigsaw, please enable studio in Iris/settings.json");
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!sender.isPlayer())
|
||||
{
|
||||
sender.sendMessage("Ingame only");
|
||||
return true;
|
||||
}
|
||||
printHelp(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getArgsUsage()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
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.IrisStructurePiece;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class CommandIrisJigsawEdit extends MortarCommand
|
||||
{
|
||||
public CommandIrisJigsawEdit()
|
||||
{
|
||||
super("edit", "e", "*");
|
||||
requiresPermission(Iris.perm);
|
||||
setCategory("Jigsaw");
|
||||
setDescription("Create a new jigsaw piece");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTabOptions(MortarSender sender, String[] args, KList<String> list) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(MortarSender sender, String[] args)
|
||||
{
|
||||
if(!IrisSettings.get().isStudio())
|
||||
{
|
||||
sender.sendMessage("To use Iris Studio Jigsaw, please enable studio in Iris/settings.json");
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!sender.isPlayer())
|
||||
{
|
||||
sender.sendMessage("Ingame only");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
IrisStructurePiece piece = IrisDataManager.loadAnyStructurePiece(args[0]);
|
||||
|
||||
if(piece != null)
|
||||
{
|
||||
File dest = piece.getLoadFile();
|
||||
new JigsawEditor(sender.player(), piece, IrisDataManager.loadAnyObject(piece.getObject()), dest);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getArgsUsage()
|
||||
{
|
||||
return "<name>";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
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.IrisObject;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class CommandIrisJigsawNew extends MortarCommand
|
||||
{
|
||||
public CommandIrisJigsawNew()
|
||||
{
|
||||
super("create", "new", "+");
|
||||
requiresPermission(Iris.perm);
|
||||
setCategory("Jigsaw");
|
||||
setDescription("Create a new jigsaw piece");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTabOptions(MortarSender sender, String[] args, KList<String> list) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(MortarSender sender, String[] args)
|
||||
{
|
||||
if(!IrisSettings.get().isStudio())
|
||||
{
|
||||
sender.sendMessage("To use Iris Studio Jigsaw, please enable studio in Iris/settings.json");
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!sender.isPlayer())
|
||||
{
|
||||
sender.sendMessage("Ingame only");
|
||||
return true;
|
||||
}
|
||||
|
||||
if(args.length != 3)
|
||||
{
|
||||
sender.sendMessage(getArgsUsage());
|
||||
return true;
|
||||
}
|
||||
|
||||
IrisObject object = IrisDataManager.loadAnyObject(args[2]);
|
||||
File dest = Iris.instance.getDataFile("packs", args[1], "structure-pieces", args[0] + ".json");
|
||||
new JigsawEditor(sender.player(), null, object, dest);
|
||||
sender.sendMessage("* Right Click blocks to make them connectors");
|
||||
sender.sendMessage("* Right Click connectors to orient them");
|
||||
sender.sendMessage("* Shift + Right Click connectors to remove them");
|
||||
sender.sendMessage("Remember to use /iris jigsaw save");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getArgsUsage()
|
||||
{
|
||||
return "<name> <project> <object>";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.volmit.iris.manager.command;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.IrisSettings;
|
||||
import com.volmit.iris.manager.edit.JigsawEditor;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
|
||||
public class CommandIrisJigsawSave extends MortarCommand
|
||||
{
|
||||
public CommandIrisJigsawSave()
|
||||
{
|
||||
super("save");
|
||||
requiresPermission(Iris.perm);
|
||||
setCategory("Jigsaw");
|
||||
setDescription("Save a currently open piece");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTabOptions(MortarSender sender, String[] args, KList<String> list) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(MortarSender sender, String[] args)
|
||||
{
|
||||
if(!IrisSettings.get().isStudio())
|
||||
{
|
||||
sender.sendMessage("To use Iris Studio Jigsaw, please enable studio in Iris/settings.json");
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!sender.isPlayer())
|
||||
{
|
||||
sender.sendMessage("Ingame only");
|
||||
return true;
|
||||
}
|
||||
|
||||
JigsawEditor editor = JigsawEditor.editors.get(sender.player());
|
||||
|
||||
if(editor == null)
|
||||
{
|
||||
sender.sendMessage("You don't have any pieces open to save!");
|
||||
return true;
|
||||
}
|
||||
|
||||
editor.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getArgsUsage()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.volmit.iris.manager.edit;
|
||||
|
||||
import com.volmit.iris.util.J;
|
||||
import com.volmit.iris.scaffold.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.SR;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@@ -20,6 +21,48 @@ public class BlockSignal {
|
||||
of(block, 100);
|
||||
}
|
||||
|
||||
public static Runnable forever(Block block)
|
||||
{
|
||||
Location tg = block.getLocation().clone().add(0.5, 0, 0.5).clone();
|
||||
FallingBlock e = block.getWorld().spawnFallingBlock(tg.clone(), block.getBlockData());
|
||||
e.setGravity(false);
|
||||
e.setInvulnerable(true);
|
||||
e.setGlowing(true);
|
||||
e.teleport(tg.clone());
|
||||
e.setDropItem(false);
|
||||
e.setHurtEntities(false);
|
||||
e.setSilent(true);
|
||||
e.setTicksLived(1);
|
||||
e.setVelocity(new Vector(0, 0, 0));
|
||||
|
||||
new SR(20) {
|
||||
@Override
|
||||
public void run() {
|
||||
if(e.isDead())
|
||||
{
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
e.setTicksLived(1);
|
||||
e.teleport(tg.clone());
|
||||
e.setVelocity(new Vector(0, 0, 0));
|
||||
}
|
||||
};
|
||||
|
||||
return () -> {
|
||||
e.remove();
|
||||
BlockData type = block.getBlockData();
|
||||
|
||||
MultiBurst.burst.lazy(() -> {
|
||||
for(Player i : block.getWorld().getPlayers())
|
||||
{
|
||||
i.sendBlockChange(block.getLocation(), block.getBlockData());
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
public BlockSignal(Block block, int ticks)
|
||||
{
|
||||
Location tg = block.getLocation().clone().add(0.5, 0, 0.5).clone();
|
||||
|
||||
193
src/main/java/com/volmit/iris/manager/edit/JigsawEditor.java
Normal file
193
src/main/java/com/volmit/iris/manager/edit/JigsawEditor.java
Normal file
@@ -0,0 +1,193 @@
|
||||
package com.volmit.iris.manager.edit;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.object.*;
|
||||
import com.volmit.iris.util.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class JigsawEditor implements Listener {
|
||||
public static final KMap<Player, JigsawEditor> editors = new KMap<>();
|
||||
private final Player player;
|
||||
private final IrisObject object;
|
||||
private final File targetSaveLocation;
|
||||
private final IrisStructurePiece piece;
|
||||
private final Location origin;
|
||||
private final Cuboid cuboid;
|
||||
private final int ticker;
|
||||
private Location target;
|
||||
private final KMap<IrisPosition, Runnable> falling = new KMap<>();
|
||||
private final ChronoLatch cl = new ChronoLatch(100);
|
||||
|
||||
public JigsawEditor(Player player, IrisStructurePiece piece, IrisObject object, File saveLocation)
|
||||
{
|
||||
if(editors.containsKey(player))
|
||||
{
|
||||
editors.get(player).close();
|
||||
}
|
||||
|
||||
editors.put(player, this);
|
||||
this.object = object;
|
||||
this.player = player;
|
||||
origin = player.getLocation().clone().add(0, 7, 0);
|
||||
target = origin;
|
||||
this.targetSaveLocation = saveLocation;
|
||||
this.piece = piece == null ? new IrisStructurePiece() : piece;
|
||||
this.piece.setObject(object.getLoadKey());
|
||||
cuboid = new Cuboid(origin.clone(), origin.clone().add(object.getW()-1, object.getH()-1, object.getD()-1));
|
||||
ticker = J.sr(this::onTick, 0);
|
||||
object.placeCenterY(origin);
|
||||
Iris.instance.registerListener(this);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void on(PlayerMoveEvent e)
|
||||
{
|
||||
if(e.getPlayer().equals(player))
|
||||
{
|
||||
try
|
||||
{
|
||||
target = player.getTargetBlockExact(7).getLocation();
|
||||
}
|
||||
|
||||
catch(Throwable ex)
|
||||
{
|
||||
target = player.getLocation();
|
||||
return;
|
||||
}
|
||||
|
||||
if(cuboid.contains(target))
|
||||
{
|
||||
for(IrisPosition i : falling.k())
|
||||
{
|
||||
Location at = origin.clone().add(new Vector(i.getX()+1, i.getY()+1, i.getZ()+1)).getBlock().getLocation();
|
||||
|
||||
if(at.equals(target))
|
||||
{
|
||||
falling.remove(i).run();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void on(PlayerInteractEvent e)
|
||||
{
|
||||
if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK))
|
||||
{
|
||||
if(e.getClickedBlock() != null && cuboid.contains(e.getClickedBlock().getLocation()) && e.getPlayer().equals(player))
|
||||
{
|
||||
Vector v = e.getClickedBlock().getLocation().clone().subtract(origin.clone()).toVector();
|
||||
IrisPosition pos = new IrisPosition(v.getBlockX(), v.getBlockY(), v.getBlockZ());
|
||||
IrisStructurePieceConnector connector = null;
|
||||
for(IrisStructurePieceConnector i : piece.getConnectors())
|
||||
{
|
||||
if(i.getPosition().equals(pos))
|
||||
{
|
||||
connector = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!player.isSneaking() && connector == null)
|
||||
{
|
||||
connector = new IrisStructurePieceConnector();
|
||||
connector.setDirection(IrisDirection.getDirection(e.getBlockFace()));
|
||||
connector.setPosition(pos);
|
||||
piece.getConnectors().add(connector);
|
||||
player.playSound(e.getClickedBlock().getLocation(), Sound.ENTITY_ITEM_FRAME_ADD_ITEM, 1f, 1f);
|
||||
}
|
||||
|
||||
else if(player.isSneaking() && connector != null)
|
||||
{
|
||||
piece.getConnectors().remove(connector);
|
||||
player.playSound(e.getClickedBlock().getLocation(), Sound.ENTITY_ITEM_FRAME_REMOVE_ITEM, 1f, 1f);
|
||||
}
|
||||
|
||||
else if(connector != null && !player.isSneaking())
|
||||
{
|
||||
connector.setDirection(IrisDirection.getDirection(e.getBlockFace()));
|
||||
player.playSound(e.getClickedBlock().getLocation(), Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
J.car(ticker);
|
||||
Iris.instance.unregisterListener(this);
|
||||
object.unplaceCenterY(origin);
|
||||
editors.remove(player);
|
||||
falling.v().forEach(Runnable::run);
|
||||
try {
|
||||
IO.writeAll(targetSaveLocation, new JSONObject(new Gson().toJson(piece)).toString(4));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void onTick()
|
||||
{
|
||||
if(cl.flip())
|
||||
{
|
||||
Iris.wand.draw(cuboid, player);
|
||||
|
||||
f: for(IrisPosition i : falling.k())
|
||||
{
|
||||
for(IrisStructurePieceConnector j : piece.getConnectors())
|
||||
{
|
||||
if(j.getPosition().equals(i))
|
||||
{
|
||||
continue f;
|
||||
}
|
||||
}
|
||||
|
||||
falling.remove(i).run();
|
||||
}
|
||||
|
||||
for(IrisStructurePieceConnector i : piece.getConnectors())
|
||||
{
|
||||
IrisPosition pos = i.getPosition();
|
||||
Location at = origin.clone().add(new Vector(pos.getX()+1, pos.getY()+1, pos.getZ()+1));
|
||||
|
||||
Vector dir = i.getDirection().toVector().clone();
|
||||
|
||||
|
||||
for(int ix = 0; ix < RNG.r.i(1, 3); ix++)
|
||||
{
|
||||
at.getWorld().spawnParticle(Particle.SOUL_FIRE_FLAME, at.clone().getBlock().getLocation().add(0.25, 0.25, 0.25).add(RNG.r.d(0.5), RNG.r.d(0.5), RNG.r.d(0.5)), 0, dir.getX(), dir.getY(), dir.getZ(), 0.092 + RNG.r.d(-0.03, 0.08));
|
||||
}
|
||||
|
||||
if(at.getBlock().getLocation().equals(target))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!falling.containsKey(pos))
|
||||
{
|
||||
if(at.getBlock().getType().isAir())
|
||||
{
|
||||
at.getBlock().setType(Material.STONE);
|
||||
}
|
||||
|
||||
falling.put(pos, BlockSignal.forever(at.getBlock()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user