From 1c2468735fb227b8c98a37892af4c0fdfe11144d Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 24 Aug 2021 04:16:50 +0800 Subject: [PATCH] Implement item properties --- .../registry/ItemPropertiesRegistry.java | 47 +++++++++++++++++++ .../main/resources/architectury.accessWidener | 4 +- .../main/resources/architectury.accessWidener | 4 +- .../resources/META-INF/accesstransformer.cfg | 1 + 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 common/src/main/java/me/shedaniel/architectury/registry/ItemPropertiesRegistry.java diff --git a/common/src/main/java/me/shedaniel/architectury/registry/ItemPropertiesRegistry.java b/common/src/main/java/me/shedaniel/architectury/registry/ItemPropertiesRegistry.java new file mode 100644 index 00000000..cb3863bd --- /dev/null +++ b/common/src/main/java/me/shedaniel/architectury/registry/ItemPropertiesRegistry.java @@ -0,0 +1,47 @@ +/* + * 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 me.shedaniel.architectury.registry; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.renderer.item.ItemProperties; +import net.minecraft.client.renderer.item.ItemPropertyFunction; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; + +/** + * 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() { + } + + public static ItemPropertyFunction registerGeneric(ResourceLocation propertyId, ItemPropertyFunction function) { + return ItemProperties.registerGeneric(propertyId, function); + } + + public static ItemPropertyFunction register(Item item, ResourceLocation propertyId, ItemPropertyFunction function) { + ItemProperties.register(item, propertyId, function); + return function; + } +} diff --git a/common/src/main/resources/architectury.accessWidener b/common/src/main/resources/architectury.accessWidener index cbf6f035..3ad2c0a1 100644 --- a/common/src/main/resources/architectury.accessWidener +++ b/common/src/main/resources/architectury.accessWidener @@ -45,4 +45,6 @@ mutable field net/minecraft/world/item/AxeItem STRIPABLES 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/ItemPropertyFunction;)Lnet/minecraft/client/renderer/item/ItemPropertyFunction; +accessible method net/minecraft/client/renderer/item/ItemProperties register (Lnet/minecraft/world/item/Item;Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/client/renderer/item/ItemPropertyFunction;)V diff --git a/fabric/src/main/resources/architectury.accessWidener b/fabric/src/main/resources/architectury.accessWidener index e5df1e35..a62397fd 100644 --- a/fabric/src/main/resources/architectury.accessWidener +++ b/fabric/src/main/resources/architectury.accessWidener @@ -101,4 +101,6 @@ mutable field net/minecraft/world/item/AxeItem STRIPABLES 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/ItemPropertyFunction;)Lnet/minecraft/client/renderer/item/ItemPropertyFunction; +accessible method net/minecraft/client/renderer/item/ItemProperties register (Lnet/minecraft/world/item/Item;Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/client/renderer/item/ItemPropertyFunction;)V diff --git a/forge/src/main/resources/META-INF/accesstransformer.cfg b/forge/src/main/resources/META-INF/accesstransformer.cfg index efb3bcfa..21e76b0e 100644 --- a/forge/src/main/resources/META-INF/accesstransformer.cfg +++ b/forge/src/main/resources/META-INF/accesstransformer.cfg @@ -36,3 +36,4 @@ public net.minecraft.world.storage.FolderName (Ljava/lang/String;)V public-f net.minecraft.item.AxeItem field_203176_a # STRIPABLES public-f net.minecraft.item.ShovelItem field_195955_e # FLATTENABLES public-f net.minecraft.item.HoeItem field_195973_b # TILLABLES +public net.minecraft.item.ItemModelsProperties func_239420_a_(Lnet/minecraft/util/ResourceLocation;Lnet/minecraft/item/IItemPropertyGetter;)Lnet/minecraft/item/IItemPropertyGetter; # registerGeneric