/* * Minecraft Forge * Copyright (c) 2016-2018. * * This library 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 version 2.1 * of the License. * * This library 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 library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ package net.minecraftforge.fml.client.registry; import com.google.common.collect.Maps; import net.minecraft.client.renderer.tileentity.TileEntityRenderer; import net.minecraft.entity.Entity; import net.minecraft.util.ResourceLocation; import org.apache.commons.lang3.ArrayUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.client.settings.KeyBinding; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.fml.common.registry.GameRegistry; import java.util.Map; public class ClientRegistry { private static Map, ResourceLocation> entityShaderMap = Maps.newHashMap(); /** * * Utility method for registering a tile entity and it's renderer at once - generally you should register them separately * * @param tileEntityClass * @param id * @param specialRenderer */ public static void registerTileEntity(Class tileEntityClass, String id, TileEntityRenderer specialRenderer) { GameRegistry.registerTileEntity(tileEntityClass, id); bindTileEntitySpecialRenderer(tileEntityClass, specialRenderer); } public static void bindTileEntitySpecialRenderer(Class tileEntityClass, TileEntityRenderer specialRenderer) { TileEntityRendererDispatcher.instance.renderers.put(tileEntityClass, specialRenderer); specialRenderer.setRendererDispatcher(TileEntityRendererDispatcher.instance); } public static void registerKeyBinding(KeyBinding key) { Minecraft.getMinecraft().gameSettings.keyBindings = ArrayUtils.add(Minecraft.getMinecraft().gameSettings.keyBindings, key); } /** * Register a shader for an entity. This shader gets activated when a spectator begins spectating an entity. * Vanilla examples of this are the green effect for creepers and the invert effect for endermen. * * @param entityClass * @param shader */ public static void registerEntityShader(Class entityClass, ResourceLocation shader) { entityShaderMap.put(entityClass, shader); } public static ResourceLocation getEntityShader(Class entityClass) { return entityShaderMap.get(entityClass); } }