Skip to content

Commit

Permalink
整理事件
Browse files Browse the repository at this point in the history
  • Loading branch information
HappyRespawnanchor committed Nov 16, 2024
1 parent e2c6ec2 commit 53ef0e6
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public class ModelSelectMenuScreen extends AyameScreen {
public static final int searchBarHeight = 23;
protected static final Path MODEL_DIR = Path.of("config/ayame/models/");
public final List<IModelResource> modelResources;
private Entity entity;
public @Nullable ModelType selectedModel = AyameModelCache.getPlayerModel(Minecraft.getInstance().player);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import org.ayamemc.ayame.client.AyameClient;
import org.ayamemc.ayame.fabric.client.event.AyameKeyMappingEventHandler;
import org.ayamemc.ayame.fabric.client.util.AyameKeyRegister;

/**
* Fabric客户端初始化所使用的类
Expand All @@ -37,7 +37,7 @@ public final class AyameFabricClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
// 不要动AyameKeyMappingEventHandler的init方法
AyameKeyMappingEventHandler.init();
AyameKeyRegister.init();
FabricClientEventHandler.init();
AyameClient.init();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import net.minecraft.world.item.ItemStack;
import org.ayamemc.ayame.client.handler.EventHandler;
import org.ayamemc.ayame.fabric.client.api.event.RenderArmCallback;
import org.ayamemc.ayame.fabric.client.event.AyameKeyMappingEventHandler;
import org.ayamemc.ayame.fabric.client.util.AyameKeyRegister;
import org.ayamemc.ayame.util.TaskManager;


Expand Down Expand Up @@ -109,7 +109,7 @@ private static InteractionResult renderCustomHand(
}

private static void endClientTickEvent(Minecraft minecraft) {
AyameKeyMappingEventHandler.processKeyPressed();
AyameKeyRegister.processKeyPressed();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* along with Ayame. If not, see <https://www.gnu.org/licenses/>.
*/

package org.ayamemc.ayame.fabric.client.event;
package org.ayamemc.ayame.fabric.client.util;

import com.mojang.blaze3d.platform.InputConstants;
import net.fabricmc.api.EnvType;
Expand All @@ -27,7 +27,6 @@
import net.minecraft.client.KeyMapping;
import org.ayamemc.ayame.client.gui.screen.ModelSelectMenuScreen;
import org.ayamemc.ayame.client.handler.EventHandler;
import org.ayamemc.ayame.fabric.client.util.AyameTMSKeyMappings;
import org.ayamemc.ayame.util.JavaUtil;
import org.ayamemc.ayame.util.TranslatableName;
import org.jetbrains.annotations.Nullable;
Expand All @@ -38,11 +37,11 @@
/**
* 注册Ayame所使用的按键,若安装了 <a href="https://github.com/wyatt-herkamp/too-many-shortcuts">too-many-shortcuts</a>组则会使用其提供的组合按键绑定。
*
* @see AyameTMSKeyMappings
* @see AyameTmsKey
* @see JavaUtil
*/
@Environment(EnvType.CLIENT)
public class AyameKeyMappingEventHandler {
public class AyameKeyRegister {
public static final KeyMapping MODEL_SELECT_MENU = registerKeyMapping(
TranslatableName.SELECT_MODEL_MENU,
InputConstants.Type.KEYSYM,
Expand All @@ -58,8 +57,8 @@ public class AyameKeyMappingEventHandler {
* @param type 输入类型,见{@link InputConstants}
* @param keyCode 键位,见{@link GLFW}
* @param category 按键绑定页面的种类
* @param modifier 组合键位,见{@link AyameTMSKeyMappings}
* @return 调用 {@link AyameTMSKeyMappings}
* @param modifier 组合键位,见{@link AyameTmsKey}
* @return 调用 {@link AyameTmsKey}
* @see KeyMapping
*/
public static KeyMapping registerKeyMapping(String name, InputConstants.Type type, int keyCode, String category, @Nullable String modifier) {
Expand All @@ -68,7 +67,7 @@ public static KeyMapping registerKeyMapping(String name, InputConstants.Type typ
// 直接检查 TMSKeyBinding 是否存在
Class.forName("dev.kingtux.tms.api.TMSKeyBinding");
if (modifier != null) {
keyMapping = AyameTMSKeyMappings.registerTMSKeyMapping(name, type, keyCode, category, modifier);
keyMapping = AyameTmsKey.registerTMSKeyMapping(name, type, keyCode, category, modifier);
} else {
keyMapping = new KeyMapping("key." + MOD_ID + "." + name, type, keyCode, category);
}
Expand All @@ -89,7 +88,7 @@ public static void init() {
* @see KeyMapping
*/
public static void processKeyPressed() {
while (AyameKeyMappingEventHandler.MODEL_SELECT_MENU.consumeClick()) {
while (AyameKeyRegister.MODEL_SELECT_MENU.consumeClick()) {
EventHandler.openSelectMenuKeyPressed();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,30 @@

import com.mojang.blaze3d.platform.InputConstants;
import dev.kingtux.tms.api.TMSKeyBinding;
import dev.kingtux.tms.api.modifiers.BindingModifiers;
import dev.kingtux.tms.api.modifiers.BindingModifier;
import dev.kingtux.tms.api.modifiers.KeyModifier;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.KeyMapping;
import org.ayamemc.ayame.fabric.client.event.AyameKeyMappingEventHandler;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFW;

import static org.ayamemc.ayame.util.ResourceLocationHelper.withAyameNamespace;


/**
* 注册{@code too-many-shortcuts}的组合按键,检测是否安装其的逻辑位于{@link AyameKeyMappingEventHandler}。
* 注册{@code too-many-shortcuts}的组合按键,检测是否安装其的逻辑位于{@link AyameKeyRegister}。
*/
@Environment(EnvType.CLIENT)
public class AyameTMSKeyMappings {
public class AyameTmsKey {
/**
* 使用TMS注册按键
*
* @param name 按键绑定页面显示的键位名称
* @param type 输入类型,见{@link InputConstants}
* @param keyCode 键位,见{@link GLFW}
* @param category 按键绑定页面的种类
* @param modifier TMS提供的组合键位,见{@link AyameTMSKeyMappings}
* @param modifier TMS提供的组合键位,见{@link AyameTmsKey}
* @return AyameKeyMappings
*/
public static KeyMapping registerTMSKeyMapping(String name, @NotNull InputConstants.Type type, int keyCode, String category, @NotNull String modifier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,32 @@

import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.ModLoadingContext;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.config.ModConfig;
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
import net.neoforged.neoforge.common.NeoForge;
import org.ayamemc.ayame.Ayame;
import org.ayamemc.ayame.client.AyameClient;
import org.ayamemc.ayame.client.IAyameClientEvents;
import org.ayamemc.ayame.client.gui.screen.SettingsScreen;
import org.ayamemc.ayame.neoforge.client.event.NeoForgeClientEventHandler;
import org.ayamemc.ayame.neoforge.client.event.RegisterKeyEventHandler;

@OnlyIn(Dist.CLIENT)
@Mod(value = Ayame.MOD_ID, dist = Dist.CLIENT)
public class AyameNeoForgeClient {
public AyameNeoForgeClient() {
public AyameNeoForgeClient(IEventBus modBus) {
AyameClient.init();

NeoForge.EVENT_BUS.register(NeoForgeClientEventHandler.class);

modBus.register(RegisterKeyEventHandler.class);

IAyameClientEvents.Instance.INSTANCE = new AyameClientEventsNeoForgeImpl();

ModLoadingContext.get().registerExtensionPoint(
IConfigScreenFactory.class,
() -> (modContainer, lastScreen) -> new SettingsScreen(lastScreen)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,22 @@

package org.ayamemc.ayame.neoforge.client.event;

import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.client.event.ClientTickEvent;
import net.neoforged.neoforge.client.event.RenderHandEvent;
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
import org.ayamemc.ayame.Ayame;
import org.ayamemc.ayame.client.gui.screen.ModelSelectMenuScreen;
import org.ayamemc.ayame.client.handler.EventHandler;
import org.ayamemc.ayame.util.TaskManager;


@EventBusSubscriber(modid = Ayame.MOD_ID, value = Dist.CLIENT)
public class NeoForgeClientEventHandler {
/**
* 按下按键后打开{@link ModelSelectMenuScreen}屏幕
*/
@SubscribeEvent
public static void onClientClick(ClientTickEvent.Post event) {
while (RegisterKeyMappingEventHandler.MODEL_SELECT_MENU.get().consumeClick()) {
while (RegisterKeyEventHandler.MODEL_SELECT_MENU.get().consumeClick()) {
EventHandler.openSelectMenuKeyPressed();
}
}
Expand All @@ -59,15 +55,17 @@ public static void onPlayerLeave(PlayerEvent.PlayerLoggedOutEvent event) {
@SubscribeEvent
public static void renderCustomModelHand(RenderHandEvent event) {
event.setCanceled(true); // 取消渲染默认手臂
EventHandler.renderCustomHandEventHandler(event.getHand(),
EventHandler.renderCustomHandEventHandler(
event.getHand(),
event.getPoseStack(),
event.getMultiBufferSource(),
event.getPackedLight(),
event.getPartialTick(),
event.getInterpolatedPitch(),
event.getSwingProgress(),
event.getEquipProgress(),
event.getItemStack());
event.getItemStack()
);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
* @see KeyModifier
*/
@OnlyIn(Dist.CLIENT)
@EventBusSubscriber(modid = Ayame.MOD_ID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public class RegisterKeyMappingEventHandler {
public class RegisterKeyEventHandler {
public static final Lazy<KeyMapping> MODEL_SELECT_MENU = Lazy.of(() -> new KeyMapping(
"key." + Ayame.MOD_ID + "." + TranslatableName.SELECT_MODEL_MENU,
KeyConflictContext.IN_GAME,
Expand Down

0 comments on commit 53ef0e6

Please sign in to comment.