Skip to content

Commit

Permalink
Fixed most things
Browse files Browse the repository at this point in the history
  • Loading branch information
LudoCrypt committed Jan 13, 2023
1 parent c5bf1bc commit b1c712a
Show file tree
Hide file tree
Showing 15 changed files with 179 additions and 113 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ org.gradle.jvmargs = -Xmx1G
org.gradle.parallel = false
org.gradle.workers.max = 1

version=7.3.2
version=7.3.3
maven_group=net.ludocrypt
archives_base_name=limlib
2 changes: 1 addition & 1 deletion limlib_effects/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ org.gradle.jvmargs = -Xmx1G
org.gradle.parallel = false
org.gradle.workers.max = 1

version=7.3.2
version=7.3.3
maven_group=net.ludocrypt
archives_base_name=limlib-effects
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.registry.RegistryKey;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import net.minecraft.world.World;

@Mixin(GameRenderer.class)
public class GameRendererMixin {
Expand All @@ -30,27 +30,16 @@ public class GameRendererMixin {
private MinecraftClient client;

@Unique
private final Function<RegistryKey<World>, Optional<ManagedShaderEffect>> memoizedShaders = Util.memoize((world) -> {
Optional<PostEffect> optionalPostEffect = LimlibEffects.snatch(client.world.getRegistryManager().getLookup(PostEffect.POST_EFFECT_KEY).get(), RegistryKey.of(PostEffect.POST_EFFECT_KEY, client.world.getRegistryKey().getValue()));
if (optionalPostEffect.isPresent()) {
if (optionalPostEffect.get().getShaderLocation() != null) {
return Optional.of(ShaderEffectManager.getInstance().manage(optionalPostEffect.get().getShaderLocation()));
}
}
return Optional.empty();
});
private final Function<Identifier, ManagedShaderEffect> memoizedShaders = Util.memoize(id -> ShaderEffectManager.getInstance().manage(id));

@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldRenderer;drawEntityOutlinesFramebuffer()V", shift = Shift.AFTER))
private void limlib$render(float tickDelta, long nanoTime, boolean renderLevel, CallbackInfo info) {
Optional<PostEffect> optionalPostEffect = LimlibEffects.snatch(client.world.getRegistryManager().getLookup(PostEffect.POST_EFFECT_KEY).get(), RegistryKey.of(PostEffect.POST_EFFECT_KEY, client.world.getRegistryKey().getValue()));
if (optionalPostEffect.isPresent()) {
PostEffect postEffect = optionalPostEffect.get();
if (postEffect.shouldRender()) {
Optional<ManagedShaderEffect> shaderEffect = memoizedShaders.apply(client.world.getRegistryKey());
if (shaderEffect.isPresent()) {
postEffect.beforeRender();
shaderEffect.get().render(tickDelta);
}
postEffect.beforeRender();
memoizedShaders.apply(postEffect.getShaderLocation()).render(tickDelta);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion limlib_registry/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ org.gradle.jvmargs = -Xmx1G
org.gradle.parallel = false
org.gradle.workers.max = 1

version=7.3.2
version=7.3.3
maven_group=net.ludocrypt
archives_base_name=limlib-registry
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package net.ludocrypt.limlib.registry.mixin;

import java.util.Set;

import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.At.Shift;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.google.common.collect.Sets;

import net.ludocrypt.limlib.registry.registration.LimlibWorld;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.unmapped.C_oiwekzxo;
import net.minecraft.world.dimension.DimensionOptions;

@Mixin(C_oiwekzxo.class)
public class DimensionOptionsC_oiwekzxoMixin {

@Shadow
@Final
@Mutable
private static Set<RegistryKey<DimensionOptions>> f_txffzdje;

@Inject(method = "<clinit>", at = @At(value = "INVOKE", target = "Ljava/util/Set;size()I", shift = Shift.BEFORE, ordinal = 0))
private static void limlib$clinit(CallbackInfo ci) {
Set<RegistryKey<DimensionOptions>> dimensions = Sets.newHashSet();
dimensions.addAll(f_txffzdje);
LimlibWorld.LIMLIB_WORLD.getEntries().forEach((entry) -> dimensions.add(RegistryKey.of(RegistryKeys.DIMENSION, entry.getKey().getValue())));
f_txffzdje = dimensions;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package net.ludocrypt.limlib.registry.mixin;

import java.io.Reader;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.quiltmc.loader.api.QuiltLoader;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.At.Shift;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.mojang.serialization.Decoder;
import com.mojang.serialization.Lifecycle;

import net.ludocrypt.limlib.registry.registration.LimlibWorld;
import net.ludocrypt.limlib.registry.registration.LimlibWorld.RegistryProvider;
import net.ludocrypt.limlib.registry.registration.RegistryLoaderBootstrap;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.HolderProvider;
import net.minecraft.registry.MutableRegistry;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.RegistryLoader;
import net.minecraft.registry.RegistryOps;
import net.minecraft.registry.ResourceFileNamespace;
import net.minecraft.resource.Resource;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;
import net.minecraft.world.dimension.DimensionOptions;
import net.minecraft.world.dimension.DimensionType;

@Mixin(RegistryLoader.class)
public class RegistryLoaderMixin {

@Inject(method = "Lnet/minecraft/registry/RegistryLoader;loadRegistryContents(Lnet/minecraft/registry/RegistryOps$RegistryInfoLookup;Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/registry/RegistryKey;Lnet/minecraft/registry/MutableRegistry;Lcom/mojang/serialization/Decoder;Ljava/util/Map;)V", at = @At(value = "INVOKE", target = "Lcom/mojang/serialization/Decoder;parse(Lcom/mojang/serialization/DynamicOps;Ljava/lang/Object;)Lcom/mojang/serialization/DataResult;", shift = Shift.BEFORE), locals = LocalCapture.CAPTURE_FAILHARD)
private static <E> void limlib$loadRegistryContents(RegistryOps.RegistryInfoLookup infoLookup, ResourceManager resourceManager, RegistryKey<? extends Registry<E>> registryKey, MutableRegistry<E> registry, Decoder<E> decoder, Map<RegistryKey<?>, Exception> readFailures, CallbackInfo ci, String string, ResourceFileNamespace resourceFileNamespace, RegistryOps<JsonElement> registryOps, Iterator<Map.Entry<Identifier, Resource>> var9, Map.Entry<Identifier, Resource> entry, Identifier identifier, RegistryKey<E> registryKey2, Resource resource, Reader reader, JsonElement jsonElement) {
if (registryKey2.isOf(RegistryKeys.GENERATOR_TYPE)) {
JsonObject presetType = jsonElement.getAsJsonObject();
JsonObject dimensions = presetType.get("dimensions").getAsJsonObject();
LimlibWorld.LIMLIB_WORLD.getEntries().forEach((world) -> dimensions.add(world.getKey().getValue().toString(), DimensionOptions.CODEC.encodeStart(registryOps, world.getValue().getDimensionOptionsSupplier().apply(new RegistryProvider() {

@Override
public <T> HolderProvider<T> get(RegistryKey<Registry<T>> key) {
return registryOps.getHolderProvider(key).get();
}

})).result().get()));
}
}

@SuppressWarnings("unchecked")
@Inject(method = "Lnet/minecraft/registry/RegistryLoader;loadRegistryContents(Lnet/minecraft/registry/RegistryOps$RegistryInfoLookup;Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/registry/RegistryKey;Lnet/minecraft/registry/MutableRegistry;Lcom/mojang/serialization/Decoder;Ljava/util/Map;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/registry/ResourceFileNamespace;findMatchingResources(Lnet/minecraft/resource/ResourceManager;)Ljava/util/Map;", shift = Shift.BEFORE))
private static <E> void limlib$loadRegistryContents(RegistryOps.RegistryInfoLookup infoLookup, ResourceManager resourceManager, RegistryKey<? extends Registry<E>> registryKey, MutableRegistry<E> registry, Decoder<E> decoder, Map<RegistryKey<?>, Exception> readFailures, CallbackInfo ci) {
QuiltLoader.getEntrypoints(RegistryLoaderBootstrap.ENTRYPOINT_KEY, RegistryLoaderBootstrap.class).forEach((bootstrap) -> bootstrap.register(infoLookup, registryKey, registry));
if (registryKey.equals(RegistryKeys.DIMENSION_TYPE)) {
LimlibWorld.LIMLIB_WORLD.getEntries().forEach((world) -> ((MutableRegistry<DimensionType>) registry).register(RegistryKey.of(RegistryKeys.DIMENSION_TYPE, world.getKey().getValue()), world.getValue().getDimensionTypeSupplier().get(), Lifecycle.stable()));
}
}

@Inject(method = "Lnet/minecraft/registry/RegistryLoader;loadRegistriesIntoManager(Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/registry/DynamicRegistryManager;Ljava/util/List;)Lnet/minecraft/registry/DynamicRegistryManager$Frozen;", at = @At("TAIL"))
private static void limlib$loadRegistriesIntoManager(ResourceManager resourceManager, DynamicRegistryManager registryManager, List<RegistryLoader.DecodingData<?>> decodingData, CallbackInfoReturnable<DynamicRegistryManager.Frozen> ci) {
LimlibWorld.LOADED_REGISTRY.set(registryManager.freeze());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.ludocrypt.limlib.registry.registration.PreRegistration;
import net.ludocrypt.limlib.registry.registration.DimensionBootstrap;
import net.minecraft.registry.VanillaDynamicRegistries;

@Mixin(VanillaDynamicRegistries.class)
public class VanillaDynamicRegistriesMixin {

@Inject(method = "<clinit>", at = @At(value = "NEW", target = "net/minecraft/registry/RegistrySetBuilder", shift = Shift.BEFORE, ordinal = 0))
private static void limlib$clinit(CallbackInfo ci) {
QuiltLoader.getEntrypoints(PreRegistration.ENTRYPOINT_KEY, PreRegistration.class).forEach(PreRegistration::register);
QuiltLoader.getEntrypoints(DimensionBootstrap.ENTRYPOINT_KEY, DimensionBootstrap.class).forEach(DimensionBootstrap::register);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@

import com.google.common.collect.Maps;
import com.mojang.datafixers.DataFixer;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.Dynamic;

import net.ludocrypt.limlib.registry.registration.LimlibWorld;
import net.ludocrypt.limlib.registry.registration.LimlibWorld.RegistryProvider;
import net.minecraft.nbt.NbtOps;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.HolderProvider;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.RegistryOps;
import net.minecraft.registry.ServerRegistryLayer;
import net.minecraft.world.dimension.DimensionOptions;
import net.minecraft.world.storage.WorldSaveStorage;

Expand All @@ -42,9 +42,16 @@ public class WorldSaveStorageMixin {
if (!dimensions.get(key.getValue().toString()).result().isPresent()) {
Map<Dynamic<T>, Dynamic<T>> dimensionsMap = Maps.newHashMap(dimensions.getMapValues().result().get());

DynamicRegistryManager registryManager = ServerRegistryLayer.createLayeredManager().getCompositeManager();
DynamicRegistryManager registryManager = LimlibWorld.LOADED_REGISTRY.get();

dimensionsMap.put(dimensions.createString(key.getValue().toString()), new Dynamic<T>(dimensions.getOps(), (T) DimensionOptions.CODEC.encodeStart(RegistryOps.create(NbtOps.INSTANCE, registryManager), world.getDimensionOptionsSupplier().apply(Pair.of(registryManager.getLookup(RegistryKeys.DIMENSION_TYPE).get(), registryManager.getLookup(RegistryKeys.BIOME).get()))).result().get()));
dimensionsMap.put(dimensions.createString(key.getValue().toString()), new Dynamic<T>(dimensions.getOps(), (T) DimensionOptions.CODEC.encodeStart(RegistryOps.create(NbtOps.INSTANCE, registryManager), world.getDimensionOptionsSupplier().apply(new RegistryProvider() {

@Override
public <Q> HolderProvider<Q> get(RegistryKey<Registry<Q>> key) {
return registryManager.getLookup(key).get();
}

})).result().get()));
in = in.set("dimensions", in.createMap(dimensionsMap));
}
return in;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package net.ludocrypt.limlib.registry.registration;

/**
* A built-in registry helper.
* Bootstrap Registration for World's
* <p>
* In {@code quilt.mod.json}, the entrypoint is defined with
* {@value #ENTRYPOINT_KEY} key.
* <p>
*/
public interface PreRegistration {
public interface DimensionBootstrap {

/**
* Represents the key which this entrypoint is defined with, whose value is
* {@value}.
*/
public static String ENTRYPOINT_KEY = "limlib:pre_registration";
public static String ENTRYPOINT_KEY = "limlib:dimension_bootstrap";

/**
* Registers everything.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package net.ludocrypt.limlib.registry.registration;

import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

import org.jetbrains.annotations.Nullable;

import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.Maps;
import com.mojang.datafixers.util.Pair;
import com.google.common.base.Suppliers;

import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder;
import net.fabricmc.fabric.api.event.registry.RegistryAttribute;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.HolderProvider;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.SimpleRegistry;
import net.minecraft.util.Identifier;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.dimension.DimensionOptions;
import net.minecraft.world.dimension.DimensionType;

Expand All @@ -27,56 +25,25 @@ public class LimlibWorld {
public static final SimpleRegistry<LimlibWorld> LIMLIB_WORLD = FabricRegistryBuilder.createSimple(LimlibWorld.class, new Identifier("limlib", "limlib_world")).attribute(RegistryAttribute.SYNCED).buildAndRegister();

private Supplier<DimensionType> dimensionTypeSupplier;
private Function<RegistryProvider, DimensionOptions> dimensionOptionsSupplier;

private Function<Pair<HolderProvider<DimensionType>, HolderProvider<Biome>>, DimensionOptions> dimensionOptionsSupplier;
public static final AtomicReference<DynamicRegistryManager.Frozen> LOADED_REGISTRY = new AtomicReference<DynamicRegistryManager.Frozen>();

public LimlibWorld(Supplier<DimensionType> dimensionTypeSupplier, Function<Pair<HolderProvider<DimensionType>, HolderProvider<Biome>>, DimensionOptions> dimensionOptionsSupplier) {
this.dimensionTypeSupplier = memoize(dimensionTypeSupplier);
this.dimensionOptionsSupplier = memoize(dimensionOptionsSupplier);
public LimlibWorld(Supplier<DimensionType> dimensionTypeSupplier, Function<RegistryProvider, DimensionOptions> dimensionOptionsSupplier) {
this.dimensionTypeSupplier = Suppliers.memoize(dimensionTypeSupplier);
this.dimensionOptionsSupplier = dimensionOptionsSupplier;
}

public Supplier<DimensionType> getDimensionTypeSupplier() {
return dimensionTypeSupplier;
}

public Function<Pair<HolderProvider<DimensionType>, HolderProvider<Biome>>, DimensionOptions> getDimensionOptionsSupplier() {
public Function<RegistryProvider, DimensionOptions> getDimensionOptionsSupplier() {
return dimensionOptionsSupplier;
}

private <T> Supplier<T> memoize(Supplier<T> delegate) {
return new Supplier<T>() {

private final AtomicReference<T> cache = new AtomicReference<T>();

@Override
public @Nullable T get() {

if (cache.get() == null) {
cache.set(delegate.get());
}

return cache.get();
}

};
}

private <T, R> Function<T, R> memoize(Function<T, R> delegate) {
return new Function<T, R>() {

private final Map<T, R> cache = Maps.newHashMap();

@Override
public R apply(T in) {

if (!cache.containsKey(in)) {
cache.put(in, delegate.apply(in));
}

return cache.get(in);
}

};
public static interface RegistryProvider {
public <T> HolderProvider<T> get(RegistryKey<Registry<T>> key);
}

}
Loading

0 comments on commit b1c712a

Please sign in to comment.