Skip to content

Commit

Permalink
Updated to 1.20.4 removed qsl
Browse files Browse the repository at this point in the history
  • Loading branch information
LudoCrypt committed Dec 9, 2023
1 parent b527557 commit 9097025
Show file tree
Hide file tree
Showing 24 changed files with 299 additions and 94 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies {
minecraft libs.minecraft
mappings variantOf(libs.quilt.mappings) { classifier 'intermediary-v2' }
modImplementation libs.quilt.loader
modImplementation libs.quilted.fabric.api
// modImplementation libs.quilted.fabric.api
}

processResources {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
org.gradle.jvmargs = -Xmx1G
org.gradle.parallel = true

version = 11.0.0
version = 11.1.0
maven_group = net.ludocrypt
archives_base_name = limlib
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
minecraft = "1.20.1"
quilt_mappings = "1.20.1+build.9"
minecraft = "1.20.4"
quilt_mappings = "1.20.4+build.1"
quilt_loader = "0.21.0"

quilted_fabric_api = "7.4.0+0.90.0-1.20.1"
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/net/ludocrypt/limlib/api/LimlibRegistryHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryOps;
import net.minecraft.registry.RegistryOps.RegistryInfoLookup;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;

public class LimlibRegistryHooks {

Expand All @@ -23,6 +26,8 @@ public class LimlibRegistryHooks {
@Internal
public static final Map<RegistryKey<? extends Registry<?>>, Set<LimlibJsonRegistryHook<?>>> REGISTRY_JSON_HOOKS = Maps
.newHashMap();
@Internal
public static final Map<TagKey<?>, Set<LimlibJsonTagHook<?>>> TAG_JSON_HOOKS = Maps.newHashMap();

public static <O, T extends Registry<O>> void hook(RegistryKey<T> key, LimlibRegistryHook<O> hook) {
Set<LimlibRegistryHook<?>> hooks = REGISTRY_HOOKS.computeIfAbsent(key, k -> Sets.newHashSet());
Expand All @@ -34,6 +39,16 @@ public static <O, T extends Registry<O>> void hook(RegistryKey<T> key, LimlibJso
hooks.add(hook);
}

public static <O, T extends Registry<O>> void hook(RegistryKey<T> key, Identifier tag, LimlibJsonTagHook<O> hook) {
Set<LimlibJsonTagHook<?>> hooks = TAG_JSON_HOOKS.computeIfAbsent(TagKey.of(key, tag), k -> Sets.newHashSet());
hooks.add(hook);
}

public static <O> void hook(TagKey<O> key, LimlibJsonTagHook<O> hook) {
Set<LimlibJsonTagHook<?>> hooks = TAG_JSON_HOOKS.computeIfAbsent(key, k -> Sets.newHashSet());
hooks.add(hook);
}

@FunctionalInterface
public interface LimlibRegistryHook<O> {

Expand Down Expand Up @@ -61,4 +76,17 @@ void register(RegistryInfoLookup infoLookup, RegistryKey<? extends Registry<O>>

}

@FunctionalInterface
public interface LimlibJsonTagHook<O> {

/**
* @param ResourceManager The resource manager.
* @param tag The tag being hooked into.
* @param jsonElement The jsonElement to modify before being read by a
* CODEC.
*/
void register(ResourceManager manager, TagKey<O> tag, JsonElement jsonElement);

}

}
17 changes: 15 additions & 2 deletions src/main/java/net/ludocrypt/limlib/api/LimlibTravelling.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.Set;

import org.jetbrains.annotations.ApiStatus.Internal;
import org.quiltmc.qsl.worldgen.dimension.api.QuiltDimensions;

import net.minecraft.entity.Entity;
import net.minecraft.server.network.ServerPlayerEntity;
Expand All @@ -28,6 +27,7 @@ public class LimlibTravelling {
@Internal
public static float travelingPitch = 1.0F;

@SuppressWarnings("unchecked")
public static <E extends Entity> E travelTo(E teleported, ServerWorld destination, TeleportTarget target,
SoundEvent sound, float volume, float pitch) {

Expand Down Expand Up @@ -70,12 +70,17 @@ public static <E extends Entity> E travelTo(E teleported, ServerWorld destinatio
return teleported;
} else {

((Travelling) teleported).limlib$setTeleportTarget(target);

try {
travelingSound = sound;
travelingVolume = volume;
travelingPitch = pitch;
return QuiltDimensions.teleport(teleported, destination, target);

return (E) teleported.moveToWorld(destination);

} finally {
((Travelling) teleported).limlib$setTeleportTarget(null);
travelingSound = null;
travelingVolume = 0.0F;
travelingPitch = 0.0F;
Expand All @@ -85,4 +90,12 @@ public static <E extends Entity> E travelTo(E teleported, ServerWorld destinatio

}

public static interface Travelling {

public TeleportTarget limlib$getTeleportTarget();

public void limlib$setTeleportTarget(TeleportTarget teleportTarget);

}

}
11 changes: 4 additions & 7 deletions src/main/java/net/ludocrypt/limlib/api/LimlibWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.mojang.serialization.Lifecycle;

import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder;
import net.fabricmc.fabric.api.event.registry.RegistryAttribute;
import net.ludocrypt.limlib.impl.mixin.RegistriesAccessor;
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.dimension.DimensionOptions;
import net.minecraft.world.dimension.DimensionType;
Expand All @@ -18,10 +17,8 @@ public class LimlibWorld {

public static final RegistryKey<Registry<LimlibWorld>> LIMLIB_WORLD_KEY = RegistryKey
.ofRegistry(new Identifier("limlib", "limlib_world"));
public static final SimpleRegistry<LimlibWorld> LIMLIB_WORLD = FabricRegistryBuilder
.createSimple(LIMLIB_WORLD_KEY)
.attribute(RegistryAttribute.SYNCED)
.buildAndRegister();
public static final Registry<LimlibWorld> LIMLIB_WORLD = RegistriesAccessor
.callRegisterSimple(LIMLIB_WORLD_KEY, Lifecycle.stable(), registry -> new LimlibWorld(() -> null, (r) -> null));

private Supplier<DimensionType> dimensionTypeSupplier;
private Function<RegistryProvider, DimensionOptions> dimensionOptionsSupplier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import net.minecraft.nbt.NbtInt;
import net.minecraft.nbt.NbtIo;
import net.minecraft.nbt.NbtList;
import net.minecraft.nbt.NbtTagSizeTracker;
import net.minecraft.registry.Registries;
import net.minecraft.resource.Resource;
import net.minecraft.resource.ResourceManager;
Expand Down Expand Up @@ -198,7 +199,7 @@ public static Optional<NbtCompound> loadNbtSafe(Identifier id, ResourceManager m

public static NbtCompound readStructure(Resource resource) throws IOException {
InputStream stream = resource.open();
NbtCompound nbt = NbtIo.readCompressed(stream);
NbtCompound nbt = NbtIo.method_10629(stream, NbtTagSizeTracker.method_53898());
stream.close();
return nbt;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected void modifyStructure(ChunkRegion region, BlockPos pos, BlockState stat

if (blockEntity instanceof LootableContainerBlockEntity lootTable) {
lootTable
.setLootTable(this.getContainerLootTable(lootTable), region.getSeed() + LimlibHelper.blockSeed(pos));
.method_54867(this.getContainerLootTable(lootTable), region.getSeed() + LimlibHelper.blockSeed(pos));
}

}
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/net/ludocrypt/limlib/impl/Limlib.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package net.ludocrypt.limlib.impl;

import org.quiltmc.loader.api.ModContainer;
import org.quiltmc.loader.api.QuiltLoader;
import org.quiltmc.qsl.base.api.entrypoint.ModInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -26,12 +24,11 @@
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;

public class Limlib implements ModInitializer {
public class Limlib {

public static final Logger LOGGER = LoggerFactory.getLogger("Limlib");

@Override
public void onInitialize(ModContainer mod) {
public static void onInitialize() {
LimlibWorld.load();
Registry.register(ReverbEffect.REVERB_EFFECT_CODEC, new Identifier("limlib", "static"), StaticReverbEffect.CODEC);
Registry
Expand Down
17 changes: 0 additions & 17 deletions src/main/java/net/ludocrypt/limlib/impl/LimlibClient.java

This file was deleted.

11 changes: 0 additions & 11 deletions src/main/java/net/ludocrypt/limlib/impl/SaveStorageSupplier.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.ludocrypt.limlib.impl.access;

import java.util.Optional;

import org.jetbrains.annotations.Nullable;

import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;

public interface TagGroupLoaderAccess {

public Optional<RegistryKey<? extends Registry<?>>> getRegistryKey();

public void setRegistryKey(@Nullable RegistryKey<? extends Registry<?>> key);

}
19 changes: 16 additions & 3 deletions src/main/java/net/ludocrypt/limlib/impl/debug/DebugWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import java.util.Map;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.mojang.serialization.Lifecycle;

import net.ludocrypt.limlib.api.LimlibRegistrar;
import net.ludocrypt.limlib.api.LimlibRegistryHooks;
import net.minecraft.client.world.GeneratorType;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.WorldPresetTags;
import net.minecraft.util.Identifier;
import net.minecraft.world.biome.Biomes;
import net.minecraft.world.dimension.DimensionOptions;
Expand All @@ -21,8 +24,8 @@ public class DebugWorld implements LimlibRegistrar {

@Override
public void registerHooks() {
LimlibRegistryHooks
.hook(RegistryKeys.GENERATOR_TYPE, (infoLookup, registryKey, registry) -> registry
LimlibRegistryHooks.hook(RegistryKeys.GENERATOR_TYPE, (infoLookup, registryKey, registry) -> {
registry
.register(DEBUG_KEY, new GeneratorType(Map
.of(DimensionOptions.OVERWORLD,
new DimensionOptions(
Expand All @@ -33,7 +36,17 @@ public void registerHooks() {
.getHolderOrThrow(DimensionTypes.OVERWORLD),
new DebugNbtChunkGenerator(
infoLookup.lookup(RegistryKeys.BIOME).get().getter().getHolderOrThrow(Biomes.THE_VOID))))),
Lifecycle.stable()));
Lifecycle.stable());
});
LimlibRegistryHooks.hook(WorldPresetTags.EXTENDED, (manager, tag, json) -> {
JsonObject obj = json.getAsJsonObject();

if (obj.has("values")) {
JsonArray values = obj.get("values").getAsJsonArray();
values.add(DEBUG_KEY.getValue().toString());
}

});
}

}
20 changes: 20 additions & 0 deletions src/main/java/net/ludocrypt/limlib/impl/mixin/BootstrapMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.ludocrypt.limlib.impl.mixin;

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 net.ludocrypt.limlib.impl.Limlib;
import net.minecraft.Bootstrap;

@Mixin(Bootstrap.class)
public class BootstrapMixin {

@Inject(method = "initialize", at = @At(value = "INVOKE", target = "Lnet/minecraft/recipe/BrewingRecipeRegistry;registerDefaults()V", shift = Shift.AFTER))
private static void limlib$initialize(CallbackInfo ci) {
Limlib.onInitialize();
}

}
39 changes: 39 additions & 0 deletions src/main/java/net/ludocrypt/limlib/impl/mixin/EntityMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package net.ludocrypt.limlib.impl.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import net.ludocrypt.limlib.api.LimlibTravelling.Travelling;
import net.minecraft.entity.Entity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.TeleportTarget;

@Mixin(Entity.class)
public class EntityMixin implements Travelling {

@Unique
public TeleportTarget limlib$overriddenTeleportTarget = null;

@Inject(method = "getTeleportTarget(Lnet/minecraft/server/world/ServerWorld;)Lnet/minecraft/world/TeleportTarget;", at = @At("HEAD"), cancellable = true)
public void limlib$getTeleportTarget(ServerWorld destination, CallbackInfoReturnable<TeleportTarget> cir) {

if (this.limlib$overriddenTeleportTarget != null) {
cir.setReturnValue(this.limlib$overriddenTeleportTarget);
}

}

@Override
public TeleportTarget limlib$getTeleportTarget() {
return limlib$overriddenTeleportTarget;
}

@Override
public void limlib$setTeleportTarget(TeleportTarget teleportTarget) {
this.limlib$overriddenTeleportTarget = teleportTarget;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
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.common.collect.Lists;
Expand All @@ -32,8 +31,6 @@
import net.ludocrypt.limlib.api.effects.sky.DimensionEffects;
import net.ludocrypt.limlib.api.effects.sound.SoundEffects;
import net.ludocrypt.limlib.api.skybox.Skybox;
import net.ludocrypt.limlib.impl.SaveStorageSupplier;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.HolderProvider;
import net.minecraft.registry.MutableRegistry;
import net.minecraft.registry.Registry;
Expand Down Expand Up @@ -119,11 +116,4 @@ public <T> HolderProvider<T> get(RegistryKey<Registry<T>> key) {
.forEach((registrarhook -> ((LimlibRegistryHook<E>) registrarhook).register(infoLookup, registryKey, registry)));
}

@Inject(method = "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) {
SaveStorageSupplier.LOADED_REGISTRY.set(registryManager.freeze());
}

}
Loading

0 comments on commit 9097025

Please sign in to comment.