SteamWar/BauSystem2.0
Archiviert
12
0

Update Laufbau
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-02-04 18:51:03 +01:00
Ursprung 00cfa1676b
Commit 1a3559b7ac

Datei anzeigen

@ -33,12 +33,16 @@ import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.data.Bisected;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Campfire;
import org.bukkit.block.data.type.Fence;
import org.bukkit.block.data.type.Slab;
import org.bukkit.block.data.type.TrapDoor;
import org.bukkit.util.Vector;
import java.util.*;
import java.util.logging.Level;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class Laufbau {
@ -48,31 +52,29 @@ public class Laufbau {
private static class BlockDataWithBoundingBox {
private BlockData blockData;
private Cuboid cuboid;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof BlockDataWithBoundingBox)) return false;
BlockDataWithBoundingBox that = (BlockDataWithBoundingBox) o;
return that.blockData.getClass() == this.blockData.getClass();
}
@Override
public int hashCode() {
return blockData.getClass().hashCode();
}
}
private static Set<BlockDataWithBoundingBox> elements = new HashSet<>();
private static List<BlockDataWithBoundingBox> elements = new ArrayList<>();
static {
elements.add(new BlockDataWithBoundingBox(Material.AIR.createBlockData(), new Cuboid(0, 0, 0, 0, 0, 0)));
elements.add(new BlockDataWithBoundingBox(Material.END_STONE.createBlockData(), new Cuboid(0, 0, 0, 1, 1, 1)));
BlockData soulSand = Material.SOUL_SAND.createBlockData();
elements.add(new BlockDataWithBoundingBox(soulSand, new Cuboid(0, 0, 0, 1, 0.9375, 1)));
BlockData stoneCutter = Material.STONECUTTER.createBlockData();
elements.add(new BlockDataWithBoundingBox(stoneCutter, new Cuboid(0, 0, 0, 1, 0.5625, 1)));
Slab bottomSlab = (Slab) Material.END_STONE_BRICK_SLAB.createBlockData();
bottomSlab.setType(Slab.Type.BOTTOM);
elements.add(new BlockDataWithBoundingBox(bottomSlab, new Cuboid(0, 0, 0, 1, 0.5, 1)));
Campfire campfire = (Campfire) Material.CAMPFIRE.createBlockData();
campfire.setSignalFire(false);
campfire.setLit(false);
elements.add(new BlockDataWithBoundingBox(campfire, new Cuboid(0, 0, 0, 1, 0.4375, 1)));
Slab topSlab = (Slab) Material.END_STONE_BRICK_SLAB.createBlockData();
topSlab.setType(Slab.Type.TOP);
elements.add(new BlockDataWithBoundingBox(topSlab, new Cuboid(0, 0.5, 0, 1, 0.5, 1)));
@ -84,6 +86,15 @@ public class Laufbau {
TrapDoor topTrapDoor = (TrapDoor) Material.IRON_TRAPDOOR.createBlockData();
topTrapDoor.setHalf(Bisected.Half.TOP);
elements.add(new BlockDataWithBoundingBox(topTrapDoor, new Cuboid(0, 0.8125, 0, 1, 0.1875, 1)));
Fence endStoneBrickWall = (Fence) Material.END_STONE_BRICK_WALL.createBlockData();
elements.add(new BlockDataWithBoundingBox(endStoneBrickWall, new Cuboid(0.25, 0, 0.25, 0.5, 1.5, 0.5)));
Fence fence = (Fence) Material.OAK_FENCE.createBlockData();
elements.add(new BlockDataWithBoundingBox(fence, new Cuboid(0.375, 0, 0.375, 0.25, 1.5, 0.25)));
Fence ironBar = (Fence) Material.IRON_BARS.createBlockData();
elements.add(new BlockDataWithBoundingBox(ironBar, new Cuboid(0.4375, 0, 0.4375, 0.125, 1, 0.125)));
}
private Set<TNTPosition> tntPositions = new HashSet<>();
@ -94,41 +105,6 @@ public class Laufbau {
private Location pos2;
public Laufbau(Location pos1, Location pos2, Material blockMaterial, Material slabMaterial) {
if (false) {
{
Cuboid c1 = new Cuboid(0, 0, 0, 1, 1, 1);
System.out.println(c1.intersects(c1));
}
{
// FALSE! -> Wrong for now
Cuboid c1 = new Cuboid(0, 0, 0, 1, 1, 1);
Cuboid c2 = new Cuboid(1, 0, 0, 1, 1, 1);
System.out.println(c1.intersects(c2));
}
{
// FALSE!
Cuboid c1 = new Cuboid(0, 0, 0, 1, 1, 1);
Cuboid c2 = new Cuboid(1.1, 0, 0, 1, 1, 1);
System.out.println(c1.intersects(c2));
}
{
Cuboid c1 = new Cuboid(0, 0, 0, 3, 3, 3);
Cuboid c2 = new Cuboid(1, 1, 1, 1, 1, 1);
System.out.println(c1.intersects(c2));
}
{
Cuboid c1 = new Cuboid(0, 0, 0, 3, 1, 3);
Cuboid c2 = new Cuboid(0, 0, 1, 1, 1, 3);
System.out.println(c1.intersects(c2));
}
{
Cuboid c1 = new Cuboid(0, 0, 0, 3, 1, 3);
Cuboid c2 = new Cuboid(0, 0.5, 0, 1, 1, 1);
System.out.println(c1.intersects(c2));
}
return;
}
this.world = pos1.getWorld();
this.pos1 = new Location(world, Math.min(pos1.getBlockX(), pos2.getBlockX()), Math.min(pos1.getBlockY(), pos2.getBlockY()), Math.min(pos1.getBlockZ(), pos2.getBlockZ()));
this.pos2 = new Location(world, Math.max(pos1.getBlockX(), pos2.getBlockX()), Math.max(pos1.getBlockY(), pos2.getBlockY()), Math.max(pos1.getBlockZ(), pos2.getBlockZ()));
@ -213,12 +189,11 @@ public class Laufbau {
return !blockMap3.contains(p1) && !blockMap3.contains(p2) && !blockMap3.contains(p3) && !blockMap3.contains(p4) && !blockMap3.contains(p5) && !blockMap3.contains(p6);
});
Map<Point, BlockDataWithBoundingBox> blockDataMap = new HashMap<>();
blockMap3.forEach(point -> {
List<BlockDataWithBoundingBox> blockDataWithBoundingBoxList = new ArrayList<>();
for (BlockDataWithBoundingBox blockDataWithBoundingBox : elements) {
Cuboid tempCuboid = blockDataWithBoundingBox.cuboid.add(point);
// Bukkit.getLogger().log(Level.INFO, tempCuboid.toString());
// Bukkit.getLogger().info(tempCuboid.toString());
boolean isInCuboid = false;
for (Cuboid cuboid : cuboidList) {
if (cuboid.intersects(tempCuboid)) {
@ -232,18 +207,27 @@ public class Laufbau {
if (blockDataWithBoundingBoxList.isEmpty()) {
return;
}
if (blockDataWithBoundingBoxList.size() == 1) {
blockDataMap.put(point, blockDataWithBoundingBoxList.get(0));
return;
Cuboid currentHighest = blockDataWithBoundingBoxList.get(0).cuboid;
BlockData highestBlockData = blockDataWithBoundingBoxList.get(0).blockData;
for (BlockDataWithBoundingBox blockDataWithBoundingBox : blockDataWithBoundingBoxList) {
if (currentHighest.getDx() < blockDataWithBoundingBox.cuboid.getDx() &&
currentHighest.getDy() < blockDataWithBoundingBox.cuboid.getDy() &&
currentHighest.getDz() < blockDataWithBoundingBox.cuboid.getDz()) {
currentHighest = blockDataWithBoundingBox.cuboid;
highestBlockData = blockDataWithBoundingBox.blockData;
}
Bukkit.getLogger().log(Level.INFO, blockDataWithBoundingBoxList.size() + " " + blockDataWithBoundingBoxList);
// System.out.println(blockDataWithBoundingBoxList.size() + " " + blockDataWithBoundingBoxList);
}
// blockDataMap.put(point, new BlockDataWithBoundingBox(highestBlockData, currentHighest));
Location location = new Location(world, point.getX(), point.getY(), point.getZ());
BlockData finalHighestBlockData = highestBlockData;
Bukkit.getOnlinePlayers().forEach(player -> {
player.sendBlockChange(location, finalHighestBlockData);
});
});
System.out.println(blockMap3.size());
display(blockMap2);
// System.out.println(blockMap2);
// System.out.println(blockMap2.size());
}
private void display(Set<Point> blockMap) {
@ -321,7 +305,7 @@ public class Laufbau {
return new Cuboid(nx, ny, nz, dx, dy, dz);
}
private double round(double value) {
private static double round(double value) {
value *= 100000000000000L;
value = Math.round(value);
value /= 100000000000000L;