mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-22 16:29:16 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@deaccd2 [ci skip] Add file reference url to help.yml (#12481) PaperMC/Paper@f86b435 Add vault change state event (#12069) PaperMC/Paper@3e3b42c Update player chat session sync (#12382) PaperMC/Paper@f8fa4f6 Add method to retrieve FishHook (#12310) PaperMC/Paper@b9d3147 Use correct placed block position for sound (#12410) PaperMC/Paper@952338b [ci skip] Add missing exception docs to Player#listPlayer (#12488) PaperMC/Paper@1db3785 [ci skip] improve javadoc for off-hand swaps through getHotbarButton (#12489) PaperMC/Paper@d1810f2 Allow Server#getDefaultGameMode before worlds are initialized (#12490) PaperMC/Paper@02d20ff Fix NPE in Server#getMap before worlds are loaded (#12492) PaperMC/Paper@9e873f5 Fix inconsistencies between offline/online spawn position getter (#11960) PaperMC/Paper@fc0c371 Fix handling of resultant crafting container from craftItemResult (#12307) PaperMC/Paper@a7a76c8 Add methods for Armadillo (#12031) PaperMC/Paper@a74400d Update adventure to 4.21.0 (#12499) PaperMC/Paper@1e93076 Fix ipv6 loopback addresses being able to get connection throttled (#12155) PaperMC/Paper@646b80c Fix unnecessary map data saves (#12296) PaperMC/Paper@e663f99 Add combat tracker API (#11853) PaperMC/Paper@cd4fe5b [ci skip] Drop non-applicable ATs (#12498) PaperMC/Paper@5acfdd6 Fix save/load NaN Entity Motion (#12269) PaperMC/Paper@2754d7c Add Throw EntityChangeBlockEvent for BrushableBlockEntity#brush (#12133) PaperMC/Paper@567f63a Parity for respawn events (#11792) PaperMC/Paper@bc3d946 Normalizes CraftEntity#toString/getHandle (#12170) PaperMC/Paper@0e9b94d Fix ItemStack amount issues with Chat Components (#12216) PaperMC/Paper@835b955 Add a method on InventoryView to get the MenuType (#12193) PaperMC/Paper@c9411bf Fix min ItemStack amount check for asHoverEvent (#12505) PaperMC/Paper@1acf3b3 Infer block entity data in brigadier blockstate argument (#12197) PaperMC/Paper@b9b3cd6 Use components instead of ChatColor in more places (#12507) PaperMC/Paper@ec42171 Add missing spaces back (#12508) PaperMC/Paper@51345a1 Correct nullable fall location type PaperMC/Paper@93246a0 Fix errors when loading raid files without a PDC PaperMC/Paper@cb3ffd0 Don't store empty PDCs on raids PaperMC/Paper@d637ae8 Fix NoSuchElementException in EntityTransformEvent for slimes (#12510) PaperMC/Paper@1074237 Pass correct draw strength for EntityShootBowEvent (#12308) PaperMC/Paper@825685f Add PlayerPickBlockEvent and PlayerPickEntityEvent (#12425) PaperMC/Paper@2bd84f6 Expand PotionMeta Api to allow getting effective potion colour and effects (#12390) PaperMC/Paper@6f1f5b6 Fix ArmorStand items for canceled EntityDeathEvent (#12288)
248 lines
16 KiB
Diff
248 lines
16 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Samsuik <kfian294ma4@gmail.com>
|
|
Date: Tue, 21 Sep 2021 23:54:25 +0100
|
|
Subject: [PATCH] Client Visibility Settings
|
|
|
|
|
|
diff --git a/net/minecraft/server/level/ChunkMap.java b/net/minecraft/server/level/ChunkMap.java
|
|
index dff3cc7456fe69ebd735aa950f79ce0dfed7e25e..07d8bb89ed0f9cea6353905939ba9f91c6fb64a5 100644
|
|
--- a/net/minecraft/server/level/ChunkMap.java
|
|
+++ b/net/minecraft/server/level/ChunkMap.java
|
|
@@ -173,6 +173,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
this.handleLegacyStructureIndex(pos);
|
|
}
|
|
// Paper end - rewrite chunk system
|
|
+ private final it.unimi.dsi.fastutil.longs.Long2IntMap minimalEntities; // Sakura - client visibility settings; minimal tnt/sand
|
|
|
|
public ChunkMap(
|
|
ServerLevel level,
|
|
@@ -237,6 +238,10 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
);
|
|
this.setServerViewDistance(serverViewDistance);
|
|
this.worldGenContext = new WorldGenContext(level, generator, structureManager, this.lightEngine, null, this::setChunkUnsaved); // Paper - rewrite chunk system
|
|
+ // Sakura start - client visibility settings; minimal tnt/sand
|
|
+ this.minimalEntities = new it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap();
|
|
+ this.minimalEntities.defaultReturnValue(Integer.MIN_VALUE);
|
|
+ // Sakura end - client visibility settings; minimal tnt/sand
|
|
}
|
|
|
|
private void setChunkUnsaved(ChunkPos chunkPos) {
|
|
@@ -1016,6 +1021,8 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
tracker.serverEntity.sendChanges();
|
|
}
|
|
}
|
|
+
|
|
+ this.minimalEntities.clear(); // Sakura - client visibility settings; minimal tnt/sand
|
|
}
|
|
// Paper end - optimise entity tracker
|
|
|
|
@@ -1226,6 +1233,32 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
return !this.seenBy.isEmpty();
|
|
}
|
|
// Paper end - optimise entity tracker
|
|
+ // Sakura start - client visibility settings; entity visibility
|
|
+ private boolean checkEntityVisibility(final ServerPlayer player) {
|
|
+ final Entity entity = this.entity;
|
|
+ final me.samsuik.sakura.player.visibility.VisibilitySettings settings = player.visibilitySettings;
|
|
+ if (!settings.playerModified() || !(entity.isPrimedTNT || entity.isFallingBlock)) {
|
|
+ return true;
|
|
+ }
|
|
+ final me.samsuik.sakura.player.visibility.VisibilityType type;
|
|
+ if (entity.isPrimedTNT) {
|
|
+ type = me.samsuik.sakura.player.visibility.VisibilityTypes.TNT;
|
|
+ } else {
|
|
+ type = me.samsuik.sakura.player.visibility.VisibilityTypes.SAND;
|
|
+ }
|
|
+ final me.samsuik.sakura.player.visibility.VisibilityState state = settings.get(type);
|
|
+ if (state == me.samsuik.sakura.player.visibility.VisibilityState.MINIMAL) {
|
|
+ final long key = entity.blockPosition().asLong() ^ entity.getType().hashCode();
|
|
+ final long visibleEntity = ChunkMap.this.minimalEntities.get(key);
|
|
+ if (visibleEntity != Integer.MIN_VALUE) {
|
|
+ return entity.getId() == visibleEntity;
|
|
+ } else {
|
|
+ ChunkMap.this.minimalEntities.put(key, entity.getId());
|
|
+ }
|
|
+ }
|
|
+ return state != me.samsuik.sakura.player.visibility.VisibilityState.OFF;
|
|
+ }
|
|
+ // Sakura end - client visibility settings; entity visibility
|
|
|
|
public TrackedEntity(final Entity entity, final int range, final int updateInterval, final boolean trackDelta) {
|
|
this.serverEntity = new ServerEntity(ChunkMap.this.level, entity, updateInterval, trackDelta, this::broadcast, this::broadcastIgnorePlayers, this.seenBy); // Paper
|
|
@@ -1304,6 +1337,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
}
|
|
flag = flag && this.entity.broadcastToPlayer(player) && ChunkMap.this.isChunkTracked(player, this.entity.chunkPosition().x, this.entity.chunkPosition().z);
|
|
// Paper end - Configurable entity tracking range by Y
|
|
+ flag = flag && this.checkEntityVisibility(player); // Sakura start - client visibility settings; entity visibility
|
|
// CraftBukkit start - respect vanish API
|
|
if (flag && !player.getBukkitEntity().canSee(this.entity.getBukkitEntity())) { // Paper - only consider hits
|
|
flag = false;
|
|
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
|
|
index 8097ad52b8c38726155251376015fca2105f5547..2ed1d5d504a69c03f4860f05e146c320cdb48a60 100644
|
|
--- a/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/net/minecraft/server/level/ServerLevel.java
|
|
@@ -561,6 +561,21 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
this.playerTickingChunks.remove((LevelChunk)chunkHolder.getCurrentChunk());
|
|
}
|
|
// Paper end - chunk tick iteration
|
|
+ // Sakura start - client visibility settings
|
|
+ public final LongSet explosionPositions = new it.unimi.dsi.fastutil.longs.LongOpenHashSet();
|
|
+
|
|
+ public final boolean checkExplosionVisibility(final Vec3 position, final ServerPlayer player) {
|
|
+ final me.samsuik.sakura.player.visibility.VisibilitySettings settings = player.visibilitySettings;
|
|
+ if (settings.isDisabled(me.samsuik.sakura.player.visibility.VisibilityTypes.EXPLOSIONS)) {
|
|
+ return false;
|
|
+ } else if (settings.isToggled(me.samsuik.sakura.player.visibility.VisibilityTypes.EXPLOSIONS)) {
|
|
+ final BlockPos blockPosition = BlockPos.containing(position);
|
|
+ final long encodedPosition = blockPosition.asLong();
|
|
+ return this.explosionPositions.add(encodedPosition);
|
|
+ }
|
|
+ return true;
|
|
+ }
|
|
+ // Sakura end - client visibility settings
|
|
|
|
public ServerLevel(
|
|
MinecraftServer server,
|
|
@@ -671,6 +686,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
this.chunkDataController = new ca.spottedleaf.moonrise.patches.chunk_system.io.datacontroller.ChunkDataController((ServerLevel)(Object)this, this.chunkTaskScheduler);
|
|
// Paper end - rewrite chunk system
|
|
this.getCraftServer().addWorld(this.getWorld()); // CraftBukkit
|
|
+ this.levelTickScheduler.registerNewTask(this.explosionPositions::clear, 0); // Sakura - client visibility settings
|
|
}
|
|
|
|
// Paper start
|
|
@@ -1876,7 +1892,18 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
for (ServerPlayer serverPlayer : this.players) {
|
|
if (serverPlayer.distanceToSqr(vec3) < 4096.0) {
|
|
Optional<Vec3> optional = Optional.ofNullable(serverExplosion.getHitPlayers().get(serverPlayer));
|
|
- serverPlayer.connection.send(new ClientboundExplodePacket(vec3, optional, particleOptions, explosionSound));
|
|
+ // Sakura start - client visibility settings; let players toggle explosion particles
|
|
+ ParticleOptions particle = particleOptions;
|
|
+ Vec3 position = vec3;
|
|
+ // In 1.22 and later this should be replaced with sending the motion through a PlayerPositionPacket.
|
|
+ // The problem here is SetEntityMotion is capped to 3.9 b/pt and the only other alternate mean was
|
|
+ // implemented in 1.21.3. I believe it's best to just wait on this issue and deal with this hack.
|
|
+ if (!this.checkExplosionVisibility(vec3, serverPlayer)) {
|
|
+ position = new Vec3(0.0, -1024.0, 0.0);
|
|
+ particle = net.minecraft.core.particles.ParticleTypes.SMOKE;
|
|
+ }
|
|
+ serverPlayer.connection.send(new ClientboundExplodePacket(position, optional, particle, explosionSound));
|
|
+ // Sakura end - client visibility settings; let players toggle explosion particles
|
|
}
|
|
}
|
|
|
|
diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
|
|
index 0689dc62a9fefc6d3876787f7d67c0ab4b12716b..1771460df96e294bb9547568d6f00708fa672a4a 100644
|
|
--- a/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -459,6 +459,7 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
|
|
return this.viewDistanceHolder;
|
|
}
|
|
// Paper end - rewrite chunk system
|
|
+ public final me.samsuik.sakura.player.visibility.PlayerVisibilitySettings visibilitySettings = new me.samsuik.sakura.player.visibility.PlayerVisibilitySettings(); // Sakura - client visibility settings
|
|
|
|
public ServerPlayer(MinecraftServer server, ServerLevel level, GameProfile gameProfile, ClientInformation clientInformation) {
|
|
super(level, level.getSharedSpawnPos(), level.getSharedSpawnAngle(), gameProfile);
|
|
diff --git a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
|
index 186393485396cfe9b1baef29586198356e2d2600..a06f5a9b577cd9cc2cb948b2801b0aec31db8836 100644
|
|
--- a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
|
+++ b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
|
@@ -51,6 +51,21 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
|
|
public final java.util.Map<java.util.UUID, net.kyori.adventure.resource.ResourcePackCallback> packCallbacks = new java.util.concurrent.ConcurrentHashMap<>(); // Paper - adventure resource pack callbacks
|
|
private static final long KEEPALIVE_LIMIT = Long.getLong("paper.playerconnection.keepalive", 30) * 1000; // Paper - provide property to set keepalive limit
|
|
protected static final net.minecraft.resources.ResourceLocation MINECRAFT_BRAND = net.minecraft.resources.ResourceLocation.withDefaultNamespace("brand"); // Paper - Brand support
|
|
+ // Sakura start - client visibility settings
|
|
+ private @Nullable Packet<?> recreatePacket(final Packet<?> packet) {
|
|
+ final me.samsuik.sakura.player.visibility.VisibilitySettings settings = this.player.visibilitySettings;
|
|
+ if (packet instanceof net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket bedPacket) {
|
|
+ if (settings.isToggled(me.samsuik.sakura.player.visibility.VisibilityTypes.SPAWNERS) && bedPacket.getType() == net.minecraft.world.level.block.entity.BlockEntityType.MOB_SPAWNER) {
|
|
+ return null;
|
|
+ }
|
|
+ } else if (packet instanceof net.minecraft.network.protocol.game.ClientboundBlockEventPacket bePacket) {
|
|
+ if (settings.isToggled(me.samsuik.sakura.player.visibility.VisibilityTypes.PISTONS) && bePacket.getBlock() instanceof net.minecraft.world.level.block.piston.PistonBaseBlock) {
|
|
+ return null;
|
|
+ }
|
|
+ }
|
|
+ return packet;
|
|
+ }
|
|
+ // Sakura end - client visibility settings
|
|
|
|
public ServerCommonPacketListenerImpl(MinecraftServer server, Connection connection, CommonListenerCookie cookie, net.minecraft.server.level.ServerPlayer player) { // CraftBukkit
|
|
this.server = server;
|
|
@@ -291,6 +306,12 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
|
|
} else if (packet instanceof net.minecraft.network.protocol.game.ClientboundSetDefaultSpawnPositionPacket defaultSpawnPositionPacket) {
|
|
this.player.compassTarget = org.bukkit.craftbukkit.util.CraftLocation.toBukkit(defaultSpawnPositionPacket.getPos(), this.getCraftPlayer().getWorld());
|
|
}
|
|
+ // Sakura start - client visibility settings
|
|
+ if (this.player.visibilitySettings.playerModified()) {
|
|
+ packet = this.recreatePacket(packet);
|
|
+ if (packet == null) return;
|
|
+ }
|
|
+ // Sakura end - client visibility settings
|
|
// CraftBukkit end
|
|
if (packet.isTerminal()) {
|
|
this.close();
|
|
@@ -303,7 +324,10 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
|
|
} catch (Throwable var7) {
|
|
CrashReport crashReport = CrashReport.forThrowable(var7, "Sending packet");
|
|
CrashReportCategory crashReportCategory = crashReport.addCategory("Packet being sent");
|
|
- crashReportCategory.setDetail("Packet class", () -> packet.getClass().getCanonicalName());
|
|
+ // Sakura start - client visibility settings; packet has to be effectively final
|
|
+ final Packet<?> packetFinal = packet;
|
|
+ crashReportCategory.setDetail("Packet class", () -> packetFinal.getClass().getCanonicalName());
|
|
+ // Sakura end - client visibility settings; packet has to be effectively final
|
|
throw new ReportedException(crashReport);
|
|
}
|
|
}
|
|
diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
index 064a9b6cf6792192fc1fa80095a48c2025cebf2a..266a8e6b164d6d76c2fc26c986290569781cf871 100644
|
|
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -3192,6 +3192,7 @@ public class ServerGamePacketListenerImpl
|
|
|
|
event.setCancelled(cancelled);
|
|
net.minecraft.world.inventory.AbstractContainerMenu oldContainer = this.player.containerMenu; // SPIGOT-1224
|
|
+ me.samsuik.sakura.player.gui.FeatureGui.clickEvent(event); // Sakura - client visibility settings
|
|
this.cserver.getPluginManager().callEvent(event);
|
|
if (this.player.containerMenu != oldContainer) {
|
|
return;
|
|
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
|
index 76945e5eab70734015995288faa51c7cc5438d08..ca2939dcc380989d87bed516c4b7a73be90ebf06 100644
|
|
--- a/net/minecraft/world/entity/Entity.java
|
|
+++ b/net/minecraft/world/entity/Entity.java
|
|
@@ -512,6 +512,10 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
}
|
|
// Paper end - optimise entity tracker
|
|
public boolean pushedByFluid = true; // Sakura - entity pushed by fluid api
|
|
+ // Sakura start - client visibility settings
|
|
+ public boolean isPrimedTNT;
|
|
+ public boolean isFallingBlock;
|
|
+ // Sakura end - client visibility settings
|
|
|
|
public Entity(EntityType<?> entityType, Level level) {
|
|
this.type = entityType;
|
|
diff --git a/net/minecraft/world/entity/item/FallingBlockEntity.java b/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
index 5b036edf61c53596528bf722c46673b47c01f51d..6660e6c78303db5585a06d6836b035d0e8582922 100644
|
|
--- a/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
+++ b/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
@@ -76,6 +76,7 @@ public class FallingBlockEntity extends Entity {
|
|
super(entityType, level);
|
|
this.dropItem = level.sakuraConfig().cannons.sand.dropItems; // Sakura - configure falling blocks dropping items
|
|
this.heightParity = level.sakuraConfig().cannons.mechanics.fallingBlockParity; // Sakura - configure cannon mechanics
|
|
+ this.isFallingBlock = true; // Sakura - client visibility settings
|
|
}
|
|
|
|
public FallingBlockEntity(Level level, double x, double y, double z, BlockState state) {
|
|
diff --git a/net/minecraft/world/entity/item/PrimedTnt.java b/net/minecraft/world/entity/item/PrimedTnt.java
|
|
index deb5e9e4cdd235311ff4e51ffb2f02f35d580645..7e3d7d5b47557e57bf661aa8d3eefcb416cb408b 100644
|
|
--- a/net/minecraft/world/entity/item/PrimedTnt.java
|
|
+++ b/net/minecraft/world/entity/item/PrimedTnt.java
|
|
@@ -64,6 +64,7 @@ public class PrimedTnt extends Entity implements TraceableEntity {
|
|
public PrimedTnt(EntityType<? extends PrimedTnt> entityType, Level level) {
|
|
super(entityType, level);
|
|
this.blocksBuilding = true;
|
|
+ this.isPrimedTNT = true; // Sakura - client visibility settings
|
|
}
|
|
|
|
public PrimedTnt(Level level, double x, double y, double z, @Nullable LivingEntity owner) {
|