-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
properly integrate 'RegistryOps' with SerializationAttributes.REGISTRIES
- Loading branch information
Showing
7 changed files
with
101 additions
and
14 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/main/java/io/wispforest/owo/mixin/RegistryOpsAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.wispforest.owo.mixin; | ||
|
||
import net.minecraft.registry.RegistryOps; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
import org.spongepowered.asm.mixin.gen.Invoker; | ||
|
||
@Mixin(RegistryOps.class) | ||
public interface RegistryOpsAccessor { | ||
@Invoker("caching") | ||
static RegistryOps.RegistryInfoGetter owo$caching(RegistryOps.RegistryInfoGetter registryInfoGetter) {throw new UnsupportedOperationException();} | ||
|
||
@Accessor("registryInfoGetter") | ||
RegistryOps.RegistryInfoGetter owo$infoGetter(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/main/java/io/wispforest/owo/serialization/RegistriesAttribute.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package io.wispforest.owo.serialization; | ||
|
||
import net.minecraft.registry.*; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Optional; | ||
|
||
public final class RegistriesAttribute implements SerializationAttribute.Instance { | ||
|
||
private final RegistryOps.RegistryInfoGetter infoGetter; | ||
private final @Nullable DynamicRegistryManager registryManager; | ||
|
||
private RegistriesAttribute(RegistryOps.RegistryInfoGetter infoGetter, @Nullable DynamicRegistryManager registryManager) { | ||
this.infoGetter = infoGetter; | ||
this.registryManager = registryManager; | ||
} | ||
|
||
public static RegistriesAttribute of(DynamicRegistryManager registryManager) { | ||
return new RegistriesAttribute( | ||
new RegistryOps.RegistryInfoGetter() { | ||
@Override | ||
public <T> Optional<RegistryOps.RegistryInfo<T>> getRegistryInfo(RegistryKey<? extends Registry<? extends T>> registryRef) { | ||
return registryManager.getOptionalWrapper(registryRef).map(RegistryOps.RegistryInfo::fromWrapper); | ||
} | ||
}, | ||
registryManager | ||
); | ||
} | ||
|
||
@ApiStatus.Internal | ||
public static RegistriesAttribute infoGetterOnly(RegistryOps.RegistryInfoGetter lookup) { | ||
return new RegistriesAttribute(lookup, null); | ||
} | ||
|
||
public RegistryOps.RegistryInfoGetter infoGetter() { | ||
return this.infoGetter; | ||
} | ||
|
||
public boolean hasRegistryManager() { | ||
return this.registryManager != null; | ||
} | ||
|
||
public @NotNull DynamicRegistryManager registryManager() { | ||
if (!this.hasRegistryManager()) { | ||
throw new IllegalStateException("This instance of RegistriesAttribute does not supply a DynamicRegistryManager"); | ||
} | ||
|
||
return this.registryManager; | ||
} | ||
|
||
@Override | ||
public SerializationAttribute attribute() { | ||
return SerializationAttributes.REGISTRIES; | ||
} | ||
|
||
@Override | ||
public Object value() { | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters