Scissors/patches/server/0017-Limit-amount-of-vehicle-collision-checks-to-3-and-di.patch

101 lines
5.3 KiB
Diff
Raw Normal View History

2022-07-28 03:57:50 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Allink <arclicious@vivaldi.net>
Date: Thu, 21 Apr 2022 13:52:32 +0100
2022-07-28 03:57:50 +00:00
Subject: [PATCH] Limit amount of vehicle collision checks to 3 and discard
vehicles if they collide with more than 15 other entities
diff --git a/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java b/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java
2024-02-24 22:32:31 +00:00
index d514ec1e4cbdc579c3a61533998437903afdc8b6..7ee1f3552b81bff834c6f414e611e8b05463fc6f 100644
2022-07-28 03:57:50 +00:00
--- a/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java
+++ b/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java
@@ -8,6 +8,7 @@ import com.mojang.datafixers.util.Pair;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.TimeUnit; // Scissors
2022-07-28 03:57:50 +00:00
import javax.annotation.Nullable;
import net.minecraft.BlockUtil;
import net.minecraft.Util;
2023-12-11 00:23:09 +00:00
@@ -104,6 +105,7 @@ public abstract class AbstractMinecart extends VehicleEntity {
2023-12-29 18:36:48 +00:00
private double flyingX = 0.95;
private double flyingY = 0.95;
private double flyingZ = 0.95;
2022-07-28 03:57:50 +00:00
+ private long lastLargeCollision = 0L; // Scissors - Add a collision debounce
public double maxSpeed = 0.4D;
// CraftBukkit end
2023-12-11 00:23:09 +00:00
@@ -384,8 +386,8 @@ public abstract class AbstractMinecart extends VehicleEntity {
2022-07-28 03:57:50 +00:00
if (this.getMinecartType() == AbstractMinecart.Type.RIDEABLE && this.getDeltaMovement().horizontalDistanceSqr() > 0.01D) {
2023-06-09 00:58:46 +00:00
List<Entity> list = this.level().getEntities((Entity) this, this.getBoundingBox().inflate(0.20000000298023224D, 0.0D, 0.20000000298023224D), EntitySelector.pushableBy(this));
2022-07-28 03:57:50 +00:00
- if (!list.isEmpty()) {
2023-10-15 22:45:13 +00:00
- Iterator iterator = list.iterator();
+ if (!list.isEmpty() && (System.currentTimeMillis() - lastLargeCollision) >= TimeUnit.SECONDS.toMillis(5)) { // Scissors - add collision debounce, using TimeUnit for better code readability
+ Iterator iterator = list.size() <= 15 ? list.iterator() : list.subList(0, 15).iterator(); // Scissors
2022-07-28 03:57:50 +00:00
2023-10-15 22:45:13 +00:00
while (iterator.hasNext()) {
Entity entity = (Entity) iterator.next();
2023-12-11 00:23:09 +00:00
@@ -414,6 +416,14 @@ public abstract class AbstractMinecart extends VehicleEntity {
2022-07-28 03:57:50 +00:00
entity.push(this);
}
}
+
+ // Scissors start - Add a collision debounce
2022-07-28 03:57:50 +00:00
+ if (list.size() > 15) {
2024-02-24 22:32:31 +00:00
+ this.discard(null);
+ } else if (list.size() > 3) {
+ lastLargeCollision = System.currentTimeMillis();
2022-07-28 03:57:50 +00:00
+ }
+ // Scissors end
2022-07-28 03:57:50 +00:00
}
} else {
2023-10-15 22:45:13 +00:00
Iterator iterator1 = this.level().getEntities(this, this.getBoundingBox().inflate(0.20000000298023224D, 0.0D, 0.20000000298023224D)).iterator();
2022-07-28 03:57:50 +00:00
diff --git a/src/main/java/net/minecraft/world/entity/vehicle/Boat.java b/src/main/java/net/minecraft/world/entity/vehicle/Boat.java
2024-02-24 22:32:31 +00:00
index db6aa75d642f4a7258f197933671907faf79c8f2..e4490494a865e129c69d7df3742f61860763a8d8 100644
2022-07-28 03:57:50 +00:00
--- a/src/main/java/net/minecraft/world/entity/vehicle/Boat.java
+++ b/src/main/java/net/minecraft/world/entity/vehicle/Boat.java
2022-12-11 06:04:11 +00:00
@@ -5,6 +5,7 @@ import com.google.common.collect.UnmodifiableIterator;
2022-07-28 03:57:50 +00:00
import java.util.Iterator;
import java.util.List;
2022-12-11 06:04:11 +00:00
import java.util.function.IntFunction;
+import java.util.concurrent.TimeUnit; // Scissors
2022-07-28 03:57:50 +00:00
import javax.annotation.Nullable;
import net.minecraft.BlockUtil;
import net.minecraft.core.BlockPos;
2023-12-11 00:23:09 +00:00
@@ -108,6 +109,7 @@ public class Boat extends VehicleEntity implements VariantHolder<Boat.Type> {
2022-07-28 03:57:50 +00:00
public double unoccupiedDeceleration = -1;
public boolean landBoats = false;
// CraftBukkit end
+ private long lastLargeCollision = 0L; // Scissors - Add a collision debounce
public Boat(EntityType<? extends Boat> type, Level world) {
super(type, world);
2023-12-11 00:23:09 +00:00
@@ -408,9 +410,9 @@ public class Boat extends VehicleEntity implements VariantHolder<Boat.Type> {
2022-07-28 03:57:50 +00:00
this.checkInsideBlocks();
2023-06-09 00:58:46 +00:00
List<Entity> list = this.level().getEntities((Entity) this, this.getBoundingBox().inflate(0.20000000298023224D, -0.009999999776482582D, 0.20000000298023224D), EntitySelector.pushableBy(this));
2022-07-28 03:57:50 +00:00
- if (!list.isEmpty()) {
+ if (!list.isEmpty() && (System.currentTimeMillis() - lastLargeCollision) >= TimeUnit.SECONDS.toMillis(5)) { // Scissors - add collision debounce, using TimeUnit for better code readability
2023-06-09 00:58:46 +00:00
boolean flag = !this.level().isClientSide && !(this.getControllingPassenger() instanceof Player);
2023-10-15 22:45:13 +00:00
- Iterator iterator = list.iterator();
+ Iterator iterator = list.size() <= 15 ? list.iterator() : list.subList(0, 15).iterator(); // Scissors
2022-07-28 03:57:50 +00:00
2023-10-15 22:45:13 +00:00
while (iterator.hasNext()) {
Entity entity = (Entity) iterator.next();
2023-12-11 00:23:09 +00:00
@@ -423,6 +425,14 @@ public class Boat extends VehicleEntity implements VariantHolder<Boat.Type> {
2022-07-28 03:57:50 +00:00
}
}
}
+
+ // Scissors start - Add collision debounce
2022-07-28 03:57:50 +00:00
+ if (list.size() > 15) {
2024-02-24 22:32:31 +00:00
+ this.discard(null);
+ } else if (list.size() > 3) {
+ lastLargeCollision = System.currentTimeMillis();
2022-07-28 03:57:50 +00:00
+ }
+ // Scissors end
2022-07-28 03:57:50 +00:00
}
}