This commit is contained in:
Daniel Mills
2020-12-23 19:47:30 -05:00
parent 89e1af456f
commit 5487cd7858
12 changed files with 694 additions and 154 deletions

View File

@@ -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();

View 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()));
}
}
}
}
}