优化NBT#BoltActionTime

This commit is contained in:
17146 2024-12-24 16:35:22 +08:00
parent 7acd77914b
commit e798d66182
13 changed files with 20 additions and 20 deletions

View file

@ -168,7 +168,7 @@ public class GunEventHandler {
if (stack.is(ModTags.Items.REVOLVER)) return;
ModUtils.queueServerWork((int) (stack.getOrCreateTag().getDouble("bolt_action_time") / 2 + 1.5 * shooterHeight), () -> {
ModUtils.queueServerWork((int) (GunsTool.getGunDoubleTag(stack, "BoltActionTime", 0) / 2 + 1.5 * shooterHeight), () -> {
if (stack.is(ModTags.Items.SHOTGUN)) {
SoundTool.playLocalSound(serverPlayer, ModSounds.SHELL_CASING_SHOTGUN.get(), (float) Math.max(0.75 - 0.12 * shooterHeight, 0), 1);
} else if (stack.is(ModTags.Items.SNIPER_RIFLE)) {
@ -687,7 +687,7 @@ public class GunEventHandler {
// 三阶段结束
if (tag.getInt("finish") == 1) {
tag.putInt("reload_stage", 0);
if (tag.getDouble("bolt_action_time") > 0) {
if (GunsTool.getGunIntTag(stack, "BoltActionTime", 0) > 0) {
stack.getOrCreateTag().putBoolean("need_bolt_action", false);
}
tag.putBoolean("reloading", false);

View file

@ -330,7 +330,7 @@ public class LivingEventHandler {
}
var oldTags = oldStack.getTag();
if (oldTags.getInt("bolt_action_time") > 0) {
if (GunsTool.getGunDoubleTag(oldStack, "BoltActionTime", 0) > 0) {
oldTags.putInt("bolt_action_anim", 0);
}
@ -366,7 +366,7 @@ public class LivingEventHandler {
if (newStack.getItem() instanceof GunItem) {
player.getPersistentData().putDouble("noRun", 40);
newStack.getOrCreateTag().putBoolean("draw", true);
if (newStack.getOrCreateTag().getInt("bolt_action_time") > 0) {
if (GunsTool.getGunIntTag(newStack, "BoltActionTime", 0) > 0) {
newStack.getOrCreateTag().putInt("bolt_action_anim", 0);
}
newStack.getOrCreateTag().putBoolean("is_normal_reloading", false);

View file

@ -258,7 +258,7 @@ public class Trachelium extends GunItem implements GeoItem, AnimatedItem {
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
super.inventoryTick(stack, world, entity, slot, selected);
var tag = stack.getOrCreateTag();
tag.putInt("bolt_action_time", tag.getBoolean("DA") ? 12 : 0);
GunsTool.setGunIntTag(stack, "BoltActionTime", tag.getBoolean("DA") ? 12 : 0);
int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE);
int gripType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP);

View file

@ -148,12 +148,12 @@ public class FireMessage {
}
private static void handleGunBolt(Player player, ItemStack stack) {
if (stack.getOrCreateTag().getInt("bolt_action_time") > 0 && stack.getOrCreateTag().getInt("ammo") > (stack.is(ModTags.Items.REVOLVER) ? -1 : 0) && stack.getOrCreateTag().getInt("bolt_action_anim") == 0
if (GunsTool.getGunIntTag(stack, "BoltActionTime", 0) > 0 && stack.getOrCreateTag().getInt("ammo") > (stack.is(ModTags.Items.REVOLVER) ? -1 : 0) && stack.getOrCreateTag().getInt("bolt_action_anim") == 0
&& !(stack.getOrCreateTag().getBoolean("is_normal_reloading") || stack.getOrCreateTag().getBoolean("is_empty_reloading"))
&& !stack.getOrCreateTag().getBoolean("reloading")
&& !stack.getOrCreateTag().getBoolean("charging")) {
if (!player.getCooldowns().isOnCooldown(stack.getItem()) && stack.getOrCreateTag().getBoolean("need_bolt_action")) {
stack.getOrCreateTag().putInt("bolt_action_anim", stack.getOrCreateTag().getInt("bolt_action_time") + 1);
stack.getOrCreateTag().putInt("bolt_action_anim", GunsTool.getGunIntTag(stack, "BoltActionTime", 0) + 1);
GunEventHandler.playGunBoltSounds(player);
}
}

View file

@ -72,8 +72,8 @@ public class ShootMessage {
stack.getOrCreateTag().putBoolean("canImmediatelyShoot", false);
}
// 判断是否为栓动武器bolt_action_time > 0并在开火后给一个需要上膛的状态
if (stack.getOrCreateTag().getDouble("bolt_action_time") > 0 && stack.getOrCreateTag().getInt("ammo") > (stack.is(ModTags.Items.REVOLVER) ? 0 : 1)) {
// 判断是否为栓动武器BoltActionTime > 0并在开火后给一个需要上膛的状态
if (GunsTool.getGunIntTag(stack, "BoltActionTime", 0) > 0 && stack.getOrCreateTag().getInt("ammo") > (stack.is(ModTags.Items.REVOLVER) ? 0 : 1)) {
stack.getOrCreateTag().putBoolean("need_bolt_action", true);
}

View file

@ -56,7 +56,7 @@ public class GunsTool {
// TODO 临时使用移植完毕后删除
private static final Set<String> STRING_SET = Set.of("EmptyReloadTime", "FireMode", "Weight", "SoundRadius", "BurstSize", "ProjectileAmount",
"Spread", "NormalReloadTime", "Headshot", "Semi", "Burst", "Auto", "RecoilX", "RecoilY", "Velocity", "Damage", "BypassesArmor",
"RPM", "Magazine", "MinZoom", "MaxZoom", "CustomZoom", "ExplosionDamage", "ExplosionRadius");
"RPM", "Magazine", "MinZoom", "MaxZoom", "CustomZoom", "ExplosionDamage", "ExplosionRadius", "BoltActionTime");
public static void initGun(Level level, ItemStack stack, String location) {
if (level.getServer() == null) return;
@ -120,7 +120,7 @@ public class GunsTool {
int ammoToAdd = mag - ammo + (extraOne ? 1 : 0);
// 空仓换弹的栓动武器应该在换单后取消待上膛标记
if (ammo == 0 && tag.getDouble("bolt_action_time") > 0 && !stack.is(ModTags.Items.REVOLVER)) {
if (ammo == 0 && GunsTool.getGunIntTag(stack, "BoltActionTime", 0) > 0 && !stack.is(ModTags.Items.REVOLVER)) {
tag.putBoolean("need_bolt_action", false);
}

View file

@ -6,7 +6,7 @@
"Headshot": 3,
"Velocity": 37.75,
"Magazine": 5,
"bolt_action_time": 22,
"BoltActionTime": 22,
"Weight": 5,
"FireMode": 0,
"Semi": 1,

View file

@ -17,5 +17,5 @@
"finish_time": 12,
"BypassesArmor": 0.05,
"SoundRadius": 16,
"bolt_action_time": 11
"BoltActionTime": 11
}

View file

@ -1,7 +1,7 @@
{
"CustomZoom": 4.75,
"min_zoom": 4,
"max_zoom": 8,
"MinZoom": 4,
"MaxZoom": 8,
"Spread": 6,
"RecoilX": 0.007,
"RecoilY": 0.013,
@ -9,7 +9,7 @@
"Headshot": 3,
"Velocity": 47.2,
"Magazine": 5,
"bolt_action_time": 18,
"BoltActionTime": 18,
"Weight": 7,
"FireMode": 0,
"Semi": 1,

View file

@ -15,5 +15,5 @@
"finish_time": 19,
"BypassesArmor": 0.3,
"SoundRadius": 15,
"bolt_action_time": 12
"BoltActionTime": 12
}

View file

@ -7,7 +7,7 @@
"Headshot": 3,
"Velocity": 42,
"Magazine": 5,
"bolt_action_time": 22,
"BoltActionTime": 22,
"Weight": 5,
"FireMode": 0,
"Semi": 1,

View file

@ -7,7 +7,7 @@
"Headshot": 3,
"Velocity": 36,
"Magazine": 3,
"bolt_action_time": 37,
"BoltActionTime": 37,
"Weight": 10,
"FireMode": 0,
"Semi": 1,

View file

@ -7,7 +7,7 @@
"Magazine": 5,
"Headshot": 3,
"Velocity": 70,
"bolt_action_time": 22,
"BoltActionTime": 22,
"Weight": 7,
"FireMode": 0,
"Semi": 1,