Skip to content

Commit 88c8785

Browse files
committed
i forget
1 parent 507d9c0 commit 88c8785

7 files changed

Lines changed: 74 additions & 58 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
org.gradle.jvmargs = -Xmx1G
22
org.gradle.parallel = true
33

4-
version = 9.1.1
4+
version = 9.2.0
55
maven_group = net.ludocrypt
66
archives_base_name = limlib

src/main/java/net/ludocrypt/limlib/api/LimlibRegistryHooks.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
11
package net.ludocrypt.limlib.api;
22

3-
import java.util.ArrayList;
4-
import java.util.List;
53
import java.util.Map;
4+
import java.util.Set;
65

76
import org.jetbrains.annotations.ApiStatus.Internal;
87

98
import com.google.common.collect.Maps;
9+
import com.google.common.collect.Sets;
10+
import com.google.gson.JsonElement;
1011

1112
import net.minecraft.registry.MutableRegistry;
1213
import net.minecraft.registry.Registry;
1314
import net.minecraft.registry.RegistryKey;
15+
import net.minecraft.registry.RegistryOps;
1416
import net.minecraft.registry.RegistryOps.RegistryInfoLookup;
1517

1618
public class LimlibRegistryHooks {
1719

1820
@Internal
19-
public static final Map<RegistryKey<? extends Registry<?>>, List<LimlibRegistryHook<?>>> REGISTRY_HOOKS = Maps.newHashMap();
21+
public static final Map<RegistryKey<? extends Registry<?>>, Set<LimlibRegistryHook<?>>> REGISTRY_HOOKS = Maps.newHashMap();
22+
@Internal
23+
public static final Map<RegistryKey<? extends Registry<?>>, Set<LimlibJsonRegistryHook<?>>> REGISTRY_JSON_HOOKS = Maps.newHashMap();
2024

2125
public static <O, T extends Registry<O>> void hook(RegistryKey<T> key, LimlibRegistryHook<O> hook) {
22-
List<LimlibRegistryHook<?>> hooks = REGISTRY_HOOKS.computeIfAbsent(key, k -> new ArrayList<>());
26+
Set<LimlibRegistryHook<?>> hooks = REGISTRY_HOOKS.computeIfAbsent(key, k -> Sets.newHashSet());
27+
hooks.add(hook);
28+
}
29+
30+
public static <O, T extends Registry<O>> void hook(RegistryKey<T> key, LimlibJsonRegistryHook<O> hook) {
31+
Set<LimlibJsonRegistryHook<?>> hooks = REGISTRY_JSON_HOOKS.computeIfAbsent(key, k -> Sets.newHashSet());
2332
hooks.add(hook);
2433
}
2534

@@ -35,4 +44,17 @@ public interface LimlibRegistryHook<O> {
3544

3645
}
3746

47+
@FunctionalInterface
48+
public interface LimlibJsonRegistryHook<O> {
49+
50+
/**
51+
* @param infoLookup The full registry lookup.
52+
* @param registryKey The RegistryKey of the registry.
53+
* @param registry The MutableRegistry where to register.
54+
* @param jsonElement The jsonElement to modify before being read by a CODEC.
55+
*/
56+
void register(RegistryInfoLookup infoLookup, RegistryKey<? extends Registry<O>> registryKey, RegistryOps<JsonElement> registryOps, JsonElement jsonElement);
57+
58+
}
59+
3860
}

src/main/java/net/ludocrypt/limlib/api/world/NbtPlacerUtil.java

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import com.mojang.datafixers.util.Pair;
1414

1515
import net.minecraft.block.BlockState;
16-
import net.minecraft.block.Blocks;
1716
import net.minecraft.entity.Entity;
1817
import net.minecraft.entity.EntityType;
1918
import net.minecraft.entity.decoration.AbstractDecorationEntity;
@@ -35,6 +34,7 @@
3534
import net.minecraft.util.math.Direction;
3635
import net.minecraft.util.math.MathHelper;
3736
import net.minecraft.util.math.Vec3d;
37+
import net.minecraft.util.math.Vec3i;
3838
import net.minecraft.world.ChunkRegion;
3939

4040
public class NbtPlacerUtil {
@@ -46,6 +46,7 @@ public class NbtPlacerUtil {
4646
public final int sizeX;
4747
public final int sizeY;
4848
public final int sizeZ;
49+
public final Vec3i sizeVector;
4950

5051
public NbtPlacerUtil(NbtCompound storedNbt, HashMap<BlockPos, Pair<BlockState, Optional<NbtCompound>>> positions, NbtList entities, BlockPos lowestPos, int sizeX, int sizeY, int sizeZ) {
5152
this.storedNbt = storedNbt;
@@ -55,6 +56,7 @@ public NbtPlacerUtil(NbtCompound storedNbt, HashMap<BlockPos, Pair<BlockState, O
5556
this.sizeX = sizeX;
5657
this.sizeY = sizeY;
5758
this.sizeZ = sizeZ;
59+
this.sizeVector = new Vec3i(sizeX, sizeY, sizeZ);
5860
}
5961

6062
public NbtPlacerUtil(NbtCompound storedNbt, HashMap<BlockPos, Pair<BlockState, Optional<NbtCompound>>> positions, NbtList entities, BlockPos lowestPos, BlockPos sizePos) {
@@ -152,26 +154,10 @@ public static NbtCompound readStructure(Resource resource) throws IOException {
152154
}
153155

154156
public NbtPlacerUtil generateNbt(ChunkRegion region, BlockPos at, TriConsumer<BlockPos, BlockState, Optional<NbtCompound>> consumer) {
155-
156-
for (int xi = 0; xi < this.sizeX; xi++) {
157-
158-
for (int yi = 0; yi < this.sizeY; yi++) {
159-
160-
for (int zi = 0; zi < this.sizeZ; zi++) {
161-
Pair<BlockState, Optional<NbtCompound>> pair = this.positions.get(new BlockPos(xi, yi, zi));
162-
BlockState state = pair.getFirst();
163-
Optional<NbtCompound> nbt = pair.getSecond();
164-
consumer.accept(at.add(xi, yi, zi), state == null ? Blocks.BARRIER.getDefaultState() : state, nbt);
165-
}
166-
167-
}
168-
169-
}
170-
171-
return this;
157+
return generateNbt(region, BlockPos.ZERO, at, at.add(this.sizeVector), consumer);
172158
}
173159

174-
public NbtPlacerUtil generateNbt(ChunkRegion region, BlockPos offset, BlockPos from, BlockPos to, TriConsumer<BlockPos, BlockState, Optional<NbtCompound>> consumer) {
160+
public NbtPlacerUtil generateNbt(ChunkRegion region, Vec3i offset, BlockPos from, BlockPos to, TriConsumer<BlockPos, BlockState, Optional<NbtCompound>> consumer) {
175161

176162
for (int xi = 0; xi < Math.min(to.subtract(from).getX(), this.sizeX); xi++) {
177163

@@ -180,9 +166,17 @@ public NbtPlacerUtil generateNbt(ChunkRegion region, BlockPos offset, BlockPos f
180166
for (int zi = 0; zi < Math.min(to.subtract(from).getZ(), this.sizeZ); zi++) {
181167
BlockPos pos = new BlockPos(xi, yi, zi);
182168
Pair<BlockState, Optional<NbtCompound>> pair = this.positions.get(pos.add(offset));
183-
BlockState state = pair.getFirst();
184-
Optional<NbtCompound> nbt = pair.getSecond();
185-
consumer.accept(from.add(pos), state == null ? Blocks.BARRIER.getDefaultState() : state, nbt);
169+
170+
if (pair != null) {
171+
BlockState state = pair.getFirst();
172+
Optional<NbtCompound> nbt = pair.getSecond();
173+
174+
if (state != null) {
175+
consumer.accept(from.add(pos), state, nbt);
176+
}
177+
178+
}
179+
186180
}
187181

188182
}
@@ -412,11 +406,10 @@ public static Vec3d abs(Vec3d in) {
412406

413407
public static NbtList createNbtIntList(int... ints) {
414408
NbtList nbtList = new NbtList();
415-
int[] var3 = ints;
416-
int var4 = ints.length;
409+
int size = ints.length;
417410

418-
for (int var5 = 0; var5 < var4; ++var5) {
419-
int i = var3[var5];
411+
for (int j = 0; j < size; ++j) {
412+
int i = ints[j];
420413
nbtList.add(NbtInt.of(i));
421414
}
422415

src/main/java/net/ludocrypt/limlib/impl/debug/DebugNbtChunkGenerator.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.LinkedHashMap;
66
import java.util.List;
77
import java.util.Map;
8+
import java.util.Optional;
89
import java.util.concurrent.CompletableFuture;
910
import java.util.concurrent.Executor;
1011
import java.util.function.Function;
@@ -19,11 +20,13 @@
1920
import net.ludocrypt.limlib.api.world.NbtPlacerUtil;
2021
import net.ludocrypt.limlib.api.world.chunk.AbstractNbtChunkGenerator;
2122
import net.minecraft.block.Block;
23+
import net.minecraft.block.BlockState;
2224
import net.minecraft.block.Blocks;
2325
import net.minecraft.block.StructureBlock;
2426
import net.minecraft.block.entity.BlockEntity;
2527
import net.minecraft.block.entity.StructureBlockBlockEntity;
2628
import net.minecraft.block.enums.StructureBlockMode;
29+
import net.minecraft.nbt.NbtCompound;
2730
import net.minecraft.registry.Holder;
2831
import net.minecraft.registry.RegistryOps;
2932
import net.minecraft.resource.Resource;
@@ -69,6 +72,11 @@ public int getChunkDistance() {
6972
public CompletableFuture<Chunk> populateNoise(ChunkRegion chunkRegion, ChunkStatus targetStatus, Executor executor, ServerWorld world, ChunkGenerator generator,
7073
StructureTemplateManager structureTemplateManager, ServerLightingProvider lightingProvider, Function<Chunk, CompletableFuture<Either<Chunk, Unloaded>>> fullChunkConverter,
7174
List<Chunk> chunks, Chunk chunk) {
75+
76+
if (chunk.getPos().getStartPos().getX() < 0 || chunk.getPos().getStartPos().getZ() < 0) {
77+
return CompletableFuture.completedFuture(chunk);
78+
}
79+
7280
ResourceManager resourceManager = world.getServer().getResourceManager();
7381

7482
if (positions.isEmpty()) {
@@ -144,7 +152,16 @@ public CompletableFuture<Chunk> populateNoise(ChunkRegion chunkRegion, ChunkStat
144152

145153
@Override
146154
public int getWorldHeight() {
147-
return 384 + 64;
155+
return 448;
156+
}
157+
158+
@Override
159+
protected void modifyStructure(ChunkRegion region, BlockPos pos, BlockState state, Optional<NbtCompound> blockEntityNbt, int update) {
160+
region.setBlockState(pos, state, update, 1);
161+
blockEntityNbt.ifPresent((nbt) -> {
162+
if (region.getBlockEntity(pos) != null)
163+
region.getBlockEntity(pos).readNbt(nbt);
164+
});
148165
}
149166

150167
@Override

src/main/java/net/ludocrypt/limlib/impl/mixin/RegistryLoaderMixin.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
1818

1919
import com.google.common.collect.Lists;
20+
import com.google.common.collect.Sets;
2021
import com.google.gson.JsonElement;
2122
import com.google.gson.JsonObject;
2223
import com.mojang.serialization.Decoder;
2324
import com.mojang.serialization.Lifecycle;
2425

2526
import net.ludocrypt.limlib.api.LimlibRegistryHooks;
27+
import net.ludocrypt.limlib.api.LimlibRegistryHooks.LimlibJsonRegistryHook;
2628
import net.ludocrypt.limlib.api.LimlibRegistryHooks.LimlibRegistryHook;
2729
import net.ludocrypt.limlib.api.LimlibWorld;
2830
import net.ludocrypt.limlib.api.LimlibWorld.RegistryProvider;
@@ -54,7 +56,6 @@ public class RegistryLoaderMixin {
5456
@Final
5557
@Mutable
5658
public static List<RegistryLoader.DecodingData<?>> WORLDGEN_REGISTRIES;
57-
5859
static {
5960
List<RegistryLoader.DecodingData<?>> newRegistries = Lists.newArrayList();
6061
newRegistries.addAll(WORLDGEN_REGISTRIES);
@@ -70,6 +71,7 @@ public class RegistryLoaderMixin {
7071
MutableRegistry<E> registry, Decoder<E> decoder, Map<RegistryKey<?>, Exception> readFailures, CallbackInfo ci, String string, ResourceFileNamespace resourceFileNamespace,
7172
RegistryOps<JsonElement> registryOps, Iterator<Map.Entry<Identifier, Resource>> var9, Map.Entry<Identifier, Resource> entry, Identifier identifier, RegistryKey<E> registryKey2,
7273
Resource resource, Reader reader, JsonElement jsonElement) {
74+
7375
if (registryKey2.isOf(RegistryKeys.GENERATOR_TYPE)) {
7476
JsonObject presetType = jsonElement.getAsJsonObject();
7577
JsonObject dimensions = presetType.get("dimensions").getAsJsonObject();
@@ -83,17 +85,21 @@ public <T> HolderProvider<T> get(RegistryKey<Registry<T>> key) {
8385

8486
})).result().get()));
8587
}
88+
89+
LimlibRegistryHooks.REGISTRY_JSON_HOOKS.getOrDefault(registryKey, Sets.newHashSet())
90+
.forEach((registrarhook -> ((LimlibJsonRegistryHook<E>) registrarhook).register(infoLookup, registryKey, registryOps, jsonElement)));
8691
}
8792

88-
@Inject(method = "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))
93+
@Inject(method = "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("TAIL"))
8994
private static <E> void limlib$loadRegistryContents(RegistryOps.RegistryInfoLookup infoLookup, ResourceManager resourceManager, RegistryKey<? extends Registry<E>> registryKey,
9095
MutableRegistry<E> registry, Decoder<E> decoder, Map<RegistryKey<?>, Exception> readFailures, CallbackInfo ci) {
91-
LimlibRegistryHooks.REGISTRY_HOOKS.getOrDefault(registryKey, Lists.newArrayList())
92-
.forEach((registrarhook -> ((LimlibRegistryHook<E>) registrarhook).register(infoLookup, registryKey, registry)));
96+
9397
if (registryKey.equals(RegistryKeys.DIMENSION_TYPE)) {
9498
LimlibWorld.LIMLIB_WORLD.getEntries().forEach((world) -> ((MutableRegistry<DimensionType>) registry).register(RegistryKey.of(RegistryKeys.DIMENSION_TYPE, world.getKey().getValue()),
9599
world.getValue().getDimensionTypeSupplier().get(), Lifecycle.stable()));
96100
}
101+
102+
LimlibRegistryHooks.REGISTRY_HOOKS.getOrDefault(registryKey, Sets.newHashSet()).forEach((registrarhook -> ((LimlibRegistryHook<E>) registrarhook).register(infoLookup, registryKey, registry)));
97103
}
98104

99105
@Inject(method = "loadRegistriesIntoManager(Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/registry/DynamicRegistryManager;Ljava/util/List;)Lnet/minecraft/registry/DynamicRegistryManager$Frozen;", at = @At("TAIL"))

src/main/java/net/ludocrypt/limlib/impl/mixin/VanillaDynamicRegistriesMixin.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/main/resources/limlib.mixins.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"RegistriesAccessor",
1212
"RegistryLoaderMixin",
1313
"ServerPlayerEntityMixin",
14-
"VanillaDynamicRegistriesMixin",
1514
"WorldDimensionsMixin",
1615
"WorldSaveStorageMixin"
1716
],

0 commit comments

Comments
 (0)