-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
123 additions
and
54 deletions.
There are no files selected for viewing
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
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
10 changes: 0 additions & 10 deletions
10
src/mod/java/dev/su5ed/sinytra/connector/mod/compat/DynamicRegistryPrefixes.java
This file was deleted.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
src/mod/java/dev/su5ed/sinytra/connector/mod/compat/RegistryUtil.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,57 @@ | ||
package dev.su5ed.sinytra.connector.mod.compat; | ||
|
||
import com.google.common.collect.BiMap; | ||
import com.mojang.datafixers.util.Pair; | ||
import com.mojang.logging.LogUtils; | ||
import dev.su5ed.sinytra.connector.loader.ConnectorEarlyLoader; | ||
import net.fabricmc.fabric.impl.registry.sync.DynamicRegistriesImpl; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraftforge.fml.loading.FMLLoader; | ||
import net.minecraftforge.registries.ForgeRegistries; | ||
import net.minecraftforge.registries.ForgeRegistry; | ||
import net.minecraftforge.registries.IForgeRegistry; | ||
import org.slf4j.Logger; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
import java.lang.invoke.VarHandle; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static cpw.mods.modlauncher.api.LamdbaExceptionUtils.uncheck; | ||
|
||
public class RegistryUtil { | ||
private static final VarHandle REGISTRY_NAMES = uncheck(() -> MethodHandles.privateLookupIn(ForgeRegistry.class, MethodHandles.lookup()).findVarHandle(ForgeRegistry.class, "names", BiMap.class)); | ||
private static final ResourceLocation PARTICLE_TYPE_REGISTRY = ForgeRegistries.Keys.PARTICLE_TYPES.location(); | ||
private static final Logger LOGGER = LogUtils.getLogger(); | ||
|
||
public static boolean isRegisteredFabricDynamicRegistry(ResourceKey<?> key) { | ||
return DynamicRegistriesImpl.FABRIC_DYNAMIC_REGISTRY_KEYS.stream().anyMatch(key::equals); | ||
} | ||
|
||
public static <V> void retainFabricClientEntries(ResourceLocation name, ForgeRegistry<V> from, IForgeRegistry<V> to) { | ||
if (FMLLoader.getDist().isClient() && name.equals(PARTICLE_TYPE_REGISTRY)) { | ||
List<Pair<ResourceLocation, V>> list = new ArrayList<>(); | ||
|
||
for (Map.Entry<ResourceKey<V>, V> entry : to.getEntries()) { | ||
ResourceLocation location = entry.getKey().location(); | ||
if (!from.containsKey(location) && ConnectorEarlyLoader.isConnectorMod(location.getNamespace())) { | ||
list.add(Pair.of(location, entry.getValue())); | ||
} | ||
} | ||
|
||
if (!list.isEmpty()) { | ||
LOGGER.info("Connector found {} items to retain in registry {}", list.size(), name); | ||
} | ||
|
||
for (Pair<ResourceLocation, V> pair : list) { | ||
RegistryUtil.getNames(from).put(pair.getFirst(), pair.getSecond()); | ||
} | ||
} | ||
} | ||
|
||
private static <V> BiMap<ResourceLocation, V> getNames(ForgeRegistry<V> registry) { | ||
return (BiMap<ResourceLocation, V>) uncheck(() -> REGISTRY_NAMES.get(registry)); | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
src/mod/java/dev/su5ed/sinytra/connector/mod/mixin/registries/ClientForgeRegistryMixin.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,19 @@ | ||
package dev.su5ed.sinytra.connector.mod.mixin.registries; | ||
|
||
import dev.su5ed.sinytra.connector.mod.compat.RegistryUtil; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraftforge.registries.ForgeRegistry; | ||
import net.minecraftforge.registries.IForgeRegistry; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(ForgeRegistry.class) | ||
public abstract class ClientForgeRegistryMixin<V> implements IForgeRegistry<V> { | ||
|
||
@Inject(method = "sync", at = @At(value = "INVOKE", target = "Lcom/google/common/collect/BiMap;clear()V", ordinal = 0), remap = false) | ||
private void retainFabricClientEntries(ResourceLocation name, ForgeRegistry<V> from, CallbackInfo ci) { | ||
RegistryUtil.retainFabricClientEntries(name, from, 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