Skip to content

Commit 257147b

Browse files
committed
Properly mark registries as modded
1 parent 262beb6 commit 257147b

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

  • station-registry-api-v0/src/main/java/net/modificationstation/stationapi/api/registry

station-registry-api-v0/src/main/java/net/modificationstation/stationapi/api/registry/SimpleRegistry.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
import it.unimi.dsi.fastutil.objects.*;
1111
import net.mine_diver.unsafeevents.EventBus;
1212
import net.mine_diver.unsafeevents.MutableEventBus;
13-
import net.modificationstation.stationapi.api.event.registry.RegistryEntryAddedEvent;
14-
import net.modificationstation.stationapi.api.event.registry.RegistryEntryRemovedEvent;
15-
import net.modificationstation.stationapi.api.event.registry.RegistryIdRemapEvent;
13+
import net.modificationstation.stationapi.api.event.registry.*;
1614
import net.modificationstation.stationapi.api.registry.RegistryEntry.Reference;
1715
import net.modificationstation.stationapi.api.registry.RegistryEntryList.Named;
1816
import net.modificationstation.stationapi.api.registry.RegistryWrapper.Impl;
@@ -30,6 +28,7 @@
3028

3129
import static java.util.Objects.requireNonNullElseGet;
3230
import static net.modificationstation.stationapi.api.StationAPI.LOGGER;
31+
import static net.modificationstation.stationapi.api.util.Namespace.MINECRAFT;
3332

3433
public class SimpleRegistry<T> implements MutableRegistry<T>, RemappableRegistry, ListenableRegistry {
3534
final RegistryKey<? extends Registry<T>> key;
@@ -132,6 +131,17 @@ public Reference<T> set(int rawId, RegistryKey<T> registryKey, T value, Lifecycl
132131
return set(rawId, registryKey, value, lifecycle, true);
133132
}
134133

134+
private void onChange(RegistryKey<T> registryKey) {
135+
if (MINECRAFT == registryKey.getValue().getNamespace()) return;
136+
137+
RegistryAttributeHolder holder = RegistryAttributeHolder.get(getKey());
138+
139+
if (holder.hasAttribute(RegistryAttribute.MODDED)) return;
140+
141+
RegistryAttributeHolder.get(getKey()).addAttribute(RegistryAttribute.MODDED);
142+
LOGGER.debug("Registry {} has been marked as modded, registry entry {} was changed", getKey().getValue(), registryKey.getValue());
143+
}
144+
135145
private Reference<T> set(int rawId, RegistryKey<T> registryKey, T value, Lifecycle lifecycle, boolean checkReservation) {
136146
this.assertNotFrozen(registryKey);
137147
Validate.notNull(registryKey);
@@ -204,6 +214,7 @@ private Reference<T> set(int rawId, RegistryKey<T> registryKey, T value, Lifecyc
204214
.object(value)
205215
.build());
206216

217+
onChange(registryKey);
207218
return reference;
208219
}
209220

0 commit comments

Comments
 (0)