Fix Simulator19 Update many things for dynamic preview Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
6409748d32
Commit
6ebc9b1068
@ -49,14 +49,14 @@ public class AxisMovementLimiter {
|
||||
this.movement = movement;
|
||||
|
||||
// Calculate the min and max values for the movement
|
||||
minX = x;
|
||||
maxX = x + 0.98;
|
||||
minX = x - 0.49;
|
||||
maxX = x + 0.49;
|
||||
|
||||
minY = y;
|
||||
maxY = y + 0.98;
|
||||
|
||||
minZ = z;
|
||||
maxZ = z + 0.98;
|
||||
minZ = z - 0.49;
|
||||
maxZ = z + 0.49;
|
||||
|
||||
switch (axis) {
|
||||
case X:
|
||||
|
@ -61,6 +61,9 @@ public class Simulator19 implements Simulator {
|
||||
@Override
|
||||
public synchronized PreviewRecord run(Pair<Integer, Map<Integer, List<List<Pair<TNTData, Integer>>>>> toCalculate) {
|
||||
PreviewRecord previewRecord = new PreviewRecord();
|
||||
if (toCalculate == null) {
|
||||
return previewRecord;
|
||||
}
|
||||
int currentTick = 0;
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
@ -74,7 +77,7 @@ public class Simulator19 implements Simulator {
|
||||
pairs.forEach(pair -> {
|
||||
if (pair.getValue() > 0) {
|
||||
hasSomeLeft.set(true);
|
||||
TNT tnt = new TNT(pair.getKey().location.getX() - 0.49, pair.getKey().location.getY(), pair.getKey().location.getZ() - 0.49);
|
||||
TNT tnt = new TNT(pair.getKey().location.getX(), pair.getKey().location.getY(), pair.getKey().location.getZ());
|
||||
if (!pair.getKey().xVelocity) tnt.setVx(0.0);
|
||||
if (!pair.getKey().yVelocity) tnt.setVy(0.0);
|
||||
if (!pair.getKey().zVelocity) tnt.setVz(0.0);
|
||||
@ -97,7 +100,6 @@ public class Simulator19 implements Simulator {
|
||||
}
|
||||
tntList.removeAll(remove);
|
||||
}
|
||||
System.out.println(AIR_BLOCKS);
|
||||
AIR_BLOCKS.forEach(pos -> previewRecord.addAir(new Vector(pos.x, pos.y, pos.z)));
|
||||
System.out.println("Time: " + (System.currentTimeMillis() - time) + "ms " + cacheMisses + "/" + accessed + "/" + aired);
|
||||
|
||||
|
@ -44,7 +44,7 @@ public class SimulatorCursor {
|
||||
private Map<Player, REntityServer> rEntityServerMap = new HashMap<>();
|
||||
|
||||
public void show(Player player, TNTSimulator tntSimulator, RayTraceUtils.RRayTraceResult result) {
|
||||
REntityServer cursor = rEntityServerMap.get(player);
|
||||
REntityServer cursor = rEntityServerMap.remove(player);
|
||||
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
@ -140,4 +140,8 @@ public class SimulatorCursor {
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
public boolean has(Player player) {
|
||||
return rEntityServerMap.containsKey(player);
|
||||
}
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ public class SimulatorStorage implements Enable, Disable {
|
||||
if (content.isEmpty()) continue;
|
||||
TNTSimulator tntSimulator = new TNTSimulator();
|
||||
for (YAPIONObject element : content.streamObject().collect(Collectors.toList())) {
|
||||
tntSimulator.getTntElementList().add(new TNTElement(element, null, tntSimulator.getEntityServer()));
|
||||
tntSimulator.getTntElementList().add(new TNTElement(element, tntSimulator, null, tntSimulator.getEntityServer()));
|
||||
}
|
||||
tntSimulators.put(newName, tntSimulator);
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.configplayer.Config;
|
||||
import de.steamwar.bausystem.features.simulator.gui.TNTElementGUI;
|
||||
import de.steamwar.bausystem.features.simulator.gui.TNTSimulatorGui;
|
||||
import de.steamwar.bausystem.features.simulator.preview.PreviewRecord;
|
||||
import de.steamwar.bausystem.features.simulator.preview.Simulator;
|
||||
import de.steamwar.bausystem.features.simulator.tnt.SimulatorElement;
|
||||
import de.steamwar.bausystem.features.simulator.tnt.TNTElement;
|
||||
import de.steamwar.bausystem.features.simulator.tnt.TNTGroup;
|
||||
@ -34,7 +36,6 @@ import de.steamwar.bausystem.utils.RayTraceUtils;
|
||||
import de.steamwar.entity.REntity;
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
@ -57,8 +58,9 @@ public class TNTSimulator {
|
||||
|
||||
private List<SimulatorElement> tntElementList = new ArrayList<>();
|
||||
|
||||
public TNTSimulator() {
|
||||
private PreviewRecord previewRecord = null;
|
||||
|
||||
public TNTSimulator() {
|
||||
}
|
||||
|
||||
public TNTSimulator(YAPIONObject yapionObject) {
|
||||
@ -66,9 +68,9 @@ public class TNTSimulator {
|
||||
YAPIONArray yapionArray = yapionObject.getArrayOrDefault("tntElements", new YAPIONArray());
|
||||
for (YAPIONObject element : yapionArray.streamObject().collect(Collectors.toList())) {
|
||||
if (element.containsKey("elements", YAPIONType.ARRAY)) {
|
||||
tntElementList.add(new TNTGroup(element, entityServer));
|
||||
tntElementList.add(new TNTGroup(element, this, entityServer));
|
||||
} else {
|
||||
tntElementList.add(new TNTElement(element, null, entityServer));
|
||||
tntElementList.add(new TNTElement(element, this, null, entityServer));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -100,10 +102,39 @@ public class TNTSimulator {
|
||||
entityServer.removePlayer(player);
|
||||
players.remove(player);
|
||||
}
|
||||
hidePreview(player);
|
||||
}
|
||||
|
||||
void _hide(Player player) {
|
||||
players.remove(player);
|
||||
public void showPreview(Player player) {
|
||||
if (previewRecord == null) {
|
||||
calcPreview(true);
|
||||
}
|
||||
if (previewRecord != null) {
|
||||
previewRecord.show(player);
|
||||
}
|
||||
}
|
||||
|
||||
public void hidePreview(Player player) {
|
||||
if (previewRecord != null && previewRecord.hide(player)) {
|
||||
previewRecord = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void calcPreview(boolean force) {
|
||||
if (!force && previewRecord == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
PreviewRecord newRecord = Simulator.impl.run(locations());
|
||||
PreviewRecord oldRecord = previewRecord;
|
||||
previewRecord = newRecord;
|
||||
if (newRecord == null) return;
|
||||
if (oldRecord != null) {
|
||||
new HashSet<>(oldRecord.getPlayers()).forEach(player -> {
|
||||
oldRecord.hide(player);
|
||||
newRecord.show(player);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public List<REntity> getEntities() {
|
||||
@ -120,6 +151,7 @@ public class TNTSimulator {
|
||||
|
||||
public void clear() {
|
||||
new ArrayList<>(tntElementList).forEach(this::remove);
|
||||
calcPreview(false);
|
||||
}
|
||||
|
||||
public void remove(SimulatorElement element) {
|
||||
@ -142,6 +174,7 @@ public class TNTSimulator {
|
||||
}
|
||||
element.close();
|
||||
tntElementList.remove(element);
|
||||
calcPreview(false);
|
||||
}
|
||||
|
||||
public void change() {
|
||||
@ -151,6 +184,7 @@ public class TNTSimulator {
|
||||
((TNTGroup) simulatorElement).getElements().forEach(SimulatorElement::change);
|
||||
}
|
||||
});
|
||||
calcPreview(false);
|
||||
}
|
||||
|
||||
public void edit(Player player, RayTraceUtils.RRayTraceResult result) {
|
||||
@ -200,16 +234,15 @@ public class TNTSimulator {
|
||||
return;
|
||||
}
|
||||
|
||||
TNTElement tntElement = new TNTElement(SimulatorCursor.getPos(player, result), null, entityServer);
|
||||
TNTElement tntElement = new TNTElement(this, SimulatorCursor.getPos(player, result), null, entityServer);
|
||||
tntElementList.add(tntElement);
|
||||
TNTElementGUI.open(player, tntElement, null);
|
||||
}
|
||||
|
||||
public Pair<Integer, Map<Integer, List<List<Pair<TNTData, Integer>>>>> locations(Player p) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
public Pair<Integer, Map<Integer, List<List<Pair<TNTData, Integer>>>>> locations() {
|
||||
Map<Integer, Map<Integer, Set<Pair<TNTData, Integer>>>> result = new HashMap<>();
|
||||
for (SimulatorElement element : tntElementList) {
|
||||
if (element.locations(result, region, p.getLocation())) {
|
||||
if (element.locations(result)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -234,7 +267,7 @@ public class TNTSimulator {
|
||||
|
||||
public void start(Player p) {
|
||||
Region region = Region.getRegion(p.getLocation());
|
||||
Pair<Integer, Map<Integer, List<List<Pair<TNTData, Integer>>>>> result = locations(p);
|
||||
Pair<Integer, Map<Integer, List<List<Pair<TNTData, Integer>>>>> result = locations();
|
||||
if (result == null) {
|
||||
BauSystem.MESSAGE.send("SIMULATOR_REGION_FROZEN", p);
|
||||
return;
|
||||
|
@ -28,23 +28,24 @@ import de.steamwar.bausystem.shared.Pair;
|
||||
import de.steamwar.bausystem.utils.ItemUtils;
|
||||
import de.steamwar.bausystem.utils.RayTraceUtils;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Linked
|
||||
public class TNTSimulatorListener implements Listener {
|
||||
|
||||
private Map<Player, PreviewRecord> previewRecordMap = new HashMap<>();
|
||||
private Map<Player, TNTSimulator> currentSimulator = new HashMap<>();
|
||||
|
||||
private boolean permissionCheck(Player player) {
|
||||
@ -55,114 +56,125 @@ public class TNTSimulatorListener implements Listener {
|
||||
return true;
|
||||
}
|
||||
|
||||
private Pair<TNTSimulator, Boolean> getSimulator(Player player) {
|
||||
if (ItemUtils.isItem(player.getInventory().getItemInOffHand(), "simulator")) {
|
||||
return new Pair<>(SimulatorStorage.getSimulator(player.getInventory().getItemInOffHand()), true);
|
||||
private Pair<TNTSimulator, Boolean> getSimulator(ItemStack offHand, ItemStack mainHand) {
|
||||
if (ItemUtils.isItem(offHand, "simulator")) {
|
||||
return new Pair<>(SimulatorStorage.getSimulator(offHand), true);
|
||||
}
|
||||
if (ItemUtils.isItem(player.getInventory().getItemInMainHand(), "simulator")) {
|
||||
return new Pair<>(SimulatorStorage.getSimulator(player.getInventory().getItemInMainHand()), false);
|
||||
if (ItemUtils.isItem(mainHand, "simulator")) {
|
||||
return new Pair<>(SimulatorStorage.getSimulator(mainHand), false);
|
||||
}
|
||||
return new Pair<>(null, false);
|
||||
}
|
||||
|
||||
private Pair<TNTSimulator, Boolean> getSimulator(Player player) {
|
||||
return getSimulator(player.getInventory().getItemInOffHand(), player.getInventory().getItemInMainHand());
|
||||
}
|
||||
|
||||
static RayTraceUtils.RRayTraceResult trace(Player player, Location to, TNTSimulator simulator) {
|
||||
return RayTraceUtils.traceREntity(player, to, simulator.getEntities());
|
||||
}
|
||||
|
||||
private void hideShow(Player player, TNTSimulator simulator) {
|
||||
private void hideShow(Player player, Pair<TNTSimulator, Boolean> simulatorPair) {
|
||||
TNTSimulator simulator = simulatorPair.getKey();
|
||||
TNTSimulator tntSimulator = currentSimulator.remove(player);
|
||||
if (tntSimulator == simulator) return;
|
||||
if (tntSimulator != null) tntSimulator.hide(player);
|
||||
if (simulator != null) {
|
||||
if (simulator == null) return;
|
||||
currentSimulator.put(player, simulator);
|
||||
simulator.show(player);
|
||||
SimulatorCursor.show(player, simulator, trace(player, player.getLocation(), simulator));
|
||||
if (simulatorPair.getValue()) {
|
||||
simulator.showPreview(player);
|
||||
} else {
|
||||
simulator.hidePreview(player);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent e) {
|
||||
Pair<TNTSimulator, Boolean> simulatorPair = getSimulator(e.getPlayer());
|
||||
hideShow(e.getPlayer(), simulatorPair.getKey());
|
||||
hideShow(e.getPlayer(), simulatorPair);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerItemHeld(PlayerItemHeldEvent e) {
|
||||
Pair<TNTSimulator, Boolean> simulatorPair = getSimulator(e.getPlayer());
|
||||
hideShow(e.getPlayer(), simulatorPair.getKey());
|
||||
Pair<TNTSimulator, Boolean> simulatorPair = getSimulator(e.getPlayer().getInventory().getItemInOffHand(), e.getPlayer().getInventory().getItem(e.getNewSlot()));
|
||||
hideShow(e.getPlayer(), simulatorPair);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDropItem(PlayerDropItemEvent e) {
|
||||
Pair<TNTSimulator, Boolean> simulatorPair = getSimulator(e.getPlayer());
|
||||
hideShow(e.getPlayer(), simulatorPair.getKey());
|
||||
Pair<TNTSimulator, Boolean> simulatorPair = getSimulator(e.getPlayer().getInventory().getItemInOffHand(), new ItemStack(Material.AIR));
|
||||
hideShow(e.getPlayer(), simulatorPair);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||
Pair<TNTSimulator, Boolean> simulatorPair = getSimulator(e.getPlayer());
|
||||
hideShow(e.getPlayer(), simulatorPair.getKey());
|
||||
hideShow(e.getPlayer(), simulatorPair);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||
hideShow(e.getPlayer(), null);
|
||||
hideShow(e.getPlayer(), new Pair<>(null, false));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent e) {
|
||||
Pair<TNTSimulator, Boolean> simulatorPair = getSimulator(e.getPlayer());
|
||||
hideShow(e.getPlayer(), simulatorPair.getKey());
|
||||
|
||||
if (!simulatorPair.getValue()) return;
|
||||
|
||||
TNTSimulator simulator = SimulatorStorage.getSimulator(e.getOffHandItem());
|
||||
if (preview(e.getPlayer(), simulator)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean preview(Player player, TNTSimulator simulator) {
|
||||
if (simulator == null) return false;
|
||||
Pair<Integer, Map<Integer, List<List<Pair<TNTData, Integer>>>>> toCalculate = simulator.locations(player);
|
||||
PreviewRecord previewRecord = Simulator.impl.run(toCalculate);
|
||||
if (previewRecord == null) {
|
||||
return true;
|
||||
}
|
||||
previewRecord.add(player);
|
||||
previewRecordMap.put(player, previewRecord);
|
||||
return false;
|
||||
Pair<TNTSimulator, Boolean> simulatorPair = getSimulator(e.getOffHandItem(), e.getMainHandItem());
|
||||
hideShow(e.getPlayer(), simulatorPair);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (!ItemUtils.isItem(event.getItem(), "simulator")) {
|
||||
public void onPlayerInteract(PlayerInteractEvent e) {
|
||||
if (!ItemUtils.isItem(e.getItem(), "simulator")) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
if (!permissionCheck(event.getPlayer())) {
|
||||
Pair<TNTSimulator, Boolean> simulatorPair = getSimulator(e.getPlayer());
|
||||
if (!SimulatorCursor.has(e.getPlayer()) && simulatorPair.getValue()) {
|
||||
return;
|
||||
}
|
||||
TNTSimulator simulator = SimulatorStorage.getSimulator(event.getItem());
|
||||
e.setCancelled(true);
|
||||
if (!permissionCheck(e.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
TNTSimulator simulator = simulatorPair.getKey();
|
||||
|
||||
switch (event.getAction()) {
|
||||
switch (e.getAction()) {
|
||||
case LEFT_CLICK_BLOCK:
|
||||
case LEFT_CLICK_AIR:
|
||||
if (simulator == null) {
|
||||
if (simulator == null || simulatorPair.getValue()) {
|
||||
return;
|
||||
}
|
||||
simulator.start(event.getPlayer());
|
||||
simulator.start(e.getPlayer());
|
||||
break;
|
||||
case RIGHT_CLICK_BLOCK:
|
||||
case RIGHT_CLICK_AIR:
|
||||
if (simulator == null) {
|
||||
SimulatorSelectionGUI.open(event.getPlayer(), event.getItem());
|
||||
SimulatorSelectionGUI.open(e.getPlayer(), e.getItem());
|
||||
} else {
|
||||
simulator.edit(event.getPlayer(), trace(event.getPlayer(), event.getPlayer().getLocation(), simulator));
|
||||
simulator.edit(e.getPlayer(), trace(e.getPlayer(), e.getPlayer().getLocation(), simulator));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event) { // TODO: Optimize this
|
||||
currentSimulator.values().forEach(simulator -> {
|
||||
simulator.calcPreview(false);
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event) { // TODO: Optimize this
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||
currentSimulator.values().forEach(simulator -> {
|
||||
simulator.calcPreview(false);
|
||||
});
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
@ -310,7 +310,7 @@ public class TNTElementGUI {
|
||||
tntSimulator.getTntElementList().remove(tntElement);
|
||||
Vector vector = tntElement.getOwnPosition().clone();
|
||||
int tickOffset = tntElement.getOwnTickOffset();
|
||||
TNTGroup tntGroup = new TNTGroup(vector);
|
||||
TNTGroup tntGroup = new TNTGroup(tntSimulator, vector);
|
||||
tntGroup.setTickOffset(tickOffset);
|
||||
tntGroup.add(tntElement);
|
||||
tntElement.setTickOffset(0);
|
||||
@ -318,7 +318,7 @@ public class TNTElementGUI {
|
||||
tntSimulator.getTntElementList().add(tntGroup);
|
||||
|
||||
// Add new TNT
|
||||
TNTElement newElement = new TNTElement(new Vector(0, 0, 0), tntGroup, tntSimulator.getEntityServer());
|
||||
TNTElement newElement = new TNTElement(tntSimulator, new Vector(0, 0, 0), tntGroup, tntSimulator.getEntityServer());
|
||||
newElement.setTickOffset(1);
|
||||
tntGroup.add(newElement);
|
||||
|
||||
@ -334,7 +334,7 @@ public class TNTElementGUI {
|
||||
inv.setItem(25, new SWItem(Material.DISPENSER, BauSystem.MESSAGE.parse("SIMULATOR_TNT_SPAWN_ADD_TNT", player), clickType -> {
|
||||
if (clickType == ClickType.DOUBLE_CLICK) return;
|
||||
Vector vector = tntElement.getOwnPosition().clone();
|
||||
TNTElement newElement = new TNTElement(vector, null, tntSimulator.getEntityServer());
|
||||
TNTElement newElement = new TNTElement(tntSimulator, vector, null, tntSimulator.getEntityServer());
|
||||
if (tntElement.hasParent()) {
|
||||
newElement.setTickOffset(tntElement.getOwnTickOffset() + 1);
|
||||
tntElement.getParent().add(newElement);
|
||||
|
@ -21,8 +21,11 @@ package de.steamwar.bausystem.features.simulator.preview;
|
||||
|
||||
import de.steamwar.entity.REntityServer;
|
||||
import de.steamwar.entity.RFallingBlockEntity;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
@ -32,43 +35,45 @@ import java.util.Set;
|
||||
|
||||
public class PreviewRecord {
|
||||
|
||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
||||
private static final BlockData AIR_BLOCK_DATA = Material.AIR.createBlockData();
|
||||
|
||||
private Set<Vector> vectorList = new HashSet<>();
|
||||
private Set<Vector> destroyedBlocks = new HashSet<>();
|
||||
private REntityServer rEntityServer;
|
||||
|
||||
@Getter
|
||||
private Set<Player> players = new HashSet<>();
|
||||
private REntityServer rEntityServer = new REntityServer();
|
||||
|
||||
public void add(double x, double y, double z) {
|
||||
vectorList.add(new Vector(x + 0.49, y, z + 0.49));
|
||||
Vector vector = new Vector(x, y, z);
|
||||
if (vectorList.add(vector)) {
|
||||
RFallingBlockEntity entity = new RFallingBlockEntity(rEntityServer, vector.toLocation(WORLD), Material.RED_STAINED_GLASS);
|
||||
entity.setNoGravity(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void addAir(Vector destroyed) {
|
||||
destroyedBlocks.add(destroyed);
|
||||
}
|
||||
|
||||
public void add(Player player) {
|
||||
if (rEntityServer == null) {
|
||||
rEntityServer = new REntityServer();
|
||||
|
||||
vectorList.forEach(vector -> {
|
||||
RFallingBlockEntity entity = new RFallingBlockEntity(rEntityServer, vector.toLocation(player.getWorld()), Material.RED_STAINED_GLASS);
|
||||
entity.setNoGravity(true);
|
||||
});
|
||||
}
|
||||
public void show(Player player) {
|
||||
if (players.add(player)) {
|
||||
rEntityServer.addPlayer(player);
|
||||
|
||||
destroyedBlocks.forEach(vector -> {
|
||||
player.sendBlockChange(vector.toLocation(player.getWorld()), AIR_BLOCK_DATA);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void close(Player player) {
|
||||
rEntityServer.close();
|
||||
rEntityServer = null;
|
||||
|
||||
public boolean hide(Player player) {
|
||||
if (players.remove(player)) {
|
||||
rEntityServer.removePlayer(player);
|
||||
destroyedBlocks.forEach(vector -> {
|
||||
Location location = vector.toLocation(player.getWorld());
|
||||
player.sendBlockChange(location, location.getBlock().getBlockData());
|
||||
});
|
||||
}
|
||||
return players.isEmpty();
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public interface SimulatorElement {
|
||||
void remove(TNTElement tntElement);
|
||||
|
||||
SWItem menu(Player p);
|
||||
boolean locations(Map<Integer, Map<Integer, Set<Pair<TNTData, Integer>>>> result, Region region, Location location); // Ticks to subtick order to spawning runnable to count of activations
|
||||
boolean locations(Map<Integer, Map<Integer, Set<Pair<TNTData, Integer>>>> result); // Ticks to subtick order to spawning runnable to count of activations
|
||||
int tntCount();
|
||||
int tick();
|
||||
|
||||
|
@ -23,6 +23,7 @@ import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.simulator.OrderUtils;
|
||||
import de.steamwar.bausystem.features.simulator.SimulatorStorage;
|
||||
import de.steamwar.bausystem.features.simulator.TNTData;
|
||||
import de.steamwar.bausystem.features.simulator.TNTSimulator;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.region.flags.Flag;
|
||||
import de.steamwar.bausystem.region.flags.flagvalues.FreezeMode;
|
||||
@ -55,6 +56,7 @@ public class TNTElement implements SimulatorElement {
|
||||
private RFallingBlockEntity entity;
|
||||
TNTGroup tntGroup = null;
|
||||
|
||||
private final TNTSimulator tntSimulator;
|
||||
private final Vector position;
|
||||
private int fuseTicks = 80;
|
||||
private int count = 1;
|
||||
@ -72,14 +74,16 @@ public class TNTElement implements SimulatorElement {
|
||||
private Material material = Material.TNT;
|
||||
private boolean disabled = false;
|
||||
|
||||
public TNTElement(Vector position, TNTGroup tntGroup, REntityServer entityServer) {
|
||||
public TNTElement(TNTSimulator tntSimulator, Vector position, TNTGroup tntGroup, REntityServer entityServer) {
|
||||
this.tntSimulator = tntSimulator;
|
||||
this.entityServer = entityServer;
|
||||
this.tntGroup = tntGroup;
|
||||
this.position = position;
|
||||
initEntity();
|
||||
}
|
||||
|
||||
public TNTElement(YAPIONObject yapionObject, TNTGroup tntGroup, REntityServer entityServer) {
|
||||
public TNTElement(YAPIONObject yapionObject, TNTSimulator tntSimulator, TNTGroup tntGroup, REntityServer entityServer) {
|
||||
this.tntSimulator = tntSimulator;
|
||||
this.entityServer = entityServer;
|
||||
this.tntGroup = tntGroup;
|
||||
this.position = new Vector(yapionObject.getDoubleOrDefault("x", yapionObject.getDoubleOrDefault("positionX", 0)), yapionObject.getDoubleOrDefault("y", yapionObject.getDoubleOrDefault("positionY", 0)), yapionObject.getDoubleOrDefault("z", yapionObject.getDoubleOrDefault("positionZ", 0)));
|
||||
@ -147,6 +151,7 @@ public class TNTElement implements SimulatorElement {
|
||||
this.position.setY(position.getY());
|
||||
this.position.setZ(position.getZ());
|
||||
_updatePosition();
|
||||
tntSimulator.calcPreview(false);
|
||||
}
|
||||
|
||||
void _updatePosition() {
|
||||
@ -168,6 +173,7 @@ public class TNTElement implements SimulatorElement {
|
||||
@Override
|
||||
public void remove(TNTElement tntElement) {
|
||||
entity.die();
|
||||
tntSimulator.calcPreview(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -190,15 +196,9 @@ public class TNTElement implements SimulatorElement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean locations(Map<Integer, Map<Integer, Set<Pair<TNTData, Integer>>>> result, Region region, Location radius) {
|
||||
public boolean locations(Map<Integer, Map<Integer, Set<Pair<TNTData, Integer>>>> result) {
|
||||
if (disabled) return false;
|
||||
Location location = getPosition().toLocation(SimulatorStorage.WORLD);
|
||||
if (region.isGlobal() && location.distanceSquared(radius) > 10000) {
|
||||
return false;
|
||||
}
|
||||
if (!region.inRegion(location, RegionType.NORMAL, RegionExtensionType.NORMAL)) {
|
||||
return false;
|
||||
}
|
||||
Region thisRegion = Region.getRegion(location);
|
||||
if (thisRegion.getFlagStorage().get(Flag.FREEZE) == FreezeMode.ACTIVE) {
|
||||
return true;
|
||||
@ -224,6 +224,7 @@ public class TNTElement implements SimulatorElement {
|
||||
if (count < 0) count = 0;
|
||||
if (count > 400) count = 400;
|
||||
this.count = count;
|
||||
tntSimulator.calcPreview(false);
|
||||
}
|
||||
|
||||
public int getOwnTickOffset() {
|
||||
@ -240,19 +241,23 @@ public class TNTElement implements SimulatorElement {
|
||||
public void setTickOffset(int tickOffset) {
|
||||
if (getTickOffset() - this.tickOffset + tickOffset < 0) {
|
||||
this.tickOffset = -this.getParentTickOffset();
|
||||
tntSimulator.calcPreview(false);
|
||||
return;
|
||||
}
|
||||
if (getTickOffset() - this.tickOffset + tickOffset > 400) {
|
||||
this.tickOffset = 400 - this.getParentTickOffset();
|
||||
tntSimulator.calcPreview(false);
|
||||
return;
|
||||
}
|
||||
this.tickOffset = tickOffset;
|
||||
tntSimulator.calcPreview(false);
|
||||
}
|
||||
|
||||
public void setFuseTicks(int fuseTicks) {
|
||||
if (fuseTicks < 0) fuseTicks = 0;
|
||||
if (fuseTicks > 160) fuseTicks = 160;
|
||||
this.fuseTicks = fuseTicks;
|
||||
tntSimulator.calcPreview(false);
|
||||
}
|
||||
|
||||
public Vector getOwnPosition() {
|
||||
@ -261,6 +266,7 @@ public class TNTElement implements SimulatorElement {
|
||||
|
||||
public void setOrder(Material material) {
|
||||
this.order = material;
|
||||
tntSimulator.calcPreview(false);
|
||||
}
|
||||
|
||||
public void setMaterial(Material material) {
|
||||
@ -278,6 +284,7 @@ public class TNTElement implements SimulatorElement {
|
||||
public void setDisabled(boolean disabled) {
|
||||
this.disabled = disabled;
|
||||
_updatePosition();
|
||||
tntSimulator.calcPreview(false);
|
||||
}
|
||||
|
||||
public void align(Vector offset) {
|
||||
|
@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.simulator.tnt;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.simulator.TNTData;
|
||||
import de.steamwar.bausystem.features.simulator.TNTSimulator;
|
||||
import de.steamwar.bausystem.region.Region;
|
||||
import de.steamwar.bausystem.shared.Pair;
|
||||
import de.steamwar.entity.REntity;
|
||||
@ -43,24 +44,27 @@ import java.util.stream.Collectors;
|
||||
@Getter
|
||||
public class TNTGroup implements SimulatorElement {
|
||||
|
||||
private final TNTSimulator tntSimulator;
|
||||
private final Vector position;
|
||||
private int tickOffset = 0;
|
||||
private Material material = Material.BARREL;
|
||||
private boolean disabled = false;
|
||||
private List<TNTElement> elements = new ArrayList<>();
|
||||
|
||||
public TNTGroup(Vector position) {
|
||||
public TNTGroup(TNTSimulator tntSimulator, Vector position) {
|
||||
this.tntSimulator = tntSimulator;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public TNTGroup(YAPIONObject yapionObject, REntityServer entityServer) {
|
||||
public TNTGroup(YAPIONObject yapionObject, TNTSimulator tntSimulator, REntityServer entityServer) {
|
||||
this.tntSimulator = tntSimulator;
|
||||
this.position = new Vector(yapionObject.getDoubleOrDefault("x", 0), yapionObject.getDoubleOrDefault("y", 0), yapionObject.getDoubleOrDefault("z", 0));
|
||||
this.tickOffset = yapionObject.getIntOrDefault("tickOffset", 0);
|
||||
this.material = Material.getMaterial(yapionObject.getStringOrDefault("material", "BARREL"));
|
||||
this.disabled = yapionObject.getBooleanOrDefault("disabled", false);
|
||||
YAPIONArray elements = yapionObject.getArrayOrDefault("elements", new YAPIONArray());
|
||||
for (YAPIONObject element : elements.streamObject().collect(Collectors.toList())) {
|
||||
TNTElement tntElement = new TNTElement(element, this, entityServer);
|
||||
TNTElement tntElement = new TNTElement(element, tntSimulator, this, entityServer);
|
||||
this.elements.add(tntElement);
|
||||
tntElement._updatePosition();
|
||||
}
|
||||
@ -86,6 +90,7 @@ public class TNTGroup implements SimulatorElement {
|
||||
public void add(TNTElement tntElement) {
|
||||
tntElement.tntGroup = this;
|
||||
elements.add(tntElement);
|
||||
tntSimulator.calcPreview(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -113,6 +118,7 @@ public class TNTGroup implements SimulatorElement {
|
||||
this.position.setY(position.getY());
|
||||
this.position.setZ(position.getZ());
|
||||
elements.forEach(TNTElement::_updatePosition);
|
||||
tntSimulator.calcPreview(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -141,10 +147,10 @@ public class TNTGroup implements SimulatorElement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean locations(Map<Integer, Map<Integer, Set<Pair<TNTData, Integer>>>> result, Region region, Location location) {
|
||||
public boolean locations(Map<Integer, Map<Integer, Set<Pair<TNTData, Integer>>>> result) {
|
||||
if (disabled) return false;
|
||||
for (TNTElement element : elements) {
|
||||
if (element.locations(result, region, location)) {
|
||||
if (element.locations(result)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -174,6 +180,7 @@ public class TNTGroup implements SimulatorElement {
|
||||
}
|
||||
}
|
||||
this.tickOffset = tickOffset;
|
||||
tntSimulator.calcPreview(false);
|
||||
}
|
||||
|
||||
public void setMaterial(Material material) {
|
||||
@ -183,5 +190,6 @@ public class TNTGroup implements SimulatorElement {
|
||||
public void setDisabled(boolean disabled) {
|
||||
this.disabled = disabled;
|
||||
elements.forEach(TNTElement::_updatePosition);
|
||||
tntSimulator.calcPreview(false);
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren