Skip to content

Commit

Permalink
Update to 20.2.59-beta & Adapt to Registry Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
shedaniel committed Nov 20, 2023
1 parent 426ca41 commit 9aba3cf
Show file tree
Hide file tree
Showing 13 changed files with 755 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* This file is part of architectury.
* Copyright (C) 2020, 2021, 2022 architectury
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package dev.architectury.impl;

import com.mojang.datafixers.util.Either;
import dev.architectury.registry.registries.RegistrySupplier;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderOwner;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;

@ApiStatus.Internal
public interface RegistrySupplierImpl<T> extends RegistrySupplier<T> {
@Nullable
Holder<T> getHolder();

@Override
default T value() {
return get();
}

@Override
default boolean isBound() {
return isPresent();
}

@Override
default boolean is(ResourceLocation resourceLocation) {
return getId().equals(resourceLocation);
}

@Override
default boolean is(ResourceKey<T> resourceKey) {
return getKey().equals(resourceKey);
}

@Override
default boolean is(Predicate<ResourceKey<T>> predicate) {
return predicate.test(getKey());
}

@Override
default boolean is(TagKey<T> tagKey) {
Holder<T> holder = getHolder();
return holder != null && holder.is(tagKey);
}

@Override
default Stream<TagKey<T>> tags() {
Holder<T> holder = getHolder();
return holder != null ? holder.tags() : Stream.empty();
}

@Override
default Either<ResourceKey<T>, T> unwrap() {
return Either.left(getKey());
}

@Override
default Optional<ResourceKey<T>> unwrapKey() {
return Optional.of(getKey());
}

@Override
default Kind kind() {
return Kind.REFERENCE;
}

@Override
default boolean canSerializeIn(HolderOwner<T> holderOwner) {
Holder<T> holder = getHolder();
return holder != null && holder.canSerializeIn(holderOwner);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package dev.architectury.registry.registries;

import com.google.common.base.Suppliers;
import dev.architectury.impl.RegistrySupplierImpl;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -90,16 +92,25 @@ public Registrar<T> getRegistrar() {
return registriesSupplier.get().get(key);
}

private class Entry<R> implements RegistrySupplier<R> {
private class Entry<R> implements RegistrySupplierImpl<R> {
private final ResourceLocation id;
private final Supplier<R> supplier;
private RegistrySupplier<R> value;
@Nullable
private Holder<R> holder = null;

public Entry(ResourceLocation id, Supplier<R> supplier) {
this.id = id;
this.supplier = supplier;
}

@Nullable
@Override
public Holder<R> getHolder() {
if (holder != null) return holder;
return holder = getRegistrar().getHolder(getId());
}

@Override
public RegistrarManager getRegistrarManager() {
return DeferredRegister.this.getRegistrarManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package dev.architectury.registry.registries;

import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -68,6 +69,14 @@ default <R extends T> RegistrySupplier<R> wrap(R obj) {

ResourceKey<? extends Registry<T>> key();

@Nullable
Holder<T> getHolder(ResourceKey<T> key);

@Nullable
default Holder<T> getHolder(ResourceLocation id) {
return getHolder(ResourceKey.create(key(), id));
}

/**
* Listens to when the registry entry is registered, and calls the given action.
* Evaluates immediately if the entry is already registered.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@

package dev.architectury.registry.registries;

import net.minecraft.core.Holder;
import org.jetbrains.annotations.ApiStatus;

import java.util.function.Consumer;

@ApiStatus.NonExtendable
public interface RegistrySupplier<T> extends DeferredSupplier<T> {
public interface RegistrySupplier<T> extends DeferredSupplier<T>, Holder<T> {
RegistrarManager getRegistrarManager();

Registrar<T> getRegistrar();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.common.base.Suppliers;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import dev.architectury.impl.RegistrySupplierImpl;
import dev.architectury.registry.registries.Registrar;
import dev.architectury.registry.registries.RegistrarBuilder;
import dev.architectury.registry.registries.RegistrarManager;
Expand All @@ -32,6 +33,7 @@
import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder;
import net.fabricmc.fabric.api.event.registry.RegistryAttribute;
import net.fabricmc.fabric.api.event.registry.RegistryEntryAddedCallback;
import net.minecraft.core.Holder;
import net.minecraft.core.MappedRegistry;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
Expand Down Expand Up @@ -153,7 +155,17 @@ public RegistrarImpl(String modId, Registry<T> delegate) {
public RegistrySupplier<T> delegate(ResourceLocation id) {
Supplier<T> value = Suppliers.memoize(() -> get(id));
RegistrarImpl<T> registrar = this;
return new RegistrySupplier<>() {
return new RegistrySupplierImpl<T>() {
@Nullable
Holder<T> holder = null;

@Nullable
@Override
public Holder<T> getHolder() {
if (holder != null) return holder;
return holder = registrar.getHolder(getId());
}

@Override
public RegistrarManager getRegistrarManager() {
return RegistrarManager.get(modId);
Expand Down Expand Up @@ -259,6 +271,12 @@ public ResourceKey<? extends Registry<T>> key() {
return delegate.key();
}

@Override
@Nullable
public Holder<T> getHolder(ResourceKey<T> key) {
return delegate.getHolder(key).orElse(null);
}

@Override
public Iterator<T> iterator() {
return delegate.iterator();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* This file is part of architectury.
* Copyright (C) 2020, 2021, 2022 architectury
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package dev.architectury.hooks.forgelike;

import com.mojang.serialization.Codec;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.common.world.BiomeModifier;
import org.jetbrains.annotations.ApiStatus;

import java.util.function.Supplier;

@ApiStatus.Internal
public class ForgeLikeHooks {
@ExpectPlatform
public static void registerBiomeModifier(ResourceLocation id, Supplier<Codec<? extends BiomeModifier>> codecSupplier) {
throw new AssertionError();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

import com.google.common.collect.Lists;
import com.mojang.serialization.Codec;
import dev.architectury.hooks.forgelike.ForgeLikeHooks;
import dev.architectury.hooks.level.biome.*;
import dev.architectury.platform.hooks.EventBusesHooks;
import dev.architectury.registry.level.biome.BiomeModifications.BiomeContext;
import dev.architectury.utils.ArchitecturyConstants;
import dev.architectury.utils.GameInstance;
Expand All @@ -42,8 +42,6 @@
import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import net.minecraftforge.common.world.*;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegisterEvent;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.Nullable;

Expand All @@ -64,14 +62,8 @@ public class BiomeModificationsImpl {
private static Codec<BiomeModifierImpl> noneBiomeModCodec = null;

public static void init() {
EventBusesHooks.whenAvailable(ArchitecturyConstants.MOD_ID,bus -> {
bus.<RegisterEvent>addListener(event -> {
event.register(ForgeRegistries.Keys.BIOME_MODIFIER_SERIALIZERS, registry -> {
registry.register(new ResourceLocation(ArchitecturyConstants.MOD_ID, "none_biome_mod_codec"),
noneBiomeModCodec = Codec.unit(BiomeModifierImpl.INSTANCE));
});
});
});
ForgeLikeHooks.registerBiomeModifier(new ResourceLocation(ArchitecturyConstants.MOD_ID, "none_biome_mod_codec"),
() -> noneBiomeModCodec = Codec.unit(BiomeModifierImpl.INSTANCE));
}

public static void addProperties(Predicate<BiomeContext> predicate, BiConsumer<BiomeContext, BiomeProperties.Mutable> modifier) {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fabric_api_version=0.89.1+1.20.2
mod_menu_version=7.0.0

forge_version=48.0.38
neoforge_version=20.2.52-beta
neoforge_version=20.2.59-beta

curseforge_id=419699
modrinth_id=lhGA9TYQ
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* This file is part of architectury.
* Copyright (C) 2020, 2021, 2022 architectury
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package dev.architectury.hooks.forgelike.forge;

import com.mojang.serialization.Codec;
import dev.architectury.platform.hooks.EventBusesHooks;
import dev.architectury.utils.ArchitecturyConstants;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.common.world.BiomeModifier;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegisterEvent;

import java.util.function.Supplier;

public class ForgeLikeHooksImpl {
public static void registerBiomeModifier(ResourceLocation id, Supplier<Codec<? extends BiomeModifier>> codecSupplier) {
EventBusesHooks.whenAvailable(ArchitecturyConstants.MOD_ID, bus -> {
bus.<RegisterEvent>addListener(event -> {
event.register(ForgeRegistries.Keys.BIOME_MODIFIER_SERIALIZERS, registry -> {
registry.register(id, codecSupplier.get());
});
});
});
}
}
Loading

0 comments on commit 9aba3cf

Please sign in to comment.