mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 18:40:46 +00:00
evil registry hacks
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package com.dfsek.terra.lifecycle.mixin;
|
||||
|
||||
|
||||
import net.minecraft.registry.entry.RegistryEntry.Reference;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
|
||||
@Mixin(Reference.class)
|
||||
public interface RegistryEntryReferenceInvoker<T> {
|
||||
@Invoker("setValue")
|
||||
void invokeSetValue(T value);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.dfsek.terra.lifecycle.mixin;
|
||||
|
||||
import com.dfsek.terra.lifecycle.util.RegistryHack;
|
||||
|
||||
import net.minecraft.registry.SimpleRegistry;
|
||||
import net.minecraft.registry.entry.RegistryEntry;
|
||||
import net.minecraft.registry.entry.RegistryEntry.Reference;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Mixin(SimpleRegistry.class)
|
||||
public class SimpleRegistryMixin<T> implements RegistryHack {
|
||||
@Shadow
|
||||
@Final
|
||||
private Map<T, Reference<T>> valueToEntry;
|
||||
|
||||
@Override
|
||||
public void terra_bind() {
|
||||
valueToEntry.forEach((value, entry) -> {
|
||||
//noinspection unchecked
|
||||
((RegistryEntryReferenceInvoker<T>) entry).invokeSetValue(value);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package com.dfsek.terra.lifecycle.mixin.lifecycle;
|
||||
|
||||
import com.dfsek.terra.lifecycle.LifecyclePlatform;
|
||||
|
||||
import com.dfsek.terra.lifecycle.util.RegistryHack;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.registry.MutableRegistry;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
@@ -34,32 +36,18 @@ public class RegistryLoaderMixin {
|
||||
)
|
||||
)
|
||||
private static void grabManager(List<Pair<MutableRegistry<?>, Object>> instance, Consumer<Pair<MutableRegistry<?>, Object>> consumer) {
|
||||
MutableRegistry<Biome> biomeMutableRegistry = (MutableRegistry<Biome>)
|
||||
instance.stream()
|
||||
.map(Pair::getFirst)
|
||||
.filter(r -> r.getKey().equals(RegistryKeys.BIOME))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
MutableRegistry<WorldPreset> worldPresetMutableRegistry = (MutableRegistry<WorldPreset>)
|
||||
instance.stream()
|
||||
.map(Pair::getFirst)
|
||||
.filter(r -> r.getKey().equals(RegistryKeys.WORLD_PRESET))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
MutableRegistry<DimensionType> dimensionTypeMutableRegistry = (MutableRegistry<DimensionType>)
|
||||
instance.stream()
|
||||
.map(Pair::getFirst)
|
||||
.filter(r -> r.getKey().equals(RegistryKeys.DIMENSION_TYPE))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
MutableRegistry<ChunkGeneratorSettings> chunkGeneratorSettingsMutableRegistry = (MutableRegistry<ChunkGeneratorSettings>)
|
||||
instance.stream()
|
||||
.map(Pair::getFirst)
|
||||
.filter(r -> r.getKey().equals(RegistryKeys.CHUNK_GENERATOR_SETTINGS))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
LifecyclePlatform.setRegistries(biomeMutableRegistry, dimensionTypeMutableRegistry, chunkGeneratorSettingsMutableRegistry);
|
||||
LifecycleUtil.initialize(biomeMutableRegistry, worldPresetMutableRegistry);
|
||||
|
||||
//LifecyclePlatform.setRegistries(biomeMutableRegistry, dimensionTypeMutableRegistry, chunkGeneratorSettingsMutableRegistry);
|
||||
//LifecycleUtil.initialize(biomeMutableRegistry, worldPresetMutableRegistry);
|
||||
instance.forEach(mutableRegistryObjectPair -> {
|
||||
System.out.println(mutableRegistryObjectPair.getFirst());
|
||||
System.out.println(mutableRegistryObjectPair.getFirst().size());
|
||||
if(mutableRegistryObjectPair.getFirst().getKey().equals(RegistryKeys.BIOME)) {
|
||||
((RegistryHack) mutableRegistryObjectPair.getFirst()).terra_bind();
|
||||
System.out.println("BIOMES: " + mutableRegistryObjectPair.getFirst().stream().toList());
|
||||
}
|
||||
//System.out.println(mutableRegistryObjectPair.getFirst().stream().toList());
|
||||
});
|
||||
instance.forEach(consumer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.dfsek.terra.lifecycle.util;
|
||||
|
||||
public interface RegistryHack {
|
||||
void terra_bind();
|
||||
}
|
||||
@@ -5,7 +5,9 @@
|
||||
"compatibilityLevel" : "JAVA_17",
|
||||
"mixins" : [
|
||||
"NoiseConfigMixin",
|
||||
"RegistryEntryReferenceInvoker",
|
||||
"RegistryMixin",
|
||||
"SimpleRegistryMixin",
|
||||
"lifecycle.MinecraftServerMixin",
|
||||
"lifecycle.RegistryLoaderMixin"
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user