mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-29 03:49:15 +00:00
优化一对一列表实现
This commit is contained in:
@@ -1,22 +1,16 @@
|
||||
package net.momirealms.craftengine.core.util;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
public class IntIdentityList implements IndexedIterable<Integer> {
|
||||
private final int size;
|
||||
private final List<Integer> list;
|
||||
|
||||
public IntIdentityList(int size) {
|
||||
this.size = size;
|
||||
list = new IntArrayList(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
list.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -36,6 +30,29 @@ public class IntIdentityList implements IndexedIterable<Integer> {
|
||||
|
||||
@Override
|
||||
public @NotNull Iterator<Integer> iterator() {
|
||||
return list.iterator();
|
||||
return new IntIterator(size);
|
||||
}
|
||||
}
|
||||
|
||||
private static class IntIterator implements Iterator<Integer> {
|
||||
private final int size;
|
||||
private int current;
|
||||
|
||||
public IntIterator(int size) {
|
||||
this.size = size;
|
||||
this.current = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return current < size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer next() {
|
||||
if (!hasNext()) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
return current++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ public class MCSection {
|
||||
private short nonEmptyBlockCount;
|
||||
private final PalettedContainer<Integer> serverBlockStateContainer;
|
||||
private final IndexedIterable<Integer> clientBlockStateList;
|
||||
private ReadableContainer<Integer> biomeContainer;
|
||||
private PalettedContainer<Integer> biomeContainer;
|
||||
|
||||
public MCSection(IndexedIterable<Integer> clientBlockStateList, IndexedIterable<Integer> serverBlockStateList, IndexedIterable<Integer> biomeList) {
|
||||
this.serverBlockStateContainer = new PalettedContainer<>(serverBlockStateList, 0, PalettedContainer.PaletteProvider.BLOCK_STATE);
|
||||
@@ -42,4 +42,8 @@ public class MCSection {
|
||||
public PalettedContainer<Integer> blockStateContainer() {
|
||||
return serverBlockStateContainer;
|
||||
}
|
||||
|
||||
public PalettedContainer<Integer> biomeContainer() {
|
||||
return biomeContainer;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user