mirror of
https://github.com/Dreeam-qwq/Gale.git
synced 2025-12-19 14:59:29 +00:00
83 lines
3.8 KiB
Diff
83 lines
3.8 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/net/minecraft/world/entity/projectile/Projectile.java b/net/minecraft/world/entity/projectile/Projectile.java
|
|
index af71a71ff11b418a43728fd464b1e673d593140f..689fede25ae3f73ebe897ab9b8abd70ead032f06 100644
|
|
--- a/net/minecraft/world/entity/projectile/Projectile.java
|
|
+++ b/net/minecraft/world/entity/projectile/Projectile.java
|
|
@@ -49,6 +49,45 @@ public abstract class Projectile extends Entity implements TraceableEntity {
|
|
super(entityType, level);
|
|
}
|
|
|
|
+ // 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 owner) {
|
|
if (owner != null) {
|
|
this.ownerUUID = owner.getUUID();
|