SteamWar/BauSystem2.0
Archiviert
12
0

Optimize Laufbau
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-10-02 15:46:22 +02:00
Ursprung 9728341529
Commit 41a457920d
10 geänderte Dateien mit 265 neuen und 524 gelöschten Zeilen

Datei anzeigen

@ -1103,11 +1103,7 @@ LAUFBAU_NO_PERM = §cYou are not allowed to use the barrel building system here
LAUFBAU_NO_WORLDEDIT = §cYou don't have a WorldEdit selection
LAUFBAU_STATE_FILTERING_TRACES = Filtering traces
LAUFBAU_STATE_PROCESSING_TRACES = Connnecting traces
LAUFBAU_STATE_EXPANDING_TRACES = Expanding traces
LAUFBAU_STATE_SPLITTING_POINTS = Splitting points
LAUFBAU_STATE_SHRINKING_POINTS = Shrinking points
LAUFBAU_STATE_CREATING_INNER_BLOCKS = Creating inner blocks
LAUFBAU_STATE_CREATING_OUTER_BLOCKS = Creating outer blocks
LAUFBAU_STATE_CREATE_LAUF = Create Barrel
LAUFBAU_SIMPLE_PROGRESS = §e{0}§8: §e{1}§8/§e{2} §7Time left§8: §e{3}
LAUFBAU_DONE = §aDone

Datei anzeigen

@ -1081,11 +1081,7 @@ LAUFBAU_NO_PERM = §cDu darfst hier nicht das Laufbau System verwenden
LAUFBAU_NO_WORLDEDIT = §cDu hast keine WorldEdit Selection
LAUFBAU_STATE_FILTERING_TRACES = Traces filtern
LAUFBAU_STATE_PROCESSING_TRACES = Traces verbinden
LAUFBAU_STATE_EXPANDING_TRACES = Traces aufblähen
LAUFBAU_STATE_SPLITTING_POINTS = Punkte trennen
LAUFBAU_STATE_SHRINKING_POINTS = Punkte ausdünnen
LAUFBAU_STATE_CREATING_INNER_BLOCKS = Innenraum füllen
LAUFBAU_STATE_CREATING_OUTER_BLOCKS = Mantel bauen
LAUFBAU_STATE_CREATE_LAUF = Lauf erstellen
LAUFBAU_SIMPLE_PROGRESS = §e{0}§8: §e{1}§8/§e{2} §7Übrige Zeit §8: §e{3}
LAUFBAU_DONE = §aZuende gebaut

Datei anzeigen

@ -20,8 +20,11 @@
package de.steamwar.bausystem.features.slaves.laufbau;
import com.sk89q.worldedit.EditSession;
import de.steamwar.bausystem.features.slaves.laufbau.states.FilteringTracesState;
import de.steamwar.bausystem.features.slaves.laufbau.states.LaufbauState;
import de.steamwar.bausystem.features.slaves.laufbau.states.CreatingLaufState;
import de.steamwar.bausystem.features.slaves.laufbau.states.ProcessingTracesState;
import de.steamwar.bausystem.utils.WorldEditUtils;
import de.steamwar.bausystem.features.slaves.laufbau.states.*;
import lombok.Getter;
import org.bukkit.Location;
import org.bukkit.World;
@ -37,15 +40,9 @@ public class Laufbau {
private Location pos1;
private Location pos2;
private boolean preferingBlastResistance;
private FilteringTracesState filteringTracesState = null;
private ProcessingTracesState processingTracesState = null;
private ExpandingTracesState expandingTracesState = null;
private SplittingPointsState splittingPointsState = null;
private ShrinkingOuterPointsState shrinkingOuterPointsState = null;
private CreatingInnerBlocksState creatingInnerBlocksState = null;
private CreatingOuterBlocksState creatingOuterBlocksState = null;
private CreatingLaufState creatingLaufState = null;
private List<BlockBoundingBox> elements;
@ -57,8 +54,6 @@ public class Laufbau {
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()));
this.preferingBlastResistance = preferingBlastResistance;
filteringTracesState = new FilteringTracesState(world, this::inRegion);
editSession = WorldEditUtils.getEditSession(world);
@ -86,20 +81,8 @@ public class Laufbau {
}
private LaufbauState getActive() {
if (creatingOuterBlocksState != null) {
return creatingOuterBlocksState;
}
if (creatingInnerBlocksState != null) {
return creatingInnerBlocksState;
}
if (shrinkingOuterPointsState != null) {
return shrinkingOuterPointsState;
}
if (splittingPointsState != null) {
return splittingPointsState;
}
if (expandingTracesState != null) {
return expandingTracesState;
if (creatingLaufState != null) {
return creatingLaufState;
}
if (processingTracesState != null) {
return processingTracesState;
@ -108,30 +91,14 @@ public class Laufbau {
}
private void createNextState() {
if (creatingOuterBlocksState != null) {
return;
}
if (creatingInnerBlocksState != null) {
creatingOuterBlocksState = new CreatingOuterBlocksState(shrinkingOuterPointsState.getShrunkOuterPoints(), world, editSession);
return;
}
if (shrinkingOuterPointsState != null) {
creatingInnerBlocksState = new CreatingInnerBlocksState(splittingPointsState.getInnerPoints(), world, splittingPointsState.getIntersectedCuboid(), editSession, elements);
return;
}
if (splittingPointsState != null) {
shrinkingOuterPointsState = new ShrinkingOuterPointsState(splittingPointsState.getOuterPoints(), splittingPointsState.getInnerPoints());
return;
}
if (expandingTracesState != null) {
splittingPointsState = new SplittingPointsState(expandingTracesState.getBlocks(), processingTracesState.getCuboidList());
if (creatingLaufState != null) {
return;
}
if (processingTracesState != null) {
expandingTracesState = new ExpandingTracesState(processingTracesState.getCuboidList(), world, this::inRegion);
creatingLaufState = new CreatingLaufState(processingTracesState.getBlocks(), processingTracesState.getCuboidList(), world, editSession, elements);
return;
}
processingTracesState = new ProcessingTracesState(filteringTracesState.getTntPositions());
processingTracesState = new ProcessingTracesState(filteringTracesState.getTntPositions(), world, this::inRegion);
}
public String actionBarMessage(Player p) {

Datei anzeigen

@ -1,111 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.slaves.laufbau.states;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.slaves.laufbau.BlockBoundingBox;
import de.steamwar.bausystem.features.slaves.laufbau.Cuboid;
import de.steamwar.bausystem.region.Point;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class CreatingInnerBlocksState implements LaufbauState {
private long start = System.currentTimeMillis();
private List<Point> innerBlocks;
private int index = 0;
private World world;
private Map<Point, List<Cuboid>> intersectedCuboid;
private EditSession editSession;
private List<BlockBoundingBox> elements;
public CreatingInnerBlocksState(List<Point> innerBlocks, World world, Map<Point, List<Cuboid>> intersectedCuboid, EditSession editSession, List<BlockBoundingBox> elements) {
this.innerBlocks = innerBlocks;
this.world = world;
this.intersectedCuboid = intersectedCuboid;
this.editSession = editSession;
this.elements = elements;
}
@Override
public String actionBarMessage(Player p) {
return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_CREATING_INNER_BLOCKS", p), index, innerBlocks.size(), eta(p, start, index, innerBlocks.size()));
}
@Override
public boolean hasNext() {
return index < innerBlocks.size();
}
@Override
public void next() {
Point point = innerBlocks.get(index);
index++;
List<Cuboid> neededCuboids = intersectedCuboid.get(point);
List<BlockBoundingBox> blockDataWithBoundingBoxList = new ArrayList<>();
for (BlockBoundingBox blockDataWithBoundingBox : elements) {
List<Cuboid> cuboids = blockDataWithBoundingBox.getCuboidList().stream().map(c -> c.add(point)).collect(Collectors.toList());
boolean isInCuboid = false;
for (Cuboid cuboid : neededCuboids) {
if (cuboids.stream().anyMatch(cuboid::intersects)) {
isInCuboid = true;
break;
}
}
if (!isInCuboid) {
blockDataWithBoundingBoxList.add(blockDataWithBoundingBox);
break;
}
}
if (blockDataWithBoundingBoxList.isEmpty()) {
return;
}
BlockBoundingBox highest = blockDataWithBoundingBoxList.get(0);
Location location = new Location(world, point.getX(), point.getY(), point.getZ());
if (!location.getBlock().getType().isAir()) {
return;
}
try {
editSession.setBlock(BukkitAdapter.asBlockVector(location), BukkitAdapter.adapt(highest.blockData));
location.getBlock().setBlockData(highest.blockData, false);
if (highest.blockConsumer != null) highest.blockConsumer.accept(location.getBlock());
} catch (MaxChangedBlocksException e) {
e.printStackTrace();
// ignored
}
}
}

Datei anzeigen

@ -0,0 +1,200 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.slaves.laufbau.states;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockTypes;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.slaves.laufbau.BlockBoundingBox;
import de.steamwar.bausystem.features.slaves.laufbau.Cuboid;
import de.steamwar.bausystem.region.Point;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class CreatingLaufState implements LaufbauState {
private static final Cuboid ONE = new Cuboid(0, 0, 0, 1, 1, 1);
private static final Cuboid ABOVE_HALF = new Cuboid(0, 1, 0, 1, 0.5, 1);
private static final BaseBlock SHELL;
static {
SHELL = BlockTypes.get("minecraft:end_stone").getDefaultState().toBaseBlock();
}
private long start = System.currentTimeMillis();
private List<Point> blocks;
private List<Cuboid> cuboids;
private List<Point> outerPoints = new ArrayList<>();
private Set<Point> innerPoints = new HashSet<>();
private World world;
private EditSession editSession;
private List<BlockBoundingBox> elements;
private int operations = 0;
private int totalOperations;
public CreatingLaufState(Set<Point> blocks, List<Cuboid> cuboids, World world, EditSession editSession, List<BlockBoundingBox> elements) {
this.blocks = new ArrayList<>(blocks);
this.cuboids = cuboids;
this.world = world;
this.editSession = editSession;
this.elements = elements;
totalOperations = blocks.size() * 2;
}
@Override
public String actionBarMessage(Player p) {
return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_CREATE_LAUF", p), operations, totalOperations, eta(p, start, operations, totalOperations));
}
@Override
public boolean hasNext() {
return !blocks.isEmpty() || !outerPoints.isEmpty();
}
@Override
public void next() {
operations++;
if (!blocks.isEmpty()) {
Point point = blocks.remove(0);
boolean isInCuboid = false;
Cuboid tempCuboid = ONE.add(point);
Cuboid aboveHalfTempCuboid = ABOVE_HALF.add(point);
List<Cuboid> intersectedCuboids = new ArrayList<>();
for (Cuboid cuboid : cuboids) {
if (cuboid.intersects(tempCuboid)) {
isInCuboid = true;
intersectedCuboids.add(cuboid);
}
if (cuboid.intersects(aboveHalfTempCuboid)) {
intersectedCuboids.add(cuboid);
}
}
if (!isInCuboid) {
if (hasInnerNeighbour(point)) {
operations++;
setShell(point);
} else {
outerPoints.add(point);
}
} else {
innerPoints.add(point);
operations++;
calcInnerBlock(point, intersectedCuboids);
}
} else {
Point point = outerPoints.remove(0);
setShell(point);
}
}
private void calcInnerBlock(Point point, List<Cuboid> neededCuboids) {
List<BlockBoundingBox> blockDataWithBoundingBoxList = new ArrayList<>();
for (BlockBoundingBox blockDataWithBoundingBox : elements) {
List<Cuboid> cuboids = blockDataWithBoundingBox.getCuboidList().stream().map(c -> c.add(point)).collect(Collectors.toList());
boolean isInCuboid = false;
for (Cuboid cuboid : neededCuboids) {
if (cuboids.stream().anyMatch(cuboid::intersects)) {
isInCuboid = true;
break;
}
}
if (!isInCuboid) {
blockDataWithBoundingBoxList.add(blockDataWithBoundingBox);
break;
}
}
if (blockDataWithBoundingBoxList.isEmpty()) {
return;
}
BlockBoundingBox highest = blockDataWithBoundingBoxList.get(0);
Location location = new Location(world, point.getX(), point.getY(), point.getZ());
if (!location.getBlock().getType().isAir()) {
return;
}
try {
editSession.setBlock(BukkitAdapter.asBlockVector(location), BukkitAdapter.adapt(highest.blockData));
location.getBlock().setBlockData(highest.blockData, false);
if (highest.blockConsumer != null) highest.blockConsumer.accept(location.getBlock());
} catch (MaxChangedBlocksException e) {
e.printStackTrace();
// ignored
}
}
private boolean hasInnerNeighbour(Point point) {
Point p1 = new Point(point.getX() - 1, point.getY(), point.getZ());
if (innerPoints.contains(p1)) {
return true;
}
Point p2 = new Point(point.getX() + 1, point.getY(), point.getZ());
if (innerPoints.contains(p2)) {
return true;
}
Point p3 = new Point(point.getX(), point.getY() - 1, point.getZ());
if (innerPoints.contains(p3)) {
return true;
}
Point p4 = new Point(point.getX(), point.getY() + 1, point.getZ());
if (innerPoints.contains(p4)) {
return true;
}
Point p5 = new Point(point.getX(), point.getY(), point.getZ() - 1);
if (innerPoints.contains(p5)) {
return true;
}
Point p6 = new Point(point.getX(), point.getY(), point.getZ() + 1);
if (innerPoints.contains(p6)) {
return true;
}
return false;
}
private void setShell(Point point) {
if (hasInnerNeighbour(point)) {
Location location = new Location(world, point.getX(), point.getY(), point.getZ());
if (!location.getBlock().getType().isAir()) {
return;
}
try {
editSession.setBlock(BukkitAdapter.asBlockVector(location), SHELL);
location.getBlock().setType(Material.END_STONE, false);
} catch (MaxChangedBlocksException e) {
e.printStackTrace();
// ingored
}
}
}
}

Datei anzeigen

@ -1,85 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.slaves.laufbau.states;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockTypes;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.region.Point;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;
import java.util.List;
public class CreatingOuterBlocksState implements LaufbauState {
private static final BaseBlock SHELL;
static {
SHELL = BlockTypes.get("minecraft:end_stone").getDefaultState().toBaseBlock();
}
private long start = System.currentTimeMillis();
private List<Point> outerBlocks;
private int index = 0;
private World world;
private EditSession editSession;
public CreatingOuterBlocksState(List<Point> outerBlocks, World world, EditSession editSession) {
this.outerBlocks = outerBlocks;
this.world = world;
this.editSession = editSession;
}
@Override
public String actionBarMessage(Player p) {
return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_CREATING_OUTER_BLOCKS", p), index, outerBlocks.size(), eta(p, start, index, outerBlocks.size()));
}
@Override
public boolean hasNext() {
return index < outerBlocks.size();
}
@Override
public void next() {
Point point = outerBlocks.get(index);
index++;
Location location = new Location(world, point.getX(), point.getY(), point.getZ());
if (!location.getBlock().getType().isAir()) {
return;
}
try {
editSession.setBlock(BukkitAdapter.asBlockVector(location), SHELL);
location.getBlock().setType(Material.END_STONE, false);
} catch (MaxChangedBlocksException e) {
e.printStackTrace();
// ingored
}
}
}

Datei anzeigen

@ -1,82 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.slaves.laufbau.states;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.slaves.laufbau.Cuboid;
import de.steamwar.bausystem.region.Point;
import lombok.Getter;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.BiPredicate;
public class ExpandingTracesState implements LaufbauState {
private long start = System.currentTimeMillis();
private List<Cuboid> cuboidList;
private int totalCuboids;
private World world;
private BiPredicate<Vector, Integer> inRegionCheck;
@Getter
private Set<Point> blocks = new HashSet<>();
public ExpandingTracesState(List<Cuboid> cuboidList, World world, BiPredicate<Vector, Integer> inRegionCheck) {
this.cuboidList = new ArrayList<>(cuboidList);
this.totalCuboids = cuboidList.size();
this.world = world;
this.inRegionCheck = inRegionCheck;
}
@Override
public String actionBarMessage(Player p) {
return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_EXPANDING_TRACES", p), totalCuboids - cuboidList.size(), totalCuboids, eta(p, start, totalCuboids - cuboidList.size(), totalCuboids));
}
@Override
public boolean hasNext() {
return !cuboidList.isEmpty();
}
@Override
public void next() {
Cuboid cuboid = cuboidList.remove(0);
for (double x = cuboid.getX() - 2; x < cuboid.getX() + cuboid.getDx() + 2; x++) {
for (double y = cuboid.getY() - 2; y < cuboid.getY() + cuboid.getDy() + 2; y++) {
for (double z = cuboid.getZ() - 2; z < cuboid.getZ() + cuboid.getDz() + 2; z++) {
Location location = new Location(world, x, y, z);
if (inRegionCheck.test(new Vector(location.getBlockX(), location.getBlockY(), location.getBlockZ()), 0)) {
Point point = new Point(location.getBlockX(), location.getBlockY(), location.getBlockZ());
blocks.add(point);
}
}
}
}
}
}

Datei anzeigen

@ -21,56 +21,97 @@ package de.steamwar.bausystem.features.slaves.laufbau.states;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.slaves.laufbau.Cuboid;
import de.steamwar.bausystem.features.slaves.laufbau.states.LaufbauState;
import de.steamwar.bausystem.features.tracer.TNTPosition;
import de.steamwar.bausystem.region.Point;
import lombok.Getter;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.BiPredicate;
public class ProcessingTracesState implements LaufbauState {
private long start = System.currentTimeMillis();
private int totalTNTPositions;
private int totalCuboids;
private List<TNTPosition> tntPositionList;
private World world;
private BiPredicate<Vector, Integer> inRegionCheck;
private List<Cuboid> toExpand = new ArrayList<>();
@Getter
private List<Cuboid> cuboidList = new ArrayList<>();
public ProcessingTracesState(List<TNTPosition> tntPositionList) {
@Getter
private Set<Point> blocks = new HashSet<>();
public ProcessingTracesState(List<TNTPosition> tntPositionList, World world, BiPredicate<Vector, Integer> inRegionCheck) {
this.tntPositionList = tntPositionList;
this.totalTNTPositions = tntPositionList.size();
this.totalCuboids = tntPositionList.stream().mapToInt(tntPosition -> tntPosition.getPreviousLocation() == null ? 1 : 3).sum();
this.world = world;
this.inRegionCheck = inRegionCheck;
}
@Override
public String actionBarMessage(Player p) {
return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_PROCESSING_TRACES", p), totalTNTPositions - tntPositionList.size(), totalTNTPositions, eta(p, start, totalTNTPositions - tntPositionList.size(), totalTNTPositions));
return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_PROCESSING_TRACES", p), totalCuboids - cuboidList.size(), totalCuboids, eta(p, start, totalCuboids - cuboidList.size(), totalCuboids));
}
@Override
public boolean hasNext() {
return !tntPositionList.isEmpty();
return !tntPositionList.isEmpty() || !toExpand.isEmpty();
}
@Override
public void next() {
TNTPosition tntPosition = tntPositionList.remove(0);
if (!toExpand.isEmpty()) {
Cuboid cuboid = toExpand.remove(0);
expandCuboid(cuboid);
} else {
TNTPosition tntPosition = tntPositionList.remove(0);
createCuboid(tntPosition);
}
}
private void createCuboid(TNTPosition tntPosition) {
Vector location = tntPosition.getLocation();
Vector previousLocation = tntPosition.getPreviousLocation();
if (previousLocation == null) {
cuboidList.add(new Cuboid(location.getX() - 0.49, location.getY(), location.getZ() - 0.49, 0.98, 0.98, 0.98));
toExpand.add(new Cuboid(location.getX() - 0.49, location.getY(), location.getZ() - 0.49, 0.98, 0.98, 0.98));
} else {
Vector movement = location.clone().subtract(previousLocation);
cuboidList.add(new Cuboid(previousLocation.getX() - 0.49, Math.min(previousLocation.getY(), location.getY()), previousLocation.getZ() - 0.49, 0.98, Math.abs(movement.getY()) + 0.98, 0.98));
toExpand.add(new Cuboid(previousLocation.getX() - 0.49, Math.min(previousLocation.getY(), location.getY()), previousLocation.getZ() - 0.49, 0.98, Math.abs(movement.getY()) + 0.98, 0.98));
if (Math.abs(tntPosition.getUpdateVelocity().getX()) >= Math.abs(tntPosition.getUpdateVelocity().getZ())) {
cuboidList.add(new Cuboid(Math.min(previousLocation.getX(), location.getX()) - 0.49, location.getY(), previousLocation.getZ() - 0.49, Math.abs(movement.getX()) + 0.98, 0.98, 0.98));
cuboidList.add(new Cuboid(location.getX() - 0.49, location.getY(), Math.min(previousLocation.getZ(), location.getZ()) - 0.49, 0.98, 0.98, Math.abs(movement.getZ()) + 0.98));
toExpand.add(new Cuboid(Math.min(previousLocation.getX(), location.getX()) - 0.49, location.getY(), previousLocation.getZ() - 0.49, Math.abs(movement.getX()) + 0.98, 0.98, 0.98));
toExpand.add(new Cuboid(location.getX() - 0.49, location.getY(), Math.min(previousLocation.getZ(), location.getZ()) - 0.49, 0.98, 0.98, Math.abs(movement.getZ()) + 0.98));
} else {
cuboidList.add(new Cuboid(previousLocation.getX() - 0.49, location.getY(), Math.min(previousLocation.getZ(), location.getZ()) - 0.49, 0.98, 0.98, Math.abs(movement.getZ()) + 0.98));
cuboidList.add(new Cuboid(Math.min(previousLocation.getX(), location.getX()) - 0.49, location.getY(), location.getZ() - 0.49, Math.abs(movement.getX()) + 0.98, 0.98, 0.98));
toExpand.add(new Cuboid(previousLocation.getX() - 0.49, location.getY(), Math.min(previousLocation.getZ(), location.getZ()) - 0.49, 0.98, 0.98, Math.abs(movement.getZ()) + 0.98));
toExpand.add(new Cuboid(Math.min(previousLocation.getX(), location.getX()) - 0.49, location.getY(), location.getZ() - 0.49, Math.abs(movement.getX()) + 0.98, 0.98, 0.98));
}
}
}
private void expandCuboid(Cuboid cuboid) {
cuboidList.add(cuboid);
for (double x = cuboid.getX() - 2; x < cuboid.getX() + cuboid.getDx() + 2; x++) {
for (double y = cuboid.getY() - 2; y < cuboid.getY() + cuboid.getDy() + 2; y++) {
for (double z = cuboid.getZ() - 2; z < cuboid.getZ() + cuboid.getDz() + 2; z++) {
Location location = new Location(world, x, y, z);
if (inRegionCheck.test(new Vector(location.getBlockX(), location.getBlockY(), location.getBlockZ()), 0)) {
Point point = new Point(location.getBlockX(), location.getBlockY(), location.getBlockZ());
blocks.add(point);
}
}
}
}
}

Datei anzeigen

@ -1,92 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.slaves.laufbau.states;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.region.Point;
import lombok.Getter;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class ShrinkingOuterPointsState implements LaufbauState {
private long start = System.currentTimeMillis();
private List<Point> outerPoints;
private List<Point> innerPoints;
private int index = 0;
@Getter
private List<Point> shrunkOuterPoints = new ArrayList<>();
public ShrinkingOuterPointsState(List<Point> outerPoints, List<Point> innerPoints) {
this.outerPoints = outerPoints;
this.innerPoints = innerPoints;
}
@Override
public String actionBarMessage(Player p) {
return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_SHRINKING_POINTS", p), index, outerPoints.size(), eta(p, start, index, outerPoints.size()));
}
@Override
public boolean hasNext() {
return index < outerPoints.size();
}
@Override
public void next() {
Point point = outerPoints.get(index);
index++;
Point p1 = new Point(point.getX() - 1, point.getY(), point.getZ());
if (innerPoints.contains(p1)) {
shrunkOuterPoints.add(point);
return;
}
Point p2 = new Point(point.getX() + 1, point.getY(), point.getZ());
if (innerPoints.contains(p2)) {
shrunkOuterPoints.add(point);
return;
}
Point p3 = new Point(point.getX(), point.getY() - 1, point.getZ());
if (innerPoints.contains(p3)) {
shrunkOuterPoints.add(point);
return;
}
Point p4 = new Point(point.getX(), point.getY() + 1, point.getZ());
if (innerPoints.contains(p4)) {
shrunkOuterPoints.add(point);
return;
}
Point p5 = new Point(point.getX(), point.getY(), point.getZ() - 1);
if (innerPoints.contains(p5)) {
shrunkOuterPoints.add(point);
return;
}
Point p6 = new Point(point.getX(), point.getY(), point.getZ() + 1);
if (innerPoints.contains(p6)) {
shrunkOuterPoints.add(point);
return;
}
}
}

Datei anzeigen

@ -1,89 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.slaves.laufbau.states;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.slaves.laufbau.Cuboid;
import de.steamwar.bausystem.region.Point;
import lombok.Getter;
import org.bukkit.entity.Player;
import java.util.*;
public class SplittingPointsState implements LaufbauState {
private static final Cuboid ONE = new Cuboid(0, 0, 0, 1, 1, 1);
private static final Cuboid ABOVE_HALF = new Cuboid(0, 1, 0, 1, 0.5, 1);
private long start = System.currentTimeMillis();
private List<Point> blocks;
private int totalBlocks;
private List<Cuboid> cuboidList;
@Getter
private List<Point> innerPoints = new ArrayList<>();
@Getter
private List<Point> outerPoints = new ArrayList<>();
@Getter
private Map<Point, List<Cuboid>> intersectedCuboid = new HashMap<>();
public SplittingPointsState(Set<Point> blocks, List<Cuboid> cuboidList) {
this.blocks = new ArrayList<>(blocks);
this.totalBlocks = blocks.size();
this.cuboidList = cuboidList;
}
@Override
public String actionBarMessage(Player p) {
return BauSystem.MESSAGE.parse("LAUFBAU_SIMPLE_PROGRESS", p, BauSystem.MESSAGE.parse("LAUFBAU_STATE_SPLITTING_POINTS", p), totalBlocks - blocks.size(), totalBlocks, eta(p, start, totalBlocks - blocks.size(), totalBlocks));
}
@Override
public boolean hasNext() {
return !blocks.isEmpty();
}
@Override
public void next() {
Point point = blocks.remove(0);
boolean isInCuboid = false;
Cuboid tempCuboid = ONE.add(point);
Cuboid aboveHalfTempCuboid = ABOVE_HALF.add(point);
List<Cuboid> intersectedCuboids = new ArrayList<>();
for (Cuboid cuboid : cuboidList) {
if (cuboid.intersects(tempCuboid)) {
isInCuboid = true;
intersectedCuboids.add(cuboid);
}
if (cuboid.intersects(aboveHalfTempCuboid)) {
intersectedCuboids.add(cuboid);
}
}
if (!isInCuboid) {
outerPoints.add(point);
} else {
innerPoints.add(point);
intersectedCuboid.put(point, intersectedCuboids);
}
}
}