mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
121 lines
8.1 KiB
Diff
121 lines
8.1 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
|
|
|
|
Removed since Gale 1.20.6
|
|
Mojang added attributes that can control player's `Entity Interaction Range`
|
|
and `Block Interaction Range` for every player since 1.20.5
|
|
|
|
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 a7b217ddbcbf92513bd38101fdfca2075505e267..840dc3c57dd60d5f16155fc0c6f8c9fea49685c9 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 allow digging into unloaded chunks; 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 ec0cf74e977d3ba4cbd43572af8f7fd4a496462f..9025505e7c8ac81d97a553e0ebbeb5727bd69bb6 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -250,7 +250,7 @@ import org.bukkit.inventory.SmithingInventory;
|
|
public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl implements ServerGamePacketListener, ServerPlayerConnection, TickablePacketListener {
|
|
|
|
static final Logger LOGGER = LogUtils.getLogger();
|
|
- 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");
|
|
@@ -328,6 +328,13 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
|
private boolean justTeleported = false;
|
|
// 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) {
|
|
@@ -1928,7 +1935,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
|
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;
|
|
|
|
@@ -2720,7 +2727,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
|
|
|
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 9caf067fcfbf74bbf260bf9149122f7ff8f317e4..a0bd0093bd232070c5826eb7271e490d9138db58 100644
|
|
--- a/src/main/java/net/minecraft/world/item/BrushItem.java
|
|
+++ b/src/main/java/net/minecraft/world/item/BrushItem.java
|
|
@@ -4,6 +4,7 @@ import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.core.particles.BlockParticleOption;
|
|
import net.minecraft.core.particles.ParticleTypes;
|
|
+import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
|
import net.minecraft.sounds.SoundEvent;
|
|
import net.minecraft.sounds.SoundEvents;
|
|
import net.minecraft.sounds.SoundSource;
|
|
@@ -97,7 +98,7 @@ public class BrushItem extends Item {
|
|
|
|
private HitResult calculateHitResult(Player user) {
|
|
return ProjectileUtil.getHitResultOnViewVector(
|
|
- user, entity -> !entity.isSpectator() && entity.isPickable(), (double)Player.getPickRange(user.isCreative())
|
|
+ user, entity -> !entity.isSpectator() && entity.isPickable(), Math.sqrt(ServerGamePacketListenerImpl.getMaxInteractionDistanceSquared(user.level())) - 1.0D // Gale - make max interaction distance configurable
|
|
);
|
|
}
|
|
|
|
diff --git a/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java b/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java
|
|
index 5d499e77800466210473e36b2355873807b9f86a..c5b23bafb7909130a8a294e3b5bf94daa313ee11 100644
|
|
--- a/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java
|
|
+++ b/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java
|
|
@@ -9,6 +9,7 @@ import io.papermc.paper.configuration.PaperConfigurations;
|
|
import net.minecraft.resources.ResourceLocation;
|
|
import org.slf4j.Logger;
|
|
import org.spigotmc.SpigotWorldConfig;
|
|
+import org.spongepowered.configurate.objectmapping.meta.PostProcess;
|
|
import org.spongepowered.configurate.objectmapping.meta.Setting;
|
|
|
|
@SuppressWarnings({"FieldCanBeLocal", "FieldMayBeFinal", "NotNullFieldNotInitialized", "InnerClassMayBeStatic"})
|
|
@@ -130,6 +131,16 @@ public class GaleWorldConfiguration extends ConfigurationPart {
|
|
public boolean hideFlamesOnEntitiesWithFireResistance = false; // Gale - Slice - hide flames on entities with fire resistance
|
|
public boolean tryRespawnEnderDragonAfterEndCrystalPlace = true; // Gale - Pufferfish - make ender dragon respawn attempt after placing end crystals configurable
|
|
|
|
+ // Gale start - make max interaction distance configurable
|
|
+ public double playerMaxInteractionDistance = -1.0;
|
|
+ public transient double playerMaxInteractionDistanceSquared;
|
|
+ // Gale end - make max interaction distance configurable
|
|
+
|
|
+ @PostProcess
|
|
+ public void postProcess() {
|
|
+ this.playerMaxInteractionDistanceSquared = this.playerMaxInteractionDistance * this.playerMaxInteractionDistance; // Gale - make max interaction distance configurable
|
|
+ }
|
|
+
|
|
}
|
|
|
|
}
|