添加common config

This commit is contained in:
17146 2024-10-10 00:58:38 +08:00
parent ec66fe642e
commit 1b7d5d5beb
13 changed files with 98 additions and 57 deletions

View file

@ -1,6 +1,7 @@
package net.mcreator.superbwarfare;
import net.mcreator.superbwarfare.config.ClientConfig;
import net.mcreator.superbwarfare.config.CommonConfig;
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.COMMON, CommonConfig.init());
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();

View file

@ -109,8 +109,6 @@ public class CrossHairOverlay {
}
}
// 在开启伤害指示器时才进行渲染
if (DisplayConfig.KILL_INDICATION.get()) {
renderKillIndicator(guiGraphics, w, h, moveX, moveY);

View file

@ -5,6 +5,7 @@ import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
import net.mcreator.superbwarfare.compat.clothconfig.client.DisplayClothConfig;
import net.mcreator.superbwarfare.compat.clothconfig.client.KillMessageClothConfig;
import net.mcreator.superbwarfare.compat.clothconfig.client.ReloadClothConfig;
import net.mcreator.superbwarfare.compat.clothconfig.common.GameplayClothConfig;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraftforge.client.ConfigScreenHandler;
@ -23,6 +24,8 @@ public class ClothConfigHelper {
KillMessageClothConfig.init(root, entryBuilder);
DisplayClothConfig.init(root, entryBuilder);
GameplayClothConfig.init(root, entryBuilder);
return root;
}

View file

@ -19,14 +19,6 @@ public class DisplayClothConfig {
.build()
);
category.addEntry(entryBuilder
.startBooleanToggle(Component.translatable("config.superbwarfare.client.display.global_indication"), DisplayConfig.GLOBAL_INDICATION.get())
.setDefaultValue(false)
.setSaveConsumer(DisplayConfig.GLOBAL_INDICATION::set)
.setTooltip(Component.translatable("config.superbwarfare.client.display.global_indication.des"))
.build()
);
category.addEntry(entryBuilder
.startBooleanToggle(Component.translatable("config.superbwarfare.client.display.ammo_hud"), DisplayConfig.AMMO_HUD.get())
.setDefaultValue(true)

View file

@ -0,0 +1,22 @@
package net.mcreator.superbwarfare.compat.clothconfig.common;
import me.shedaniel.clothconfig2.api.ConfigBuilder;
import me.shedaniel.clothconfig2.api.ConfigCategory;
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
import net.mcreator.superbwarfare.config.common.GameplayConfig;
import net.minecraft.network.chat.Component;
public class GameplayClothConfig {
public static void init(ConfigBuilder root, ConfigEntryBuilder entryBuilder) {
ConfigCategory category = root.getOrCreateCategory(Component.translatable("config.superbwarfare.common.gameplay"));
category.addEntry(entryBuilder
.startBooleanToggle(Component.translatable("config.superbwarfare.common.gameplay.global_indication"), GameplayConfig.GLOBAL_INDICATION.get())
.setDefaultValue(false)
.setSaveConsumer(GameplayConfig.GLOBAL_INDICATION::set)
.setTooltip(Component.translatable("config.superbwarfare.common.gameplay.global_indication.des"))
.build()
);
}
}

View file

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

View file

@ -5,7 +5,6 @@ import net.minecraftforge.common.ForgeConfigSpec;
public class DisplayConfig {
public static ForgeConfigSpec.BooleanValue KILL_INDICATION;
public static ForgeConfigSpec.BooleanValue GLOBAL_INDICATION;
public static ForgeConfigSpec.BooleanValue AMMO_HUD;
public static ForgeConfigSpec.BooleanValue FLOAT_CROSS_HAIR;
public static ForgeConfigSpec.BooleanValue CAMERA_ROTATE;
@ -17,9 +16,6 @@ public class DisplayConfig {
builder.comment("Set TRUE if you want to show kill indication while killing an entity");
KILL_INDICATION = builder.define("kill_indication", true);
builder.comment("Set FALSE if you want to show kill indication ONLY while killing an entity with a gun");
GLOBAL_INDICATION = builder.define("global_indication", true);
builder.comment("Set TRUE to show ammo and gun info on HUD");
AMMO_HUD = builder.define("ammo_hud", true);

View file

@ -0,0 +1,18 @@
package net.mcreator.superbwarfare.config.common;
import net.minecraftforge.common.ForgeConfigSpec;
public class GameplayConfig {
public static ForgeConfigSpec.BooleanValue GLOBAL_INDICATION;
public static void init(ForgeConfigSpec.Builder builder) {
builder.push("gameplay");
builder.comment("Set FALSE if you want to show kill indication ONLY while killing an entity with a gun");
GLOBAL_INDICATION = builder.define("global_indication", true);
builder.pop();
}
}

View file

@ -1,7 +1,7 @@
package net.mcreator.superbwarfare.event;
import net.mcreator.superbwarfare.ModUtils;
import net.mcreator.superbwarfare.config.client.DisplayConfig;
import net.mcreator.superbwarfare.config.common.GameplayConfig;
import net.mcreator.superbwarfare.entity.TargetEntity;
import net.mcreator.superbwarfare.entity.projectile.ProjectileEntity;
import net.mcreator.superbwarfare.init.*;
@ -193,12 +193,12 @@ public class LivingEventHandler {
}
// 如果配置不选择全局伤害提示则只在伤害类型为mod添加的时显示指示器
if (!DisplayConfig.GLOBAL_INDICATION.get() && !DamageTypeTool.isModDamage(source)) {
if (!GameplayConfig.GLOBAL_INDICATION.get() && !DamageTypeTool.isModDamage(source)) {
return;
}
if (!sourceEntity.level().isClientSide() && sourceEntity instanceof ServerPlayer player) {
SoundTool.playLocalSound(player, ModSounds.TARGET_DOWN.get(), 100f, 1f);
SoundTool.playLocalSound(player, ModSounds.TARGET_DOWN.get(), 3f, 1f);
ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> player), new ClientIndicatorMessage(2, 8));
}

View file

@ -4,7 +4,8 @@ import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
import net.mcreator.superbwarfare.entity.DroneEntity;
import net.mcreator.superbwarfare.tools.ItemNBTTool;
import net.mcreator.superbwarfare.tools.TooltipTool;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
@ -19,6 +20,7 @@ import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import java.text.DecimalFormat;
import java.util.List;
public class Monitor extends Item {
@ -65,21 +67,32 @@ public class Monitor extends Item {
}
@Override
public Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers(EquipmentSlot equipmentSlot) {
if (equipmentSlot == EquipmentSlot.MAINHAND) {
public Multimap<Attribute, AttributeModifier> getAttributeModifiers(EquipmentSlot slot, ItemStack stack) {
if (slot == EquipmentSlot.MAINHAND) {
ImmutableMultimap.Builder<Attribute, AttributeModifier> builder = ImmutableMultimap.builder();
builder.putAll(super.getDefaultAttributeModifiers(equipmentSlot));
builder.putAll(super.getAttributeModifiers(slot, stack));
builder.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(BASE_ATTACK_DAMAGE_UUID, "Item modifier", 2d, AttributeModifier.Operation.ADDITION));
builder.put(Attributes.ATTACK_SPEED, new AttributeModifier(BASE_ATTACK_SPEED_UUID, "Item modifier", -2.4, AttributeModifier.Operation.ADDITION));
return builder.build();
}
return super.getDefaultAttributeModifiers(equipmentSlot);
}
return super.getAttributeModifiers(slot, stack);
}
@Override
public void appendHoverText(ItemStack stack, Level world, List<Component> list, TooltipFlag flag) {
TooltipTool.addMonitorTips(list, stack.getOrCreateTag().getString(LINKED_DRONE));
if (stack.getOrCreateTag().getString(LINKED_DRONE).equals("none")) return;
Player player = Minecraft.getInstance().player;
if (player == null) return;
DroneEntity entity = player.level().getEntitiesOfClass(DroneEntity.class, player.getBoundingBox().inflate(512))
.stream().filter(e -> e.getStringUUID().equals(stack.getOrCreateTag().getString(LINKED_DRONE))).findFirst().orElse(null);
if (entity == null) return;
list.add(Component.translatable("des.superbwarfare.tips.distance").withStyle(ChatFormatting.GRAY)
.append(Component.literal("").withStyle(ChatFormatting.RESET))
.append(Component.literal("Distance:" + new DecimalFormat("##.#").format(player.distanceTo(entity)) + "M").withStyle(ChatFormatting.GRAY)));
}
@Override

View file

@ -1,18 +1,15 @@
package net.mcreator.superbwarfare.tools;
import net.mcreator.superbwarfare.entity.DroneEntity;
import net.mcreator.superbwarfare.init.ModPerks;
import net.mcreator.superbwarfare.init.ModTags;
import net.mcreator.superbwarfare.perk.AmmoPerk;
import net.mcreator.superbwarfare.perk.Perk;
import net.mcreator.superbwarfare.perk.PerkHelper;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
@ -308,20 +305,4 @@ public class TooltipTool {
}
public static void addMonitorTips(List<Component> tooltip, String id) {
if (id.equals("none")) return;
Player player = Minecraft.getInstance().player;
if (player == null) return;
DroneEntity entity = player.level().getEntitiesOfClass(DroneEntity.class, player.getBoundingBox().inflate(512))
.stream().filter(e -> e.getStringUUID().equals(id)).findFirst().orElse(null);
if (entity == null) return;
tooltip.add(Component.translatable("des.superbwarfare.tips.distance").withStyle(ChatFormatting.GRAY)
.append(Component.literal("").withStyle(ChatFormatting.RESET))
.append(Component.literal("Distance:" + new DecimalFormat("##.#").format(player.distanceTo(entity)) + "M").withStyle(ChatFormatting.GRAY)));
}
}

View file

@ -345,8 +345,6 @@
"commands.ammo.get": "Current %s ammo: %s",
"commands.ammo.set": "Set %s ammo to %s for %s players",
"commands.ammo.add": "Added %s ammo of amount %s for %s players",
"commands.pvp_mode.on": "Enabled PVP Mode",
"commands.pvp_mode.off": "Disabled PVP Mode",
"des.superbwarfare.monitor.linked": "Connect",
"des.superbwarfare.monitor.monitor_already_linked": "This monitor has been connected",
@ -379,8 +377,6 @@
"config.superbwarfare.client.display": "Display Config",
"config.superbwarfare.client.display.kill_indication": "Kill Indication",
"config.superbwarfare.client.display.kill_indication.des": "The kill indicator will appear around the cross hair after a creature is killed when turned on",
"config.superbwarfare.client.display.global_indication": "Global damage indicator",
"config.superbwarfare.client.display.global_indication.des": "Whether to show a kill indication around the cross hair when killing a creature with only the damage type of this module",
"config.superbwarfare.client.display.ammo_hud": "Ammo HUD",
"config.superbwarfare.client.display.ammo_hud.des": "Display firearm and ammo information in the lower right corner when turned on",
"config.superbwarfare.client.display.float_cross_hair": "Dynamic Cross Hair",
@ -390,6 +386,10 @@
"config.superbwarfare.client.display.armor_plate_hud": "Armor Plate HUD",
"config.superbwarfare.client.display.armor_plate_hud.des": "Display the durability of the bulletproof insert currently equipped on the chest armor in the lower left corner when turned on",
"config.superbwarfare.common.gameplay": "Gameplay Config",
"config.superbwarfare.common.gameplay.global_indication": "Global damage indicator",
"config.superbwarfare.common.gameplay.global_indication.des": "Whether to show a kill indication around the cross hair when killing a creature with only the damage type of this module",
"des.superbwarfare.perk_damage_reduce": "Damage -",
"des.superbwarfare.perk_damage_plus": "Damage +",
"des.superbwarfare.perk_speed_reduce": "Velocity -",

View file

@ -345,8 +345,6 @@
"commands.ammo.get": "当前%s弹药数量: %s",
"commands.ammo.set": "为%3$s位玩家的%1$s弹药数量设置为%2$s",
"commands.ammo.add": "为%3$s位玩家添加了%2$s发%1$s弹药",
"commands.pvp_mode.on": "已启用PVP模式",
"commands.pvp_mode.off": "已禁用PVP模式",
"des.superbwarfare.monitor.linked": "连接成功!",
"des.superbwarfare.monitor.monitor_already_linked": "这个遥控器已连接到一个设备!",
@ -379,8 +377,6 @@
"config.superbwarfare.client.display": "显示配置",
"config.superbwarfare.client.display.kill_indication": "击杀提示",
"config.superbwarfare.client.display.kill_indication.des": "开启时,击杀生物时会在准星周围显示击杀提示",
"config.superbwarfare.client.display.global_indication": "全局伤害提示",
"config.superbwarfare.client.display.global_indication.des": "是否在仅使用本模组的伤害类型击杀生物时,在准星周围显示击杀提示",
"config.superbwarfare.client.display.ammo_hud": "枪械信息",
"config.superbwarfare.client.display.ammo_hud.des": "开启时,在屏幕右下角显示枪械和弹药信息",
"config.superbwarfare.client.display.float_cross_hair": "浮动准星",
@ -390,6 +386,10 @@
"config.superbwarfare.client.display.armor_plate_hud": "防弹插板信息",
"config.superbwarfare.client.display.armor_plate_hud.des": "开启时,在屏幕左下角显示当前胸甲装备的防弹插板的耐久",
"config.superbwarfare.common.gameplay": "游戏内容配置",
"config.superbwarfare.common.gameplay.global_indication": "全局伤害提示",
"config.superbwarfare.common.gameplay.global_indication.des": "是否在仅使用本模组的伤害类型击杀生物时,在准星周围显示击杀提示",
"des.superbwarfare.perk_damage_reduce": "伤害 -",
"des.superbwarfare.perk_damage_plus": "伤害 +",
"des.superbwarfare.perk_speed_reduce": "子弹初速 -",