Forráskód Böngészése

Implement item properties

shedaniel 3 éve
szülő
commit
1c2468735f

+ 47 - 0
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;
+    }
+}

+ 3 - 1
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;
+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

+ 3 - 1
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;
+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

+ 1 - 0
forge/src/main/resources/META-INF/accesstransformer.cfg

@@ -36,3 +36,4 @@ public net.minecraft.world.storage.FolderName <init>(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