From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Allink Date: Thu, 21 Apr 2022 13:52:32 +0100 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 index ee4f924afe15c9a4d96af7a55b357076c7b28501..602337661d96a21d13c4da66622b7d845613c5de 100644 --- 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 import javax.annotation.Nullable; import net.minecraft.BlockUtil; import net.minecraft.Util; @@ -106,6 +107,7 @@ public abstract class AbstractMinecart extends Entity { private double flyingX = 0.949999988079071D; // Paper - restore vanilla precision private double flyingY = 0.949999988079071D; // Paper - restore vanilla precision private double flyingZ = 0.949999988079071D; // Paper - restore vanilla precision + private long lastLargeCollision = 0L; // Scissors - Add a collision debounce public double maxSpeed = 0.4D; // CraftBukkit end @@ -432,8 +434,10 @@ public abstract class AbstractMinecart extends Entity { if (this.getMinecartType() == AbstractMinecart.Type.RIDEABLE && this.getDeltaMovement().horizontalDistanceSqr() > 0.01D) { List list = this.level.getEntities((Entity) this, this.getBoundingBox().inflate(0.20000000298023224D, 0.0D, 0.20000000298023224D), EntitySelector.pushableBy(this)); - if (!list.isEmpty()) { - for (int l = 0; l < list.size(); ++l) { + // Scissors start + if (!list.isEmpty() && (System.currentTimeMillis() - lastLargeCollision) >= TimeUnit.SECONDS.toMillis(5)) { // Using TimeUnit for better code readability + for (int l = 0; l < Math.min(3, list.size()); ++l) { + // Scissors end Entity entity = (Entity) list.get(l); if (!(entity instanceof Player) && !(entity instanceof IronGolem) && !(entity instanceof AbstractMinecart) && !this.isVehicle() && !entity.isPassenger()) { @@ -460,6 +464,14 @@ public abstract class AbstractMinecart extends Entity { entity.push(this); } } + + // Scissors start - Add a collision debounce + if (list.size() > 15) { + this.discard(); + } else if (list.size() > 3) { + lastLargeCollision = System.currentTimeMillis(); + } + // Scissors end } } else { Iterator iterator = this.level.getEntities(this, this.getBoundingBox().inflate(0.20000000298023224D, 0.0D, 0.20000000298023224D)).iterator(); diff --git a/src/main/java/net/minecraft/world/entity/vehicle/Boat.java b/src/main/java/net/minecraft/world/entity/vehicle/Boat.java index 12e3209c5246ede89daaf8455fe70b4a517e12f6..c5bc5e38ea6b856b1cc3e9c3907f697235b32c50 100644 --- a/src/main/java/net/minecraft/world/entity/vehicle/Boat.java +++ b/src/main/java/net/minecraft/world/entity/vehicle/Boat.java @@ -5,6 +5,7 @@ import com.google.common.collect.UnmodifiableIterator; import java.util.Iterator; import java.util.List; import java.util.function.IntFunction; +import java.util.concurrent.TimeUnit; // Scissors import javax.annotation.Nullable; import net.minecraft.BlockUtil; import net.minecraft.core.BlockPos; @@ -109,6 +110,7 @@ public class Boat extends Entity implements VariantHolder { public double unoccupiedDeceleration = -1; public boolean landBoats = false; // CraftBukkit end + private long lastLargeCollision = 0L; // Scissors - Add a collision debounce public Boat(EntityType type, Level world) { super(type, world); @@ -421,10 +423,10 @@ public class Boat extends Entity implements VariantHolder { this.checkInsideBlocks(); List list = this.level.getEntities((Entity) this, this.getBoundingBox().inflate(0.20000000298023224D, -0.009999999776482582D, 0.20000000298023224D), EntitySelector.pushableBy(this)); - if (!list.isEmpty()) { + if (!list.isEmpty() && (System.currentTimeMillis() - lastLargeCollision) >= TimeUnit.SECONDS.toMillis(5)) { // Scissors - add collision debounce, using TimeUnit for better code readability boolean flag = !this.level.isClientSide && !(this.getControllingPassenger() instanceof Player); - for (int j = 0; j < list.size(); ++j) { + for (int j = 0; j < Math.min(3, list.size()); ++j) { // Scissors - Limit amount of vehicle collision checks to 3 maximum Entity entity = (Entity) list.get(j); if (!entity.hasPassenger((Entity) this)) { @@ -435,6 +437,14 @@ public class Boat extends Entity implements VariantHolder { } } } + + // Scissors start - Add collision debounce + if (list.size() > 15) { + this.discard(); + } else if (list.size() > 3) { + lastLargeCollision = System.currentTimeMillis(); + } + // Scissors end } }