From b1ff8b812b5445ca6d5d65bbe49ff7f023ee06f9 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Thu, 6 Jun 2024 22:48:24 +0200 Subject: [PATCH 1/2] Allow setting the min id possible of a registry --- .../fabric/impl/registry/IdsHolderImpl.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/IdsHolderImpl.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/IdsHolderImpl.java index 9024ef4c8..c83167389 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/IdsHolderImpl.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/IdsHolderImpl.java @@ -32,14 +32,24 @@ public class IdsHolderImpl implements IdsHolder { private final IdentityHashMap valueToId = new IdentityHashMap<>(512); private final List values = Lists.newArrayList(); + private final int minId; + + public IdsHolderImpl(int minId) { + this.minId = minId; + } + + public IdsHolderImpl() { + this(0); + } + @Override public IdsHolder 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++; @@ -70,7 +80,7 @@ public class IdsHolderImpl implements IdsHolder { @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 From b7a8575b20876bd5c313360030bc216bb391705a Mon Sep 17 00:00:00 2001 From: Cat Core Date: Thu, 6 Jun 2024 22:48:44 +0200 Subject: [PATCH 2/2] Fix entry count in IdsHolder --- .../mixin/registry/sync/versioned/OtherIdListMixin.java | 6 +++--- .../legacyfabric/fabric/impl/registry/IdsHolderImpl.java | 2 +- .../legacyfabric/fabric/impl/registry/RegistryRemapper.java | 2 +- .../fabric/mixin/registry/sync/IdListMixinV2.java | 5 +++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/OtherIdListMixin.java b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/OtherIdListMixin.java index f6faa63d7..08d5ed10d 100644 --- a/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/OtherIdListMixin.java +++ b/legacy-fabric-registry-sync-api-v2/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/versioned/OtherIdListMixin.java @@ -35,10 +35,10 @@ public abstract class OtherIdListMixin implements IdsHolder { 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 fabric$new() { @@ -61,7 +61,7 @@ public abstract class OtherIdListMixin implements IdsHolder { @Override public int fabric$size() { - return this.field_14375.length; + return this.size(); } @Override diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/IdsHolderImpl.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/IdsHolderImpl.java index c83167389..da31e5450 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/IdsHolderImpl.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/IdsHolderImpl.java @@ -69,7 +69,7 @@ public IdsHolderImpl() { @Override public int fabric$size() { - return values.size(); + return this.valueToId.size(); } @Override diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryRemapper.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryRemapper.java index 166c5624b..382757f25 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryRemapper.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/impl/registry/RegistryRemapper.java @@ -132,7 +132,7 @@ private IntSupplier normalizeEntryList(IdsHolder 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; diff --git a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java index a7c3ac826..8a7d3f42a 100644 --- a/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java +++ b/legacy-fabric-registry-sync-api-v2/common/src/main/java/net/legacyfabric/fabric/mixin/registry/sync/IdListMixinV2.java @@ -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; @@ -40,7 +41,7 @@ public abstract class IdListMixinV2 implements IdsHolder { @Shadow @Final - private List list; + private IdentityHashMap idMap; @Override public IdsHolder fabric$new() { @@ -63,7 +64,7 @@ public abstract class IdListMixinV2 implements IdsHolder { @Override public int fabric$size() { - return list.size(); + return idMap.size(); } @Override