Skip to content

Commit

Permalink
Ignore registry ID check for vanilla registries
Browse files Browse the repository at this point in the history
This will only be enforced for custom registries.

Closes #6
  • Loading branch information
Su5eD committed Jul 22, 2023
1 parent 19cabd4 commit a9c90db
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public static <T> FabricRegistryBuilder<T, SimpleDefaultedRegistry<T>> createDef
private FabricRegistryBuilder(R registry) {
this.registry = registry;
attribute(RegistryAttribute.MODDED);
attribute(RegistryAttribute.CUSTOM);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@ public enum RegistryAttribute {
/**
* Registry has been modded.
*/
MODDED
MODDED,

/**
* Custom registry
*/
CUSTOM
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,13 @@ private void onChange(RegistryKey<Registry<T>> registryKey) {

@Inject(method = "set", at = @At("HEAD"))
public void setPre(int id, RegistryKey<T> registryId, T object, Lifecycle lifecycle, CallbackInfoReturnable<RegistryEntry<T>> info) {
int indexedEntriesId = entryToRawId.getInt(object);
RegistryAttributeHolder holder = RegistryAttributeHolder.get(getKey());
if (holder.hasAttribute(RegistryAttribute.CUSTOM)) {
int indexedEntriesId = entryToRawId.getInt(object);

if (indexedEntriesId >= 0) {
throw new RuntimeException("Attempted to register object " + object + " twice! (at raw IDs " + indexedEntriesId + " and " + id + " )");
if (indexedEntriesId >= 0) {
throw new RuntimeException("Attempted to register object " + object + " twice! (at raw IDs " + indexedEntriesId + " and " + id + " )");
}
}

if (!idToEntry.containsKey(registryId.getValue())) {
Expand All @@ -195,7 +198,7 @@ public void setPre(int id, RegistryKey<T> registryId, T object, Lifecycle lifecy
if (oldObject != null && oldObject.value() != null && oldObject.value() != object) {
int oldId = entryToRawId.getInt(oldObject.value());

if (oldId != id) {
if (holder.hasAttribute(RegistryAttribute.CUSTOM) && oldId != id) {
throw new RuntimeException("Attempted to register ID " + registryId + " at different raw IDs (" + oldId + ", " + id + ")! If you're trying to override an item, use .set(), not .register()!");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public static void onCommonSetup(FMLCommonSetupEvent event) {
Validate.isTrue(Registries.REGISTRIES.getIds().contains(new Identifier("registry_sync", "fabric_registry")));

Validate.isTrue(RegistryAttributeHolder.get(fabricRegistry).hasAttribute(RegistryAttribute.MODDED));
Validate.isTrue(RegistryAttributeHolder.get(fabricRegistry).hasAttribute(RegistryAttribute.CUSTOM));
Validate.isTrue(RegistryAttributeHolder.get(fabricRegistry).hasAttribute(RegistryAttribute.SYNCED));
Validate.isTrue(!RegistryAttributeHolder.get(fabricRegistry).hasAttribute(RegistryAttribute.PERSISTED));

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ fabric-client-tags-api-v1-version=1.1.1
loom.platform=forge
forge_version=1.20.1-47.1.3
pack_format=15
forgified_version=1.4.2
forgified_version=1.5.0

0 comments on commit a9c90db

Please sign in to comment.