mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-08 06:26:43 +01:00
Fixed item replacement not working correctly without liteloader
This commit is contained in:
parent
81b7693e34
commit
5dd390140d
1 changed files with 23 additions and 3 deletions
|
@ -1,11 +1,14 @@
|
||||||
package com.minelittlepony.unicopia.forgebullshit;
|
package com.minelittlepony.unicopia.forgebullshit;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
import net.minecraft.util.registry.RegistryNamespaced;
|
import net.minecraft.util.registry.RegistryNamespaced;
|
||||||
|
import net.minecraftforge.fml.common.Loader;
|
||||||
|
import net.minecraftforge.fml.common.ModContainer;
|
||||||
import net.minecraftforge.registries.ILockableRegistry;
|
import net.minecraftforge.registries.ILockableRegistry;
|
||||||
|
|
||||||
public class RegistryLockSpinner {
|
public final class RegistryLockSpinner {
|
||||||
|
|
||||||
public static void unlock(RegistryNamespaced<?, ?> registry) {
|
public static void unlock(RegistryNamespaced<?, ?> registry) {
|
||||||
if (registry instanceof ILockableRegistry) {
|
if (registry instanceof ILockableRegistry) {
|
||||||
|
@ -21,15 +24,32 @@ public class RegistryLockSpinner {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <K, V> void commit(RegistryNamespaced<K, V> registry, V from, V to, Class<?> inClass) {
|
public static <K, V> void commit(RegistryNamespaced<K, V> registry, V from, V to, Class<?> inClass) {
|
||||||
|
|
||||||
registry.register(registry.getIDForObject(from), registry.getNameForObject(from), to);
|
registry.register(registry.getIDForObject(from), registry.getNameForObject(from), to);
|
||||||
|
|
||||||
|
Field modifieres = null;
|
||||||
|
try {
|
||||||
|
modifieres = Field.class.getDeclaredField("modifiers");
|
||||||
|
modifieres.setAccessible(true);
|
||||||
|
} catch (NoSuchFieldException | SecurityException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
for (Field i : inClass.getDeclaredFields()) {
|
for (Field i : inClass.getDeclaredFields()) {
|
||||||
try {
|
try {
|
||||||
if (i.get(null) == from) {
|
if (i.get(null) == from) {
|
||||||
|
i.setAccessible(true);
|
||||||
|
|
||||||
|
if (Modifier.isFinal(i.getModifiers())) {
|
||||||
|
if (modifieres == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
modifieres.setInt(i, i.getModifiers() & ~Modifier.FINAL);
|
||||||
|
}
|
||||||
|
|
||||||
i.set(null, to);
|
i.set(null, to);
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
} catch (IllegalArgumentException | IllegalAccessException | SecurityException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue