优化NBT#Headshot

This commit is contained in:
17146 2024-12-24 15:03:00 +08:00
parent c00da95dbf
commit 6f578f8d65
33 changed files with 44 additions and 43 deletions

View file

@ -1,14 +1,15 @@
package com.atsuishio.superbwarfare.client.tooltip; package com.atsuishio.superbwarfare.client.tooltip;
import com.atsuishio.superbwarfare.client.tooltip.component.GunImageComponent;
import com.atsuishio.superbwarfare.init.ModKeyMappings; import com.atsuishio.superbwarfare.init.ModKeyMappings;
import com.atsuishio.superbwarfare.init.ModPerks; import com.atsuishio.superbwarfare.init.ModPerks;
import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.perk.AmmoPerk; import com.atsuishio.superbwarfare.perk.AmmoPerk;
import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.perk.PerkHelper; import com.atsuishio.superbwarfare.perk.PerkHelper;
import com.atsuishio.superbwarfare.tools.GunsTool;
import com.atsuishio.superbwarfare.tools.ItemNBTTool; import com.atsuishio.superbwarfare.tools.ItemNBTTool;
import com.atsuishio.superbwarfare.tools.TooltipTool; import com.atsuishio.superbwarfare.tools.TooltipTool;
import com.atsuishio.superbwarfare.client.tooltip.component.GunImageComponent;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.Font; import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.GuiGraphics;
@ -64,7 +65,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
} }
protected boolean shouldRenderBypassAndHeadshotTooltip() { protected boolean shouldRenderBypassAndHeadshotTooltip() {
return ItemNBTTool.getDouble(stack, "BypassesArmor", 0) > 0 || ItemNBTTool.getDouble(stack, "headshot", 0) > 0; return ItemNBTTool.getDouble(stack, "BypassesArmor", 0) > 0 || GunsTool.getGunDoubleTag(stack, "Headshot", 0) > 0;
} }
protected boolean shouldRenderEditTooltip() { protected boolean shouldRenderEditTooltip() {
@ -186,7 +187,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
* 获取武器爆头倍率文本组件 * 获取武器爆头倍率文本组件
*/ */
protected Component getHeadshotComponent() { protected Component getHeadshotComponent() {
double headshot = ItemNBTTool.getDouble(stack, "headshot", 0); double headshot = GunsTool.getGunDoubleTag(stack, "Headshot", 0);
return Component.translatable("des.superbwarfare.tips.headshot").withStyle(ChatFormatting.GRAY) return Component.translatable("des.superbwarfare.tips.headshot").withStyle(ChatFormatting.GRAY)
.append(Component.literal("").withStyle(ChatFormatting.RESET)) .append(Component.literal("").withStyle(ChatFormatting.RESET))
.append(Component.literal(new DecimalFormat("##.#").format(headshot) + "x").withStyle(ChatFormatting.AQUA)); .append(Component.literal(new DecimalFormat("##.#").format(headshot) + "x").withStyle(ChatFormatting.AQUA));

View file

@ -185,7 +185,7 @@ public class GunEventHandler {
ItemStack heldItem = player.getMainHandItem(); ItemStack heldItem = player.getMainHandItem();
if (!player.level().isClientSide()) { if (!player.level().isClientSide()) {
float headshot = (float) heldItem.getOrCreateTag().getDouble("headshot"); float headshot = (float) GunsTool.getGunDoubleTag(heldItem, "Headshot", 0);
float damage = (float) (heldItem.getOrCreateTag().getDouble("damage") + heldItem.getOrCreateTag().getDouble("sentinelChargeDamage")) * (float) perkDamage(heldItem); float damage = (float) (heldItem.getOrCreateTag().getDouble("damage") + heldItem.getOrCreateTag().getDouble("sentinelChargeDamage")) * (float) perkDamage(heldItem);
float velocity = (float) ((heldItem.getOrCreateTag().getDouble("velocity") + heldItem.getOrCreateTag().getDouble("CustomVelocity")) * perkSpeed(heldItem)); float velocity = (float) ((heldItem.getOrCreateTag().getDouble("velocity") + heldItem.getOrCreateTag().getDouble("CustomVelocity")) * perkSpeed(heldItem));
int projectileAmount = GunsTool.getGunIntTag(heldItem, "ProjectileAmount", 1); int projectileAmount = GunsTool.getGunIntTag(heldItem, "ProjectileAmount", 1);
@ -322,7 +322,7 @@ public class GunEventHandler {
stack.getOrCreateTag().putBoolean("is_empty_reloading", true); stack.getOrCreateTag().putBoolean("is_empty_reloading", true);
playGunEmptyReloadSounds(player); playGunEmptyReloadSounds(player);
} else { } else {
data.putInt("ReloadTime", GunsTool.getGunIntTag(stack, "NormalReloadTime") + 1); data.putInt("ReloadTime", data.getInt("NormalReloadTime") + 1);
stack.getOrCreateTag().putBoolean("is_normal_reloading", true); stack.getOrCreateTag().putBoolean("is_normal_reloading", true);
playGunNormalReloadSounds(player); playGunNormalReloadSounds(player);
} }

View file

@ -1,19 +1,19 @@
package com.atsuishio.superbwarfare.item.gun.handgun; package com.atsuishio.superbwarfare.item.gun.handgun;
import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.client.PoseTool;
import com.atsuishio.superbwarfare.client.renderer.item.TracheliumItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.TracheliumItemRenderer;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.network.ModVariables;
import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.perk.PerkHelper;
import com.atsuishio.superbwarfare.tools.GunsTool;
import com.atsuishio.superbwarfare.tools.TooltipTool;
import com.atsuishio.superbwarfare.client.PoseTool;
import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.AnimatedItem; import com.atsuishio.superbwarfare.item.AnimatedItem;
import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
import com.atsuishio.superbwarfare.network.ModVariables;
import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.perk.PerkHelper;
import com.atsuishio.superbwarfare.tools.GunsTool;
import com.atsuishio.superbwarfare.tools.TooltipTool;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.model.HumanoidModel; import net.minecraft.client.model.HumanoidModel;
@ -278,12 +278,12 @@ public class Trachelium extends GunItem implements GeoItem, AnimatedItem {
tag.putDouble("CustomVelocity", 15); tag.putDouble("CustomVelocity", 15);
tag.putDouble("BypassesArmor", 0.4); tag.putDouble("BypassesArmor", 0.4);
tag.putDouble("damage", 21); tag.putDouble("damage", 21);
tag.putDouble("headshot", 2.5); GunsTool.setGunDoubleTag(stack, "Headshot", 2.5);
} else { } else {
tag.putDouble("CustomVelocity", 0); tag.putDouble("CustomVelocity", 0);
tag.putDouble("BypassesArmor", 0.3); tag.putDouble("BypassesArmor", 0.3);
tag.putDouble("damage", 19); tag.putDouble("damage", 19);
tag.putDouble("headshot", 2); GunsTool.setGunDoubleTag(stack, "Headshot", 2);
} }
double customZoom = switch (scopeType) { double customZoom = switch (scopeType) {

View file

@ -238,7 +238,7 @@ public class FireMessage {
CompoundTag tag = heldItem.getOrCreateTag(); CompoundTag tag = heldItem.getOrCreateTag();
var perk = PerkHelper.getPerkByType(heldItem, Perk.Type.AMMO); var perk = PerkHelper.getPerkByType(heldItem, Perk.Type.AMMO);
float headshot = (float) tag.getDouble("headshot"); float headshot = (float) GunsTool.getGunDoubleTag(heldItem, "Headshot", 0);
float velocity = 2 * (float) tag.getDouble("speed") * (float) perkSpeed(heldItem); float velocity = 2 * (float) tag.getDouble("speed") * (float) perkSpeed(heldItem);
float bypassArmorRate = (float) heldItem.getOrCreateTag().getDouble("BypassesArmor"); float bypassArmorRate = (float) heldItem.getOrCreateTag().getDouble("BypassesArmor");
double damage; double damage;

View file

@ -55,7 +55,7 @@ public class GunsTool {
// TODO 临时使用移植完毕后删除 // TODO 临时使用移植完毕后删除
private static final Set<String> STRING_SET = Set.of("EmptyReloadTime", "FireMode", "Weight", "SoundRadius", "BurstSize", "ProjectileAmount", private static final Set<String> STRING_SET = Set.of("EmptyReloadTime", "FireMode", "Weight", "SoundRadius", "BurstSize", "ProjectileAmount",
"Spread", "NormalReloadTime"); "Spread", "NormalReloadTime", "Headshot");
public static void initGun(Level level, ItemStack stack, String location) { public static void initGun(Level level, ItemStack stack, String location) {
if (level.getServer() == null) return; if (level.getServer() == null) return;

View file

@ -3,7 +3,7 @@
"recoil_x": 0.006, "recoil_x": 0.006,
"recoil_y": 0.018, "recoil_y": 0.018,
"damage": 2.5, "damage": 2.5,
"headshot": 1.5, "Headshot": 1.5,
"velocity": 17, "velocity": 17,
"mag": 25, "mag": 25,
"ProjectileAmount": 12, "ProjectileAmount": 12,

View file

@ -3,7 +3,7 @@
"recoil_x": 0.005, "recoil_x": 0.005,
"recoil_y": 0.026, "recoil_y": 0.026,
"damage": 5, "damage": 5,
"headshot": 1.5, "Headshot": 1.5,
"velocity": 15, "velocity": 15,
"mag": 2, "mag": 2,
"ProjectileAmount": 12, "ProjectileAmount": 12,

View file

@ -5,7 +5,7 @@
"recoil_x": 0.0015, "recoil_x": 0.0015,
"recoil_y": 0.01, "recoil_y": 0.01,
"damage": 7.7, "damage": 7.7,
"headshot": 2, "Headshot": 2,
"velocity": 44.5, "velocity": 44.5,
"mag": 30, "mag": 30,
"Weight": 4, "Weight": 4,

View file

@ -5,7 +5,7 @@
"recoil_x": 0.002, "recoil_x": 0.002,
"recoil_y": 0.012, "recoil_y": 0.012,
"damage": 8.5, "damage": 8.5,
"headshot": 2, "Headshot": 2,
"velocity": 36, "velocity": 36,
"mag": 30, "mag": 30,
"Weight": 5, "Weight": 5,

View file

@ -1,7 +1,7 @@
{ {
"CustomZoom": 0.75, "CustomZoom": 0.75,
"Spread": 4, "Spread": 4,
"headshot": 2.5, "Headshot": 2.5,
"damage": 48, "damage": 48,
"Weight": 3, "Weight": 3,
"BypassesArmor": 0.25 "BypassesArmor": 0.25

View file

@ -4,7 +4,7 @@
"recoil_x": 0.0018, "recoil_x": 0.0018,
"recoil_y": 0.01, "recoil_y": 0.01,
"damage": 9.5, "damage": 9.5,
"headshot": 2, "Headshot": 2,
"velocity": 40, "velocity": 40,
"mag": 55, "mag": 55,
"Weight": 6, "Weight": 6,

View file

@ -3,7 +3,7 @@
"recoil_x": 0.004, "recoil_x": 0.004,
"recoil_y": 0.013, "recoil_y": 0.013,
"damage": 5.5, "damage": 5.5,
"headshot": 1.5, "Headshot": 1.5,
"velocity": 17, "velocity": 17,
"mag": 17, "mag": 17,
"Weight": 1, "Weight": 1,

View file

@ -3,7 +3,7 @@
"recoil_x": 0.004, "recoil_x": 0.004,
"recoil_y": 0.013, "recoil_y": 0.013,
"damage": 5.5, "damage": 5.5,
"headshot": 1.5, "Headshot": 1.5,
"velocity": 17, "velocity": 17,
"mag": 17, "mag": 17,
"Weight": 1, "Weight": 1,

View file

@ -5,7 +5,7 @@
"recoil_x": 0.0016, "recoil_x": 0.0016,
"recoil_y": 0.009, "recoil_y": 0.009,
"damage": 7.5, "damage": 7.5,
"headshot": 2, "Headshot": 2,
"velocity": 44, "velocity": 44,
"mag": 30, "mag": 30,
"Weight": 4, "Weight": 4,

View file

@ -3,7 +3,7 @@
"recoil_x": 0.004, "recoil_x": 0.004,
"recoil_y": 0.04, "recoil_y": 0.04,
"damage": 65, "damage": 65,
"headshot": 3, "Headshot": 3,
"velocity": 38, "velocity": 38,
"mag": 1, "mag": 1,
"Weight": 5, "Weight": 5,

View file

@ -3,7 +3,7 @@
"recoil_x": 0.002, "recoil_x": 0.002,
"recoil_y": 0.063, "recoil_y": 0.063,
"damage": 35, "damage": 35,
"headshot": 3, "Headshot": 3,
"velocity": 37.75, "velocity": 37.75,
"mag": 5, "mag": 5,
"bolt_action_time": 22, "bolt_action_time": 22,

View file

@ -3,7 +3,7 @@
"recoil_x": 0.006, "recoil_x": 0.006,
"recoil_y": 0.018, "recoil_y": 0.018,
"damage": 9.5, "damage": 9.5,
"headshot": 1.5, "Headshot": 1.5,
"velocity": 15, "velocity": 15,
"mag": 7, "mag": 7,
"Weight": 2, "Weight": 2,

View file

@ -5,7 +5,7 @@
"recoil_x": 0.0015, "recoil_x": 0.0015,
"recoil_y": 0.011, "recoil_y": 0.011,
"damage": 7, "damage": 7,
"headshot": 2, "Headshot": 2,
"velocity": 44, "velocity": 44,
"mag": 30, "mag": 30,
"Weight": 4, "Weight": 4,

View file

@ -3,7 +3,7 @@
"recoil_x": 0.004, "recoil_x": 0.004,
"recoil_y": 0.014, "recoil_y": 0.014,
"damage": 9, "damage": 9,
"headshot": 2, "Headshot": 2,
"velocity": 43, "velocity": 43,
"mag": 100, "mag": 100,
"Weight": 8, "Weight": 8,

View file

@ -3,7 +3,7 @@
"recoil_x": 0.009, "recoil_x": 0.009,
"recoil_y": 0.04, "recoil_y": 0.04,
"damage": 3, "damage": 3,
"headshot": 1.5, "Headshot": 1.5,
"velocity": 17, "velocity": 17,
"mag": 8, "mag": 8,
"force_stop_reloading": 1, "force_stop_reloading": 1,

View file

@ -6,7 +6,7 @@
"recoil_x": 0.007, "recoil_x": 0.007,
"recoil_y": 0.013, "recoil_y": 0.013,
"damage": 38, "damage": 38,
"headshot": 3, "Headshot": 3,
"velocity": 47.2, "velocity": 47.2,
"mag": 5, "mag": 5,
"bolt_action_time": 18, "bolt_action_time": 18,

View file

@ -3,7 +3,7 @@
"recoil_x": 0.004, "recoil_x": 0.004,
"recoil_y": 0.031, "recoil_y": 0.031,
"damage": 16, "damage": 16,
"headshot": 2.5, "Headshot": 2.5,
"velocity": 38, "velocity": 38,
"mag": 8, "mag": 8,
"force_stop_reloading": 1, "force_stop_reloading": 1,

View file

@ -3,7 +3,7 @@
"recoil_x": 0.003, "recoil_x": 0.003,
"recoil_y": 0.02, "recoil_y": 0.02,
"damage": 8, "damage": 8,
"headshot": 2, "Headshot": 2,
"velocity": 46, "velocity": 46,
"Weight": 10, "Weight": 10,
"FireMode": 2, "FireMode": 2,

View file

@ -5,7 +5,7 @@
"recoil_x": 0.006, "recoil_x": 0.006,
"recoil_y": 0.014, "recoil_y": 0.014,
"damage": 12, "damage": 12,
"headshot": 2.5, "Headshot": 2.5,
"velocity": 42.5, "velocity": 42.5,
"mag": 20, "mag": 20,
"Weight": 5, "Weight": 5,

View file

@ -4,7 +4,7 @@
"recoil_x": 0.002, "recoil_x": 0.002,
"recoil_y": 0.063, "recoil_y": 0.063,
"damage": 33, "damage": 33,
"headshot": 3, "Headshot": 3,
"velocity": 42, "velocity": 42,
"mag": 5, "mag": 5,
"bolt_action_time": 22, "bolt_action_time": 22,

View file

@ -4,7 +4,7 @@
"recoil_x": 0.01, "recoil_x": 0.01,
"recoil_y": 0.038, "recoil_y": 0.038,
"damage": 140, "damage": 140,
"headshot": 3, "Headshot": 3,
"velocity": 36, "velocity": 36,
"mag": 3, "mag": 3,
"bolt_action_time": 37, "bolt_action_time": 37,

View file

@ -5,7 +5,7 @@
"recoil_x": 0.0013, "recoil_x": 0.0013,
"recoil_y": 0.009, "recoil_y": 0.009,
"damage": 8.25, "damage": 8.25,
"headshot": 2, "Headshot": 2,
"velocity": 46, "velocity": 46,
"mag": 30, "mag": 30,
"Weight": 4, "Weight": 4,

View file

@ -3,7 +3,7 @@
"recoil_x": 0.0018, "recoil_x": 0.0018,
"recoil_y": 0.012, "recoil_y": 0.012,
"damage": 8.75, "damage": 8.75,
"headshot": 2, "Headshot": 2,
"velocity": 38, "velocity": 38,
"mag": 75, "mag": 75,
"Weight": 6, "Weight": 6,

View file

@ -5,7 +5,7 @@
"recoil_y": 0.018, "recoil_y": 0.018,
"damage": 35, "damage": 35,
"mag": 5, "mag": 5,
"headshot": 3, "Headshot": 3,
"velocity": 70, "velocity": 70,
"bolt_action_time": 22, "bolt_action_time": 22,
"Weight": 7, "Weight": 7,

View file

@ -3,7 +3,7 @@
"recoil_x": 0.004, "recoil_x": 0.004,
"recoil_y": 0.015, "recoil_y": 0.015,
"damage": 9.5, "damage": 9.5,
"headshot": 2, "Headshot": 2,
"velocity": 36, "velocity": 36,
"mag": 20, "mag": 20,
"Weight": 4, "Weight": 4,

View file

@ -4,7 +4,7 @@
"recoil_x": 0.004, "recoil_x": 0.004,
"recoil_y": 0.009, "recoil_y": 0.009,
"damage": 18, "damage": 18,
"headshot": 2, "Headshot": 2,
"velocity": 42, "velocity": 42,
"mag": 10, "mag": 10,
"Weight": 5, "Weight": 5,

View file

@ -3,7 +3,7 @@
"recoil_x": 0.005, "recoil_x": 0.005,
"recoil_y": 0.032, "recoil_y": 0.032,
"damage": 19, "damage": 19,
"headshot": 2, "Headshot": 2,
"velocity": 24, "velocity": 24,
"mag": 6, "mag": 6,
"Weight": 2, "Weight": 2,

View file

@ -3,7 +3,7 @@
"recoil_x": 0.002, "recoil_x": 0.002,
"recoil_y": 0.007, "recoil_y": 0.007,
"damage": 6, "damage": 6,
"headshot": 1.5, "Headshot": 1.5,
"velocity": 16, "velocity": 16,
"mag": 13, "mag": 13,
"Weight": 3, "Weight": 3,