mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-03 08:26:11 +00:00
Merge remote-tracking branch 'origin/v3.4.3' into v3.4.3
This commit is contained in:
commit
df8fa79209
@ -381,7 +381,7 @@ public class CommandObject implements DecreeExecutor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
o.write(file);
|
o.write(file, sender());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
sender().sendMessage(C.RED + "Failed to save object because of an IOException: " + e.getMessage());
|
sender().sendMessage(C.RED + "Failed to save object because of an IOException: " + e.getMessage());
|
||||||
Iris.reportError(e);
|
Iris.reportError(e);
|
||||||
|
@ -36,6 +36,7 @@ import com.volmit.iris.util.plugin.VolmitSender;
|
|||||||
import com.volmit.iris.util.scheduling.J;
|
import com.volmit.iris.util.scheduling.J;
|
||||||
import com.volmit.iris.util.scheduling.S;
|
import com.volmit.iris.util.scheduling.S;
|
||||||
import com.volmit.iris.util.scheduling.SR;
|
import com.volmit.iris.util.scheduling.SR;
|
||||||
|
import com.volmit.iris.util.scheduling.jobs.Job;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
@ -55,11 +56,12 @@ import java.awt.Color;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public class WandSVC implements IrisService {
|
public class WandSVC implements IrisService {
|
||||||
private static final Particle CRIT_MAGIC = E.getOrDefault(Particle.class, "CRIT_MAGIC", "CRIT");
|
private static final Particle CRIT_MAGIC = E.getOrDefault(Particle.class, "CRIT_MAGIC", "CRIT");
|
||||||
private static final Particle REDSTONE = E.getOrDefault(Particle.class, "REDSTONE", "DUST");
|
private static final Particle REDSTONE = E.getOrDefault(Particle.class, "REDSTONE", "DUST");
|
||||||
private static final int BLOCKS_PER_TICK = Integer.parseInt(System.getProperty("iris.blocks_per_tick", "1000"));
|
private static final int MS_PER_TICK = Integer.parseInt(System.getProperty("iris.ms_per_tick", "30"));
|
||||||
|
|
||||||
private static ItemStack dust;
|
private static ItemStack dust;
|
||||||
private static ItemStack wand;
|
private static ItemStack wand;
|
||||||
@ -85,27 +87,63 @@ public class WandSVC implements IrisService {
|
|||||||
IrisObject s = new IrisObject(c.getSizeX(), c.getSizeY(), c.getSizeZ());
|
IrisObject s = new IrisObject(c.getSizeX(), c.getSizeY(), c.getSizeZ());
|
||||||
|
|
||||||
var it = c.iterator();
|
var it = c.iterator();
|
||||||
|
|
||||||
|
int total = c.getSizeX() * c.getSizeY() * c.getSizeZ();
|
||||||
|
AtomicInteger i = new AtomicInteger(0);
|
||||||
var latch = new CountDownLatch(1);
|
var latch = new CountDownLatch(1);
|
||||||
|
new Job() {
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "Scanning Selection";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
new SR() {
|
new SR() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
for (int i = 0; i < BLOCKS_PER_TICK; i++) {
|
var time = M.ms() + MS_PER_TICK;
|
||||||
|
while (time > M.ms()) {
|
||||||
if (!it.hasNext()) {
|
if (!it.hasNext()) {
|
||||||
cancel();
|
cancel();
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
var b = it.next();
|
var b = it.next();
|
||||||
if (b.getType().equals(Material.AIR))
|
if (b.getType().equals(Material.AIR))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
BlockVector bv = b.getLocation().subtract(c.getLowerNE().toVector()).toVector().toBlockVector();
|
BlockVector bv = b.getLocation().subtract(c.getLowerNE().toVector()).toVector().toBlockVector();
|
||||||
s.setUnsigned(bv.getBlockX(), bv.getBlockY(), bv.getBlockZ(), b);
|
s.setUnsigned(bv.getBlockX(), bv.getBlockY(), bv.getBlockZ(), b);
|
||||||
|
} finally {
|
||||||
|
i.incrementAndGet();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
try {
|
||||||
latch.await();
|
latch.await();
|
||||||
|
} catch (InterruptedException ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void completeWork() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTotalWork() {
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getWorkCompleted() {
|
||||||
|
return i.get();
|
||||||
|
}
|
||||||
|
}.execute(new VolmitSender(p), true, () -> {});
|
||||||
|
try {
|
||||||
|
latch.await();
|
||||||
|
} catch (InterruptedException ignored) {}
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
@ -43,6 +43,7 @@ import com.volmit.iris.util.parallel.MultiBurst;
|
|||||||
import com.volmit.iris.util.plugin.VolmitSender;
|
import com.volmit.iris.util.plugin.VolmitSender;
|
||||||
import com.volmit.iris.util.scheduling.IrisLock;
|
import com.volmit.iris.util.scheduling.IrisLock;
|
||||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||||
|
import com.volmit.iris.util.scheduling.jobs.Job;
|
||||||
import com.volmit.iris.util.stream.ProceduralStream;
|
import com.volmit.iris.util.stream.ProceduralStream;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@ -63,7 +64,9 @@ import org.bukkit.util.Vector;
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
@ -384,6 +387,88 @@ public class IrisObject extends IrisRegistrant {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void write(OutputStream o, VolmitSender sender) throws IOException {
|
||||||
|
AtomicReference<IOException> ref = new AtomicReference<>();
|
||||||
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
new Job() {
|
||||||
|
private int total = getBlocks().size() * 3 + getStates().size();
|
||||||
|
private int c = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "Saving Object";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
|
try {
|
||||||
|
DataOutputStream dos = new DataOutputStream(o);
|
||||||
|
dos.writeInt(w);
|
||||||
|
dos.writeInt(h);
|
||||||
|
dos.writeInt(d);
|
||||||
|
dos.writeUTF("Iris V2 IOB;");
|
||||||
|
|
||||||
|
KList<String> palette = new KList<>();
|
||||||
|
|
||||||
|
for (BlockData i : getBlocks().values()) {
|
||||||
|
palette.addIfMissing(i.getAsString());
|
||||||
|
++c;
|
||||||
|
}
|
||||||
|
total -= getBlocks().size() - palette.size();
|
||||||
|
|
||||||
|
dos.writeShort(palette.size());
|
||||||
|
|
||||||
|
for (String i : palette) {
|
||||||
|
dos.writeUTF(i);
|
||||||
|
++c;
|
||||||
|
}
|
||||||
|
|
||||||
|
dos.writeInt(getBlocks().size());
|
||||||
|
|
||||||
|
for (BlockVector i : getBlocks().keySet()) {
|
||||||
|
dos.writeShort(i.getBlockX());
|
||||||
|
dos.writeShort(i.getBlockY());
|
||||||
|
dos.writeShort(i.getBlockZ());
|
||||||
|
dos.writeShort(palette.indexOf(getBlocks().get(i).getAsString()));
|
||||||
|
++c;
|
||||||
|
}
|
||||||
|
|
||||||
|
dos.writeInt(getStates().size());
|
||||||
|
for (BlockVector i : getStates().keySet()) {
|
||||||
|
dos.writeShort(i.getBlockX());
|
||||||
|
dos.writeShort(i.getBlockY());
|
||||||
|
dos.writeShort(i.getBlockZ());
|
||||||
|
getStates().get(i).toBinary(dos);
|
||||||
|
++c;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
ref.set(e);
|
||||||
|
} finally {
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void completeWork() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTotalWork() {
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getWorkCompleted() {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}.execute(sender, true, () -> {});
|
||||||
|
|
||||||
|
try {
|
||||||
|
latch.await();
|
||||||
|
} catch (InterruptedException ignored) {}
|
||||||
|
if (ref.get() != null)
|
||||||
|
throw ref.get();
|
||||||
|
}
|
||||||
|
|
||||||
public void read(File file) throws IOException {
|
public void read(File file) throws IOException {
|
||||||
var fin = new BufferedInputStream(new FileInputStream(file));
|
var fin = new BufferedInputStream(new FileInputStream(file));
|
||||||
try {
|
try {
|
||||||
@ -408,6 +493,16 @@ public class IrisObject extends IrisRegistrant {
|
|||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void write(File file, VolmitSender sender) throws IOException {
|
||||||
|
if (file == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FileOutputStream out = new FileOutputStream(file);
|
||||||
|
write(out, sender);
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
|
||||||
public void shrinkwrap() {
|
public void shrinkwrap() {
|
||||||
BlockVector min = new BlockVector();
|
BlockVector min = new BlockVector();
|
||||||
BlockVector max = new BlockVector();
|
BlockVector max = new BlockVector();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user