Skip to content

Commit

Permalink
Merge branch 'refs/heads/feature/registry-sync-v2/api' into feature/r…
Browse files Browse the repository at this point in the history
…egistry-sync-v2/item
  • Loading branch information
thecatcore committed Jun 6, 2024
2 parents f0920b7 + b7a8575 commit 7e4d6fe
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public abstract class OtherIdListMixin<T> implements IdsHolder<T> {
public abstract void add(T value, int id);

@Shadow
private T[] field_14375;
public abstract int getId(T value);

@Shadow
public abstract int getId(T value);
public abstract int size();

@Override
public IdsHolder<T> fabric$new() {
Expand All @@ -61,7 +61,7 @@ public abstract class OtherIdListMixin<T> implements IdsHolder<T> {

@Override
public int fabric$size() {
return this.field_14375.length;
return this.size();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,24 @@ public class IdsHolderImpl<T> implements IdsHolder<T> {
private final IdentityHashMap<T, Integer> valueToId = new IdentityHashMap<>(512);
private final List<T> values = Lists.newArrayList();

private final int minId;

public IdsHolderImpl(int minId) {
this.minId = minId;
}

public IdsHolderImpl() {
this(0);
}

@Override
public IdsHolder<T> fabric$new() {
return new IdsHolderImpl<>();
return new IdsHolderImpl<>(this.minId);
}

@Override
public int fabric$nextId() {
int id = 0;
int id = this.minId;

while (this.fabric$getValue(id) != null) id++;

Expand All @@ -59,7 +69,7 @@ public class IdsHolderImpl<T> implements IdsHolder<T> {

@Override
public int fabric$size() {
return values.size();
return this.valueToId.size();
}

@Override
Expand All @@ -70,7 +80,7 @@ public class IdsHolderImpl<T> implements IdsHolder<T> {

@Override
public T fabric$getValue(int rawId) {
return rawId >= 0 && rawId < this.values.size() ? this.values.get(rawId) : null;
return rawId >= this.minId && rawId < this.values.size() ? this.values.get(rawId) : null;
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private IntSupplier normalizeEntryList(IdsHolder<T> ids) {
addNewEntries(ids);

if (currentSize.getAsInt() != previousSize.getAsInt() && this.missingMap.isEmpty()) {
throw new IllegalStateException("An error occured during remapping");
throw new IllegalStateException("An error occurred during remapping");
}

return previousSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package net.legacyfabric.fabric.mixin.registry.sync;

import java.util.IdentityHashMap;
import java.util.List;

import org.spongepowered.asm.mixin.Final;
Expand All @@ -40,7 +41,7 @@ public abstract class IdListMixinV2<T> implements IdsHolder<T> {

@Shadow
@Final
private List<T> list;
private IdentityHashMap<T, Integer> idMap;

@Override
public IdsHolder<T> fabric$new() {
Expand All @@ -63,7 +64,7 @@ public abstract class IdListMixinV2<T> implements IdsHolder<T> {

@Override
public int fabric$size() {
return list.size();
return idMap.size();
}

@Override
Expand Down

0 comments on commit 7e4d6fe

Please sign in to comment.