优化NBT#RPM

This commit is contained in:
17146 2024-12-24 15:56:04 +08:00
parent 46f9428889
commit 2668a19e72
25 changed files with 48 additions and 47 deletions

View file

@ -4,6 +4,7 @@ import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.gun.machinegun.MinigunItem;
import com.atsuishio.superbwarfare.tools.GunsTool;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
@ -56,7 +57,7 @@ public class MinigunItemModel extends GeoModel<MinigunItem> {
double fp = ClientEventHandler.firePos;
double fr = ClientEventHandler.fireRot;
int rpm = stack.getOrCreateTag().getInt("rpm");
int rpm = GunsTool.getGunIntTag(stack, "RPM", 0);
gun.setRotZ(gun.getRotZ() + times * -0.07f * ((float) rpm / 1200) * ClientEventHandler.miniGunRot);

View file

@ -1,14 +1,14 @@
package com.atsuishio.superbwarfare.client.screens;
import com.atsuishio.superbwarfare.init.ModKeyMappings;
import com.atsuishio.superbwarfare.network.ModVariables;
import com.atsuishio.superbwarfare.tools.GunsTool;
import com.mojang.blaze3d.vertex.PoseStack;
import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.config.client.DisplayConfig;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModKeyMappings;
import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.gun.GunItem;
import com.atsuishio.superbwarfare.network.ModVariables;
import com.atsuishio.superbwarfare.tools.GunsTool;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
@ -95,7 +95,7 @@ public class AmmoBarOverlay {
// 渲染加特林射速
event.getGuiGraphics().drawString(
Minecraft.getInstance().font,
stack.getOrCreateTag().getInt("rpm") + " RPM",
GunsTool.getGunIntTag(stack, "RPM", 0) + " RPM",
w - 111f,
h - 20,
0xFFFFFF,

View file

@ -105,7 +105,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
} else {
return Component.translatable("des.superbwarfare.tips.rpm").withStyle(ChatFormatting.GRAY)
.append(Component.literal("").withStyle(ChatFormatting.RESET))
.append(Component.literal(new DecimalFormat("##").format(ItemNBTTool.getDouble(stack, "rpm", 0) + ItemNBTTool.getDouble(stack, "customRpm", 0)))
.append(Component.literal(new DecimalFormat("##").format(GunsTool.getGunIntTag(stack, "RPM", 0) + ItemNBTTool.getDouble(stack, "customRpm", 0)))
.withStyle(ChatFormatting.GREEN));
}
}

View file

@ -192,14 +192,10 @@ public class ClientEventHandler {
return;
}
ItemStack stack = player.getMainHandItem();
if (stack.getItem() == ModItems.MINIGUN.get()) {
if (stack.is(ModItems.MINIGUN.get())) {
if (holdFire || zoom) {
miniGunRot = Math.min(miniGunRot + 5, 21);
float rpm = 1;
if (player.getMainHandItem().is(ModItems.MINIGUN.get())) {
rpm = (float) player.getMainHandItem().getOrCreateTag().getInt("rpm") / 3600;
}
float rpm = (float) GunsTool.getGunIntTag(stack, "RPM", 0) / 3600;
player.playSound(ModSounds.MINIGUN_ROT.get(), 1, 0.7f + rpm);
}
}
@ -269,7 +265,7 @@ public class ClientEventHandler {
cantFireTime = Mth.clamp(cantFireTime - 6 * speed * times, 0, 40);
}
int rpm = (int) (stack.getOrCreateTag().getDouble("rpm") + customRpm);
int rpm = GunsTool.getGunIntTag(stack, "RPM", 0) + customRpm;
if (rpm == 0) {
rpm = 600;
}
@ -900,8 +896,8 @@ public class ClientEventHandler {
double rpm = 1;
if (entity.getMainHandItem().is(ModItems.MINIGUN.get())) {
rpm = (double) entity.getMainHandItem().getOrCreateTag().getInt("rpm") / 1800;
if (stack.is(ModItems.MINIGUN.get())) {
rpm = (double) GunsTool.getGunIntTag(stack, "RPM", 0) / 1800;
}
float[] shake = {0, 0};
@ -991,7 +987,7 @@ public class ClientEventHandler {
double rpm = 1;
if (stack.is(ModItems.MINIGUN.get())) {
rpm = (double) stack.getOrCreateTag().getInt("rpm") / 1800;
rpm = (double) GunsTool.getGunIntTag(stack, "RPM", 0) / 1800;
}
float gunRecoilX = (float) GunsTool.getGunDoubleTag(stack, "RecoilX", 0) * 60;

View file

@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.network.message;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.tools.GunsTool;
import com.atsuishio.superbwarfare.tools.SoundTool;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
@ -11,6 +12,7 @@ import net.minecraft.util.Mth;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.network.NetworkEvent;
import java.text.DecimalFormat;
import java.util.function.Supplier;
public class AdjustZoomFovMessage {
@ -45,20 +47,21 @@ public class AdjustZoomFovMessage {
double minRpm = 300;
double maxRpm = 2400;
tag.putInt("rpm", (int) Mth.clamp(tag.getInt("rpm") + 50 * message.scroll, minRpm, maxRpm));
if (tag.getInt("rpm") == 1150) {
tag.putInt("rpm", 1145);
GunsTool.setGunIntTag(stack, "RPM", (int) Mth.clamp(GunsTool.getGunIntTag(stack, "RPM", 0) + 50 * message.scroll, minRpm, maxRpm));
if (GunsTool.getGunIntTag(stack, "RPM", 0) == 1150) {
GunsTool.setGunIntTag(stack, "RPM", 1145);
}
if (tag.getInt("rpm") == 1195) {
tag.putInt("rpm", 1200);
if (GunsTool.getGunIntTag(stack, "RPM", 0) == 1195) {
GunsTool.setGunIntTag(stack, "RPM", 1200);
}
if (tag.getInt("rpm") == 1095) {
tag.putInt("rpm", 1100);
if (GunsTool.getGunIntTag(stack, "RPM", 0) == 1095) {
GunsTool.setGunIntTag(stack, "RPM", 1100);
}
player.displayClientMessage(Component.literal("Rpm:" + new java.text.DecimalFormat("##").format(tag.getInt("rpm"))), true);
if (tag.getInt("rpm") > minRpm && tag.getInt("rpm") < maxRpm) {
player.displayClientMessage(Component.literal("RPM: " + new DecimalFormat("##").format(GunsTool.getGunIntTag(stack, "RPM", 0))), true);
int rpm = GunsTool.getGunIntTag(stack, "RPM", 0);
if (rpm > minRpm && rpm < maxRpm) {
SoundTool.playLocalSound(player, ModSounds.ADJUST_FOV.get(), 1f, 0.7f);
}
} else {

View file

@ -55,7 +55,8 @@ 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");
"Spread", "NormalReloadTime", "Headshot", "Semi", "Burst", "Auto", "RecoilX", "RecoilY", "Velocity", "Damage", "BypassesArmor",
"RPM");
public static void initGun(Level level, ItemStack stack, String location) {
if (level.getServer() == null) return;

View file

@ -15,5 +15,5 @@
"EmptyReloadTime": 85,
"BypassesArmor": 0.05,
"SoundRadius": 18,
"rpm": 360
"RPM": 360
}

View file

@ -14,5 +14,5 @@
"EmptyReloadTime": 83,
"BypassesArmor": 0.01,
"SoundRadius": 16,
"rpm": 600
"RPM": 600
}

View file

@ -16,5 +16,5 @@
"EmptyReloadTime": 58,
"BypassesArmor": 0.23,
"SoundRadius": 12,
"rpm": 700
"RPM": 700
}

View file

@ -16,5 +16,5 @@
"EmptyReloadTime": 65,
"BypassesArmor": 0.2,
"SoundRadius": 14,
"rpm": 600
"RPM": 600
}

View file

@ -14,5 +14,5 @@
"EmptyReloadTime": 95,
"BypassesArmor": 0.25,
"SoundRadius": 13,
"rpm": 400
"RPM": 400
}

View file

@ -13,5 +13,5 @@
"EmptyReloadTime": 35,
"BypassesArmor": 0.15,
"SoundRadius": 8,
"rpm": 400
"RPM": 400
}

View file

@ -14,5 +14,5 @@
"EmptyReloadTime": 35,
"BypassesArmor": 0.15,
"SoundRadius": 8,
"rpm": 1300
"RPM": 1300
}

View file

@ -16,5 +16,5 @@
"EmptyReloadTime": 64,
"BypassesArmor": 0.25,
"SoundRadius": 14,
"rpm": 900
"RPM": 900
}

View file

@ -13,5 +13,5 @@
"EmptyReloadTime": 35,
"BypassesArmor": 0.2,
"SoundRadius": 10,
"rpm": 400
"RPM": 400
}

View file

@ -16,5 +16,5 @@
"EmptyReloadTime": 64,
"BypassesArmor": 0.25,
"SoundRadius": 14,
"rpm": 850
"RPM": 850
}

View file

@ -13,5 +13,5 @@
"EmptyReloadTime": 133,
"BypassesArmor": 0.25,
"SoundRadius": 15,
"rpm": 600
"RPM": 600
}

View file

@ -9,5 +9,5 @@
"FireMode": 2,
"BypassesArmor": 0.3,
"SoundRadius": 14,
"rpm": 1200
"RPM": 1200
}

View file

@ -16,5 +16,5 @@
"EmptyReloadTime": 71,
"BypassesArmor": 0.4,
"SoundRadius": 16,
"rpm": 700
"RPM": 700
}

View file

@ -16,5 +16,5 @@
"EmptyReloadTime": 74,
"BypassesArmor": 0.28,
"SoundRadius": 13,
"rpm": 650
"RPM": 650
}

View file

@ -14,5 +14,5 @@
"EmptyReloadTime": 95,
"BypassesArmor": 0.23,
"SoundRadius": 14,
"rpm": 600
"RPM": 600
}

View file

@ -13,5 +13,5 @@
"EmptyReloadTime": 75,
"BypassesArmor": 0.23,
"SoundRadius": 16,
"rpm": 400
"RPM": 400
}

View file

@ -14,5 +14,5 @@
"EmptyReloadTime": 70,
"BypassesArmor": 0.45,
"SoundRadius": 17,
"rpm": 300
"RPM": 300
}

View file

@ -12,5 +12,5 @@
"EmptyReloadTime": 65,
"BypassesArmor": 0.3,
"SoundRadius": 10,
"rpm": 240
"RPM": 240
}

View file

@ -16,5 +16,5 @@
"EmptyReloadTime": 64,
"BypassesArmor": 0.15,
"SoundRadius": 11,
"rpm": 1200
"RPM": 1200
}