mirror of
https://github.com/AtlasMediaGroup/Scissors.git
synced 2024-11-16 18:46:12 +00:00
101 lines
5.4 KiB
Diff
101 lines
5.4 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Allink <arclicious@vivaldi.net>
|
|
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 44a6118d3bd67a95180f750c17967561946e2e87..8aece67eba8d6b558bc2441b8b8e599f86e12e4f 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;
|
|
@@ -111,6 +112,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,8 @@ public abstract class AbstractMinecart extends Entity {
|
|
if (this.getMinecartType() == AbstractMinecart.Type.RIDEABLE && this.getDeltaMovement().horizontalDistanceSqr() > 0.01D) {
|
|
List<Entity> list = this.level().getEntities((Entity) this, this.getBoundingBox().inflate(0.20000000298023224D, 0.0D, 0.20000000298023224D), EntitySelector.pushableBy(this));
|
|
|
|
- if (!list.isEmpty()) {
|
|
- 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
|
|
|
|
while (iterator.hasNext()) {
|
|
Entity entity = (Entity) iterator.next();
|
|
@@ -462,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 iterator1 = 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 5c07da62c82bc70138f6cb5007629d6974be69ac..301a72dffd4ac58333d987e85d22136498d2d82a 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;
|
|
@@ -112,6 +113,7 @@ public class Boat extends Entity implements VariantHolder<Boat.Type> {
|
|
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);
|
|
@@ -465,9 +467,9 @@ public class Boat extends Entity implements VariantHolder<Boat.Type> {
|
|
this.checkInsideBlocks();
|
|
List<Entity> 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);
|
|
- Iterator iterator = list.iterator();
|
|
+ Iterator iterator = list.size() <= 15 ? list.iterator() : list.subList(0, 15).iterator(); // Scissors
|
|
|
|
while (iterator.hasNext()) {
|
|
Entity entity = (Entity) iterator.next();
|
|
@@ -480,6 +482,14 @@ public class Boat extends Entity implements VariantHolder<Boat.Type> {
|
|
}
|
|
}
|
|
}
|
|
+
|
|
+ // Scissors start - Add collision debounce
|
|
+ if (list.size() > 15) {
|
|
+ this.discard();
|
|
+ } else if (list.size() > 3) {
|
|
+ lastLargeCollision = System.currentTimeMillis();
|
|
+ }
|
|
+ // Scissors end
|
|
}
|
|
|
|
}
|