9
0
mirror of https://github.com/Dreeam-qwq/Gale.git synced 2025-12-21 15:59:28 +00:00
Files
Gale/patches/server/0021-Reduce-projectile-chunk-loading.patch
2024-06-21 11:44:11 +08:00

110 lines
5.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Thu, 24 Nov 2022 12:00:55 +0100
Subject: [PATCH] Reduce projectile chunk loading
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
This patch is based on the following patch:
"Reduce projectile chunk loading"
By: Paul Sauve <paul@technove.co>
As part of: Airplane (https://github.com/TECHNOVE/Airplane)
Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
* Airplane copyright *
Airplane
Copyright (C) 2020 Technove LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
diff --git a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
index 5f7d152f41eb85f17bcded4bc8099b998e5a338b..bf1e1e7561b674ace6bfd601a5c1ddfcd203ac04 100644
--- a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
@@ -52,6 +52,45 @@ public abstract class Projectile extends Entity implements TraceableEntity {
super(type, world);
}
+ // Gale start - Airplane - reduce projectile chunk loading
+ private static int chunksLoadedThisTick = 0;
+ private static int chunksLoadedInTick;
+ private int chunksLoadedByProjectile = 0;
+
+ @Override
+ public void setPos(double x, double y, double z) {
+ int currentTick = net.minecraft.server.MinecraftServer.currentTick;
+ if (chunksLoadedInTick != currentTick) {
+ chunksLoadedInTick = currentTick;
+ chunksLoadedThisTick = 0;
+ }
+ int previousX = Mth.floor(this.getX()) >> 4, previousZ = Mth.floor(this.getZ()) >> 4;
+ int newX = Mth.floor(x) >> 4, newZ = Mth.floor(z) >> 4;
+ if (previousX != newX || previousZ != newZ) {
+ boolean isLoaded = ((net.minecraft.server.level.ServerChunkCache) this.level().getChunkSource()).getChunkAtIfLoadedImmediately(newX, newZ) != null;
+ if (!isLoaded) {
+ var maxProjectileChunkLoadsConfig = this.level().galeConfig().smallOptimizations.maxProjectileChunkLoads;
+ int maxChunkLoadsPerTick = maxProjectileChunkLoadsConfig.perTick;
+ if (maxChunkLoadsPerTick >= 0 && chunksLoadedThisTick > maxChunkLoadsPerTick) {
+ return;
+ }
+ int maxChunkLoadsPerProjectile = maxProjectileChunkLoadsConfig.perProjectile.max;
+ if (maxChunkLoadsPerProjectile >= 0 && this.chunksLoadedByProjectile >= maxChunkLoadsPerProjectile) {
+ if (maxProjectileChunkLoadsConfig.perProjectile.removeFromWorldAfterReachLimit) {
+ this.discard();
+ } else if (maxProjectileChunkLoadsConfig.perProjectile.resetMovementAfterReachLimit) {
+ this.setDeltaMovement(0, this.getDeltaMovement().y, 0);
+ }
+ return;
+ }
+ chunksLoadedThisTick++;
+ this.chunksLoadedByProjectile++;
+ }
+ }
+ super.setPos(x, y, z);
+ }
+ // Gale end - Airplane - reduce projectile chunk loading
+
public void setOwner(@Nullable Entity entity) {
if (entity != null) {
this.ownerUUID = entity.getUUID();
diff --git a/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java b/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java
index b82bb95b524c95cdefb81abef906eded0717e9a1..eabe9e6a7f99a7ad1f2a9f210f8a7489a89dc4cc 100644
--- a/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java
+++ b/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java
@@ -33,7 +33,21 @@ public class GaleWorldConfiguration extends ConfigurationPart {
public SmallOptimizations smallOptimizations;
public class SmallOptimizations extends ConfigurationPart {
- public int dummyValue = 0;
+ // Gale start - Airplane - reduce projectile chunk loading
+ public MaxProjectileChunkLoads maxProjectileChunkLoads;
+ public class MaxProjectileChunkLoads extends ConfigurationPart {
+
+ public int perTick = 10;
+
+ public PerProjectile perProjectile;
+ public class PerProjectile extends ConfigurationPart {
+ public int max = 10;
+ public boolean resetMovementAfterReachLimit = false;
+ public boolean removeFromWorldAfterReachLimit = false;
+ }
+
+ }
+ // Gale end - Airplane - reduce projectile chunk loading
}