mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 08:27:43 +01:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@44ee1cd fix recipe packet limiter (#9841) PaperMC/Paper@e57af7d sync netty version with vanilla (#9842) Pufferfish Changes: pufferfish-gg/Pufferfish@0020a8b Port a patch from upstream pufferfish-gg/Pufferfish@979d3a2 Update upstream (last 1.20.1) pufferfish-gg/Pufferfish@06262c1 Initial 1.20.2 update
129 lines
5.6 KiB
Diff
129 lines
5.6 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: BillyGalbreath <blake.galbreath@gmail.com>
|
|
Date: Thu, 30 Dec 2021 09:56:43 -0600
|
|
Subject: [PATCH] Give bee counts in beehives to Purpur clients
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
index ef25e6f4a36e98279061a8f066b37be956b92d49..7951d617accb093e650d0ca30e2088b5a795d2a2 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -1019,6 +1019,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
}
|
|
public void safeShutdown(boolean waitForShutdown, boolean isRestarting) {
|
|
org.purpurmc.purpur.task.BossBarTask.stopAll(); // Purpur
|
|
+ org.purpurmc.purpur.task.BeehiveTask.instance().unregister(); // Purpur
|
|
this.isRestarting = isRestarting;
|
|
this.hasLoggedStop = true; // Paper
|
|
if (isDebugging()) io.papermc.paper.util.TraceUtil.dumpTraceForThread("Server stopped"); // Paper
|
|
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
index 21ea9ed1eaf767b7af3ccafbf5fdb88b4a9dc917..fdda6d2767749d0c2affbf3fba494e000bc47036 100644
|
|
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
@@ -375,6 +375,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
|
|
|
if (gg.pufferfish.pufferfish.PufferfishConfig.enableAsyncMobSpawning) mobSpawnExecutor.start(); // Pufferfish
|
|
org.purpurmc.purpur.task.BossBarTask.startAll(); // Purpur
|
|
+ org.purpurmc.purpur.task.BeehiveTask.instance().register(); // Purpur
|
|
return true;
|
|
}
|
|
}
|
|
diff --git a/src/main/java/org/purpurmc/purpur/task/BeehiveTask.java b/src/main/java/org/purpurmc/purpur/task/BeehiveTask.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..8a5faed6c1ac6850b87405e774e4393877d61c92
|
|
--- /dev/null
|
|
+++ b/src/main/java/org/purpurmc/purpur/task/BeehiveTask.java
|
|
@@ -0,0 +1,92 @@
|
|
+package org.purpurmc.purpur.task;
|
|
+
|
|
+import com.google.common.io.ByteArrayDataInput;
|
|
+import com.google.common.io.ByteArrayDataOutput;
|
|
+import com.google.common.io.ByteStreams;
|
|
+import io.netty.buffer.Unpooled;
|
|
+import net.minecraft.core.BlockPos;
|
|
+import net.minecraft.network.FriendlyByteBuf;
|
|
+import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
|
|
+import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
|
+import net.minecraft.resources.ResourceLocation;
|
|
+import net.minecraft.server.level.ServerPlayer;
|
|
+import net.minecraft.world.level.block.entity.BeehiveBlockEntity;
|
|
+import net.minecraft.world.level.block.entity.BlockEntity;
|
|
+import org.bukkit.Bukkit;
|
|
+import org.bukkit.craftbukkit.entity.CraftPlayer;
|
|
+import org.bukkit.craftbukkit.scheduler.MinecraftInternalPlugin;
|
|
+import org.bukkit.entity.Player;
|
|
+import org.bukkit.plugin.PluginBase;
|
|
+import org.bukkit.plugin.messaging.PluginMessageListener;
|
|
+import org.jetbrains.annotations.NotNull;
|
|
+
|
|
+public class BeehiveTask implements PluginMessageListener {
|
|
+ public static final ResourceLocation BEEHIVE_C2S = new ResourceLocation("purpur", "beehive_c2s");
|
|
+ public static final ResourceLocation BEEHIVE_S2C = new ResourceLocation("purpur", "beehive_s2c");
|
|
+
|
|
+ private static BeehiveTask instance;
|
|
+
|
|
+ public static BeehiveTask instance() {
|
|
+ if (instance == null) {
|
|
+ instance = new BeehiveTask();
|
|
+ }
|
|
+ return instance;
|
|
+ }
|
|
+
|
|
+ private final PluginBase plugin = new MinecraftInternalPlugin();
|
|
+
|
|
+ private BeehiveTask() {
|
|
+ }
|
|
+
|
|
+ public void register() {
|
|
+ Bukkit.getMessenger().registerOutgoingPluginChannel(this.plugin, BEEHIVE_S2C.toString());
|
|
+ Bukkit.getMessenger().registerIncomingPluginChannel(this.plugin, BEEHIVE_C2S.toString(), this);
|
|
+ }
|
|
+
|
|
+ public void unregister() {
|
|
+ Bukkit.getMessenger().unregisterOutgoingPluginChannel(this.plugin, BEEHIVE_S2C.toString());
|
|
+ Bukkit.getMessenger().unregisterIncomingPluginChannel(this.plugin, BEEHIVE_C2S.toString());
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void onPluginMessageReceived(@NotNull String channel, Player player, byte[] bytes) {
|
|
+ ByteArrayDataInput in = in(bytes);
|
|
+ long packedPos = in.readLong();
|
|
+ BlockPos pos = BlockPos.of(packedPos);
|
|
+
|
|
+ ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
|
|
+
|
|
+ BlockEntity blockEntity = serverPlayer.level().getBlockEntity(pos);
|
|
+ if (!(blockEntity instanceof BeehiveBlockEntity beehive)) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ ByteArrayDataOutput out = out();
|
|
+
|
|
+ out.writeInt(beehive.getOccupantCount());
|
|
+ out.writeLong(packedPos);
|
|
+
|
|
+ FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(out.toByteArray()));
|
|
+ serverPlayer.connection.send(new ClientboundCustomPayloadPacket(new CustomPacketPayload() {
|
|
+ @Override
|
|
+ public void write(final FriendlyByteBuf buf) {
|
|
+ buf.writeBytes(byteBuf.copy());
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public ResourceLocation id() {
|
|
+ return BEEHIVE_S2C;
|
|
+ }
|
|
+ }));
|
|
+ }
|
|
+
|
|
+ @SuppressWarnings("UnstableApiUsage")
|
|
+ private static ByteArrayDataOutput out() {
|
|
+ return ByteStreams.newDataOutput();
|
|
+ }
|
|
+
|
|
+ @SuppressWarnings("UnstableApiUsage")
|
|
+ private static ByteArrayDataInput in(byte[] bytes) {
|
|
+ return ByteStreams.newDataInput(bytes);
|
|
+ }
|
|
+}
|