添加更多的config

This commit is contained in:
17146 2024-09-29 09:50:42 +08:00
parent a61530cda0
commit 67257e21e9
9 changed files with 75 additions and 8 deletions

View file

@ -1,6 +1,7 @@
package net.mcreator.superbwarfare;
import net.mcreator.superbwarfare.config.ClientConfig;
import net.mcreator.superbwarfare.config.ServerConfig;
import net.mcreator.superbwarfare.init.*;
import net.mcreator.superbwarfare.network.ModVariables;
import net.mcreator.superbwarfare.network.message.*;
@ -43,6 +44,7 @@ public class ModUtils {
public ModUtils() {
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ClientConfig.init());
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, ServerConfig.init());
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();

View file

@ -3,6 +3,7 @@ package net.mcreator.superbwarfare.client.screens;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.mcreator.superbwarfare.ModUtils;
import net.mcreator.superbwarfare.config.client.KillMessageClientConfig;
import net.mcreator.superbwarfare.event.KillMessageHandler;
import net.mcreator.superbwarfare.init.ModDamageTypes;
import net.mcreator.superbwarfare.init.ModItems;
@ -44,7 +45,11 @@ public class KillMessageOverlay {
private static final ResourceLocation WORLD_PEACE_STAFF = new ResourceLocation(ModUtils.MODID, "textures/gun_icon/compat/world_peace_staff.png");
@SubscribeEvent(priority = EventPriority.NORMAL)
public static void eventHandler(RenderGuiEvent.Pre event) {
public static void onRenderGui(RenderGuiEvent.Pre event) {
if (!KillMessageClientConfig.SHOW_KILL_MESSAGE.get()) {
return;
}
Player player = Minecraft.getInstance().player;
if (player == null) {

View file

@ -1,6 +1,7 @@
package net.mcreator.superbwarfare.config;
import net.mcreator.superbwarfare.config.client.EmptyAutoReloadConfig;
import net.mcreator.superbwarfare.config.client.KillMessageClientConfig;
import net.minecraftforge.common.ForgeConfigSpec;
public class ClientConfig {
@ -9,6 +10,7 @@ public class ClientConfig {
ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
EmptyAutoReloadConfig.init(builder);
KillMessageClientConfig.init(builder);
return builder.build();
}

View file

@ -0,0 +1,16 @@
package net.mcreator.superbwarfare.config;
import net.mcreator.superbwarfare.config.server.KillMessageServerConfig;
import net.minecraftforge.common.ForgeConfigSpec;
public class ServerConfig {
public static ForgeConfigSpec init() {
ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
KillMessageServerConfig.init(builder);
return builder.build();
}
}

View file

@ -0,0 +1,22 @@
package net.mcreator.superbwarfare.config.client;
import net.minecraftforge.common.ForgeConfigSpec;
public class KillMessageClientConfig {
public static ForgeConfigSpec.BooleanValue SHOW_KILL_MESSAGE;
public static ForgeConfigSpec.IntValue KILL_MESSAGE_COUNT;
public static void init(ForgeConfigSpec.Builder builder) {
builder.push("kill_message");
builder.comment("Set TRUE if you want to show kill message");
SHOW_KILL_MESSAGE = builder.define("show_kill_message", false);
builder.comment("The max count of kill messages to show concurrently");
KILL_MESSAGE_COUNT = builder.defineInRange("kill_message_count", 5, 1, 20);
builder.pop();
}
}

View file

@ -0,0 +1,17 @@
package net.mcreator.superbwarfare.config.server;
import net.minecraftforge.common.ForgeConfigSpec;
public class KillMessageServerConfig {
public static ForgeConfigSpec.BooleanValue SEND_KILL_MESSAGE;
public static void init(ForgeConfigSpec.Builder builder) {
builder.push("kill_message");
SEND_KILL_MESSAGE = builder.define("send_kill_message", false);
builder.pop();
}
}

View file

@ -13,7 +13,6 @@ import java.util.Queue;
public class KillMessageHandler {
public static Queue<PlayerKillRecord> QUEUE = new ArrayDeque<>();
public static final int MAX_SIZE = 10;
@SubscribeEvent
public static void onClientTick(TickEvent.ClientTickEvent event) {

View file

@ -1,6 +1,7 @@
package net.mcreator.superbwarfare.event;
import net.mcreator.superbwarfare.ModUtils;
import net.mcreator.superbwarfare.config.server.KillMessageServerConfig;
import net.mcreator.superbwarfare.entity.TargetEntity;
import net.mcreator.superbwarfare.entity.projectile.ProjectileEntity;
import net.mcreator.superbwarfare.init.*;
@ -234,15 +235,17 @@ public class LivingEventHandler {
});
}
/**
* 发送击杀消息
*/
private static void handlePlayerKillEntity(LivingDeathEvent event) {
LivingEntity entity = event.getEntity();
DamageSource source = event.getSource();
if (!ModVariables.MapVariables.get(entity.level()).pvpMode) {
if (!KillMessageServerConfig.SEND_KILL_MESSAGE.get()) {
return;
}
LivingEntity entity = event.getEntity();
DamageSource source = event.getSource();
ResourceKey<DamageType> damageTypeResourceKey = source.typeHolder().unwrapKey().isPresent() ? source.typeHolder().unwrapKey().get() : DamageTypes.GENERIC;
ServerPlayer attacker = null;

View file

@ -2,6 +2,7 @@ package net.mcreator.superbwarfare.network;
import net.mcreator.superbwarfare.client.screens.CrossHairOverlay;
import net.mcreator.superbwarfare.client.screens.DroneUIOverlay;
import net.mcreator.superbwarfare.config.client.KillMessageClientConfig;
import net.mcreator.superbwarfare.event.KillMessageHandler;
import net.mcreator.superbwarfare.network.message.ClientIndicatorMessage;
import net.mcreator.superbwarfare.network.message.GunsDataMessage;
@ -26,7 +27,7 @@ public class ClientPacketHandler {
public static void handlePlayerKillMessage(Player attacker, Entity target, boolean headshot, ResourceKey<DamageType> damageType, Supplier<NetworkEvent.Context> ctx) {
if (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT) {
if (KillMessageHandler.QUEUE.size() >= KillMessageHandler.MAX_SIZE) {
if (KillMessageHandler.QUEUE.size() >= KillMessageClientConfig.KILL_MESSAGE_COUNT.get()) {
KillMessageHandler.QUEUE.poll();
}
KillMessageHandler.QUEUE.offer(new PlayerKillRecord(attacker, target, attacker.getMainHandItem(), headshot, damageType));