Skip to content

Commit

Permalink
re-add bee count patch
Browse files Browse the repository at this point in the history
  • Loading branch information
granny committed Apr 29, 2024
1 parent fa3017b commit 2c5e308
Show file tree
Hide file tree
Showing 66 changed files with 141 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ index 29af03b8690e4d402d1e4e4516e4dc731b7b4323..56c6800ae5696397ffba2dc2e0393019
}
}
diff --git a/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
index 19e54e22ca2e024074c28dda3bbdf75ce9f1b083..2d32b5aaa2b2f33b773f9157aee4f7461c48147a 100644
index a34c44ba770ded446b7969a31d3d05016717c13b..e50954e35116ea60b68ae00191771f8d9f78b45d 100644
--- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java
+++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
@@ -434,6 +434,11 @@ public class PurpurConfig {
@@ -418,6 +418,11 @@ public class PurpurConfig {
allowWaterPlacementInTheEnd = getBoolean("settings.allow-water-placement-in-the-end", allowWaterPlacementInTheEnd);
}

Expand All @@ -44,23 +44,81 @@ index 19e54e22ca2e024074c28dda3bbdf75ce9f1b083..2d32b5aaa2b2f33b773f9157aee4f746
public static boolean loggerSuppressInitLegacyMaterialError = false;
public static boolean loggerSuppressIgnoredAdvancementWarnings = false;
public static boolean loggerSuppressUnrecognizedRecipeErrors = false;
diff --git a/src/main/java/org/purpurmc/purpur/network/ClientboundBeehivePayload.java b/src/main/java/org/purpurmc/purpur/network/ClientboundBeehivePayload.java
new file mode 100644
index 0000000000000000000000000000000000000000..57e195fd2d457295cda6c366684be5577aeef071
--- /dev/null
+++ b/src/main/java/org/purpurmc/purpur/network/ClientboundBeehivePayload.java
@@ -0,0 +1,27 @@
+package org.purpurmc.purpur.network;
+
+import net.minecraft.core.BlockPos;
+import net.minecraft.network.FriendlyByteBuf;
+import net.minecraft.network.codec.StreamCodec;
+import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
+import net.minecraft.resources.ResourceLocation;
+import org.jetbrains.annotations.NotNull;
+
+public record ClientboundBeehivePayload(BlockPos pos, int numOfBees) implements CustomPacketPayload {
+ public static final StreamCodec<FriendlyByteBuf, ClientboundBeehivePayload> STREAM_CODEC = CustomPacketPayload.codec(ClientboundBeehivePayload::write, ClientboundBeehivePayload::new);
+ public static final Type<ClientboundBeehivePayload> TYPE = new Type<>(new ResourceLocation("purpur", "beehive_s2c"));
+
+ public ClientboundBeehivePayload(FriendlyByteBuf friendlyByteBuf) {
+ this(friendlyByteBuf.readBlockPos(), friendlyByteBuf.readInt());
+ }
+
+ private void write(FriendlyByteBuf friendlyByteBuf) {
+ friendlyByteBuf.writeBlockPos(this.pos);
+ friendlyByteBuf.writeInt(this.numOfBees);
+ }
+
+ @Override
+ public @NotNull Type<? extends CustomPacketPayload> type() {
+ return TYPE;
+ }
+}
diff --git a/src/main/java/org/purpurmc/purpur/network/ServerboundBeehivePayload.java b/src/main/java/org/purpurmc/purpur/network/ServerboundBeehivePayload.java
new file mode 100644
index 0000000000000000000000000000000000000000..27689754565bf048d1206d540913495d7194a54d
--- /dev/null
+++ b/src/main/java/org/purpurmc/purpur/network/ServerboundBeehivePayload.java
@@ -0,0 +1,26 @@
+package org.purpurmc.purpur.network;
+
+import net.minecraft.core.BlockPos;
+import net.minecraft.network.FriendlyByteBuf;
+import net.minecraft.network.codec.StreamCodec;
+import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
+import net.minecraft.resources.ResourceLocation;
+import org.jetbrains.annotations.NotNull;
+
+public record ServerboundBeehivePayload(BlockPos pos) implements CustomPacketPayload {
+ public static final StreamCodec<FriendlyByteBuf, ServerboundBeehivePayload> STREAM_CODEC = CustomPacketPayload.codec(ServerboundBeehivePayload::write, ServerboundBeehivePayload::new);
+ public static final Type<ServerboundBeehivePayload> TYPE = new Type<>(new ResourceLocation("purpur", "beehive_c2s"));
+
+ public ServerboundBeehivePayload(FriendlyByteBuf friendlyByteBuf) {
+ this(friendlyByteBuf.readBlockPos());
+ }
+
+ private void write(FriendlyByteBuf friendlyByteBuf) {
+ friendlyByteBuf.writeBlockPos(this.pos);
+ }
+
+ @Override
+ public @NotNull Type<? extends CustomPacketPayload> type() {
+ return TYPE;
+ }
+}
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..15e760d5c0465b24969df3e25bf8409faab8b62e
index 0000000000000000000000000000000000000000..e20fa234520c42e4d32a2a634fc0a2938904f983
--- /dev/null
+++ b/src/main/java/org/purpurmc/purpur/task/BeehiveTask.java
@@ -0,0 +1,96 @@
@@ -0,0 +1,66 @@
+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;
Expand All @@ -71,10 +129,10 @@ index 0000000000000000000000000000000000000000..15e760d5c0465b24969df3e25bf8409f
+import org.bukkit.plugin.PluginBase;
+import org.bukkit.plugin.messaging.PluginMessageListener;
+import org.jetbrains.annotations.NotNull;
+import org.purpurmc.purpur.network.ClientboundBeehivePayload;
+import org.purpurmc.purpur.network.ServerboundBeehivePayload;
+
+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;
+
Expand All @@ -91,58 +149,35 @@ index 0000000000000000000000000000000000000000..15e760d5c0465b24969df3e25bf8409f
+ }
+
+ public void register() {
+ Bukkit.getMessenger().registerOutgoingPluginChannel(this.plugin, BEEHIVE_S2C.toString());
+ Bukkit.getMessenger().registerIncomingPluginChannel(this.plugin, BEEHIVE_C2S.toString(), this);
+ Bukkit.getMessenger().registerOutgoingPluginChannel(this.plugin, ClientboundBeehivePayload.TYPE.id().toString());
+ Bukkit.getMessenger().registerIncomingPluginChannel(this.plugin, ServerboundBeehivePayload.TYPE.id().toString(), this);
+ }
+
+ public void unregister() {
+ Bukkit.getMessenger().unregisterOutgoingPluginChannel(this.plugin, BEEHIVE_S2C.toString());
+ Bukkit.getMessenger().unregisterIncomingPluginChannel(this.plugin, BEEHIVE_C2S.toString());
+ Bukkit.getMessenger().unregisterOutgoingPluginChannel(this.plugin, ClientboundBeehivePayload.TYPE.id().toString());
+ Bukkit.getMessenger().unregisterIncomingPluginChannel(this.plugin, ServerboundBeehivePayload.TYPE.id().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);
+ public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, byte[] bytes) {
+ FriendlyByteBuf byteBuf = new FriendlyByteBuf(Unpooled.copiedBuffer(bytes));
+ ServerboundBeehivePayload payload = ServerboundBeehivePayload.STREAM_CODEC.decode(byteBuf);
+
+ ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
+
+ // targeted block info max range specified in client at net.minecraft.client.gui.hud.DebugHud#render
+ if (!pos.getCenter().closerThan(serverPlayer.position(), 20)) return; // Targeted Block info max range is 20
+ if (serverPlayer.level().getChunkIfLoaded(pos) == null) return;
+ if (!payload.pos().getCenter().closerThan(serverPlayer.position(), 20)) return; // Targeted Block info max range is 20
+ if (serverPlayer.level().getChunkIfLoaded(payload.pos()) == null) return;
+
+ BlockEntity blockEntity = serverPlayer.level().getBlockEntity(pos);
+ BlockEntity blockEntity = serverPlayer.level().getBlockEntity(payload.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);
+ ClientboundBeehivePayload customPacketPayload = new ClientboundBeehivePayload(payload.pos(), beehive.getOccupantCount());
+ FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.buffer());
+ ClientboundBeehivePayload.STREAM_CODEC.encode(friendlyByteBuf, customPacketPayload);
+ byte[] byteArray = new byte[friendlyByteBuf.readableBytes()];
+ player.sendPluginMessage(this.plugin, customPacketPayload.type().id().toString(), byteArray);
+ }
+}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ index 58d28b6c1cc7da7d786f78308db971f7502ad844..9f274048be29ed54dd91983447beadf0
}
// Paper end - Buffer joins to world
diff --git a/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
index a34c44ba770ded446b7969a31d3d05016717c13b..f0c3566e6b03c88c0cb53a90d44627d0967d13eb 100644
index e50954e35116ea60b68ae00191771f8d9f78b45d..64fc2ae0b1f086390614f03dc15aff4037d57d68 100644
--- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java
+++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
@@ -435,8 +435,10 @@ public class PurpurConfig {
@@ -440,8 +440,10 @@ public class PurpurConfig {
}

public static boolean useUPnP = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ index af18de11dd55938b6091f5ab183bd3fe4e8df152..2c741860afa1fa4d5798c68b84ec3fe1
}

diff --git a/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
index f0c3566e6b03c88c0cb53a90d44627d0967d13eb..c5dd0979f5bce259b920c47d974f2bf6b805c045 100644
index 64fc2ae0b1f086390614f03dc15aff4037d57d68..1e28c96f5b142a28be530dfc24d67b99c3803948 100644
--- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java
+++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
@@ -382,6 +382,7 @@ public class PurpurConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ index 2391a0c59bfbf315f00ce41c5e0a03ea23a25448..1bd373d835cfcf1b43b28dbd0f138fac
} else if (source.is(DamageTypes.HOT_FLOOR)) {
cause = DamageCause.HOT_FLOOR;
diff --git a/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
index c5dd0979f5bce259b920c47d974f2bf6b805c045..4a1d8b2c412a51e4c29e3846ea9c1bde99346010 100644
index 1e28c96f5b142a28be530dfc24d67b99c3803948..cadb07b2ec32baa5f509b9da3bfd9044cee19ba4 100644
--- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java
+++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
@@ -209,8 +209,10 @@ public class PurpurConfig {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ index 395ad65503c87250c0e2fa8112208f26fd3681be..7b28ec1c6d87bad32b46c6ac6cf9e97d

voxelshape1 = (VoxelShape) iterator.next();
diff --git a/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
index 4a1d8b2c412a51e4c29e3846ea9c1bde99346010..f500c3b42a9ba346a0e4305c0169159f847e3457 100644
index cadb07b2ec32baa5f509b9da3bfd9044cee19ba4..801d269a038e68d428b31f12d372fd11ab552d50 100644
--- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java
+++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
@@ -440,9 +440,11 @@ public class PurpurConfig {
@@ -445,9 +445,11 @@ public class PurpurConfig {

public static boolean useUPnP = false;
public static boolean maxJoinsPerSecond = false;
Expand Down
Loading

0 comments on commit 2c5e308

Please sign in to comment.