大幅优化了恶劣环境下射击连续性问题
This commit is contained in:
parent
33fa1bae26
commit
3c7717303e
5 changed files with 126 additions and 67 deletions
|
@ -61,7 +61,7 @@ public class MinigunItemModel extends GeoModel<MinigunItem> {
|
|||
|
||||
heat_barrels.setScaleZ(4 * heat);
|
||||
|
||||
gun.setRotZ((float) (gun.getRotZ() + times * -0.008f * stack.getOrCreateTag().getDouble("minigun_rotation")));
|
||||
gun.setRotZ((float) (gun.getRotZ() + times * -0.18f * stack.getOrCreateTag().getDouble("minigun_rotation")));
|
||||
|
||||
shen.setPosX((float) (0.75f * ClientEventHandler.recoilHorizon * fpz * fp));
|
||||
shen.setPosY((float) (-0.03f * fp - 0.06f * fr));
|
||||
|
|
|
@ -69,7 +69,7 @@ public class SentinelItemModel extends GeoModel<SentinelItem> {
|
|||
gun.setScaleZ(1f - (0.7f * (float) zp));
|
||||
|
||||
scope.setScaleZ(1f - (0.8f * (float) zp));
|
||||
cb.setRotZ(cb.getRotZ() + times * 0.03f * (float) (stack.getOrCreateTag().getDouble("chamber_rot")));
|
||||
cb.setRotZ(cb.getRotZ() + times * (float) (stack.getOrCreateTag().getDouble("chamber_rot")));
|
||||
|
||||
CoreGeoBone holo = getAnimationProcessor().getBone("holo");
|
||||
holo.setPosY(0.09f);
|
||||
|
|
|
@ -4,10 +4,7 @@ import net.mcreator.superbwarfare.ModUtils;
|
|||
import net.mcreator.superbwarfare.config.client.DisplayConfig;
|
||||
import net.mcreator.superbwarfare.entity.DroneEntity;
|
||||
import net.mcreator.superbwarfare.entity.ICannonEntity;
|
||||
import net.mcreator.superbwarfare.init.ModItems;
|
||||
import net.mcreator.superbwarfare.init.ModMobEffects;
|
||||
import net.mcreator.superbwarfare.init.ModPerks;
|
||||
import net.mcreator.superbwarfare.init.ModTags;
|
||||
import net.mcreator.superbwarfare.init.*;
|
||||
import net.mcreator.superbwarfare.network.ModVariables;
|
||||
import net.mcreator.superbwarfare.network.message.ShootMessage;
|
||||
import net.mcreator.superbwarfare.perk.AmmoPerk;
|
||||
|
@ -21,6 +18,8 @@ import net.minecraft.client.Minecraft;
|
|||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
|
@ -36,14 +35,17 @@ import net.minecraftforge.client.event.RenderGuiOverlayEvent;
|
|||
import net.minecraftforge.client.event.RenderHandEvent;
|
||||
import net.minecraftforge.client.event.ViewportEvent;
|
||||
import net.minecraftforge.client.gui.overlay.VanillaGuiOverlay;
|
||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.network.NetworkEvent;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import software.bernie.geckolib.core.animatable.model.CoreGeoBone;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static net.mcreator.superbwarfare.entity.DroneEntity.ROT_X;
|
||||
|
@ -205,6 +207,13 @@ public class ClientEventHandler {
|
|||
&& drawTime < 0.01
|
||||
&& !notInGame()
|
||||
&& !player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).edit
|
||||
&& ((GLFW.glfwGetMouseButton(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_MOUSE_BUTTON_LEFT) == GLFW.GLFW_PRESS || stack.getOrCreateTag().getInt("burst_fire") > 0)
|
||||
&& !(stack.getOrCreateTag().getBoolean("is_normal_reloading") || stack.getOrCreateTag().getBoolean("is_empty_reloading"))
|
||||
&& !stack.getOrCreateTag().getBoolean("reloading")
|
||||
&& !stack.getOrCreateTag().getBoolean("charging")
|
||||
&& stack.getOrCreateTag().getInt("ammo") > 0
|
||||
&& !player.getCooldowns().isOnCooldown(stack.getItem())
|
||||
&& !stack.getOrCreateTag().getBoolean("need_bolt_action"))
|
||||
|| (stack.is(ModItems.MINIGUN.get()) && !player.isSprinting() && stack.getOrCreateTag().getDouble("overheat") == 0 && !player.getCooldowns().isOnCooldown(stack.getItem()) && stack.getOrCreateTag().getDouble("minigun_rotation") >= 10
|
||||
))) {
|
||||
double customRpm = 0;
|
||||
|
@ -239,6 +248,7 @@ public class ClientEventHandler {
|
|||
}
|
||||
|
||||
if (clientTimer.getProgress() >= cooldown) {
|
||||
shootClient(player);
|
||||
ModUtils.PACKET_HANDLER.sendToServer(new ShootMessage(spread));
|
||||
clientTimer.setProgress((long) (clientTimer.getProgress() - cooldown));
|
||||
}
|
||||
|
@ -253,6 +263,106 @@ public class ClientEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
public static void shootClient(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (stack.is(ModTags.Items.NORMAL_GUN)) {
|
||||
|
||||
if (stack.getOrCreateTag().getInt("ammo") > 0) {
|
||||
|
||||
playGunClientSounds(player);
|
||||
handleClientShoot();
|
||||
}
|
||||
} else if (stack.is(ModItems.MINIGUN.get())) {
|
||||
var tag = stack.getOrCreateTag();
|
||||
|
||||
|
||||
if ((player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).rifleAmmo > 0
|
||||
|| player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) {
|
||||
|
||||
var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
|
||||
float pitch = tag.getDouble("heat") <= 40 ? 1 : (float) (1 - 0.025 * Math.abs(40 - tag.getDouble("heat")));
|
||||
|
||||
player.playSound(ModSounds.MINIGUN_FIRE_1P.get(), 2f, pitch);
|
||||
|
||||
if (perk == ModPerks.BEAST_BULLET.get()) {
|
||||
player.playSound(ModSounds.HENG.get(), 4f, 1f);
|
||||
}
|
||||
}
|
||||
|
||||
handleClientShoot();
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleClientShoot() {
|
||||
Player player = Minecraft.getInstance().player;
|
||||
if (player == null) return;
|
||||
CompoundTag tag = player.getMainHandItem().getOrCreateTag();
|
||||
if (!player.getMainHandItem().is(ModTags.Items.GUN)) return;
|
||||
|
||||
fireRecoilTime = 10;
|
||||
|
||||
float gunRecoilY = (float) tag.getDouble("recoil_y") * 10;
|
||||
recoilY = (float) (2 * Math.random() - 1) * gunRecoilY;
|
||||
|
||||
}
|
||||
|
||||
public static void playGunClientSounds(Player player) {
|
||||
ItemStack stack = player.getMainHandItem();
|
||||
if (!stack.is(ModTags.Items.GUN)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String origin = stack.getItem().getDescriptionId();
|
||||
String name = origin.substring(origin.lastIndexOf(".") + 1);
|
||||
|
||||
if (stack.getItem() == ModItems.SENTINEL.get()) {
|
||||
AtomicBoolean charged = new AtomicBoolean(false);
|
||||
|
||||
stack.getCapability(ForgeCapabilities.ENERGY).ifPresent(
|
||||
e -> charged.set(e.getEnergyStored() > 0)
|
||||
);
|
||||
|
||||
if (charged.get()) {
|
||||
SoundEvent sound1p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(ModUtils.MODID, "sentinel_charge_fire_1p"));
|
||||
if (sound1p != null) {
|
||||
player.playSound(sound1p, 2, 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO);
|
||||
|
||||
if (perk == ModPerks.BEAST_BULLET.get()) {
|
||||
player.playSound(ModSounds.HENG.get(), 4f, 1f);
|
||||
}
|
||||
|
||||
int barrelType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.BARREL);
|
||||
|
||||
SoundEvent sound1p = ForgeRegistries.SOUND_EVENTS.getValue(ModUtils.loc(name + (barrelType == 2 ? "_fire_1p_s" : "_fire_1p")));
|
||||
|
||||
if (sound1p != null) {
|
||||
player.playSound(sound1p, 2, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleFireRecoilTimeMessage(double time, Supplier<NetworkEvent.Context> ctx) {
|
||||
if (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT) {
|
||||
Player player = Minecraft.getInstance().player;
|
||||
if (player == null) return;
|
||||
if (!player.getMainHandItem().is(ModTags.Items.GUN)) return;
|
||||
|
||||
|
||||
// fireRecoilTime = time;
|
||||
shellIndex++;
|
||||
shellIndexTime[shellIndex] = 0.001;
|
||||
|
||||
randomShell[0] = (1 + 0.2 * (Math.random() - 0.5));
|
||||
randomShell[1] = (0.2 + (Math.random() - 0.5));
|
||||
randomShell[2] = (0.7 + (Math.random() - 0.5));
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void handleWeaponBreathSway(TickEvent.RenderTickEvent event) {
|
||||
Player player = Minecraft.getInstance().player;
|
||||
|
@ -486,28 +596,6 @@ public class ClientEventHandler {
|
|||
zoomPosZ = -Math.pow(2 * zoomTime - 1, 2) + 1;
|
||||
}
|
||||
|
||||
public static void handleFireRecoilTimeMessage(double time, Supplier<NetworkEvent.Context> ctx) {
|
||||
if (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT) {
|
||||
Player player = Minecraft.getInstance().player;
|
||||
if (player == null) return;
|
||||
CompoundTag tag = player.getMainHandItem().getOrCreateTag();
|
||||
if (!player.getMainHandItem().is(ModTags.Items.GUN)) return;
|
||||
|
||||
fireRecoilTime = time;
|
||||
shellIndex++;
|
||||
|
||||
shellIndexTime[shellIndex] = 0.001;
|
||||
|
||||
randomShell[0] = (1 + 0.2 * (Math.random() - 0.5));
|
||||
randomShell[1] = (0.2 + (Math.random() - 0.5));
|
||||
randomShell[2] = (0.7 + (Math.random() - 0.5));
|
||||
|
||||
float gunRecoilY = (float) tag.getDouble("recoil_y") * 10;
|
||||
recoilY = (float) (2 * Math.random() - 1) * gunRecoilY;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static void handleWeaponFire(ViewportEvent.ComputeCameraAngles event, LivingEntity entity) {
|
||||
float times = 2f * Math.min(Minecraft.getInstance().getDeltaFrameTime(), 0.48f);
|
||||
float yaw = event.getYaw();
|
||||
|
|
|
@ -18,7 +18,6 @@ import net.minecraft.nbt.CompoundTag;
|
|||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
@ -116,24 +115,19 @@ public class GunEventHandler {
|
|||
);
|
||||
|
||||
if (charged.get()) {
|
||||
SoundEvent sound1p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(ModUtils.MODID, "sentinel_charge_fire_1p"));
|
||||
if (sound1p != null && player instanceof ServerPlayer serverPlayer) {
|
||||
SoundTool.playLocalSound(serverPlayer, sound1p, 2f, 1f);
|
||||
}
|
||||
|
||||
SoundEvent sound3p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(ModUtils.MODID, "sentinel_charge_fire_3p"));
|
||||
if (sound3p != null) {
|
||||
player.level().playSound(null, player.getOnPos(), sound3p, SoundSource.PLAYERS, (float) stack.getOrCreateTag().getDouble("SoundRadius") * 0.4f, 1f);
|
||||
player.playSound(sound3p, (float) stack.getOrCreateTag().getDouble("SoundRadius") * 0.4f, 1f);
|
||||
}
|
||||
|
||||
SoundEvent soundFar = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(ModUtils.MODID, "sentinel_charge_far"));
|
||||
if (soundFar != null) {
|
||||
player.level().playSound(null, player.getOnPos(), soundFar, SoundSource.PLAYERS, (float) stack.getOrCreateTag().getDouble("SoundRadius") * 0.7f, 1f);
|
||||
player.playSound(soundFar, (float) stack.getOrCreateTag().getDouble("SoundRadius") * 0.7f, 1f);
|
||||
}
|
||||
|
||||
SoundEvent soundVeryFar = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(ModUtils.MODID, "sentinel_charge_veryfar"));
|
||||
if (soundVeryFar != null) {
|
||||
player.level().playSound(null, player.getOnPos(), soundVeryFar, SoundSource.PLAYERS, (float) stack.getOrCreateTag().getDouble("SoundRadius"), 1f);
|
||||
player.playSound(soundVeryFar, (float) stack.getOrCreateTag().getDouble("SoundRadius"), 1f);
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -144,34 +138,25 @@ public class GunEventHandler {
|
|||
|
||||
if (perk == ModPerks.BEAST_BULLET.get()) {
|
||||
player.playSound(ModSounds.HENG.get(), 4f, 1f);
|
||||
|
||||
if (player instanceof ServerPlayer serverPlayer) {
|
||||
SoundTool.playLocalSound(serverPlayer, ModSounds.HENG.get(), 4f, 1f);
|
||||
}
|
||||
}
|
||||
|
||||
float soundRadius = (float) (stack.getOrCreateTag().getDouble("SoundRadius") * stack.getOrCreateTag().getDouble("CustomSoundRadius"));
|
||||
|
||||
int barrelType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.BARREL);
|
||||
|
||||
SoundEvent sound1p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(ModUtils.MODID, name + (barrelType == 2 ? "_fire_1p_s" : "_fire_1p")));
|
||||
if (sound1p != null && player instanceof ServerPlayer serverPlayer) {
|
||||
SoundTool.playLocalSound(serverPlayer, sound1p, 2f, 1f);
|
||||
}
|
||||
|
||||
SoundEvent sound3p = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(ModUtils.MODID, name + (barrelType == 2 ? "_fire_3p_s" : "_fire_3p")));
|
||||
if (sound3p != null) {
|
||||
player.level().playSound(null, player.getOnPos(), sound3p, SoundSource.PLAYERS, soundRadius * 0.4f, 1f);
|
||||
player.playSound(sound3p, soundRadius * 0.4f, 1f);
|
||||
}
|
||||
|
||||
SoundEvent soundFar = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(ModUtils.MODID, name + (barrelType == 2 ? "_far_s" : "_far")));
|
||||
if (soundFar != null) {
|
||||
player.level().playSound(null, player.getOnPos(), soundFar, SoundSource.PLAYERS, soundRadius * 0.7f, 1f);
|
||||
player.playSound(soundFar, soundRadius * 0.7f, 1f);
|
||||
}
|
||||
|
||||
SoundEvent soundVeryFar = ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation(ModUtils.MODID, name + (barrelType == 2 ? "_veryfar_s" : "_veryfar")));
|
||||
if (soundVeryFar != null) {
|
||||
player.level().playSound(null, player.getOnPos(), soundVeryFar, SoundSource.PLAYERS, soundRadius, 1f);
|
||||
player.playSound(soundVeryFar, soundRadius, 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,13 +70,7 @@ public class ShootMessage {
|
|||
double mode = stack.getOrCreateTag().getInt("fire_mode");
|
||||
int projectileAmount = (int) stack.getOrCreateTag().getDouble("projectile_amount");
|
||||
|
||||
if (((player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).holdFire || stack.getOrCreateTag().getInt("burst_fire") > 0)
|
||||
&& !(stack.getOrCreateTag().getBoolean("is_normal_reloading") || stack.getOrCreateTag().getBoolean("is_empty_reloading"))
|
||||
&& !stack.getOrCreateTag().getBoolean("reloading")
|
||||
&& !stack.getOrCreateTag().getBoolean("charging")
|
||||
&& stack.getOrCreateTag().getInt("ammo") > 0
|
||||
&& !player.getCooldowns().isOnCooldown(stack.getItem())
|
||||
&& !stack.getOrCreateTag().getBoolean("need_bolt_action")) {
|
||||
if (stack.getOrCreateTag().getInt("ammo") > 0) {
|
||||
|
||||
int singleInterval = 0;
|
||||
int burstCooldown = 0;
|
||||
|
@ -171,14 +165,8 @@ public class ShootMessage {
|
|||
|
||||
int projectileAmount = (int) tag.getDouble("projectile_amount");
|
||||
|
||||
int count = 0;
|
||||
for (var inv : player.getInventory().items) {
|
||||
if (inv.is(ModItems.CREATIVE_AMMO_BOX.get())) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if ((player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).rifleAmmo > 0 || count > 0) {
|
||||
if ((player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).rifleAmmo > 0
|
||||
|| player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) {
|
||||
tag.putDouble("heat", (tag.getDouble("heat") + 0.5));
|
||||
if (tag.getDouble("heat") >= 50.5) {
|
||||
tag.putDouble("overheat", 40);
|
||||
|
@ -191,14 +179,12 @@ public class ShootMessage {
|
|||
float pitch = tag.getDouble("heat") <= 40 ? 1 : (float) (1 - 0.025 * Math.abs(40 - tag.getDouble("heat")));
|
||||
|
||||
if (!player.level().isClientSide() && player instanceof ServerPlayer serverPlayer) {
|
||||
SoundTool.playLocalSound(serverPlayer, ModSounds.MINIGUN_FIRE_1P.get(), 2f, pitch);
|
||||
player.playSound(ModSounds.MINIGUN_FIRE_3P.get(), (float) stack.getOrCreateTag().getDouble("SoundRadius") * 0.2f, pitch);
|
||||
player.playSound(ModSounds.MINIGUN_FAR.get(), (float) stack.getOrCreateTag().getDouble("SoundRadius") * 0.5f, pitch);
|
||||
player.playSound(ModSounds.MINIGUN_VERYFAR.get(), (float) stack.getOrCreateTag().getDouble("SoundRadius"), pitch);
|
||||
|
||||
if (perk == ModPerks.BEAST_BULLET.get()) {
|
||||
player.playSound(ModSounds.HENG.get(), 4f, pitch);
|
||||
SoundTool.playLocalSound(serverPlayer, ModSounds.HENG.get(), 4f, pitch);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -206,7 +192,7 @@ public class ShootMessage {
|
|||
gunShoot(player, spared);
|
||||
}
|
||||
|
||||
if (count == 0) {
|
||||
if (!player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) {
|
||||
player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
capability.rifleAmmo = player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).rifleAmmo - 1;
|
||||
capability.syncPlayerVariables(player);
|
||||
|
|
Loading…
Add table
Reference in a new issue