Add ItemConvertible overload for BuiltinItemRendererRegistry (#955)

Closes #953.
This commit is contained in:
Juuxel 2020-08-13 20:14:01 +03:00 committed by GitHub
parent 54fedaeb9b
commit fc24ff24ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 1 deletions

View file

@ -1,5 +1,5 @@
archivesBaseName = "fabric-rendering-v1" archivesBaseName = "fabric-rendering-v1"
version = getSubprojectVersion(project, "1.1.2") version = getSubprojectVersion(project, "1.2.0")
dependencies { dependencies {
compile project(path: ':fabric-api-base', configuration: 'dev') compile project(path: ':fabric-api-base', configuration: 'dev')

View file

@ -17,6 +17,7 @@
package net.fabricmc.fabric.api.client.rendering.v1; package net.fabricmc.fabric.api.client.rendering.v1;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemConvertible;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
@ -44,4 +45,16 @@ public interface BuiltinItemRendererRegistry {
* @throws NullPointerException if either the item or the renderer is null * @throws NullPointerException if either the item or the renderer is null
*/ */
void register(Item item, BuiltinItemRenderer renderer); void register(Item item, BuiltinItemRenderer renderer);
/**
* Registers the renderer for the item.
*
* <p>Note that the item's JSON model must also extend {@code minecraft:builtin/entity}.
*
* @param item the item
* @param renderer the renderer
* @throws IllegalArgumentException if the item already has a registered renderer
* @throws NullPointerException if either the item or the renderer is null
*/
void register(ItemConvertible item, BuiltinItemRenderer renderer);
} }

View file

@ -21,6 +21,7 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemConvertible;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
@ -49,6 +50,12 @@ public final class BuiltinItemRendererRegistryImpl implements BuiltinItemRendere
RENDERERS.put(item, renderer); RENDERERS.put(item, renderer);
} }
@Override
public void register(ItemConvertible item, BuiltinItemRenderer renderer) {
Objects.requireNonNull(item, "item is null");
register(item.asItem(), renderer);
}
/* @Nullable */ /* @Nullable */
public static BuiltinItemRenderer getRenderer(Item item) { public static BuiltinItemRenderer getRenderer(Item item) {
return RENDERERS.get(item); return RENDERERS.get(item);