SteamWar/BauSystem
Archiviert
13
0

Add TNTSimulator 0tick simulation capabilities

Dieser Commit ist enthalten in:
jojo 2021-01-20 23:42:04 +01:00
Ursprung 9373fe21f7
Commit cc929b88a7
2 geänderte Dateien mit 59 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -22,7 +22,6 @@
package de.steamwar.bausystem.cannonsimulator; package de.steamwar.bausystem.cannonsimulator;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.inventory.SWAnvilInv;
import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
import de.steamwar.inventory.SWListInv; import de.steamwar.inventory.SWListInv;
@ -34,6 +33,7 @@ import org.bukkit.util.Consumer;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
public class TNTSimulator { public class TNTSimulator {
@ -197,6 +197,12 @@ public class TNTSimulator {
editTNT(player, tntSpawn); editTNT(player, tntSpawn);
})); }));
// Repeater before Comparator
swInventory.setItem(4, new SWItem(tntSpawn.isComparator() ? Material.COMPARATOR : Material.REPEATER, "§7Gezündet durch §8- §e" + (tntSpawn.isComparator() ? "Comparator" : "Repeater"), clickType -> {
tntSpawn.setComparator(!tntSpawn.isComparator());
editTNT(player, tntSpawn);
}));
// Velocity Settings // Velocity Settings
swInventory.setItem(13, new SWItem(tntSpawn.isxVelocity() ? Material.LIME_CONCRETE : Material.RED_CONCRETE, "§7Start §eVelocity X §8- §7" + active(tntSpawn.isxVelocity()), clickType -> { swInventory.setItem(13, new SWItem(tntSpawn.isxVelocity() ? Material.LIME_CONCRETE : Material.RED_CONCRETE, "§7Start §eVelocity X §8- §7" + active(tntSpawn.isxVelocity()), clickType -> {
tntSpawn.setxVelocity(!tntSpawn.isxVelocity()); tntSpawn.setxVelocity(!tntSpawn.isxVelocity());
@ -310,10 +316,46 @@ public class TNTSimulator {
private Set<TNTSpawn> tntSpawns = new HashSet<>(); private Set<TNTSpawn> tntSpawns = new HashSet<>();
private static class TNTSpawnPair {
private int countLeft;
private TNTSpawn tntSpawn;
public TNTSpawnPair(int countLeft, TNTSpawn tntSpawn) {
this.countLeft = countLeft;
this.tntSpawn = tntSpawn;
}
private void spawn() {
tntSpawn.spawn();
countLeft--;
}
}
public void start() { public void start() {
Map<Integer, List<TNTSpawnPair>[]> tntSpawnMap = new HashMap<>();
tntSpawns.forEach(tntSpawn -> { tntSpawns.forEach(tntSpawn -> {
Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), tntSpawn::spawn, tntSpawn.getTickOffset() + 1L); tntSpawnMap.computeIfAbsent(tntSpawn.getTickOffset(), integer -> new ArrayList[]{new ArrayList<>(), new ArrayList<>()})[tntSpawn.isComparator() ? 1 : 0].add(new TNTSpawnPair(tntSpawn.getCount(), tntSpawn));
});
tntSpawnMap.forEach((integer, tntSpawnPairs) -> {
Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> {
spawnRandomList(tntSpawnPairs[0]);
spawnRandomList(tntSpawnPairs[1]);
}, integer + 1L);
}); });
} }
private void spawnRandomList(List<TNTSpawnPair> tntSpawnPairs) {
AtomicInteger index = new AtomicInteger(tntSpawnPairs.size() - 1);
while (!tntSpawnPairs.isEmpty()) {
TNTSpawnPair tntSpawnPair = tntSpawnPairs.get(index.get());
tntSpawnPair.spawn();
if (tntSpawnPair.countLeft <= 0) {
tntSpawnPairs.remove(index.get());
}
if (index.decrementAndGet() < 0) index.set(tntSpawnPairs.size() - 1);
}
}
} }

Datei anzeigen

@ -38,20 +38,19 @@ public class TNTSpawn implements Comparable<TNTSpawn> {
private boolean xVelocity = true; private boolean xVelocity = true;
private boolean yVelocity = true; private boolean yVelocity = true;
private boolean zVelocity = true; private boolean zVelocity = true;
private boolean comparator = false;
public TNTSpawn(Vector position) { public TNTSpawn(Vector position) {
this.position = position; this.position = position;
} }
public void spawn() { public void spawn() {
for (int i = 0; i < count; i++) { WORLD.spawn(position.toLocation(WORLD), TNTPrimed.class, tntPrimed -> {
WORLD.spawn(position.toLocation(WORLD), TNTPrimed.class, tntPrimed -> { tntPrimed.setFuseTicks(fuseTicks);
tntPrimed.setFuseTicks(fuseTicks); if (!xVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0));
if (!xVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0)); if (!yVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setY(0));
if (!yVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setY(0)); if (!zVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setZ(0));
if (!zVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setZ(0)); });
});
}
} }
public String getName() { public String getName() {
@ -118,6 +117,14 @@ public class TNTSpawn implements Comparable<TNTSpawn> {
this.zVelocity = zVelocity; this.zVelocity = zVelocity;
} }
public boolean isComparator() {
return comparator;
}
public void setComparator(boolean comparator) {
this.comparator = comparator;
}
@Override @Override
public int compareTo(TNTSpawn tntSpawn) { public int compareTo(TNTSpawn tntSpawn) {
return -Integer.compare(tickOffset, tntSpawn.tickOffset); return -Integer.compare(tickOffset, tntSpawn.tickOffset);