Implement item properties (#132)

This commit is contained in:
shedaniel
2021-08-30 01:44:30 +08:00
parent c8667222a3
commit 88dbf04c9b
6 changed files with 141 additions and 3 deletions

View File

@@ -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();
}
}

View File

@@ -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;
mutable field net/minecraft/world/item/HoeItem TILLABLES Ljava/util/Map;

View File

@@ -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;
}
}

View File

@@ -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;
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

View File

@@ -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;
}
}

View File

@@ -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