--- a/net/minecraft/util/SortedArraySet.java
+++ b/net/minecraft/util/SortedArraySet.java
@@ -14,6 +14,14 @@
     T[] contents;
     int size;
 
+    // Paper start - rewrite chunk system
+    public SortedArraySet(final SortedArraySet<T> other) {
+        this.comparator = other.comparator;
+        this.size = other.size;
+        this.contents = Arrays.copyOf(other.contents, this.size);
+    }
+    // Paper end - rewrite chunk system
+
     private SortedArraySet(int initialCapacity, Comparator<T> comparator) {
         this.comparator = comparator;
         if (initialCapacity < 0) {
@@ -22,13 +30,48 @@
             this.contents = (T[])castRawArray(new Object[initialCapacity]);
         }
     }
+    // Paper start - optimise removeIf
+    @Override
+    public boolean removeIf(java.util.function.Predicate<? super T> filter) {
+        // prev. impl used an iterator, which could be n^2 and creates garbage
+        int i = 0, len = this.size;
+        T[] backingArray = this.contents;
+
+        for (;;) {
+            if (i >= len) {
+                return false;
+            }
+            if (!filter.test(backingArray[i])) {
+                ++i;
+                continue;
+            }
+            break;
+        }
+
+        // we only want to write back to backingArray if we really need to
+
+        int lastIndex = i; // this is where new elements are shifted to
+
+        for (; i < len; ++i) {
+            T curr = backingArray[i];
+            if (!filter.test(curr)) { // if test throws we're screwed
+                backingArray[lastIndex++] = curr;
+            }
+        }
+
+        // cleanup end
+        Arrays.fill(backingArray, lastIndex, len, null);
+        this.size = lastIndex;
+        return true;
+    }
+    // Paper end - optimise removeIf
 
     public static <T extends Comparable<T>> SortedArraySet<T> create() {
         return create(10);
     }
 
     public static <T extends Comparable<T>> SortedArraySet<T> create(int initialCapacity) {
-        return new SortedArraySet<>(initialCapacity, Comparator.naturalOrder());
+        return new SortedArraySet<>(initialCapacity, Comparator.<T>naturalOrder()); // Paper - decompile fix
     }
 
     public static <T> SortedArraySet<T> create(Comparator<T> comparator) {
@@ -110,6 +153,31 @@
         }
     }
 
+    // Paper start - rewrite chunk system
+    public T replace(T object) {
+        int i = this.findIndex(object);
+        if (i >= 0) {
+            T old = this.contents[i];
+            this.contents[i] = object;
+            return old;
+        } else {
+            this.addInternal(object, getInsertionPosition(i));
+            return object;
+        }
+    }
+
+    public T removeAndGet(T object) {
+        int i = this.findIndex(object);
+        if (i >= 0) {
+            final T ret = this.contents[i];
+            this.removeInternal(i);
+            return ret;
+        } else {
+            return null;
+        }
+    }
+    // Paper end - rewrite chunk system
+
     @Override
     public boolean remove(Object object) {
         int i = this.findIndex((T)object);
