--- a/net/minecraft/util/SimpleBitStorage.java
+++ b/net/minecraft/util/SimpleBitStorage.java
@@ -204,8 +204,8 @@
     private final long mask;
     private final int size;
     private final int valuesPerLong;
-    private final int divideMul;
-    private final int divideAdd;
+    private final int divideMul; private final long divideMulUnsigned; // Paper - Perf: Optimize SimpleBitStorage; referenced in b(int) with 2 Integer.toUnsignedLong calls
+    private final int divideAdd; private final long divideAddUnsigned; // Paper - Perf: Optimize SimpleBitStorage
     private final int divideShift;
 
     public SimpleBitStorage(int elementBits, int size, int[] data) {
@@ -248,8 +248,8 @@
         this.mask = (1L << elementBits) - 1L;
         this.valuesPerLong = (char)(64 / elementBits);
         int i = 3 * (this.valuesPerLong - 1);
-        this.divideMul = MAGIC[i + 0];
-        this.divideAdd = MAGIC[i + 1];
+        this.divideMul = MAGIC[i + 0]; this.divideMulUnsigned = Integer.toUnsignedLong(this.divideMul); // Paper - Perf: Optimize SimpleBitStorage
+        this.divideAdd = MAGIC[i + 1]; this.divideAddUnsigned = Integer.toUnsignedLong(this.divideAdd); // Paper - Perf: Optimize SimpleBitStorage
         this.divideShift = MAGIC[i + 2];
         int j = (size + this.valuesPerLong - 1) / this.valuesPerLong;
         if (data != null) {
@@ -264,15 +264,15 @@
     }
 
     private int cellIndex(int index) {
-        long l = Integer.toUnsignedLong(this.divideMul);
-        long m = Integer.toUnsignedLong(this.divideAdd);
-        return (int)((long)index * l + m >> 32 >> this.divideShift);
+        //long l = Integer.toUnsignedLong(this.divideMul); // Paper - Perf: Optimize SimpleBitStorage
+        //long m = Integer.toUnsignedLong(this.divideAdd); // Paper - Perf: Optimize SimpleBitStorage
+        return (int) (index * this.divideMulUnsigned + this.divideAddUnsigned >> 32 >> this.divideShift); // Paper - Perf: Optimize SimpleBitStorage
     }
 
     @Override
-    public int getAndSet(int index, int value) {
-        Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)index);
-        Validate.inclusiveBetween(0L, this.mask, (long)value);
+    public final int getAndSet(int index, int value) { // Paper - Perf: Optimize SimpleBitStorage
+        //Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)index); // Paper - Perf: Optimize SimpleBitStorage
+        //Validate.inclusiveBetween(0L, this.mask, (long)value); // Paper - Perf: Optimize SimpleBitStorage
         int i = this.cellIndex(index);
         long l = this.data[i];
         int j = (index - i * this.valuesPerLong) * this.bits;
@@ -282,9 +282,9 @@
     }
 
     @Override
-    public void set(int index, int value) {
-        Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)index);
-        Validate.inclusiveBetween(0L, this.mask, (long)value);
+    public final void set(int index, int value) { // Paper - Perf: Optimize SimpleBitStorage
+        //Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)index); // Paper - Perf: Optimize SimpleBitStorage
+        //Validate.inclusiveBetween(0L, this.mask, (long)value); // Paper - Perf: Optimize SimpleBitStorage
         int i = this.cellIndex(index);
         long l = this.data[i];
         int j = (index - i * this.valuesPerLong) * this.bits;
@@ -292,8 +292,8 @@
     }
 
     @Override
-    public int get(int index) {
-        Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)index);
+    public final int get(int index) { // Paper - Perf: Optimize SimpleBitStorage
+        //Validate.inclusiveBetween(0L, (long)(this.size - 1), (long)index); // Paper - Perf: Optimize SimpleBitStorage
         int i = this.cellIndex(index);
         long l = this.data[i];
         int j = (index - i * this.valuesPerLong) * this.bits;
@@ -362,6 +362,40 @@
         return new SimpleBitStorage(this.bits, this.size, (long[])this.data.clone());
     }
 
+    // Paper start - block counting
+    @Override
+    public final it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap<it.unimi.dsi.fastutil.ints.IntArrayList> moonrise$countEntries() {
+        final int valuesPerLong = this.valuesPerLong;
+        final int bits = this.bits;
+        final long mask = this.mask;
+        final int size = this.size;
+
+        // we may be backed by global palette, so limit bits for init capacity
+        final it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap<it.unimi.dsi.fastutil.ints.IntArrayList> ret = new it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap<>(
+            1 << Math.min(6, bits)
+        );
+
+        int index = 0;
+
+        for (long value : this.data) {
+            int li = 0;
+            do {
+                final int paletteIdx = (int)(value & mask);
+                value >>= bits;
+
+                ret.computeIfAbsent(paletteIdx, (final int key) -> {
+                    return new it.unimi.dsi.fastutil.ints.IntArrayList();
+                }).add(index);
+
+                ++li;
+                ++index;
+            } while (li < valuesPerLong && index < size);
+        }
+
+        return ret;
+    }
+    // Paper end - block counting
+
     public static class InitializationException extends RuntimeException {
         InitializationException(String message) {
             super(message);
