mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-25 10:38:18 +01:00
Test hasPredictableViewers
This commit is contained in:
parent
708307dbde
commit
122d3ebaf3
@ -103,7 +103,7 @@ final class EntityView {
|
||||
public boolean hasPredictableViewers() {
|
||||
// Verify if this entity's viewers can be predicted from surrounding entities
|
||||
synchronized (mutex) {
|
||||
return viewableOption.isAuto() && manualViewers.isEmpty();
|
||||
return viewableOption.isAuto() && viewableOption.predictable && manualViewers.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,6 +140,8 @@ final class EntityView {
|
||||
// The custom rule used to determine if an entity is viewable.
|
||||
private Predicate<T> predicate = entity -> true;
|
||||
|
||||
private boolean predictable = true;
|
||||
|
||||
public Option(EntityTracker.Target<T> target, Predicate<T> loopPredicate,
|
||||
Consumer<T> addition, Consumer<T> removal) {
|
||||
this.target = target;
|
||||
@ -192,6 +194,7 @@ final class EntityView {
|
||||
}
|
||||
|
||||
void updateRule0(Predicate<T> predicate) {
|
||||
this.predictable = false;
|
||||
update(loopPredicate, entity -> {
|
||||
final boolean result = predicate.test(entity);
|
||||
if (result != isRegistered(entity)) {
|
||||
|
@ -6,8 +6,7 @@ import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.network.packet.server.play.SpawnLivingEntityPacket;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@EnvTest
|
||||
public class EntityViewIntegrationTest {
|
||||
@ -96,6 +95,33 @@ public class EntityViewIntegrationTest {
|
||||
assertEquals(1, p2.getViewers().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void predictableViewers(Env env) {
|
||||
var instance = env.createFlatInstance();
|
||||
var p = env.createPlayer(instance, new Pos(0, 42, 0));
|
||||
assertTrue(p.hasPredictableViewers());
|
||||
p.setAutoViewable(false);
|
||||
assertFalse(p.hasPredictableViewers());
|
||||
p.setAutoViewable(true);
|
||||
assertTrue(p.hasPredictableViewers());
|
||||
// MANUAL VIEWERS
|
||||
{
|
||||
var tmpPlayer = env.createPlayer(instance, new Pos(0, 42, 0));
|
||||
p.addViewer(tmpPlayer);
|
||||
assertFalse(p.hasPredictableViewers());
|
||||
p.removeViewer(tmpPlayer);
|
||||
tmpPlayer.remove();
|
||||
assertTrue(p.hasPredictableViewers());
|
||||
}
|
||||
// CHANGE RULE
|
||||
{
|
||||
// May cause all subsequent `hasPredictableViewers` to return false
|
||||
// due to the server not able detect always-true predicate
|
||||
p.updateViewableRule(player -> false);
|
||||
assertFalse(p.hasPredictableViewers());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void livingVehicle(Env env) {
|
||||
var instance = env.createFlatInstance();
|
||||
|
Loading…
Reference in New Issue
Block a user