mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-22 08:19:26 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@2ef589c okaaay let's go PaperMC/Paper@d0028b7 you saw nothing PaperMC/Paper@e080b20 Bundles are no longer experimental (thanks lynx) PaperMC/Paper@d280061 First batch of server patches PaperMC/Paper@3585434 first 100! PaperMC/Paper@6b27267 oops PaperMC/Paper@152e82c Some work PaperMC/Paper@9e92fed More work? PaperMC/Paper@f1649d7 Work it PaperMC/Paper@9d63c81 Work work work PaperMC/Paper@dc5af48 Breakpoint before projectile mess PaperMC/Paper@7c04a31 Update projectile launch to 1.21.2 PaperMC/Paper@a400929 242 PaperMC/Paper@8851d25 Fluid Flowing ifLoaded patch PaperMC/Paper@f677393 Skip Improve-exact-choice-recipe-ingredients for now PaperMC/Paper@5e262c1 298 PaperMC/Paper@aa37f72 Patches PaperMC/Paper@af125d2 Patch PaperMC/Paper@6bfc6db Patch PaperMC/Paper@09b625e 400 PaperMC/Paper@1f8b537 440 PaperMC/Paper@f5177aa Some more work PaperMC/Paper@2810f50 503 PaperMC/Paper@0bb4d1d 553 PaperMC/Paper@4db2503 Work work work work PaperMC/Paper@cbf6416 A bunch of patches PaperMC/Paper@6456b5d A bunch more 637 PaperMC/Paper@cb79de8 moooore PaperMC/Paper@1dc1425 MOOOOORE PaperMC/Paper@d52e2d2 MOOOOOOOORE PaperMC/Paper@4baf9ab MOOOOOOOOOOORE PaperMC/Paper@dd87f9f fix gruesome copyright violation PaperMC/Paper@5a6011c MOOOOOOOOOOOOOORE PaperMC/Paper@5d19e2b good luck americans PaperMC/Paper@457d035 Patches, patches, patches PaperMC/Paper@80de05f Patch me this, patch me that PaperMC/Paper@26f7b4c Patch PaperMC/Paper@89bf081 Patch PaperMC/Paper@7d4cce9 Patch PaperMC/Paper@b237528 Readd wrongly removed diff PaperMC/Paper@fc05430 963 PaperMC/Paper@9047541 Upstream update PaperMC/Paper@d67e55d Checkpoint PaperMC/Paper@fe142cd Anti Xray PaperMC/Paper@35e01d7 Update work 989 PaperMC/Paper@7616ebc 1000 PaperMC/Paper@6a31574 1020 PaperMC/Paper@227caac Wrong attempt at Tag lifecycle PaperMC/Paper@afbb0d8 1037 PaperMC/Paper@b06e0b0 Work on compile errors PaperMC/Paper@9c83387 Compile issues 1 PaperMC/Paper@0f011a3 Some more compile issues PaperMC/Paper@6fb86bb Compiler issues v2 PaperMC/Paper@918ca96 Compiler issues v3 PaperMC/Paper@bb124f4 Compiler issues v4 PaperMC/Paper@0a8fd78 Compiler issue v5 PaperMC/Paper@e19f484 Test compile fixes PaperMC/Paper@3518974 fix some issues PaperMC/Paper@6df21e6 Start Moonrise update PaperMC/Paper@47258a7 Move common diffs to MCUtils PaperMC/Paper@ecf4d97 Begin fixing issues PaperMC/Paper@8e569ba Merge patches PaperMC/Paper@3b31621 Implement config hooks in PaperHooks PaperMC/Paper@e9c58f5 Implement chunk tick iteration optimisations PaperMC/Paper@2a95ad1 Implement explosion optimisations PaperMC/Paper@16d2c9d Implement Starlight PaperMC/Paper@3d7b570 Implement chunk system PaperMC/Paper@1d341df Fix some compile errors from patches PaperMC/Paper@6daedd7 Prepare rebase PaperMC/Paper@75e3409 Complete rebase, start review PaperMC/Paper@f1a11a6 Finish mixin diff review PaperMC/Paper@a911f4a Prepare rebase PaperMC/Paper@35ef293 Finish rebase PaperMC/Paper@9ecf77e Fix compile issues PaperMC/Paper@62e3bcd Review patch-to-patch diff PaperMC/Paper@b711764 Rebase fixups PaperMC/Paper@2e76d3f Specify mainCapabilityAttribute for paper-api PaperMC/Paper@e4efb59 fix compile issues PaperMC/Paper@683ce20 Fix Anti-Xray using wrong data in chunk deserialize PaperMC/Paper@e92607c Fix MSPT command PaperMC/Paper@dcd81a8 Fix crafting (and server icon) PaperMC/Paper@61136fe Add max minecarft speed gamerule config PaperMC/Paper@ba1ee87 Revert "Add max minecarft speed gamerule config" PaperMC/Paper@cf03bed Add startup flag to disable gamerule limits PaperMC/Paper@be2edea Fix boats/minecarts not dropping when destroyed PaperMC/Paper@b14d336 Apply watchdoge patches PaperMC/Paper@2946dbb Update WorldServer#serverlevelData mapping PaperMC/Paper@98af0e0 update generator PaperMC/Paper@20507b4 Apply more patches PaperMC/Paper@7162ff0 fix item meta PaperMC/Paper@7d67d3f fix DamageTypeTags init PaperMC/Paper@0971875 re-add improve perf of mass crafts PaperMC/Paper@bcf52fe Delete some old patches PaperMC/Paper@348c855 Readd last API patch (with TODO) PaperMC/Paper@b630564 More patches PaperMC/Paper@3cb16c9 Add back per player mob spawning PaperMC/Paper@fe7b741 Another one PaperMC/Paper@12ed021 Update material tags and entity effect PaperMC/Paper@02bca1e Remove timings impl PaperMC/Paper@4d87302 Fix NPE and StackOverflowError for dispensers PaperMC/Paper@f8f230a Remove unnecessary AT PaperMC/Paper@29bf7be Fix unused parameter in PlayerList#remove PaperMC/Paper@9e35192 Execute spark tasks during tick sleep (#11525) PaperMC/Paper@e35f199 Use declaration order for state holder property iteration PaperMC/Paper@6288adb Remove leftover missed timings calls (#11527) PaperMC/Paper@99b1bf9 Use new ClientboundPlayerRotationPacket for setting player rotation PaperMC/Paper@40211a0 Update Gradle wrapper to 8.10.2 PaperMC/Paper@49eae0d remove some leftovers PaperMC/Paper@d576cfc cleanup bugfix patch PaperMC/Paper@1196ab5 Avoid issues with certain tasks not processing during sleep (#11526) PaperMC/Paper@fe2f3d4 Fix portal exit resulting in bad teleport transition PaperMC/Paper@9f1fa0b Fix item gravity on inactive items, remove dumb active skipping PaperMC/Paper@1a1d0cf Use target pitch in teleport (generally the same thing) PaperMC/Paper@8ba3073 fix "is_freezing" damage type tag PaperMC/Paper@1523212 don't resend effects when PlayerItemConsumeEvent is cancelled PaperMC/Paper@1330880 Add Friction API to minecarts PaperMC/Paper@580a610 Allow using old ender pearl behavior & apply ender pearl exploit patch (#11524) PaperMC/Paper@40a960d Rebuild patches
558 lines
29 KiB
Diff
558 lines
29 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] Visibility API and Command
|
|
|
|
|
|
diff --git a/src/main/java/me/samsuik/sakura/command/SakuraCommands.java b/src/main/java/me/samsuik/sakura/command/SakuraCommands.java
|
|
index 3e85c19db0655034c203eaab8d2e6b5504da5da8..9b550fad76a45fb6ea8d07f75c2ff901d56ae514 100644
|
|
--- a/src/main/java/me/samsuik/sakura/command/SakuraCommands.java
|
|
+++ b/src/main/java/me/samsuik/sakura/command/SakuraCommands.java
|
|
@@ -1,6 +1,9 @@
|
|
package me.samsuik.sakura.command;
|
|
|
|
import me.samsuik.sakura.command.subcommands.ConfigCommand;
|
|
+import me.samsuik.sakura.command.subcommands.FPSCommand;
|
|
+import me.samsuik.sakura.command.subcommands.VisualCommand;
|
|
+import me.samsuik.sakura.player.visibility.Visibility;
|
|
import net.minecraft.server.MinecraftServer;
|
|
import org.bukkit.command.Command;
|
|
|
|
@@ -12,6 +15,10 @@ public final class SakuraCommands {
|
|
static {
|
|
COMMANDS.put("sakura", new SakuraCommand("sakura"));
|
|
COMMANDS.put("config", new ConfigCommand("config"));
|
|
+ COMMANDS.put("fps", new FPSCommand("fps"));
|
|
+ COMMANDS.put("tntvisibility", new VisualCommand(Visibility.Setting.TNT_VISIBILITY, "tnttoggle"));
|
|
+ COMMANDS.put("sandvisibility", new VisualCommand(Visibility.Setting.SAND_VISIBILITY, "sandtoggle"));
|
|
+ COMMANDS.put("minimal", new VisualCommand(Visibility.Setting.MINIMAL, "minimaltnt", "tntlag"));
|
|
}
|
|
|
|
public static void registerCommands(MinecraftServer server) {
|
|
diff --git a/src/main/java/me/samsuik/sakura/command/subcommands/FPSCommand.java b/src/main/java/me/samsuik/sakura/command/subcommands/FPSCommand.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..65f7f7dee78e352bdc88ff42714d10585aa25e21
|
|
--- /dev/null
|
|
+++ b/src/main/java/me/samsuik/sakura/command/subcommands/FPSCommand.java
|
|
@@ -0,0 +1,24 @@
|
|
+package me.samsuik.sakura.command.subcommands;
|
|
+
|
|
+import me.samsuik.sakura.command.BaseSubCommand;
|
|
+import me.samsuik.sakura.player.visibility.VisibilityGUI;
|
|
+import org.bukkit.command.CommandSender;
|
|
+import org.bukkit.entity.Player;
|
|
+import org.checkerframework.checker.nullness.qual.NonNull;
|
|
+import org.checkerframework.framework.qual.DefaultQualifier;
|
|
+
|
|
+@DefaultQualifier(NonNull.class)
|
|
+public final class FPSCommand extends BaseSubCommand {
|
|
+ private final VisibilityGUI gui = new VisibilityGUI();
|
|
+
|
|
+ public FPSCommand(String name) {
|
|
+ super(name);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void execute(CommandSender sender, String[] args) {
|
|
+ if (sender instanceof Player player) {
|
|
+ this.gui.showTo(player);
|
|
+ }
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/me/samsuik/sakura/command/subcommands/VisualCommand.java b/src/main/java/me/samsuik/sakura/command/subcommands/VisualCommand.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..2931294d1063eb78b43f637269b27c257726b0ff
|
|
--- /dev/null
|
|
+++ b/src/main/java/me/samsuik/sakura/command/subcommands/VisualCommand.java
|
|
@@ -0,0 +1,43 @@
|
|
+package me.samsuik.sakura.command.subcommands;
|
|
+
|
|
+import me.samsuik.sakura.command.BaseSubCommand;
|
|
+import me.samsuik.sakura.configuration.GlobalConfiguration;
|
|
+import me.samsuik.sakura.player.visibility.Visibility;
|
|
+import net.kyori.adventure.text.minimessage.MiniMessage;
|
|
+import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
|
+import org.bukkit.command.CommandSender;
|
|
+import org.bukkit.entity.Player;
|
|
+import org.checkerframework.checker.nullness.qual.NonNull;
|
|
+import org.checkerframework.framework.qual.DefaultQualifier;
|
|
+
|
|
+import java.util.Arrays;
|
|
+
|
|
+@DefaultQualifier(NonNull.class)
|
|
+public final class VisualCommand extends BaseSubCommand {
|
|
+ private final Visibility.Setting type;
|
|
+
|
|
+ public VisualCommand(Visibility.Setting type, String... aliases) {
|
|
+ super(type.basicName());
|
|
+ this.setAliases(Arrays.asList(aliases));
|
|
+ this.type = type;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void execute(CommandSender sender, String[] args) {
|
|
+ if (!(sender instanceof Player player)) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ Visibility visibility = player.getVisibility();
|
|
+
|
|
+ // Toggle clicked setting visibility
|
|
+ visibility.toggle(this.type);
|
|
+
|
|
+ // Send message to player
|
|
+ String state = visibility.isEnabled(this.type) ? "Enabled" : "Disabled";
|
|
+ player.sendRichMessage(GlobalConfiguration.get().messages.fpsSettingChange,
|
|
+ Placeholder.unparsed("name", this.type.friendlyName()),
|
|
+ Placeholder.unparsed("state", state)
|
|
+ );
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/me/samsuik/sakura/player/visibility/VisibilityGUI.java b/src/main/java/me/samsuik/sakura/player/visibility/VisibilityGUI.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..049befac3219413be44c0a56f7b930a2eb55cee9
|
|
--- /dev/null
|
|
+++ b/src/main/java/me/samsuik/sakura/player/visibility/VisibilityGUI.java
|
|
@@ -0,0 +1,123 @@
|
|
+package me.samsuik.sakura.player.visibility;
|
|
+
|
|
+import me.samsuik.sakura.configuration.GlobalConfiguration;
|
|
+import me.samsuik.sakura.player.gui.ItemIcon;
|
|
+import me.samsuik.sakura.player.gui.PlayerGUI;
|
|
+import net.kyori.adventure.text.Component;
|
|
+import net.kyori.adventure.text.format.NamedTextColor;
|
|
+import net.kyori.adventure.text.format.TextDecoration;
|
|
+import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
|
+import org.bukkit.Bukkit;
|
|
+import org.bukkit.Material;
|
|
+import org.bukkit.entity.Player;
|
|
+import org.bukkit.inventory.Inventory;
|
|
+import org.bukkit.inventory.ItemStack;
|
|
+import org.bukkit.inventory.meta.ItemMeta;
|
|
+
|
|
+import java.util.function.BiFunction;
|
|
+
|
|
+public final class VisibilityGUI extends PlayerGUI {
|
|
+
|
|
+ private static final BiFunction<Player, Holder, Inventory> CREATE_INVENTORY = (player, holder) -> {
|
|
+ Inventory inventory = Bukkit.createInventory(holder, 45, Component.text("FPS GUI"));
|
|
+
|
|
+ for (int i = 0; i < inventory.getSize(); ++i) {
|
|
+ int column = i % 9;
|
|
+ int row = (i + 1) / 9;
|
|
+
|
|
+ Material background = column > 0 && column < 8 ? (row > 0 && row < 4 || column > 1 && column < 7)
|
|
+ ? GlobalConfiguration.get().fps.material
|
|
+ : Material.WHITE_STAINED_GLASS_PANE
|
|
+ : Material.BLACK_STAINED_GLASS_PANE;
|
|
+
|
|
+ ItemStack itemstack = new ItemStack(background);
|
|
+ ItemMeta meta = itemstack.getItemMeta();
|
|
+ meta.displayName(Component.space());
|
|
+ itemstack.setItemMeta(meta);
|
|
+
|
|
+ inventory.setItem(i, itemstack);
|
|
+ }
|
|
+
|
|
+ return inventory;
|
|
+ };
|
|
+
|
|
+ public VisibilityGUI() {
|
|
+ super(CREATE_INVENTORY);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ protected void register() {
|
|
+ registerFPSIcon(Visibility.Setting.TNT_VISIBILITY, 12);
|
|
+ registerFPSIcon(Visibility.Setting.SAND_VISIBILITY, 14);
|
|
+ registerFPSIcon(Visibility.Setting.MINIMAL, 13);
|
|
+ registerFPSIcon(Visibility.Setting.SPAWNERS, 20);
|
|
+ // ...22
|
|
+ registerFPSIcon(Visibility.Setting.EXPLOSIONS, 24);
|
|
+ registerFPSIcon(Visibility.Setting.PISTONS, 30);
|
|
+ registerFPSIcon(Visibility.Setting.REDSTONE, 31);
|
|
+ registerFPSIcon(Visibility.Setting.ENCHANTMENT_GLINT, 32);
|
|
+
|
|
+ registerIcon(new ItemIcon(player -> {
|
|
+ Visibility.State state = player.getVisibility().getState();
|
|
+ ItemStack itemstack = new ItemStack(state.material());
|
|
+
|
|
+ itemstack.editMeta(meta -> {
|
|
+ Component title = Component.text("Toggle all", state.colour());
|
|
+
|
|
+ // italic is default
|
|
+ title = title.decoration(TextDecoration.ITALIC, false);
|
|
+
|
|
+ meta.displayName(title.append(Component.space())
|
|
+ .append(Component.text(state.title(), NamedTextColor.GRAY)));
|
|
+ });
|
|
+
|
|
+ return itemstack;
|
|
+ }, player -> {
|
|
+ player.getVisibility().toggleAll();
|
|
+ // refresh icons after toggling
|
|
+ this.refresh(player);
|
|
+ }, 26));
|
|
+ }
|
|
+
|
|
+ private void registerFPSIcon(Visibility.Setting setting, int slot) {
|
|
+ registerIcon(new ItemIcon(player -> {
|
|
+ Visibility visibility = player.getVisibility();
|
|
+ ItemStack itemstack = new ItemStack(setting.material());
|
|
+
|
|
+ itemstack.editMeta(meta -> {
|
|
+ // Get the current state as a string
|
|
+ String state = visibility.isEnabled(setting) ? "Enabled" : "Disabled";
|
|
+
|
|
+ // Friendly name as a component
|
|
+ Component title = Component.text(setting.friendlyName(), setting.colour());
|
|
+
|
|
+ // Display names are italic by default
|
|
+ title = title.decoration(TextDecoration.ITALIC, false);
|
|
+
|
|
+ // Set the display name
|
|
+ meta.displayName(title.append(Component.space())
|
|
+ .append(Component.text(state, NamedTextColor.GRAY)));
|
|
+ });
|
|
+
|
|
+ return itemstack;
|
|
+ }, player -> {
|
|
+ Visibility visibility = player.getVisibility();
|
|
+
|
|
+ // Toggle clicked setting visibility
|
|
+ visibility.toggle(setting);
|
|
+
|
|
+ // Get the current state as a string
|
|
+ String state = visibility.isEnabled(setting) ? "Enabled" : "Disabled";
|
|
+
|
|
+ // Send message to player
|
|
+ player.sendRichMessage(GlobalConfiguration.get().messages.fpsSettingChange,
|
|
+ Placeholder.unparsed("name", setting.friendlyName()),
|
|
+ Placeholder.unparsed("state", state)
|
|
+ );
|
|
+
|
|
+ // Update toggle all icon
|
|
+ this.refreshSlot(player, 26);
|
|
+ }, slot));
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundSectionBlocksUpdatePacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundSectionBlocksUpdatePacket.java
|
|
index 1a37654aff9a9c86c9f7af10a1cf721371f0c5ec..82644b34a77dc5e5af38260b7b07b3ec9aceae33 100644
|
|
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundSectionBlocksUpdatePacket.java
|
|
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundSectionBlocksUpdatePacket.java
|
|
@@ -19,7 +19,7 @@ public class ClientboundSectionBlocksUpdatePacket implements Packet<ClientGamePa
|
|
private static final int POS_IN_SECTION_BITS = 12;
|
|
private final SectionPos sectionPos;
|
|
private final short[] positions;
|
|
- private final BlockState[] states;
|
|
+ public final BlockState[] states; // Sakura - private -> public
|
|
|
|
public ClientboundSectionBlocksUpdatePacket(SectionPos sectionPos, ShortSet positions, LevelChunkSection section) {
|
|
this.sectionPos = sectionPos;
|
|
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
index 5b3a886c624b36557cbfaccdc3fb05a46a4ba36a..464fc90376075ecc46f7b7731ba5e2c705324e7d 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
@@ -179,6 +179,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 = new it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap(); // Sakura - visibility api
|
|
|
|
public ChunkMap(ServerLevel world, LevelStorageSource.LevelStorageAccess session, DataFixer dataFixer, StructureTemplateManager structureTemplateManager, Executor executor, BlockableEventLoop<Runnable> mainThreadExecutor, LightChunkGetter chunkProvider, ChunkGenerator chunkGenerator, ChunkProgressListener worldGenerationProgressListener, ChunkStatusUpdateListener chunkStatusChangeListener, Supplier<DimensionDataStorage> persistentStateManagerFactory, int viewDistance, boolean dsync) {
|
|
super(new RegionStorageInfo(session.getLevelId(), world.dimension(), "chunk"), session.getDimensionPath(world.dimension()).resolve("region"), dataFixer, dsync);
|
|
@@ -979,6 +980,8 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
tracker.serverEntity.sendChanges();
|
|
}
|
|
}
|
|
+
|
|
+ this.minimalEntities.clear(); // Sakura - visibility api and command
|
|
}
|
|
// Paper end - optimise entity tracker
|
|
|
|
@@ -1216,6 +1219,31 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
return !this.seenBy.isEmpty();
|
|
}
|
|
// Paper end - optimise entity tracker
|
|
+ // Sakura start - visibility api and command
|
|
+ private boolean checkEntityVisibility(final ServerPlayer player) {
|
|
+ final Entity entity = this.entity;
|
|
+ final me.samsuik.sakura.player.visibility.Visibility visibility = player.visibility;
|
|
+ if (visibility.isModified() || !(entity.isPrimedTNT || entity.isFallingBlock)) {
|
|
+ return true;
|
|
+ }
|
|
+ if (entity.isPrimedTNT && visibility.isToggled(me.samsuik.sakura.player.visibility.Visibility.Setting.TNT_VISIBILITY)) {
|
|
+ return false;
|
|
+ }
|
|
+ if (entity.isFallingBlock && visibility.isToggled(me.samsuik.sakura.player.visibility.Visibility.Setting.SAND_VISIBILITY)) {
|
|
+ return false;
|
|
+ }
|
|
+ if (visibility.isToggled(me.samsuik.sakura.player.visibility.Visibility.Setting.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 true;
|
|
+ }
|
|
+ // Sakura end - visibility api and command
|
|
|
|
public TrackedEntity(final Entity entity, final int i, final int j, final boolean flag) {
|
|
this.serverEntity = new ServerEntity(ChunkMap.this.level, entity, j, flag, this::broadcast, this.seenBy); // CraftBukkit
|
|
@@ -1293,6 +1321,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 - visibility api and command
|
|
|
|
// CraftBukkit start - respect vanish API
|
|
if (flag && !player.getBukkitEntity().canSee(this.entity.getBukkitEntity())) { // Paper - only consider hits
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
index 32742470eea2ec86c0fff02aa157bfcc89530ad3..de2f6a27ae4d76bf27f127f448e0692f93b2a971 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
@@ -1895,7 +1895,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
while (iterator.hasNext()) {
|
|
ServerPlayer entityplayer = (ServerPlayer) iterator.next();
|
|
|
|
- if (entityplayer.distanceToSqr(vec3d) < 4096.0D) {
|
|
+ if (entityplayer.distanceToSqr(vec3d) < 4096.0D && !entityplayer.visibility.isToggled(me.samsuik.sakura.player.visibility.Visibility.Setting.EXPLOSIONS)) { // Sakura - visibility api
|
|
Optional<Vec3> optional = Optional.ofNullable((Vec3) serverexplosion.getHitPlayers().get(entityplayer));
|
|
|
|
entityplayer.connection.send(new ClientboundExplodePacket(vec3d, optional, particleparam2, holder));
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
index cffbd3300967e5d80b5973b35a76235bb2aa1b73..ad85e5ebe00918a7fea4071351741566e4883dd0 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -308,6 +308,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple
|
|
public final int[] mobCounts = new int[MOBCATEGORY_TOTAL_ENUMS]; // Paper
|
|
// Paper end - Optional per player mob spawns
|
|
public final int[] mobBackoffCounts = new int[MOBCATEGORY_TOTAL_ENUMS]; // Paper - per player mob count backoff
|
|
+ public final me.samsuik.sakura.player.visibility.Visibility visibility = new me.samsuik.sakura.player.visibility.Visibility(); // Sakura - visiblity api
|
|
|
|
// CraftBukkit start
|
|
public CraftPlayer.TransferCookieConnection transferCookieConnection;
|
|
@@ -678,6 +679,15 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple
|
|
this.respawnDimension = (ResourceKey) dataresult1.resultOrPartial(logger1::error).orElse(Level.OVERWORLD);
|
|
}
|
|
}
|
|
+ // Sakura start - visibility api
|
|
+ CompoundTag tag = nbt.getCompound("Sakura.Visuals");
|
|
+
|
|
+ for (me.samsuik.sakura.player.visibility.Visibility.Setting setting : me.samsuik.sakura.player.visibility.Visibility.Setting.values()) {
|
|
+ if (tag.getBoolean(setting.name())) {
|
|
+ visibility.toggle(setting);
|
|
+ }
|
|
+ }
|
|
+ // Sakura end - visibility api
|
|
|
|
this.spawnExtraParticlesOnFall = nbt.getBoolean("spawn_extra_particles_on_fall");
|
|
Tag nbtbase = nbt.get("raid_omen_position");
|
|
@@ -731,6 +741,13 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple
|
|
});
|
|
}
|
|
this.getBukkitEntity().setExtraData(nbt); // CraftBukkit
|
|
+ // Sakura start - visibility api
|
|
+ CompoundTag tag = new CompoundTag();
|
|
+ for (me.samsuik.sakura.player.visibility.Visibility.Setting setting : me.samsuik.sakura.player.visibility.Visibility.Setting.values()) {
|
|
+ tag.putBoolean(setting.name(), visibility.isToggled(setting));
|
|
+ }
|
|
+ nbt.put("Sakura.Visuals", tag);
|
|
+ // Sakura end - visibility api
|
|
|
|
nbt.putBoolean("spawn_extra_particles_on_fall", this.spawnExtraParticlesOnFall);
|
|
if (this.raidOmenPosition != null) {
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
|
index b0bc66dc7248aae691dcab68b925b52a1695e63f..b1a04865b0efee94227f0868910fc00712bcd6fa 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
|
@@ -44,6 +44,23 @@ import org.bukkit.craftbukkit.util.CraftLocation;
|
|
import org.bukkit.craftbukkit.util.Waitable;
|
|
import org.bukkit.event.player.PlayerKickEvent;
|
|
import org.bukkit.event.player.PlayerResourcePackStatusEvent;
|
|
+// Sakura start
|
|
+import com.mojang.datafixers.util.Pair;
|
|
+import me.samsuik.sakura.player.visibility.Visibility.Setting;
|
|
+import net.minecraft.core.component.DataComponents;
|
|
+import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
|
|
+import net.minecraft.network.protocol.game.ClientboundBlockEventPacket;
|
|
+import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
|
|
+import net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket;
|
|
+import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
|
|
+import net.minecraft.world.entity.EquipmentSlot;
|
|
+import net.minecraft.world.item.ItemStack;
|
|
+import net.minecraft.world.level.block.Blocks;
|
|
+import net.minecraft.world.level.block.DiodeBlock;
|
|
+import net.minecraft.world.level.block.RedStoneWireBlock;
|
|
+import net.minecraft.world.level.block.piston.PistonBaseBlock;
|
|
+import net.minecraft.world.level.block.piston.PistonHeadBlock;
|
|
+// Sakura end
|
|
|
|
public abstract class ServerCommonPacketListenerImpl implements ServerCommonPacketListener, CraftPlayer.TransferCookieConnection {
|
|
|
|
@@ -101,6 +118,65 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
|
|
protected final org.bukkit.craftbukkit.CraftServer cserver;
|
|
public boolean processedDisconnect;
|
|
|
|
+ // Sakura start - visibility api
|
|
+ private @Nullable Packet<?> recreatePacket(Packet<?> packet) {
|
|
+ me.samsuik.sakura.player.visibility.Visibility visibility = this.player.visibility;
|
|
+ if (packet instanceof ClientboundSetEquipmentPacket equipment && visibility.isToggled(Setting.ENCHANTMENT_GLINT)) {
|
|
+ java.util.List<Pair<EquipmentSlot, ItemStack>> slots = new java.util.ArrayList<>();
|
|
+
|
|
+ for (int i = 0; i < equipment.getSlots().size(); i++) {
|
|
+ Pair<EquipmentSlot, ItemStack> pair = equipment.getSlots().get(i);
|
|
+ ItemStack itemstack = pair.getSecond();
|
|
+
|
|
+ if (itemstack.isEnchanted()) {
|
|
+ ItemStack copy = itemstack.copy();
|
|
+ copy.remove(DataComponents.ENCHANTMENTS);
|
|
+ itemstack = copy;
|
|
+ }
|
|
+
|
|
+ slots.add(new Pair<>(pair.getFirst(), itemstack));
|
|
+ }
|
|
+
|
|
+ packet = new ClientboundSetEquipmentPacket(equipment.getEntity(), slots);
|
|
+ } else if (packet instanceof ClientboundBlockEntityDataPacket blockdata
|
|
+ && visibility.isToggled(Setting.SPAWNERS)
|
|
+ && this.player.level().getBlockIfLoaded(blockdata.getPos()) == Blocks.SPAWNER) {
|
|
+ packet = new ClientboundBlockUpdatePacket(blockdata.getPos(), Blocks.BLACK_STAINED_GLASS.defaultBlockState());
|
|
+ } else if (packet instanceof ClientboundBlockUpdatePacket updatePacket) {
|
|
+ if (visibility.isToggled(Setting.SPAWNERS) && updatePacket.blockState.getBlock() == Blocks.SPAWNER) {
|
|
+ packet = new ClientboundBlockUpdatePacket(updatePacket.getPos(), Blocks.BLACK_STAINED_GLASS.defaultBlockState());
|
|
+ } else if (visibility.isToggled(Setting.REDSTONE)
|
|
+ && (updatePacket.blockState.getBlock() instanceof DiodeBlock
|
|
+ || updatePacket.blockState.getBlock() instanceof RedStoneWireBlock)) {
|
|
+ return null;
|
|
+ } else if (visibility.isToggled(Setting.PISTONS)
|
|
+ && (updatePacket.blockState.getBlock() instanceof PistonBaseBlock
|
|
+ || updatePacket.blockState.getBlock() instanceof PistonHeadBlock)) {
|
|
+ return null;
|
|
+ }
|
|
+ } else if (packet instanceof ClientboundSectionBlocksUpdatePacket sectionPacket) {
|
|
+ for (net.minecraft.world.level.block.state.BlockState state : sectionPacket.states) {
|
|
+ if (visibility.isToggled(Setting.REDSTONE)
|
|
+ && (state.getBlock() instanceof DiodeBlock
|
|
+ || state.getBlock() instanceof RedStoneWireBlock)) {
|
|
+ return null;
|
|
+ } else if (visibility.isToggled(Setting.PISTONS)
|
|
+ && (state.getBlock() instanceof PistonBaseBlock
|
|
+ || state.getBlock() instanceof PistonHeadBlock)) {
|
|
+ return null;
|
|
+ }
|
|
+ }
|
|
+ } else if (packet instanceof ClientboundBlockEventPacket blockevent
|
|
+ && visibility.isToggled(Setting.PISTONS)
|
|
+ && (blockevent.getBlock() instanceof PistonBaseBlock
|
|
+ || blockevent.getBlock() instanceof PistonHeadBlock)) {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ return packet;
|
|
+ }
|
|
+ // Sakura end - visibility api
|
|
+
|
|
public CraftPlayer getCraftPlayer() {
|
|
return (this.player == null) ? null : (CraftPlayer) this.player.getBukkitEntity();
|
|
// CraftBukkit end
|
|
@@ -309,6 +385,12 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
|
|
ClientboundSetDefaultSpawnPositionPacket packet6 = (ClientboundSetDefaultSpawnPositionPacket) packet;
|
|
this.player.compassTarget = CraftLocation.toBukkit(packet6.pos, this.getCraftPlayer().getWorld());
|
|
}
|
|
+ // Sakura start - visibility api
|
|
+ if (this.player.visibility.isModified()) {
|
|
+ packet = this.recreatePacket(packet);
|
|
+ if (packet == null) return;
|
|
+ }
|
|
+ // Sakura end - visibility api
|
|
// CraftBukkit end
|
|
if (packet.isTerminal()) {
|
|
this.close();
|
|
@@ -322,8 +404,11 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
|
|
CrashReport crashreport = CrashReport.forThrowable(throwable, "Sending packet");
|
|
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Packet being sent");
|
|
|
|
+ // Sakura start - this has to be effectively final as we're modifying the packet above
|
|
+ var packetFinal = packet;
|
|
crashreportsystemdetails.setDetail("Packet class", () -> {
|
|
- return packet.getClass().getCanonicalName();
|
|
+ return packetFinal.getClass().getCanonicalName();
|
|
+ // Sakura end
|
|
});
|
|
throw new ReportedException(crashreport);
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
index c4b016a2fb5c79fb3f191e243712bee7cbe5cd2c..d8767738733a4d936723c1dccd2c4d273407b649 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -3246,6 +3246,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
|
|
|
event.setCancelled(cancelled);
|
|
AbstractContainerMenu oldContainer = this.player.containerMenu; // SPIGOT-1224
|
|
+ me.samsuik.sakura.player.gui.PlayerGUI.onWindowClick(event); // Sakura - visibility gui
|
|
this.cserver.getPluginManager().callEvent(event);
|
|
if (this.player.containerMenu != oldContainer) {
|
|
return;
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
index 6574219da33a7b9a4906883e65b78d7806f6e67b..eec06c841ae4dc9b3bf9c59d47352b4bd859c9c8 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -610,6 +610,10 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
}
|
|
}
|
|
// Paper end - optimise entity tracker
|
|
+ // Sakura start - visibility api and command
|
|
+ public boolean isPrimedTNT;
|
|
+ public boolean isFallingBlock;
|
|
+ // Sakura end - visibility api and command
|
|
|
|
public Entity(EntityType<?> type, Level world) {
|
|
this.id = Entity.ENTITY_COUNTER.incrementAndGet();
|
|
diff --git a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
index 06d9a519e64d4b8b8764b3ad7691ad93b5cee065..4a50ef9b25b9162815b879c60c294ed4be2edd5c 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
@@ -78,6 +78,7 @@ public class FallingBlockEntity extends Entity {
|
|
this.blockState = Blocks.SAND.defaultBlockState();
|
|
this.dropItem = true;
|
|
this.fallDamageMax = 40;
|
|
+ this.isFallingBlock = true; // Sakura
|
|
}
|
|
|
|
public FallingBlockEntity(Level world, double x, double y, double z, BlockState block) {
|
|
diff --git a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
|
|
index de87483600e55d88176fe25db621bbd3e464729f..5bd189fad703ac99d57258fa448dbcc103077297 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
|
|
@@ -63,6 +63,7 @@ public class PrimedTnt extends Entity implements TraceableEntity {
|
|
super(type, world);
|
|
this.explosionPower = 4.0F;
|
|
this.blocksBuilding = true;
|
|
+ this.isPrimedTNT = true; // Sakura
|
|
}
|
|
|
|
public PrimedTnt(Level world, double x, double y, double z, @Nullable LivingEntity igniter) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
index 9e4c416ddeccff87ea9ed5b45a2ef04eae2280bf..20c271879a79cc23c57421782e1199e0d52dfc2f 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -552,6 +552,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
this.getHandle().displayName = name == null ? this.getName() : name;
|
|
}
|
|
|
|
+ // Sakura start - visiblity api
|
|
+ @Override
|
|
+ public me.samsuik.sakura.player.visibility.Visibility getVisibility() {
|
|
+ return getHandle().visibility;
|
|
+ }
|
|
+ // Sakura end
|
|
+
|
|
// Paper start
|
|
@Override
|
|
public void playerListName(net.kyori.adventure.text.Component name) {
|