Add overwrite for StateHolder#trySetValue
Now that we do not initialise the Vanilla table field, we need to overwrite this method as well with our own implementation.
This commit is contained in:
@@ -87,7 +87,20 @@ abstract class StateHolderMixin<O, S> implements PropertyAccessStateHolder {
|
||||
public <T extends Comparable<T>, V extends T> S setValue(final Property<T> property, final V value) {
|
||||
final S ret = this.optimisedTable.set(this.tableIndex, property, value);
|
||||
if (ret == null) {
|
||||
throw new IllegalArgumentException("Cannot set property " + property + " to " + value + " on " + this.owner + ", it is not an allowed value");
|
||||
throw new IllegalArgumentException("Cannot set property " + property + " to " + value + " on " + this.owner);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @reason Replace with optimisedTable
|
||||
* @author Spottedleaf
|
||||
*/
|
||||
@Overwrite
|
||||
public <T extends Comparable<T>, V extends T> S trySetValue(final Property<T> property, final V value) {
|
||||
final S ret = this.optimisedTable.trySet(this.tableIndex, property, value, (S)(StateHolder<O, S>)(Object)this);
|
||||
if (ret == null) {
|
||||
throw new IllegalArgumentException("Cannot set property " + property + " to " + value + " on " + this.owner);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -128,6 +128,28 @@ public final class ZeroCollidingReferenceStateTable<O, S> {
|
||||
return this.lookup[(int)newIndex];
|
||||
}
|
||||
|
||||
public <T extends Comparable<T>> S trySet(final long index, final Property<T> property, final T with, final S dfl) {
|
||||
final Indexer indexer = this.propertyToIndexer.get(((PropertyAccess<T>)property).moonrise$getId());
|
||||
if (indexer == null) {
|
||||
return dfl;
|
||||
}
|
||||
|
||||
final int newValueId = ((PropertyAccess<T>)property).moonrise$getIdFor(with);
|
||||
if (newValueId < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final long divided = (index * indexer.multipleDivMagic) >>> 32;
|
||||
final long modded = (((divided * indexer.modMagic) & 0xFFFFFFFFL) * indexer.totalValues) >>> 32;
|
||||
// equiv to: divided = index / multiple
|
||||
// modded = divided % totalValues
|
||||
|
||||
// subtract out the old value, add in the new
|
||||
final long newIndex = (((long)newValueId - modded) * indexer.multiple) + index;
|
||||
|
||||
return this.lookup[(int)newIndex];
|
||||
}
|
||||
|
||||
private static final record Indexer(
|
||||
int totalValues, int multiple, long multipleDivMagic, long modMagic
|
||||
) {}
|
||||
|
||||
Reference in New Issue
Block a user