|
| 1 | +/* |
| 2 | + * Minecraft Forge, Patchwork Project |
| 3 | + * Copyright (c) 2016-2020, 2019-2020 |
| 4 | + * |
| 5 | + * This library is free software; you can redistribute it and/or |
| 6 | + * modify it under the terms of the GNU Lesser General Public |
| 7 | + * License as published by the Free Software Foundation version 2.1 |
| 8 | + * of the License. |
| 9 | + * |
| 10 | + * This library is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | + * Lesser General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Lesser General Public |
| 16 | + * License along with this library; if not, write to the Free Software |
| 17 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | + */ |
| 19 | + |
| 20 | +package net.minecraftforge.fml.client.registry; |
| 21 | + |
| 22 | +import java.util.Map; |
| 23 | +import java.util.concurrent.ConcurrentHashMap; |
| 24 | + |
| 25 | +import net.minecraft.block.entity.BlockEntity; |
| 26 | +import net.minecraft.client.options.KeyBinding; |
| 27 | +import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher; |
| 28 | +import net.minecraft.client.render.block.entity.BlockEntityRenderer; |
| 29 | +import net.minecraft.entity.Entity; |
| 30 | +import net.minecraft.util.Identifier; |
| 31 | + |
| 32 | +import net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry; |
| 33 | +import net.fabricmc.fabric.api.client.render.BlockEntityRendererRegistry; |
| 34 | + |
| 35 | +import com.patchworkmc.impl.registries.AddedKeybinds; |
| 36 | + |
| 37 | +public class ClientRegistry { |
| 38 | + private static Map<Class<? extends Entity>, Identifier> entityShaderMap = new ConcurrentHashMap<>(); |
| 39 | + |
| 40 | + /** |
| 41 | + * Registers a Tile Entity renderer. |
| 42 | + * Call this during {@link net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent}. |
| 43 | + * This method is safe to call during parallel mod loading. |
| 44 | + */ |
| 45 | + public static synchronized <T extends BlockEntity> void bindTileEntitySpecialRenderer(Class<T> tileEntityClass, BlockEntityRenderer<? super T> specialRenderer) { |
| 46 | + BlockEntityRendererRegistry.INSTANCE.register(tileEntityClass, specialRenderer); |
| 47 | + specialRenderer.setRenderManager(BlockEntityRenderDispatcher.INSTANCE); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Registers a KeyBinding. |
| 52 | + * Call this during {@link net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent}. |
| 53 | + * This method is safe to call during parallel mod loading. |
| 54 | + */ |
| 55 | + public static synchronized void registerKeyBinding(KeyBinding key) { |
| 56 | + KeyBindingRegistry.INSTANCE.addCategory(key.getCategory()); |
| 57 | + AddedKeybinds.registerKeyBinding(key); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Register a shader for an entity. This shader gets activated when a spectator begins spectating an entity. |
| 62 | + * Vanilla examples of this are the green effect for creepers and the invert effect for endermen. |
| 63 | + * Call this during {@link net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent}. |
| 64 | + * This method is safe to call during parallel mod loading. |
| 65 | + */ |
| 66 | + public static void registerEntityShader(Class<? extends Entity> entityClass, Identifier shader) { |
| 67 | + entityShaderMap.put(entityClass, shader); |
| 68 | + } |
| 69 | + |
| 70 | + public static Identifier getEntityShader(Class<? extends Entity> entityClass) { |
| 71 | + return entityShaderMap.get(entityClass); |
| 72 | + } |
| 73 | +} |
0 commit comments