Merge branch 'main' into Schematics/1.21

# Conflicts:
#	VelocityCore/build.gradle.kts
This commit is contained in:
2024-12-21 19:29:46 +01:00
77 changed files with 990 additions and 780 deletions
@@ -83,7 +83,7 @@ public class Permanent implements Listener {
@EventHandler
public void onTpGM3(PlayerTeleportEvent e) {
if (e.getCause() == PlayerTeleportEvent.TeleportCause.SPECTATE) {
if (ArenaMode.AntiTest.contains(Config.mode) && e.getCause() == PlayerTeleportEvent.TeleportCause.SPECTATE) {
e.setCancelled(true);
FightSystem.getMessage().sendPrefixless("NO_TELEPORT", e.getPlayer(), ChatMessageType.ACTION_BAR);
e.getPlayer().kickPlayer(null);
@@ -26,6 +26,7 @@ import de.steamwar.core.WorldEditWrapper;
import de.steamwar.entity.REntity;
import de.steamwar.entity.REntityServer;
import de.steamwar.entity.RPlayer;
import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.countdown.Countdown;
@@ -244,6 +245,9 @@ public class PacketProcessor implements Listener {
SteamwarUser user = SteamwarUser.get(userId);
addREntity(entityId, new RPlayer(entityServer, user.getUUID(), user.getUserName(), Config.SpecSpawn));
team.addEntry(user.getUserName());
if(ArenaMode.Test.contains(Config.mode))
entities.get(entityId).setGlowing(true);
});
}
@@ -25,6 +25,7 @@ import de.steamwar.fightsystem.FightSystem;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
public interface BlockIdWrapper {
@@ -41,6 +42,6 @@ public interface BlockIdWrapper {
int blockToId(Block block);
void setBlock(World world, int x, int y, int z, int blockState);
void trackEntity(Player player, int entity);
void untrackEntity(Player player, int entity);
void trackEntity(Player player, Entity entity);
void untrackEntity(Player player, Entity entity);
}
@@ -35,24 +35,28 @@ import org.bukkit.entity.Player;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.logging.Level;
import java.util.stream.IntStream;
public class Hull {
private static final IntVector[] NO_BRANCHES = new IntVector[0];
private static boolean isOccluding(Material material) {
return material.isOccluding() || Config.HiddenBlocks.contains(material);
}
private final Region region;
private final boolean groundVisible;
private final IntVector[] directions;
private final BitSet occluding;
private final BitSet visibility;
private final Map<IntVector, Map<IntVector, BitSet>> blockVisibility = new HashMap<>();
private final Set<IntVector> uncoveredSurface = new HashSet<>();
private final HashMap<IntVector, BitSet> visibilityDirections = new HashMap<>(); // Contains the visible directions of each occluding visible block
private final HashSet<IntVector> uncoveredSurface = new HashSet<>();
private final HashSet<Player> players = new HashSet<>();
private final Set<Entity> entities = new HashSet<>();
private final Set<REntity> rentities = new HashSet<>();
private final HashSet<Entity> entities = new HashSet<>();
private final HashSet<REntity> rentities = new HashSet<>();
public Hull(FightTeam team) {
this.region = team.getSchemRegion();
@@ -60,38 +64,14 @@ public class Hull {
this.occluding = new BitSet(region.volume());
this.visibility = new BitSet(region.volume());
IntVector[] directions;
if (groundVisible) {
directions = new IntVector[]{
new IntVector(1, 0, 0),
new IntVector(-1, 0, 0),
new IntVector(0, 1, 0),
new IntVector(0, -1, 0),
new IntVector(0, 0, 1),
new IntVector(0, 0, -1)
};
} else {
directions = new IntVector[]{
new IntVector(1, 0, 0),
new IntVector(-1, 0, 0),
new IntVector(0, -1, 0),
new IntVector(0, 0, 1),
new IntVector(0, 0, -1)
};
}
IntVector primaryDirection = new IntVector(0, 0, team.isBlue() == (Config.BlueToRedZ > 0) ? -1 : 1);
directions = IntStream.range(0, 27)
.mapToObj(v -> new IntVector(v%3 -1, (v/3)%3 -1, v/9 -1))
.filter(v -> v.sqLength() == 1 || v.x*primaryDirection.x + v.y*primaryDirection.y + v.z*primaryDirection.z == 1) // Not pointing away from primary direction
.toArray(IntVector[]::new);
// Generate quadrants for each direction
for (IntVector direction : directions) {
Map<IntVector, BitSet> map = new HashMap<>();
for (int z = (direction.z == 0 ? -1 : 0); z <= 1; z += 2) {
for (int y = (direction.y == 0 ? -1 : 0); y <= 1; y += 2) {
for (int x = (direction.x == 0 ? -1 : 0); x <= 1; x += 2) {
map.put(new IntVector(x, y, z), new BitSet(region.volume()));
}
}
}
blockVisibility.put(direction, map);
}
for(IntVector direction : directions)
visibilityDirections.put(direction, new BitSet(region.volume()));
}
public boolean blockPrecise(Player player, int chunkX, int chunkY, int chunkZ) {
@@ -109,29 +89,29 @@ public class Hull {
public void addPlayer(Player player) {
if(players.add(player)) {
for(Entity entity : entities)
BlockIdWrapper.impl.untrackEntity(player, entity.getEntityId());
BlockIdWrapper.impl.untrackEntity(player, entity);
}
}
public void removePlayer(Player player, boolean activeRemoval) {
if(players.remove(player) && activeRemoval) {
for(Entity entity : entities)
BlockIdWrapper.impl.trackEntity(player, entity.getEntityId());
BlockIdWrapper.impl.trackEntity(player, entity);
// techhider triggers block change sending
}
}
public void checkEntity(Entity entity) {
Location location = entity.getLocation();
if(region.inRegion(location) && !visibility.get(new IntVector(location).toId(region))) { //TODO more precise
if(region.inRegion(location) && !visibility.get(new IntVector(location).toId(region))) {
if(entities.add(entity)) {
for(Player player : players)
BlockIdWrapper.impl.untrackEntity(player, entity.getEntityId());
BlockIdWrapper.impl.untrackEntity(player, entity);
}
} else {
if(entities.remove(entity)) {
for(Player player : players)
BlockIdWrapper.impl.trackEntity(player, entity.getEntityId());
BlockIdWrapper.impl.trackEntity(player, entity);
}
}
}
@@ -142,7 +122,7 @@ public class Hull {
public void checkREntity(REntity entity) {
Location location = new Location(Config.world, entity.getX(), entity.getY(), entity.getZ());
if(region.inRegion(location) && !visibility.get(new IntVector(location).toId(region))) { //TODO more precise
if(region.inRegion(location) && !visibility.get(new IntVector(location).toId(region))) {
if(rentities.add(entity))
entity.hide(true);
} else {
@@ -159,10 +139,8 @@ public class Hull {
visibility.clear();
occluding.clear();
uncoveredSurface.clear();
for (Map<IntVector, BitSet> direction : blockVisibility.values()) {
for (BitSet set : direction.values())
set.clear();
}
for(BitSet directionalVisibility : visibilityDirections.values())
directionalVisibility.clear();
long start = System.currentTimeMillis();
region.forEach((x, y, z) -> {
@@ -170,11 +148,7 @@ public class Hull {
if (isOccluding(Config.world.getBlockAt(x, y, z).getType()))
occluding.set(block.toId(region));
});
forEachBorder((root, direction) -> {
for (Map.Entry<IntVector, BitSet> quadrant : blockVisibility.get(direction).entrySet()) {
checkBlock(new NullList<>(), root, direction, quadrant.getKey(), quadrant.getValue());
}
});
forEachBorder((root, direction) -> uncoverBlocks(new NullList<>(), root, direction));
FightSystem.getPlugin().getLogger().log(Level.INFO, () -> "[HullHider] initialisation finished: " + (System.currentTimeMillis() - start) + " ms, visible blocks: " + visibility.cardinality());
}
@@ -187,41 +161,19 @@ public class Hull {
if (!occluding.get(id) || isOccluding(changedType))
return;
List<IntVector> uncovered = new ArrayList<>();
occluding.clear(id);
for (Map.Entry<IntVector, Map<IntVector, BitSet>> direction : blockVisibility.entrySet()) {
for (Map.Entry<IntVector, BitSet> quadrant : direction.getValue().entrySet()) {
if (quadrant.getValue().get(id)) {
quadrant.getValue().clear(id);
checkBlock(uncovered, root, direction.getKey(), quadrant.getKey(), quadrant.getValue());
}
}
}
if(uncovered.isEmpty())
if(!visibility.get(id))
return;
Set<IntVector> uncoveredSet = new HashSet<>(uncovered);
Iterator<Entity> it = entities.iterator();
while(it.hasNext()) {
Entity entity = it.next();
if(uncoveredSet.contains(new IntVector(entity.getLocation()))) { //TODO more precise
it.remove();
for(Player player : players)
BlockIdWrapper.impl.trackEntity(player, entity.getEntityId());
List<IntVector> uncovered = new ArrayList<>();
for(Map.Entry<IntVector, BitSet> directionalVisibility : visibilityDirections.entrySet()) {
if(directionalVisibility.getValue().get(id)) {
directionalVisibility.getValue().clear(id);
uncoverBlocks(uncovered, root, directionalVisibility.getKey());
}
}
Iterator<REntity> rit = rentities.iterator();
while(rit.hasNext()) {
REntity entity = rit.next();
if(uncoveredSet.contains(new IntVector(new Location(Config.world, entity.getX(), entity.getY(), entity.getZ())))) { //TODO more precise
rit.remove();
entity.hide(false);
}
}
uncoveredSurface.addAll(uncoveredSet);
uncoveredSurface.addAll(new HashSet<>(uncovered));
uncoveredSurface.remove(root);
}
@@ -266,15 +218,26 @@ public class Hull {
}
}
private void checkBlock(List<IntVector> uncovered, IntVector block, IntVector direction, IntVector quadrant, BitSet quadVisibility) {
private void uncoverBlocks(List<IntVector> uncovered, IntVector block, IntVector direction) {
uncoverBlocks(
uncovered, block, direction, visibilityDirections.get(direction),
direction.sqLength() == 1
? Arrays.stream(directions)
.filter(v -> v.sqLength() >= 2 && v.x*direction.x + v.y*direction.y + v.z*direction.z == 1)
.toArray(IntVector[]::new)
: NO_BRANCHES
);
}
private void uncoverBlocks(List<IntVector> uncovered, IntVector block, IntVector direction, BitSet directionalVisibility, IntVector[] branchDirections) {
if (block.notInRegion(region))
return;
int id = block.toId(region);
if (quadVisibility.get(id))
if(directionalVisibility.get(id))
return;
directionalVisibility.set(id);
quadVisibility.set(id);
if (!visibility.get(id)) {
visibility.set(id);
uncovered.add(block);
@@ -283,31 +246,9 @@ public class Hull {
if (occluding.get(id))
return;
IntVector neighbour = block.add(direction);
checkBlock(uncovered, neighbour, direction, quadrant, quadVisibility);
boolean neigbourTransparent = boundedNonOccluding(neighbour);
boolean diagonalReachable = false;
if (direction.x == 0 && (neigbourTransparent || boundedNonOccluding(block.add(quadrant.x, 0, 0)))) {
checkBlock(uncovered, neighbour.add(quadrant.x, 0, 0), direction, quadrant, quadVisibility);
diagonalReachable = boundedNonOccluding(neighbour.add(quadrant.x, 0, 0));
}
if (direction.y == 0 && (neigbourTransparent || boundedNonOccluding(block.add(0, quadrant.y, 0)))) {
checkBlock(uncovered, neighbour.add(0, quadrant.y, 0), direction, quadrant, quadVisibility);
diagonalReachable = diagonalReachable || boundedNonOccluding(neighbour.add(0, quadrant.y, 0));
}
if (direction.z == 0 && (neigbourTransparent || boundedNonOccluding(block.add(0, 0, quadrant.z)))) {
checkBlock(uncovered, neighbour.add(0, 0, quadrant.z), direction, quadrant, quadVisibility);
diagonalReachable = diagonalReachable || boundedNonOccluding(neighbour.add(0, 0, quadrant.z));
}
if (diagonalReachable)
checkBlock(uncovered, neighbour.add(quadrant), direction, quadrant, quadVisibility);
}
private boolean boundedNonOccluding(IntVector block) {
return !(block.notInRegion(region) || occluding.get(block.toId(region)));
uncoverBlocks(uncovered, block.add(direction), direction, directionalVisibility, branchDirections);
for(IntVector branchDirection : branchDirections)
uncoverBlocks(uncovered, block.add(branchDirection), branchDirection, visibilityDirections.get(branchDirection), NO_BRANCHES);
}
@@ -340,6 +281,10 @@ public class Hull {
return add(v.x, v.y, v.z);
}
public int sqLength() {
return x*x + y*y + z*z;
}
@Override
public int hashCode() {
return y << 24 ^ x << 12 ^ z;