优化武器数据读取、同步和初始化方式

This commit is contained in:
Light_Quanta 2025-04-03 04:38:51 +08:00
parent 60f79e9f62
commit 1da96065fc
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
67 changed files with 285 additions and 565 deletions

View file

@ -164,7 +164,7 @@ public class ClickHandler {
var tag = NBTTool.getTag(stack); var tag = NBTTool.getTag(stack);
if (stack.is(ModTags.Items.GUN) && ClientEventHandler.zoom) { if (stack.is(ModTags.Items.GUN) && ClientEventHandler.zoom) {
if (GunsTool.getGunBooleanTag(tag, "CanSwitchScope", false)) { if (GunsTool.getGunBooleanTag(tag, "CanSwitchScope")) {
PacketDistributor.sendToServer(new SwitchScopeMessage(scroll)); PacketDistributor.sendToServer(new SwitchScopeMessage(scroll));
} else if (tag.getBoolean("CanAdjustZoomFov") || stack.is(ModItems.MINIGUN.get())) { } else if (tag.getBoolean("CanAdjustZoomFov") || stack.is(ModItems.MINIGUN.get())) {
PacketDistributor.sendToServer(new AdjustZoomFovMessage(scroll)); PacketDistributor.sendToServer(new AdjustZoomFovMessage(scroll));
@ -323,7 +323,7 @@ public class ClickHandler {
&& (!(tag.getBoolean("is_normal_reloading") || tag.getBoolean("is_empty_reloading")) && (!(tag.getBoolean("is_normal_reloading") || tag.getBoolean("is_empty_reloading"))
&& !GunsTool.getGunBooleanTag(tag, "Reloading") && !GunsTool.getGunBooleanTag(tag, "Reloading")
&& !GunsTool.getGunBooleanTag(tag, "Charging") && !GunsTool.getGunBooleanTag(tag, "Charging")
&& !GunsTool.getGunBooleanTag(tag, "NeedBoltAction", false)) && !GunsTool.getGunBooleanTag(tag, "NeedBoltAction"))
&& cantFireTime == 0 && cantFireTime == 0
&& drawTime < 0.01 && drawTime < 0.01
&& !notInGame() && !notInGame()
@ -331,14 +331,14 @@ public class ClickHandler {
if ((!(tag.getBoolean("is_normal_reloading") || tag.getBoolean("is_empty_reloading")) if ((!(tag.getBoolean("is_normal_reloading") || tag.getBoolean("is_empty_reloading"))
&& !GunsTool.getGunBooleanTag(tag, "Reloading") && !GunsTool.getGunBooleanTag(tag, "Reloading")
&& !GunsTool.getGunBooleanTag(tag, "Charging") && !GunsTool.getGunBooleanTag(tag, "Charging")
&& !GunsTool.getGunBooleanTag(tag, "NeedBoltAction", false)) && !GunsTool.getGunBooleanTag(tag, "NeedBoltAction"))
&& cantFireTime == 0 && cantFireTime == 0
&& drawTime < 0.01 && drawTime < 0.01
&& !notInGame()) { && !notInGame()) {
player.playSound(ModSounds.TRIGGER_CLICK.get(), 1, 1); player.playSound(ModSounds.TRIGGER_CLICK.get(), 1, 1);
} }
if (!gunItem.useBackpackAmmo(stack) && GunsTool.getGunIntTag(tag, "Ammo", 0) <= 0 && GunsTool.getGunIntTag(tag, "ReloadTime") == 0) { if (!gunItem.useBackpackAmmo(stack) && GunsTool.getGunIntTag(tag, "Ammo") <= 0 && GunsTool.getGunIntTag(tag, "ReloadTime") == 0) {
if (ReloadConfig.LEFT_CLICK_RELOAD.get()) { if (ReloadConfig.LEFT_CLICK_RELOAD.get()) {
PacketDistributor.sendToServer(new ReloadMessage(0)); PacketDistributor.sendToServer(new ReloadMessage(0));
ClientEventHandler.burstFireSize = 0; ClientEventHandler.burstFireSize = 0;
@ -347,7 +347,7 @@ public class ClickHandler {
PacketDistributor.sendToServer(new FireMessage(0)); PacketDistributor.sendToServer(new FireMessage(0));
if (GunsTool.getGunIntTag(tag, "FireMode") == 1) { if (GunsTool.getGunIntTag(tag, "FireMode") == 1) {
if (ClientEventHandler.burstFireSize == 0) { if (ClientEventHandler.burstFireSize == 0) {
ClientEventHandler.burstFireSize = GunsTool.getGunIntTag(tag, "BurstSize", 1); ClientEventHandler.burstFireSize = GunsTool.getGunIntTag(tag, "BurstSize");
} }
} else { } else {
if (!stack.is(ModItems.BOCEK.get())) { if (!stack.is(ModItems.BOCEK.get())) {

View file

@ -45,7 +45,7 @@ public class K98ItemModel extends GeoModel<K98Item> {
if (!stack.is(ModTags.Items.GUN)) return; if (!stack.is(ModTags.Items.GUN)) return;
final var tag = NBTTool.getTag(stack); final var tag = NBTTool.getTag(stack);
if (NBTTool.getTag(stack).getDouble("prepare") > 11 && GunsTool.getGunIntTag(tag, "Ammo", 0) == 1) { if (NBTTool.getTag(stack).getDouble("prepare") > 11 && GunsTool.getGunIntTag(tag, "Ammo") == 1) {
clip.setScaleX(0); clip.setScaleX(0);
clip.setScaleY(0); clip.setScaleY(0);
clip.setScaleZ(0); clip.setScaleZ(0);

View file

@ -60,7 +60,7 @@ public class M60ItemModel extends GeoModel<M60Item> {
} }
final var tag = NBTTool.getTag(stack); final var tag = NBTTool.getTag(stack);
int ammo = GunsTool.getGunIntTag(tag, "Ammo", 0); int ammo = GunsTool.getGunIntTag(tag, "Ammo");
boolean flag = GunsTool.getGunBooleanTag(tag, "HideBulletChain"); boolean flag = GunsTool.getGunBooleanTag(tag, "HideBulletChain");
if (ammo < 5 && flag) { if (ammo < 5 && flag) {

View file

@ -60,7 +60,7 @@ public class MinigunItemModel extends GeoModel<MinigunItem> {
double fr = ClientEventHandler.fireRot; double fr = ClientEventHandler.fireRot;
final var tag = NBTTool.getTag(stack); final var tag = NBTTool.getTag(stack);
int rpm = GunsTool.getGunIntTag(tag, "RPM", 0); int rpm = GunsTool.getGunIntTag(tag, "RPM");
gun.setRotZ(gun.getRotZ() + times * -0.07f * ((float) rpm / 1200) * ClientEventHandler.miniGunRot); gun.setRotZ(gun.getRotZ() + times * -0.07f * ((float) rpm / 1200) * ClientEventHandler.miniGunRot);

View file

@ -107,8 +107,8 @@ public class SentinelItemModel extends GeoModel<SentinelItem> {
root.setRotY((float) (0.2f * movePosX + Mth.DEG_TO_RAD * 300 * ClientEventHandler.drawTime + Mth.DEG_TO_RAD * turnRotY)); root.setRotY((float) (0.2f * movePosX + Mth.DEG_TO_RAD * 300 * ClientEventHandler.drawTime + Mth.DEG_TO_RAD * turnRotY));
root.setRotZ((float) (0.2f * movePosX + moveRotZ + Mth.DEG_TO_RAD * 90 * ClientEventHandler.drawTime + 2.7f * mph + Mth.DEG_TO_RAD * turnRotZ)); root.setRotZ((float) (0.2f * movePosX + moveRotZ + Mth.DEG_TO_RAD * 90 * ClientEventHandler.drawTime + 2.7f * mph + Mth.DEG_TO_RAD * turnRotZ));
if (GunsTool.getGunIntTag(tag, "Ammo", 0) <= 5) { if (GunsTool.getGunIntTag(tag, "Ammo") <= 5) {
ammo.setScaleX((float) GunsTool.getGunIntTag(tag, "Ammo", 0) / 5); ammo.setScaleX((float) GunsTool.getGunIntTag(tag, "Ammo") / 5);
} }
GeoBone camera = getAnimationProcessor().getBone("camera"); GeoBone camera = getAnimationProcessor().getBone("camera");

View file

@ -100,7 +100,7 @@ public class AmmoBarOverlay {
// 渲染加特林射速 // 渲染加特林射速
event.getGuiGraphics().drawString( event.getGuiGraphics().drawString(
Minecraft.getInstance().font, Minecraft.getInstance().font,
GunsTool.getGunIntTag(tag, "RPM", 0) + " RPM", GunsTool.getGunIntTag(tag, "RPM") + " RPM",
w - 111f, w - 111f,
h - 20, h - 20,
0xFFFFFF, 0xFFFFFF,
@ -410,7 +410,7 @@ public class AmmoBarOverlay {
return GunsTool.getGunIntTag(tag, "MaxAmmo"); return GunsTool.getGunIntTag(tag, "MaxAmmo");
} }
return GunsTool.getGunIntTag(tag, "Ammo", 0); return GunsTool.getGunIntTag(tag, "Ammo");
} }
private static String getPlayerAmmoCount(Player player) { private static String getPlayerAmmoCount(Player player) {

View file

@ -78,7 +78,7 @@ public class JavelinHudOverlay {
float j1 = l + j; float j1 = l + j;
preciseBlit(event.getGuiGraphics(), Mod.loc("textures/screens/javelin/javelin_hud.png"), k, l, 0, 0.0F, i, j, i, j); preciseBlit(event.getGuiGraphics(), Mod.loc("textures/screens/javelin/javelin_hud.png"), k, l, 0, 0.0F, i, j, i, j);
preciseBlit(event.getGuiGraphics(), Mod.loc(tag.getBoolean("TopMode") ? "textures/screens/javelin/top.png" : "textures/screens/javelin/dir.png"), k, l, 0, 0.0F, i, j, i, j); preciseBlit(event.getGuiGraphics(), Mod.loc(tag.getBoolean("TopMode") ? "textures/screens/javelin/top.png" : "textures/screens/javelin/dir.png"), k, l, 0, 0.0F, i, j, i, j);
preciseBlit(event.getGuiGraphics(), Mod.loc(GunsTool.getGunIntTag(tag, "Ammo", 0) > 0 ? "textures/screens/javelin/missile_green.png" : "textures/screens/javelin/missile_red.png"), k, l, 0, 0.0F, i, j, i, j); preciseBlit(event.getGuiGraphics(), Mod.loc(GunsTool.getGunIntTag(tag, "Ammo") > 0 ? "textures/screens/javelin/missile_green.png" : "textures/screens/javelin/missile_red.png"), k, l, 0, 0.0F, i, j, i, j);
if (tag.getInt("SeekTime") > 1 && tag.getInt("SeekTime") < 20) { if (tag.getInt("SeekTime") > 1 && tag.getInt("SeekTime") < 20) {
preciseBlit(event.getGuiGraphics(), Mod.loc("textures/screens/javelin/seek.png"), k, l, 0, 0.0F, i, j, i, j); preciseBlit(event.getGuiGraphics(), Mod.loc("textures/screens/javelin/seek.png"), k, l, 0, 0.0F, i, j, i, j);
} }

View file

@ -25,7 +25,7 @@ public class ClientBocekImageTooltip extends ClientGunImageTooltip {
slug = true; slug = true;
} }
double total = GunsTool.getGunDoubleTag(tag, "Damage", 0) * TooltipTool.perkDamage(stack); double total = GunsTool.getGunDoubleTag(tag, "Damage") * TooltipTool.perkDamage(stack);
if (slug) { if (slug) {
return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY) return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY)

View file

@ -65,7 +65,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
} }
protected boolean shouldRenderBypassAndHeadshotTooltip() { protected boolean shouldRenderBypassAndHeadshotTooltip() {
return GunsTool.getGunDoubleTag(tag, "BypassesArmor", 0) > 0 || GunsTool.getGunDoubleTag(tag, "Headshot", 0) > 0; return GunsTool.getGunDoubleTag(tag, "BypassesArmor") > 0 || GunsTool.getGunDoubleTag(tag, "Headshot") > 0;
} }
protected boolean shouldRenderEditTooltip() { protected boolean shouldRenderEditTooltip() {
@ -92,7 +92,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
* 获取武器伤害的文本组件 * 获取武器伤害的文本组件
*/ */
protected Component getDamageComponent() { protected Component getDamageComponent() {
double damage = GunsTool.getGunDoubleTag(tag, "Damage", 0) * TooltipTool.perkDamage(stack); double damage = GunsTool.getGunDoubleTag(tag, "Damage") * TooltipTool.perkDamage(stack);
return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY) return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY)
.append(Component.literal("").withStyle(ChatFormatting.RESET)) .append(Component.literal("").withStyle(ChatFormatting.RESET))
.append(Component.literal(FormatTool.format1D(damage) + (TooltipTool.heBullet(stack) ? " + " .append(Component.literal(FormatTool.format1D(damage) + (TooltipTool.heBullet(stack) ? " + "
@ -106,7 +106,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
if (this.stack.getItem() instanceof GunItem gunItem && gunItem.isAutoWeapon(this.stack)) { if (this.stack.getItem() instanceof GunItem gunItem && gunItem.isAutoWeapon(this.stack)) {
return Component.translatable("des.superbwarfare.guns.rpm").withStyle(ChatFormatting.GRAY) return Component.translatable("des.superbwarfare.guns.rpm").withStyle(ChatFormatting.GRAY)
.append(Component.literal("").withStyle(ChatFormatting.RESET)) .append(Component.literal("").withStyle(ChatFormatting.RESET))
.append(Component.literal(FormatTool.format0D(GunsTool.getGunIntTag(tag, "RPM", 0))) .append(Component.literal(FormatTool.format0D(GunsTool.getGunIntTag(tag, "RPM")))
.withStyle(ChatFormatting.GREEN)); .withStyle(ChatFormatting.GREEN));
} }
return Component.literal(""); return Component.literal("");
@ -125,8 +125,8 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
* 获取武器等级文本组件 * 获取武器等级文本组件
*/ */
protected Component getLevelComponent() { protected Component getLevelComponent() {
int level = GunsTool.getGunIntTag(tag, "Level", 0); int level = GunsTool.getGunIntTag(tag, "Level");
double rate = GunsTool.getGunDoubleTag(tag, "Exp", 0) / (20 * Math.pow(level, 2) + 160 * level + 20); double rate = GunsTool.getGunDoubleTag(tag, "Exp") / (20 * Math.pow(level, 2) + 160 * level + 20);
ChatFormatting formatting; ChatFormatting formatting;
if (level < 10) { if (level < 10) {
@ -152,7 +152,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
* 获取武器强化点数文本组件 * 获取武器强化点数文本组件
*/ */
protected Component getUpgradePointComponent() { protected Component getUpgradePointComponent() {
int upgradePoint = Mth.floor(GunsTool.getGunDoubleTag(tag, "UpgradePoint", 0)); int upgradePoint = Mth.floor(GunsTool.getGunDoubleTag(tag, "UpgradePoint"));
return Component.translatable("des.superbwarfare.guns.upgrade_point").withStyle(ChatFormatting.GRAY) return Component.translatable("des.superbwarfare.guns.upgrade_point").withStyle(ChatFormatting.GRAY)
.append(Component.literal("").withStyle(ChatFormatting.RESET)) .append(Component.literal("").withStyle(ChatFormatting.RESET))
.append(Component.literal(String.valueOf(upgradePoint)).withStyle(ChatFormatting.WHITE).withStyle(ChatFormatting.BOLD)); .append(Component.literal(String.valueOf(upgradePoint)).withStyle(ChatFormatting.WHITE).withStyle(ChatFormatting.BOLD));
@ -178,7 +178,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
int level = PerkHelper.getItemPerkLevel(perk, tag); int level = PerkHelper.getItemPerkLevel(perk, tag);
perkBypassArmorRate = ammoPerk.bypassArmorRate + (perk == ModPerks.AP_BULLET.get() ? 0.05f * (level - 1) : 0); perkBypassArmorRate = ammoPerk.bypassArmorRate + (perk == ModPerks.AP_BULLET.get() ? 0.05f * (level - 1) : 0);
} }
double bypassRate = Math.max(GunsTool.getGunDoubleTag(tag, "BypassesArmor", 0) + perkBypassArmorRate, 0); double bypassRate = Math.max(GunsTool.getGunDoubleTag(tag, "BypassesArmor") + perkBypassArmorRate, 0);
return Component.translatable("des.superbwarfare.guns.bypass").withStyle(ChatFormatting.GRAY) return Component.translatable("des.superbwarfare.guns.bypass").withStyle(ChatFormatting.GRAY)
.append(Component.literal("").withStyle(ChatFormatting.RESET)) .append(Component.literal("").withStyle(ChatFormatting.RESET))
@ -189,7 +189,7 @@ public class ClientGunImageTooltip implements ClientTooltipComponent {
* 获取武器爆头倍率文本组件 * 获取武器爆头倍率文本组件
*/ */
protected Component getHeadshotComponent() { protected Component getHeadshotComponent() {
double headshot = GunsTool.getGunDoubleTag(tag, "Headshot", 0); double headshot = GunsTool.getGunDoubleTag(tag, "Headshot");
return Component.translatable("des.superbwarfare.guns.headshot").withStyle(ChatFormatting.GRAY) return Component.translatable("des.superbwarfare.guns.headshot").withStyle(ChatFormatting.GRAY)
.append(Component.literal("").withStyle(ChatFormatting.RESET)) .append(Component.literal("").withStyle(ChatFormatting.RESET))
.append(Component.literal(FormatTool.format1D(headshot, "x")).withStyle(ChatFormatting.AQUA)); .append(Component.literal(FormatTool.format1D(headshot, "x")).withStyle(ChatFormatting.AQUA));

View file

@ -17,11 +17,11 @@ public class ClientLauncherImageTooltip extends ClientGunImageTooltip {
@Override @Override
protected Component getDamageComponent() { protected Component getDamageComponent() {
double damage = GunsTool.getGunDoubleTag(tag, "Damage", 0) * TooltipTool.perkDamage(stack); double damage = GunsTool.getGunDoubleTag(tag, "Damage") * TooltipTool.perkDamage(stack);
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), tag); int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), tag);
if (perkLevel > 0) damage *= 1.1f + perkLevel * 0.1f; if (perkLevel > 0) damage *= 1.1f + perkLevel * 0.1f;
double explosionDamage = GunsTool.getGunDoubleTag(tag, "ExplosionDamage", 0); double explosionDamage = GunsTool.getGunDoubleTag(tag, "ExplosionDamage");
return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY) return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY)
.append(Component.literal("").withStyle(ChatFormatting.RESET)) .append(Component.literal("").withStyle(ChatFormatting.RESET))

View file

@ -17,11 +17,11 @@ public class ClientSecondaryCataclysmImageTooltip extends ClientEnergyImageToolt
@Override @Override
protected Component getDamageComponent() { protected Component getDamageComponent() {
double damage = GunsTool.getGunDoubleTag(tag, "Damage", 0) * TooltipTool.perkDamage(stack); double damage = GunsTool.getGunDoubleTag(tag, "Damage") * TooltipTool.perkDamage(stack);
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), tag); int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), tag);
if (perkLevel > 0) damage *= 1.1f + perkLevel * 0.1f; if (perkLevel > 0) damage *= 1.1f + perkLevel * 0.1f;
double explosionDamage = GunsTool.getGunDoubleTag(tag, "ExplosionDamage", 0); double explosionDamage = GunsTool.getGunDoubleTag(tag, "ExplosionDamage");
return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY) return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY)
.append(Component.literal("").withStyle(ChatFormatting.RESET)) .append(Component.literal("").withStyle(ChatFormatting.RESET))

View file

@ -19,8 +19,8 @@ public class ClientSentinelImageTooltip extends ClientEnergyImageTooltip {
var cap = stack.getCapability(Capabilities.EnergyStorage.ITEM); var cap = stack.getCapability(Capabilities.EnergyStorage.ITEM);
if (cap != null && cap.getEnergyStored() > 0) { if (cap != null && cap.getEnergyStored() > 0) {
double damage = (GunsTool.getGunDoubleTag(tag, "Damage", 0) + double damage = (GunsTool.getGunDoubleTag(tag, "Damage") +
GunsTool.getGunDoubleTag(tag, "ChargedDamage", 0)) GunsTool.getGunDoubleTag(tag, "ChargedDamage"))
* TooltipTool.perkDamage(stack); * TooltipTool.perkDamage(stack);
return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY) return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY)
.append(Component.literal("").withStyle(ChatFormatting.RESET)) .append(Component.literal("").withStyle(ChatFormatting.RESET))
@ -28,7 +28,7 @@ public class ClientSentinelImageTooltip extends ClientEnergyImageTooltip {
FormatTool.format1D(0.8 * damage * (1 + 0.1 * TooltipTool.heBulletLevel(stack))) : "")) FormatTool.format1D(0.8 * damage * (1 + 0.1 * TooltipTool.heBulletLevel(stack))) : ""))
.withStyle(ChatFormatting.AQUA).withStyle(ChatFormatting.BOLD)); .withStyle(ChatFormatting.AQUA).withStyle(ChatFormatting.BOLD));
} else { } else {
double damage = GunsTool.getGunDoubleTag(tag, "Damage", 0) * TooltipTool.perkDamage(stack); double damage = GunsTool.getGunDoubleTag(tag, "Damage") * TooltipTool.perkDamage(stack);
return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY) return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY)
.append(Component.literal("").withStyle(ChatFormatting.RESET)) .append(Component.literal("").withStyle(ChatFormatting.RESET))
.append(Component.literal(FormatTool.format1D(damage) + (TooltipTool.heBullet(stack) ? .append(Component.literal(FormatTool.format1D(damage) + (TooltipTool.heBullet(stack) ?

View file

@ -26,16 +26,16 @@ public class ClientShotgunImageTooltip extends ClientGunImageTooltip {
} }
if (slug) { if (slug) {
double damage = GunsTool.getGunDoubleTag(tag, "Damage", 0) * GunsTool.getGunIntTag(tag, "ProjectileAmount", 1) * TooltipTool.perkDamage(stack); double damage = GunsTool.getGunDoubleTag(tag, "Damage") * GunsTool.getGunIntTag(tag, "ProjectileAmount") * TooltipTool.perkDamage(stack);
return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY) return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY)
.append(Component.literal("").withStyle(ChatFormatting.RESET)) .append(Component.literal("").withStyle(ChatFormatting.RESET))
.append(Component.literal(FormatTool.format1D(damage) + (TooltipTool.heBullet(stack) ? " + " + .append(Component.literal(FormatTool.format1D(damage) + (TooltipTool.heBullet(stack) ? " + " +
FormatTool.format1D(0.8 * damage * (1 + 0.1 * TooltipTool.heBulletLevel(stack))) : "")).withStyle(ChatFormatting.GREEN)); FormatTool.format1D(0.8 * damage * (1 + 0.1 * TooltipTool.heBulletLevel(stack))) : "")).withStyle(ChatFormatting.GREEN));
} else { } else {
double damage = GunsTool.getGunDoubleTag(tag, "Damage", 0) * TooltipTool.perkDamage(stack); double damage = GunsTool.getGunDoubleTag(tag, "Damage") * TooltipTool.perkDamage(stack);
return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY) return Component.translatable("des.superbwarfare.guns.damage").withStyle(ChatFormatting.GRAY)
.append(Component.literal("").withStyle(ChatFormatting.RESET)) .append(Component.literal("").withStyle(ChatFormatting.RESET))
.append(Component.literal(FormatTool.format1D(damage) + " * " + FormatTool.format0D(GunsTool.getGunIntTag(tag, "ProjectileAmount", 1))).withStyle(ChatFormatting.GREEN)); .append(Component.literal(FormatTool.format1D(damage) + " * " + FormatTool.format0D(GunsTool.getGunIntTag(tag, "ProjectileAmount"))).withStyle(ChatFormatting.GREEN));
} }
} }
} }

View file

@ -221,7 +221,7 @@ public class ClientEventHandler {
if (stack.is(ModItems.MINIGUN.get())) { if (stack.is(ModItems.MINIGUN.get())) {
if (holdFire || zoom) { if (holdFire || zoom) {
miniGunRot = Math.min(miniGunRot + 5, 21); miniGunRot = Math.min(miniGunRot + 5, 21);
float rpm = (float) GunsTool.getGunIntTag(tag, "RPM", 0) / 3600; float rpm = (float) GunsTool.getGunIntTag(tag, "RPM") / 3600;
player.playSound(ModSounds.MINIGUN_ROT.get(), 1, 0.7f + rpm); player.playSound(ModSounds.MINIGUN_ROT.get(), 1, 0.7f + rpm);
} }
} }
@ -437,7 +437,7 @@ public class ClientEventHandler {
cantFireTime = Mth.clamp(cantFireTime - 6 * speed * times, 0, 40); cantFireTime = Mth.clamp(cantFireTime - 6 * speed * times, 0, 40);
} }
int rpm = GunsTool.getGunIntTag(tag, "RPM", 0) + customRpm; int rpm = GunsTool.getGunIntTag(tag, "RPM") + customRpm;
if (rpm == 0) { if (rpm == 0) {
rpm = 600; rpm = 600;
} }
@ -474,9 +474,9 @@ public class ClientEventHandler {
&& (!(tag.getBoolean("is_normal_reloading") || tag.getBoolean("is_empty_reloading")) && (!(tag.getBoolean("is_normal_reloading") || tag.getBoolean("is_empty_reloading"))
&& !GunsTool.getGunBooleanTag(tag, "Reloading") && !GunsTool.getGunBooleanTag(tag, "Reloading")
&& !GunsTool.getGunBooleanTag(tag, "Charging") && !GunsTool.getGunBooleanTag(tag, "Charging")
&& GunsTool.getGunIntTag(tag, "Ammo", 0) > 0 && GunsTool.getGunIntTag(tag, "Ammo") > 0
&& !player.getCooldowns().isOnCooldown(stack.getItem()) && !player.getCooldowns().isOnCooldown(stack.getItem())
&& !GunsTool.getGunBooleanTag(tag, "NeedBoltAction", false) && !GunsTool.getGunBooleanTag(tag, "NeedBoltAction")
&& revolverPre(tag)) && revolverPre(tag))
|| (stack.is(ModItems.MINIGUN.get()) || (stack.is(ModItems.MINIGUN.get())
&& !player.isSprinting() && !player.isSprinting()
@ -548,14 +548,14 @@ public class ClientEventHandler {
public static void shootClient(Player player, final CompoundTag tag) { public static void shootClient(Player player, final CompoundTag tag) {
ItemStack stack = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
if (stack.is(ModTags.Items.NORMAL_GUN)) { if (stack.is(ModTags.Items.NORMAL_GUN)) {
if (GunsTool.getGunIntTag(tag, "Ammo", 0) > 0) { if (GunsTool.getGunIntTag(tag, "Ammo") > 0) {
int mode = GunsTool.getGunIntTag(tag, "FireMode"); int mode = GunsTool.getGunIntTag(tag, "FireMode");
if (mode != 2) { if (mode != 2) {
holdFire = false; holdFire = false;
} }
if (mode == 1) { if (mode == 1) {
if (GunsTool.getGunIntTag(tag, "Ammo", 0) == 1) { if (GunsTool.getGunIntTag(tag, "Ammo") == 1) {
burstFireSize = 1; burstFireSize = 1;
} }
if (burstFireSize == 1) { if (burstFireSize == 1) {
@ -581,7 +581,7 @@ public class ClientEventHandler {
} }
// 判断是否为栓动武器BoltActionTime > 0并在开火后给一个需要上膛的状态 // 判断是否为栓动武器BoltActionTime > 0并在开火后给一个需要上膛的状态
if (GunsTool.getGunIntTag(tag, "BoltActionTime", 0) > 0 && GunsTool.getGunIntTag(tag, "Ammo", 0) > (stack.is(ModTags.Items.REVOLVER) ? 0 : 1)) { if (GunsTool.getGunIntTag(tag, "BoltActionTime") > 0 && GunsTool.getGunIntTag(tag, "Ammo") > (stack.is(ModTags.Items.REVOLVER) ? 0 : 1)) {
GunsTool.setGunBooleanTag(tag, "NeedBoltAction", true); GunsTool.setGunBooleanTag(tag, "NeedBoltAction", true);
} }
@ -627,7 +627,7 @@ public class ClientEventHandler {
PacketDistributor.sendToServer(new ShootMessage(gunSpread)); PacketDistributor.sendToServer(new ShootMessage(gunSpread));
fireRecoilTime = 10; fireRecoilTime = 10;
float gunRecoilY = (float) GunsTool.getGunDoubleTag(tag, "RecoilY", 0) * 10; float gunRecoilY = (float) GunsTool.getGunDoubleTag(tag, "RecoilY") * 10;
recoilY = (float) (2 * Math.random() - 1) * gunRecoilY; recoilY = (float) (2 * Math.random() - 1) * gunRecoilY;
@ -1091,7 +1091,7 @@ public class ClientEventHandler {
float roll = event.getRoll(); float roll = event.getRoll();
ItemStack stack = entity.getMainHandItem(); ItemStack stack = entity.getMainHandItem();
double amplitude = 15000 * GunsTool.getGunDoubleTag(tag, "RecoilY", 0) * GunsTool.getGunDoubleTag(tag, "RecoilX", 0); double amplitude = 15000 * GunsTool.getGunDoubleTag(tag, "RecoilY") * GunsTool.getGunDoubleTag(tag, "RecoilX");
if (fireRecoilTime > 0) { if (fireRecoilTime > 0) {
firePosTimer = 0.001; firePosTimer = 0.001;
@ -1126,7 +1126,7 @@ public class ClientEventHandler {
double rpm = 1; double rpm = 1;
if (stack.is(ModItems.MINIGUN.get())) { if (stack.is(ModItems.MINIGUN.get())) {
rpm = (double) GunsTool.getGunIntTag(tag, "RPM", 0) / 1800; rpm = (double) GunsTool.getGunIntTag(tag, "RPM") / 1800;
} }
float[] shake = {0, 0}; float[] shake = {0, 0};
@ -1215,10 +1215,10 @@ public class ClientEventHandler {
double rpm = 1; double rpm = 1;
if (stack.is(ModItems.MINIGUN.get())) { if (stack.is(ModItems.MINIGUN.get())) {
rpm = (double) GunsTool.getGunIntTag(tag, "RPM", 0) / 1800; rpm = (double) GunsTool.getGunIntTag(tag, "RPM") / 1800;
} }
float gunRecoilX = (float) GunsTool.getGunDoubleTag(tag, "RecoilX", 0) * 60; float gunRecoilX = (float) GunsTool.getGunDoubleTag(tag, "RecoilX") * 60;
recoilHorizon = Mth.lerp(0.2 * times, recoilHorizon, 0) + recoilY; recoilHorizon = Mth.lerp(0.2 * times, recoilHorizon, 0) + recoilY;
recoilY = 0; recoilY = 0;
@ -1389,7 +1389,7 @@ public class ClientEventHandler {
p = zoomPos; p = zoomPos;
} }
customZoom = Mth.lerp(0.6 * times, customZoom, GunsTool.getGunDoubleTag(tag, "CustomZoom", 0)); customZoom = Mth.lerp(0.6 * times, customZoom, GunsTool.getGunDoubleTag(tag, "CustomZoom"));
double zoomFov = 1.25 + customZoom; double zoomFov = 1.25 + customZoom;

View file

@ -166,7 +166,7 @@ public class ClientMouseHandler {
return original; return original;
} }
double zoom = 1.25 + GunsTool.getGunDoubleTag(tag, "CustomZoom", 0); double zoom = 1.25 + GunsTool.getGunDoubleTag(tag, "CustomZoom");
float customSens = (float) tag.getInt("sensitivity"); float customSens = (float) tag.getInt("sensitivity");
if (!player.getMainHandItem().isEmpty() && mc.options.getCameraType() == CameraType.FIRST_PERSON) { if (!player.getMainHandItem().isEmpty() && mc.options.getCameraType() == CameraType.FIRST_PERSON) {

View file

@ -118,7 +118,7 @@ public class GunEventHandler {
player.playSound(ModSounds.HENG.get(), 4f, 1f); player.playSound(ModSounds.HENG.get(), 4f, 1f);
} }
float soundRadius = (float) (GunsTool.getGunDoubleTag(tag, "SoundRadius") * GunsTool.getGunDoubleTag(tag, "CustomSoundRadius", 1)); float soundRadius = (float) (GunsTool.getGunDoubleTag(tag, "SoundRadius") * GunsTool.getGunDoubleTag(tag, "CustomSoundRadius"));
int barrelType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.BARREL); int barrelType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.BARREL);
SoundEvent sound3p = BuiltInRegistries.SOUND_EVENT.get(Mod.loc(name + (barrelType == 2 ? "_fire_3p_s" : "_fire_3p"))); SoundEvent sound3p = BuiltInRegistries.SOUND_EVENT.get(Mod.loc(name + (barrelType == 2 ? "_fire_3p_s" : "_fire_3p")));
@ -156,7 +156,7 @@ public class GunEventHandler {
if (stack.is(ModTags.Items.REVOLVER)) return; if (stack.is(ModTags.Items.REVOLVER)) return;
Mod.queueServerWork((int) (GunsTool.getGunDoubleTag(tag, "BoltActionTime", 0) / 2 + 1.5 * shooterHeight), () -> { Mod.queueServerWork((int) (GunsTool.getGunDoubleTag(tag, "BoltActionTime") / 2 + 1.5 * shooterHeight), () -> {
if (stack.is(ModTags.Items.SHOTGUN)) { if (stack.is(ModTags.Items.SHOTGUN)) {
SoundTool.playLocalSound(serverPlayer, ModSounds.SHELL_CASING_SHOTGUN.get(), (float) Math.max(0.75 - 0.12 * shooterHeight, 0), 1); 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)) { } else if (stack.is(ModTags.Items.SNIPER_RIFLE)) {
@ -173,12 +173,12 @@ public class GunEventHandler {
ItemStack stack = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
if (!player.level().isClientSide()) { if (!player.level().isClientSide()) {
float headshot = (float) GunsTool.getGunDoubleTag(tag, "Headshot", 0); float headshot = (float) GunsTool.getGunDoubleTag(tag, "Headshot");
float damage = (float) (GunsTool.getGunDoubleTag(tag, "Damage", 0) + float damage = (float) (GunsTool.getGunDoubleTag(tag, "Damage") +
GunsTool.getGunDoubleTag(tag, "ChargedDamage", 0)) * (float) perkDamage(tag); GunsTool.getGunDoubleTag(tag, "ChargedDamage")) * (float) perkDamage(tag);
float velocity = (float) ((GunsTool.getGunDoubleTag(tag, "Velocity", 0) + GunsTool.getGunDoubleTag(tag, "CustomVelocity", 0)) * perkSpeed(tag)); float velocity = (float) ((GunsTool.getGunDoubleTag(tag, "Velocity") + GunsTool.getGunDoubleTag(tag, "CustomVelocity")) * perkSpeed(tag));
int projectileAmount = GunsTool.getGunIntTag(tag, "ProjectileAmount", 1); int projectileAmount = GunsTool.getGunIntTag(tag, "ProjectileAmount");
float bypassArmorRate = (float) GunsTool.getGunDoubleTag(tag, "BypassesArmor", 0); float bypassArmorRate = (float) GunsTool.getGunDoubleTag(tag, "BypassesArmor");
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE); var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
boolean zoom = cap != null && cap.zoom; boolean zoom = cap != null && cap.zoom;
@ -319,7 +319,7 @@ public class GunEventHandler {
NeoForge.EVENT_BUS.post(new ReloadEvent.Pre(player, stack)); NeoForge.EVENT_BUS.post(new ReloadEvent.Pre(player, stack));
if (gunItem.isOpenBolt(stack)) { if (gunItem.isOpenBolt(stack)) {
if (GunsTool.getGunIntTag(tag, "Ammo", 0) == 0) { if (GunsTool.getGunIntTag(tag, "Ammo") == 0) {
data.putInt("ReloadTime", data.getInt("EmptyReloadTime") + 1); data.putInt("ReloadTime", data.getInt("EmptyReloadTime") + 1);
tag.putBoolean("is_empty_reloading", true); tag.putBoolean("is_empty_reloading", true);
playGunEmptyReloadSounds(player); playGunEmptyReloadSounds(player);
@ -387,7 +387,7 @@ public class GunEventHandler {
if (data.getInt("ReloadTime") == 1) { if (data.getInt("ReloadTime") == 1) {
if (gunItem.isOpenBolt(stack)) { if (gunItem.isOpenBolt(stack)) {
if (GunsTool.getGunIntTag(tag, "Ammo", 0) == 0) { if (GunsTool.getGunIntTag(tag, "Ammo") == 0) {
playGunEmptyReload(player, tag); playGunEmptyReload(player, tag);
} else { } else {
playGunNormalReload(player, tag); playGunNormalReload(player, tag);
@ -533,24 +533,24 @@ public class GunEventHandler {
if (tag.getBoolean("start_single_reload")) { if (tag.getBoolean("start_single_reload")) {
NeoForge.EVENT_BUS.post(new ReloadEvent.Pre(player, stack)); NeoForge.EVENT_BUS.post(new ReloadEvent.Pre(player, stack));
if ((GunsTool.getGunIntTag(tag, "PrepareLoadTime", 0) != 0 if ((GunsTool.getGunIntTag(tag, "PrepareLoadTime") != 0
&& GunsTool.getGunIntTag(tag, "Ammo", 0) == 0) && GunsTool.getGunIntTag(tag, "Ammo") == 0)
|| stack.is(ModItems.SECONDARY_CATACLYSM.get()) || stack.is(ModItems.SECONDARY_CATACLYSM.get())
) { ) {
// 此处判断空仓换弹的时候是否在准备阶段就需要装填一发如M870 // 此处判断空仓换弹的时候是否在准备阶段就需要装填一发如M870
playGunPrepareLoadReloadSounds(player); playGunPrepareLoadReloadSounds(player);
int prepareLoadTime = GunsTool.getGunIntTag(tag, "PrepareLoadTime", 0); int prepareLoadTime = GunsTool.getGunIntTag(tag, "PrepareLoadTime");
tag.putInt("prepare_load", prepareLoadTime + 1); tag.putInt("prepare_load", prepareLoadTime + 1);
player.getCooldowns().addCooldown(stack.getItem(), prepareLoadTime); player.getCooldowns().addCooldown(stack.getItem(), prepareLoadTime);
} else if (GunsTool.getGunIntTag(tag, "PrepareEmptyTime", 0) != 0 && GunsTool.getGunIntTag(tag, "Ammo", 0) == 0) { } else if (GunsTool.getGunIntTag(tag, "PrepareEmptyTime") != 0 && GunsTool.getGunIntTag(tag, "Ammo") == 0) {
// 此处判断空仓换弹如莫辛纳甘 // 此处判断空仓换弹如莫辛纳甘
playGunEmptyPrepareSounds(player); playGunEmptyPrepareSounds(player);
int prepareEmptyTime = GunsTool.getGunIntTag(tag, "PrepareEmptyTime", 0); int prepareEmptyTime = GunsTool.getGunIntTag(tag, "PrepareEmptyTime");
tag.putInt("prepare", prepareEmptyTime + 1); tag.putInt("prepare", prepareEmptyTime + 1);
player.getCooldowns().addCooldown(stack.getItem(), prepareEmptyTime); player.getCooldowns().addCooldown(stack.getItem(), prepareEmptyTime);
} else { } else {
playGunPrepareReloadSounds(player); playGunPrepareReloadSounds(player);
int prepareTime = GunsTool.getGunIntTag(tag, "PrepareTime", 0); int prepareTime = GunsTool.getGunIntTag(tag, "PrepareTime");
tag.putInt("prepare", prepareTime + 1); tag.putInt("prepare", prepareTime + 1);
player.getCooldowns().addCooldown(stack.getItem(), prepareTime); player.getCooldowns().addCooldown(stack.getItem(), prepareTime);
} }
@ -588,13 +588,13 @@ public class GunEventHandler {
tag.putBoolean("force_stage3_start", true); tag.putBoolean("force_stage3_start", true);
} else if (stack.is(ModTags.Items.LAUNCHER) && GunsTool.getGunIntTag(tag, "MaxAmmo") == 0) { } else if (stack.is(ModTags.Items.LAUNCHER) && GunsTool.getGunIntTag(tag, "MaxAmmo") == 0) {
tag.putBoolean("force_stage3_start", true); tag.putBoolean("force_stage3_start", true);
} else if (stack.is(ModItems.SECONDARY_CATACLYSM.get()) && GunsTool.getGunIntTag(tag, "Ammo", 0) >= GunsTool.getGunIntTag(tag, "Magazine", 0)) { } else if (stack.is(ModItems.SECONDARY_CATACLYSM.get()) && GunsTool.getGunIntTag(tag, "Ammo") >= GunsTool.getGunIntTag(tag, "Magazine")) {
tag.putBoolean("force_stage3_start", true); tag.putBoolean("force_stage3_start", true);
} else { } else {
tag.putInt("reload_stage", 2); tag.putInt("reload_stage", 2);
} }
} else { } else {
if (stack.is(ModItems.SECONDARY_CATACLYSM.get()) && GunsTool.getGunIntTag(tag, "Ammo", 0) >= GunsTool.getGunIntTag(tag, "Magazine", 0)) { if (stack.is(ModItems.SECONDARY_CATACLYSM.get()) && GunsTool.getGunIntTag(tag, "Ammo") >= GunsTool.getGunIntTag(tag, "Magazine")) {
tag.putBoolean("force_stage3_start", true); tag.putBoolean("force_stage3_start", true);
} else { } else {
tag.putInt("reload_stage", 2); tag.putInt("reload_stage", 2);
@ -613,11 +613,11 @@ public class GunEventHandler {
&& tag.getInt("reload_stage") == 2 && tag.getInt("reload_stage") == 2
&& tag.getInt("iterative") == 0 && tag.getInt("iterative") == 0
&& !tag.getBoolean("stop") && !tag.getBoolean("stop")
&& GunsTool.getGunIntTag(tag, "Ammo", 0) < GunsTool.getGunIntTag(tag, "Magazine", 0) && GunsTool.getGunIntTag(tag, "Ammo") < GunsTool.getGunIntTag(tag, "Magazine")
+ GunsTool.getGunIntTag(tag, "CustomMagazine", 0)) { + GunsTool.getGunIntTag(tag, "CustomMagazine")) {
playGunLoopReloadSounds(player); playGunLoopReloadSounds(player);
int iterativeTime = GunsTool.getGunIntTag(tag, "IterativeTime", 0); int iterativeTime = GunsTool.getGunIntTag(tag, "IterativeTime");
tag.putDouble("iterative", iterativeTime); tag.putDouble("iterative", iterativeTime);
player.getCooldowns().addCooldown(stack.getItem(), iterativeTime); player.getCooldowns().addCooldown(stack.getItem(), iterativeTime);
// 动画播放nbt // 动画播放nbt
@ -650,8 +650,8 @@ public class GunEventHandler {
// 二阶段结束 // 二阶段结束
if (tag.getInt("iterative") == 1) { if (tag.getInt("iterative") == 1) {
// 装满结束 // 装满结束
if (GunsTool.getGunIntTag(tag, "Ammo", 0) >= GunsTool.getGunIntTag(tag, "Magazine", 0) if (GunsTool.getGunIntTag(tag, "Ammo") >= GunsTool.getGunIntTag(tag, "Magazine")
+ GunsTool.getGunIntTag(tag, "CustomMagazine", 0)) { + GunsTool.getGunIntTag(tag, "CustomMagazine")) {
tag.putInt("reload_stage", 3); tag.putInt("reload_stage", 3);
} }
@ -685,7 +685,7 @@ public class GunEventHandler {
if ((tag.getInt("iterative") == 1 && tag.getInt("reload_stage") == 3) || tag.getBoolean("force_stage3_start")) { if ((tag.getInt("iterative") == 1 && tag.getInt("reload_stage") == 3) || tag.getBoolean("force_stage3_start")) {
tag.putInt("reload_stage", 3); tag.putInt("reload_stage", 3);
tag.putBoolean("force_stage3_start", false); tag.putBoolean("force_stage3_start", false);
int finishTime = GunsTool.getGunIntTag(tag, "FinishTime", 0); int finishTime = GunsTool.getGunIntTag(tag, "FinishTime");
tag.putInt("finish", finishTime + 2); tag.putInt("finish", finishTime + 2);
player.getCooldowns().addCooldown(stack.getItem(), finishTime + 2); player.getCooldowns().addCooldown(stack.getItem(), finishTime + 2);
playGunEndReloadSounds(player); playGunEndReloadSounds(player);
@ -698,7 +698,7 @@ public class GunEventHandler {
// 三阶段结束 // 三阶段结束
if (tag.getInt("finish") == 1) { if (tag.getInt("finish") == 1) {
tag.putInt("reload_stage", 0); tag.putInt("reload_stage", 0);
if (GunsTool.getGunIntTag(tag, "BoltActionTime", 0) > 0) { if (GunsTool.getGunIntTag(tag, "BoltActionTime") > 0) {
GunsTool.setGunBooleanTag(tag, "NeedBoltAction", false); GunsTool.setGunBooleanTag(tag, "NeedBoltAction", false);
} }
GunsTool.setGunBooleanTag(tag, "Reloading", false); GunsTool.setGunBooleanTag(tag, "Reloading", false);
@ -766,7 +766,7 @@ public class GunEventHandler {
double shooterHeight = player.getEyePosition().distanceTo((Vec3.atLowerCornerOf(player.level().clip(new ClipContext(player.getEyePosition(), player.getEyePosition().add(new Vec3(0, -1, 0).scale(10)), double shooterHeight = player.getEyePosition().distanceTo((Vec3.atLowerCornerOf(player.level().clip(new ClipContext(player.getEyePosition(), player.getEyePosition().add(new Vec3(0, -1, 0).scale(10)),
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player)).getBlockPos()))); ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player)).getBlockPos())));
Mod.queueServerWork((int) (GunsTool.getGunIntTag(tag, "PrepareEmptyTime", 0) / 2 + 3 + 1.5 * shooterHeight), () -> { Mod.queueServerWork((int) (GunsTool.getGunIntTag(tag, "PrepareEmptyTime") / 2 + 3 + 1.5 * shooterHeight), () -> {
if (stack.is(ModTags.Items.SHOTGUN)) { if (stack.is(ModTags.Items.SHOTGUN)) {
SoundTool.playLocalSound(serverPlayer, ModSounds.SHELL_CASING_SHOTGUN.get(), (float) Math.max(0.75 - 0.12 * shooterHeight, 0), 1); 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) || stack.is(ModTags.Items.HEAVY_WEAPON)) { } else if (stack.is(ModTags.Items.SNIPER_RIFLE) || stack.is(ModTags.Items.HEAVY_WEAPON)) {
@ -866,11 +866,11 @@ public class GunEventHandler {
data.putBoolean("StartCharge", true); data.putBoolean("StartCharge", true);
} }
if (GunsTool.getGunIntTag(tag, "ChargeTime", 0) > 0) { if (GunsTool.getGunIntTag(tag, "ChargeTime") > 0) {
data.putInt("ChargeTime", data.getInt("ChargeTime") - 1); data.putInt("ChargeTime", data.getInt("ChargeTime") - 1);
} }
if (GunsTool.getGunIntTag(tag, "ChargeTime", 0) == 17) { if (GunsTool.getGunIntTag(tag, "ChargeTime") == 17) {
for (var cell : player.getInventory().items) { for (var cell : player.getInventory().items) {
if (cell.is(ModItems.CELL.get())) { if (cell.is(ModItems.CELL.get())) {
var stackStorage = cell.getCapability(Capabilities.EnergyStorage.ITEM); var stackStorage = cell.getCapability(Capabilities.EnergyStorage.ITEM);
@ -893,7 +893,7 @@ public class GunEventHandler {
} }
} }
if (GunsTool.getGunIntTag(tag, "ChargeTime", 0) == 1) { if (GunsTool.getGunIntTag(tag, "ChargeTime") == 1) {
data.putBoolean("Charging", false); data.putBoolean("Charging", false);
} }
} }

View file

@ -214,14 +214,14 @@ public class LivingEventHandler {
// 先处理发射器类武器或高爆弹的爆炸伤害 // 先处理发射器类武器或高爆弹的爆炸伤害
if (source.is(ModDamageTypes.PROJECTILE_BOOM)) { if (source.is(ModDamageTypes.PROJECTILE_BOOM)) {
if (stack.is(ModTags.Items.LAUNCHER) || PerkHelper.getItemPerkLevel(ModPerks.HE_BULLET.get(), tag) > 0) { if (stack.is(ModTags.Items.LAUNCHER) || PerkHelper.getItemPerkLevel(ModPerks.HE_BULLET.get(), tag) > 0) {
GunsTool.setGunDoubleTag(tag, "Exp", GunsTool.getGunDoubleTag(tag, "Exp", 0) + amount); GunsTool.setGunDoubleTag(tag, "Exp", GunsTool.getGunDoubleTag(tag, "Exp") + amount);
} }
} }
// 再判断是不是枪械能造成的伤害 // 再判断是不是枪械能造成的伤害
if (!DamageTypeTool.isGunDamage(source)) return; if (!DamageTypeTool.isGunDamage(source)) return;
GunsTool.setGunDoubleTag(tag, "Exp", GunsTool.getGunDoubleTag(tag, "Exp", 0) + amount); GunsTool.setGunDoubleTag(tag, "Exp", GunsTool.getGunDoubleTag(tag, "Exp") + amount);
NBTTool.saveTag(stack, tag); NBTTool.saveTag(stack, tag);
} }
@ -240,27 +240,27 @@ public class LivingEventHandler {
// 先处理发射器类武器或高爆弹的爆炸伤害 // 先处理发射器类武器或高爆弹的爆炸伤害
if (source.is(ModDamageTypes.PROJECTILE_BOOM)) { if (source.is(ModDamageTypes.PROJECTILE_BOOM)) {
if (stack.is(ModTags.Items.LAUNCHER) || PerkHelper.getItemPerkLevel(ModPerks.HE_BULLET.get(), tag) > 0) { if (stack.is(ModTags.Items.LAUNCHER) || PerkHelper.getItemPerkLevel(ModPerks.HE_BULLET.get(), tag) > 0) {
GunsTool.setGunDoubleTag(tag, "Exp", GunsTool.getGunDoubleTag(tag, "Exp", 0) + amount); GunsTool.setGunDoubleTag(tag, "Exp", GunsTool.getGunDoubleTag(tag, "Exp") + amount);
} }
} }
// 再判断是不是枪械能造成的伤害 // 再判断是不是枪械能造成的伤害
if (DamageTypeTool.isGunDamage(source)) { if (DamageTypeTool.isGunDamage(source)) {
GunsTool.setGunDoubleTag(tag, "Exp", GunsTool.getGunDoubleTag(tag, "Exp", 0) + amount); GunsTool.setGunDoubleTag(tag, "Exp", GunsTool.getGunDoubleTag(tag, "Exp") + amount);
} }
// 提升武器等级 // 提升武器等级
int level = GunsTool.getGunIntTag(tag, "Level", 0); int level = GunsTool.getGunIntTag(tag, "Level");
double exp = GunsTool.getGunDoubleTag(tag, "Exp", 0); double exp = GunsTool.getGunDoubleTag(tag, "Exp");
double upgradeExpNeeded = 20 * Math.pow(level, 2) + 160 * level + 20; double upgradeExpNeeded = 20 * Math.pow(level, 2) + 160 * level + 20;
while (exp >= upgradeExpNeeded) { while (exp >= upgradeExpNeeded) {
exp -= upgradeExpNeeded; exp -= upgradeExpNeeded;
level = GunsTool.getGunIntTag(tag, "Level", 0) + 1; level = GunsTool.getGunIntTag(tag, "Level") + 1;
upgradeExpNeeded = 20 * Math.pow(level, 2) + 160 * level + 20; upgradeExpNeeded = 20 * Math.pow(level, 2) + 160 * level + 20;
GunsTool.setGunDoubleTag(tag, "Exp", exp); GunsTool.setGunDoubleTag(tag, "Exp", exp);
GunsTool.setGunIntTag(tag, "Level", level); GunsTool.setGunIntTag(tag, "Level", level);
GunsTool.setGunDoubleTag(tag, "UpgradePoint", GunsTool.getGunDoubleTag(tag, "UpgradePoint", 0) + 0.5); GunsTool.setGunDoubleTag(tag, "UpgradePoint", GunsTool.getGunDoubleTag(tag, "UpgradePoint") + 0.5);
} }
NBTTool.saveTag(stack, tag); NBTTool.saveTag(stack, tag);
} }
@ -274,17 +274,17 @@ public class LivingEventHandler {
if (event.getEntity() instanceof TargetEntity) return; if (event.getEntity() instanceof TargetEntity) return;
final var tag = NBTTool.getTag(stack); final var tag = NBTTool.getTag(stack);
int level = GunsTool.getGunIntTag(tag, "Level", 0); int level = GunsTool.getGunIntTag(tag, "Level");
double exp = GunsTool.getGunDoubleTag(tag, "Exp", 0); double exp = GunsTool.getGunDoubleTag(tag, "Exp");
double upgradeExpNeeded = 20 * Math.pow(level, 2) + 160 * level + 20; double upgradeExpNeeded = 20 * Math.pow(level, 2) + 160 * level + 20;
while (exp >= upgradeExpNeeded) { while (exp >= upgradeExpNeeded) {
exp -= upgradeExpNeeded; exp -= upgradeExpNeeded;
level = GunsTool.getGunIntTag(tag, "Level", 0) + 1; level = GunsTool.getGunIntTag(tag, "Level") + 1;
upgradeExpNeeded = 20 * Math.pow(level, 2) + 160 * level + 20; upgradeExpNeeded = 20 * Math.pow(level, 2) + 160 * level + 20;
GunsTool.setGunDoubleTag(tag, "Exp", exp); GunsTool.setGunDoubleTag(tag, "Exp", exp);
GunsTool.setGunIntTag(tag, "Level", level); GunsTool.setGunIntTag(tag, "Level", level);
GunsTool.setGunDoubleTag(tag, "UpgradePoint", GunsTool.getGunDoubleTag(tag, "UpgradePoint", 0) + 0.5); GunsTool.setGunDoubleTag(tag, "UpgradePoint", GunsTool.getGunDoubleTag(tag, "UpgradePoint") + 0.5);
} }
NBTTool.saveTag(stack, tag); NBTTool.saveTag(stack, tag);
} }
@ -355,7 +355,7 @@ public class LivingEventHandler {
CompoundTag data = oldTag.getCompound("GunData"); CompoundTag data = oldTag.getCompound("GunData");
if (GunsTool.getGunDoubleTag(oldTag, "BoltActionTime", 0) > 0) { if (GunsTool.getGunDoubleTag(oldTag, "BoltActionTime") > 0) {
data.putInt("BoltActionTick", 0); data.putInt("BoltActionTick", 0);
} }
@ -365,7 +365,7 @@ public class LivingEventHandler {
oldTag.putBoolean("is_normal_reloading", false); oldTag.putBoolean("is_normal_reloading", false);
oldTag.putBoolean("is_empty_reloading", false); oldTag.putBoolean("is_empty_reloading", false);
if (GunsTool.getGunIntTag(oldTag, "IterativeTime", 0) != 0) { if (GunsTool.getGunIntTag(oldTag, "IterativeTime") != 0) {
oldTag.putBoolean("force_stop", false); oldTag.putBoolean("force_stop", false);
oldTag.putBoolean("stop", false); oldTag.putBoolean("stop", false);
oldTag.putInt("reload_stage", 0); oldTag.putInt("reload_stage", 0);
@ -391,7 +391,7 @@ public class LivingEventHandler {
if (newStack.getItem() instanceof GunItem) { if (newStack.getItem() instanceof GunItem) {
player.getPersistentData().putDouble("noRun", 40); player.getPersistentData().putDouble("noRun", 40);
newTag.putBoolean("draw", true); newTag.putBoolean("draw", true);
if (GunsTool.getGunIntTag(newTag, "BoltActionTime", 0) > 0) { if (GunsTool.getGunIntTag(newTag, "BoltActionTime") > 0) {
GunsTool.setGunIntTag(newTag, "BoltActionTick", 0); GunsTool.setGunIntTag(newTag, "BoltActionTick", 0);
} }
newTag.putBoolean("is_normal_reloading", false); newTag.putBoolean("is_normal_reloading", false);
@ -401,7 +401,7 @@ public class LivingEventHandler {
data.putInt("ReloadTime", 0); data.putInt("ReloadTime", 0);
newTag.put("GunData", data); newTag.put("GunData", data);
if (GunsTool.getGunIntTag(newTag, "IterativeTime", 0) != 0) { if (GunsTool.getGunIntTag(newTag, "IterativeTime") != 0) {
newTag.putBoolean("force_stop", false); newTag.putBoolean("force_stop", false);
newTag.putBoolean("stop", false); newTag.putBoolean("stop", false);
newTag.putInt("reload_stage", 0); newTag.putInt("reload_stage", 0);
@ -653,8 +653,8 @@ public class LivingEventHandler {
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE); var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
if (cap == null) return; if (cap == null) return;
int mag = GunsTool.getGunIntTag(tag, "Magazine", 0) + GunsTool.getGunIntTag(tag, "CustomMagazine", 0); int mag = GunsTool.getGunIntTag(tag, "Magazine") + GunsTool.getGunIntTag(tag, "CustomMagazine");
int ammo = GunsTool.getGunIntTag(tag, "Ammo", 0); int ammo = GunsTool.getGunIntTag(tag, "Ammo");
int ammoReload = (int) Math.min(mag, mag * rate); int ammoReload = (int) Math.min(mag, mag * rate);
int ammoNeed = Math.min(mag - ammo, ammoReload); int ammoNeed = Math.min(mag - ammo, ammoReload);

View file

@ -198,7 +198,7 @@ public class PlayerEventHandler {
ItemStack stack = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
final var tag = NBTTool.getTag(stack); final var tag = NBTTool.getTag(stack);
if ((stack.is(ModItems.RPG.get()) || stack.is(ModItems.BOCEK.get())) && GunsTool.getGunIntTag(tag, "Ammo", 0) == 1) { if ((stack.is(ModItems.RPG.get()) || stack.is(ModItems.BOCEK.get())) && GunsTool.getGunIntTag(tag, "Ammo") == 1) {
tag.putDouble("empty", 0); tag.putDouble("empty", 0);
NBTTool.saveTag(stack, tag); NBTTool.saveTag(stack, tag);
} }
@ -284,25 +284,25 @@ public class PlayerEventHandler {
GunsTool.reload(player, stack, tag, AmmoType.HEAVY); GunsTool.reload(player, stack, tag, AmmoType.HEAVY);
} }
if (stack.getItem() == ModItems.TASER.get() && GunsTool.getGunIntTag(tag, "MaxAmmo") > 0 && GunsTool.getGunIntTag(tag, "Ammo", 0) == 0) { if (stack.getItem() == ModItems.TASER.get() && GunsTool.getGunIntTag(tag, "MaxAmmo") > 0 && GunsTool.getGunIntTag(tag, "Ammo") == 0) {
GunsTool.setGunIntTag(tag, "Ammo", 1); GunsTool.setGunIntTag(tag, "Ammo", 1);
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.TASER_ELECTRODE.get(), 1, player.inventoryMenu.getCraftSlots()); player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.TASER_ELECTRODE.get(), 1, player.inventoryMenu.getCraftSlots());
} }
if (stack.getItem() == ModItems.M_79.get() && GunsTool.getGunIntTag(tag, "MaxAmmo") > 0 && GunsTool.getGunIntTag(tag, "Ammo", 0) == 0) { if (stack.getItem() == ModItems.M_79.get() && GunsTool.getGunIntTag(tag, "MaxAmmo") > 0 && GunsTool.getGunIntTag(tag, "Ammo") == 0) {
GunsTool.setGunIntTag(tag, "Ammo", 1); GunsTool.setGunIntTag(tag, "Ammo", 1);
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.GRENADE_40MM.get(), 1, player.inventoryMenu.getCraftSlots()); player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.GRENADE_40MM.get(), 1, player.inventoryMenu.getCraftSlots());
} }
if (stack.getItem() == ModItems.RPG.get() && GunsTool.getGunIntTag(tag, "MaxAmmo") > 0 && GunsTool.getGunIntTag(tag, "Ammo", 0) == 0) { if (stack.getItem() == ModItems.RPG.get() && GunsTool.getGunIntTag(tag, "MaxAmmo") > 0 && GunsTool.getGunIntTag(tag, "Ammo") == 0) {
GunsTool.setGunIntTag(tag, "Ammo", 1); GunsTool.setGunIntTag(tag, "Ammo", 1);
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.ROCKET.get(), 1, player.inventoryMenu.getCraftSlots()); player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.ROCKET.get(), 1, player.inventoryMenu.getCraftSlots());
} }
if (stack.getItem() == ModItems.JAVELIN.get() && GunsTool.getGunIntTag(tag, "MaxAmmo") > 0 && GunsTool.getGunIntTag(tag, "Ammo", 0) == 0) { if (stack.getItem() == ModItems.JAVELIN.get() && GunsTool.getGunIntTag(tag, "MaxAmmo") > 0 && GunsTool.getGunIntTag(tag, "Ammo") == 0) {
GunsTool.setGunIntTag(tag, "Ammo", 1); GunsTool.setGunIntTag(tag, "Ammo", 1);
player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.JAVELIN_MISSILE.get(), 1, player.inventoryMenu.getCraftSlots()); player.getInventory().clearOrCountMatchingItems(p -> p.getItem() == ModItems.JAVELIN_MISSILE.get(), 1, player.inventoryMenu.getCraftSlots());
} }
} else { } else {
GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Magazine", 0) GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Magazine")
+ GunsTool.getGunIntTag(tag, "CustomMagazine", 0)); + GunsTool.getGunIntTag(tag, "CustomMagazine"));
} }
GunsTool.setGunBooleanTag(tag, "HoldOpen", false); GunsTool.setGunBooleanTag(tag, "HoldOpen", false);
NBTTool.saveTag(stack, tag); NBTTool.saveTag(stack, tag);
@ -354,7 +354,7 @@ public class PlayerEventHandler {
ItemStack output = left.copy(); ItemStack output = left.copy();
final var outputTag = NBTTool.getTag(output); final var outputTag = NBTTool.getTag(output);
GunsTool.setGunDoubleTag(outputTag, "UpgradePoint", GunsTool.getGunDoubleTag(outputTag, "UpgradePoint", 0) + 1); GunsTool.setGunDoubleTag(outputTag, "UpgradePoint", GunsTool.getGunDoubleTag(outputTag, "UpgradePoint") + 1);
NBTTool.saveTag(output, outputTag); NBTTool.saveTag(output, outputTag);
event.setOutput(output); event.setOutput(output);

View file

@ -2,24 +2,7 @@ package com.atsuishio.superbwarfare.init;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.item.*; import com.atsuishio.superbwarfare.item.*;
import com.atsuishio.superbwarfare.item.gun.handgun.*; import com.atsuishio.superbwarfare.tools.NBTTool;
import com.atsuishio.superbwarfare.item.gun.heavy.Ntw20Item;
import com.atsuishio.superbwarfare.item.gun.launcher.JavelinItem;
import com.atsuishio.superbwarfare.item.gun.launcher.M79Item;
import com.atsuishio.superbwarfare.item.gun.launcher.RpgItem;
import com.atsuishio.superbwarfare.item.gun.launcher.SecondaryCataclysm;
import com.atsuishio.superbwarfare.item.gun.machinegun.DevotionItem;
import com.atsuishio.superbwarfare.item.gun.machinegun.M60Item;
import com.atsuishio.superbwarfare.item.gun.machinegun.MinigunItem;
import com.atsuishio.superbwarfare.item.gun.machinegun.RpkItem;
import com.atsuishio.superbwarfare.item.gun.rifle.*;
import com.atsuishio.superbwarfare.item.gun.shotgun.Aa12Item;
import com.atsuishio.superbwarfare.item.gun.shotgun.HomemadeShotgunItem;
import com.atsuishio.superbwarfare.item.gun.shotgun.M870Item;
import com.atsuishio.superbwarfare.item.gun.smg.VectorItem;
import com.atsuishio.superbwarfare.item.gun.sniper.*;
import com.atsuishio.superbwarfare.item.gun.special.BocekItem;
import com.atsuishio.superbwarfare.item.gun.special.TaserItem;
import net.minecraft.core.HolderLookup; import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
@ -32,6 +15,7 @@ import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.alchemy.PotionContents; import net.minecraft.world.item.alchemy.PotionContents;
import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent; import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent;
import net.neoforged.neoforge.registries.DeferredHolder; import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister; import net.neoforged.neoforge.registries.DeferredRegister;
@ -48,43 +32,25 @@ public class ModTabs {
() -> CreativeModeTab.builder() () -> CreativeModeTab.builder()
.title(Component.translatable("item_group.superbwarfare.guns")) .title(Component.translatable("item_group.superbwarfare.guns"))
.icon(() -> new ItemStack(ModItems.TASER.get())) .icon(() -> new ItemStack(ModItems.TASER.get()))
.displayItems((param, output) -> { .displayItems((param, output) -> ModItems.GUNS.getEntries().forEach(registryObject -> {
output.accept(TaserItem.getGunInstance()); // 普通枪械
output.accept(Glock17Item.getGunInstance()); var stack = new ItemStack(registryObject.get());
output.accept(Glock18Item.getGunInstance()); var id = stack.getDescriptionId();
output.accept(M1911Item.getGunInstance()); var tag = NBTTool.getTag(stack);
output.accept(Mp443Item.getGunInstance()); tag.putString("id", id.substring(id.lastIndexOf(".") + 1));
output.accept(HomemadeShotgunItem.getGunInstance()); NBTTool.saveTag(stack, tag);
output.accept(Trachelium.getGunInstance());
output.accept(VectorItem.getGunInstance()); output.accept(stack);
output.accept(SksItem.getGunInstance());
output.accept(AK47Item.getGunInstance()); // 充电后枪械
output.accept(AK12Item.getGunInstance()); var newStack = stack.copy();
output.accept(M4Item.getGunInstance()); var cap = newStack.getCapability(Capabilities.EnergyStorage.ITEM);
output.accept(Hk416Item.getGunInstance());
output.accept(Qbz95Item.getGunInstance()); if (cap != null) {
output.accept(InsidiousItem.getGunInstance()); cap.receiveEnergy(Integer.MAX_VALUE, false);
output.accept(Mk14Item.getGunInstance()); output.accept(newStack);
output.accept(MarlinItem.getGunInstance()); }
output.accept(K98Item.getGunInstance()); }))
output.accept(MosinNagantItem.getGunInstance());
output.accept(SvdItem.getGunInstance());
output.accept(HuntingRifleItem.getGunInstance());
output.accept(M98bItem.getGunInstance());
output.accept(SentinelItem.getGunInstance());
output.accept(Ntw20Item.getGunInstance());
output.accept(M870Item.getGunInstance());
output.accept(Aa12Item.getGunInstance());
output.accept(DevotionItem.getGunInstance());
output.accept(RpkItem.getGunInstance());
output.accept(M60Item.getGunInstance());
output.accept(MinigunItem.getGunInstance());
output.accept(BocekItem.getGunInstance());
output.accept(M79Item.getGunInstance());
output.accept(SecondaryCataclysm.getGunInstance());
output.accept(RpgItem.getGunInstance());
output.accept(JavelinItem.getGunInstance());
})
.build()); .build());
public static final DeferredHolder<CreativeModeTab, CreativeModeTab> PERK_TAB = TABS.register("perk", public static final DeferredHolder<CreativeModeTab, CreativeModeTab> PERK_TAB = TABS.register("perk",

View file

@ -15,7 +15,7 @@ public class GunEvents {
if (stack.is(ModTags.Items.GUN)) { if (stack.is(ModTags.Items.GUN)) {
final var tag = NBTTool.getTag(stack); final var tag = NBTTool.getTag(stack);
tag.putBoolean("draw", true); tag.putBoolean("draw", true);
tag.putBoolean("init", true); tag.putBoolean("init", false);
NBTTool.saveTag(stack, tag); NBTTool.saveTag(stack, tag);
} }
} }

View file

@ -62,8 +62,21 @@ public abstract class GunItem extends Item implements CustomRendererItem {
) return; ) return;
var tag = NBTTool.getTag(stack); var tag = NBTTool.getTag(stack);
if (tag.getString("id").isEmpty()) {
var id = stack.getDescriptionId();
tag.putString("id", id.substring(id.lastIndexOf(".") + 1));
}
if (!tag.getBoolean("init")) { if (!tag.getBoolean("init")) {
GunsTool.initGun(level, tag, this.getDescriptionId().substring(this.getDescriptionId().lastIndexOf('.') + 1)); var name = this.getDescriptionId().substring(this.getDescriptionId().lastIndexOf('.') + 1);
if (level.getServer() != null && entity instanceof Player player && player.isCreative()) {
GunsTool.initCreativeGun(tag, name);
} else {
GunsTool.initGun(tag, name);
}
GunsTool.generateAndSetUUID(tag); GunsTool.generateAndSetUUID(tag);
tag.putBoolean("init", true); tag.putBoolean("init", true);
} }
@ -73,9 +86,9 @@ public abstract class GunItem extends Item implements CustomRendererItem {
handleGunAttachment(tag); handleGunAttachment(tag);
var hasBulletInBarrel = gunItem.hasBulletInBarrel(stack); var hasBulletInBarrel = gunItem.hasBulletInBarrel(stack);
var ammoCount = GunsTool.getGunIntTag(tag, "Ammo", 0); var ammoCount = GunsTool.getGunIntTag(tag, "Ammo");
var magazine = GunsTool.getGunIntTag(tag, "Magazine", 0); var magazine = GunsTool.getGunIntTag(tag, "Magazine");
var customMagazine = GunsTool.getGunIntTag(tag, "CustomMagazine", 0); var customMagazine = GunsTool.getGunIntTag(tag, "CustomMagazine");
if ((hasBulletInBarrel && ammoCount > magazine + customMagazine + 1) if ((hasBulletInBarrel && ammoCount > magazine + customMagazine + 1)
|| (!hasBulletInBarrel && ammoCount > magazine + customMagazine) || (!hasBulletInBarrel && ammoCount > magazine + customMagazine)
@ -184,8 +197,8 @@ public abstract class GunItem extends Item implements CustomRendererItem {
GunsTool.setPerkIntTag(tag, "FourthTimesCharmTick", 0); GunsTool.setPerkIntTag(tag, "FourthTimesCharmTick", 0);
GunsTool.setPerkIntTag(tag, "FourthTimesCharmCount", 0); GunsTool.setPerkIntTag(tag, "FourthTimesCharmCount", 0);
int mag = GunsTool.getGunIntTag(tag, "Magazine", 0) + GunsTool.getGunIntTag(tag, "CustomMagazine", 0); int mag = GunsTool.getGunIntTag(tag, "Magazine") + GunsTool.getGunIntTag(tag, "CustomMagazine");
GunsTool.setGunIntTag(tag, "Ammo", Math.min(mag, GunsTool.getGunIntTag(tag, "Ammo", 0) + 2)); GunsTool.setGunIntTag(tag, "Ammo", Math.min(mag, GunsTool.getGunIntTag(tag, "Ammo") + 2));
} }
} }
} }

View file

@ -3,13 +3,11 @@ package com.atsuishio.superbwarfare.item.gun.handgun;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.renderer.item.Glock17ItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.Glock17ItemRenderer;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
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.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
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.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.player.LocalPlayer;
@ -101,12 +99,6 @@ public class Glock17Item extends GunItem implements GeoItem {
return Set.of(ModSounds.GLOCK_17_RELOAD_EMPTY.get(), ModSounds.GLOCK_17_RELOAD_NORMAL.get()); return Set.of(ModSounds.GLOCK_17_RELOAD_EMPTY.get(), ModSounds.GLOCK_17_RELOAD_NORMAL.get());
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.GLOCK_17.get());
GunsTool.initCreativeGun(stack, ModItems.GLOCK_17.getId().getPath());
return stack;
}
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return Mod.loc("textures/gun_icon/glock_icon.png"); return Mod.loc("textures/gun_icon/glock_icon.png");

View file

@ -3,14 +3,12 @@ package com.atsuishio.superbwarfare.item.gun.handgun;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.renderer.item.Glock18ItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.Glock18ItemRenderer;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModPerks; import com.atsuishio.superbwarfare.init.ModPerks;
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.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
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.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.player.LocalPlayer;
@ -104,12 +102,6 @@ public class Glock18Item extends GunItem implements GeoItem {
); );
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.GLOCK_18.get());
GunsTool.initCreativeGun(stack, ModItems.GLOCK_18.getId().getPath());
return stack;
}
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return Mod.loc("textures/gun_icon/glock_icon.png"); return Mod.loc("textures/gun_icon/glock_icon.png");

View file

@ -3,13 +3,11 @@ package com.atsuishio.superbwarfare.item.gun.handgun;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.renderer.item.M1911ItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.M1911ItemRenderer;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
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.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
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.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.player.LocalPlayer;
@ -104,12 +102,6 @@ public class M1911Item extends GunItem implements GeoItem {
); );
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.M_1911.get());
GunsTool.initCreativeGun(stack, ModItems.M_1911.getId().getPath());
return stack;
}
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return Mod.loc("textures/gun_icon/m1911_icon.png"); return Mod.loc("textures/gun_icon/m1911_icon.png");

View file

@ -3,13 +3,11 @@ package com.atsuishio.superbwarfare.item.gun.handgun;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.renderer.item.Mp443ItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.Mp443ItemRenderer;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
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.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
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.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.player.LocalPlayer;
@ -101,12 +99,6 @@ public class Mp443Item extends GunItem implements GeoItem {
return Set.of(ModSounds.MP_443_RELOAD_EMPTY.get(), ModSounds.MP_443_RELOAD_NORMAL.get()); return Set.of(ModSounds.MP_443_RELOAD_EMPTY.get(), ModSounds.MP_443_RELOAD_NORMAL.get());
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.MP_443.get());
GunsTool.initCreativeGun(stack, ModItems.MP_443.getId().getPath());
return stack;
}
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return Mod.loc("textures/gun_icon/mp443_icon.png"); return Mod.loc("textures/gun_icon/mp443_icon.png");

View file

@ -5,7 +5,6 @@ import com.atsuishio.superbwarfare.capability.ModCapabilities;
import com.atsuishio.superbwarfare.client.TooltipTool; import com.atsuishio.superbwarfare.client.TooltipTool;
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.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.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
@ -235,12 +234,6 @@ public class Trachelium extends GunItem implements GeoItem {
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.TRACHELIUM.get());
GunsTool.initCreativeGun(stack, ModItems.TRACHELIUM.getId().getPath());
return stack;
}
@Override @Override
@ParametersAreNonnullByDefault @ParametersAreNonnullByDefault
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) { public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {

View file

@ -4,7 +4,6 @@ import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.capability.ModCapabilities; import com.atsuishio.superbwarfare.capability.ModCapabilities;
import com.atsuishio.superbwarfare.client.renderer.item.Ntw20Renderer; import com.atsuishio.superbwarfare.client.renderer.item.Ntw20Renderer;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModRarity; import com.atsuishio.superbwarfare.init.ModRarity;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.init.ModTags;
@ -144,7 +143,7 @@ public class Ntw20Item extends GunItem implements GeoItem {
double customZoom = switch (scopeType) { double customZoom = switch (scopeType) {
case 0, 1 -> 0; case 0, 1 -> 0;
case 2 -> 2.25; case 2 -> 2.25;
default -> GunsTool.getGunDoubleTag(tag, "CustomZoom", 0); default -> GunsTool.getGunDoubleTag(tag, "CustomZoom");
}; };
tag.putBoolean("CanAdjustZoomFov", scopeType == 3); tag.putBoolean("CanAdjustZoomFov", scopeType == 3);
@ -153,12 +152,6 @@ public class Ntw20Item extends GunItem implements GeoItem {
NBTTool.saveTag(stack, tag); NBTTool.saveTag(stack, tag);
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.NTW_20.get());
GunsTool.initCreativeGun(stack, ModItems.NTW_20.getId().getPath());
return stack;
}
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return Mod.loc("textures/gun_icon/ntw_20_icon.png"); return Mod.loc("textures/gun_icon/ntw_20_icon.png");

View file

@ -206,12 +206,6 @@ public class JavelinItem extends GunItem implements GeoItem, SpecialFireWeapon {
return stack.getItem() == ModItems.JAVELIN_MISSILE.get(); return stack.getItem() == ModItems.JAVELIN_MISSILE.get();
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.JAVELIN.get());
GunsTool.initCreativeGun(stack, ModItems.JAVELIN.getId().getPath());
return stack;
}
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return Mod.loc("textures/gun_icon/javelin_icon.png"); return Mod.loc("textures/gun_icon/javelin_icon.png");
@ -253,9 +247,9 @@ public class JavelinItem extends GunItem implements GeoItem, SpecialFireWeapon {
if (player.level() instanceof ServerLevel serverLevel) { if (player.level() instanceof ServerLevel serverLevel) {
JavelinMissileEntity missileEntity = new JavelinMissileEntity(player, level, JavelinMissileEntity missileEntity = new JavelinMissileEntity(player, level,
(float) GunsTool.getGunDoubleTag(tag, "Damage", 0), (float) GunsTool.getGunDoubleTag(tag, "Damage"),
(float) GunsTool.getGunDoubleTag(tag, "ExplosionDamage", 0), (float) GunsTool.getGunDoubleTag(tag, "ExplosionDamage"),
(float) GunsTool.getGunDoubleTag(tag, "ExplosionRadius", 0), (float) GunsTool.getGunDoubleTag(tag, "ExplosionRadius"),
tag.getInt("GuideType"), tag.getInt("GuideType"),
new Vec3(tag.getDouble("TargetPosX"), tag.getDouble("TargetPosY"), tag.getDouble("TargetPosZ"))); new Vec3(tag.getDouble("TargetPosX"), tag.getDouble("TargetPosY"), tag.getDouble("TargetPosZ")));
@ -286,7 +280,7 @@ public class JavelinItem extends GunItem implements GeoItem, SpecialFireWeapon {
} }
player.getCooldowns().addCooldown(stack.getItem(), 10); player.getCooldowns().addCooldown(stack.getItem(), 10);
GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Ammo", 0) - 1); GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Ammo") - 1);
NBTTool.saveTag(stack, tag); NBTTool.saveTag(stack, tag);
} }
@ -305,7 +299,7 @@ public class JavelinItem extends GunItem implements GeoItem, SpecialFireWeapon {
@Override @Override
public void fireOnPress(Player player, final CompoundTag tag) { public void fireOnPress(Player player, final CompoundTag tag) {
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE); var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
if (cap != null && !cap.zoom || GunsTool.getGunIntTag(tag, "Ammo", 0) <= 0) return; if (cap != null && !cap.zoom || GunsTool.getGunIntTag(tag, "Ammo") <= 0) return;
Entity seekingEntity = SeekTool.seekEntity(player, player.level(), 512, 8); Entity seekingEntity = SeekTool.seekEntity(player, player.level(), 512, 8);

View file

@ -139,12 +139,6 @@ public class M79Item extends GunItem implements GeoItem, SpecialFireWeapon {
return stack.getItem() == ModItems.GRENADE_40MM.get(); return stack.getItem() == ModItems.GRENADE_40MM.get();
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.M_79.get());
GunsTool.initCreativeGun(stack, ModItems.M_79.getId().getPath());
return stack;
}
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return Mod.loc("textures/gun_icon/m79_icon.png"); return Mod.loc("textures/gun_icon/m79_icon.png");
@ -175,7 +169,7 @@ public class M79Item extends GunItem implements GeoItem, SpecialFireWeapon {
ItemStack stack = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
if (GunsTool.getGunBooleanTag(tag, "Reloading")) return; if (GunsTool.getGunBooleanTag(tag, "Reloading")) return;
if (player.getCooldowns().isOnCooldown(stack.getItem()) || GunsTool.getGunIntTag(tag, "Ammo", 0) <= 0) return; if (player.getCooldowns().isOnCooldown(stack.getItem()) || GunsTool.getGunIntTag(tag, "Ammo") <= 0) return;
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE); var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
boolean zooming = cap != null && cap.zoom; boolean zooming = cap != null && cap.zoom;
@ -183,9 +177,9 @@ public class M79Item extends GunItem implements GeoItem, SpecialFireWeapon {
if (player.level() instanceof ServerLevel serverLevel) { if (player.level() instanceof ServerLevel serverLevel) {
GunGrenadeEntity gunGrenadeEntity = new GunGrenadeEntity(player, serverLevel, GunGrenadeEntity gunGrenadeEntity = new GunGrenadeEntity(player, serverLevel,
(float) GunsTool.getGunDoubleTag(tag, "Damage", 0), (float) GunsTool.getGunDoubleTag(tag, "Damage"),
(float) GunsTool.getGunDoubleTag(tag, "ExplosionDamage", 0), (float) GunsTool.getGunDoubleTag(tag, "ExplosionDamage"),
(float) GunsTool.getGunDoubleTag(tag, "ExplosionRadius", 0)); (float) GunsTool.getGunDoubleTag(tag, "ExplosionRadius"));
var dmgPerk = PerkHelper.getPerkByType(tag, Perk.Type.DAMAGE); var dmgPerk = PerkHelper.getPerkByType(tag, Perk.Type.DAMAGE);
if (dmgPerk == ModPerks.MONSTER_HUNTER.get()) { if (dmgPerk == ModPerks.MONSTER_HUNTER.get()) {
@ -195,11 +189,11 @@ public class M79Item extends GunItem implements GeoItem, SpecialFireWeapon {
gunGrenadeEntity.setNoGravity(PerkHelper.getPerkByType(tag, Perk.Type.AMMO) == ModPerks.MICRO_MISSILE.get()); gunGrenadeEntity.setNoGravity(PerkHelper.getPerkByType(tag, Perk.Type.AMMO) == ModPerks.MICRO_MISSILE.get());
float velocity = (float) GunsTool.getGunDoubleTag(tag, "Velocity", 0); float velocity = (float) GunsTool.getGunDoubleTag(tag, "Velocity");
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), tag); int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), tag);
if (perkLevel > 0) { if (perkLevel > 0) {
gunGrenadeEntity.setExplosionRadius((float) GunsTool.getGunDoubleTag(tag, "ExplosionRadius", 0) * 0.5f); gunGrenadeEntity.setExplosionRadius((float) GunsTool.getGunDoubleTag(tag, "ExplosionRadius") * 0.5f);
gunGrenadeEntity.setDamage((float) GunsTool.getGunDoubleTag(tag, "Damage", 0) * (1.1f + perkLevel * 0.1f)); gunGrenadeEntity.setDamage((float) GunsTool.getGunDoubleTag(tag, "Damage") * (1.1f + perkLevel * 0.1f));
velocity *= 1.2f; velocity *= 1.2f;
} }
@ -224,6 +218,6 @@ public class M79Item extends GunItem implements GeoItem, SpecialFireWeapon {
} }
player.getCooldowns().addCooldown(stack.getItem(), 2); player.getCooldowns().addCooldown(stack.getItem(), 2);
GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Ammo", 0) - 1); GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Ammo") - 1);
} }
} }

View file

@ -132,7 +132,7 @@ public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon {
if (tag.getBoolean("draw")) { if (tag.getBoolean("draw")) {
tag.putBoolean("draw", false); tag.putBoolean("draw", false);
if (GunsTool.getGunIntTag(tag, "Ammo", 0) == 0) { if (GunsTool.getGunIntTag(tag, "Ammo") == 0) {
tag.putDouble("empty", 1); tag.putDouble("empty", 1);
} }
} }
@ -149,12 +149,6 @@ public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon {
return stack.getItem() == ModItems.ROCKET.get(); return stack.getItem() == ModItems.ROCKET.get();
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.RPG.get());
GunsTool.initCreativeGun(stack, ModItems.RPG.getId().getPath());
return stack;
}
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return Mod.loc("textures/gun_icon/rpg_icon.png"); return Mod.loc("textures/gun_icon/rpg_icon.png");
@ -187,7 +181,7 @@ public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon {
if (GunsTool.getGunBooleanTag(tag, "Reloading") if (GunsTool.getGunBooleanTag(tag, "Reloading")
|| player.getCooldowns().isOnCooldown(stack.getItem()) || player.getCooldowns().isOnCooldown(stack.getItem())
|| GunsTool.getGunIntTag(tag, "Ammo", 0) <= 0 || GunsTool.getGunIntTag(tag, "Ammo") <= 0
) return; ) return;
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE); var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
@ -196,9 +190,9 @@ public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon {
if (player.level() instanceof ServerLevel serverLevel) { if (player.level() instanceof ServerLevel serverLevel) {
RpgRocketEntity rocket = new RpgRocketEntity(player, level, RpgRocketEntity rocket = new RpgRocketEntity(player, level,
(float) GunsTool.getGunDoubleTag(tag, "Damage", 0), (float) GunsTool.getGunDoubleTag(tag, "Damage"),
(float) GunsTool.getGunDoubleTag(tag, "ExplosionDamage", 0), (float) GunsTool.getGunDoubleTag(tag, "ExplosionDamage"),
(float) GunsTool.getGunDoubleTag(tag, "ExplosionRadius", 0)); (float) GunsTool.getGunDoubleTag(tag, "ExplosionRadius"));
var dmgPerk = PerkHelper.getPerkByType(tag, Perk.Type.DAMAGE); var dmgPerk = PerkHelper.getPerkByType(tag, Perk.Type.DAMAGE);
if (dmgPerk == ModPerks.MONSTER_HUNTER.get()) { if (dmgPerk == ModPerks.MONSTER_HUNTER.get()) {
@ -206,7 +200,7 @@ public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon {
rocket.setMonsterMultiplier(0.1f + 0.1f * perkLevel); rocket.setMonsterMultiplier(0.1f + 0.1f * perkLevel);
} }
float velocity = (float) GunsTool.getGunDoubleTag(tag, "Velocity", 0); float velocity = (float) GunsTool.getGunDoubleTag(tag, "Velocity");
if (PerkHelper.getPerkByType(tag, Perk.Type.AMMO) == ModPerks.MICRO_MISSILE.get()) { if (PerkHelper.getPerkByType(tag, Perk.Type.AMMO) == ModPerks.MICRO_MISSILE.get()) {
rocket.setNoGravity(true); rocket.setNoGravity(true);
@ -214,7 +208,7 @@ public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon {
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), tag); int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), tag);
if (perkLevel > 0) { if (perkLevel > 0) {
rocket.setExplosionRadius(0.5f); rocket.setExplosionRadius(0.5f);
rocket.setDamage((float) GunsTool.getGunDoubleTag(tag, "Damage", 0) * (1.1f + perkLevel * 0.1f)); rocket.setDamage((float) GunsTool.getGunDoubleTag(tag, "Damage") * (1.1f + perkLevel * 0.1f));
velocity *= 1.2f; velocity *= 1.2f;
} }
} }
@ -239,12 +233,12 @@ public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon {
PacketDistributor.sendToPlayer(serverPlayer, new ShootClientMessage(10)); PacketDistributor.sendToPlayer(serverPlayer, new ShootClientMessage(10));
} }
if (GunsTool.getGunIntTag(tag, "Ammo", 0) == 1) { if (GunsTool.getGunIntTag(tag, "Ammo") == 1) {
tag.putBoolean("empty", true); tag.putBoolean("empty", true);
GunsTool.setGunBooleanTag(tag, "CloseHammer", true); GunsTool.setGunBooleanTag(tag, "CloseHammer", true);
} }
player.getCooldowns().addCooldown(stack.getItem(), 10); player.getCooldowns().addCooldown(stack.getItem(), 10);
GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Ammo", 0) - 1); GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Ammo") - 1);
} }
} }

View file

@ -206,12 +206,6 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, SpecialFireW
return stack.getItem() == ModItems.GRENADE_40MM.get(); return stack.getItem() == ModItems.GRENADE_40MM.get();
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.SECONDARY_CATACLYSM.get());
GunsTool.initCreativeGun(stack, ModItems.SECONDARY_CATACLYSM.getId().getPath());
return stack;
}
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return Mod.loc("textures/gun_icon/secondary_cataclysm_icon.png"); return Mod.loc("textures/gun_icon/secondary_cataclysm_icon.png");
@ -264,7 +258,7 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, SpecialFireW
public void fireOnPress(Player player, final CompoundTag tag) { public void fireOnPress(Player player, final CompoundTag tag) {
ItemStack stack = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
if (GunsTool.getGunBooleanTag(tag, "Reloading")) return; if (GunsTool.getGunBooleanTag(tag, "Reloading")) return;
if (player.getCooldowns().isOnCooldown(stack.getItem()) || GunsTool.getGunIntTag(tag, "Ammo", 0) <= 0) return; if (player.getCooldowns().isOnCooldown(stack.getItem()) || GunsTool.getGunIntTag(tag, "Ammo") <= 0) return;
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE); var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
boolean zooming = cap != null && cap.zoom; boolean zooming = cap != null && cap.zoom;
@ -277,9 +271,9 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, SpecialFireW
if (player.level() instanceof ServerLevel serverLevel) { if (player.level() instanceof ServerLevel serverLevel) {
GunGrenadeEntity gunGrenadeEntity = new GunGrenadeEntity(player, serverLevel, GunGrenadeEntity gunGrenadeEntity = new GunGrenadeEntity(player, serverLevel,
(float) GunsTool.getGunDoubleTag(tag, "Damage", 0), (float) GunsTool.getGunDoubleTag(tag, "Damage"),
(float) GunsTool.getGunDoubleTag(tag, "ExplosionDamage", 0), (float) GunsTool.getGunDoubleTag(tag, "ExplosionDamage"),
(float) GunsTool.getGunDoubleTag(tag, "ExplosionRadius", 0)); (float) GunsTool.getGunDoubleTag(tag, "ExplosionRadius"));
var dmgPerk = PerkHelper.getPerkByType(tag, Perk.Type.DAMAGE); var dmgPerk = PerkHelper.getPerkByType(tag, Perk.Type.DAMAGE);
if (dmgPerk == ModPerks.MONSTER_HUNTER.get()) { if (dmgPerk == ModPerks.MONSTER_HUNTER.get()) {
@ -290,11 +284,11 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, SpecialFireW
gunGrenadeEntity.setNoGravity(PerkHelper.getPerkByType(tag, Perk.Type.AMMO) == ModPerks.MICRO_MISSILE.get()); gunGrenadeEntity.setNoGravity(PerkHelper.getPerkByType(tag, Perk.Type.AMMO) == ModPerks.MICRO_MISSILE.get());
gunGrenadeEntity.charged(isChargedFire); gunGrenadeEntity.charged(isChargedFire);
float velocity = (float) GunsTool.getGunDoubleTag(tag, "Velocity", 0); float velocity = (float) GunsTool.getGunDoubleTag(tag, "Velocity");
int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), tag); int perkLevel = PerkHelper.getItemPerkLevel(ModPerks.MICRO_MISSILE.get(), tag);
if (perkLevel > 0) { if (perkLevel > 0) {
gunGrenadeEntity.setExplosionRadius((float) GunsTool.getGunDoubleTag(tag, "ExplosionRadius", 0) * 0.5f); gunGrenadeEntity.setExplosionRadius((float) GunsTool.getGunDoubleTag(tag, "ExplosionRadius") * 0.5f);
gunGrenadeEntity.setDamage((float) GunsTool.getGunDoubleTag(tag, "Damage", 0) * (1.1f + perkLevel * 0.1f)); gunGrenadeEntity.setDamage((float) GunsTool.getGunDoubleTag(tag, "Damage") * (1.1f + perkLevel * 0.1f));
velocity *= 1.2f; velocity *= 1.2f;
} }
@ -331,7 +325,7 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, SpecialFireW
PacketDistributor.sendToPlayer(serverPlayer, new ShootClientMessage(10)); PacketDistributor.sendToPlayer(serverPlayer, new ShootClientMessage(10));
} }
GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Ammo", 0) - 1); GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Ammo") - 1);
player.getCooldowns().addCooldown(stack.getItem(), 6); player.getCooldowns().addCooldown(stack.getItem(), 6);
} }

View file

@ -3,14 +3,12 @@ package com.atsuishio.superbwarfare.item.gun.machinegun;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.renderer.item.DevotionItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.DevotionItemRenderer;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModPerks; import com.atsuishio.superbwarfare.init.ModPerks;
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.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
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.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.player.LocalPlayer;
@ -87,12 +85,6 @@ public class DevotionItem extends GunItem implements GeoItem {
return Set.of(ModSounds.DEVOTION_RELOAD_EMPTY.get(), ModSounds.DEVOTION_RELOAD_NORMAL.get()); return Set.of(ModSounds.DEVOTION_RELOAD_EMPTY.get(), ModSounds.DEVOTION_RELOAD_NORMAL.get());
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.DEVOTION.get());
GunsTool.initCreativeGun(stack, ModItems.DEVOTION.getId().getPath());
return stack;
}
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return Mod.loc("textures/gun_icon/devotion_icon.png"); return Mod.loc("textures/gun_icon/devotion_icon.png");

View file

@ -3,7 +3,6 @@ package com.atsuishio.superbwarfare.item.gun.machinegun;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.renderer.item.M60ItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.M60ItemRenderer;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModPerks; import com.atsuishio.superbwarfare.init.ModPerks;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.init.ModTags;
@ -105,12 +104,6 @@ public class M60Item extends GunItem implements GeoItem {
return Set.of(ModSounds.M_60_RELOAD_EMPTY.get(), ModSounds.M_60_RELOAD_NORMAL.get()); return Set.of(ModSounds.M_60_RELOAD_EMPTY.get(), ModSounds.M_60_RELOAD_NORMAL.get());
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.M_60.get());
GunsTool.initCreativeGun(stack, ModItems.M_60.getId().getPath());
return stack;
}
@Override @Override
@ParametersAreNonnullByDefault @ParametersAreNonnullByDefault
public void inventoryTick(ItemStack stack, Level level, Entity entity, int slot, boolean selected) { public void inventoryTick(ItemStack stack, Level level, Entity entity, int slot, boolean selected) {
@ -118,7 +111,7 @@ public class M60Item extends GunItem implements GeoItem {
if (tag.getBoolean("draw")) { if (tag.getBoolean("draw")) {
tag.putBoolean("draw", false); tag.putBoolean("draw", false);
if (GunsTool.getGunIntTag(tag, "Ammo", 0) <= 5) { if (GunsTool.getGunIntTag(tag, "Ammo") <= 5) {
GunsTool.setGunBooleanTag(tag, "HideBulletChain", true); GunsTool.setGunBooleanTag(tag, "HideBulletChain", true);
} }
NBTTool.saveTag(stack, tag); NBTTool.saveTag(stack, tag);

View file

@ -3,10 +3,12 @@ package com.atsuishio.superbwarfare.item.gun.machinegun;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.renderer.item.MinigunItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.MinigunItemRenderer;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.init.ModParticleTypes;
import com.atsuishio.superbwarfare.init.ModPerks;
import com.atsuishio.superbwarfare.init.ModRarity;
import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.tools.GunsTool;
import com.atsuishio.superbwarfare.tools.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.ParticleTool;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@ -145,12 +147,6 @@ public class MinigunItem extends GunItem implements GeoItem {
NBTTool.saveTag(stack, tag); NBTTool.saveTag(stack, tag);
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.MINIGUN.get());
GunsTool.initCreativeGun(stack, ModItems.MINIGUN.getId().getPath());
return stack;
}
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return Mod.loc("textures/gun_icon/minigun_icon.png"); return Mod.loc("textures/gun_icon/minigun_icon.png");

View file

@ -3,14 +3,12 @@ package com.atsuishio.superbwarfare.item.gun.machinegun;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.renderer.item.RpkItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.RpkItemRenderer;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModPerks; import com.atsuishio.superbwarfare.init.ModPerks;
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.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
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.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.player.LocalPlayer;
@ -87,12 +85,6 @@ public class RpkItem extends GunItem implements GeoItem {
return Set.of(ModSounds.RPK_RELOAD_EMPTY.get(), ModSounds.RPK_RELOAD_NORMAL.get()); return Set.of(ModSounds.RPK_RELOAD_EMPTY.get(), ModSounds.RPK_RELOAD_NORMAL.get());
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.RPK.get());
GunsTool.initCreativeGun(stack, ModItems.RPK.getId().getPath());
return stack;
}
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return Mod.loc("textures/gun_icon/rpk_icon.png"); return Mod.loc("textures/gun_icon/rpk_icon.png");

View file

@ -4,7 +4,6 @@ import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.capability.ModCapabilities; import com.atsuishio.superbwarfare.capability.ModCapabilities;
import com.atsuishio.superbwarfare.client.renderer.item.AK12ItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.AK12ItemRenderer;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
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.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
@ -134,12 +133,6 @@ public class AK12Item extends GunItem implements GeoItem {
return this.cache; return this.cache;
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.AK_12.get());
GunsTool.initCreativeGun(stack, ModItems.AK_12.getId().getPath());
return stack;
}
@Override @Override
@ParametersAreNonnullByDefault @ParametersAreNonnullByDefault
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) { public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
@ -160,7 +153,7 @@ public class AK12Item extends GunItem implements GeoItem {
double customZoom = switch (scopeType) { double customZoom = switch (scopeType) {
case 0, 1 -> 0; case 0, 1 -> 0;
case 2 -> 2.15; case 2 -> 2.15;
default -> GunsTool.getGunDoubleTag(tag, "CustomZoom", 0); default -> GunsTool.getGunDoubleTag(tag, "CustomZoom");
}; };
tag.putBoolean("CanAdjustZoomFov", scopeType == 3); tag.putBoolean("CanAdjustZoomFov", scopeType == 3);

View file

@ -4,7 +4,6 @@ import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.capability.ModCapabilities; import com.atsuishio.superbwarfare.capability.ModCapabilities;
import com.atsuishio.superbwarfare.client.renderer.item.AK47ItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.AK47ItemRenderer;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
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.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
@ -142,12 +141,6 @@ public class AK47Item extends GunItem implements GeoItem {
return this.cache; return this.cache;
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.AK_47.get());
GunsTool.initCreativeGun(stack, ModItems.AK_47.getId().getPath());
return stack;
}
@Override @Override
@ParametersAreNonnullByDefault @ParametersAreNonnullByDefault
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) { public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
@ -168,7 +161,7 @@ public class AK47Item extends GunItem implements GeoItem {
double customZoom = switch (scopeType) { double customZoom = switch (scopeType) {
case 0, 1 -> 0; case 0, 1 -> 0;
case 2 -> 2.75; case 2 -> 2.75;
default -> GunsTool.getGunDoubleTag(tag, "CustomZoom", 0); default -> GunsTool.getGunDoubleTag(tag, "CustomZoom");
}; };
tag.putBoolean("CanAdjustZoomFov", scopeType == 3); tag.putBoolean("CanAdjustZoomFov", scopeType == 3);

View file

@ -4,7 +4,6 @@ import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.capability.ModCapabilities; import com.atsuishio.superbwarfare.capability.ModCapabilities;
import com.atsuishio.superbwarfare.client.renderer.item.Hk416ItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.Hk416ItemRenderer;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
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.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
@ -150,7 +149,7 @@ public class Hk416Item extends GunItem implements GeoItem {
double customZoom = switch (scopeType) { double customZoom = switch (scopeType) {
case 0, 1 -> 0; case 0, 1 -> 0;
case 2 -> 2.25; case 2 -> 2.25;
default -> GunsTool.getGunDoubleTag(tag, "CustomZoom", 0); default -> GunsTool.getGunDoubleTag(tag, "CustomZoom");
}; };
tag.putBoolean("CanAdjustZoomFov", scopeType == 3); tag.putBoolean("CanAdjustZoomFov", scopeType == 3);
@ -169,12 +168,6 @@ public class Hk416Item extends GunItem implements GeoItem {
return Set.of(ModSounds.HK_416_RELOAD_EMPTY.get(), ModSounds.HK_416_RELOAD_NORMAL.get()); return Set.of(ModSounds.HK_416_RELOAD_EMPTY.get(), ModSounds.HK_416_RELOAD_NORMAL.get());
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.HK_416.get());
GunsTool.initCreativeGun(stack, ModItems.HK_416.getId().getPath());
return stack;
}
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return Mod.loc("textures/gun_icon/hk416_icon.png"); return Mod.loc("textures/gun_icon/hk416_icon.png");

View file

@ -3,13 +3,11 @@ package com.atsuishio.superbwarfare.item.gun.rifle;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.renderer.item.InsidiousItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.InsidiousItemRenderer;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
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.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
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.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.player.LocalPlayer;
@ -78,12 +76,6 @@ public class InsidiousItem extends GunItem implements GeoItem {
return this.cache; return this.cache;
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.INSIDIOUS.get());
GunsTool.initCreativeGun(stack, ModItems.INSIDIOUS.getId().getPath());
return stack;
}
@Override @Override
public Set<SoundEvent> getReloadSound() { public Set<SoundEvent> getReloadSound() {
return Set.of(ModSounds.VECTOR_RELOAD_NORMAL.get(), ModSounds.VECTOR_RELOAD_EMPTY.get()); return Set.of(ModSounds.VECTOR_RELOAD_NORMAL.get(), ModSounds.VECTOR_RELOAD_EMPTY.get());

View file

@ -4,7 +4,6 @@ import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.capability.ModCapabilities; import com.atsuishio.superbwarfare.capability.ModCapabilities;
import com.atsuishio.superbwarfare.client.renderer.item.M4ItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.M4ItemRenderer;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
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.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
@ -142,12 +141,6 @@ public class M4Item extends GunItem implements GeoItem {
return Set.of(ModSounds.M_4_RELOAD_EMPTY.get(), ModSounds.M_4_RELOAD_NORMAL.get()); return Set.of(ModSounds.M_4_RELOAD_EMPTY.get(), ModSounds.M_4_RELOAD_NORMAL.get());
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.M_4.get());
GunsTool.initCreativeGun(stack, ModItems.M_4.getId().getPath());
return stack;
}
@Override @Override
@ParametersAreNonnullByDefault @ParametersAreNonnullByDefault
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) { public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
@ -168,7 +161,7 @@ public class M4Item extends GunItem implements GeoItem {
double customZoom = switch (scopeType) { double customZoom = switch (scopeType) {
case 0, 1 -> 0; case 0, 1 -> 0;
case 2 -> NBTTool.getTag(stack).getBoolean("ScopeAlt") ? 0 : 2.75; case 2 -> NBTTool.getTag(stack).getBoolean("ScopeAlt") ? 0 : 2.75;
default -> GunsTool.getGunDoubleTag(tag, "CustomZoom", 0); default -> GunsTool.getGunDoubleTag(tag, "CustomZoom");
}; };
GunsTool.setGunBooleanTag(tag, "CanSwitchScope", scopeType == 2); GunsTool.setGunBooleanTag(tag, "CanSwitchScope", scopeType == 2);

View file

@ -3,7 +3,6 @@ package com.atsuishio.superbwarfare.item.gun.rifle;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.renderer.item.MarlinItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.MarlinItemRenderer;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
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.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
@ -122,12 +121,6 @@ public class MarlinItem extends GunItem implements GeoItem {
ModSounds.MARLIN_BOLT.get()); ModSounds.MARLIN_BOLT.get());
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.MARLIN.get());
GunsTool.initCreativeGun(stack, ModItems.MARLIN.getId().getPath());
return stack;
}
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return Mod.loc("textures/gun_icon/marlin_icon.png"); return Mod.loc("textures/gun_icon/marlin_icon.png");

View file

@ -4,7 +4,6 @@ import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.capability.ModCapabilities; import com.atsuishio.superbwarfare.capability.ModCapabilities;
import com.atsuishio.superbwarfare.client.renderer.item.Mk14ItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.Mk14ItemRenderer;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
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.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
@ -155,7 +154,7 @@ public class Mk14Item extends GunItem implements GeoItem {
double customZoom = switch (scopeType) { double customZoom = switch (scopeType) {
case 0, 1 -> 0; case 0, 1 -> 0;
case 2 -> 2.25; case 2 -> 2.25;
default -> GunsTool.getGunDoubleTag(tag, "CustomZoom", 0); default -> GunsTool.getGunDoubleTag(tag, "CustomZoom");
}; };
tag.putBoolean("CanAdjustZoomFov", scopeType == 3); tag.putBoolean("CanAdjustZoomFov", scopeType == 3);
@ -169,12 +168,6 @@ public class Mk14Item extends GunItem implements GeoItem {
return Set.of(ModSounds.MK_14_RELOAD_EMPTY.get(), ModSounds.MK_14_RELOAD_NORMAL.get()); return Set.of(ModSounds.MK_14_RELOAD_EMPTY.get(), ModSounds.MK_14_RELOAD_NORMAL.get());
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.MK_14.get());
GunsTool.initCreativeGun(stack, ModItems.MK_14.getId().getPath());
return stack;
}
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return Mod.loc("textures/gun_icon/mk14ebr_icon.png"); return Mod.loc("textures/gun_icon/mk14ebr_icon.png");

View file

@ -4,7 +4,6 @@ import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.capability.ModCapabilities; import com.atsuishio.superbwarfare.capability.ModCapabilities;
import com.atsuishio.superbwarfare.client.renderer.item.Qbz95ItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.Qbz95ItemRenderer;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
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.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
@ -157,7 +156,7 @@ public class Qbz95Item extends GunItem implements GeoItem {
double customZoom = switch (scopeType) { double customZoom = switch (scopeType) {
case 0, 1 -> 0; case 0, 1 -> 0;
case 2 -> 2.15; case 2 -> 2.15;
default -> GunsTool.getGunDoubleTag(rootTag, "CustomZoom", 0); default -> GunsTool.getGunDoubleTag(rootTag, "CustomZoom");
}; };
rootTag.putBoolean("CanAdjustZoomFov", scopeType == 3); rootTag.putBoolean("CanAdjustZoomFov", scopeType == 3);
@ -171,12 +170,6 @@ public class Qbz95Item extends GunItem implements GeoItem {
return Set.of(ModSounds.QBZ_95_RELOAD_EMPTY.get(), ModSounds.QBZ_95_RELOAD_NORMAL.get()); return Set.of(ModSounds.QBZ_95_RELOAD_EMPTY.get(), ModSounds.QBZ_95_RELOAD_NORMAL.get());
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.QBZ_95.get());
GunsTool.initCreativeGun(stack, ModItems.QBZ_95.getId().getPath());
return stack;
}
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return Mod.loc("textures/gun_icon/qbz95_icon.png"); return Mod.loc("textures/gun_icon/qbz95_icon.png");

View file

@ -3,7 +3,6 @@ package com.atsuishio.superbwarfare.item.gun.rifle;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.renderer.item.SksItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.SksItemRenderer;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
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.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
@ -89,12 +88,6 @@ public class SksItem extends GunItem implements GeoItem {
return this.cache; return this.cache;
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.SKS.get());
GunsTool.initCreativeGun(stack, ModItems.SKS.getId().getPath());
return stack;
}
@Override @Override
@ParametersAreNonnullByDefault @ParametersAreNonnullByDefault
public void inventoryTick(ItemStack stack, Level level, Entity entity, int slot, boolean selected) { public void inventoryTick(ItemStack stack, Level level, Entity entity, int slot, boolean selected) {
@ -102,7 +95,7 @@ public class SksItem extends GunItem implements GeoItem {
final var tag = NBTTool.getTag(stack); final var tag = NBTTool.getTag(stack);
tag.putBoolean("draw", false); tag.putBoolean("draw", false);
if (GunsTool.getGunIntTag(tag, "Ammo", 0) == 0) { if (GunsTool.getGunIntTag(tag, "Ammo") == 0) {
GunsTool.setGunBooleanTag(tag, "HoldOpen", true); GunsTool.setGunBooleanTag(tag, "HoldOpen", true);
} }
NBTTool.saveTag(stack, tag); NBTTool.saveTag(stack, tag);

View file

@ -4,11 +4,13 @@ import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.renderer.item.Aa12ItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.Aa12ItemRenderer;
import com.atsuishio.superbwarfare.client.tooltip.component.ShotgunImageComponent; import com.atsuishio.superbwarfare.client.tooltip.component.ShotgunImageComponent;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.init.ModPerks;
import com.atsuishio.superbwarfare.init.ModRarity;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
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.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.player.LocalPlayer;
@ -109,12 +111,6 @@ public class Aa12Item extends GunItem implements GeoItem {
return Set.of(ModSounds.AA_12_RELOAD_EMPTY.get(), ModSounds.AA_12_RELOAD_NORMAL.get()); return Set.of(ModSounds.AA_12_RELOAD_EMPTY.get(), ModSounds.AA_12_RELOAD_NORMAL.get());
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.AA_12.get());
GunsTool.initCreativeGun(stack, ModItems.AA_12.getId().getPath());
return stack;
}
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return Mod.loc("textures/gun_icon/aa_12_icon.png"); return Mod.loc("textures/gun_icon/aa_12_icon.png");

View file

@ -4,13 +4,11 @@ import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.renderer.item.HomemadeShotgunItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.HomemadeShotgunItemRenderer;
import com.atsuishio.superbwarfare.client.tooltip.component.ShotgunImageComponent; import com.atsuishio.superbwarfare.client.tooltip.component.ShotgunImageComponent;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
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.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
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.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.player.LocalPlayer;
@ -90,12 +88,6 @@ public class HomemadeShotgunItem extends GunItem implements GeoItem {
return this.cache; return this.cache;
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.HOMEMADE_SHOTGUN.get());
GunsTool.initCreativeGun(stack, ModItems.HOMEMADE_SHOTGUN.getId().getPath());
return stack;
}
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return Mod.loc("textures/gun_icon/homemade_shotgun_icon.png"); return Mod.loc("textures/gun_icon/homemade_shotgun_icon.png");

View file

@ -4,7 +4,6 @@ import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.renderer.item.M870ItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.M870ItemRenderer;
import com.atsuishio.superbwarfare.client.tooltip.component.ShotgunImageComponent; import com.atsuishio.superbwarfare.client.tooltip.component.ShotgunImageComponent;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
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.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
@ -126,12 +125,6 @@ public class M870Item extends GunItem implements GeoItem {
ModSounds.M_870_BOLT.get()); ModSounds.M_870_BOLT.get());
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.M_870.get());
GunsTool.initCreativeGun(stack, ModItems.M_870.getId().getPath());
return stack;
}
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return Mod.loc("textures/gun_icon/m870_icon.png"); return Mod.loc("textures/gun_icon/m870_icon.png");

View file

@ -4,7 +4,6 @@ import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.capability.ModCapabilities; import com.atsuishio.superbwarfare.capability.ModCapabilities;
import com.atsuishio.superbwarfare.client.renderer.item.VectorItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.VectorItemRenderer;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
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.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
@ -137,7 +136,7 @@ public class VectorItem extends GunItem implements GeoItem {
double customZoom = switch (scopeType) { double customZoom = switch (scopeType) {
case 0, 1 -> 0; case 0, 1 -> 0;
case 2 -> 0.75; case 2 -> 0.75;
default -> GunsTool.getGunDoubleTag(tag, "CustomZoom", 0); default -> GunsTool.getGunDoubleTag(tag, "CustomZoom");
}; };
GunsTool.setGunDoubleTag(tag, "CustomZoom", customZoom); GunsTool.setGunDoubleTag(tag, "CustomZoom", customZoom);
@ -145,12 +144,6 @@ public class VectorItem extends GunItem implements GeoItem {
NBTTool.saveTag(stack, tag); NBTTool.saveTag(stack, tag);
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.VECTOR.get());
GunsTool.initCreativeGun(stack, ModItems.VECTOR.getId().getPath());
return stack;
}
@Override @Override
public Set<SoundEvent> getReloadSound() { public Set<SoundEvent> getReloadSound() {
return Set.of(ModSounds.VECTOR_RELOAD_NORMAL.get(), ModSounds.VECTOR_RELOAD_EMPTY.get()); return Set.of(ModSounds.VECTOR_RELOAD_NORMAL.get(), ModSounds.VECTOR_RELOAD_EMPTY.get());

View file

@ -3,13 +3,11 @@ package com.atsuishio.superbwarfare.item.gun.sniper;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.renderer.item.HuntingRifleItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.HuntingRifleItemRenderer;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
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.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
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.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.player.LocalPlayer;
@ -81,12 +79,6 @@ public class HuntingRifleItem extends GunItem implements GeoItem {
return this.cache; return this.cache;
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.HUNTING_RIFLE.get());
GunsTool.initCreativeGun(stack, ModItems.HUNTING_RIFLE.getId().getPath());
return stack;
}
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return Mod.loc("textures/gun_icon/hunting_rifle_icon.png"); return Mod.loc("textures/gun_icon/hunting_rifle_icon.png");

View file

@ -3,7 +3,6 @@ package com.atsuishio.superbwarfare.item.gun.sniper;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.renderer.item.K98ItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.K98ItemRenderer;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
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.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
@ -128,12 +127,6 @@ public class K98Item extends GunItem implements GeoItem {
); );
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.K_98.get());
GunsTool.initCreativeGun(stack, ModItems.K_98.getId().getPath());
return stack;
}
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return Mod.loc("textures/gun_icon/k98_icon.png"); return Mod.loc("textures/gun_icon/k98_icon.png");

View file

@ -3,7 +3,6 @@ package com.atsuishio.superbwarfare.item.gun.sniper;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.renderer.item.M98bItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.M98bItemRenderer;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
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.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
@ -105,12 +104,6 @@ public class M98bItem extends GunItem implements GeoItem {
return Set.of(ModSounds.M_98B_RELOAD_EMPTY.get(), ModSounds.M_98B_RELOAD_NORMAL.get(), ModSounds.M_98B_BOLT.get()); return Set.of(ModSounds.M_98B_RELOAD_EMPTY.get(), ModSounds.M_98B_RELOAD_NORMAL.get(), ModSounds.M_98B_BOLT.get());
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.M_98B.get());
GunsTool.initCreativeGun(stack, ModItems.M_98B.getId().getPath());
return stack;
}
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return Mod.loc("textures/gun_icon/m98b_icon.png"); return Mod.loc("textures/gun_icon/m98b_icon.png");

View file

@ -3,7 +3,6 @@ package com.atsuishio.superbwarfare.item.gun.sniper;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.renderer.item.MosinNagantItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.MosinNagantItemRenderer;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
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.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
@ -56,11 +55,11 @@ public class MosinNagantItem extends GunItem implements GeoItem {
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.mosin.shift")); return event.setAndContinue(RawAnimation.begin().thenPlay("animation.mosin.shift"));
} }
if (NBTTool.getTag(stack).getInt("reload_stage") == 1 && GunsTool.getGunIntTag(tag, "Ammo", 0) == 0) { if (NBTTool.getTag(stack).getInt("reload_stage") == 1 && GunsTool.getGunIntTag(tag, "Ammo") == 0) {
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.mosin.prepare_empty")); return event.setAndContinue(RawAnimation.begin().thenPlay("animation.mosin.prepare_empty"));
} }
if (NBTTool.getTag(stack).getInt("reload_stage") == 1 && GunsTool.getGunIntTag(tag, "Ammo", 0) > 0) { if (NBTTool.getTag(stack).getInt("reload_stage") == 1 && GunsTool.getGunIntTag(tag, "Ammo") > 0) {
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.mosin.prepare")); return event.setAndContinue(RawAnimation.begin().thenPlay("animation.mosin.prepare"));
} }
@ -128,12 +127,6 @@ public class MosinNagantItem extends GunItem implements GeoItem {
); );
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.MOSIN_NAGANT.get());
GunsTool.initCreativeGun(stack, ModItems.MOSIN_NAGANT.getId().getPath());
return stack;
}
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return Mod.loc("textures/gun_icon/mosin_nagant_icon.png"); return Mod.loc("textures/gun_icon/mosin_nagant_icon.png");

View file

@ -4,7 +4,6 @@ import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.renderer.item.SentinelItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.SentinelItemRenderer;
import com.atsuishio.superbwarfare.client.tooltip.component.SentinelImageComponent; import com.atsuishio.superbwarfare.client.tooltip.component.SentinelImageComponent;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModRarity; import com.atsuishio.superbwarfare.init.ModRarity;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.init.ModTags;
@ -142,7 +141,7 @@ public class SentinelItem extends GunItem implements GeoItem, EnergyStorageItem
if (cap != null && cap.getEnergyStored() > 0) { if (cap != null && cap.getEnergyStored() > 0) {
cap.extractEnergy(1, false); cap.extractEnergy(1, false);
GunsTool.setGunDoubleTag(tag, "ChargedDamage", 0.2857142857142857 GunsTool.setGunDoubleTag(tag, "ChargedDamage", 0.2857142857142857
* GunsTool.getGunDoubleTag(tag, "Damage", 0)); * GunsTool.getGunDoubleTag(tag, "Damage"));
} else { } else {
GunsTool.setGunDoubleTag(tag, "ChargedDamage", 0); GunsTool.setGunDoubleTag(tag, "ChargedDamage", 0);
} }
@ -159,12 +158,6 @@ public class SentinelItem extends GunItem implements GeoItem, EnergyStorageItem
); );
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.SENTINEL.get());
GunsTool.initCreativeGun(stack, ModItems.SENTINEL.getId().getPath());
return stack;
}
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return Mod.loc("textures/gun_icon/sentinel_icon.png"); return Mod.loc("textures/gun_icon/sentinel_icon.png");

View file

@ -4,7 +4,6 @@ import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.capability.ModCapabilities; import com.atsuishio.superbwarfare.capability.ModCapabilities;
import com.atsuishio.superbwarfare.client.renderer.item.SvdItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.SvdItemRenderer;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
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.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
@ -107,12 +106,6 @@ public class SvdItem extends GunItem implements GeoItem {
return Set.of(ModSounds.SVD_RELOAD_EMPTY.get(), ModSounds.SVD_RELOAD_NORMAL.get()); return Set.of(ModSounds.SVD_RELOAD_EMPTY.get(), ModSounds.SVD_RELOAD_NORMAL.get());
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.SVD.get());
GunsTool.initCreativeGun(stack, ModItems.SVD.getId().getPath());
return stack;
}
@Override @Override
@ParametersAreNonnullByDefault @ParametersAreNonnullByDefault
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) { public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
@ -131,7 +124,7 @@ public class SvdItem extends GunItem implements GeoItem {
double customZoom = switch (scopeType) { double customZoom = switch (scopeType) {
case 0, 1 -> 0; case 0, 1 -> 0;
case 2 -> 3.75; case 2 -> 3.75;
default -> GunsTool.getGunDoubleTag(tag, "CustomZoom", 0); default -> GunsTool.getGunDoubleTag(tag, "CustomZoom");
}; };
tag.putBoolean("CanAdjustZoomFov", scopeType == 3); tag.putBoolean("CanAdjustZoomFov", scopeType == 3);

View file

@ -134,12 +134,6 @@ public class BocekItem extends GunItem implements GeoItem, SpecialFireWeapon {
return stack.getItem() == Items.ARROW; return stack.getItem() == Items.ARROW;
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.BOCEK.get());
GunsTool.initCreativeGun(stack, ModItems.BOCEK.getId().getPath());
return stack;
}
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return Mod.loc("textures/gun_icon/bocek_icon.png"); return Mod.loc("textures/gun_icon/bocek_icon.png");

View file

@ -193,16 +193,6 @@ public class TaserItem extends GunItem implements GeoItem, SpecialFireWeapon, En
return stack.getItem() == ModItems.TASER_ELECTRODE.get(); return stack.getItem() == ModItems.TASER_ELECTRODE.get();
} }
public static ItemStack getGunInstance() {
ItemStack stack = new ItemStack(ModItems.TASER.get());
GunsTool.initCreativeGun(stack, ModItems.TASER.getId().getPath());
var cap = stack.getCapability(Capabilities.EnergyStorage.ITEM);
if (cap != null) {
cap.receiveEnergy(MAX_ENERGY, false);
}
return stack;
}
@Override @Override
public ResourceLocation getGunIcon() { public ResourceLocation getGunIcon() {
return Mod.loc("textures/gun_icon/taser_icon.png"); return Mod.loc("textures/gun_icon/taser_icon.png");
@ -243,7 +233,7 @@ public class TaserItem extends GunItem implements GeoItem, SpecialFireWeapon, En
var hasEnoughEnergy = energyStorage != null && energyStorage.getEnergyStored() >= 400 + 100 * perkLevel; var hasEnoughEnergy = energyStorage != null && energyStorage.getEnergyStored() >= 400 + 100 * perkLevel;
if (player.getCooldowns().isOnCooldown(stack.getItem()) if (player.getCooldowns().isOnCooldown(stack.getItem())
|| GunsTool.getGunIntTag(tag, "Ammo", 0) <= 0 || GunsTool.getGunIntTag(tag, "Ammo") <= 0
|| !hasEnoughEnergy || !hasEnoughEnergy
) return; ) return;
@ -263,17 +253,17 @@ public class TaserItem extends GunItem implements GeoItem, SpecialFireWeapon, En
var level = serverPlayer.level(); var level = serverPlayer.level();
TaserBulletEntity taserBulletProjectile = new TaserBulletEntity(player, level, TaserBulletEntity taserBulletProjectile = new TaserBulletEntity(player, level,
(float) GunsTool.getGunDoubleTag(tag, "Damage", 0), volt, wireLength); (float) GunsTool.getGunDoubleTag(tag, "Damage"), volt, wireLength);
taserBulletProjectile.setPos(player.getX(), player.getEyeY() - 0.1, player.getZ()); taserBulletProjectile.setPos(player.getX(), player.getEyeY() - 0.1, player.getZ());
taserBulletProjectile.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, (float) GunsTool.getGunDoubleTag(tag, "Velocity", 0), taserBulletProjectile.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, (float) GunsTool.getGunDoubleTag(tag, "Velocity"),
(float) (zoom ? 0.1 : spread)); (float) (zoom ? 0.1 : spread));
level.addFreshEntity(taserBulletProjectile); level.addFreshEntity(taserBulletProjectile);
PacketDistributor.sendToPlayer(serverPlayer, new ShootClientMessage(10)); PacketDistributor.sendToPlayer(serverPlayer, new ShootClientMessage(10));
} }
GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Ammo", 0) - 1); GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Ammo") - 1);
energyStorage.extractEnergy(400 + 100 * perkLevel, false); energyStorage.extractEnergy(400 + 100 * perkLevel, false);
tag.putBoolean("shoot", true); tag.putBoolean("shoot", true);
} }

View file

@ -115,7 +115,7 @@ public class ReforgingTableMenu extends AbstractContainerMenu {
if (!this.moveItemStackTo(stack, INPUT_SLOT, INPUT_SLOT + 1, false)) { if (!this.moveItemStackTo(stack, INPUT_SLOT, INPUT_SLOT + 1, false)) {
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }
} else if (stack.getItem() instanceof PerkItem perkItem) { } else if (stack.getItem() instanceof PerkItem<?> perkItem) {
Perk.Type type = perkItem.getPerk().type; Perk.Type type = perkItem.getPerk().type;
if (type == Perk.Type.AMMO) { if (type == Perk.Type.AMMO) {
if (!this.moveItemStackTo(stack, AMMO_PERK_SLOT, AMMO_PERK_SLOT + 1, false)) { if (!this.moveItemStackTo(stack, AMMO_PERK_SLOT, AMMO_PERK_SLOT + 1, false)) {
@ -209,7 +209,7 @@ public class ReforgingTableMenu extends AbstractContainerMenu {
} }
final var tag = NBTTool.getTag(stack); final var tag = NBTTool.getTag(stack);
double oldPoint = GunsTool.getGunDoubleTag(tag, "UpgradePoint", 0); double oldPoint = GunsTool.getGunDoubleTag(tag, "UpgradePoint");
int point = (int) oldPoint; int point = (int) oldPoint;
int newPoint = this.upgradePoint.get(); int newPoint = this.upgradePoint.get();
int delta = newPoint - point; int delta = newPoint - point;
@ -295,15 +295,15 @@ public class ReforgingTableMenu extends AbstractContainerMenu {
int level = PerkHelper.getItemPerkLevel(perkItem.getPerk(), tag); int level = PerkHelper.getItemPerkLevel(perkItem.getPerk(), tag);
if (level <= 0) { if (level <= 0) {
this.upgradePoint.set((int) GunsTool.getGunDoubleTag(tag, "UpgradePoint", 0)); this.upgradePoint.set((int) GunsTool.getGunDoubleTag(tag, "UpgradePoint"));
return; return;
} }
ItemStack output = gun.copy(); ItemStack output = gun.copy();
final var outputTag = NBTTool.getTag(output); final var outputTag = NBTTool.getTag(output);
PerkHelper.removePerkByType(outputTag, perkItem.getPerk().type); PerkHelper.removePerkByType(outputTag, perkItem.getPerk().type);
GunsTool.setGunDoubleTag(outputTag, "UpgradePoint", Math.min(MAX_UPGRADE_POINT, level - 1 + GunsTool.getGunDoubleTag(outputTag, "UpgradePoint", 0))); GunsTool.setGunDoubleTag(outputTag, "UpgradePoint", Math.min(MAX_UPGRADE_POINT, level - 1 + GunsTool.getGunDoubleTag(outputTag, "UpgradePoint")));
this.upgradePoint.set((int) GunsTool.getGunDoubleTag(outputTag, "UpgradePoint", 0)); this.upgradePoint.set((int) GunsTool.getGunDoubleTag(outputTag, "UpgradePoint"));
NBTTool.saveTag(output, outputTag); NBTTool.saveTag(output, outputTag);
this.container.setItem(INPUT_SLOT, output); this.container.setItem(INPUT_SLOT, output);
@ -338,7 +338,7 @@ public class ReforgingTableMenu extends AbstractContainerMenu {
return; return;
} }
final var tag = NBTTool.getTag(stack); final var tag = NBTTool.getTag(stack);
int point = (int) GunsTool.getGunDoubleTag(tag, "UpgradePoint", 0); int point = (int) GunsTool.getGunDoubleTag(tag, "UpgradePoint");
this.upgradePoint.set(Mth.clamp(point, 0, MAX_UPGRADE_POINT)); this.upgradePoint.set(Mth.clamp(point, 0, MAX_UPGRADE_POINT));
var ammoPerk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO); var ammoPerk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);

View file

@ -39,30 +39,30 @@ public record AdjustZoomFovMessage(double scroll) implements CustomPacketPayload
double minRpm = 300; double minRpm = 300;
double maxRpm = 2400; double maxRpm = 2400;
GunsTool.setGunIntTag(tag, "RPM", (int) Mth.clamp(GunsTool.getGunIntTag(tag, "RPM", 0) + 50 * message.scroll, minRpm, maxRpm)); GunsTool.setGunIntTag(tag, "RPM", (int) Mth.clamp(GunsTool.getGunIntTag(tag, "RPM") + 50 * message.scroll, minRpm, maxRpm));
if (GunsTool.getGunIntTag(tag, "RPM", 0) == 1150) { if (GunsTool.getGunIntTag(tag, "RPM") == 1150) {
GunsTool.setGunIntTag(tag, "RPM", 1145); GunsTool.setGunIntTag(tag, "RPM", 1145);
} }
if (GunsTool.getGunIntTag(tag, "RPM", 0) == 1195) { if (GunsTool.getGunIntTag(tag, "RPM") == 1195) {
GunsTool.setGunIntTag(tag, "RPM", 1200); GunsTool.setGunIntTag(tag, "RPM", 1200);
} }
if (GunsTool.getGunIntTag(tag, "RPM", 0) == 1095) { if (GunsTool.getGunIntTag(tag, "RPM") == 1095) {
GunsTool.setGunIntTag(tag, "RPM", 1100); GunsTool.setGunIntTag(tag, "RPM", 1100);
} }
player.displayClientMessage(Component.literal("RPM: " + FormatTool.format0D(GunsTool.getGunIntTag(tag, "RPM", 0))), true); player.displayClientMessage(Component.literal("RPM: " + FormatTool.format0D(GunsTool.getGunIntTag(tag, "RPM"))), true);
int rpm = GunsTool.getGunIntTag(tag, "RPM", 0); int rpm = GunsTool.getGunIntTag(tag, "RPM");
if (rpm > minRpm && rpm < maxRpm) { if (rpm > minRpm && rpm < maxRpm) {
SoundTool.playLocalSound(player, ModSounds.ADJUST_FOV.get(), 1f, 0.7f); SoundTool.playLocalSound(player, ModSounds.ADJUST_FOV.get(), 1f, 0.7f);
} }
} else { } else {
double minZoom = GunsTool.getGunDoubleTag(tag, "MinZoom", 0) - 1.25; double minZoom = GunsTool.getGunDoubleTag(tag, "MinZoom") - 1.25;
double maxZoom = GunsTool.getGunDoubleTag(tag, "MaxZoom", 0) - 1.25; double maxZoom = GunsTool.getGunDoubleTag(tag, "MaxZoom") - 1.25;
double customZoom = GunsTool.getGunDoubleTag(tag, "CustomZoom", 0); double customZoom = GunsTool.getGunDoubleTag(tag, "CustomZoom");
GunsTool.setGunDoubleTag(tag, "CustomZoom", Mth.clamp(customZoom + 0.5 * message.scroll, minZoom, maxZoom)); GunsTool.setGunDoubleTag(tag, "CustomZoom", Mth.clamp(customZoom + 0.5 * message.scroll, minZoom, maxZoom));
if (GunsTool.getGunDoubleTag(tag, "CustomZoom", 0) > minZoom && if (GunsTool.getGunDoubleTag(tag, "CustomZoom") > minZoom &&
GunsTool.getGunDoubleTag(tag, "CustomZoom", 0) < maxZoom) { GunsTool.getGunDoubleTag(tag, "CustomZoom") < maxZoom) {
SoundTool.playLocalSound(player, ModSounds.ADJUST_FOV.get(), 1f, 0.7f); SoundTool.playLocalSound(player, ModSounds.ADJUST_FOV.get(), 1f, 0.7f);
} }
} }

View file

@ -51,7 +51,7 @@ public record FireMessage(int msgType) implements CustomPacketPayload {
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE); var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
if (type == 0) { if (type == 0) {
if (tag.getDouble("prepare") == 0 && GunsTool.getGunBooleanTag(tag, "Reloading") && GunsTool.getGunIntTag(tag, "Ammo", 0) > 0) { if (tag.getDouble("prepare") == 0 && GunsTool.getGunBooleanTag(tag, "Reloading") && GunsTool.getGunIntTag(tag, "Ammo") > 0) {
tag.putDouble("force_stop", 1); tag.putDouble("force_stop", 1);
NBTTool.saveTag(stack, tag); NBTTool.saveTag(stack, tag);
} }
@ -90,15 +90,15 @@ public record FireMessage(int msgType) implements CustomPacketPayload {
private static void handleGunBolt(Player player, ItemStack stack, final CompoundTag tag) { private static void handleGunBolt(Player player, ItemStack stack, final CompoundTag tag) {
if (!stack.is(ModTags.Items.GUN)) return; if (!stack.is(ModTags.Items.GUN)) return;
if (GunsTool.getGunIntTag(tag, "BoltActionTime", 0) > 0 if (GunsTool.getGunIntTag(tag, "BoltActionTime") > 0
&& GunsTool.getGunIntTag(tag, "Ammo", 0) > (stack.is(ModTags.Items.REVOLVER) ? -1 : 0) && GunsTool.getGunIntTag(tag, "Ammo") > (stack.is(ModTags.Items.REVOLVER) ? -1 : 0)
&& GunsTool.getGunIntTag(tag, "BoltActionTick") == 0 && GunsTool.getGunIntTag(tag, "BoltActionTick") == 0
&& !(tag.getBoolean("is_normal_reloading") && !(tag.getBoolean("is_normal_reloading")
|| tag.getBoolean("is_empty_reloading")) || tag.getBoolean("is_empty_reloading"))
&& !GunsTool.getGunBooleanTag(tag, "Reloading") && !GunsTool.getGunBooleanTag(tag, "Reloading")
&& !GunsTool.getGunBooleanTag(tag, "Charging")) { && !GunsTool.getGunBooleanTag(tag, "Charging")) {
if (!player.getCooldowns().isOnCooldown(stack.getItem()) && GunsTool.getGunBooleanTag(tag, "NeedBoltAction", false)) { if (!player.getCooldowns().isOnCooldown(stack.getItem()) && GunsTool.getGunBooleanTag(tag, "NeedBoltAction")) {
GunsTool.setGunIntTag(tag, "BoltActionTick", GunsTool.getGunIntTag(tag, "BoltActionTime", 0) + 1); GunsTool.setGunIntTag(tag, "BoltActionTick", GunsTool.getGunIntTag(tag, "BoltActionTime") + 1);
GunEventHandler.playGunBoltSounds(player); GunEventHandler.playGunBoltSounds(player);
} }
} }
@ -126,9 +126,9 @@ public record FireMessage(int msgType) implements CustomPacketPayload {
if (player.level().isClientSide()) return; if (player.level().isClientSide()) return;
var perk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO); var perk = PerkHelper.getPerkByType(tag, Perk.Type.AMMO);
float headshot = (float) GunsTool.getGunDoubleTag(tag, "Headshot", 0); float headshot = (float) GunsTool.getGunDoubleTag(tag, "Headshot");
float velocity = 2 * (float) GunsTool.getGunDoubleTag(tag, "Power", 6) * (float) perkSpeed(tag); float velocity = 2 * (float) GunsTool.getGunDoubleTag(tag, "Power", 6) * (float) perkSpeed(tag);
float bypassArmorRate = (float) GunsTool.getGunDoubleTag(tag, "BypassesArmor", 0); float bypassArmorRate = (float) GunsTool.getGunDoubleTag(tag, "BypassesArmor");
double damage; double damage;
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE); var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
@ -137,12 +137,12 @@ public record FireMessage(int msgType) implements CustomPacketPayload {
float spread; float spread;
if (zoom) { if (zoom) {
spread = 0.01f; spread = 0.01f;
damage = 0.08333333 * GunsTool.getGunDoubleTag(tag, "Damage", 0) * damage = 0.08333333 * GunsTool.getGunDoubleTag(tag, "Damage") *
GunsTool.getGunDoubleTag(tag, "Power", 6) * perkDamage(stack); GunsTool.getGunDoubleTag(tag, "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(tag, "Damage", 0) * GunsTool.getGunDoubleTag(tag, "Damage") *
GunsTool.getGunDoubleTag(tag, "Power", 6) * perkDamage(stack); GunsTool.getGunDoubleTag(tag, "Power", 6) * perkDamage(stack);
} }

View file

@ -109,7 +109,7 @@ public record FireModeMessage(int msgType) implements CustomPacketPayload {
} }
} }
if (stack.getItem() == ModItems.TRACHELIUM.get() && !GunsTool.getGunBooleanTag(tag, "NeedBoltAction", false)) { if (stack.getItem() == ModItems.TRACHELIUM.get() && !GunsTool.getGunBooleanTag(tag, "NeedBoltAction")) {
tag.putBoolean("DA", !tag.getBoolean("DA")); tag.putBoolean("DA", !tag.getBoolean("DA"));
NBTTool.saveTag(stack, tag); NBTTool.saveTag(stack, tag);
if (!tag.getBoolean("canImmediatelyShoot")) { if (!tag.getBoolean("canImmediatelyShoot")) {

View file

@ -50,7 +50,7 @@ public record ReloadMessage(int msgType) implements CustomPacketPayload {
) { ) {
boolean canSingleReload = gunItem.isIterativeReload(stack); boolean canSingleReload = gunItem.isIterativeReload(stack);
boolean canReload = gunItem.isMagazineReload(stack) && !gunItem.isClipReload(stack); boolean canReload = gunItem.isMagazineReload(stack) && !gunItem.isClipReload(stack);
boolean clipLoad = GunsTool.getGunIntTag(tag, "Ammo", 0) == 0 && gunItem.isClipReload(stack); boolean clipLoad = GunsTool.getGunIntTag(tag, "Ammo") == 0 && gunItem.isClipReload(stack);
// 检查备弹 // 检查备弹
boolean hasCreativeAmmoBox = player.getInventory().hasAnyMatching(item -> item.is(ModItems.CREATIVE_AMMO_BOX.get())); boolean hasCreativeAmmoBox = player.getInventory().hasAnyMatching(item -> item.is(ModItems.CREATIVE_AMMO_BOX.get()));
@ -74,9 +74,9 @@ public record ReloadMessage(int msgType) implements CustomPacketPayload {
} }
if (canReload || clipLoad) { if (canReload || clipLoad) {
int magazine = GunsTool.getGunIntTag(tag, "Magazine", 0); int magazine = GunsTool.getGunIntTag(tag, "Magazine");
int ammo = GunsTool.getGunIntTag(tag, "Ammo", 0); int ammo = GunsTool.getGunIntTag(tag, "Ammo");
int customMagazine = GunsTool.getGunIntTag(tag, "CustomMagazine", 0); int customMagazine = GunsTool.getGunIntTag(tag, "CustomMagazine");
if (gunItem.isOpenBolt(stack)) { if (gunItem.isOpenBolt(stack)) {
if (gunItem.hasBulletInBarrel(stack)) { if (gunItem.hasBulletInBarrel(stack)) {
@ -94,9 +94,9 @@ public record ReloadMessage(int msgType) implements CustomPacketPayload {
} }
if (canSingleReload if (canSingleReload
&& GunsTool.getGunIntTag(tag, "Ammo", 0) && GunsTool.getGunIntTag(tag, "Ammo")
< GunsTool.getGunIntTag(tag, "Magazine", 0) < GunsTool.getGunIntTag(tag, "Magazine")
+ GunsTool.getGunIntTag(tag, "CustomMagazine", 0)) { + GunsTool.getGunIntTag(tag, "CustomMagazine")) {
tag.putBoolean("start_single_reload", true); tag.putBoolean("start_single_reload", true);
} }

View file

@ -45,9 +45,9 @@ public record ShootMessage(double spread) implements CustomPacketPayload {
if (stack.is(ModTags.Items.NORMAL_GUN)) { if (stack.is(ModTags.Items.NORMAL_GUN)) {
int projectileAmount = GunsTool.getGunIntTag(tag, "ProjectileAmount", 1); int projectileAmount = GunsTool.getGunIntTag(tag, "ProjectileAmount", 1);
if (GunsTool.getGunIntTag(tag, "Ammo", 0) > 0) { if (GunsTool.getGunIntTag(tag, "Ammo") > 0) {
// 空仓挂机 // 空仓挂机
if (GunsTool.getGunIntTag(tag, "Ammo", 0) == 1) { if (GunsTool.getGunIntTag(tag, "Ammo") == 1) {
GunsTool.setGunBooleanTag(tag, "HoldOpen", true); GunsTool.setGunBooleanTag(tag, "HoldOpen", true);
} }
@ -56,14 +56,14 @@ public record ShootMessage(double spread) implements CustomPacketPayload {
} }
// 判断是否为栓动武器BoltActionTime > 0并在开火后给一个需要上膛的状态 // 判断是否为栓动武器BoltActionTime > 0并在开火后给一个需要上膛的状态
if (GunsTool.getGunIntTag(tag, "BoltActionTime", 0) > 0 && GunsTool.getGunIntTag(tag, "Ammo", 0) > (stack.is(ModTags.Items.REVOLVER) ? 0 : 1)) { if (GunsTool.getGunIntTag(tag, "BoltActionTime") > 0 && GunsTool.getGunIntTag(tag, "Ammo") > (stack.is(ModTags.Items.REVOLVER) ? 0 : 1)) {
GunsTool.setGunBooleanTag(tag, "NeedBoltAction", true); GunsTool.setGunBooleanTag(tag, "NeedBoltAction", true);
} }
GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Ammo", 0) - 1); GunsTool.setGunIntTag(tag, "Ammo", GunsTool.getGunIntTag(tag, "Ammo") - 1);
tag.putDouble("empty", 1); tag.putDouble("empty", 1);
if (stack.getItem() == ModItems.M_60.get() && GunsTool.getGunIntTag(tag, "Ammo", 0) <= 5) { if (stack.getItem() == ModItems.M_60.get() && GunsTool.getGunIntTag(tag, "Ammo") <= 5) {
GunsTool.setGunBooleanTag(tag, "HideBulletChain", true); GunsTool.setGunBooleanTag(tag, "HideBulletChain", true);
} }

View file

@ -10,9 +10,9 @@ import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.event.OnDatapackSyncEvent;
import net.neoforged.neoforge.event.entity.player.PlayerEvent; import net.neoforged.neoforge.event.entity.player.PlayerEvent;
import net.neoforged.neoforge.event.server.ServerStartedEvent; import net.neoforged.neoforge.event.server.ServerStartedEvent;
import net.neoforged.neoforge.network.PacketDistributor; import net.neoforged.neoforge.network.PacketDistributor;
@ -21,6 +21,7 @@ import javax.annotation.Nullable;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.HashMap; import java.util.HashMap;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
@EventBusSubscriber(modid = Mod.MODID) @EventBusSubscriber(modid = Mod.MODID)
public class GunsTool { public class GunsTool {
@ -53,26 +54,26 @@ public class GunsTool {
} }
} }
public static void initGun(Level level, final CompoundTag tag, String location) { public static void initGun(final CompoundTag tag, String location) {
if (level.getServer() == null) return; if (gunsData != null && gunsData.get(location) != null) {
gunsData.get(location).forEach((k, v) -> {
CompoundTag data = tag.getCompound("GunData"); CompoundTag data = tag.getCompound("GunData");
data.putDouble(k, v);
gunsData.get(location).forEach(data::putDouble);
data.putBoolean("Init", true);
tag.put("GunData", data); tag.put("GunData", data);
}); }
} }
public static void initCreativeGun(ItemStack stack, String location) { public static void initCreativeGun(final CompoundTag tag, String location) {
if (gunsData != null && gunsData.get(location) != null) { var fillAmmo = !tag.getCompound("GunData").getBoolean("Init");
final var tag = NBTTool.getTag(stack);
gunsData.get(location).forEach((k, v) -> { initGun(tag, location);
CompoundTag data = tag.getCompound("GunData");
data.putDouble(k, v); if (fillAmmo) {
tag.put("GunData", data);
});
var data = tag.getCompound("GunData"); var data = tag.getCompound("GunData");
data.putInt("Ammo", data.getInt("Magazine") + data.getInt("CustomMagazine")); data.putInt("Ammo", GunsTool.getGunIntTag(tag, "Magazine")
NBTTool.saveTag(stack, tag); + GunsTool.getGunIntTag(tag, "CustomMagazine")
);
} }
} }
@ -83,6 +84,17 @@ public class GunsTool {
tag.put("GunData", data); tag.put("GunData", data);
} }
public static double getGunDefaultData(final CompoundTag tag, String name) {
var id = tag.getString("id");
if (!tag.getBoolean("init")) {
return GunsTool.gunsData
.getOrDefault(id, new HashMap<>())
.getOrDefault(name, 0.0);
}
return getGunDoubleTag(tag, name);
}
@SubscribeEvent @SubscribeEvent
public static void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) { public static void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) {
if (event.getEntity() instanceof ServerPlayer player) { if (event.getEntity() instanceof ServerPlayer player) {
@ -95,6 +107,19 @@ public class GunsTool {
initJsonData(event.getServer().getResourceManager()); initJsonData(event.getServer().getResourceManager());
} }
@SubscribeEvent
public static void datapackSync(OnDatapackSyncEvent event) {
AtomicInteger count = new AtomicInteger();
event.getRelevantPlayers().forEach(player -> {
if (count.get() == 0 && player.getServer() != null) {
initJsonData(player.getServer().getResourceManager());
}
count.getAndIncrement();
PacketDistributor.sendToPlayer(player, new GunsDataMessage(GunsTool.gunsData));
});
}
public static void reload(Player player, ItemStack stack, final CompoundTag tag, AmmoType type) { public static void reload(Player player, ItemStack stack, final CompoundTag tag, AmmoType type) {
reload(player, stack, tag, type, false); reload(player, stack, tag, type, false);
} }
@ -202,7 +227,9 @@ public class GunsTool {
} }
public static int getGunIntTag(final CompoundTag tag, String name) { public static int getGunIntTag(final CompoundTag tag, String name) {
return getGunIntTag(tag, name, 0); var data = tag.getCompound("GunData");
if (!data.contains(name)) return (int) getGunDefaultData(tag, name);
return data.getInt(name);
} }
public static int getGunIntTag(final CompoundTag tag, String name, int defaultValue) { public static int getGunIntTag(final CompoundTag tag, String name, int defaultValue) {
@ -218,7 +245,9 @@ public class GunsTool {
} }
public static double getGunDoubleTag(final CompoundTag tag, String name) { public static double getGunDoubleTag(final CompoundTag tag, String name) {
return getGunDoubleTag(tag, name, 0); var data = tag.getCompound("GunData");
if (!data.contains(name) && !tag.getBoolean("init")) return getGunDefaultData(tag, name);
return data.getDouble(name);
} }
public static double getGunDoubleTag(final CompoundTag tag, String name, double defaultValue) { public static double getGunDoubleTag(final CompoundTag tag, String name, double defaultValue) {
@ -234,12 +263,8 @@ public class GunsTool {
} }
public static boolean getGunBooleanTag(final CompoundTag tag, String name) { public static boolean getGunBooleanTag(final CompoundTag tag, String name) {
return getGunBooleanTag(tag, name, false);
}
public static boolean getGunBooleanTag(final CompoundTag tag, String name, boolean defaultValue) {
var data = tag.getCompound("GunData"); var data = tag.getCompound("GunData");
if (!data.contains(name)) return defaultValue; if (!data.contains(name)) return getGunDefaultData(tag, name) != 0;
return data.getBoolean(name); return data.getBoolean(name);
} }

View file

@ -1,9 +0,0 @@
{
"type": "minecraft:blasting",
"cookingtime": 100,
"experience": 0.3,
"ingredient": {
"tag": "c:dusts/silver"
},
"result": "superbwarfare:silver_ingot"
}

View file

@ -1,10 +0,0 @@
{
"type": "minecraft:blasting",
"category": "misc",
"experience": 4,
"cookingtime": 400,
"ingredient": {
"item": "superbwarfare:scheelite"
},
"result": "superbwarfare:tungsten_ingot"
}

View file

@ -1,10 +0,0 @@
{
"type": "minecraft:blasting",
"category": "misc",
"experience": 4,
"cookingtime": 200,
"ingredient": {
"item": "superbwarfare:tungsten_powder"
},
"result": "superbwarfare:tungsten_ingot"
}

View file

@ -1,9 +0,0 @@
{
"type": "minecraft:blasting",
"cookingtime": 100,
"experience": 0.3,
"ingredient": {
"tag": "c:dusts/tungsten"
},
"result": "superbwarfare:tungsten_ingot"
}