优化NBT#CloseHammer Power HoldOpen

This commit is contained in:
17146 2025-01-04 00:57:34 +08:00
parent 7a8f24ac18
commit 5e17d423f5
4 changed files with 29 additions and 27 deletions

View file

@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.gun.launcher.RpgItem; import com.atsuishio.superbwarfare.item.gun.launcher.RpgItem;
import com.atsuishio.superbwarfare.tools.GunsTool;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
@ -43,7 +44,7 @@ public class RpgItemModel extends GeoModel<RpgItem> {
ItemStack stack = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
if (!stack.is(ModTags.Items.GUN)) return; if (!stack.is(ModTags.Items.GUN)) return;
if (stack.getOrCreateTag().getBoolean("close_hammer")) { if (GunsTool.getGunBooleanTag(stack, "CloseHammer")) {
hammer.setRotX(-90 * Mth.DEG_TO_RAD); hammer.setRotX(-90 * Mth.DEG_TO_RAD);
} }

View file

@ -334,7 +334,7 @@ public class GunEventHandler {
stack.getOrCreateTag().putBoolean("is_empty_reloading", true); stack.getOrCreateTag().putBoolean("is_empty_reloading", true);
playGunEmptyReloadSounds(player); playGunEmptyReloadSounds(player);
} }
GunsTool.setGunBooleanTag(stack, "StartReload", false); data.putBoolean("StartReload", false);
} }
if (data.getInt("ReloadTime") > 0) { if (data.getInt("ReloadTime") > 0) {
@ -346,19 +346,19 @@ public class GunEventHandler {
tag.putBoolean("empty", false); tag.putBoolean("empty", false);
} }
if (data.getInt("ReloadTime") == 7) { if (data.getInt("ReloadTime") == 7) {
tag.putBoolean("close_hammer", false); data.putBoolean("CloseHammer", false);
} }
} }
if (stack.getItem() == ModItems.MK_14.get()) { if (stack.getItem() == ModItems.MK_14.get()) {
if (data.getInt("ReloadTime") == 18) { if (data.getInt("ReloadTime") == 18) {
GunsTool.setGunBooleanTag(stack, "HoldOpen", false); data.putBoolean("HoldOpen", false);
} }
} }
if (stack.getItem() == ModItems.SKS.get()) { if (stack.getItem() == ModItems.SKS.get()) {
if (data.getInt("ReloadTime") == 14) { if (data.getInt("ReloadTime") == 14) {
GunsTool.setGunBooleanTag(stack, "HoldOpen", false); data.putBoolean("HoldOpen", false);
} }
} }
@ -370,13 +370,13 @@ public class GunEventHandler {
if (stack.getItem() == ModItems.GLOCK_17.get() || stack.getItem() == ModItems.GLOCK_18.get() || stack.getItem() == ModItems.M_1911.get()) { if (stack.getItem() == ModItems.GLOCK_17.get() || stack.getItem() == ModItems.GLOCK_18.get() || stack.getItem() == ModItems.M_1911.get()) {
if (data.getInt("ReloadTime") == 5) { if (data.getInt("ReloadTime") == 5) {
GunsTool.setGunBooleanTag(stack, "HoldOpen", false); data.putBoolean("HoldOpen", false);
} }
} }
if (stack.getItem() == ModItems.QBZ_95.get()) { if (stack.getItem() == ModItems.QBZ_95.get()) {
if (data.getInt("ReloadTime") == 14) { if (data.getInt("ReloadTime") == 14) {
GunsTool.setGunBooleanTag(stack, "HoldOpen", false); data.putBoolean("HoldOpen", false);
} }
} }
@ -390,7 +390,7 @@ public class GunEventHandler {
} else { } else {
playGunEmptyReload(player); playGunEmptyReload(player);
} }
GunsTool.setGunBooleanTag(stack, "StartReload", false); data.putBoolean("StartReload", false);
} }
stack.addTagElement("GunData", data); stack.addTagElement("GunData", data);

View file

@ -241,16 +241,16 @@ public class PlayerEventHandler {
} }
private static void handleBocekPulling(Player player) { private static void handleBocekPulling(Player player) {
ItemStack mainHandItem = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
CompoundTag tag = mainHandItem.getOrCreateTag(); CompoundTag tag = stack.getOrCreateTag();
if ((player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).bowPullHold) { if ((player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).bowPullHold) {
if (mainHandItem.getItem() == ModItems.BOCEK.get() if (stack.getItem() == ModItems.BOCEK.get()
&& tag.getInt("max_ammo") > 0 && tag.getInt("max_ammo") > 0
&& !player.getCooldowns().isOnCooldown(mainHandItem.getItem()) && !player.getCooldowns().isOnCooldown(stack.getItem())
&& tag.getDouble("power") < 12 && GunsTool.getGunDoubleTag(stack, "Power") < 12
) { ) {
tag.putDouble("power", tag.getDouble("power") + 1); GunsTool.setGunDoubleTag(stack, "Power", GunsTool.getGunDoubleTag(stack, "Power") + 1);
player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.bowPull = true; capability.bowPull = true;
@ -259,15 +259,15 @@ public class PlayerEventHandler {
}); });
player.setSprinting(false); player.setSprinting(false);
} }
if (tag.getDouble("power") == 1) { if (GunsTool.getGunDoubleTag(stack, "Power") == 1) {
if (!player.level().isClientSide() && player instanceof ServerPlayer serverPlayer) { if (!player.level().isClientSide() && player instanceof ServerPlayer serverPlayer) {
SoundTool.playLocalSound(serverPlayer, ModSounds.BOCEK_PULL_1P.get(), 2f, 1f); SoundTool.playLocalSound(serverPlayer, ModSounds.BOCEK_PULL_1P.get(), 2f, 1f);
player.level().playSound(null, player.blockPosition(), ModSounds.BOCEK_PULL_3P.get(), SoundSource.PLAYERS, 0.5f, 1); player.level().playSound(null, player.blockPosition(), ModSounds.BOCEK_PULL_3P.get(), SoundSource.PLAYERS, 0.5f, 1);
} }
} }
} else { } else {
if (mainHandItem.getItem() == ModItems.BOCEK.get()) { if (stack.getItem() == ModItems.BOCEK.get()) {
tag.putDouble("power", 0); GunsTool.setGunDoubleTag(stack, "Power", 0);
} }
player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.bowPull = false; capability.bowPull = false;
@ -275,7 +275,7 @@ public class PlayerEventHandler {
}); });
} }
if (tag.getDouble("power") > 0) { if (GunsTool.getGunDoubleTag(stack, "Power") > 0) {
player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.tacticalSprint = false; capability.tacticalSprint = false;
capability.syncPlayerVariables(player); capability.syncPlayerVariables(player);

View file

@ -182,8 +182,7 @@ public class FireMessage {
SoundTool.stopSound(serverPlayer, ModSounds.BOCEK_PULL_3P.getId(), SoundSource.PLAYERS); SoundTool.stopSound(serverPlayer, ModSounds.BOCEK_PULL_3P.getId(), SoundSource.PLAYERS);
} }
if (stack.getOrCreateTag().getDouble("power") >= 6) { if (GunsTool.getGunDoubleTag(stack, "Power") >= 6) {
stack.getOrCreateTag().putDouble("speed", stack.getOrCreateTag().getDouble("power"));
if ((player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).zoom) { if ((player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).zoom) {
spawnBullet(player); spawnBullet(player);
@ -206,9 +205,9 @@ public class FireMessage {
} }
} }
player.getCooldowns().addCooldown(player.getMainHandItem().getItem(), 7); player.getCooldowns().addCooldown(stack.getItem(), 7);
player.getMainHandItem().getOrCreateTag().putInt("arrow_empty", 7); stack.getOrCreateTag().putInt("arrow_empty", 7);
player.getMainHandItem().getOrCreateTag().putDouble("power", 0); GunsTool.setGunDoubleTag(stack, "Power", 0);
int count = 0; int count = 0;
for (var inv : player.getInventory().items) { for (var inv : player.getInventory().items) {
@ -234,7 +233,7 @@ public class FireMessage {
CompoundTag tag = stack.getOrCreateTag(); CompoundTag tag = stack.getOrCreateTag();
var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO); var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
float headshot = (float) GunsTool.getGunDoubleTag(stack, "Headshot", 0); float headshot = (float) GunsTool.getGunDoubleTag(stack, "Headshot", 0);
float velocity = 2 * (float) tag.getDouble("speed") * (float) perkSpeed(stack); float velocity = 2 * (float) GunsTool.getGunDoubleTag(stack, "Power", 6) * (float) perkSpeed(stack);
float bypassArmorRate = (float) GunsTool.getGunDoubleTag(stack, "BypassesArmor", 0); float bypassArmorRate = (float) GunsTool.getGunDoubleTag(stack, "BypassesArmor", 0);
double damage; double damage;
boolean zoom = player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).zoom; boolean zoom = player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).zoom;
@ -242,11 +241,13 @@ public class FireMessage {
float spread; float spread;
if ((player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).zoom) { if ((player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).zoom) {
spread = 0.01f; spread = 0.01f;
damage = 0.08333333 * GunsTool.getGunDoubleTag(stack, "Damage", 0) * tag.getDouble("speed") * perkDamage(stack); damage = 0.08333333 * GunsTool.getGunDoubleTag(stack, "Damage", 0) *
GunsTool.getGunDoubleTag(stack, "Power", 6) * perkDamage(stack);
} else { } else {
spread = perk instanceof AmmoPerk ammoPerk && ammoPerk.slug ? 0.5f : 2.5f; spread = perk instanceof AmmoPerk ammoPerk && ammoPerk.slug ? 0.5f : 2.5f;
damage = (perk instanceof AmmoPerk ammoPerk && ammoPerk.slug ? 0.08333333 : 0.008333333) * damage = (perk instanceof AmmoPerk ammoPerk && ammoPerk.slug ? 0.08333333 : 0.008333333) *
GunsTool.getGunDoubleTag(stack, "Damage", 0) * tag.getDouble("speed") * perkDamage(stack); GunsTool.getGunDoubleTag(stack, "Damage", 0) *
GunsTool.getGunDoubleTag(stack, "Power", 6) * perkDamage(stack);
} }
ProjectileEntity projectile = new ProjectileEntity(player.level()) ProjectileEntity projectile = new ProjectileEntity(player.level())
@ -443,7 +444,7 @@ public class FireMessage {
if (GunsTool.getGunIntTag(stack, "Ammo", 0) == 1) { if (GunsTool.getGunIntTag(stack, "Ammo", 0) == 1) {
tag.putBoolean("empty", true); tag.putBoolean("empty", true);
tag.putBoolean("close_hammer", true); GunsTool.setGunBooleanTag(stack, "CloseHammer", true);
} }
player.getCooldowns().addCooldown(stack.getItem(), 10); player.getCooldowns().addCooldown(stack.getItem(), 10);