mirror of
https://github.com/Dreeam-qwq/Gale.git
synced 2025-12-19 14:59:29 +00:00
134 lines
8.4 KiB
Diff
134 lines
8.4 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: GPL-3.0 (https://www.gnu.org/licenses/gpl-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 baf3e79489e310f443788bc917c553ae7ea86c89..f830ff98ac6e94fa4f0c9d85bcdd8f3816ecc645 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 35f88385ed5b7a5a22486d801052f61300a97fe1..c6d13f1df78d93fb4a21e6733c4ca7d22464bded 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -256,7 +256,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");
|
|
@@ -354,6 +354,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) {
|
|
@@ -2012,7 +2019,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;
|
|
|
|
@@ -2876,7 +2883,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 392e0c346ee9f11d21bcc78c5c59f2baab5f391d..243a76badb7e09ce4dcf7d5dd8ed57d55768b341 100644
|
|
--- a/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java
|
|
+++ b/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java
|
|
@@ -271,7 +271,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
|
|
/**
|
|
@@ -293,6 +293,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 {
|
|
|
|
@@ -325,6 +339,11 @@ public class GaleWorldConfiguration extends ConfigurationPart {
|
|
|
|
public boolean tryRespawnEnderDragonAfterEndCrystalPlace = true; // Gale - Pufferfish - make ender dragon respawn attempt after placing end crystals configurable
|
|
|
|
+ @Override
|
|
+ public void postProcess() {
|
|
+ this.playerMaxInteractionDistanceSquared = this.playerMaxInteractionDistance * this.playerMaxInteractionDistance; // Gale - make max interaction distance configurable
|
|
+ }
|
|
+
|
|
}
|
|
|
|
}
|