Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash on Loader 0.15+ #165

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx3G
org.gradle.parallel=true

base_version = 1.9.2
loader_version = 0.14.22
loader_version = 0.15.7
yarn_mappings_build = 530

## Module versions
Expand All @@ -18,6 +18,6 @@ legacy-fabric-lifecycle-events-v1.version = 1.0.1
legacy-fabric-logger-api-v1.version = 1.0.4
legacy-fabric-networking-api-v1.version = 2.0.1
legacy-fabric-permissions-api-v1.version = 1.0.1
legacy-fabric-registry-sync-api-v1.version = 2.1.0
legacy-fabric-registry-sync-api-v1.version = 2.2.0
legacy-fabric-rendering-api-v1.version = 1.0.0
legacy-fabric-resource-loader-v1.version = 2.1.1
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@
import net.minecraft.item.Item;
import net.minecraft.world.biome.Biome;

import net.fabricmc.tinyremapper.extension.mixin.common.data.Pair;

import net.legacyfabric.fabric.api.event.Event;
import net.legacyfabric.fabric.api.event.EventFactory;
import net.legacyfabric.fabric.api.util.BeforeMC;
import net.legacyfabric.fabric.api.util.Identifier;
import net.legacyfabric.fabric.api.util.SinceMC;
import net.legacyfabric.fabric.impl.registry.RegistryHelperImpl;
import net.legacyfabric.fabric.impl.registry.util.BiomePair;

/**
* Allows registration of Blocks, Items, Block Entity Classes, Status Effects and Enchantments.
Expand Down Expand Up @@ -209,7 +208,7 @@ public static Biome registerBiome(EntryCreator<Biome> biome, Identifier id) {
* @return The biomes registered
*/
@BeforeMC("1.9")
public static Pair<Biome, Biome> registerBiomeWithMutatedVariant(
public static BiomePair registerBiomeWithMutatedVariant(
EntryCreator<Biome> parentBiome, Identifier parentId,
EntryCreator<Biome> mutatedBiome, Identifier mutatedId
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.tinyremapper.extension.mixin.common.data.Pair;

import net.legacyfabric.fabric.api.registry.v1.RegistryHelper;
import net.legacyfabric.fabric.api.registry.v1.RegistryIds;
Expand All @@ -50,6 +49,8 @@
import net.legacyfabric.fabric.impl.registry.sync.compat.SimpleRegistryCompat;
import net.legacyfabric.fabric.impl.registry.sync.remappers.RegistryRemapper;
import net.legacyfabric.fabric.impl.registry.util.ArrayAndMapBasedRegistry;
import net.legacyfabric.fabric.impl.registry.util.BiomePair;
import net.legacyfabric.fabric.impl.registry.util.NumericalIdPair;

@ApiStatus.Internal
public class RegistryHelperImpl {
Expand Down Expand Up @@ -168,22 +169,22 @@ public static Biome registerBiome(RegistryHelper.EntryCreator<Biome> biomeCreato
return biome;
}

public static Pair<Biome, Biome> registerBiomeWithMutatedVariant(
public static BiomePair registerBiomeWithMutatedVariant(
RegistryHelper.EntryCreator<Biome> parentBiomeCreator, Identifier parentId,
RegistryHelper.EntryCreator<Biome> mutatedBiomeCreator, Identifier mutatedId
) {
RegistryRemapper<Biome> registryRemapper = RegistryRemapper.getRegistryRemapper(RegistryIds.BIOMES);
Pair<Integer, Integer> rawIds = nextIds(registryRemapper.getRegistry(), 128);
NumericalIdPair rawIds = nextIds(registryRemapper.getRegistry(), 128);

((ArrayAndMapBasedRegistry) registryRemapper.getRegistry()).updateArrayLength(rawIds.second());
((ArrayAndMapBasedRegistry) registryRemapper.getRegistry()).updateArrayLength(rawIds.getSecondary());

Biome parentBiome = parentBiomeCreator.create(rawIds.first());
registryRemapper.register(rawIds.first(), parentId, parentBiome);
Biome parentBiome = parentBiomeCreator.create(rawIds.getMain());
registryRemapper.register(rawIds.getMain(), parentId, parentBiome);

Biome mutatedBiome = mutatedBiomeCreator.create(rawIds.second());
registryRemapper.register(rawIds.second(), mutatedId, mutatedBiome);
Biome mutatedBiome = mutatedBiomeCreator.create(rawIds.getSecondary());
registryRemapper.register(rawIds.getSecondary(), mutatedId, mutatedBiome);

return Pair.of(parentBiome, mutatedBiome);
return new BiomePair(parentBiome, mutatedBiome);
}

public static <V> V getValue(Identifier id, Identifier registryId) {
Expand Down Expand Up @@ -236,7 +237,7 @@ public static int nextId(SimpleRegistryCompat<?, ?> registry, int minId) {
return id;
}

public static Pair<Integer, Integer> nextIds(SimpleRegistryCompat<?, ?> registry, int interval) {
public static NumericalIdPair nextIds(SimpleRegistryCompat<?, ?> registry, int offset) {
int id = 0;

RegistryRemapper<?> registryRemapper = RegistryRemapper.getRegistryRemapper(registry);
Expand All @@ -246,12 +247,12 @@ public static Pair<Integer, Integer> nextIds(SimpleRegistryCompat<?, ?> registry
}

while (id < registryRemapper.getMinId()
|| !(getIdList(registry).fromInt(id) == null && getIdList(registry).fromInt(id + interval) == null)
|| !(getIdList(registry).fromInt(id) == null && getIdList(registry).fromInt(id + offset) == null)
) {
id++;
}

return Pair.of(id, id + interval);
return new NumericalIdPair(id, id + offset);
}

public static int nextId(IdListCompat<?> idList, SimpleRegistryCompat<?, ?> registry) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2020 - 2024 Legacy Fabric
* Copyright (c) 2016 - 2022 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.legacyfabric.fabric.impl.registry.util;

import net.minecraft.world.biome.Biome;

public class BiomePair {
private final Biome parent, mutated;

public BiomePair(Biome parent, Biome mutated) {
this.parent = parent;
this.mutated = mutated;
}

public Biome getParent() {
return parent;
}

public Biome getMutated() {
return mutated;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2020 - 2024 Legacy Fabric
* Copyright (c) 2016 - 2022 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.legacyfabric.fabric.impl.registry.util;

public class NumericalIdPair {
private final int main, secondary;

public NumericalIdPair(int main, int secondary) {
this.main = main;
this.secondary = secondary;
}

public int getMain() {
return main;
}

public int getSecondary() {
return secondary;
}
}
Loading