-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to 20.2.59-beta & Adapt to Registry Changes
- Loading branch information
Showing
13 changed files
with
755 additions
and
20 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
common/src/main/java/dev/architectury/impl/RegistrySupplierImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
forge/src/main/java/dev/architectury/hooks/forgelike/ForgeLikeHooks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
minecraftforge/src/main/java/dev/architectury/hooks/forgelike/forge/ForgeLikeHooksImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
}); | ||
}); | ||
}); | ||
} | ||
} |
Oops, something went wrong.