Fixed the keybinding and skull rendering

This commit is contained in:
Sollace 2019-05-30 14:09:24 +02:00
parent d829042dd1
commit 037f2199c2
6 changed files with 45 additions and 6 deletions

View file

@ -1,15 +1,22 @@
package com.minelittlepony.client;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding;
import net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.options.KeyBinding;
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.util.InputUtil;
import net.minecraft.entity.Entity;
import net.minecraft.util.Identifier;
import com.minelittlepony.client.gui.hdskins.MineLPHDSkins;
import com.minelittlepony.client.mixin.MixinBlockEntityRenderDispatcher;
import com.minelittlepony.client.settings.ClientPonyConfig;
import com.minelittlepony.hdskins.mixin.MixinEntityRenderDispatcher;
import com.minelittlepony.settings.SensibleJsonConfig;
@ -32,8 +39,27 @@ public class FabMod implements ClientModInitializer, IModUtilities {
mlp.init(SensibleJsonConfig.of(getConfigDirectory().resolve("minelp.json"), ClientPonyConfig::new));
}
@Override
public KeyBinding registerKeybind(String category, int key, String bindName) {
// normalize Fabric's behavior
if (bindName.startsWith("key.")) {
bindName = bindName.replace("key.", "");
}
FabricKeyBinding binding = FabricKeyBinding.Builder.create(new Identifier(bindName) {
@Override
public String toString() { return getPath(); }
}, InputUtil.Type.KEYSYM, key, category).build();
KeyBindingRegistry.INSTANCE.register(binding);
return binding;
}
@Override
public <T extends BlockEntity> void addRenderer(Class<T> type, BlockEntityRenderer<T> renderer) {
MixinBlockEntityRenderDispatcher mx = ((MixinBlockEntityRenderDispatcher)BlockEntityRenderDispatcher.INSTANCE);
mx.getRenderers().put(type, renderer);
renderer.setRenderManager(BlockEntityRenderDispatcher.INSTANCE);
}
@Override

View file

@ -1,6 +1,7 @@
package com.minelittlepony.client;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.options.KeyBinding;
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.render.entity.EntityRenderer;
@ -18,6 +19,10 @@ public interface IModUtilities {
return false;
}
default KeyBinding registerKeybind(String category, int key, String bindName) {
return new KeyBinding(category, key, bindName);
}
Path getConfigDirectory();
Path getAssetsDirectory();

View file

@ -25,9 +25,6 @@ import org.lwjgl.glfw.GLFW;
*/
public class MineLPClient extends MineLittlePony {
static final KeyBinding SETTINGS_GUI = new KeyBinding("Settings", GLFW.GLFW_KEY_F9, "Mine Little Pony");
private static int modelUpdateCounter = 0;
private static boolean reloadingModels = false;
@ -38,6 +35,8 @@ public class MineLPClient extends MineLittlePony {
private final PonyRenderManager renderManager = PonyRenderManager.getInstance();
private KeyBinding keyBinding;
public static MineLPClient getInstance() {
return (MineLPClient)MineLittlePony.getInstance();
}
@ -49,6 +48,7 @@ public class MineLPClient extends MineLittlePony {
protected void init(PonyConfig newConfig) {
config = newConfig;
ponyManager = new PonyManager(config);
keyBinding = utilities.registerKeybind("Settings", GLFW.GLFW_KEY_F9, "key.minelittlepony.settings");
}
/**
@ -62,9 +62,9 @@ public class MineLPClient extends MineLittlePony {
irrm.registerListener(ponyManager);
}
void onTick(MinecraftClient minecraft, boolean inGame) {
public void onTick(MinecraftClient minecraft, boolean inGame) {
if (inGame && minecraft.currentScreen == null) {
if (SETTINGS_GUI.isPressed()) {
if (keyBinding.isPressed()) {
minecraft.disconnect(new GuiHost(new GuiPonySettings()));
} else {
long handle = minecraft.window.getHandle();

View file

@ -19,6 +19,12 @@ public abstract class MixinMinecraftClient extends NonBlockingThreadExecutor<Run
@Inject(method = "init()V", at = @At("RETURN"))
private void onInit(CallbackInfo info) {
MineLPClient.getInstance().postInit(MinecraftClient.getInstance());
MineLPClient.getInstance().postInit((MinecraftClient)(Object)this);
}
@Inject(method = "tick()V", at = @At("RETURN"))
private void onTick(CallbackInfo info) {
MinecraftClient self = (MinecraftClient)(Object)this;
MineLPClient.getInstance().onTick(self, self.world != null && self.player != null);
}
}

View file

@ -1,4 +1,5 @@
{
"key.minelittlepony.settings": "Mine Little Pony",
"minelp.options.title": "Mine Little Pony Settings",
"minelp.options.ponylevel": "Pony Level",
"minelp.options.ponylevel.ponies": "Ponies Only",

View file

@ -6,6 +6,7 @@
"compatibilityLevel": "JAVA_8",
"mixins": [
"IResizeable",
"MixinBlockEntityRenderDispatcher",
"MixinDefaultPlayerSkin",
"MixinFirstPersonRenderer",
"MixinGlStateManager",