diff --git a/src/main/java/com/atsuishio/superbwarfare/capability/player/PlayerVariable.java b/src/main/java/com/atsuishio/superbwarfare/capability/player/PlayerVariable.java index 9133ba013..0b2a42914 100644 --- a/src/main/java/com/atsuishio/superbwarfare/capability/player/PlayerVariable.java +++ b/src/main/java/com/atsuishio/superbwarfare/capability/player/PlayerVariable.java @@ -21,23 +21,15 @@ import javax.annotation.ParametersAreNonnullByDefault; @EventBusSubscriber(modid = Mod.MODID) public class PlayerVariable implements INBTSerializable { private PlayerVariable old = null; - - public boolean zoom = false; - public boolean holdFire = false; public int rifleAmmo = 0; public int handgunAmmo = 0; public int shotgunAmmo = 0; public int sniperAmmo = 0; public int heavyAmmo = 0; - public boolean bowPullHold = false; - public boolean bowPull = false; public boolean playerDoubleJump = false; public boolean tacticalSprint = false; public int tacticalSprintTime = 600; public boolean tacticalSprintExhaustion = false; - public boolean breath = false; - public int breathTime = 160; - public boolean breathExhaustion = false; public boolean edit = false; public void sync(Entity entity) { @@ -65,44 +57,29 @@ public class PlayerVariable implements INBTSerializable { public CompoundTag writeToNBT() { CompoundTag nbt = new CompoundTag(); - nbt.putBoolean("Zoom", zoom); - nbt.putBoolean("HoldFire", holdFire); for (var type : AmmoType.values()) { type.set(nbt, type.get(this)); } - nbt.putBoolean("BowPullHold", bowPullHold); - nbt.putBoolean("BowPull", bowPull); nbt.putBoolean("DoubleJump", playerDoubleJump); nbt.putBoolean("TacticalSprint", tacticalSprint); nbt.putInt("TacticalSprintTime", tacticalSprintTime); nbt.putBoolean("TacticalSprintExhaustion", tacticalSprintExhaustion); - nbt.putBoolean("Breath", breath); - nbt.putInt("BreathTime", breathTime); - nbt.putBoolean("BreathExhaustion", breathExhaustion); nbt.putBoolean("EditMode", edit); return nbt; } public PlayerVariable readFromNBT(CompoundTag tag) { - zoom = tag.getBoolean("Zoom"); - holdFire = tag.getBoolean("HoldFire"); - for (var type : AmmoType.values()) { type.set(this, type.get(tag)); } - bowPullHold = tag.getBoolean("BowPullHold"); - bowPull = tag.getBoolean("BowPull"); playerDoubleJump = tag.getBoolean("DoubleJump"); tacticalSprint = tag.getBoolean("TacticalSprint"); tacticalSprintTime = tag.getInt("TacticalSprintTime"); tacticalSprintExhaustion = tag.getBoolean("TacticalSprintExhaustion"); - breath = tag.getBoolean("Breath"); - breathTime = tag.getInt("BreathTime"); - breathExhaustion = tag.getBoolean("BreathExhaustion"); edit = tag.getBoolean("EditMode"); return this; @@ -111,22 +88,15 @@ public class PlayerVariable implements INBTSerializable { public PlayerVariable copy() { var clone = new PlayerVariable(); - clone.zoom = this.zoom; - clone.holdFire = this.holdFire; clone.rifleAmmo = this.rifleAmmo; clone.handgunAmmo = this.handgunAmmo; clone.shotgunAmmo = this.shotgunAmmo; clone.sniperAmmo = this.sniperAmmo; clone.heavyAmmo = this.heavyAmmo; - clone.bowPullHold = this.bowPullHold; - clone.bowPull = this.bowPull; clone.playerDoubleJump = this.playerDoubleJump; clone.tacticalSprint = this.tacticalSprint; clone.tacticalSprintTime = this.tacticalSprintTime; clone.tacticalSprintExhaustion = this.tacticalSprintExhaustion; - clone.breath = this.breath; - clone.breathTime = this.breathTime; - clone.breathExhaustion = this.breathExhaustion; clone.edit = this.edit; return clone; @@ -136,22 +106,14 @@ public class PlayerVariable implements INBTSerializable { public boolean equals(Object obj) { if (!(obj instanceof PlayerVariable other)) return false; - return zoom == other.zoom - && holdFire == other.holdFire - && rifleAmmo == other.rifleAmmo + return rifleAmmo == other.rifleAmmo && handgunAmmo == other.handgunAmmo && shotgunAmmo == other.shotgunAmmo && sniperAmmo == other.sniperAmmo && heavyAmmo == other.heavyAmmo - && bowPullHold == other.bowPullHold - && bowPull == other.bowPull && playerDoubleJump == other.playerDoubleJump && tacticalSprint == other.tacticalSprint -// && tacticalSprintTime == other.tacticalSprintTime && tacticalSprintExhaustion == other.tacticalSprintExhaustion - && breath == other.breath -// && breathTime == other.breathTime - && breathExhaustion == other.breathExhaustion && edit == other.edit; } diff --git a/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java b/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java index b953fedf5..63113ad85 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java @@ -275,7 +275,7 @@ public class ClickHandler { } if (key == ModKeyMappings.BREATH.getKey().getValue()) { - PacketDistributor.sendToServer(new BreathMessage(true)); +// PacketDistributor.sendToServer(new BreathMessage(true)); } } else { if (player.hasEffect(ModMobEffects.SHOCK)) return; @@ -293,7 +293,7 @@ public class ClickHandler { } if (event.getAction() == GLFW.GLFW_RELEASE && key == ModKeyMappings.BREATH.getKey().getValue()) { - PacketDistributor.sendToServer(new BreathMessage(false)); +// PacketDistributor.sendToServer(new BreathMessage(false)); } } } @@ -343,9 +343,7 @@ public class ClickHandler { ClientEventHandler.burstFireAmount = data.burstAmount(); } } else { - if (!stack.is(ModItems.BOCEK.get())) { - ClientEventHandler.holdFire = true; - } + ClientEventHandler.holdFire = true; } } } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/TargetEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/TargetEntity.java index 3a391073a..ccb3cb327 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/TargetEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/TargetEntity.java @@ -1,7 +1,6 @@ package com.atsuishio.superbwarfare.entity; import com.atsuishio.superbwarfare.Mod; -import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.tools.FormatTool; @@ -145,12 +144,10 @@ public class TargetEntity extends LivingEntity implements GeoEntity { player.addItem(new ItemStack(ModItems.TARGET_DEPLOYER.get())); } } else { - if (!player.getData(ModAttachments.PLAYER_VARIABLE).zoom) { - this.lookAt(EntityAnchorArgument.Anchor.EYES, new Vec3((player.getX()), this.getY(), (player.getZ()))); - this.setXRot(0); - this.xRotO = this.getXRot(); - this.entityData.set(DOWN_TIME, 0); - } + this.lookAt(EntityAnchorArgument.Anchor.EYES, new Vec3((player.getX()), this.getY(), (player.getZ()))); + this.setXRot(0); + this.xRotO = this.getXRot(); + this.entityData.set(DOWN_TIME, 0); } return InteractionResult.sidedSuccess(this.level().isClientSide()); diff --git a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java index 794df512d..ae54dcb69 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java @@ -123,6 +123,7 @@ public class ClientEventHandler { public static boolean holdFire = false; public static boolean zoom = false; + public static boolean breath = false; public static boolean holdFireVehicle = false; public static boolean zoomVehicle = false; @@ -630,7 +631,7 @@ public class ClientEventHandler { if (!stack.is(ModTags.Items.GUN)) return; var data = GunData.from(stack); - PacketDistributor.sendToServer(new ShootMessage(gunSpread)); + PacketDistributor.sendToServer(new ShootMessage(gunSpread, zoom)); fireRecoilTime = 10; var gunRecoilY = data.recoilY() * 10; @@ -848,9 +849,7 @@ public class ClientEventHandler { double customWeight = data.customWeight(); - var cap = player.getData(ModAttachments.PLAYER_VARIABLE); - - if (!cap.breath && cap.zoom) { + if (!breath && zoom) { float newPitch = (float) (player.getXRot() - 0.01f * Mth.sin((float) (0.03 * player.tickCount)) * pose * Mth.nextDouble(RandomSource.create(), 0.1, 1) * times * sway * (1 - 0.03 * customWeight)); player.setXRot(newPitch); player.xRotO = player.getXRot(); @@ -1268,7 +1267,6 @@ public class ClientEventHandler { private static void handlePlayerBreath(LivingEntity entity) { float times = (float) Math.min(Minecraft.getInstance().getTimer().getRealtimeDeltaTicks(), 0.8); - boolean breath = entity.getData(ModAttachments.PLAYER_VARIABLE).breath; breathTime = Mth.lerp(0.2f * times, breathTime, breath ? 1 : 0); } @@ -1339,7 +1337,7 @@ public class ClientEventHandler { private static void handleBowPullAnimation(LivingEntity entity) { float times = 4 * (float) Math.min(Minecraft.getInstance().getTimer().getRealtimeDeltaTicks(), 0.8); - if (entity.getData(ModAttachments.PLAYER_VARIABLE).bowPull) { + if (holdFire) { pullTimer = Math.min(pullTimer + 0.024 * times, 1.4); bowTimer = Math.min(bowTimer + 0.018 * times, 1); handTimer = Math.min(handTimer + 0.018 * times, 1); @@ -1536,7 +1534,7 @@ public class ClientEventHandler { public static void aimAtVillager(Player player) { if (aimVillagerCountdown > 0) return; - if (player.getData(ModAttachments.PLAYER_VARIABLE).zoom) { + if (zoom) { Entity entity = TraceTool.findLookingEntity(player, 10); if (entity instanceof AbstractVillager villager) { List entities = SeekTool.seekLivingEntities(villager, villager.level(), 16, 120); diff --git a/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java index 264c78391..4eeb25e4c 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java @@ -169,7 +169,7 @@ public class GunEventHandler { } } - public static void gunShoot(Player player, GunData data, double spared) { + public static void gunShoot(Player player, GunData data, double spared, boolean zoom) { var stack = data.stack(); if (!player.level().isClientSide()) { @@ -178,7 +178,6 @@ public class GunEventHandler { float velocity = (float) (data.velocity() * perkSpeed(data)); int projectileAmount = data.projectileAmount(); float bypassArmorRate = (float) data.bypassArmor(); - boolean zoom = player.getData(ModAttachments.PLAYER_VARIABLE).zoom; var perkInstance = data.perk.getInstance(Perk.Type.AMMO); var perk = perkInstance != null ? perkInstance.perk() : null; diff --git a/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java index 86227a967..20ba81c50 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java @@ -382,11 +382,6 @@ public class LivingEventHandler { var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch(); cap.edit = false; - if (oldStack.is(ModItems.BOCEK)) { - oldData.data().putInt("Power", 0); - cap.bowPullHold = false; - } - player.setData(ModAttachments.PLAYER_VARIABLE, cap); cap.sync(player); @@ -421,10 +416,6 @@ public class LivingEventHandler { } var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch(); - if (newStack.is(ModItems.BOCEK)) { - newData.data().putInt("Power", 0); - cap.bowPullHold = false; - } int level = newData.perk.getLevel(ModPerks.KILLING_TALLY); if (level != 0) { diff --git a/src/main/java/com/atsuishio/superbwarfare/event/PlayerEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/PlayerEventHandler.java index 9ea48a49f..9b78d8ab7 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/PlayerEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/PlayerEventHandler.java @@ -4,12 +4,14 @@ import com.atsuishio.superbwarfare.config.common.GameplayConfig; import com.atsuishio.superbwarfare.config.server.MiscConfig; import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModItems; -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.data.GunData; import com.atsuishio.superbwarfare.network.message.receive.SimulationDistanceMessage; -import com.atsuishio.superbwarfare.tools.*; +import com.atsuishio.superbwarfare.tools.AmmoType; +import com.atsuishio.superbwarfare.tools.GunsTool; +import com.atsuishio.superbwarfare.tools.InventoryTool; +import com.atsuishio.superbwarfare.tools.NBTTool; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvents; @@ -57,7 +59,6 @@ public class PlayerEventHandler { Player player = event.getEntity(); var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch(); - cap.zoom = false; cap.tacticalSprintExhaustion = false; cap.tacticalSprintTime = 600; player.setData(ModAttachments.PLAYER_VARIABLE, cap); @@ -87,37 +88,14 @@ public class PlayerEventHandler { if (stack.is(ModTags.Items.GUN)) { handlePlayerSprint(player); handleSpecialWeaponAmmo(player); - handleBocekPulling(player); } handleGround(player); handleTacticalSprint(player); - handleBreath(player); variable.sync(player); } - private static void handleBreath(Player player) { - var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch(); - - if (cap.breath) { - cap.breathTime = Mth.clamp(cap.breathTime - 1, 0, 100); - } else { - cap.breathTime = Mth.clamp(cap.breathTime + 1, 0, 100); - } - - if (cap.breathTime == 0) { - cap.breathExhaustion = true; - cap.breath = false; - } - - if (cap.breathTime == 100) { - cap.breathExhaustion = false; - } - - player.setData(ModAttachments.PLAYER_VARIABLE, cap); - } - private static void handleTacticalSprint(Player player) { var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch(); @@ -171,23 +149,23 @@ public class PlayerEventHandler { * 判断玩家是否在奔跑 */ private static void handlePlayerSprint(Player player) { - var cap = player.getData(ModAttachments.PLAYER_VARIABLE); + if (!player.level().isClientSide) return; - if (cap.holdFire) { + if (ClientEventHandler.holdFire) { player.getPersistentData().putDouble("noRun", 10); } if (player.isShiftKeyDown() || player.isPassenger() || player.isInWater() - || cap.zoom + || ClientEventHandler.zoom ) player.getPersistentData().putDouble("noRun", 3); if (player.getPersistentData().getDouble("noRun") > 0) { player.getPersistentData().putDouble("noRun", (player.getPersistentData().getDouble("noRun") - 1)); } - if (cap.zoom || cap.holdFire) { + if (ClientEventHandler.zoom || ClientEventHandler.holdFire) { player.setSprinting(false); } } @@ -211,51 +189,6 @@ public class PlayerEventHandler { } } - private static void handleBocekPulling(Player player) { - ItemStack stack = player.getMainHandItem(); - - var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch(); - - var data = GunData.from(stack); - final var tag = data.tag(); - - if (cap.bowPullHold) { - if (stack.getItem() == ModItems.BOCEK.get() - && data.maxAmmo() > 0 - && !player.getCooldowns().isOnCooldown(stack.getItem()) - && GunsTool.getGunDoubleTag(tag, "Power") < 12 - ) { - GunsTool.setGunDoubleTag(tag, "Power", GunsTool.getGunDoubleTag(tag, "Power") + 1); - - cap.bowPull = true; - cap.tacticalSprint = false; - player.setData(ModAttachments.PLAYER_VARIABLE, cap); - player.setSprinting(false); - } - if (GunsTool.getGunDoubleTag(tag, "Power") == 1) { - if (!player.level().isClientSide() && player instanceof ServerPlayer serverPlayer) { - SoundTool.playLocalSound(serverPlayer, ModSounds.BOCEK_PULL_1P.get(), 2f, 1f); - player.level().playSound(null, player.blockPosition(), ModSounds.BOCEK_PULL_3P.get(), SoundSource.PLAYERS, 0.5f, 1); - } - } - } else { - if (stack.getItem() == ModItems.BOCEK.get()) { - GunsTool.setGunDoubleTag(tag, "Power", 0); - } - cap.bowPull = false; - player.setData(ModAttachments.PLAYER_VARIABLE, cap); - } - - if (GunsTool.getGunDoubleTag(tag, "Power") > 0) { - cap.tacticalSprint = false; - player.setData(ModAttachments.PLAYER_VARIABLE, cap); - player.setSprinting(false); - } - - cap.sync(player); - data.save(); - } - private static void handleSimulationDistance(Player player) { if (player.level() instanceof ServerLevel serverLevel && player instanceof ServerPlayer serverPlayer) { var distance = serverLevel.getChunkSource().chunkMap.serverViewDistance; diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/SpecialFireWeapon.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/SpecialFireWeapon.java index 22b20e5ac..acf8f3764 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/SpecialFireWeapon.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/SpecialFireWeapon.java @@ -16,7 +16,7 @@ public interface SpecialFireWeapon { * @param player 玩家 */ - default void fireOnPress(Player player, final GunData data) { + default void fireOnPress(Player player, final GunData data, boolean zoom) { } /** @@ -24,7 +24,7 @@ public interface SpecialFireWeapon { * * @param player 玩家 */ - default void fireOnRelease(Player player, final GunData data) { + default void fireOnRelease(Player player, final GunData data, double power, boolean zoom) { } } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/JavelinItem.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/JavelinItem.java index 06343d27e..c90456664 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/JavelinItem.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/JavelinItem.java @@ -294,7 +294,7 @@ public class JavelinItem extends GunItem implements GeoItem, SpecialFireWeapon { } @Override - public void fireOnRelease(Player player, final GunData data) { + public void fireOnRelease(Player player, final GunData data, double power, boolean zoom) { fire(player); var tag = data.tag(); tag.putBoolean("Seeking", false); @@ -307,10 +307,10 @@ public class JavelinItem extends GunItem implements GeoItem, SpecialFireWeapon { } @Override - public void fireOnPress(Player player, final GunData data) { + public void fireOnPress(Player player, final GunData data, boolean zoom) { var tag = data.tag(); - if (!player.getData(ModAttachments.PLAYER_VARIABLE).zoom || data.ammo() <= 0) return; + if (!zoom || data.ammo() <= 0) return; Entity seekingEntity = SeekTool.seekEntity(player, player.level(), 512, 8); diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/M79Item.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/M79Item.java index bba1eb099..0a8d87427 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/M79Item.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/M79Item.java @@ -5,7 +5,10 @@ import com.atsuishio.superbwarfare.client.renderer.item.M79ItemRenderer; import com.atsuishio.superbwarfare.client.tooltip.component.LauncherImageComponent; import com.atsuishio.superbwarfare.entity.projectile.GunGrenadeEntity; import com.atsuishio.superbwarfare.event.ClientEventHandler; -import com.atsuishio.superbwarfare.init.*; +import com.atsuishio.superbwarfare.init.ModItems; +import com.atsuishio.superbwarfare.init.ModPerks; +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.SpecialFireWeapon; import com.atsuishio.superbwarfare.item.gun.data.GunData; @@ -165,12 +168,11 @@ public class M79Item extends GunItem implements GeoItem, SpecialFireWeapon { } @Override - public void fireOnPress(Player player, final GunData data) { + public void fireOnPress(Player player, final GunData data, boolean zoom) { if (data.reloading()) return; ItemStack stack = data.stack(); if (player.getCooldowns().isOnCooldown(stack.getItem()) || data.ammo() <= 0) return; - boolean zooming = player.getData(ModAttachments.PLAYER_VARIABLE).zoom; double spread = data.spread(); if (player.level() instanceof ServerLevel serverLevel) { @@ -198,7 +200,7 @@ public class M79Item extends GunItem implements GeoItem, SpecialFireWeapon { gunGrenadeEntity.setPos(player.getX(), player.getEyeY() - 0.1, player.getZ()); gunGrenadeEntity.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, velocity, - (float) (zooming ? 0.1 : spread)); + (float) (zoom ? 0.1 : spread)); serverLevel.addFreshEntity(gunGrenadeEntity); ParticleTool.sendParticle(serverLevel, ParticleTypes.CLOUD, player.getX() + 1.8 * player.getLookAngle().x, diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/RpgItem.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/RpgItem.java index 3e19dc19e..68246fe69 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/RpgItem.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/RpgItem.java @@ -5,7 +5,10 @@ import com.atsuishio.superbwarfare.client.renderer.item.RpgItemRenderer; import com.atsuishio.superbwarfare.client.tooltip.component.LauncherImageComponent; import com.atsuishio.superbwarfare.entity.projectile.RpgRocketEntity; import com.atsuishio.superbwarfare.event.ClientEventHandler; -import com.atsuishio.superbwarfare.init.*; +import com.atsuishio.superbwarfare.init.ModItems; +import com.atsuishio.superbwarfare.init.ModPerks; +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.SpecialFireWeapon; import com.atsuishio.superbwarfare.item.gun.data.GunData; @@ -178,7 +181,7 @@ public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon { } @Override - public void fireOnPress(Player player, final GunData data) { + public void fireOnPress(Player player, final GunData data, boolean zoom) { Level level = player.level(); ItemStack stack = player.getMainHandItem(); @@ -187,7 +190,6 @@ public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon { || data.ammo() <= 0 ) return; - boolean zoom = player.getData(ModAttachments.PLAYER_VARIABLE).zoom; double spread = data.spread(); if (player.level() instanceof ServerLevel serverLevel) { diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/SecondaryCataclysm.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/SecondaryCataclysm.java index 5724f87b6..70f29b048 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/SecondaryCataclysm.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/SecondaryCataclysm.java @@ -266,18 +266,17 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, SpecialFireW } @Override - public void fireOnPress(Player player, final GunData data) { + public void fireOnPress(Player player, final GunData data, boolean zoom) { if (data.reloading()) return; ItemStack stack = data.stack(); if (player.getCooldowns().isOnCooldown(stack.getItem()) || data.ammo() <= 0) return; - boolean zooming = player.getData(ModAttachments.PLAYER_VARIABLE).zoom; double spread = data.spread(); var stackCap = stack.getCapability(Capabilities.EnergyStorage.ITEM); var hasEnoughEnergy = stackCap != null && stackCap.getEnergyStored() >= 3000; - boolean isChargedFire = zooming && hasEnoughEnergy; + boolean isChargedFire = zoom && hasEnoughEnergy; if (player.level() instanceof ServerLevel serverLevel) { GunGrenadeEntity gunGrenadeEntity = new GunGrenadeEntity(player, serverLevel, @@ -305,7 +304,7 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, SpecialFireW gunGrenadeEntity.setPos(player.getX(), player.getEyeY() - 0.1, player.getZ()); gunGrenadeEntity.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, (isChargedFire ? 4 : 1) * velocity, - (float) (zooming ? 0.1 : spread)); + (float) (zoom ? 0.1 : spread)); serverLevel.addFreshEntity(gunGrenadeEntity); ParticleTool.sendParticle(serverLevel, ParticleTypes.CLOUD, player.getX() + 1.8 * player.getLookAngle().x, diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/special/BocekItem.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/special/BocekItem.java index 1656f0ed7..44ac335d2 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/special/BocekItem.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/special/BocekItem.java @@ -4,11 +4,13 @@ import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.client.renderer.item.BocekItemRenderer; import com.atsuishio.superbwarfare.client.tooltip.component.BocekImageComponent; import com.atsuishio.superbwarfare.event.ClientEventHandler; -import com.atsuishio.superbwarfare.init.*; +import com.atsuishio.superbwarfare.init.ModItems; +import com.atsuishio.superbwarfare.init.ModPerks; +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.SpecialFireWeapon; import com.atsuishio.superbwarfare.item.gun.data.GunData; -import com.atsuishio.superbwarfare.network.message.receive.ShootClientMessage; import com.atsuishio.superbwarfare.perk.AmmoPerk; import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.tools.GunsTool; @@ -28,7 +30,6 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.Rarity; import net.minecraft.world.level.Level; -import net.neoforged.neoforge.network.PacketDistributor; import org.jetbrains.annotations.NotNull; import software.bernie.geckolib.animatable.GeoItem; import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache; @@ -164,29 +165,22 @@ public class BocekItem extends GunItem implements GeoItem, SpecialFireWeapon { } @Override - public void fireOnRelease(Player player, final GunData data) { + public void fireOnRelease(Player player, final GunData data, double power, boolean zoom) { if (player.level().isClientSide()) return; var tag = data.tag(); var stack = data.stack(); var perk = data.perk.get(Perk.Type.AMMO); - if (player instanceof ServerPlayer serverPlayer) { - SoundTool.stopSound(serverPlayer, ModSounds.BOCEK_PULL_1P.getId(), SoundSource.PLAYERS); - SoundTool.stopSound(serverPlayer, ModSounds.BOCEK_PULL_3P.getId(), SoundSource.PLAYERS); - - PacketDistributor.sendToPlayer(serverPlayer, new ShootClientMessage(10)); - } - - if (GunsTool.getGunDoubleTag(tag, "Power") >= 6) { - if (player.getData(ModAttachments.PLAYER_VARIABLE).zoom) { - spawnBullet(player, tag); + if (power * 12 >= 6) { + if (zoom) { + spawnBullet(player, tag, power, true); SoundTool.playLocalSound(player, ModSounds.BOCEK_ZOOM_FIRE_1P.get(), 10, 1); player.playSound(ModSounds.BOCEK_ZOOM_FIRE_3P.get(), 2, 1); } else { for (int i = 0; i < (perk instanceof AmmoPerk ammoPerk && ammoPerk.slug ? 1 : 10); i++) { - spawnBullet(player, tag); + spawnBullet(player, tag, power, false); } SoundTool.playLocalSound(player, ModSounds.BOCEK_SHATTER_CAP_FIRE_1P.get(), 10, 1); @@ -203,7 +197,6 @@ public class BocekItem extends GunItem implements GeoItem, SpecialFireWeapon { player.getCooldowns().addCooldown(stack.getItem(), 7); GunsTool.setGunIntTag(tag, "ArrowEmpty", 7); - GunsTool.setGunDoubleTag(tag, "Power", 0); if (!InventoryTool.hasCreativeAmmoBox(player) && !player.isCreative()) { player.getInventory().clearOrCountMatchingItems(p -> Items.ARROW == p.getItem(), 1, player.inventoryMenu.getCraftSlots()); @@ -212,10 +205,10 @@ public class BocekItem extends GunItem implements GeoItem, SpecialFireWeapon { } @Override - public void fireOnPress(Player player, final GunData data) { - var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch(); - cap.bowPullHold = true; - player.setData(ModAttachments.PLAYER_VARIABLE, cap); - cap.sync(player); + public void fireOnPress(Player player, final GunData data, boolean zoom) { + if (player instanceof ServerPlayer serverPlayer) { + SoundTool.stopSound(serverPlayer, ModSounds.BOCEK_PULL_1P.getId(), SoundSource.PLAYERS); + SoundTool.stopSound(serverPlayer, ModSounds.BOCEK_PULL_3P.getId(), SoundSource.PLAYERS); + } } } \ No newline at end of file diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/special/TaserItem.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/special/TaserItem.java index b1732c942..946569c2c 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/special/TaserItem.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/special/TaserItem.java @@ -5,7 +5,10 @@ import com.atsuishio.superbwarfare.client.renderer.item.TaserItemRenderer; import com.atsuishio.superbwarfare.client.tooltip.component.EnergyImageComponent; import com.atsuishio.superbwarfare.entity.projectile.TaserBulletEntity; import com.atsuishio.superbwarfare.event.ClientEventHandler; -import com.atsuishio.superbwarfare.init.*; +import com.atsuishio.superbwarfare.init.ModItems; +import com.atsuishio.superbwarfare.init.ModPerks; +import com.atsuishio.superbwarfare.init.ModSounds; +import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.item.EnergyStorageItem; import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.SpecialFireWeapon; @@ -217,7 +220,7 @@ public class TaserItem extends GunItem implements GeoItem, SpecialFireWeapon, En } @Override - public void fireOnPress(Player player, final GunData data) { + public void fireOnPress(Player player, final GunData data, boolean zoom) { if (data.reloading()) return; ItemStack stack = data.stack(); @@ -233,7 +236,6 @@ public class TaserItem extends GunItem implements GeoItem, SpecialFireWeapon, En player.getCooldowns().addCooldown(stack.getItem(), 5); if (player instanceof ServerPlayer serverPlayer) { - boolean zoom = player.getData(ModAttachments.PLAYER_VARIABLE).zoom; double spread = data.spread(); int volt = data.perk.getLevel(ModPerks.VOLT_OVERLOAD); diff --git a/src/main/java/com/atsuishio/superbwarfare/network/NetworkRegistry.java b/src/main/java/com/atsuishio/superbwarfare/network/NetworkRegistry.java index 981d5f959..b2b4da936 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/NetworkRegistry.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/NetworkRegistry.java @@ -24,7 +24,6 @@ public class NetworkRegistry { registrar.playToClient(SimulationDistanceMessage.TYPE, SimulationDistanceMessage.STREAM_CODEC, SimulationDistanceMessage::handler); registrar.playToServer(LaserShootMessage.TYPE, LaserShootMessage.STREAM_CODEC, LaserShootMessage::handler); - registrar.playToServer(BreathMessage.TYPE, BreathMessage.STREAM_CODEC, BreathMessage::handler); registrar.playToServer(ShootMessage.TYPE, ShootMessage.STREAM_CODEC, ShootMessage::handler); registrar.playToServer(DoubleJumpMessage.TYPE, DoubleJumpMessage.STREAM_CODEC, DoubleJumpMessage::handler); registrar.playToServer(VehicleMovementMessage.TYPE, VehicleMovementMessage.STREAM_CODEC, VehicleMovementMessage::handler); diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/send/BreathMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/send/BreathMessage.java deleted file mode 100644 index a7c530e15..000000000 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/send/BreathMessage.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.atsuishio.superbwarfare.network.message.send; - -import com.atsuishio.superbwarfare.Mod; -import com.atsuishio.superbwarfare.init.ModAttachments; -import io.netty.buffer.ByteBuf; -import net.minecraft.network.codec.ByteBufCodecs; -import net.minecraft.network.codec.StreamCodec; -import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.minecraft.server.level.ServerPlayer; -import net.neoforged.neoforge.network.handling.IPayloadContext; -import org.jetbrains.annotations.NotNull; - -public record BreathMessage(boolean msgType) implements CustomPacketPayload { - public static final Type TYPE = new Type<>(Mod.loc("breath")); - - public static final StreamCodec STREAM_CODEC = StreamCodec.composite( - ByteBufCodecs.BOOL, - BreathMessage::msgType, - BreathMessage::new - ); - - - public static void handler(final BreathMessage message, final IPayloadContext context) { - ServerPlayer player = (ServerPlayer) context.player(); - - var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch(); - if (message.msgType - && !cap.breathExhaustion - && cap.zoom - && player.getPersistentData().getDouble("NoBreath") == 0 - ) { - cap.breath = true; - player.setData(ModAttachments.PLAYER_VARIABLE, cap); - cap.sync(player); - } - - if (!message.msgType) { - cap.breath = false; - player.setData(ModAttachments.PLAYER_VARIABLE, cap); - cap.sync(player); - } - } - - @Override - public @NotNull Type type() { - return TYPE; - } -} \ No newline at end of file diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/send/FireMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/send/FireMessage.java index 05f4f061a..21ffa62da 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/send/FireMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/send/FireMessage.java @@ -2,15 +2,16 @@ package com.atsuishio.superbwarfare.network.message.send; import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; +import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.GunEventHandler; import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModPerks; import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.item.gun.SpecialFireWeapon; import com.atsuishio.superbwarfare.item.gun.data.GunData; +import com.atsuishio.superbwarfare.item.gun.special.BocekItem; import com.atsuishio.superbwarfare.perk.AmmoPerk; import com.atsuishio.superbwarfare.perk.Perk; -import com.atsuishio.superbwarfare.tools.GunsTool; import io.netty.buffer.ByteBuf; import net.minecraft.core.Holder; import net.minecraft.nbt.CompoundTag; @@ -63,18 +64,15 @@ public record FireMessage(int msgType) implements CustomPacketPayload { cap.sync(player); return; } - specialFireWeapon.fireOnPress(player, data); - - cap.holdFire = true; - player.setData(ModAttachments.PLAYER_VARIABLE, cap); + specialFireWeapon.fireOnPress(player, data, ClientEventHandler.zoom); } else if (type == 1) { - cap.bowPullHold = false; - cap.holdFire = false; - player.setData(ModAttachments.PLAYER_VARIABLE, cap); - // 松开开火 if (stack.getItem() instanceof SpecialFireWeapon specialFireWeapon) { - specialFireWeapon.fireOnRelease(player, data); + if (specialFireWeapon instanceof BocekItem) { + specialFireWeapon.fireOnRelease(player, data, ClientEventHandler.bowTimer, ClientEventHandler.zoom); + } else { + specialFireWeapon.fireOnRelease(player, data, 0, ClientEventHandler.zoom); + } } } cap.sync(player); @@ -100,6 +98,13 @@ public record FireMessage(int msgType) implements CustomPacketPayload { } } + public static double perkDamage(Perk perk) { + if (perk instanceof AmmoPerk ammoPerk) { + return ammoPerk.damageRate; + } + return 1; + } + public static double perkSpeed(Perk perk) { if (perk instanceof AmmoPerk ammoPerk) { return ammoPerk.speedRate; @@ -107,29 +112,26 @@ public record FireMessage(int msgType) implements CustomPacketPayload { return 1; } - public static void spawnBullet(Player player, final CompoundTag tag) { + public static void spawnBullet(Player player, final CompoundTag tag, double power, boolean zoom) { ItemStack stack = player.getMainHandItem(); if (player.level().isClientSide()) return; var data = GunData.from(stack); var perk = data.perk.get(Perk.Type.AMMO); float headshot = (float) data.headshot(); - float velocity = 2 * (float) GunsTool.getGunDoubleTag(tag, "Power", 6) * (float) perkSpeed(perk); + float velocity = (float) (24 * power * (float) perkSpeed(perk)); float bypassArmorRate = (float) data.bypassArmor(); double damage; - boolean zoom = player.getData(ModAttachments.PLAYER_VARIABLE).zoom; - float spread; if (zoom) { spread = 0.01f; damage = 0.08333333 * data.damage() * - GunsTool.getGunDoubleTag(tag, "Power", 6); + 12 * power * perkDamage(perk); } else { spread = perk instanceof AmmoPerk ammoPerk && ammoPerk.slug ? 0.5f : 2.5f; damage = (perk instanceof AmmoPerk ammoPerk && ammoPerk.slug ? 0.08333333 : 0.008333333) * - data.damage() * - GunsTool.getGunDoubleTag(tag, "Power", 6); + data.damage() * 12 * power * perkDamage(perk); } ProjectileEntity projectile = new ProjectileEntity(player.level()) diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/send/ShootMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/send/ShootMessage.java index c34216037..89f65ddff 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/send/ShootMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/send/ShootMessage.java @@ -23,21 +23,23 @@ import net.neoforged.neoforge.capabilities.Capabilities; import net.neoforged.neoforge.network.handling.IPayloadContext; import org.jetbrains.annotations.NotNull; -public record ShootMessage(double spread) implements CustomPacketPayload { +public record ShootMessage(double spread, boolean zoom) implements CustomPacketPayload { public static final Type TYPE = new Type<>(Mod.loc("shoot")); public static final StreamCodec STREAM_CODEC = StreamCodec.composite( ByteBufCodecs.DOUBLE, ShootMessage::spread, + ByteBufCodecs.BOOL, + ShootMessage::zoom, ShootMessage::new ); public static void handler(final ShootMessage message, final IPayloadContext context) { - pressAction(context.player(), message.spread); + pressAction(context.player(), message.spread, message.zoom); } - public static void pressAction(Player player, double spared) { + public static void pressAction(Player player, double spared, boolean zoom) { ItemStack stack = player.getMainHandItem(); var data = GunData.from(stack); var tag = data.tag(); @@ -86,7 +88,7 @@ public record ShootMessage(double spread) implements CustomPacketPayload { var perk = data.perk.get(Perk.Type.AMMO); for (int index0 = 0; index0 < (perk instanceof AmmoPerk ammoPerk && ammoPerk.slug ? 1 : projectileAmount); index0++) { - GunEventHandler.gunShoot(player, data, spared); + GunEventHandler.gunShoot(player, data, spared, zoom); } GunEventHandler.playGunSounds(player); @@ -119,7 +121,7 @@ public record ShootMessage(double spread) implements CustomPacketPayload { } } - GunEventHandler.gunShoot(player, data, spared); + GunEventHandler.gunShoot(player, data, spared, false); if (!InventoryTool.hasCreativeAmmoBox(player)) { cap.rifleAmmo = cap.rifleAmmo - 1; player.setData(ModAttachments.PLAYER_VARIABLE, cap); diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/send/ZoomMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/send/ZoomMessage.java index 8b8a9844a..8b7062779 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/send/ZoomMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/send/ZoomMessage.java @@ -35,7 +35,6 @@ public record ZoomMessage(int msgType) implements CustomPacketPayload { var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch(); if (message.msgType == 0) { - cap.zoom = true; cap.edit = false; player.setData(ModAttachments.PLAYER_VARIABLE, cap); cap.sync(player); @@ -50,11 +49,6 @@ public record ZoomMessage(int msgType) implements CustomPacketPayload { } } else if (message.msgType == 1) { - cap.zoom = false; - cap.breath = false; - player.setData(ModAttachments.PLAYER_VARIABLE, cap); - cap.sync(player); - if (player.isPassenger() && vehicle instanceof WeaponVehicleEntity weaponEntity && vehicle instanceof VehicleEntity vehicleEntity