diff --git a/common/src/main/java/dev/architectury/registry/item/ItemPropertiesRegistry.java b/common/src/main/java/dev/architectury/registry/item/ItemPropertiesRegistry.java new file mode 100644 index 00000000..858919f8 --- /dev/null +++ b/common/src/main/java/dev/architectury/registry/item/ItemPropertiesRegistry.java @@ -0,0 +1,63 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021 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.registry.item; + +import dev.architectury.injectables.annotations.ExpectPlatform; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.renderer.item.ClampedItemPropertyFunction; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.ItemLike; + +/** + * Registry for registering item properties used for model predicates. + * + * @see net.minecraft.client.renderer.item.ItemProperties + */ +@Environment(EnvType.CLIENT) +public final class ItemPropertiesRegistry { + private ItemPropertiesRegistry() { + } + + /** + * Registers a generic item property function for all items. + * + * @param propertyId the id of the property + * @param function the function to be registered + * @return the function registered + */ + @ExpectPlatform + public static ClampedItemPropertyFunction registerGeneric(ResourceLocation propertyId, ClampedItemPropertyFunction function) { + throw new AssertionError(); + } + + /** + * Registers a generic item property function for a specific item. + * + * @param item the item to be registered for + * @param propertyId the id of the property + * @param function the function to be registered + * @return the function registered + */ + @ExpectPlatform + public static ClampedItemPropertyFunction register(ItemLike item, ResourceLocation propertyId, ClampedItemPropertyFunction function) { + throw new AssertionError(); + } +} diff --git a/common/src/main/resources/architectury.accessWidener b/common/src/main/resources/architectury.accessWidener index c20dffd6..ec2ed9b7 100644 --- a/common/src/main/resources/architectury.accessWidener +++ b/common/src/main/resources/architectury.accessWidener @@ -46,4 +46,4 @@ mutable field net/minecraft/world/item/AxeItem STRIPPABLES Ljava/util/Map; accessible field net/minecraft/world/item/ShovelItem FLATTENABLES Ljava/util/Map; mutable field net/minecraft/world/item/ShovelItem FLATTENABLES Ljava/util/Map; accessible field net/minecraft/world/item/HoeItem TILLABLES Ljava/util/Map; -mutable field net/minecraft/world/item/HoeItem TILLABLES Ljava/util/Map; \ No newline at end of file +mutable field net/minecraft/world/item/HoeItem TILLABLES Ljava/util/Map; diff --git a/fabric/src/main/java/dev/architectury/registry/item/fabric/ItemPropertiesRegistryImpl.java b/fabric/src/main/java/dev/architectury/registry/item/fabric/ItemPropertiesRegistryImpl.java new file mode 100644 index 00000000..eaf4cf4c --- /dev/null +++ b/fabric/src/main/java/dev/architectury/registry/item/fabric/ItemPropertiesRegistryImpl.java @@ -0,0 +1,36 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021 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.registry.item.fabric; + +import net.minecraft.client.renderer.item.ClampedItemPropertyFunction; +import net.minecraft.client.renderer.item.ItemProperties; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.ItemLike; + +public class ItemPropertiesRegistryImpl { + public static ClampedItemPropertyFunction registerGeneric(ResourceLocation propertyId, ClampedItemPropertyFunction function) { + return ItemProperties.registerGeneric(propertyId, function); + } + + public static ClampedItemPropertyFunction register(ItemLike item, ResourceLocation propertyId, ClampedItemPropertyFunction function) { + ItemProperties.register(item.asItem(), propertyId, function); + return function; + } +} diff --git a/fabric/src/main/resources/architectury.accessWidener b/fabric/src/main/resources/architectury.accessWidener index dd39e916..460ef8d5 100644 --- a/fabric/src/main/resources/architectury.accessWidener +++ b/fabric/src/main/resources/architectury.accessWidener @@ -104,4 +104,6 @@ mutable field net/minecraft/world/item/AxeItem STRIPPABLES Ljava/util/Map; accessible field net/minecraft/world/item/ShovelItem FLATTENABLES Ljava/util/Map; mutable field net/minecraft/world/item/ShovelItem FLATTENABLES Ljava/util/Map; accessible field net/minecraft/world/item/HoeItem TILLABLES Ljava/util/Map; -mutable field net/minecraft/world/item/HoeItem TILLABLES Ljava/util/Map; \ No newline at end of file +mutable field net/minecraft/world/item/HoeItem TILLABLES Ljava/util/Map; +accessible method net/minecraft/client/renderer/item/ItemProperties registerGeneric (Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/client/renderer/item/ClampedItemPropertyFunction;)Lnet/minecraft/client/renderer/item/ClampedItemPropertyFunction; +accessible method net/minecraft/client/renderer/item/ItemProperties register (Lnet/minecraft/world/item/Item;Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/client/renderer/item/ClampedItemPropertyFunction;)V diff --git a/forge/src/main/java/dev/architectury/registry/item/forge/ItemPropertiesRegistryImpl.java b/forge/src/main/java/dev/architectury/registry/item/forge/ItemPropertiesRegistryImpl.java new file mode 100644 index 00000000..a8df3506 --- /dev/null +++ b/forge/src/main/java/dev/architectury/registry/item/forge/ItemPropertiesRegistryImpl.java @@ -0,0 +1,37 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021 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.registry.item.forge; + +import net.minecraft.client.renderer.item.ClampedItemPropertyFunction; +import net.minecraft.client.renderer.item.ItemProperties; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.ItemLike; + +public class ItemPropertiesRegistryImpl { + public static ClampedItemPropertyFunction registerGeneric(ResourceLocation propertyId, ClampedItemPropertyFunction function) { + ItemProperties.registerGeneric(propertyId, function); + return function; + } + + public static ClampedItemPropertyFunction register(ItemLike item, ResourceLocation propertyId, ClampedItemPropertyFunction function) { + ItemProperties.register(item.asItem(), propertyId, function); + return function; + } +} diff --git a/gradle.properties b/gradle.properties index 61be9db0..c0d8332e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ cf_type=release archives_base_name=architectury archives_base_name_snapshot=architectury-snapshot -base_version=2.4 +base_version=2.5 maven_group=dev.architectury fabric_loader_version=0.11.6