9
0
mirror of https://github.com/Dreeam-qwq/Gale.git synced 2025-12-23 00:39:22 +00:00
Files
Gale/patches/server/0116-Make-max-interaction-distance-configurable.patch
2023-06-14 08:10:05 +02:00

134 lines
8.3 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 1635fee928d64f4d2c336dca6675ed4641918830..d65b9d2d9070d8dee2c144c9b37d6605a59cfafe 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
@@ -174,7 +174,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 93b8c00c16b26f4b76f35d1aa32560375097aef4..8d90209a01020d44626f56e2cb0dd5eca300f699 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) {
@@ -1969,7 +1976,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;
@@ -2828,7 +2835,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/net/minecraft/world/item/BrushItem.java b/src/main/java/net/minecraft/world/item/BrushItem.java
index d025232b43af3cb8dc28dff2e3e05c72e490901d..06d75d94af6aff29d542d0c5e150d8f7f8632e82 100644
--- a/src/main/java/net/minecraft/world/item/BrushItem.java
+++ b/src/main/java/net/minecraft/world/item/BrushItem.java
@@ -29,7 +29,6 @@ import net.minecraft.world.phys.Vec3;
public class BrushItem extends Item {
public static final int ANIMATION_DURATION = 10;
private static final int USE_DURATION = 200;
- private static final double MAX_BRUSH_DISTANCE = Math.sqrt(ServerGamePacketListenerImpl.MAX_INTERACTION_DISTANCE) - 1.0D;
public BrushItem(Item.Properties settings) {
super(settings);
@@ -108,7 +107,7 @@ public class BrushItem extends Item {
private HitResult calculateHitResult(LivingEntity user) {
return ProjectileUtil.getHitResultOnViewVector(user, (entity) -> {
return !entity.isSpectator() && entity.isPickable();
- }, MAX_BRUSH_DISTANCE);
+ }, Math.sqrt(ServerGamePacketListenerImpl.getMaxInteractionDistanceSquared(user.level())) - 1.0D); // Gale - make max interaction distance configurable
}
public void spawnDustParticles(Level world, BlockHitResult hitResult, BlockState state, Vec3 userRotation, HumanoidArm arm) {
diff --git a/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java b/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java
index edb4e3b5bde5309bd61a6f1605c71633facae7af..c0274ed66bfe3a2bd8c67d0af807bc090dfabf7d 100644
--- a/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java
+++ b/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java
@@ -273,7 +273,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
/**
@@ -296,6 +296,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 {
@@ -330,6 +344,11 @@ public class GaleWorldConfiguration extends ConfigurationPart {
}
+ @Override
+ public void postProcess() {
+ this.playerMaxInteractionDistanceSquared = this.playerMaxInteractionDistance * this.playerMaxInteractionDistance; // Gale - make max interaction distance configurable
+ }
+
}
}