mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-20 07:19:33 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@1e7dd72 Remove 'fix Vanilla Minecart speed' patch (#10068) PaperMC/Paper@e7e1c8a Fix and add new scoreboard API (#10037) PaperMC/Paper@49f9f6f Add Registry#getKey (#10066) PaperMC/Paper@4adca3d Update to adventure 4.15 (#10045) PaperMC/Paper@ff7b9b0 Increase default custom payload channel size limit (#10006) PaperMC/Paper@1cda66e Hotfix Entity isInRain reobf issue PaperMC/Paper@61768e0 [ci skip] Remove no longer needed mappings change PaperMC/Paper@e035fd7 Updated Upstream (Bukkit/CraftBukkit/Spigot) PaperMC/Paper@c215ce1 [ci skip] cleanup patch diff from last commit PaperMC/Paper@4fdda9e Keep newlines in outdated client/server message (#10042) PaperMC/Paper@f483b38 fix NPE on EntityTeleportEvent getTo (#10016) PaperMC/Paper@dc62150 Catch async usage of playsound (#10021) PaperMC/Paper@0d6a0c3 Fix command block async message (again) (#10082) PaperMC/Paper@d1f507f Don't fire 2 game events for certain cauldron interactions (#8904) PaperMC/Paper@a401585 Fix campfire recipes not always outputting full result (#8754) PaperMC/Paper@88d28d6 Fix long loading screen when refreshing skins (#10026) PaperMC/Paper@c081104 Add experience points api (#9688) PaperMC/Paper@8221b08 Fix global sound event gamerule not being respected (#8727) PaperMC/Paper@3c0d6aa Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10085) PaperMC/Paper@2c3ccb8 Add drops to shear events (#5678) PaperMC/Paper@b2ffb1b Add PlayerShieldDisableEvent (#9177) PaperMC/Paper@2951732 Add HiddenPotionEffect API (#9910) PaperMC/Paper@e4ab50d Properly disallow async Player#chat (#8123) PaperMC/Paper@5e978d3 Fix Folia scheduler tasks not canceling when plugin disable (#10091) PaperMC/Paper@e56e53f Fix some component bugs in login disconnect packet (#10090) PaperMC/Paper@3484ae9 Call entity_die game event after event cancel check (#10096) PaperMC/Paper@0ae58c0 cleanup player death event adventure logic (#10095) PaperMC/Paper@1281f4f Make region/lock shift accessors per world PaperMC/Paper@983377b Correctly check if bucket dispenses will succeed for event (#10109) PaperMC/Paper@58e120b [ci skip] Remove extraneous diff added in 1.20.3 update (#10101) PaperMC/Paper@816bacc Call EntityChangeBlockEvent for cake eating (#10105) PaperMC/Paper@692db0c fix CustomModelData being removed (#10113) PaperMC/Paper@509876d Keep fully frozen entities fully activated (#10103) PaperMC/Paper@1fa48d1 include relative flags in PlayerTeleportEvent (#8190) PaperMC/Paper@ae001ae Fix untrack event not being called for all 'untracks' (#10110) PaperMC/Paper@259bc76 Pass system properties to maven repo session (#10117) PaperMC/Paper@b2a6d57 Validate ResourceLocation in NBT reading PaperMC/Paper@7eaff48 [ci skip] Replace some magic values with constant references PaperMC/Paper@19a6202 Fix experience & improvements to block events (#8067) PaperMC/Paper@8379027 Fix cmd permission levels for command blocks (#7404) PaperMC/Paper@a93acc4 Fix EntityChangePoseEvent being called during worldgen (#10120) PaperMC/Paper@25a99b1 Fix BlockDestroyEvents effectBlock not being set (#10131) PaperMC/Paper@a58e29d Fix a borked update of 'Properly handle BlockBreakEvent#isDropItems' (#10134) PaperMC/Paper@570cfb4 Validate missed resource location parsing PaperMC/Paper@e46276e Fixup NamespacedKey parsing PaperMC/Paper@f1c5f01 [ci skip] Fix typo PaperMC/Paper@07b956e Fix tests by disabling them
631 lines
32 KiB
Diff
631 lines
32 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 c2651cac1dcf85fb67fe981b97efee4e56431de2..d7d0c49cc5d576c594dee16ddba037cd147e11fa 100644
|
|
--- a/src/main/java/me/samsuik/sakura/command/SakuraCommands.java
|
|
+++ b/src/main/java/me/samsuik/sakura/command/SakuraCommands.java
|
|
@@ -2,6 +2,9 @@ package me.samsuik.sakura.command;
|
|
|
|
import io.papermc.paper.command.PaperPluginsCommand;
|
|
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;
|
|
|
|
@@ -14,6 +17,10 @@ public 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(final 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..1dc2a98123d671c945e85b97a898f56e527a81f5
|
|
--- /dev/null
|
|
+++ b/src/main/java/me/samsuik/sakura/command/subcommands/FPSCommand.java
|
|
@@ -0,0 +1,26 @@
|
|
+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 class FPSCommand extends BaseSubCommand {
|
|
+
|
|
+ private final VisibilityGUI VISIBILITY_GUI = new VisibilityGUI();
|
|
+
|
|
+ public FPSCommand(String name) {
|
|
+ super(name);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void execute(CommandSender sender, String[] args) {
|
|
+ if (sender instanceof Player player) {
|
|
+ VISIBILITY_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..6027e4741e2de7c6d3bd7b094c196a212e34e2f5
|
|
--- /dev/null
|
|
+++ b/src/main/java/me/samsuik/sakura/command/subcommands/VisualCommand.java
|
|
@@ -0,0 +1,45 @@
|
|
+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 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;
|
|
+ }
|
|
+
|
|
+ var visibility = player.getVisibility();
|
|
+
|
|
+ // Toggle clicked setting visibility
|
|
+ visibility.toggle(type);
|
|
+
|
|
+ // Send message to player
|
|
+ var state = visibility.isEnabled(type) ? "Enabled" : "Disabled";
|
|
+ player.sendMessage(MiniMessage.miniMessage().deserialize(GlobalConfiguration.get().fps.message,
|
|
+ Placeholder.unparsed("name", 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..d5bd47426a219a3825deaa0b62386c88d17b4aac
|
|
--- /dev/null
|
|
+++ b/src/main/java/me/samsuik/sakura/player/visibility/VisibilityGUI.java
|
|
@@ -0,0 +1,119 @@
|
|
+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.TextColor;
|
|
+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 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)
|
|
+ ? Material.matchMaterial(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, Material.TNT, NamedTextColor.RED, 12);
|
|
+ registerFPSIcon(Visibility.Setting.SAND_VISIBILITY, Material.SAND, NamedTextColor.YELLOW, 14);
|
|
+ registerFPSIcon(Visibility.Setting.MINIMAL, Material.NETHER_BRICK_SLAB, NamedTextColor.GOLD, 13);
|
|
+ registerFPSIcon(Visibility.Setting.SPAWNERS, Material.SPAWNER, NamedTextColor.DARK_GRAY, 20);
|
|
+ registerFPSIcon(Visibility.Setting.FLASHING_TNT, Material.REDSTONE_LAMP, NamedTextColor.RED, 22);
|
|
+ registerFPSIcon(Visibility.Setting.EXPLOSIONS, Material.COBWEB, NamedTextColor.WHITE, 24);
|
|
+ registerFPSIcon(Visibility.Setting.PISTONS, Material.PISTON, NamedTextColor.GOLD, 30);
|
|
+ registerFPSIcon(Visibility.Setting.REDSTONE, Material.REDSTONE, NamedTextColor.DARK_RED, 31);
|
|
+ registerFPSIcon(Visibility.Setting.ENCHANTMENT_GLINT, Material.ENCHANTED_BOOK, NamedTextColor.DARK_PURPLE, 32);
|
|
+
|
|
+ registerIcon(new ItemIcon(
|
|
+ (player) -> {
|
|
+ ItemStack itemstack = new ItemStack(Material.GREEN_STAINED_GLASS_PANE);
|
|
+ Component title = Component.text("Toggle all", NamedTextColor.GREEN);
|
|
+
|
|
+ itemstack.editMeta(meta -> meta.displayName(title.decoration(TextDecoration.ITALIC, false)));
|
|
+ return itemstack;
|
|
+ },
|
|
+ (player) -> {
|
|
+ player.getVisibility().toggleAll();
|
|
+
|
|
+ // refresh icons after toggling
|
|
+ this.refresh(player);
|
|
+ },
|
|
+ 26
|
|
+ ));
|
|
+ }
|
|
+
|
|
+ private void registerFPSIcon(Visibility.Setting setting, Material material, TextColor colour, int slot) {
|
|
+ registerIcon(new ItemIcon((player) -> {
|
|
+ Visibility visibility = player.getVisibility();
|
|
+ ItemStack itemstack = new ItemStack(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(), 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().fps.message,
|
|
+ Placeholder.unparsed("name", setting.friendlyName()),
|
|
+ Placeholder.unparsed("state", state)
|
|
+ );
|
|
+ },
|
|
+ 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 e3f355c85eb7cc8c1683e3009502c10a5ed32daa..349e56d5caad3fc38e83eac6ffff83e2fb30eaa7 100644
|
|
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundSectionBlocksUpdatePacket.java
|
|
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundSectionBlocksUpdatePacket.java
|
|
@@ -16,7 +16,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/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
index b5e2ae560431cd3ecfc780deb25488016c0ad0e7..73dc4f245039805b635f9e89438104e3b7a93e7b 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -1745,6 +1745,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
this.profiler.pop();
|
|
worldserver.explosionDensityCache.clear(); // Paper - Optimize explosions
|
|
worldserver.localConfig().expire(currentTickLong); // Sakura
|
|
+ worldserver.minimalTNT.clear(); // Sakura - visibility api
|
|
}
|
|
this.isIteratingOverLevels = false; // Paper
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
index ecb09c74153349e78bb81d1188c282e4be4000bf..f3d4f8ba3bc148e28cab1a4d3def805081391ecc 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
@@ -1434,6 +1434,22 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
}
|
|
// Paper end - check Y
|
|
|
|
+ // Sakura start - visibility api
|
|
+ if (this.entity.isPrimedTNT && player.visibility.isToggled(me.samsuik.sakura.player.visibility.Visibility.Setting.TNT_VISIBILITY)
|
|
+ || this.entity.isFallingBlock && player.visibility.isToggled(me.samsuik.sakura.player.visibility.Visibility.Setting.SAND_VISIBILITY)) {
|
|
+ flag = false;
|
|
+ }
|
|
+
|
|
+ if (flag && (this.entity.isPrimedTNT || this.entity.isFallingBlock) && player.visibility.isToggled(me.samsuik.sakura.player.visibility.Visibility.Setting.MINIMAL)) {
|
|
+ long key = entity.blockPosition().asLong();
|
|
+
|
|
+ if (level.minimalTNT.containsKey(key)) {
|
|
+ flag = level.minimalTNT.get(key) == entity.getId();
|
|
+ } else {
|
|
+ level.minimalTNT.put(key, entity.getId());
|
|
+ }
|
|
+ }
|
|
+ // Sakura end
|
|
// CraftBukkit start - respect vanish API
|
|
if (flag && !player.getBukkitEntity().canSee(this.entity.getBukkitEntity())) { // Paper - only consider hits
|
|
flag = false;
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
index 35674f92a67f93382103c2766df4b678ba5c862f..83c4639c2bdca4dc4281d9f5eca104af3063bfa5 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
@@ -47,6 +47,13 @@ import net.minecraft.util.Mth;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.event.player.PlayerVelocityEvent;
|
|
// CraftBukkit end
|
|
+// Sakura start
|
|
+import me.samsuik.sakura.player.visibility.Visibility;
|
|
+import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
|
|
+import net.minecraft.world.entity.EntityType;
|
|
+import net.minecraft.world.level.block.Block;
|
|
+import net.minecraft.world.level.block.Blocks;
|
|
+// Sakura end
|
|
|
|
public class ServerEntity {
|
|
|
|
@@ -284,6 +291,18 @@ public class ServerEntity {
|
|
this.entity.startSeenByPlayer(player);
|
|
}
|
|
|
|
+ // Sakura start - visibility api
|
|
+ protected Packet<ClientGamePacketListener> createEntityPacket(Entity entity, ServerPlayer entityplayer) {
|
|
+ if (entity.isPrimedTNT && entityplayer.visibility.isToggled(Visibility.Setting.FLASHING_TNT)) {
|
|
+ return new ClientboundAddEntityPacket(entity.getId(), entity.getUUID(),
|
|
+ entity.getX(), entity.getY(), entity.getZ(), 0, 0, EntityType.FALLING_BLOCK,
|
|
+ Block.getId(Blocks.TNT.defaultBlockState()), entity.getDeltaMovement(), entity.getYHeadRot());
|
|
+ } else {
|
|
+ return entity.getAddEntityPacket();
|
|
+ }
|
|
+ }
|
|
+ // Sakura end
|
|
+
|
|
public void sendPairingData(ServerPlayer player, Consumer<Packet<ClientGamePacketListener>> sender) {
|
|
if (this.entity.isRemoved()) {
|
|
// CraftBukkit start - Remove useless error spam, just return
|
|
@@ -292,12 +311,19 @@ public class ServerEntity {
|
|
// CraftBukkit end
|
|
}
|
|
|
|
- Packet<ClientGamePacketListener> packet = this.entity.getAddEntityPacket();
|
|
+ Packet<ClientGamePacketListener> packet = this.createEntityPacket(this.entity, player); // Sakura - visibility api
|
|
|
|
this.yHeadRotp = Mth.floor(this.entity.getYHeadRot() * 256.0F / 360.0F);
|
|
sender.accept(packet);
|
|
if (this.trackedDataValues != null) {
|
|
- sender.accept(new ClientboundSetEntityDataPacket(this.entity.getId(), this.trackedDataValues));
|
|
+ // Sakura start - visibility api
|
|
+ if (this.entity.isPrimedTNT && player.visibility.isToggled(Visibility.Setting.FLASHING_TNT)) {
|
|
+ // Could modifying this break something elsewhere?
|
|
+ trackedDataValues.removeIf((data) -> data.id() == 8);
|
|
+ }
|
|
+
|
|
+ sender.accept(new ClientboundSetEntityDataPacket(this.entity.getId(), trackedDataValues));
|
|
+ // Sakura end
|
|
}
|
|
|
|
boolean flag = this.trackDelta;
|
|
@@ -367,6 +393,32 @@ public class ServerEntity {
|
|
}
|
|
|
|
}
|
|
+
|
|
+ // Sakura start - visibility api
|
|
+ private void broadcastEntityData(List<SynchedEntityData.DataValue<?>> packedValues) {
|
|
+ Packet<?> packet0 = new ClientboundSetEntityDataPacket(this.entity.getId(), packedValues);
|
|
+ Packet<?> packet1 = null;
|
|
+
|
|
+ if (this.entity.isPrimedTNT) {
|
|
+ var copyOfDirtyItems = Lists.newArrayList(packedValues);
|
|
+ copyOfDirtyItems.removeIf((data) -> data.id() == 8);
|
|
+
|
|
+ if (!copyOfDirtyItems.isEmpty()) {
|
|
+ packet1 = new ClientboundSetEntityDataPacket(this.entity.getId(), copyOfDirtyItems);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ for (var connection : trackedPlayers) {
|
|
+ var player = connection.getPlayer();
|
|
+
|
|
+ if (!this.entity.isPrimedTNT || !player.visibility.isToggled(Visibility.Setting.FLASHING_TNT)) {
|
|
+ connection.send(packet0);
|
|
+ } else if (packet1 != null) {
|
|
+ connection.send(packet1);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ // Sakura end
|
|
|
|
private void sendDirtyEntityData() {
|
|
SynchedEntityData datawatcher = this.entity.getEntityData();
|
|
@@ -374,7 +426,7 @@ public class ServerEntity {
|
|
|
|
if (list != null) {
|
|
this.trackedDataValues = datawatcher.getNonDefaultValues();
|
|
- this.broadcastAndSend(new ClientboundSetEntityDataPacket(this.entity.getId(), list));
|
|
+ this.broadcastEntityData(list); // Sakura - visibility api
|
|
}
|
|
|
|
if (this.entity instanceof LivingEntity) {
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
index 033f24f57cca49bba4a36c50c4b1860645d95440..5eee6ce1122ea21bd3ceaf4bb1ac365b9aa0d6da 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
@@ -1962,7 +1962,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
|
while (iterator.hasNext()) {
|
|
ServerPlayer entityplayer = (ServerPlayer) iterator.next();
|
|
|
|
- if (entityplayer.distanceToSqr(x, y, z) < 4096.0D) {
|
|
+ if (entityplayer.distanceToSqr(x, y, z) < 4096.0D && !entityplayer.visibility.isToggled(me.samsuik.sakura.player.visibility.Visibility.Setting.EXPLOSIONS)) { // Sakura - visibility api
|
|
entityplayer.connection.send(new ClientboundExplodePacket(x, y, z, power, explosion.getToBlow(), (Vec3) explosion.getHitPlayers().get(entityplayer), explosion.getBlockInteraction(), explosion.getSmallExplosionParticles(), explosion.getLargeExplosionParticles(), explosion.getExplosionSound()));
|
|
}
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
index be05a52be037042c6158100e2ce880b8ed415d53..3b2b020c5a756a9eb3f100277d96c95a10b2de29 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -261,6 +261,7 @@ public class ServerPlayer extends Player {
|
|
public final int[] mobCounts = new int[MOBCATEGORY_TOTAL_ENUMS]; // Paper
|
|
// Paper end - mob spawning rework
|
|
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 String displayName;
|
|
@@ -567,6 +568,15 @@ public class ServerPlayer extends Player {
|
|
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
|
|
|
|
}
|
|
|
|
@@ -633,6 +643,13 @@ public class ServerPlayer extends Player {
|
|
});
|
|
}
|
|
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
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
|
index d28d0ef6105ddeb562ddf31ae9088739856941fc..0328179cb0134b54e61a4b60b98a780d9abeeaba 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
|
|
@@ -40,6 +40,23 @@ import org.bukkit.craftbukkit.util.Waitable;
|
|
import org.bukkit.event.player.PlayerKickEvent;
|
|
import org.bukkit.event.player.PlayerResourcePackStatusEvent;
|
|
// CraftBukkit end
|
|
+// Sakura start
|
|
+import com.mojang.datafixers.util.Pair;
|
|
+import me.samsuik.sakura.player.visibility.Visibility.Setting;
|
|
+import net.minecraft.world.level.block.Blocks;
|
|
+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.ClientboundLevelChunkPacketData;
|
|
+import net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData.BlockEntityTagOutput;
|
|
+import net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket;
|
|
+import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
|
|
+import net.minecraft.world.level.block.DiodeBlock;
|
|
+import net.minecraft.world.level.block.entity.BlockEntityType;
|
|
+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 {
|
|
|
|
@@ -247,6 +264,61 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
|
|
} else if (packet instanceof ClientboundSetDefaultSpawnPositionPacket) {
|
|
ClientboundSetDefaultSpawnPositionPacket packet6 = (ClientboundSetDefaultSpawnPositionPacket) packet;
|
|
this.player.compassTarget = CraftLocation.toBukkit(packet6.pos, this.getCraftPlayer().getWorld());
|
|
+ // Sakura start - visibility api
|
|
+ } else if (!player.visibility.isModified()) {
|
|
+ // Skip players that haven't modified their settings
|
|
+ } else if (packet instanceof ClientboundSetEquipmentPacket equipment
|
|
+ && player.visibility.isToggled(Setting.ENCHANTMENT_GLINT)) {
|
|
+ var slots = new java.util.ArrayList<Pair<net.minecraft.world.entity.EquipmentSlot, net.minecraft.world.item.ItemStack>>();
|
|
+
|
|
+ for (int i = 0; i < equipment.getSlots().size(); i++) {
|
|
+ var pair = equipment.getSlots().get(i);
|
|
+ var itemstack = pair.getSecond();
|
|
+
|
|
+ if (itemstack.isEnchanted()) {
|
|
+ var copy = itemstack.copy();
|
|
+ copy.getTag().remove("ench");
|
|
+ itemstack = copy;
|
|
+ }
|
|
+
|
|
+ slots.add(new Pair<>(pair.getFirst(), itemstack));
|
|
+ }
|
|
+
|
|
+ packet = new ClientboundSetEquipmentPacket(equipment.getEntity(), slots);
|
|
+ } else if (packet instanceof ClientboundBlockEntityDataPacket blockdata
|
|
+ && player.visibility.isToggled(Setting.SPAWNERS)
|
|
+ && player.level().getBlockIfLoaded(blockdata.getPos()) == Blocks.SPAWNER) {
|
|
+ packet = new ClientboundBlockUpdatePacket(blockdata.getPos(), Blocks.BLACK_STAINED_GLASS.defaultBlockState());
|
|
+ } else if (packet instanceof ClientboundBlockUpdatePacket updatePacket) {
|
|
+ if (player.visibility.isToggled(Setting.SPAWNERS) && updatePacket.blockState.getBlock() == Blocks.SPAWNER) {
|
|
+ packet = new ClientboundBlockUpdatePacket(updatePacket.getPos(), Blocks.BLACK_STAINED_GLASS.defaultBlockState());
|
|
+ } else if (player.visibility.isToggled(Setting.REDSTONE)
|
|
+ && (updatePacket.blockState.getBlock() instanceof DiodeBlock
|
|
+ || updatePacket.blockState.getBlock() instanceof RedStoneWireBlock)) {
|
|
+ return;
|
|
+ } else if (player.visibility.isToggled(Setting.PISTONS)
|
|
+ && (updatePacket.blockState.getBlock() instanceof PistonBaseBlock
|
|
+ || updatePacket.blockState.getBlock() instanceof PistonHeadBlock)) {
|
|
+ return;
|
|
+ }
|
|
+ } else if (packet instanceof ClientboundSectionBlocksUpdatePacket sectionPacket) {
|
|
+ for (var state : sectionPacket.states) {
|
|
+ if (player.visibility.isToggled(Setting.REDSTONE)
|
|
+ && (state.getBlock() instanceof DiodeBlock
|
|
+ || state.getBlock() instanceof RedStoneWireBlock)) {
|
|
+ return;
|
|
+ } else if (player.visibility.isToggled(Setting.PISTONS)
|
|
+ && (state.getBlock() instanceof PistonBaseBlock
|
|
+ || state.getBlock() instanceof PistonHeadBlock)) {
|
|
+ return;
|
|
+ }
|
|
+ }
|
|
+ } else if (packet instanceof ClientboundBlockEventPacket blockevent
|
|
+ && player.visibility.isToggled(Setting.PISTONS)
|
|
+ && (blockevent.getBlock() instanceof PistonBaseBlock
|
|
+ || blockevent.getBlock() instanceof PistonHeadBlock)) {
|
|
+ return;
|
|
+ // Sakura end
|
|
}
|
|
// CraftBukkit end
|
|
boolean flag = !this.suspendFlushingOnServerThread || !this.server.isSameThread();
|
|
@@ -257,8 +329,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 8b630fc4da8a7fda08c416e70c22463f04c3b6b5..6d9cf8bb81597489729b57a8834bf0293471fbea 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -3114,6 +3114,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 1be10c57e374ad4018c08d96cfb69397a2f541d3..33a317696c62243952bbf686ff3e52a776672599 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -535,6 +535,8 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
|
this.teleportTo(worldserver, null);
|
|
}
|
|
// Paper end - make end portalling safe
|
|
+ public boolean isPrimedTNT; // Sakura
|
|
+ public boolean isFallingBlock; // Sakura
|
|
|
|
public boolean isLegacyTrackingEntity = false;
|
|
|
|
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 45c07733f03b5c11f6d8e820f65dc950c70d9a67..3ec931c9aa9e2857e0c24eeb47c1048ace05f6fe 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
@@ -73,6 +73,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 c3e47426382296d650fa00ce0bc1a82bf23c7877..62a3cd512d473d5ed673386d5c15091a09426945 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
|
|
@@ -38,6 +38,7 @@ public class PrimedTnt extends Entity implements TraceableEntity {
|
|
public PrimedTnt(EntityType<? extends PrimedTnt> type, Level world) {
|
|
super(type, world);
|
|
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/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
|
|
index 646433f2db609f19dcc9da64232f3a3ab4a9d171..1d00a1499d9921ff66eaaf405fbbc0f44497fa0d 100644
|
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
|
@@ -226,6 +226,8 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
|
|
|
public abstract ResourceKey<LevelStem> getTypeKey();
|
|
|
|
+ public final it.unimi.dsi.fastutil.longs.Long2IntMap minimalTNT = new it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap(); // Sakura - visibility api
|
|
+
|
|
protected Level(WritableLevelData worlddatamutable, ResourceKey<Level> resourcekey, RegistryAccess iregistrycustom, Holder<DimensionType> holder, Supplier<ProfilerFiller> supplier, boolean flag, boolean flag1, long i, int j, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider, org.bukkit.World.Environment env, java.util.function.Function<org.spigotmc.SpigotWorldConfig, io.papermc.paper.configuration.WorldConfiguration> paperWorldConfigCreator, Supplier<me.samsuik.sakura.configuration.WorldConfiguration> sakuraWorldConfigCreator, java.util.concurrent.Executor executor) { // Sakura // Paper - Async-Anti-Xray - Pass executor
|
|
this.spigotConfig = new org.spigotmc.SpigotWorldConfig(((net.minecraft.world.level.storage.PrimaryLevelData) worlddatamutable).getLevelName()); // Spigot
|
|
this.paperConfig = paperWorldConfigCreator.apply(this.spigotConfig); // Paper
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
index da63b4050be25dcb91d04df8c2fcc643cbb0751d..2331c21068720528d87bdb9e3f1bb76ea6fd45dd 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -494,6 +494,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) {
|