优化NBT#Reloading Charging

This commit is contained in:
17146 2025-01-04 02:06:51 +08:00
parent ef1cedbf0a
commit 8c7b576699
14 changed files with 25 additions and 26 deletions

View file

@ -320,8 +320,8 @@ public class ClickHandler {
if (stack.getItem() instanceof GunItem gunItem && !(player.getVehicle() != null && player.getVehicle() instanceof ICannonEntity)) { if (stack.getItem() instanceof GunItem gunItem && !(player.getVehicle() != null && player.getVehicle() instanceof ICannonEntity)) {
if ((!(stack.getOrCreateTag().getBoolean("is_normal_reloading") || stack.getOrCreateTag().getBoolean("is_empty_reloading")) if ((!(stack.getOrCreateTag().getBoolean("is_normal_reloading") || stack.getOrCreateTag().getBoolean("is_empty_reloading"))
&& !stack.getOrCreateTag().getBoolean("reloading") && !GunsTool.getGunBooleanTag(stack, "Reloading")
&& !stack.getOrCreateTag().getBoolean("charging") && !GunsTool.getGunBooleanTag(stack, "Charging")
&& !GunsTool.getGunBooleanTag(stack, "NeedBoltAction", false)) && !GunsTool.getGunBooleanTag(stack, "NeedBoltAction", false))
&& cantFireTime == 0 && cantFireTime == 0
&& drawTime < 0.01 && drawTime < 0.01

View file

@ -14,7 +14,7 @@ public class PoseTool {
public static HumanoidModel.ArmPose pose(LivingEntity entityLiving, InteractionHand hand, ItemStack stack) { public static HumanoidModel.ArmPose pose(LivingEntity entityLiving, InteractionHand hand, ItemStack stack) {
if (stack.getOrCreateTag().getBoolean("is_empty_reloading") if (stack.getOrCreateTag().getBoolean("is_empty_reloading")
|| stack.getOrCreateTag().getBoolean("is_normal_reloading") || stack.getOrCreateTag().getBoolean("is_normal_reloading")
|| stack.getOrCreateTag().getBoolean("reloading") || GunsTool.getGunBooleanTag(stack, "Reloading")
|| GunsTool.getGunBooleanTag(stack, "Charging")) { || GunsTool.getGunBooleanTag(stack, "Charging")) {
return HumanoidModel.ArmPose.CROSSBOW_CHARGE; return HumanoidModel.ArmPose.CROSSBOW_CHARGE;
} else if (entityLiving.isSprinting() && entityLiving.onGround() && entityLiving.getPersistentData().getDouble("noRun") == 0) { } else if (entityLiving.isSprinting() && entityLiving.onGround() && entityLiving.getPersistentData().getDouble("noRun") == 0) {

View file

@ -107,7 +107,7 @@ public class K98ItemModel extends GeoModel<K98Item> {
float numR = (float) (1 - 0.52 * zt); float numR = (float) (1 - 0.52 * zt);
float numP = (float) (1 - 0.58 * zt); float numP = (float) (1 - 0.58 * zt);
if (GunsTool.getGunIntTag(stack, "ReloadTime") > 0 || stack.getOrCreateTag().getBoolean("reloading")) { if (GunsTool.getGunIntTag(stack, "ReloadTime") > 0 || GunsTool.getGunBooleanTag(stack, "Reloading")) {
main.setRotX(numR * main.getRotX()); main.setRotX(numR * main.getRotX());
main.setRotY(numR * main.getRotY()); main.setRotY(numR * main.getRotY());
main.setRotZ(numR * main.getRotZ()); main.setRotZ(numR * main.getRotZ());

View file

@ -5,6 +5,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.shotgun.M870Item; import com.atsuishio.superbwarfare.item.gun.shotgun.M870Item;
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;
@ -98,8 +99,7 @@ public class M870ItemModel extends GeoModel<M870Item> {
float numR = (float) (1 - 0.72 * zt); float numR = (float) (1 - 0.72 * zt);
float numP = (float) (1 - 0.82 * zt); float numP = (float) (1 - 0.82 * zt);
// TODO 修改本nbt if (GunsTool.getGunBooleanTag(stack, "Reloading")) {
if (stack.getOrCreateTag().getBoolean("reloading")) {
main.setRotX(numR * main.getRotX()); main.setRotX(numR * main.getRotX());
main.setRotY(numR * main.getRotY()); main.setRotY(numR * main.getRotY());
main.setRotZ(numR * main.getRotZ()); main.setRotZ(numR * main.getRotZ());

View file

@ -5,6 +5,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.rifle.MarlinItem; import com.atsuishio.superbwarfare.item.gun.rifle.MarlinItem;
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;
@ -99,8 +100,7 @@ public class MarlinItemModel extends GeoModel<MarlinItem> {
float numR = (float) (1 - 0.55 * zt); float numR = (float) (1 - 0.55 * zt);
float numP = (float) (1 - 0.88 * zt); float numP = (float) (1 - 0.88 * zt);
// TODO 修改本nbt if (GunsTool.getGunBooleanTag(stack, "Reloading")) {
if (stack.getOrCreateTag().getBoolean("reloading")) {
main.setRotX(numR * main.getRotX()); main.setRotX(numR * main.getRotX());
main.setRotY(numR * main.getRotY()); main.setRotY(numR * main.getRotY());
main.setRotZ(numR * main.getRotZ()); main.setRotZ(numR * main.getRotZ());

View file

@ -121,8 +121,7 @@ public class MosinNagantItemModel extends GeoModel<MosinNagantItem> {
float numR = (float) (1 - 0.97 * zt); float numR = (float) (1 - 0.97 * zt);
float numP = (float) (1 - 0.81 * zt); float numP = (float) (1 - 0.81 * zt);
// TODO 修改本nbt if (GunsTool.getGunBooleanTag(stack, "Reloading") || GunsTool.getGunIntTag(stack, "BoltActionTick") > 0) {
if (stack.getOrCreateTag().getBoolean("reloading") || GunsTool.getGunIntTag(stack, "BoltActionTick") > 0) {
main.setRotX(numR * main.getRotX()); main.setRotX(numR * main.getRotX());
main.setRotY(numR * main.getRotY()); main.setRotY(numR * main.getRotY());
main.setRotZ(numR * main.getRotZ()); main.setRotZ(numR * main.getRotZ());

View file

@ -348,8 +348,8 @@ public class ClientEventHandler {
&& !notInGame() && !notInGame()
&& !player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).edit && !player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).edit
&& (!(stack.getOrCreateTag().getBoolean("is_normal_reloading") || stack.getOrCreateTag().getBoolean("is_empty_reloading")) && (!(stack.getOrCreateTag().getBoolean("is_normal_reloading") || stack.getOrCreateTag().getBoolean("is_empty_reloading"))
&& !stack.getOrCreateTag().getBoolean("reloading") && !GunsTool.getGunBooleanTag(stack, "Reloading")
&& !stack.getOrCreateTag().getBoolean("charging") && !GunsTool.getGunBooleanTag(stack, "Charging")
&& GunsTool.getGunIntTag(stack, "Ammo", 0) > 0 && GunsTool.getGunIntTag(stack, "Ammo", 0) > 0
&& !player.getCooldowns().isOnCooldown(stack.getItem()) && !player.getCooldowns().isOnCooldown(stack.getItem())
&& !GunsTool.getGunBooleanTag(stack, "NeedBoltAction", false) && !GunsTool.getGunBooleanTag(stack, "NeedBoltAction", false)

View file

@ -542,7 +542,7 @@ public class GunEventHandler {
tag.putBoolean("force_stop", false); tag.putBoolean("force_stop", false);
tag.putBoolean("stop", false); tag.putBoolean("stop", false);
tag.putInt("reload_stage", 1); tag.putInt("reload_stage", 1);
tag.putBoolean("reloading", true); GunsTool.setGunBooleanTag(stack, "Reloading", true);
tag.putBoolean("start_single_reload", false); tag.putBoolean("start_single_reload", false);
} }
@ -661,7 +661,7 @@ public class GunEventHandler {
if (GunsTool.getGunIntTag(stack, "BoltActionTime", 0) > 0) { if (GunsTool.getGunIntTag(stack, "BoltActionTime", 0) > 0) {
GunsTool.setGunBooleanTag(stack, "NeedBoltAction", false); GunsTool.setGunBooleanTag(stack, "NeedBoltAction", false);
} }
tag.putBoolean("reloading", false); GunsTool.setGunBooleanTag(stack, "Reloading", false);
tag.putBoolean("start_single_reload", false); tag.putBoolean("start_single_reload", false);
MinecraftForge.EVENT_BUS.post(new ReloadEvent.Post(player, stack)); MinecraftForge.EVENT_BUS.post(new ReloadEvent.Post(player, stack));

View file

@ -343,7 +343,7 @@ public class LivingEventHandler {
oldTags.putBoolean("force_stop", false); oldTags.putBoolean("force_stop", false);
oldTags.putBoolean("stop", false); oldTags.putBoolean("stop", false);
oldTags.putInt("reload_stage", 0); oldTags.putInt("reload_stage", 0);
oldTags.putBoolean("reloading", false); data.putBoolean("Reloading", false);
oldTags.putDouble("prepare", 0); oldTags.putDouble("prepare", 0);
oldTags.putDouble("prepare_load", 0); oldTags.putDouble("prepare_load", 0);
oldTags.putDouble("iterative", 0); oldTags.putDouble("iterative", 0);
@ -378,7 +378,7 @@ public class LivingEventHandler {
newStack.getOrCreateTag().putBoolean("force_stop", false); newStack.getOrCreateTag().putBoolean("force_stop", false);
newStack.getOrCreateTag().putBoolean("stop", false); newStack.getOrCreateTag().putBoolean("stop", false);
newStack.getOrCreateTag().putInt("reload_stage", 0); newStack.getOrCreateTag().putInt("reload_stage", 0);
newStack.getOrCreateTag().putBoolean("reloading", false); GunsTool.setGunBooleanTag(newStack, "Reloading", false);
newStack.getOrCreateTag().putDouble("prepare", 0); newStack.getOrCreateTag().putDouble("prepare", 0);
newStack.getOrCreateTag().putDouble("prepare_load", 0); newStack.getOrCreateTag().putDouble("prepare_load", 0);
newStack.getOrCreateTag().putDouble("iterative", 0); newStack.getOrCreateTag().putDouble("iterative", 0);

View file

@ -111,7 +111,7 @@ public class MarlinItem extends GunItem implements GeoItem, AnimatedItem {
&& player.onGround() && player.onGround()
&& player.getPersistentData().getDouble("noRun") == 0 && player.getPersistentData().getDouble("noRun") == 0
&& ClientEventHandler.drawTime < 0.01 && ClientEventHandler.drawTime < 0.01
&& !stack.getOrCreateTag().getBoolean("reloading")) { && !GunsTool.getGunBooleanTag(stack, "Reloading")) {
if (player.hasEffect(MobEffects.MOVEMENT_SPEED)) { if (player.hasEffect(MobEffects.MOVEMENT_SPEED)) {
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.marlin.run_fast")); return event.setAndContinue(RawAnimation.begin().thenLoop("animation.marlin.run_fast"));
} else { } else {

View file

@ -116,7 +116,7 @@ public class M870Item extends GunItem implements GeoItem, AnimatedItem {
&& player.onGround() && player.onGround()
&& player.getPersistentData().getDouble("noRun") == 0 && player.getPersistentData().getDouble("noRun") == 0
&& ClientEventHandler.drawTime < 0.01 && ClientEventHandler.drawTime < 0.01
&& !stack.getOrCreateTag().getBoolean("reloading")) { && !GunsTool.getGunBooleanTag(stack, "Reloading")) {
if (player.hasEffect(MobEffects.MOVEMENT_SPEED)) { if (player.hasEffect(MobEffects.MOVEMENT_SPEED)) {
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.m870.run_fast")); return event.setAndContinue(RawAnimation.begin().thenLoop("animation.m870.run_fast"));
} else { } else {

View file

@ -113,7 +113,7 @@ public class K98Item extends GunItem implements GeoItem, AnimatedItem {
&& stack.getOrCreateTag().getInt("reload_stage") != 2 && stack.getOrCreateTag().getInt("reload_stage") != 2
&& stack.getOrCreateTag().getInt("reload_stage") != 3 && stack.getOrCreateTag().getInt("reload_stage") != 3
&& ClientEventHandler.drawTime < 0.01 && ClientEventHandler.drawTime < 0.01
&& !stack.getOrCreateTag().getBoolean("reloading")) { && !GunsTool.getGunBooleanTag(stack, "Reloading")) {
if (player.hasEffect(MobEffects.MOVEMENT_SPEED) && GunsTool.getGunIntTag(stack, "BoltActionTick") == 0) { if (player.hasEffect(MobEffects.MOVEMENT_SPEED) && GunsTool.getGunIntTag(stack, "BoltActionTick") == 0) {
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.k98.run_fast")); return event.setAndContinue(RawAnimation.begin().thenLoop("animation.k98.run_fast"));
} else { } else {

View file

@ -113,7 +113,7 @@ public class MosinNagantItem extends GunItem implements GeoItem, AnimatedItem {
&& stack.getOrCreateTag().getInt("reload_stage") != 2 && stack.getOrCreateTag().getInt("reload_stage") != 2
&& stack.getOrCreateTag().getInt("reload_stage") != 3 && stack.getOrCreateTag().getInt("reload_stage") != 3
&& ClientEventHandler.drawTime < 0.01 && ClientEventHandler.drawTime < 0.01
&& !stack.getOrCreateTag().getBoolean("reloading")) { && !GunsTool.getGunBooleanTag(stack, "Reloading")) {
if (player.hasEffect(MobEffects.MOVEMENT_SPEED) && GunsTool.getGunIntTag(stack, "BoltActionTick") == 0) { if (player.hasEffect(MobEffects.MOVEMENT_SPEED) && GunsTool.getGunIntTag(stack, "BoltActionTick") == 0) {
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.mosin.run_fast")); return event.setAndContinue(RawAnimation.begin().thenLoop("animation.mosin.run_fast"));
} else { } else {

View file

@ -130,7 +130,7 @@ public class FireMessage {
} }
} }
if (tag.getDouble("prepare") == 0 && tag.getBoolean("reloading") && GunsTool.getGunIntTag(stack, "Ammo", 0) > 0) { if (tag.getDouble("prepare") == 0 && GunsTool.getGunBooleanTag(stack, "Reloading") && GunsTool.getGunIntTag(stack, "Ammo", 0) > 0) {
tag.putDouble("force_stop", 1); tag.putDouble("force_stop", 1);
} }
@ -146,8 +146,8 @@ public class FireMessage {
if (GunsTool.getGunIntTag(stack, "BoltActionTime", 0) > 0 && GunsTool.getGunIntTag(stack, "Ammo", 0) > (stack.is(ModTags.Items.REVOLVER) ? -1 : 0) if (GunsTool.getGunIntTag(stack, "BoltActionTime", 0) > 0 && GunsTool.getGunIntTag(stack, "Ammo", 0) > (stack.is(ModTags.Items.REVOLVER) ? -1 : 0)
&& GunsTool.getGunIntTag(stack, "BoltActionTick") == 0 && GunsTool.getGunIntTag(stack, "BoltActionTick") == 0
&& !(stack.getOrCreateTag().getBoolean("is_normal_reloading") || stack.getOrCreateTag().getBoolean("is_empty_reloading")) && !(stack.getOrCreateTag().getBoolean("is_normal_reloading") || stack.getOrCreateTag().getBoolean("is_empty_reloading"))
&& !stack.getOrCreateTag().getBoolean("reloading") && !GunsTool.getGunBooleanTag(stack, "Reloading")
&& !stack.getOrCreateTag().getBoolean("charging")) { && !GunsTool.getGunBooleanTag(stack, "Charging")) {
if (!player.getCooldowns().isOnCooldown(stack.getItem()) && GunsTool.getGunBooleanTag(stack, "NeedBoltAction", false)) { if (!player.getCooldowns().isOnCooldown(stack.getItem()) && GunsTool.getGunBooleanTag(stack, "NeedBoltAction", false)) {
GunsTool.setGunIntTag(stack, "BoltActionTick", GunsTool.getGunIntTag(stack, "BoltActionTime", 0) + 1); GunsTool.setGunIntTag(stack, "BoltActionTick", GunsTool.getGunIntTag(stack, "BoltActionTime", 0) + 1);
GunEventHandler.playGunBoltSounds(player); GunEventHandler.playGunBoltSounds(player);
@ -307,7 +307,7 @@ public class FireMessage {
if (player.isSpectator()) return; if (player.isSpectator()) return;
ItemStack stack = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
if (!stack.getOrCreateTag().getBoolean("reloading")) { if (!GunsTool.getGunBooleanTag(stack, "Reloading")) {
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.VOLT_OVERLOAD.get(), stack); int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.VOLT_OVERLOAD.get(), stack);
AtomicBoolean flag = new AtomicBoolean(false); AtomicBoolean flag = new AtomicBoolean(false);
stack.getCapability(ForgeCapabilities.ENERGY).ifPresent( stack.getCapability(ForgeCapabilities.ENERGY).ifPresent(
@ -357,7 +357,7 @@ public class FireMessage {
if (player.isSpectator()) return; if (player.isSpectator()) return;
ItemStack stack = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
if (!stack.getOrCreateTag().getBoolean("reloading")) { if (!GunsTool.getGunBooleanTag(stack, "Reloading")) {
if (!player.getCooldowns().isOnCooldown(stack.getItem()) && GunsTool.getGunIntTag(stack, "Ammo", 0) > 0) { if (!player.getCooldowns().isOnCooldown(stack.getItem()) && GunsTool.getGunIntTag(stack, "Ammo", 0) > 0) {
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;
double spread = GunsTool.getGunDoubleTag(stack, "Spread"); double spread = GunsTool.getGunDoubleTag(stack, "Spread");
@ -412,7 +412,7 @@ public class FireMessage {
ItemStack stack = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
CompoundTag tag = stack.getOrCreateTag(); CompoundTag tag = stack.getOrCreateTag();
if (!tag.getBoolean("reloading") && !player.getCooldowns().isOnCooldown(stack.getItem()) && GunsTool.getGunIntTag(stack, "Ammo", 0) > 0) { if (!GunsTool.getGunBooleanTag(stack, "Reloading") && !player.getCooldowns().isOnCooldown(stack.getItem()) && GunsTool.getGunIntTag(stack, "Ammo", 0) > 0) {
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;
double spread = GunsTool.getGunDoubleTag(stack, "Spread"); double spread = GunsTool.getGunDoubleTag(stack, "Spread");