mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-24 09:39:16 +00:00
make jigsaw place command use the same method as normal gen
This commit is contained in:
@@ -59,7 +59,7 @@ public class CommandJigsaw implements DecreeExecutor {
|
||||
PlannedStructure ps = new PlannedStructure(structure, new IrisPosition(player().getLocation()), new RNG());
|
||||
VolmitSender sender = sender();
|
||||
sender.sendMessage(C.GREEN + "Generated " + ps.getPieces().size() + " pieces in " + Form.duration(p.getMilliseconds(), 2));
|
||||
ps.place(world(), failed -> sender.sendMessage(failed == 0 ? C.GREEN + "Placed the structure!" : C.RED + "Failed to place " + failed + " pieces!"));
|
||||
ps.place(world(), failed -> sender.sendMessage(failed ? C.GREEN + "Placed the structure!" : C.RED + "Failed to place the structure!"));
|
||||
}
|
||||
|
||||
@Decree(description = "Create a jigsaw piece")
|
||||
|
||||
@@ -21,6 +21,7 @@ package com.volmit.iris.engine.jigsaw;
|
||||
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.loader.IrisData;
|
||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||
import com.volmit.iris.engine.data.cache.Cache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.object.*;
|
||||
@@ -30,13 +31,17 @@ import com.volmit.iris.util.math.Position2;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.matter.slices.container.JigsawPieceContainer;
|
||||
import com.volmit.iris.util.matter.slices.container.JigsawStructuresContainer;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.bukkit.Axis;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.TileState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.IntConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Data
|
||||
public class PlannedStructure {
|
||||
@@ -139,20 +144,86 @@ public class PlannedStructure {
|
||||
return v.place(xx, height, zz, placer, options, rng, (b, data) -> {
|
||||
e.set(b.getX(), b.getY(), b.getZ(), v.getLoadKey() + "@" + id);
|
||||
e.set(b.getX(), b.getY(), b.getZ(), container);
|
||||
}, null, getData()) != -1;
|
||||
}, null, getData().getEngine() != null ? getData() : eng.getData()) != -1;
|
||||
}
|
||||
|
||||
public void place(World world, IntConsumer consumer) {
|
||||
AtomicInteger processed = new AtomicInteger();
|
||||
AtomicInteger failures = new AtomicInteger();
|
||||
for (PlannedPiece i : pieces) {
|
||||
Iris.sq(() -> {
|
||||
if (!i.place(world)) failures.incrementAndGet();
|
||||
if (processed.incrementAndGet() == pieces.size()) {
|
||||
consumer.accept(failures.get());
|
||||
}
|
||||
});
|
||||
public void place(World world, Consumer<Boolean> consumer) {
|
||||
var a = IrisToolbelt.access(world);
|
||||
if (a == null || a.getEngine() == null) {
|
||||
consumer.accept(null);
|
||||
return;
|
||||
}
|
||||
var engine = a.getEngine();
|
||||
var engineMantle = engine.getMantle();
|
||||
var placer = new IObjectPlacer() {
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data) {
|
||||
return engineMantle.getHighest(x, z, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data, boolean ignoreFluid) {
|
||||
return engineMantle.getHighest(x, z, data, ignoreFluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, BlockData d) {
|
||||
Block block = world.getBlockAt(x, y + world.getMinHeight(), z);
|
||||
|
||||
//Prevent blocks being set in or bellow bedrock
|
||||
if (y <= world.getMinHeight() || block.getType() == Material.BEDROCK) return;
|
||||
|
||||
block.setBlockData(d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockData get(int x, int y, int z) {
|
||||
return world.getBlockAt(x, y + world.getMinHeight(), z).getBlockData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPreventingDecay() {
|
||||
return engineMantle.isPreventingDecay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
return engineMantle.isCarved(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid(int x, int y, int z) {
|
||||
return world.getBlockAt(x, y + world.getMinHeight(), z).getType().isSolid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnderwater(int x, int z) {
|
||||
return engineMantle.isUnderwater(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFluidHeight() {
|
||||
return engineMantle.getFluidHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugSmartBore() {
|
||||
return engineMantle.isDebugSmartBore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTile(int xx, int yy, int zz, TileData<? extends TileState> tile) {
|
||||
BlockState state = world.getBlockAt(xx, yy + world.getMinHeight(), zz).getState();
|
||||
tile.toBukkitTry(state);
|
||||
state.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Engine getEngine() {
|
||||
return engine;
|
||||
}
|
||||
};
|
||||
J.s(() -> consumer.accept(place(placer, engineMantle.getMantle(), engine)));
|
||||
}
|
||||
|
||||
private void generateOutwards() {
|
||||
|
||||
Reference in New Issue
Block a user