Style changes

Mostly protected -> private in final classes
This commit is contained in:
Spottedleaf
2024-05-23 06:06:50 -07:00
parent 60fe328a92
commit 2ce869b7a4
8 changed files with 58 additions and 66 deletions

View File

@@ -27,7 +27,7 @@ public final class ClientProfilerInstance implements ProfilerFiller {
if (MEASURE_CPU_TIME) {
THREAD_MX_BEAN.setThreadCpuTimeEnabled(true);
} else {
LOGGER.warn("TickRegionScheduler CPU time measurement is not available");
LOGGER.warn("ClientProfilerInstance CPU time measurement is not available");
}
}

View File

@@ -9,7 +9,7 @@ import net.minecraft.world.level.chunk.GlobalPalette;
public final class IBlockDataList {
static final GlobalPalette<BlockState> GLOBAL_PALETTE = new GlobalPalette<>(Block.BLOCK_STATE_REGISTRY);
private static final GlobalPalette<BlockState> GLOBAL_PALETTE = new GlobalPalette<>(Block.BLOCK_STATE_REGISTRY);
// map of location -> (index | (location << 16) | (palette id << 32))
private final Short2LongOpenHashMap map = new Short2LongOpenHashMap(2, 0.8f);

View File

@@ -9,16 +9,16 @@ public final class IteratorSafeOrderedReferenceSet<E> {
public static final int ITERATOR_FLAG_SEE_ADDITIONS = 1 << 0;
protected final Reference2IntLinkedOpenHashMap<E> indexMap;
protected int firstInvalidIndex = -1;
private final Reference2IntLinkedOpenHashMap<E> indexMap;
private int firstInvalidIndex = -1;
/* list impl */
protected E[] listElements;
protected int listSize;
private E[] listElements;
private int listSize;
protected final double maxFragFactor;
private final double maxFragFactor;
protected int iteratorCount;
private int iteratorCount;
public IteratorSafeOrderedReferenceSet() {
this(16, 0.75f, 16, 0.2);
@@ -74,7 +74,7 @@ public final class IteratorSafeOrderedReferenceSet<E> {
}
*/
protected final double getFragFactor() {
private double getFragFactor() {
return 1.0 - ((double)this.indexMap.size() / (double)this.listSize);
}
@@ -148,7 +148,7 @@ public final class IteratorSafeOrderedReferenceSet<E> {
return true;
}
protected void defrag() {
private void defrag() {
if (this.firstInvalidIndex < 0) {
return; // nothing to do
}
@@ -236,17 +236,17 @@ public final class IteratorSafeOrderedReferenceSet<E> {
}
protected static final class BaseIterator<E> implements IteratorSafeOrderedReferenceSet.Iterator<E> {
private static final class BaseIterator<E> implements IteratorSafeOrderedReferenceSet.Iterator<E> {
protected final IteratorSafeOrderedReferenceSet<E> set;
protected final boolean canFinish;
protected final int maxIndex;
protected int nextIndex;
protected E pendingValue;
protected boolean finished;
protected E lastReturned;
private final IteratorSafeOrderedReferenceSet<E> set;
private final boolean canFinish;
private final int maxIndex;
private int nextIndex;
private E pendingValue;
private boolean finished;
private E lastReturned;
protected BaseIterator(final IteratorSafeOrderedReferenceSet<E> set, final boolean canFinish, final int maxIndex) {
private BaseIterator(final IteratorSafeOrderedReferenceSet<E> set, final boolean canFinish, final int maxIndex) {
this.set = set;
this.canFinish = canFinish;
this.maxIndex = maxIndex;

View File

@@ -7,15 +7,24 @@ import java.util.NoSuchElementException;
public final class ReferenceList<E> implements Iterable<E> {
protected final Reference2IntOpenHashMap<E> referenceToIndex = new Reference2IntOpenHashMap<>(2, 0.8f);
private final Reference2IntOpenHashMap<E> referenceToIndex = new Reference2IntOpenHashMap<>(2, 0.8f);
{
this.referenceToIndex.defaultReturnValue(Integer.MIN_VALUE);
}
protected static final Object[] EMPTY_LIST = new Object[0];
private static final Object[] EMPTY_LIST = new Object[0];
protected Object[] references = EMPTY_LIST;
protected int count;
private E[] references;
private int count;
public ReferenceList() {
this((E[])EMPTY_LIST, 0);
}
public ReferenceList(final E[] array, final int count) {
this.references = array;
this.count = count;
}
public int size() {
return this.count;
@@ -52,7 +61,7 @@ public final class ReferenceList<E> implements Iterable<E> {
return false; // already in this list
}
Object[] list = this.references;
E[] list = this.references;
if (list.length == count) {
// resize required
@@ -69,17 +78,21 @@ public final class ReferenceList<E> implements Iterable<E> {
if (index < 0 || index >= this.count) {
throw new IndexOutOfBoundsException("Index: " + index + " is out of bounds, size: " + this.count);
}
return (E)this.references[index];
return this.references[index];
}
public E getUnchecked(final int index) {
return (E)this.references[index];
return this.references[index];
}
public Object[] getRawData() {
return this.references;
}
public E[] getRawDataUnchecked() {
return this.references;
}
public void clear() {
this.referenceToIndex.clear();
Arrays.fill(this.references, 0, this.count, null);
@@ -102,7 +115,7 @@ public final class ReferenceList<E> implements Iterable<E> {
if (this.current >= ReferenceList.this.count) {
throw new NoSuchElementException();
}
return this.lastRet = (E)ReferenceList.this.references[this.current++];
return this.lastRet = ReferenceList.this.references[this.current++];
}
@Override

View File

@@ -1,18 +1,23 @@
package ca.spottedleaf.moonrise.common.list;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Comparator;
public final class SortedList<E> {
protected static final Object[] EMPTY_LIST = new Object[0];
private static final Object[] EMPTY_LIST = new Object[0];
protected Comparator<? super E> comparator;
protected Object[] elements;
protected int count;
private Comparator<? super E> comparator;
private E[] elements;
private int count;
public SortedList(final Comparator<? super E> comparator) {
this.elements = EMPTY_LIST;
this((E[])EMPTY_LIST, comparator);
}
public SortedList(final E[] elements, final Comparator<? super E> comparator) {
this.elements = elements;
this.comparator = comparator;
}
@@ -45,7 +50,7 @@ public final class SortedList<E> {
}
public int add(final E element) {
E[] elements = (E[])this.elements;
E[] elements = this.elements;
final int count = this.count;
this.count = count + 1;
final Comparator<? super E> comparator = this.comparator;
@@ -59,7 +64,7 @@ public final class SortedList<E> {
elements[count] = element;
return idx;
} else {
final Object[] newElements = (E[])new Object[(int)Math.max(4L, count * 2L)]; // overflow results in negative
final E[] newElements = (E[])Array.newInstance(elements.getClass().getComponentType(), (int)Math.max(4L, count * 2L));
System.arraycopy(elements, 0, newElements, 0, idx);
newElements[idx] = element;
System.arraycopy(elements, idx, newElements, idx + 1, count - idx);
@@ -84,12 +89,12 @@ public final class SortedList<E> {
if (idx < 0 || idx >= this.count) {
throw new IndexOutOfBoundsException(idx);
}
return (E)this.elements[idx];
return this.elements[idx];
}
public E remove(final E element) {
E[] elements = (E[])this.elements;
E[] elements = this.elements;
final int count = this.count;
final Comparator<? super E> comparator = this.comparator;

View File

@@ -9,12 +9,6 @@ import net.minecraft.world.phys.Vec3;
public final class CoordinateUtils {
// dx, dz are relative to the target chunk
// dx, dz in [-radius, radius]
public static int getNeighbourMappedIndex(final int dx, final int dz, final int radius) {
return (dx + radius) + (2 * radius + 1)*(dz + radius);
}
// the chunk keys are compatible with vanilla
public static long getChunkKey(final BlockPos pos) {
@@ -105,24 +99,6 @@ public final class CoordinateUtils {
return (int)(key << (Long.SIZE - (SECTION_Z_SHIFT + SECTION_Z_BITS)) >> (Long.SIZE - SECTION_Z_BITS));
}
// the block coordinates are not necessarily compatible with vanilla's
public static int getBlockCoordinate(final double blockCoordinate) {
return Mth.floor(blockCoordinate);
}
public static long getBlockKey(final int x, final int y, final int z) {
return ((long)x & 0x7FFFFFF) | (((long)z & 0x7FFFFFF) << 27) | ((long)y << 54);
}
public static long getBlockKey(final BlockPos pos) {
return ((long)pos.getX() & 0x7FFFFFF) | (((long)pos.getZ() & 0x7FFFFFF) << 27) | ((long)pos.getY() << 54);
}
public static long getBlockKey(final Entity entity) {
return ((long)entity.getX() & 0x7FFFFFF) | (((long)entity.getZ() & 0x7FFFFFF) << 27) | ((long)entity.getY() << 54);
}
public static int getBlockX(final Vec3 pos) {
return Mth.floor(pos.x);
}

View File

@@ -115,7 +115,6 @@ public abstract class LevelChunkMixin extends ChunkAccess implements GetBlockChu
final LevelChunkSection section = sections[sectionY];
// note: when empty hasOnlyAir() is true, so we always fall to defaultBlockState
if (!section.hasOnlyAir()) {
final int index = (x & 15) | ((z & 15) << 4) | ((y & 15) << (4+4));
return section.states.get(index);

View File

@@ -24,7 +24,7 @@ public final class ZeroCollidingReferenceStateTable {
public ZeroCollidingReferenceStateTable(final StateHolder<?, ?> state, final Map<Property<?>, Comparable<?>> this_map) {
this.this_state = state;
this.this_index_table = this.create_table(this_map.keySet());
this.this_index_table = create_table(this_map.keySet());
int max_id = -1;
for (final Property<?> property : this_map.keySet()) {
@@ -49,7 +49,7 @@ public final class ZeroCollidingReferenceStateTable {
final Set<Property<?>> combined = new HashSet<>(table.rowKeySet());
combined.addAll(this_map.keySet());
this.index_table = this.create_table(combined);
this.index_table = create_table(combined);
int max_id = -1;
for (final Property<?> property : combined) {
@@ -90,8 +90,7 @@ public final class ZeroCollidingReferenceStateTable {
}
}
protected long[] create_table(final Collection<Property<?>> collection) {
private static long[] create_table(final Collection<Property<?>> collection) {
int max_id = -1;
for (final Property<?> property : collection) {
final int id = ((PropertyAccess)property).moonrise$getId();
@@ -143,7 +142,7 @@ public final class ZeroCollidingReferenceStateTable {
return values[withId];
}
protected static int lookup_vindex(final Property<?> property, final long[] index_table) {
private static int lookup_vindex(final Property<?> property, final long[] index_table) {
final int id = ((PropertyAccess)property).moonrise$getId();
final long bitset_mask = (1L << (id & 31));
final long lower_mask = bitset_mask - 1;