添加加特林调整射速的功能

This commit is contained in:
Atsuihsio 2024-11-08 22:04:25 +08:00
parent ecbca1a2ed
commit e118632e3c
10 changed files with 130 additions and 50 deletions

View file

@ -1,4 +1,4 @@
// 1.20.1 2024-11-08T20:06:16.3248238 Tags for minecraft:item mod id superbwarfare // 1.20.1 2024-11-08T20:57:48.1853892 Tags for minecraft:item mod id superbwarfare
cf8d49a8d2872286d1a9c3d4a7e1c2b7690db0b8 data/forge/tags/items/dusts.json cf8d49a8d2872286d1a9c3d4a7e1c2b7690db0b8 data/forge/tags/items/dusts.json
0fa06c2ff83bf09797e3ddff90f62d1124e645b4 data/forge/tags/items/dusts/coal_coke.json 0fa06c2ff83bf09797e3ddff90f62d1124e645b4 data/forge/tags/items/dusts/coal_coke.json
295ddf906b7133a0558d03e9a60eea18281fe430 data/forge/tags/items/dusts/iron.json 295ddf906b7133a0558d03e9a60eea18281fe430 data/forge/tags/items/dusts/iron.json
@ -36,7 +36,7 @@ af6fd64b4a685c353f243763db268f7b2304c009 data/forge/tags/items/storage_blocks/le
dff9ff6d6637951191906cb55a210ae5a3ad5cd6 data/superbwarfare/tags/items/extra_one_ammo.json dff9ff6d6637951191906cb55a210ae5a3ad5cd6 data/superbwarfare/tags/items/extra_one_ammo.json
52598e22974c8da0d2852defe4c9005e1d67744b data/superbwarfare/tags/items/gun.json 52598e22974c8da0d2852defe4c9005e1d67744b data/superbwarfare/tags/items/gun.json
62eb408544731ce4cfcd119d8a6cc74731189ac0 data/superbwarfare/tags/items/handgun.json 62eb408544731ce4cfcd119d8a6cc74731189ac0 data/superbwarfare/tags/items/handgun.json
835c071e873ee7061e36e1361026897b39487bd6 data/superbwarfare/tags/items/has_shell_effect.json 49fbb8c030fdfafec1f291acc1cdff406c777c7e data/superbwarfare/tags/items/has_shell_effect.json
dae3f86663e841d336efff9d23d8910aa7247be5 data/superbwarfare/tags/items/is_auto_weapon.json dae3f86663e841d336efff9d23d8910aa7247be5 data/superbwarfare/tags/items/is_auto_weapon.json
68ec25b0ccd68abbbe2f33ab7097572c2140c9da data/superbwarfare/tags/items/launcher.json 68ec25b0ccd68abbbe2f33ab7097572c2140c9da data/superbwarfare/tags/items/launcher.json
b404c6fd99d2ca68c6738f225cb7d68ee443c10a data/superbwarfare/tags/items/machine_gun.json b404c6fd99d2ca68c6738f225cb7d68ee443c10a data/superbwarfare/tags/items/machine_gun.json

View file

@ -15,7 +15,6 @@
"superbwarfare:glock_17", "superbwarfare:glock_17",
"superbwarfare:glock_18", "superbwarfare:glock_18",
"superbwarfare:m_1911", "superbwarfare:m_1911",
"superbwarfare:qbz_95", "superbwarfare:qbz_95"
"superbwarfare:minigun"
] ]
} }

View file

@ -143,7 +143,7 @@ public class ClickHandler {
if (tag.getBoolean("CanSwitchScope")) { if (tag.getBoolean("CanSwitchScope")) {
ModUtils.PACKET_HANDLER.sendToServer(new SwitchScopeMessage(scroll)); ModUtils.PACKET_HANDLER.sendToServer(new SwitchScopeMessage(scroll));
} }
else if (tag.getBoolean("CanAdjustZoomFov")) { else if (tag.getBoolean("CanAdjustZoomFov") || stack.is(ModItems.MINIGUN.get())) {
ModUtils.PACKET_HANDLER.sendToServer(new AdjustZoomFovMessage(scroll)); ModUtils.PACKET_HANDLER.sendToServer(new AdjustZoomFovMessage(scroll));
} }
event.setCanceled(true); event.setCanceled(true);

View file

@ -61,7 +61,9 @@ public class MinigunItemModel extends GeoModel<MinigunItem> {
heat_barrels.setScaleZ(4 * heat); heat_barrels.setScaleZ(4 * heat);
gun.setRotZ(gun.getRotZ() + times * -0.18f * ClientEventHandler.miniGunRot); int rpm = stack.getOrCreateTag().getInt("rpm");
gun.setRotZ(gun.getRotZ() + times * -0.07f * ((float) rpm / 1200) * ClientEventHandler.miniGunRot);
shen.setPosX((float) (0.75f * ClientEventHandler.recoilHorizon * fpz * fp)); shen.setPosX((float) (0.75f * ClientEventHandler.recoilHorizon * fpz * fp));
shen.setPosY((float) (-0.03f * fp - 0.06f * fr)); shen.setPosY((float) (-0.03f * fp - 0.06f * fr));

View file

@ -27,6 +27,7 @@ public class AmmoBarOverlay {
private static final ResourceLocation AUTO = ModUtils.loc("textures/gun_icon/fire_mode/auto.png"); private static final ResourceLocation AUTO = ModUtils.loc("textures/gun_icon/fire_mode/auto.png");
private static final ResourceLocation TOP = ModUtils.loc("textures/gun_icon/fire_mode/top.png"); private static final ResourceLocation TOP = ModUtils.loc("textures/gun_icon/fire_mode/top.png");
private static final ResourceLocation DIR = ModUtils.loc("textures/gun_icon/fire_mode/dir.png"); private static final ResourceLocation DIR = ModUtils.loc("textures/gun_icon/fire_mode/dir.png");
private static final ResourceLocation MOUSE = ModUtils.loc("textures/gun_icon/fire_mode/mouse.png");
private static boolean creativeAmmo() { private static boolean creativeAmmo() {
Player player = Minecraft.getInstance().player; Player player = Minecraft.getInstance().player;
@ -69,6 +70,7 @@ public class AmmoBarOverlay {
16); 16);
// 渲染开火模式切换按键 // 渲染开火模式切换按键
if (stack.getItem() != ModItems.MINIGUN.get()) {
event.getGuiGraphics().drawString( event.getGuiGraphics().drawString(
Minecraft.getInstance().font, Minecraft.getInstance().font,
"[" + ModKeyMappings.FIRE_MODE.getKey().getDisplayName().getString() + "]", "[" + ModKeyMappings.FIRE_MODE.getKey().getDisplayName().getString() + "]",
@ -77,6 +79,7 @@ public class AmmoBarOverlay {
0xFFFFFF, 0xFFFFFF,
false false
); );
}
// 渲染开火模式 // 渲染开火模式
ResourceLocation fireMode = getFireMode(stack); ResourceLocation fireMode = getFireMode(stack);
@ -85,6 +88,28 @@ public class AmmoBarOverlay {
fireMode = stack.getOrCreateTag().getBoolean("TopMode") ? TOP : DIR; fireMode = stack.getOrCreateTag().getBoolean("TopMode") ? TOP : DIR;
} }
if (stack.getItem() == ModItems.MINIGUN.get()) {
fireMode = MOUSE;
// 渲染加特林射速
event.getGuiGraphics().drawString(
Minecraft.getInstance().font,
stack.getOrCreateTag().getInt("rpm") + " RPM",
w - 111f,
h - 20,
0xFFFFFF,
false
);
event.getGuiGraphics().blit(fireMode,
w - 126,
h - 22,
0,
0,
12,
12,
12,
12);
} else {
event.getGuiGraphics().blit(fireMode, event.getGuiGraphics().blit(fireMode,
w - 95, w - 95,
h - 21, h - 21,
@ -94,7 +119,9 @@ public class AmmoBarOverlay {
8, 8,
8, 8,
8); 8);
}
if (stack.getItem() != ModItems.MINIGUN.get()) {
event.getGuiGraphics().blit(LINE, event.getGuiGraphics().blit(LINE,
w - 95, w - 95,
h - 16, h - 16,
@ -104,6 +131,7 @@ public class AmmoBarOverlay {
8, 8,
8, 8,
8); 8);
}
// 渲染当前弹药量 // 渲染当前弹药量
poseStack.pushPose(); poseStack.pushPose();

View file

@ -112,7 +112,7 @@ public class ModItemTagProvider extends ItemTagsProvider {
this.tag(ModTags.Items.HAS_SHELL_EFFECT).add(ModItems.AK_47.get(), ModItems.AK_12.get(), ModItems.SVD.get(), ModItems.M_60.get(), ModItems.MK_14.get(), ModItems.VECTOR.get(), this.tag(ModTags.Items.HAS_SHELL_EFFECT).add(ModItems.AK_47.get(), ModItems.AK_12.get(), ModItems.SVD.get(), ModItems.M_60.get(), ModItems.MK_14.get(), ModItems.VECTOR.get(),
ModItems.SKS.get(), ModItems.RPK.get(), ModItems.HK_416.get(), ModItems.AA_12.get(), ModItems.M_4.get(), ModItems.DEVOTION.get(), ModItems.GLOCK_17.get(), ModItems.SKS.get(), ModItems.RPK.get(), ModItems.HK_416.get(), ModItems.AA_12.get(), ModItems.M_4.get(), ModItems.DEVOTION.get(), ModItems.GLOCK_17.get(),
ModItems.GLOCK_18.get(), ModItems.M_1911.get(), ModItems.QBZ_95.get(), ModItems.MINIGUN.get()); ModItems.GLOCK_18.get(), ModItems.M_1911.get(), ModItems.QBZ_95.get());
this.tag(ModTags.Items.MILITARY_ARMOR).add(ModItems.RU_CHEST_6B43.get(), ModItems.US_CHEST_IOTV.get()); this.tag(ModTags.Items.MILITARY_ARMOR).add(ModItems.RU_CHEST_6B43.get(), ModItems.US_CHEST_IOTV.get());

View file

@ -170,7 +170,12 @@ public class ClientEventHandler {
if (stack.getItem() == ModItems.MINIGUN.get()) { if (stack.getItem() == ModItems.MINIGUN.get()) {
if (holdFire || GLFW.glfwGetMouseButton(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_MOUSE_BUTTON_RIGHT) == GLFW.GLFW_PRESS) { if (holdFire || GLFW.glfwGetMouseButton(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_MOUSE_BUTTON_RIGHT) == GLFW.GLFW_PRESS) {
miniGunRot = Math.min(miniGunRot + 5, 21); miniGunRot = Math.min(miniGunRot + 5, 21);
player.playSound(ModSounds.MINIGUN_ROT.get(), 1, 1); float rpm = 1;
if (player.getMainHandItem().is(ModItems.MINIGUN.get())) {
rpm = (float) player.getMainHandItem().getOrCreateTag().getInt("rpm") / 3600;
}
player.playSound(ModSounds.MINIGUN_ROT.get(), 1, 0.7f + rpm);
} }
} }
@ -260,7 +265,11 @@ public class ClientEventHandler {
&& stack.getOrCreateTag().getInt("ammo") > 0 && stack.getOrCreateTag().getInt("ammo") > 0
&& !player.getCooldowns().isOnCooldown(stack.getItem()) && !player.getCooldowns().isOnCooldown(stack.getItem())
&& !stack.getOrCreateTag().getBoolean("need_bolt_action")) && !stack.getOrCreateTag().getBoolean("need_bolt_action"))
|| (stack.is(ModItems.MINIGUN.get()) && !player.isSprinting() && stack.getOrCreateTag().getDouble("overheat") == 0 && !player.getCooldowns().isOnCooldown(stack.getItem()) && miniGunRot >= 20 || (stack.is(ModItems.MINIGUN.get())
&& !player.isSprinting()
&& stack.getOrCreateTag().getDouble("overheat") == 0
&& !player.getCooldowns().isOnCooldown(stack.getItem()) && miniGunRot >= 20
&& ((player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).rifleAmmo > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())))
))) { ))) {
if (mode == 0) { if (mode == 0) {
@ -352,6 +361,13 @@ public class ClientEventHandler {
if (perk == ModPerks.BEAST_BULLET.get()) { if (perk == ModPerks.BEAST_BULLET.get()) {
player.playSound(ModSounds.HENG.get(), 1f, 1f); player.playSound(ModSounds.HENG.get(), 1f, 1f);
} }
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())));
ModUtils.queueClientWork((int) (1 + 1.5 * shooterHeight), () -> {
player.playSound(ModSounds.SHELL_CASING_NORMAL.get(), (float) Math.max(1.5 - 0.2 * shooterHeight, 0), 1);
});
} }
handleClientShoot(); handleClientShoot();
@ -709,6 +725,12 @@ public class ClientEventHandler {
fireRotTimer += 0.18 * (1.9 - fireRotTimer) * times; fireRotTimer += 0.18 * (1.9 - fireRotTimer) * times;
} }
double rpm = 1;
if (entity.getMainHandItem().is(ModItems.MINIGUN.get())) {
rpm = (double) entity.getMainHandItem().getOrCreateTag().getInt("rpm") / 1800;
}
float[] shake = {0, 0}; float[] shake = {0, 0};
shake[0] = (float) (1.3 * amplitude * (1 / 6.3 * (fireRotTimer - 0.5)) * Math.sin(6.3 * (fireRotTimer - 0.5)) * (3 - Math.pow(fireRotTimer, 2)) + 1 * Mth.clamp(0.3 - fireRotTimer, 0, 1) * (2 * Math.random() - 1)); shake[0] = (float) (1.3 * amplitude * (1 / 6.3 * (fireRotTimer - 0.5)) * Math.sin(6.3 * (fireRotTimer - 0.5)) * (3 - Math.pow(fireRotTimer, 2)) + 1 * Mth.clamp(0.3 - fireRotTimer, 0, 1) * (2 * Math.random() - 1));
shake[1] = (float) (4.2 * amplitude * (1 / 6.3 * (fireRotTimer - 0.5)) * Math.sin(6.3 * (fireRotTimer - 0.5)) * (3 - Math.pow(fireRotTimer, 2)) + 3 * Mth.clamp(0.5 - fireRotTimer, 0, 0.5) * (2 * Math.random() - 1)); shake[1] = (float) (4.2 * amplitude * (1 / 6.3 * (fireRotTimer - 0.5)) * Math.sin(6.3 * (fireRotTimer - 0.5)) * (3 - Math.pow(fireRotTimer, 2)) + 3 * Mth.clamp(0.5 - fireRotTimer, 0, 0.5) * (2 * Math.random() - 1));
@ -716,13 +738,13 @@ public class ClientEventHandler {
if (0 < fireRotTimer && fireRotTimer < 1.732) { if (0 < fireRotTimer && fireRotTimer < 1.732) {
fireRot = 1 / 6.3 * (fireRotTimer - 0.5) * Math.sin(6.3 * (fireRotTimer - 0.5)) * (3 - Math.pow(fireRotTimer, 2)); fireRot = 1 / 6.3 * (fireRotTimer - 0.5) * Math.sin(6.3 * (fireRotTimer - 0.5)) * (3 - Math.pow(fireRotTimer, 2));
if (recoilY > 0) { if (recoilY > 0) {
event.setYaw(yaw - shake[0]); event.setYaw((float) (yaw - shake[0] * rpm));
event.setPitch(pitch + shake[0]); event.setPitch((float) (pitch + shake[0] * rpm));
event.setRoll(roll + shake[1]); event.setRoll((float) (roll + shake[1] * rpm));
} else if (recoilY <= 0) { } else if (recoilY <= 0) {
event.setYaw(yaw + shake[0]); event.setYaw((float) (yaw + shake[0] * rpm));
event.setPitch(pitch - shake[0]); event.setPitch((float) (pitch - shake[0] * rpm));
event.setRoll(roll - shake[1]); event.setRoll((float) (roll - shake[1] * rpm));
} }
} }
@ -786,6 +808,12 @@ public class ClientEventHandler {
double cusWeight = player.getMainHandItem().getOrCreateTag().getDouble("CustomWeight"); double cusWeight = player.getMainHandItem().getOrCreateTag().getDouble("CustomWeight");
double rpm = 1;
if (player.getMainHandItem().is(ModItems.MINIGUN.get())) {
rpm = (double) player.getMainHandItem().getOrCreateTag().getInt("rpm") / 1800;
}
float gunRecoilX = (float) tag.getDouble("recoil_x") * 60; float gunRecoilX = (float) tag.getDouble("recoil_x") * 60;
recoilHorizon = Mth.lerp(0.2 * times, recoilHorizon, 0) + recoilY; recoilHorizon = Mth.lerp(0.2 * times, recoilHorizon, 0) + recoilY;
@ -806,7 +834,7 @@ public class ClientEventHandler {
// 水平后座 // 水平后座
float newYaw = player.getYRot() - (float) (0.6 * recoilHorizon * pose * times * (0.5 + fireSpread) * recoil * (1 - 0.06 * cusWeight) * gripRecoilX); float newYaw = player.getYRot() - (float) (0.6 * recoilHorizon * pose * times * (0.5 + fireSpread) * recoil * (1 - 0.06 * cusWeight) * gripRecoilX * rpm);
player.setYRot(newYaw); player.setYRot(newYaw);
player.yRotO = player.getYRot(); player.yRotO = player.getYRot();
@ -814,7 +842,7 @@ public class ClientEventHandler {
// 竖直后座 // 竖直后座
if (0 < recoilTime && recoilTime < 0.5) { if (0 < recoilTime && recoilTime < 0.5) {
float newPitch = (float) (player.getXRot() - 0.02f * gunRecoilX * times * recoil * (1 - 0.06 * cusWeight) * gripRecoilY); float newPitch = (float) (player.getXRot() - 0.02f * gunRecoilX * times * recoil * (1 - 0.06 * cusWeight) * gripRecoilY * rpm);
player.setXRot(newPitch); player.setXRot(newPitch);
player.xRotO = player.getXRot(); player.xRotO = player.getXRot();
} }
@ -830,7 +858,7 @@ public class ClientEventHandler {
} }
if (0 < recoilTime && recoilTime < 2.5) { if (0 < recoilTime && recoilTime < 2.5) {
float newPitch = player.getXRot() - (float) (1.5 * pose * gunRecoilX * (sinRes + Mth.clamp(0.5 - recoilTime, 0, 0.5)) * times * (0.5 + fireSpread) * recoil * (1 - 0.06 * cusWeight) * gripRecoilY); float newPitch = player.getXRot() - (float) (1.5 * pose * gunRecoilX * (sinRes + Mth.clamp(0.5 - recoilTime, 0, 0.5)) * times * (0.5 + fireSpread) * recoil * (1 - 0.06 * cusWeight) * gripRecoilY * rpm);
player.setXRot(newPitch); player.setXRot(newPitch);
player.xRotO = player.getXRot(); player.xRotO = player.getXRot();
} }

View file

@ -1,9 +1,11 @@
package net.mcreator.superbwarfare.network.message; package net.mcreator.superbwarfare.network.message;
import net.mcreator.superbwarfare.init.ModItems;
import net.mcreator.superbwarfare.init.ModSounds; import net.mcreator.superbwarfare.init.ModSounds;
import net.mcreator.superbwarfare.init.ModTags; import net.mcreator.superbwarfare.init.ModTags;
import net.mcreator.superbwarfare.tools.SoundTool; import net.mcreator.superbwarfare.tools.SoundTool;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -39,13 +41,34 @@ public class AdjustZoomFovMessage {
} }
var tag = stack.getOrCreateTag(); var tag = stack.getOrCreateTag();
if (stack.is(ModItems.MINIGUN.get())) {
double minRpm = 300;
double maxRpm = 2400;
tag.putInt("rpm", (int) Mth.clamp(tag.getInt("rpm") + 50 * message.scroll, minRpm, maxRpm));
if (tag.getInt("rpm") == 1150) {
tag.putInt("rpm", 1145);
}
if (tag.getInt("rpm") == 1195) {
tag.putInt("rpm", 1200);
}
if (tag.getInt("rpm") == 1095) {
tag.putInt("rpm", 1100);
}
player.displayClientMessage(Component.literal("Rpm:" + new java.text.DecimalFormat("##").format(tag.getInt("rpm"))), true);
if (tag.getInt("rpm") > minRpm && tag.getInt("rpm") < maxRpm) {
SoundTool.playLocalSound(player, ModSounds.ADJUST_FOV.get(), 1f, 0.7f);
}
} else {
double min_zoom = tag.getDouble("MinZoom") - 1.25; double min_zoom = tag.getDouble("MinZoom") - 1.25;
double max_zoom = tag.getDouble("MaxZoom") - 1.25; double max_zoom = tag.getDouble("MaxZoom") - 1.25;
tag.putDouble("CustomZoom", Mth.clamp(tag.getDouble("CustomZoom") + 0.5 * message.scroll, min_zoom, max_zoom)); tag.putDouble("CustomZoom", Mth.clamp(tag.getDouble("CustomZoom") + 0.5 * message.scroll, min_zoom, max_zoom));
if (tag.getDouble("CustomZoom") > min_zoom && tag.getDouble("CustomZoom") < max_zoom) { if (tag.getDouble("CustomZoom") > min_zoom && tag.getDouble("CustomZoom") < max_zoom) {
SoundTool.playLocalSound(player, ModSounds.ADJUST_FOV.get(), 1f, 0.7f); SoundTool.playLocalSound(player, ModSounds.ADJUST_FOV.get(), 1f, 0.7f);
} }
}
}); });
context.get().setPacketHandled(true); context.get().setPacketHandled(true);
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 270 B

View file

@ -10,5 +10,5 @@
"projectile_amount": 1, "projectile_amount": 1,
"BypassesArmor": 0.3, "BypassesArmor": 0.3,
"SoundRadius": 14, "SoundRadius": 14,
"rpm": 2400 "rpm": 1200
} }