reimu AAAAAAAAAAAAAAAAA
This commit is contained in:
@@ -1,197 +1,199 @@
|
|||||||
package net.gensokyoreimagined.nitori.common.world.chunk;
|
package net.gensokyoreimagined.nitori.common.world.chunk;
|
||||||
|
|
||||||
//import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
//import it.unimi.dsi.fastutil.HashCommon;
|
import it.unimi.dsi.fastutil.HashCommon;
|
||||||
//import it.unimi.dsi.fastutil.objects.Reference2IntMap;
|
import it.unimi.dsi.fastutil.objects.Reference2IntMap;
|
||||||
//import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap;
|
import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap;
|
||||||
//import net.minecraft.network.FriendlyByteBuf;
|
import net.gensokyoreimagined.nitori.mixin.chunk.palette.PaletteResizeAccessor;
|
||||||
//import net.minecraft.network.VarInt;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
//import net.minecraft.core.IdMap;
|
import net.minecraft.network.VarInt;
|
||||||
//import net.minecraft.world.level.chunk.MissingPaletteEntryException;
|
import net.minecraft.core.IdMap;
|
||||||
//import net.minecraft.world.level.chunk.Palette;
|
import net.minecraft.world.level.chunk.MissingPaletteEntryException;
|
||||||
//import net.minecraft.world.level.chunk.PaletteResize;
|
import net.minecraft.world.level.chunk.Palette;
|
||||||
//
|
import org.jetbrains.annotations.NotNull;
|
||||||
//import java.util.Arrays;
|
|
||||||
//import java.util.List;
|
import java.util.Arrays;
|
||||||
//import java.util.function.Predicate;
|
import java.util.List;
|
||||||
//
|
import java.util.function.Predicate;
|
||||||
//import static it.unimi.dsi.fastutil.Hash.FAST_LOAD_FACTOR;
|
|
||||||
//
|
import static it.unimi.dsi.fastutil.Hash.FAST_LOAD_FACTOR;
|
||||||
///**
|
|
||||||
// * Generally provides better performance over the vanilla {@link net.minecraft.world.chunk.BiMapPalette} when calling
|
/**
|
||||||
// * {@link LithiumHashPalette#index(Object)} through using a faster backing map and reducing pointer chasing.
|
* Generally provides better performance over the vanilla {@link net.minecraft.world.level.chunk.HashMapPalette} when calling
|
||||||
// */
|
* {@link LithiumHashPalette#idFor(Object)} through using a faster backing map and reducing pointer chasing.
|
||||||
//public class LithiumHashPalette<T> implements Palette<T> {
|
*/
|
||||||
// private static final int ABSENT_VALUE = -1;
|
public class LithiumHashPalette<T> implements Palette<T> {
|
||||||
//
|
private static final int ABSENT_VALUE = -1;
|
||||||
// private final IdMap<T> idList;
|
|
||||||
// private final PaletteResize<T> resizeHandler;
|
private final IdMap<T> idList;
|
||||||
// private final int indexBits;
|
// private final PaletteResize<T> resizeHandler;
|
||||||
//
|
private final PaletteResizeAccessor<T> resizeHandler;
|
||||||
// private final Reference2IntMap<T> table;
|
private final int indexBits;
|
||||||
// private T[] entries;
|
|
||||||
// private int size = 0;
|
private final Reference2IntMap<T> table;
|
||||||
//
|
private T[] entries;
|
||||||
// public LithiumHashPalette(IdMap<T> idList, PaletteResize<T> resizeHandler, int indexBits, T[] entries, Reference2IntMap<T> table, int size) {
|
private int size = 0;
|
||||||
// this.idList = idList;
|
|
||||||
// this.resizeHandler = resizeHandler;
|
public LithiumHashPalette(IdMap<T> idList, PaletteResizeAccessor<T> resizeHandler, int indexBits, T[] entries, Reference2IntMap<T> table, int size) {
|
||||||
// this.indexBits = indexBits;
|
this.idList = idList;
|
||||||
// this.entries = entries;
|
this.resizeHandler = resizeHandler;
|
||||||
// this.table = table;
|
this.indexBits = indexBits;
|
||||||
// this.size = size;
|
this.entries = entries;
|
||||||
// }
|
this.table = table;
|
||||||
//
|
this.size = size;
|
||||||
// public LithiumHashPalette(IdMap<T> idList, int bits, PaletteResizeListener<T> resizeHandler, List<T> list) {
|
}
|
||||||
// this(idList, bits, resizeHandler);
|
|
||||||
//
|
public LithiumHashPalette(IdMap<T> idList, int bits, PaletteResizeAccessor<T> resizeHandler, List<T> list) {
|
||||||
// for (T t : list) {
|
this(idList, bits, resizeHandler);
|
||||||
// this.addEntry(t);
|
|
||||||
// }
|
for (T t : list) {
|
||||||
// }
|
this.addEntry(t);
|
||||||
//
|
}
|
||||||
// @SuppressWarnings("unchecked")
|
}
|
||||||
// public LithiumHashPalette(IdMap<T> idList, int bits, PaletteResizeListener<T> resizeHandler) {
|
|
||||||
// this.idList = idList;
|
@SuppressWarnings("unchecked")
|
||||||
// this.indexBits = bits;
|
public LithiumHashPalette(IdMap<T> idList, int bits, PaletteResizeAccessor<T> resizeHandler) {
|
||||||
// this.resizeHandler = resizeHandler;
|
this.idList = idList;
|
||||||
//
|
this.indexBits = bits;
|
||||||
// int capacity = 1 << bits;
|
this.resizeHandler = resizeHandler;
|
||||||
//
|
|
||||||
// this.entries = (T[]) new Object[capacity];
|
int capacity = 1 << bits;
|
||||||
// this.table = new Reference2IntOpenHashMap<>(capacity, FAST_LOAD_FACTOR);
|
|
||||||
// this.table.defaultReturnValue(ABSENT_VALUE);
|
this.entries = (T[]) new Object[capacity];
|
||||||
// }
|
this.table = new Reference2IntOpenHashMap<>(capacity, FAST_LOAD_FACTOR);
|
||||||
//
|
this.table.defaultReturnValue(ABSENT_VALUE);
|
||||||
// @Override
|
}
|
||||||
// public int index(T obj) {
|
|
||||||
// int id = this.table.getInt(obj);
|
@Override
|
||||||
//
|
public int idFor(T obj) {
|
||||||
// if (id == ABSENT_VALUE) {
|
int id = this.table.getInt(obj);
|
||||||
// id = this.computeEntry(obj);
|
|
||||||
// }
|
if (id == ABSENT_VALUE) {
|
||||||
//
|
id = this.computeEntry(obj);
|
||||||
// return id;
|
}
|
||||||
// }
|
|
||||||
//
|
return id;
|
||||||
// @Override
|
}
|
||||||
// public boolean hasAny(Predicate<T> predicate) {
|
|
||||||
// for (int i = 0; i < this.size; ++i) {
|
@Override
|
||||||
// if (predicate.test(this.entries[i])) {
|
public boolean maybeHas(Predicate<T> predicate) {
|
||||||
// return true;
|
for (int i = 0; i < this.size; ++i) {
|
||||||
// }
|
if (predicate.test(this.entries[i])) {
|
||||||
// }
|
return true;
|
||||||
//
|
}
|
||||||
// return false;
|
}
|
||||||
// }
|
|
||||||
//
|
return false;
|
||||||
// private int computeEntry(T obj) {
|
}
|
||||||
// int id = this.addEntry(obj);
|
|
||||||
//
|
private int computeEntry(T obj) {
|
||||||
// if (id >= 1 << this.indexBits) {
|
int id = this.addEntry(obj);
|
||||||
// if (this.resizeHandler == null) {
|
|
||||||
// throw new IllegalStateException("Cannot grow");
|
if (id >= 1 << this.indexBits) {
|
||||||
// } else {
|
if (this.resizeHandler == null) {
|
||||||
// id = this.resizeHandler.onResize(this.indexBits + 1, obj);
|
throw new IllegalStateException("Cannot grow");
|
||||||
// }
|
} else {
|
||||||
// }
|
id = this.resizeHandler.callOnResize(this.indexBits + 1, obj);
|
||||||
//
|
}
|
||||||
// return id;
|
}
|
||||||
// }
|
|
||||||
//
|
return id;
|
||||||
// private int addEntry(T obj) {
|
}
|
||||||
// int nextId = this.size;
|
|
||||||
//
|
private int addEntry(T obj) {
|
||||||
// if (nextId >= this.entries.length) {
|
int nextId = this.size;
|
||||||
// this.resize(this.size);
|
|
||||||
// }
|
if (nextId >= this.entries.length) {
|
||||||
//
|
this.resize(this.size);
|
||||||
// this.table.put(obj, nextId);
|
}
|
||||||
// this.entries[nextId] = obj;
|
|
||||||
//
|
this.table.put(obj, nextId);
|
||||||
// this.size++;
|
this.entries[nextId] = obj;
|
||||||
//
|
|
||||||
// return nextId;
|
this.size++;
|
||||||
// }
|
|
||||||
//
|
return nextId;
|
||||||
// private void resize(int neededCapacity) {
|
}
|
||||||
// this.entries = Arrays.copyOf(this.entries, HashCommon.nextPowerOfTwo(neededCapacity + 1));
|
|
||||||
// }
|
private void resize(int neededCapacity) {
|
||||||
//
|
this.entries = Arrays.copyOf(this.entries, HashCommon.nextPowerOfTwo(neededCapacity + 1));
|
||||||
// @Override
|
}
|
||||||
// public T get(int id) {
|
|
||||||
// T[] entries = this.entries;
|
@Override
|
||||||
//
|
public @NotNull T valueFor(int id) {
|
||||||
// T entry = null;
|
T[] entries = this.entries;
|
||||||
// if (id >= 0 && id < entries.length) {
|
|
||||||
// entry = entries[id];
|
T entry = null;
|
||||||
// }
|
if (id >= 0 && id < entries.length) {
|
||||||
//
|
entry = entries[id];
|
||||||
// if (entry != null) {
|
}
|
||||||
// return entry;
|
|
||||||
// } else {
|
if (entry != null) {
|
||||||
// throw new MissingPaletteEntryException(id);
|
return entry;
|
||||||
// }
|
} else {
|
||||||
// }
|
throw new MissingPaletteEntryException(id);
|
||||||
//
|
}
|
||||||
// @Override
|
}
|
||||||
// public void readPacket(FriendlyByteBuf buf) {
|
|
||||||
// this.clear();
|
@Override
|
||||||
//
|
public void read(FriendlyByteBuf buf) {
|
||||||
// int entryCount = buf.readVarInt();
|
this.clear();
|
||||||
//
|
|
||||||
// for (int i = 0; i < entryCount; ++i) {
|
int entryCount = buf.readVarInt();
|
||||||
// this.addEntry(this.idList.get(buf.readVarInt()));
|
|
||||||
// }
|
for (int i = 0; i < entryCount; ++i) {
|
||||||
// }
|
this.addEntry(this.idList.byId(buf.readVarInt()));
|
||||||
//
|
}
|
||||||
// @Override
|
}
|
||||||
// public void writePacket(FriendlyByteBuf buf) {
|
|
||||||
// int size = this.size;
|
@Override
|
||||||
// buf.writeVarInt(size);
|
public void write(FriendlyByteBuf buf) {
|
||||||
//
|
int size = this.size;
|
||||||
// for (int i = 0; i < size; ++i) {
|
buf.writeVarInt(size);
|
||||||
// buf.writeVarInt(this.idList.getRawId(this.get(i)));
|
|
||||||
// }
|
for (int i = 0; i < size; ++i) {
|
||||||
// }
|
buf.writeVarInt(this.idList.getId(this.valueFor(i)));
|
||||||
//
|
}
|
||||||
// @Override
|
}
|
||||||
// public int getPacketSize() {
|
|
||||||
// int size = VarInt.getSizeInBytes(this.size);
|
@Override
|
||||||
//
|
public int getSerializedSize() {
|
||||||
// for (int i = 0; i < this.size; ++i) {
|
int size = VarInt.getByteSize(this.size);
|
||||||
// size += VarInt.getSizeInBytes(this.idList.getRawId(this.get(i)));
|
|
||||||
// }
|
for (int i = 0; i < this.size; ++i) {
|
||||||
//
|
size += VarInt.getByteSize(this.idList.getId(this.valueFor(i)));
|
||||||
// return size;
|
}
|
||||||
// }
|
|
||||||
//
|
return size;
|
||||||
// @Override
|
}
|
||||||
// public int getSize() {
|
|
||||||
// return this.size;
|
@Override
|
||||||
// }
|
public int getSize() {
|
||||||
//
|
return this.size;
|
||||||
// @Override
|
}
|
||||||
// public Palette<T> copy() {
|
|
||||||
// return new LithiumHashPalette<>(this.idList, this.resizeHandler, this.indexBits, this.entries.clone(), new Reference2IntOpenHashMap<>(this.table), this.size);
|
@Override
|
||||||
// }
|
public Palette<T> copy() {
|
||||||
//
|
return new LithiumHashPalette<>(this.idList, this.resizeHandler, this.indexBits, this.entries.clone(), new Reference2IntOpenHashMap<>(this.table), this.size);
|
||||||
// private void clear() {
|
}
|
||||||
// Arrays.fill(this.entries, null);
|
|
||||||
// this.table.clear();
|
private void clear() {
|
||||||
// this.size = 0;
|
Arrays.fill(this.entries, null);
|
||||||
// }
|
this.table.clear();
|
||||||
//
|
this.size = 0;
|
||||||
// public List<T> getElements() {
|
}
|
||||||
// ImmutableList.Builder<T> builder = new ImmutableList.Builder<>();
|
|
||||||
// for (T entry : this.entries) {
|
public List<T> getElements() {
|
||||||
// if (entry != null) {
|
ImmutableList.Builder<T> builder = new ImmutableList.Builder<>();
|
||||||
// builder.add(entry);
|
for (T entry : this.entries) {
|
||||||
// }
|
if (entry != null) {
|
||||||
// }
|
builder.add(entry);
|
||||||
// return builder.build();
|
}
|
||||||
// }
|
}
|
||||||
//
|
return builder.build();
|
||||||
// public static <A> Palette<A> create(int bits, IdMap<A> idList, PaletteResizeListener<A> listener, List<A> list) {
|
}
|
||||||
// return new LithiumHashPalette<>(idList, bits, listener, list);
|
|
||||||
// }
|
public static <A> Palette<A> create(int bits, IdMap<A> idList, PaletteResizeAccessor<A> listener, List<A> list) {
|
||||||
//}
|
return new LithiumHashPalette<>(idList, bits, listener, list);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,23 +1,23 @@
|
|||||||
package net.gensokyoreimagined.nitori.mixin.alloc.enum_values.living_entity;
|
package net.gensokyoreimagined.nitori.mixin.alloc.enum_values.living_entity;
|
||||||
|
|
||||||
//import net.gensokyoreimagined.nitori.common.util.EquipmentSlotConstants;
|
import net.gensokyoreimagined.nitori.common.util.EquipmentSlotConstants;
|
||||||
//import net.minecraft.world.entity.EquipmentSlot;
|
import net.minecraft.world.entity.EquipmentSlot;
|
||||||
//import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
//import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
//import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
//import org.spongepowered.asm.mixin.injection.Redirect;
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
//
|
|
||||||
//@Mixin(LivingEntity.class)
|
@Mixin(LivingEntity.class)
|
||||||
//public class LivingEntityMixin {
|
public class LivingEntityMixin {
|
||||||
//
|
|
||||||
// @Redirect(
|
@Redirect(
|
||||||
// method = "collectEquipmentChanges()Ljava/util/Map;",
|
method = "collectEquipmentChanges()Ljava/util/Map;",
|
||||||
// at = @At(
|
at = @At(
|
||||||
// value = "INVOKE",
|
value = "INVOKE",
|
||||||
// target = "Lnet/minecraft/world/entity/LivingEntity;equipmentHasChanged(Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/item/ItemStack;)Z"
|
target = "Lnet/minecraft/world/entity/EquipmentSlot;values()[Lnet/minecraft/world/entity/EquipmentSlot;"
|
||||||
// )
|
)
|
||||||
// )
|
)
|
||||||
// private EquipmentSlot[] removeAllocation() {
|
private EquipmentSlot[] removeAllocation() {
|
||||||
// return EquipmentSlotConstants.ALL;
|
return EquipmentSlotConstants.ALL;
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
package net.gensokyoreimagined.nitori.mixin.alloc.nbt;
|
|
||||||
|
|
||||||
//import com.google.common.collect.Maps;
|
|
||||||
//import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
|
||||||
//import net.minecraft.nbt.CompoundTag;
|
|
||||||
//import net.minecraft.nbt.Tag;
|
|
||||||
//import org.spongepowered.asm.mixin.Final;
|
|
||||||
//import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
//import org.spongepowered.asm.mixin.Overwrite;
|
|
||||||
//import org.spongepowered.asm.mixin.Shadow;
|
|
||||||
//import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
//import org.spongepowered.asm.mixin.injection.ModifyArg;
|
|
||||||
//import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
|
||||||
//import org.spongepowered.asm.mixin.injection.Redirect;
|
|
||||||
//
|
|
||||||
//import java.util.HashMap;
|
|
||||||
//import java.util.Map;
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// * Use {@link Object2ObjectOpenHashMap} instead of {@link HashMap} to reduce NBT memory consumption and improve
|
|
||||||
// * iteration speed.
|
|
||||||
// *
|
|
||||||
// * @author Maity
|
|
||||||
// */
|
|
||||||
//@Mixin(CompoundTag.class)
|
|
||||||
//public class CompoundTagMixin {
|
|
||||||
//
|
|
||||||
// @Shadow
|
|
||||||
// @Final
|
|
||||||
// private Map<String, Tag> entries;
|
|
||||||
//
|
|
||||||
// @ModifyArg(
|
|
||||||
// method = "<init>()V",
|
|
||||||
// at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/CompoundTag;<init>(Ljava/util/Map;)V")
|
|
||||||
// )
|
|
||||||
// private static Map<String, Tag> useFasterCollection(Map<String, Tag> oldMap) {
|
|
||||||
// return new Object2ObjectOpenHashMap<>();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Redirect(
|
|
||||||
// method = "<init>()V",
|
|
||||||
// at = @At(
|
|
||||||
// value = "INVOKE",
|
|
||||||
// target = "Lcom/google/common/collect/Maps;newHashMap()Ljava/util/HashMap;",
|
|
||||||
// remap = false
|
|
||||||
// )
|
|
||||||
// )
|
|
||||||
// private static HashMap<?, ?> removeOldMapAlloc() {
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * @reason Use faster collection
|
|
||||||
// * @author Maity
|
|
||||||
// */
|
|
||||||
// @Overwrite
|
|
||||||
// public CompoundTag copy() {
|
|
||||||
// // [VanillaCopy] HashMap is replaced with Object2ObjectOpenHashMap
|
|
||||||
// var map = new Object2ObjectOpenHashMap<>(Maps.transformValues(this.entries, Tag::copy));
|
|
||||||
// return new CompoundTag(map);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Mixin(targets = "net.minecraft.nbt.CompoundTag$1")
|
|
||||||
// static class Type {
|
|
||||||
//
|
|
||||||
// @ModifyVariable(
|
|
||||||
// method = "loadCompound",
|
|
||||||
// at = @At(
|
|
||||||
// value = "INVOKE_ASSIGN",
|
|
||||||
// target = "Lcom/google/common/collect/Maps;newHashMap()Ljava/util/HashMap;",
|
|
||||||
// remap = false
|
|
||||||
// )
|
|
||||||
// )
|
|
||||||
// private static Map<String, Tag> useFasterCollection(Map<String, Tag> map) {
|
|
||||||
// return new Object2ObjectOpenHashMap<>();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Redirect(
|
|
||||||
// method = "loadCompound",
|
|
||||||
// at = @At(
|
|
||||||
// value = "INVOKE",
|
|
||||||
// target = "Lcom/google/common/collect/Maps;newHashMap()Ljava/util/HashMap;",
|
|
||||||
// remap = false
|
|
||||||
// )
|
|
||||||
// )
|
|
||||||
// private static HashMap<?, ?> removeOldMapAlloc() {
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package net.gensokyoreimagined.nitori.mixin.chunk.palette;
|
||||||
|
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||||
|
|
||||||
|
@Mixin(targets = "net.minecraft.world.level.chunk.PaletteResize")
|
||||||
|
public abstract class PaletteResizeAccessor<T> {
|
||||||
|
@Invoker
|
||||||
|
public abstract int callOnResize(int newBits, T object);
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package net.gensokyoreimagined.nitori.mixin.chunk.palette;
|
||||||
|
|
||||||
|
// import net.minecraft.core.IdMap;
|
||||||
|
// import net.minecraft.world.level.chunk.Palette;
|
||||||
|
// import net.minecraft.world.level.chunk.PaletteResize;
|
||||||
|
// import net.minecraft.world.level.chunk.PalettedContainer;
|
||||||
|
// import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
// import org.spongepowered.asm.mixin.gen.Invoker;
|
||||||
|
//
|
||||||
|
// @Mixin(targets = "net.minecraft.world.level.chunk.PalettedContainer.Configuration")
|
||||||
|
// public abstract class PalettedContainerConfigurationMixin<T> {
|
||||||
|
// @Invoker("<init>(Lnet/minecraft/world/level/chunk/Palette$Factory;I)V")
|
||||||
|
// public static <T> PalettedContainerConfigurationMixin<T> create(Palette.Factory factory, int bits) {
|
||||||
|
// throw new AssertionError("mukyu~!");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @Invoker
|
||||||
|
// public abstract PalettedContainer.Data<T> createData(IdMap<T> idList, PaletteResize<T> listener, int size);
|
||||||
|
// }
|
||||||
@@ -1,197 +1,89 @@
|
|||||||
package net.gensokyoreimagined.nitori.mixin.chunk.palette;
|
package net.gensokyoreimagined.nitori.mixin.chunk.palette;
|
||||||
|
|
||||||
//import com.google.common.collect.ImmutableList;
|
// import net.gensokyoreimagined.nitori.common.world.chunk.LithiumHashPalette;
|
||||||
//import it.unimi.dsi.fastutil.HashCommon;
|
// import net.minecraft.core.IdMap;
|
||||||
//import it.unimi.dsi.fastutil.objects.Reference2IntMap;
|
// import net.minecraft.world.level.chunk.PalettedContainer;
|
||||||
//import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap;
|
// import org.jetbrains.annotations.NotNull;
|
||||||
//import net.minecraft.network.PacketByteBuf;
|
// import org.spongepowered.asm.mixin.*;
|
||||||
//import net.minecraft.network.encoding.VarInts;
|
// import net.minecraft.world.level.chunk.Palette;
|
||||||
//import net.minecraft.util.collection.IndexedIterable;
|
|
||||||
//import net.minecraft.world.chunk.EntryMissingException;
|
|
||||||
//import net.minecraft.world.chunk.Palette;
|
|
||||||
//import net.minecraft.world.chunk.PaletteResizeListener;
|
|
||||||
//
|
//
|
||||||
//import java.util.Arrays;
|
// import static net.minecraft.world.level.chunk.PalettedContainer.Strategy.LINEAR_PALETTE_FACTORY;
|
||||||
//import java.util.List;
|
// import static net.minecraft.world.level.chunk.PalettedContainer.Strategy.SINGLE_VALUE_PALETTE_FACTORY;
|
||||||
//import java.util.function.Predicate;
|
|
||||||
//
|
//
|
||||||
//import static it.unimi.dsi.fastutil.Hash.FAST_LOAD_FACTOR;
|
// @Mixin(PalettedContainer.Strategy.class)
|
||||||
|
// public abstract class PalettedContainerMixin {
|
||||||
|
// @Mutable
|
||||||
|
// @Shadow
|
||||||
|
// @Final
|
||||||
|
// public static PalettedContainer.Strategy SECTION_STATES;
|
||||||
//
|
//
|
||||||
///**
|
// @Unique
|
||||||
// * Generally provides better performance over the vanilla {@link net.minecraft.world.chunk.BiMapPalette} when calling
|
// private static final PalettedContainerConfigurationMixin<?>[] BLOCKSTATE_DATA_PROVIDERS;
|
||||||
// * {@link LithiumHashPalette#index(Object)} through using a faster backing map and reducing pointer chasing.
|
// @Unique
|
||||||
|
// private static final PalettedContainerConfigurationMixin<?>[] BIOME_DATA_PROVIDERS;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// @Unique
|
||||||
|
// private static final Palette.Factory HASH = LithiumHashPalette::create;
|
||||||
|
// @Mutable
|
||||||
|
// @Shadow
|
||||||
|
// @Final
|
||||||
|
// public static PalettedContainer.Strategy SECTION_BIOMES;
|
||||||
|
// @Shadow
|
||||||
|
// @Final
|
||||||
|
// static Palette.Factory GLOBAL_PALETTE_FACTORY;
|
||||||
|
//
|
||||||
|
// /*
|
||||||
|
// * @reason Replace the hash palette from vanilla with our own and change the threshold for usage to only 3 bits,
|
||||||
|
// * as our implementation performs better at smaller key ranges.
|
||||||
|
// * @author JellySquid, 2No2Name (avoid Configuration duplication, use hash palette for 3 bit biomes)
|
||||||
// */
|
// */
|
||||||
//public class LithiumHashPalette<T> implements Palette<T> {
|
// static {
|
||||||
// private static final int ABSENT_VALUE = -1;
|
// Palette.Factory idListFactory = GLOBAL_PALETTE_FACTORY;
|
||||||
//
|
//
|
||||||
// private final IndexedIterable<T> idList;
|
// PalettedContainerConfigurationMixin<?> arrayConfiguration4bit = PalettedContainerConfigurationMixin.create(LINEAR_PALETTE_FACTORY, 4);
|
||||||
// private final PaletteResizeListener<T> resizeHandler;
|
// PalettedContainerConfigurationMixin<?> hashConfiguration4bit = PalettedContainerConfigurationMixin.create(HASH, 4);
|
||||||
// private final int indexBits;
|
// BLOCKSTATE_DATA_PROVIDERS = new PalettedContainerConfigurationMixin<?>[]{
|
||||||
//
|
// PalettedContainerConfigurationMixin.create(SINGLE_VALUE_PALETTE_FACTORY, 0),
|
||||||
// private final Reference2IntMap<T> table;
|
// // Bits 1-4 must all pass 4 bits as parameter, otherwise chunk sections will corrupt.
|
||||||
// private T[] entries;
|
// arrayConfiguration4bit,
|
||||||
// private int size = 0;
|
// arrayConfiguration4bit,
|
||||||
//
|
// hashConfiguration4bit,
|
||||||
// public LithiumHashPalette(IndexedIterable<T> idList, PaletteResizeListener<T> resizeHandler, int indexBits, T[] entries, Reference2IntMap<T> table, int size) {
|
// hashConfiguration4bit,
|
||||||
// this.idList = idList;
|
// PalettedContainerConfigurationMixin.create(HASH, 5),
|
||||||
// this.resizeHandler = resizeHandler;
|
// PalettedContainerConfigurationMixin.create(HASH, 6),
|
||||||
// this.indexBits = indexBits;
|
// PalettedContainerConfigurationMixin.create(HASH, 7),
|
||||||
// this.entries = entries;
|
// PalettedContainerConfigurationMixin.create(HASH, 8)
|
||||||
// this.table = table;
|
// };
|
||||||
// this.size = size;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public LithiumHashPalette(IndexedIterable<T> idList, int bits, PaletteResizeListener<T> resizeHandler, List<T> list) {
|
|
||||||
// this(idList, bits, resizeHandler);
|
|
||||||
//
|
|
||||||
// for (T t : list) {
|
|
||||||
// this.addEntry(t);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @SuppressWarnings("unchecked")
|
|
||||||
// public LithiumHashPalette(IndexedIterable<T> idList, int bits, PaletteResizeListener<T> resizeHandler) {
|
|
||||||
// this.idList = idList;
|
|
||||||
// this.indexBits = bits;
|
|
||||||
// this.resizeHandler = resizeHandler;
|
|
||||||
//
|
|
||||||
// int capacity = 1 << bits;
|
|
||||||
//
|
|
||||||
// this.entries = (T[]) new Object[capacity];
|
|
||||||
// this.table = new Reference2IntOpenHashMap<>(capacity, FAST_LOAD_FACTOR);
|
|
||||||
// this.table.defaultReturnValue(ABSENT_VALUE);
|
|
||||||
// }
|
|
||||||
//
|
//
|
||||||
|
// SECTION_STATES = new PalettedContainer.Strategy(4) {
|
||||||
// @Override
|
// @Override
|
||||||
// public int index(T obj) {
|
// public <A> @NotNull PalettedContainerConfigurationMixin<A> getConfiguration(@NotNull IdMap<A> idList, int bits) {
|
||||||
// int id = this.table.getInt(obj);
|
// if (bits >= 0 && bits < BLOCKSTATE_DATA_PROVIDERS.length) {
|
||||||
//
|
// //noinspection unchecked
|
||||||
// if (id == ABSENT_VALUE) {
|
// return (PalettedContainerConfigurationMixin<A>) BLOCKSTATE_DATA_PROVIDERS[bits];
|
||||||
// id = this.computeEntry(obj);
|
|
||||||
// }
|
// }
|
||||||
//
|
// return PalettedContainerConfigurationMixin.create(idListFactory, MathHelper.ceilLog2(idList.size()));
|
||||||
// return id;
|
|
||||||
// }
|
// }
|
||||||
|
// };
|
||||||
//
|
//
|
||||||
|
// BIOME_DATA_PROVIDERS = new PalettedContainerConfigurationMixin<?>[]{
|
||||||
|
// PalettedContainerConfigurationMixin.create(SINGLE_VALUE_PALETTE_FACTORY, 0),
|
||||||
|
// PalettedContainerConfigurationMixin.create(LINEAR_PALETTE_FACTORY, 1),
|
||||||
|
// PalettedContainerConfigurationMixin.create(LINEAR_PALETTE_FACTORY, 2),
|
||||||
|
// PalettedContainerConfigurationMixin.create(HASH, 3)
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// SECTION_BIOMES = new PalettedContainer.Strategy(2) {
|
||||||
// @Override
|
// @Override
|
||||||
// public boolean hasAny(Predicate<T> predicate) {
|
// public <A> @NotNull PalettedContainerConfigurationMixin<A> getConfiguration(@NotNull IdMap<A> idList, int bits) {
|
||||||
// for (int i = 0; i < this.size; ++i) {
|
// if (bits >= 0 && bits < BIOME_DATA_PROVIDERS.length) {
|
||||||
// if (predicate.test(this.entries[i])) {
|
// //noinspection unchecked
|
||||||
// return true;
|
// return (PalettedContainerConfigurationMixin<A>) BIOME_DATA_PROVIDERS[bits];
|
||||||
|
// }
|
||||||
|
// return PalettedContainerConfigurationMixin.create(idListFactory, MathHelper.ceilLog2(idList.size()));
|
||||||
|
// }
|
||||||
|
// };
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
//
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private int computeEntry(T obj) {
|
|
||||||
// int id = this.addEntry(obj);
|
|
||||||
//
|
|
||||||
// if (id >= 1 << this.indexBits) {
|
|
||||||
// if (this.resizeHandler == null) {
|
|
||||||
// throw new IllegalStateException("Cannot grow");
|
|
||||||
// } else {
|
|
||||||
// id = this.resizeHandler.onResize(this.indexBits + 1, obj);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return id;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private int addEntry(T obj) {
|
|
||||||
// int nextId = this.size;
|
|
||||||
//
|
|
||||||
// if (nextId >= this.entries.length) {
|
|
||||||
// this.resize(this.size);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// this.table.put(obj, nextId);
|
|
||||||
// this.entries[nextId] = obj;
|
|
||||||
//
|
|
||||||
// this.size++;
|
|
||||||
//
|
|
||||||
// return nextId;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private void resize(int neededCapacity) {
|
|
||||||
// this.entries = Arrays.copyOf(this.entries, HashCommon.nextPowerOfTwo(neededCapacity + 1));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public T get(int id) {
|
|
||||||
// T[] entries = this.entries;
|
|
||||||
//
|
|
||||||
// T entry = null;
|
|
||||||
// if (id >= 0 && id < entries.length) {
|
|
||||||
// entry = entries[id];
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (entry != null) {
|
|
||||||
// return entry;
|
|
||||||
// } else {
|
|
||||||
// throw new EntryMissingException(id);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void readPacket(PacketByteBuf buf) {
|
|
||||||
// this.clear();
|
|
||||||
//
|
|
||||||
// int entryCount = buf.readVarInt();
|
|
||||||
//
|
|
||||||
// for (int i = 0; i < entryCount; ++i) {
|
|
||||||
// this.addEntry(this.idList.get(buf.readVarInt()));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void writePacket(PacketByteBuf buf) {
|
|
||||||
// int size = this.size;
|
|
||||||
// buf.writeVarInt(size);
|
|
||||||
//
|
|
||||||
// for (int i = 0; i < size; ++i) {
|
|
||||||
// buf.writeVarInt(this.idList.getRawId(this.get(i)));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public int getPacketSize() {
|
|
||||||
// int size = VarInts.getSizeInBytes(this.size);
|
|
||||||
//
|
|
||||||
// for (int i = 0; i < this.size; ++i) {
|
|
||||||
// size += VarInts.getSizeInBytes(this.idList.getRawId(this.get(i)));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return size;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public int getSize() {
|
|
||||||
// return this.size;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public Palette<T> copy() {
|
|
||||||
// return new LithiumHashPalette<>(this.idList, this.resizeHandler, this.indexBits, this.entries.clone(), new Reference2IntOpenHashMap<>(this.table), this.size);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private void clear() {
|
|
||||||
// Arrays.fill(this.entries, null);
|
|
||||||
// this.table.clear();
|
|
||||||
// this.size = 0;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public List<T> getElements() {
|
|
||||||
// ImmutableList.Builder<T> builder = new ImmutableList.Builder<>();
|
|
||||||
// for (T entry : this.entries) {
|
|
||||||
// if (entry != null) {
|
|
||||||
// builder.add(entry);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return builder.build();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public static <A> Palette<A> create(int bits, IndexedIterable<A> idList, PaletteResizeListener<A> listener, List<A> list) {
|
|
||||||
// return new LithiumHashPalette<>(idList, bits, listener, list);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
@@ -67,6 +67,8 @@
|
|||||||
"util.block_tracking.AbstractBlockStateMixin",
|
"util.block_tracking.AbstractBlockStateMixin",
|
||||||
"playerwatching.MixinChunkFilter",
|
"playerwatching.MixinChunkFilter",
|
||||||
"playerwatching.MixinServerPlayerEntity",
|
"playerwatching.MixinServerPlayerEntity",
|
||||||
"playerwatching.optimize_nearby_player_lookups.MixinMobEntity"
|
"playerwatching.optimize_nearby_player_lookups.MixinMobEntity",
|
||||||
|
"alloc.enum_values.living_entity.LivingEntityMixin",
|
||||||
|
"chunk.palette.PaletteResizeAccessor",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user