添加cloth api适配,实现游戏内修改config功能
This commit is contained in:
parent
67257e21e9
commit
98a330a26d
11 changed files with 124 additions and 15 deletions
|
@ -59,6 +59,9 @@ repositories {
|
|||
name = "Jared's maven"
|
||||
url = "https://maven.blamejared.com/"
|
||||
}
|
||||
maven {
|
||||
url "https://maven.shedaniel.me/"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
@ -75,6 +78,8 @@ dependencies {
|
|||
compileOnly(fg.deobf("mezz.jei:jei-${mc_version}-forge-api:${jei_version}"))
|
||||
// at runtime, use the full JEI jar for Forge
|
||||
runtimeOnly(fg.deobf("mezz.jei:jei-${mc_version}-forge:${jei_version}"))
|
||||
|
||||
implementation fg.deobf("me.shedaniel.cloth:cloth-config-forge:${cloth_config_version}")
|
||||
}
|
||||
|
||||
mixin {
|
||||
|
|
|
@ -2,4 +2,5 @@ org.gradle.jvmargs=-Xmx3G
|
|||
org.gradle.daemon=false
|
||||
|
||||
mc_version=1.20.1
|
||||
jei_version=15.2.0.27
|
||||
jei_version=15.2.0.27
|
||||
cloth_config_version=11.1.106
|
|
@ -2,18 +2,19 @@ package net.mcreator.superbwarfare.client;
|
|||
|
||||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import net.mcreator.superbwarfare.ModUtils;
|
||||
import net.mcreator.superbwarfare.config.client.EmptyAutoReloadConfig;
|
||||
import net.mcreator.superbwarfare.compat.CompatHolder;
|
||||
import net.mcreator.superbwarfare.compat.clothconfig.ClothConfigHelper;
|
||||
import net.mcreator.superbwarfare.config.client.ReloadConfig;
|
||||
import net.mcreator.superbwarfare.entity.ICannonEntity;
|
||||
import net.mcreator.superbwarfare.entity.MortarEntity;
|
||||
import net.mcreator.superbwarfare.init.ModItems;
|
||||
import net.mcreator.superbwarfare.init.ModMobEffects;
|
||||
import net.mcreator.superbwarfare.init.ModSounds;
|
||||
import net.mcreator.superbwarfare.init.ModTags;
|
||||
import net.mcreator.superbwarfare.init.*;
|
||||
import net.mcreator.superbwarfare.item.common.ammo.CannonShellItem;
|
||||
import net.mcreator.superbwarfare.network.ModVariables;
|
||||
import net.mcreator.superbwarfare.network.message.*;
|
||||
import net.mcreator.superbwarfare.tools.TraceTool;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
@ -23,6 +24,7 @@ import net.minecraft.world.phys.Vec3;
|
|||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.InputEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
|
@ -89,7 +91,7 @@ public class ClickHandler {
|
|||
event.setCanceled(true);
|
||||
|
||||
if (stack.is(ModTags.Items.GUN) && !stack.is(ModTags.Items.CANNOT_RELOAD) && stack.getOrCreateTag().getInt("ammo") <= 0) {
|
||||
if (EmptyAutoReloadConfig.EMPTY_AUTO_RELOAD.get()) {
|
||||
if (ReloadConfig.EMPTY_AUTO_RELOAD.get()) {
|
||||
ModUtils.PACKET_HANDLER.sendToServer(new ReloadMessage(0));
|
||||
}
|
||||
} else {
|
||||
|
@ -158,9 +160,12 @@ public class ClickHandler {
|
|||
setKeyState(event);
|
||||
|
||||
int key = event.getKey();
|
||||
if (key == Minecraft.getInstance().options.keyJump.getKey().getValue()) {
|
||||
if (key == Minecraft.getInstance().options.keyJump.getKey().getValue() && event.getAction() == GLFW.GLFW_PRESS) {
|
||||
handleDoubleJump(player);
|
||||
}
|
||||
if (key == ModKeyMappings.CONFIG.getKey().getValue() && event.getAction() == GLFW.GLFW_PRESS) {
|
||||
handleConfigScreen(player);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setKeyState(InputEvent.Key event) {
|
||||
|
@ -221,4 +226,12 @@ public class ClickHandler {
|
|||
}
|
||||
}
|
||||
|
||||
private static void handleConfigScreen(Player player) {
|
||||
if (ModList.get().isLoaded(CompatHolder.CLOTH_CONFIG)) {
|
||||
CompatHolder.hasMod(CompatHolder.CLOTH_CONFIG, () -> Minecraft.getInstance().setScreen(ClothConfigHelper.getConfigScreen(null)));
|
||||
} else {
|
||||
player.displayClientMessage(Component.translatable("des.superbwarfare.no_cloth_config").withStyle(ChatFormatting.RED), true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,12 +1,21 @@
|
|||
package net.mcreator.superbwarfare.compat;
|
||||
|
||||
import net.mcreator.superbwarfare.compat.clothconfig.ClothConfigHelper;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
|
||||
import net.minecraftforge.registries.ObjectHolder;
|
||||
|
||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public class CompatHolder {
|
||||
|
||||
public static final String DMV = "dreamaticvoyage";
|
||||
public static final String VRC = "virtuarealcraft";
|
||||
public static final String CLOTH_CONFIG = "cloth_config";
|
||||
|
||||
@ObjectHolder(registryName = "minecraft:mob_effect", value = DMV + ":bleeding")
|
||||
public static final MobEffect DMV_BLEEDING = null;
|
||||
|
@ -14,4 +23,14 @@ public class CompatHolder {
|
|||
@ObjectHolder(registryName = "minecraft:mob_effect", value = VRC + ":curse_flame")
|
||||
public static final MobEffect VRC_CURSE_FLAME = null;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onInterModEnqueue(final InterModEnqueueEvent event) {
|
||||
event.enqueueWork(() -> hasMod(CLOTH_CONFIG, () -> DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> ClothConfigHelper::registerScreen)));
|
||||
}
|
||||
|
||||
public static void hasMod(String modid, Runnable runnable) {
|
||||
if (ModList.get().isLoaded(modid)) {
|
||||
runnable.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package net.mcreator.superbwarfare.compat.clothconfig;
|
||||
|
||||
import me.shedaniel.clothconfig2.api.ConfigBuilder;
|
||||
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
|
||||
import net.mcreator.superbwarfare.compat.clothconfig.client.ReloadClothConfig;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.client.ConfigScreenHandler;
|
||||
import net.minecraftforge.fml.ModLoadingContext;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ClothConfigHelper {
|
||||
|
||||
public static ConfigBuilder getConfigBuilder() {
|
||||
ConfigBuilder root = ConfigBuilder.create().setTitle(Component.translatable("config.superbwarfare.title"));
|
||||
root.setGlobalized(true);
|
||||
root.setGlobalizedExpanded(false);
|
||||
ConfigEntryBuilder entryBuilder = root.entryBuilder();
|
||||
|
||||
ReloadClothConfig.init(root, entryBuilder);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
public static void registerScreen() {
|
||||
ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, () ->
|
||||
new ConfigScreenHandler.ConfigScreenFactory((client, parent) -> getConfigScreen(parent)));
|
||||
}
|
||||
|
||||
public static Screen getConfigScreen(@Nullable Screen parent) {
|
||||
return ClothConfigHelper.getConfigBuilder().setParentScreen(parent).build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package net.mcreator.superbwarfare.compat.clothconfig.client;
|
||||
|
||||
import me.shedaniel.clothconfig2.api.ConfigBuilder;
|
||||
import me.shedaniel.clothconfig2.api.ConfigCategory;
|
||||
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
|
||||
import net.mcreator.superbwarfare.config.client.ReloadConfig;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
public class ReloadClothConfig {
|
||||
|
||||
public static void init(ConfigBuilder root, ConfigEntryBuilder entryBuilder) {
|
||||
ConfigCategory category = root.getOrCreateCategory(Component.translatable("config.superbwarfare.client.reload"));
|
||||
|
||||
category.addEntry(entryBuilder
|
||||
.startBooleanToggle(Component.translatable("config.superbwarfare.client.reload.empty_auto_reload"), ReloadConfig.EMPTY_AUTO_RELOAD.get())
|
||||
.setDefaultValue(true)
|
||||
.setSaveConsumer(ReloadConfig.EMPTY_AUTO_RELOAD::set)
|
||||
.setTooltip(Component.translatable("config.superbwarfare.client.reload.empty_auto_reload.des")).build()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package net.mcreator.superbwarfare.config;
|
||||
|
||||
import net.mcreator.superbwarfare.config.client.EmptyAutoReloadConfig;
|
||||
import net.mcreator.superbwarfare.config.client.ReloadConfig;
|
||||
import net.mcreator.superbwarfare.config.client.KillMessageClientConfig;
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
|
||||
|
@ -9,7 +9,7 @@ public class ClientConfig {
|
|||
public static ForgeConfigSpec init() {
|
||||
ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
|
||||
|
||||
EmptyAutoReloadConfig.init(builder);
|
||||
ReloadConfig.init(builder);
|
||||
KillMessageClientConfig.init(builder);
|
||||
|
||||
return builder.build();
|
||||
|
|
|
@ -2,12 +2,12 @@ package net.mcreator.superbwarfare.config.client;
|
|||
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
|
||||
public class EmptyAutoReloadConfig {
|
||||
public class ReloadConfig {
|
||||
|
||||
public static ForgeConfigSpec.BooleanValue EMPTY_AUTO_RELOAD;
|
||||
|
||||
public static void init(ForgeConfigSpec.Builder builder) {
|
||||
builder.push("empty_auto_reload");
|
||||
builder.push("reload");
|
||||
|
||||
builder.comment("Set TRUE if you want to reload guns when ammo is empty");
|
||||
EMPTY_AUTO_RELOAD = builder.define("empty_auto_reload", true);
|
|
@ -97,6 +97,8 @@ public class ModKeyMappings {
|
|||
}
|
||||
};
|
||||
|
||||
public static final KeyMapping CONFIG = new KeyMapping("key.superbwarfare.config", GLFW.GLFW_KEY_P, "key.categories.superbwarfare");
|
||||
|
||||
@SubscribeEvent
|
||||
public static void registerKeyMappings(RegisterKeyMappingsEvent event) {
|
||||
event.register(RELOAD);
|
||||
|
@ -105,9 +107,10 @@ public class ModKeyMappings {
|
|||
event.register(SENSITIVITY_REDUCE);
|
||||
event.register(INTERACT);
|
||||
event.register(BREATH);
|
||||
event.register(CONFIG);
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber({Dist.CLIENT})
|
||||
@Mod.EventBusSubscriber(value = Dist.CLIENT)
|
||||
public static class KeyEventListener {
|
||||
@SubscribeEvent
|
||||
public static void onClientTick(TickEvent.ClientTickEvent event) {
|
||||
|
|
|
@ -303,6 +303,7 @@
|
|||
"key.superbwarfare.sensitivity_reduce": "Reduce Sensitivity",
|
||||
"key.superbwarfare.interact": "Interact",
|
||||
"key.superbwarfare.breath": "Breathe",
|
||||
"key.superbwarfare.config": "Open Config Screen",
|
||||
|
||||
"effect.superbwarfare.shock": "Shock",
|
||||
"item.minecraft.potion.effect.superbwarfare_shock": "Potion of Shock",
|
||||
|
@ -328,6 +329,7 @@
|
|||
"des.superbwarfare.monitor.monitor_already_linked": "This monitor has been connected!",
|
||||
"des.superbwarfare.monitor.already_linked": "This device has been connected!",
|
||||
"des.superbwarfare.monitor.unlinked": "Disconnect!",
|
||||
"des.superbwarfare.no_cloth_config": "您尚未安装 Cloth Config API,无法打开配置界面",
|
||||
|
||||
"des.superbwarfare.drone.distance": "DISTANCE:",
|
||||
"des.superbwarfare.drone.health": "HEALTH:",
|
||||
|
@ -340,5 +342,10 @@
|
|||
|
||||
"entity.minecraft.villager.superbwarfare.armory": "Armory",
|
||||
|
||||
"container.superbwarfare.reforging_table": "Gun Reforge Table"
|
||||
"container.superbwarfare.reforging_table": "Gun Reforge Table",
|
||||
|
||||
"config.superbwarfare.title": "卓越前线:配置",
|
||||
"config.superbwarfare.client.reload": "换弹配置",
|
||||
"config.superbwarfare.client.reload.empty_auto_reload": "自动换弹",
|
||||
"config.superbwarfare.client.reload.empty_auto_reload.des": "在当前弹匣为空时,点击开火键以进行换弹"
|
||||
}
|
|
@ -302,6 +302,7 @@
|
|||
"key.superbwarfare.sensitivity_reduce": "减少灵敏度",
|
||||
"key.superbwarfare.interact": "交互",
|
||||
"key.superbwarfare.breath": "屏息",
|
||||
"key.superbwarfare.config": "打开配置界面",
|
||||
|
||||
"effect.superbwarfare.shock": "电击",
|
||||
"item.minecraft.potion.effect.superbwarfare_shock": "电击药水",
|
||||
|
@ -327,6 +328,7 @@
|
|||
"des.superbwarfare.monitor.monitor_already_linked": "这个遥控器已连接到一个设备!",
|
||||
"des.superbwarfare.monitor.already_linked": "这个设备已被连接!",
|
||||
"des.superbwarfare.monitor.unlinked": "断开连接!",
|
||||
"des.superbwarfare.no_cloth_config": "您尚未安装 Cloth Config API,无法打开配置界面",
|
||||
|
||||
"des.superbwarfare.drone.distance": "飞手距离:",
|
||||
"des.superbwarfare.drone.health": "耐久值:",
|
||||
|
@ -339,5 +341,10 @@
|
|||
|
||||
"entity.minecraft.villager.superbwarfare.armory": "军械师",
|
||||
|
||||
"container.superbwarfare.reforging_table": "枪械重铸台"
|
||||
"container.superbwarfare.reforging_table": "枪械重铸台",
|
||||
|
||||
"config.superbwarfare.title": "卓越前线:配置",
|
||||
"config.superbwarfare.client.reload": "换弹配置",
|
||||
"config.superbwarfare.client.reload.empty_auto_reload": "自动换弹",
|
||||
"config.superbwarfare.client.reload.empty_auto_reload.des": "在当前弹匣为空时,点击开火键以进行换弹"
|
||||
}
|
Loading…
Add table
Reference in a new issue