Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 0ab6448

Browse files
authored
Merge pull request #45 from Virtuoel/feature/client-registry
ClientRegistry
2 parents a7d1dd3 + 15a89f7 commit 0ab6448

4 files changed

Lines changed: 163 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 com.patchworkmc.impl.registries;
21+
22+
import java.util.ArrayList;
23+
import java.util.HashSet;
24+
import java.util.List;
25+
import java.util.Set;
26+
27+
import net.minecraft.client.options.KeyBinding;
28+
29+
public class AddedKeybinds {
30+
private static Set<KeyBinding> registeredKeys = new HashSet<>();
31+
32+
public static KeyBinding[] addRegisteredKeys(KeyBinding[] keysAll) {
33+
List<KeyBinding> newKeysAll = new ArrayList<>();
34+
35+
for (KeyBinding binding : keysAll) {
36+
newKeysAll.add(binding);
37+
}
38+
39+
newKeysAll.addAll(registeredKeys);
40+
41+
return newKeysAll.toArray(new KeyBinding[0]);
42+
}
43+
44+
public static void registerKeyBinding(KeyBinding key) {
45+
registeredKeys.add(key);
46+
}
47+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 com.patchworkmc.mixin.registries;
21+
22+
import org.spongepowered.asm.mixin.Mixin;
23+
import org.spongepowered.asm.mixin.Shadow;
24+
import org.spongepowered.asm.mixin.injection.At;
25+
import org.spongepowered.asm.mixin.injection.Inject;
26+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
27+
28+
import net.minecraft.client.options.GameOptions;
29+
import net.minecraft.client.options.KeyBinding;
30+
31+
import com.patchworkmc.impl.registries.AddedKeybinds;
32+
33+
@Mixin(GameOptions.class)
34+
public abstract class MixinGameOptions {
35+
@Shadow
36+
public KeyBinding[] keysAll;
37+
38+
@Inject(at = @At("HEAD"), method = "load()V")
39+
public void loadHook(CallbackInfo info) {
40+
keysAll = AddedKeybinds.addRegisteredKeys(keysAll);
41+
}
42+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 {@link BlockEntityRenderer}
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 {@link 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+
}

patchwork-registries/src/main/resources/patchwork-registries.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"MixinEntityType",
1818
"MixinFeature",
1919
"MixinFluid",
20+
"MixinGameOptions",
2021
"MixinItem",
2122
"MixinMemoryModuleType",
2223
"MixinPaintingMotive",

0 commit comments

Comments
 (0)