Skip to content

Commit

Permalink
EventHandler统一
Browse files Browse the repository at this point in the history
  • Loading branch information
HappyRespawnanchor committed Oct 25, 2024
1 parent 9a77405 commit 1d5f4f4
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 56 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ build/*
/fabric/.gradle/
/fabric/build/
/fabric/run/

/run/
/common/src/main/generated/
/neoforge/src/main/generated/
Expand All @@ -18,3 +19,4 @@ build/*
/.idea/
!/.idea/copyright/
/*/.architectury-transformer/
/common/run/
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ subprojects {
}



dependencies {
minecraft "net.minecraft:minecraft:$rootProject.minecraft_version"
// mappings loom.officialMojangMappings()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import org.ayamemc.ayame.client.gui.screen.ModelSelectMenuScreen;
import org.ayamemc.ayame.client.resource.ModelScanner;
import org.ayamemc.ayame.util.ConfigUtil;

Expand All @@ -36,7 +34,5 @@ public static void init() {
ModelScanner.scanModel();
}

public static void openSelectMenuKeyPressed() {
ModelSelectMenuScreen.openDefaultModelSelectMenu(Minecraft.getInstance().screen);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import org.ayamemc.ayame.model.AyameModelType;
import org.ayamemc.ayame.model.DefaultAyameModelType;
import org.ayamemc.ayame.util.FileUtil;
import org.ayamemc.ayame.util.TaskManager;
import org.ayamemc.ayame.util.ZipFileManager;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
Expand Down Expand Up @@ -60,8 +58,8 @@ public class DefaultAyameModels {

public static void init() {
//TaskManager.TaskManagerImpls.CLIENT_IN_WORLD_TASKS.addTask(() -> {
GRMMY_NEKO_MODEL_RESOURCE = createModelResource("grmmy_neko");
GRMMY_NEKO_MODEL = createModel(GRMMY_NEKO_MODEL_RESOURCE);
GRMMY_NEKO_MODEL_RESOURCE = createModelResource("grmmy_neko");
GRMMY_NEKO_MODEL = createModel(GRMMY_NEKO_MODEL_RESOURCE);
//});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.*;
import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.gui.components.ImageButton;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.client.gui.components.WidgetSprites;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@
* along with Ayame. If not, see <https://www.gnu.org/licenses/>.
*/

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

import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.item.ItemStack;
import org.ayamemc.ayame.client.gui.screen.ModelSelectMenuScreen;

public class EventHandler {
final private static Minecraft minecraft = Minecraft.getInstance();

public class RenderCustomHandEventHandler {
public static void renderCustomHandEventHandler(
InteractionHand hand,
PoseStack poseStack,
Expand All @@ -37,7 +41,10 @@ public static void renderCustomHandEventHandler(
float equipProgress,
ItemStack stack
) {
//

}

public static void openSelectMenuKeyPressed() {
ModelSelectMenuScreen.openDefaultModelSelectMenu(minecraft.screen);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class AyameModelResource implements IModelResource {
* @param content 模型内容
*/
public AyameModelResource(ZipFileManager content) throws IOException {
if (content == null){
if (content == null) {
throw new RuntimeException("Model File Content is null");
}
this.content = content;
Expand All @@ -72,7 +72,7 @@ public String getType() {

public ModelDataResource getDefault() {
try {
if (FileUtil.inputStreamToString(content.readFileContent("index.json")).equalsIgnoreCase("")){
if (FileUtil.inputStreamToString(content.readFileContent("index.json")).equalsIgnoreCase("")) {
throw new RuntimeException("Model File index is null");
}
return ModelDataResource.Builder.create().getDefaultFromZip(content).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Builder parseJson(@NotNull JsonInterpreter json) {
this.metaData(ModelMetaData.Builder.create().parseJson(json.getJsonInterpreter("metadata")).build());
this.defaultModel(ModelData.Builder.create().parseJson(json.getJsonInterpreter("default")).build());
List<ModelData> ps = new ArrayList<>();
json.getJsonList("presets").forEach(preset ->{
json.getJsonList("presets").forEach(preset -> {
if (!preset.isNullOrEmpty()) {
ps.add(ModelData.Builder.create().parseJson(preset).build());
}
Expand Down
20 changes: 10 additions & 10 deletions common/src/main/java/org/ayamemc/ayame/util/JsonInterpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public JsonInterpreter(String jsonString) {
Gson gson = new Gson();
// 将 JSON 字符串转换为 JsonObject
this.jsonObject = gson.fromJson(jsonString, JsonObject.class);
if (jsonObject == null){
throw new RuntimeException("JsonObject is null,the content of it:"+original);
if (jsonObject == null) {
throw new RuntimeException("JsonObject is null,the content of it:" + original);
}
}

Expand Down Expand Up @@ -80,14 +80,6 @@ public JsonInterpreter(Path filePath) throws IOException {
this.filePath = filePath;
}

public boolean isEmpty() {
return jsonObject.entrySet().isEmpty();
}

public boolean isNullOrEmpty() {
return this.jsonObject == null || this.isEmpty();
}

public static JsonInterpreter of(String jsonString) {
return new JsonInterpreter(jsonString);
}
Expand All @@ -109,6 +101,14 @@ public static JsonInterpreter of(InputStream content) {
return new JsonInterpreter(FileUtil.inputStreamToString(content));
}

public boolean isEmpty() {
return jsonObject.entrySet().isEmpty();
}

public boolean isNullOrEmpty() {
return this.jsonObject == null || this.isEmpty();
}

/**
* 读取值
*
Expand Down
1 change: 0 additions & 1 deletion fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ processResources {
}



sourcesJar {
def commonSources = project(":common").sourcesJar
dependsOn commonSources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.KeyMapping;
import org.ayamemc.ayame.client.AyameClient;
import org.ayamemc.ayame.fabric.client.event.AyameKeyMappingEventHandler;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.ItemStack;
import org.ayamemc.ayame.client.event.RenderCustomHandEventHandler;
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.util.TaskManager;
Expand Down Expand Up @@ -94,7 +94,7 @@ private static InteractionResult renderCustomHand(
ItemStack stack,
LocalPlayer player
) {
RenderCustomHandEventHandler.renderCustomHandEventHandler(
EventHandler.renderCustomHandEventHandler(
hand,
poseStack,
multiBufferSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import net.minecraft.client.KeyMapping;
import org.ayamemc.ayame.client.AyameClient;
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.NotNull;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;

Expand Down Expand Up @@ -91,7 +91,7 @@ public static void init() {
*/
public static void processKeyPressed() {
while (AyameKeyMappingEventHandler.MODEL_SELECT_MENU.consumeClick()) {
AyameClient.openSelectMenuKeyPressed();
EventHandler.openSelectMenuKeyPressed();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.client.event.ClientTickEvent;
import org.ayamemc.ayame.Ayame;
import org.ayamemc.ayame.client.AyameClient;
import org.ayamemc.ayame.client.gui.screen.ModelSelectMenuScreen;
import org.ayamemc.ayame.client.handler.EventHandler;


/**
Expand All @@ -43,7 +43,7 @@ public class OpenModelSelectMenuEventHandler {
@SubscribeEvent
public static void onClientClick(ClientTickEvent.Post event) {
while (RegisterKeyMappingEventHandler.MODEL_SELECT_MENU.get().consumeClick()) {
AyameClient.openSelectMenuKeyPressed();
EventHandler.openSelectMenuKeyPressed();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.client.event.RenderHandEvent;
import org.ayamemc.ayame.Ayame;
import org.ayamemc.ayame.client.event.RenderCustomHandEventHandler;
import org.ayamemc.ayame.client.handler.EventHandler;


@OnlyIn(Dist.CLIENT)
Expand All @@ -48,7 +48,7 @@ public static void renderCustomModelHand(RenderHandEvent event) {
float equipProgress = event.getEquipProgress();
ItemStack stack = event.getItemStack();
event.setCanceled(true); // 取消渲染默认手臂
RenderCustomHandEventHandler.renderCustomHandEventHandler(
EventHandler.renderCustomHandEventHandler(
hand,
poseStack,
multiBufferSource,
Expand Down
38 changes: 19 additions & 19 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
/*
* Custom player model mod. Powered by GeckoLib.
* Copyright (C) 2024 CrystalNeko, HappyRespawnanchor, pertaz(Icon Designer)
*
* This file is part of Ayame.
*
* Ayame 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, either version 3 of the License, or
* (at your option) any later version.
*
* Ayame 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 Ayame. If not, see <https://www.gnu.org/licenses/>.
*/
/*
* Custom player model mod. Powered by GeckoLib.
* Copyright (C) 2024 CrystalNeko, HappyRespawnanchor, pertaz(Icon Designer)
*
* This file is part of Ayame.
*
* Ayame 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, either version 3 of the License, or
* (at your option) any later version.
*
* Ayame 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 Ayame. If not, see <https://www.gnu.org/licenses/>.
*/

pluginManagement {
repositories {
Expand Down

0 comments on commit 1d5f4f4

Please sign in to comment.