mirror of
https://github.com/AtlasMediaGroup/Scissors.git
synced 2024-11-27 07:05:39 +00:00
Backport latest patches from 1.17.1
This commit is contained in:
parent
1fa3f6a734
commit
04a1068b17
@ -0,0 +1,30 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Business Goose <arclicious@vivaldi.net>
|
||||
Date: Sun, 1 May 2022 01:19:36 +0100
|
||||
Subject: [PATCH] Make the maximum tag size a constant & add a method for
|
||||
getting tag size
|
||||
|
||||
|
||||
diff --git a/src/main/java/com/github/atlasmediagroup/scissors/NbtUtility.java b/src/main/java/com/github/atlasmediagroup/scissors/NbtUtility.java
|
||||
index 058203440fd071ce5edbe18391ea60f0a5fbee3a..dc09fe007247e832aacc323ddeb3541cfb447069 100644
|
||||
--- a/src/main/java/com/github/atlasmediagroup/scissors/NbtUtility.java
|
||||
+++ b/src/main/java/com/github/atlasmediagroup/scissors/NbtUtility.java
|
||||
@@ -7,11 +7,17 @@ import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class NbtUtility
|
||||
{
|
||||
+ public static final long MAXIMUM_SIZE = (256 * 1024);
|
||||
+
|
||||
+ public static long getTagSize(@Nullable CompoundTag tag) {
|
||||
+ if(tag == null) return 0;
|
||||
+ return tag.toString().getBytes(StandardCharsets.UTF_8).length;
|
||||
+ }
|
||||
|
||||
public static boolean isTooLarge(@Nullable CompoundTag tag)
|
||||
{
|
||||
if (tag == null) return false;
|
||||
- return tag.toString().getBytes(StandardCharsets.UTF_8).length > (256 * 1024);
|
||||
+ return getTagSize(tag) > MAXIMUM_SIZE;
|
||||
}
|
||||
|
||||
public static class Item
|
267
patches/server/0029-Account-for-items-inside-containers.patch
Normal file
267
patches/server/0029-Account-for-items-inside-containers.patch
Normal file
@ -0,0 +1,267 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Business Goose <arclicious@vivaldi.net>
|
||||
Date: Sun, 1 May 2022 01:20:13 +0100
|
||||
Subject: [PATCH] Account for items inside containers
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/ContainerHelper.java b/src/main/java/net/minecraft/world/ContainerHelper.java
|
||||
index 4092c7a8c2b0d9d26e6f4d97386735236300d132..ad3af6d90b68bc55c29243da8814516575299bf0 100644
|
||||
--- a/src/main/java/net/minecraft/world/ContainerHelper.java
|
||||
+++ b/src/main/java/net/minecraft/world/ContainerHelper.java
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.minecraft.world;
|
||||
|
||||
+import com.github.atlasmediagroup.scissors.NbtUtility;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import net.minecraft.core.NonNullList;
|
||||
@@ -22,10 +23,14 @@ public class ContainerHelper {
|
||||
|
||||
public static CompoundTag saveAllItems(CompoundTag nbt, NonNullList<ItemStack> stacks, boolean setIfEmpty) {
|
||||
ListTag listTag = new ListTag();
|
||||
+ // Scissors - Account for items inside containers
|
||||
+ long total = 0;
|
||||
|
||||
for(int i = 0; i < stacks.size(); ++i) {
|
||||
ItemStack itemStack = stacks.get(i);
|
||||
+
|
||||
if (!itemStack.isEmpty()) {
|
||||
+ total += NbtUtility.getTagSize(itemStack.getTag());
|
||||
CompoundTag compoundTag = new CompoundTag();
|
||||
compoundTag.putByte("Slot", (byte)i);
|
||||
itemStack.save(compoundTag);
|
||||
@@ -33,7 +38,7 @@ public class ContainerHelper {
|
||||
}
|
||||
}
|
||||
|
||||
- if (!listTag.isEmpty() || setIfEmpty) {
|
||||
+ if ((!listTag.isEmpty() || setIfEmpty) && !(total > NbtUtility.MAXIMUM_SIZE)) {
|
||||
nbt.put("Items", listTag);
|
||||
}
|
||||
|
||||
@@ -42,11 +47,18 @@ public class ContainerHelper {
|
||||
|
||||
public static void loadAllItems(CompoundTag nbt, NonNullList<ItemStack> stacks) {
|
||||
ListTag listTag = nbt.getList("Items", 10);
|
||||
+ // Scissors - Account for items inside containers
|
||||
+ long total = 0;
|
||||
|
||||
for(int i = 0; i < listTag.size(); ++i) {
|
||||
CompoundTag compoundTag = listTag.getCompound(i);
|
||||
int j = compoundTag.getByte("Slot") & 255;
|
||||
if (j >= 0 && j < stacks.size()) {
|
||||
+ total += NbtUtility.getTagSize(compoundTag);
|
||||
+ if (total >= NbtUtility.MAXIMUM_SIZE) {
|
||||
+ stacks.clear();
|
||||
+ break;
|
||||
+ }
|
||||
stacks.set(j, ItemStack.of(compoundTag));
|
||||
}
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
|
||||
index 888e1f2bc6ea4ddbbcc5466f177233f25b290459..0f19ef250a2f82e49730cb58ea43ee6bf407455a 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.minecraft.world.level.block.entity;
|
||||
|
||||
+import com.github.atlasmediagroup.scissors.NbtUtility;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap.Entry;
|
||||
@@ -211,6 +212,17 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit
|
||||
public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
|
||||
|
||||
public List<ItemStack> getContents() {
|
||||
+ // Scissors - Account for items inside containers
|
||||
+ long total = 0;
|
||||
+
|
||||
+ for (ItemStack item : this.items) {
|
||||
+ total += NbtUtility.getTagSize(item.getOrCreateTag());
|
||||
+ }
|
||||
+
|
||||
+ if (total > NbtUtility.MAXIMUM_SIZE) {
|
||||
+ this.items.clear();
|
||||
+ }
|
||||
+
|
||||
return this.items;
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/entity/BarrelBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/BarrelBlockEntity.java
|
||||
index 5a47d58071b83ea911e4cb5e1cc5468801ad0d55..c6f25cb62335fda65596ba3f4a55734a88b75bd4 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/entity/BarrelBlockEntity.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/entity/BarrelBlockEntity.java
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.minecraft.world.level.block.entity;
|
||||
|
||||
+import com.github.atlasmediagroup.scissors.NbtUtility;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.NonNullList;
|
||||
@@ -35,6 +36,17 @@ public class BarrelBlockEntity extends RandomizableContainerBlockEntity {
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getContents() {
|
||||
+ // Scissors - Account for items inside containers
|
||||
+ long total = 0;
|
||||
+
|
||||
+ for (ItemStack item : this.items) {
|
||||
+ total += NbtUtility.getTagSize(item.getOrCreateTag());
|
||||
+ }
|
||||
+
|
||||
+ if (total > NbtUtility.MAXIMUM_SIZE) {
|
||||
+ this.items.clear();
|
||||
+ }
|
||||
+
|
||||
return this.items;
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java
|
||||
index 5c0f1488c8a8100cd39a03adeccded9984722249..d1e1b29298e1e074df1966498d7f3c94b20c77f4 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.minecraft.world.level.block.entity;
|
||||
|
||||
+import com.github.atlasmediagroup.scissors.NbtUtility;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -72,6 +73,17 @@ public class BrewingStandBlockEntity extends BaseContainerBlockEntity implements
|
||||
}
|
||||
|
||||
public List<ItemStack> getContents() {
|
||||
+ // Scissors - Account for items inside containers
|
||||
+ long total = 0;
|
||||
+
|
||||
+ for (ItemStack item : this.items) {
|
||||
+ total += NbtUtility.getTagSize(item.getOrCreateTag());
|
||||
+ }
|
||||
+
|
||||
+ if (total > NbtUtility.MAXIMUM_SIZE) {
|
||||
+ this.items.clear();
|
||||
+ }
|
||||
+
|
||||
return this.items;
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/entity/ChestBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/ChestBlockEntity.java
|
||||
index e56f7d76b501dab7d549efd2fafd514a9625c24e..153c70defdd6c25203764035c97ed3d20bc9c17e 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/entity/ChestBlockEntity.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/entity/ChestBlockEntity.java
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.minecraft.world.level.block.entity;
|
||||
|
||||
+import com.github.atlasmediagroup.scissors.NbtUtility;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.NonNullList;
|
||||
@@ -41,6 +42,17 @@ public class ChestBlockEntity extends RandomizableContainerBlockEntity implement
|
||||
private int maxStack = MAX_STACK;
|
||||
|
||||
public List<ItemStack> getContents() {
|
||||
+ // Scissors - Account for items inside containers
|
||||
+ long total = 0;
|
||||
+
|
||||
+ for (ItemStack item : this.items) {
|
||||
+ total += NbtUtility.getTagSize(item.getOrCreateTag());
|
||||
+ }
|
||||
+
|
||||
+ if (total > NbtUtility.MAXIMUM_SIZE) {
|
||||
+ this.items.clear();
|
||||
+ }
|
||||
+
|
||||
return this.items;
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/entity/DispenserBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/DispenserBlockEntity.java
|
||||
index f74c5bb8e1ba42c77c59d481b871fd992483b128..10393d499fa6a5e36750ed9305d22454ef98e6cf 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/entity/DispenserBlockEntity.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/entity/DispenserBlockEntity.java
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.minecraft.world.level.block.entity;
|
||||
|
||||
+import com.github.atlasmediagroup.scissors.NbtUtility;
|
||||
import java.util.Random;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.NonNullList;
|
||||
@@ -30,6 +31,17 @@ public class DispenserBlockEntity extends RandomizableContainerBlockEntity {
|
||||
private int maxStack = MAX_STACK;
|
||||
|
||||
public List<ItemStack> getContents() {
|
||||
+ // Scissors - Account for items inside containers
|
||||
+ long total = 0;
|
||||
+
|
||||
+ for (ItemStack item : this.items) {
|
||||
+ total += NbtUtility.getTagSize(item.getOrCreateTag());
|
||||
+ }
|
||||
+
|
||||
+ if (total > NbtUtility.MAXIMUM_SIZE) {
|
||||
+ this.items.clear();
|
||||
+ }
|
||||
+
|
||||
return this.items;
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
||||
index d241b25acc223982109495542fd17e0fbdf53437..ab952ef090ca5183340b014e0aae3aef553a4803 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.minecraft.world.level.block.entity;
|
||||
|
||||
+import com.github.atlasmediagroup.scissors.NbtUtility;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.function.BooleanSupplier;
|
||||
@@ -53,7 +54,19 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
||||
private int maxStack = MAX_STACK;
|
||||
|
||||
public List<ItemStack> getContents() {
|
||||
+ // Scissors - Account for items inside containers
|
||||
+ long total = 0;
|
||||
+
|
||||
+ for (ItemStack item : this.items) {
|
||||
+ total += NbtUtility.getTagSize(item.getOrCreateTag());
|
||||
+ }
|
||||
+
|
||||
+ if (total > NbtUtility.MAXIMUM_SIZE) {
|
||||
+ this.items.clear();
|
||||
+ }
|
||||
+
|
||||
return this.items;
|
||||
+
|
||||
}
|
||||
|
||||
public void onOpen(CraftHumanEntity who) {
|
||||
diff --git a/src/main/java/net/minecraft/world/level/block/entity/ShulkerBoxBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/ShulkerBoxBlockEntity.java
|
||||
index b4d38a9aa8792e979c99bedc20906679ba7991c6..5bdff2d3b13b3dbd0f3f83d9ece5a42173fb7e6c 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/block/entity/ShulkerBoxBlockEntity.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/block/entity/ShulkerBoxBlockEntity.java
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.minecraft.world.level.block.entity;
|
||||
|
||||
+import com.github.atlasmediagroup.scissors.NbtUtility;
|
||||
import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
import javax.annotation.Nullable;
|
||||
@@ -252,7 +253,19 @@ public class ShulkerBoxBlockEntity extends RandomizableContainerBlockEntity impl
|
||||
|
||||
@Override
|
||||
protected NonNullList<ItemStack> getItems() {
|
||||
+ // Scissors - Account for items inside containers
|
||||
+ long total = 0;
|
||||
+
|
||||
+ for (ItemStack item : this.itemStacks) {
|
||||
+ total += NbtUtility.getTagSize(item.getOrCreateTag());
|
||||
+ }
|
||||
+
|
||||
+ if (total > NbtUtility.MAXIMUM_SIZE) {
|
||||
+ this.itemStacks.clear();
|
||||
+ }
|
||||
+
|
||||
return this.itemStacks;
|
||||
+
|
||||
}
|
||||
|
||||
@Override
|
@ -0,0 +1,109 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Telesphoreo <me@telesphoreo.me>
|
||||
Date: Sun, 1 May 2022 14:23:35 -0500
|
||||
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 96a7bfd921e59f298f0ee502d356cc3552c30ce8..6c1a489f03ecd7dfef161822cf6910f6119c082b 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;
|
||||
@@ -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
|
||||
|
||||
@@ -422,8 +424,10 @@ 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()) {
|
||||
- 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()) {
|
||||
@@ -450,6 +454,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 0dbc85c450797d7384e641f80e1b1f8c56fd14fc..99e9867dfc0b3ba8b11dd95c264794f2f0079994 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;
|
||||
@@ -106,6 +107,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);
|
||||
@@ -398,10 +400,12 @@ public class Boat extends Entity {
|
||||
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()) {
|
||||
+ // 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((Entity) this)) {
|
||||
@@ -412,6 +416,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