mirror of
https://github.com/AtlasMediaGroup/Scissors.git
synced 2024-11-27 07:05:39 +00:00
Fix a few of my patches being formatted incorrectly & fix the Minecart/Boat lag/crash exploit (#13)
* Fix a few of my patches being formatted incorrectly * Limit amount of vehicle collision checks to 3 and discard vehicles if they collide with more than 15 other entities
This commit is contained in:
parent
dc1a5399f7
commit
6f32742d79
@ -44,7 +44,7 @@ index d02339a07e1da56fd5dc171a5e32b00d63fa555c..fe6cb52573ee50a2c02d7add38b5e841
|
|||||||
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
|
+++ b/src/main/java/net/minecraft/world/item/ItemStack.java
|
||||||
@@ -1,5 +1,6 @@
|
@@ -1,5 +1,6 @@
|
||||||
package net.minecraft.world.item;
|
package net.minecraft.world.item;
|
||||||
|
|
||||||
+import com.github.atlasmediagroup.scissors.NbtUtility;
|
+import com.github.atlasmediagroup.scissors.NbtUtility;
|
||||||
import com.google.common.collect.HashMultimap;
|
import com.google.common.collect.HashMultimap;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
@ -175,10 +175,10 @@ index d02339a07e1da56fd5dc171a5e32b00d63fa555c..fe6cb52573ee50a2c02d7add38b5e841
|
|||||||
+import java.util.function.Predicate;
|
+import java.util.function.Predicate;
|
||||||
+import java.util.stream.Collectors;
|
+import java.util.stream.Collectors;
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
|
|
||||||
public final class ItemStack {
|
public final class ItemStack {
|
||||||
@@ -245,6 +219,13 @@ public final class ItemStack {
|
@@ -245,6 +219,13 @@ public final class ItemStack {
|
||||||
|
|
||||||
// CraftBukkit - break into own method
|
// CraftBukkit - break into own method
|
||||||
private void load(CompoundTag nbttagcompound) {
|
private void load(CompoundTag nbttagcompound) {
|
||||||
+ // Scissors start - Reset large tags
|
+ // Scissors start - Reset large tags
|
||||||
@ -202,7 +202,7 @@ index d02339a07e1da56fd5dc171a5e32b00d63fa555c..fe6cb52573ee50a2c02d7add38b5e841
|
|||||||
+ }
|
+ }
|
||||||
+ // Scissors end
|
+ // Scissors end
|
||||||
}
|
}
|
||||||
|
|
||||||
return nbt;
|
return nbt;
|
||||||
@@ -815,6 +800,9 @@ public final class ItemStack {
|
@@ -815,6 +800,9 @@ public final class ItemStack {
|
||||||
}
|
}
|
||||||
@ -220,7 +220,7 @@ index 14da2997b5fff4434b1fe8d5a1b3109dde143740..a4385cea2d472611cfc7ef43662367bb
|
|||||||
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
||||||
@@ -1,16 +1,12 @@
|
@@ -1,16 +1,12 @@
|
||||||
package org.bukkit.craftbukkit.inventory;
|
package org.bukkit.craftbukkit.inventory;
|
||||||
|
|
||||||
-import static org.bukkit.craftbukkit.inventory.CraftMetaItem.*;
|
-import static org.bukkit.craftbukkit.inventory.CraftMetaItem.*;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
-import java.util.Map;
|
-import java.util.Map;
|
||||||
@ -238,7 +238,7 @@ index 14da2997b5fff4434b1fe8d5a1b3109dde143740..a4385cea2d472611cfc7ef43662367bb
|
|||||||
@@ -19,6 +15,11 @@ import org.bukkit.inventory.ItemStack;
|
@@ -19,6 +15,11 @@ import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.material.MaterialData;
|
import org.bukkit.material.MaterialData;
|
||||||
|
|
||||||
+import java.util.Map;
|
+import java.util.Map;
|
||||||
+
|
+
|
||||||
+import static org.bukkit.craftbukkit.inventory.CraftMetaItem.ENCHANTMENTS_ID;
|
+import static org.bukkit.craftbukkit.inventory.CraftMetaItem.ENCHANTMENTS_ID;
|
||||||
@ -246,4 +246,4 @@ index 14da2997b5fff4434b1fe8d5a1b3109dde143740..a4385cea2d472611cfc7ef43662367bb
|
|||||||
+
|
+
|
||||||
@DelegateDeserialization(ItemStack.class)
|
@DelegateDeserialization(ItemStack.class)
|
||||||
public final class CraftItemStack extends ItemStack {
|
public final class CraftItemStack extends ItemStack {
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ index 99a5074adbe2a254ae6115b3548f1fcd30ba2489..68ae4dfe3f4a77605b19607b5f04a2a6
|
|||||||
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||||
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||||
@@ -623,7 +623,7 @@ public abstract class LivingEntity extends Entity {
|
@@ -623,7 +623,7 @@ public abstract class LivingEntity extends Entity {
|
||||||
|
|
||||||
protected void tickDeath() {
|
protected void tickDeath() {
|
||||||
++this.deathTime;
|
++this.deathTime;
|
||||||
- if (this.deathTime >= 20 && !this.isRemoved() && !this.level.isClientSide()) { // CraftBukkit - (this.deathTicks == 20) -> (this.deathTicks >= 20 && !this.dead)
|
- if (this.deathTime >= 20 && !this.isRemoved() && !this.level.isClientSide()) { // CraftBukkit - (this.deathTicks == 20) -> (this.deathTicks >= 20 && !this.dead)
|
||||||
|
@ -0,0 +1,109 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Business Goose <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 309bafd257d4932cfd69c2c212b32306938cd234..17c6aef70089730d9ca3d20d242f6755851b9494 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;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import net.minecraft.BlockUtil;
|
||||||
|
import net.minecraft.Util;
|
||||||
|
@@ -109,6 +110,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
|
||||||
|
|
||||||
|
@@ -425,8 +427,10 @@ public abstract class AbstractMinecart extends Entity {
|
||||||
|
if (this.getMinecartType() == AbstractMinecart.Type.RIDEABLE && this.getDeltaMovement().horizontalDistanceSqr() > 0.01D) {
|
||||||
|
List<Entity> list = this.level.getEntities(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 - Add a collision debounce
|
||||||
|
+ if (!list.isEmpty() && (System.currentTimeMillis() - lastLargeCollision) >= TimeUnit.SECONDS.toMillis(5)) { // Using TimeUnit for better code readability
|
||||||
|
+ // Scissors - Limit amount of vehicle collision checks to 3 maximum
|
||||||
|
+ for (int l = 0; l < Math.min(3, list.size()); ++l) {
|
||||||
|
Entity entity = (Entity) list.get(l);
|
||||||
|
|
||||||
|
if (!(entity instanceof Player) && !(entity instanceof IronGolem) && !(entity instanceof AbstractMinecart) && !this.isVehicle() && !entity.isPassenger()) {
|
||||||
|
@@ -453,6 +457,16 @@ public abstract class AbstractMinecart extends Entity {
|
||||||
|
entity.push(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+ // Scissors - Add a collision debounce
|
||||||
|
+ if (list.size() > 3) {
|
||||||
|
+ lastLargeCollision = System.currentTimeMillis();
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ // Scissors - Delete entity if the collision amount is over 15
|
||||||
|
+ if (list.size() > 15) {
|
||||||
|
+ this.discard();
|
||||||
|
+ }
|
||||||
|
}
|
||||||
|
} 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 391454a58d18d7373b974e094fd62514ca0d0b6b..52b75015c89be054ef2bfe1f4780a69540b0f032 100644
|
||||||
|
--- a/src/main/java/net/minecraft/world/entity/vehicle/Boat.java
|
||||||
|
+++ b/src/main/java/net/minecraft/world/entity/vehicle/Boat.java
|
||||||
|
@@ -4,6 +4,7 @@ import com.google.common.collect.Lists;
|
||||||
|
import com.google.common.collect.UnmodifiableIterator;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
+import java.util.concurrent.TimeUnit;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import net.minecraft.BlockUtil;
|
||||||
|
import net.minecraft.core.BlockPos;
|
||||||
|
@@ -108,6 +109,7 @@ public class Boat extends Entity {
|
||||||
|
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);
|
||||||
|
@@ -400,10 +402,12 @@ public class Boat extends Entity {
|
||||||
|
this.checkInsideBlocks();
|
||||||
|
List<Entity> list = this.level.getEntities(this, this.getBoundingBox().inflate(0.20000000298023224D, -0.009999999776482582D, 0.20000000298023224D), EntitySelector.pushableBy(this));
|
||||||
|
|
||||||
|
- if (!list.isEmpty()) {
|
||||||
|
+ // Scissors - Add collision debounce
|
||||||
|
+ if (!list.isEmpty() && (System.currentTimeMillis() - lastLargeCollision) >= TimeUnit.SECONDS.toMillis(5)) { // Using TimeUnit for better code readability
|
||||||
|
boolean flag = !this.level.isClientSide && !(this.getControllingPassenger() instanceof Player);
|
||||||
|
|
||||||
|
- for (int j = 0; j < list.size(); ++j) {
|
||||||
|
+ // Scissors - Limit amount of vehicle collision checks to 3 maximum
|
||||||
|
+ for (int j = 0; j < Math.min(3, list.size()); ++j) {
|
||||||
|
Entity entity = (Entity) list.get(j);
|
||||||
|
|
||||||
|
if (!entity.hasPassenger(this)) {
|
||||||
|
@@ -414,6 +418,16 @@ public class Boat extends Entity {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+ // Scissors - Add collision debounce
|
||||||
|
+ if (list.size() > 3) {
|
||||||
|
+ lastLargeCollision = System.currentTimeMillis();
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ // Scissors - Delete entity if the collision amount is over 15
|
||||||
|
+ if (list.size() > 15) {
|
||||||
|
+ this.discard();
|
||||||
|
+ }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user