9
0
mirror of https://github.com/Dreeam-qwq/Gale.git synced 2025-12-23 08:49:28 +00:00
Files
Gale/patches/server/0119-Make-max-interaction-distance-configurable.patch
2023-06-08 23:16:40 +02:00

113 lines
7.0 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Sat, 24 Dec 2022 23:30:35 +0100
Subject: [PATCH] Make max interaction distance configurable
License: AGPL-3.0 (https://www.gnu.org/licenses/agpl-3.0.html)
Gale - https://galemc.org
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
index 1d33c02088c150189d7f4b0aa27f6a1de96b11cf..4c8275728175ebc1fdc8d0e8d0ba8398cefa0e17 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
@@ -173,7 +173,7 @@ public class ServerPlayerGameMode {
private void debugLogging(BlockPos pos, boolean success, int sequence, String reason) {}
public void handleBlockBreakAction(BlockPos pos, ServerboundPlayerActionPacket.Action action, Direction direction, int worldHeight, int sequence) {
- if (this.player.getEyePosition().distanceToSqr(Vec3.atCenterOf(pos)) > ServerGamePacketListenerImpl.MAX_INTERACTION_DISTANCE) {
+ if (this.player.getEyePosition().distanceToSqr(Vec3.atCenterOf(pos)) > ServerGamePacketListenerImpl.getMaxInteractionDistanceSquared(this.player.level)) { // Gale - make max interaction distance configurable
if (true) return; // Paper - Don't notify if unreasonably far away
this.debugLogging(pos, false, sequence, "too far");
} else if (pos.getY() >= worldHeight) {
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 851c97fc36e31926a2f241759e12daeee09f45c9..5d61d3ead44175654f39760f9a7fdd4914b002b3 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -254,7 +254,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
static final Logger LOGGER = LogUtils.getLogger();
private static final int LATENCY_CHECK_INTERVAL = 15000;
- public static final double MAX_INTERACTION_DISTANCE = Mth.square(6.0D);
+ public static final double DEFAULT_MAX_INTERACTION_DISTANCE_SQUARED = Mth.square(6.0D); // Gale - make max interaction distance configurable
private static final int NO_BLOCK_UPDATES_TO_ACK = -1;
private static final int TRACKED_MESSAGE_DISCONNECT_THRESHOLD = 4096;
private static final Component CHAT_VALIDATION_FAILED = Component.translatable("multiplayer.disconnect.chat_validation_failed");
@@ -352,6 +352,13 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
}
// CraftBukkit end
+ // Gale start - make max interaction distance configurable
+ public static double getMaxInteractionDistanceSquared(Level level) {
+ var config = level.galeConfig().gameplayMechanics;
+ return config.playerMaxInteractionDistance < 0 ? ServerGamePacketListenerImpl.DEFAULT_MAX_INTERACTION_DISTANCE_SQUARED : config.playerMaxInteractionDistanceSquared;
+ }
+ // Gale end - make max interaction distance configurable
+
@Override
public void tick() {
if (this.ackBlockChangesUpTo > -1) {
@@ -1968,7 +1975,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
BlockPos blockposition = movingobjectpositionblock.getBlockPos();
Vec3 vec3d1 = Vec3.atCenterOf(blockposition);
- if (this.player.getEyePosition().distanceToSqr(vec3d1) <= ServerGamePacketListenerImpl.MAX_INTERACTION_DISTANCE) {
+ if (this.player.getEyePosition().distanceToSqr(vec3d1) <= ServerGamePacketListenerImpl.getMaxInteractionDistanceSquared(this.player.level)) { // Gale - make max interaction distance configurable
Vec3 vec3d2 = vec3d.subtract(vec3d1);
double d0 = 1.0000001D;
@@ -2827,7 +2834,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
AABB axisalignedbb = entity.getBoundingBox();
- if (axisalignedbb.distanceToSqr(this.player.getEyePosition()) < ServerGamePacketListenerImpl.MAX_INTERACTION_DISTANCE) {
+ if (axisalignedbb.distanceToSqr(this.player.getEyePosition()) < ServerGamePacketListenerImpl.getMaxInteractionDistanceSquared(this.player.level)) { // Gale - make max interaction distance configurable
packet.dispatch(new ServerboundInteractPacket.Handler() {
private void performInteraction(InteractionHand enumhand, ServerGamePacketListenerImpl.EntityInteraction playerconnection_a, PlayerInteractEntityEvent event) { // CraftBukkit
ItemStack itemstack = ServerGamePacketListenerImpl.this.player.getItemInHand(enumhand);
diff --git a/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java b/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java
index 49ac6d7d324707b86364b393123ad695cfbe28e2..a16c549ee1715c24acb93d17da396355e16e9158 100644
--- a/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java
+++ b/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java
@@ -275,7 +275,7 @@ public class GaleWorldConfiguration extends ConfigurationPart {
}
public GameplayMechanics gameplayMechanics;
- public class GameplayMechanics extends ConfigurationPart {
+ public class GameplayMechanics extends ConfigurationPart.Post {
// Gale start - variable entity wake-up duration
/**
@@ -298,6 +298,20 @@ public class GaleWorldConfiguration extends ConfigurationPart {
public boolean arrowMovementResetsDespawnCounter = true; // Gale - Purpur - make arrow movement resetting despawn counter configurable
public boolean hideFlamesOnEntitiesWithFireResistance = false; // Gale - Slice - hide flames on entities with fire resistance
+ // Gale start - make max interaction distance configurable
+ /**
+ * The maximum distance for blocks with which a player can interact with left- or right-clicking.
+ * Any value < 0 uses the default max distance, which is currently 6.0.
+ * <ul>
+ * <li><i>Default</i>: -1.0</li>
+ * <li><i>Vanilla</i>: -1.0</li>
+ * </ul>
+ */
+ public double playerMaxInteractionDistance = -1.0;
+
+ public transient double playerMaxInteractionDistanceSquared;
+ // Gale end - make max interaction distance configurable
+
public Fixes fixes;
public class Fixes extends ConfigurationPart {
@@ -332,6 +346,11 @@ public class GaleWorldConfiguration extends ConfigurationPart {
}
+ @Override
+ public void postProcess() {
+ this.playerMaxInteractionDistanceSquared = this.playerMaxInteractionDistance * this.playerMaxInteractionDistance; // Gale - make max interaction distance configurable
+ }
+
}
}