铲除大坨莫名其妙的Capability

This commit is contained in:
Atsuishio 2025-04-10 21:39:05 +08:00 committed by Light_Quanta
parent 7455e08036
commit e60fca1a88
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
19 changed files with 86 additions and 261 deletions

View file

@ -21,23 +21,15 @@ import javax.annotation.ParametersAreNonnullByDefault;
@EventBusSubscriber(modid = Mod.MODID) @EventBusSubscriber(modid = Mod.MODID)
public class PlayerVariable implements INBTSerializable<CompoundTag> { public class PlayerVariable implements INBTSerializable<CompoundTag> {
private PlayerVariable old = null; private PlayerVariable old = null;
public boolean zoom = false;
public boolean holdFire = false;
public int rifleAmmo = 0; public int rifleAmmo = 0;
public int handgunAmmo = 0; public int handgunAmmo = 0;
public int shotgunAmmo = 0; public int shotgunAmmo = 0;
public int sniperAmmo = 0; public int sniperAmmo = 0;
public int heavyAmmo = 0; public int heavyAmmo = 0;
public boolean bowPullHold = false;
public boolean bowPull = false;
public boolean playerDoubleJump = false; public boolean playerDoubleJump = false;
public boolean tacticalSprint = false; public boolean tacticalSprint = false;
public int tacticalSprintTime = 600; public int tacticalSprintTime = 600;
public boolean tacticalSprintExhaustion = false; public boolean tacticalSprintExhaustion = false;
public boolean breath = false;
public int breathTime = 160;
public boolean breathExhaustion = false;
public boolean edit = false; public boolean edit = false;
public void sync(Entity entity) { public void sync(Entity entity) {
@ -65,44 +57,29 @@ public class PlayerVariable implements INBTSerializable<CompoundTag> {
public CompoundTag writeToNBT() { public CompoundTag writeToNBT() {
CompoundTag nbt = new CompoundTag(); CompoundTag nbt = new CompoundTag();
nbt.putBoolean("Zoom", zoom);
nbt.putBoolean("HoldFire", holdFire);
for (var type : AmmoType.values()) { for (var type : AmmoType.values()) {
type.set(nbt, type.get(this)); type.set(nbt, type.get(this));
} }
nbt.putBoolean("BowPullHold", bowPullHold);
nbt.putBoolean("BowPull", bowPull);
nbt.putBoolean("DoubleJump", playerDoubleJump); nbt.putBoolean("DoubleJump", playerDoubleJump);
nbt.putBoolean("TacticalSprint", tacticalSprint); nbt.putBoolean("TacticalSprint", tacticalSprint);
nbt.putInt("TacticalSprintTime", tacticalSprintTime); nbt.putInt("TacticalSprintTime", tacticalSprintTime);
nbt.putBoolean("TacticalSprintExhaustion", tacticalSprintExhaustion); nbt.putBoolean("TacticalSprintExhaustion", tacticalSprintExhaustion);
nbt.putBoolean("Breath", breath);
nbt.putInt("BreathTime", breathTime);
nbt.putBoolean("BreathExhaustion", breathExhaustion);
nbt.putBoolean("EditMode", edit); nbt.putBoolean("EditMode", edit);
return nbt; return nbt;
} }
public PlayerVariable readFromNBT(CompoundTag tag) { public PlayerVariable readFromNBT(CompoundTag tag) {
zoom = tag.getBoolean("Zoom");
holdFire = tag.getBoolean("HoldFire");
for (var type : AmmoType.values()) { for (var type : AmmoType.values()) {
type.set(this, type.get(tag)); type.set(this, type.get(tag));
} }
bowPullHold = tag.getBoolean("BowPullHold");
bowPull = tag.getBoolean("BowPull");
playerDoubleJump = tag.getBoolean("DoubleJump"); playerDoubleJump = tag.getBoolean("DoubleJump");
tacticalSprint = tag.getBoolean("TacticalSprint"); tacticalSprint = tag.getBoolean("TacticalSprint");
tacticalSprintTime = tag.getInt("TacticalSprintTime"); tacticalSprintTime = tag.getInt("TacticalSprintTime");
tacticalSprintExhaustion = tag.getBoolean("TacticalSprintExhaustion"); tacticalSprintExhaustion = tag.getBoolean("TacticalSprintExhaustion");
breath = tag.getBoolean("Breath");
breathTime = tag.getInt("BreathTime");
breathExhaustion = tag.getBoolean("BreathExhaustion");
edit = tag.getBoolean("EditMode"); edit = tag.getBoolean("EditMode");
return this; return this;
@ -111,22 +88,15 @@ public class PlayerVariable implements INBTSerializable<CompoundTag> {
public PlayerVariable copy() { public PlayerVariable copy() {
var clone = new PlayerVariable(); var clone = new PlayerVariable();
clone.zoom = this.zoom;
clone.holdFire = this.holdFire;
clone.rifleAmmo = this.rifleAmmo; clone.rifleAmmo = this.rifleAmmo;
clone.handgunAmmo = this.handgunAmmo; clone.handgunAmmo = this.handgunAmmo;
clone.shotgunAmmo = this.shotgunAmmo; clone.shotgunAmmo = this.shotgunAmmo;
clone.sniperAmmo = this.sniperAmmo; clone.sniperAmmo = this.sniperAmmo;
clone.heavyAmmo = this.heavyAmmo; clone.heavyAmmo = this.heavyAmmo;
clone.bowPullHold = this.bowPullHold;
clone.bowPull = this.bowPull;
clone.playerDoubleJump = this.playerDoubleJump; clone.playerDoubleJump = this.playerDoubleJump;
clone.tacticalSprint = this.tacticalSprint; clone.tacticalSprint = this.tacticalSprint;
clone.tacticalSprintTime = this.tacticalSprintTime; clone.tacticalSprintTime = this.tacticalSprintTime;
clone.tacticalSprintExhaustion = this.tacticalSprintExhaustion; clone.tacticalSprintExhaustion = this.tacticalSprintExhaustion;
clone.breath = this.breath;
clone.breathTime = this.breathTime;
clone.breathExhaustion = this.breathExhaustion;
clone.edit = this.edit; clone.edit = this.edit;
return clone; return clone;
@ -136,22 +106,14 @@ public class PlayerVariable implements INBTSerializable<CompoundTag> {
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (!(obj instanceof PlayerVariable other)) return false; if (!(obj instanceof PlayerVariable other)) return false;
return zoom == other.zoom return rifleAmmo == other.rifleAmmo
&& holdFire == other.holdFire
&& rifleAmmo == other.rifleAmmo
&& handgunAmmo == other.handgunAmmo && handgunAmmo == other.handgunAmmo
&& shotgunAmmo == other.shotgunAmmo && shotgunAmmo == other.shotgunAmmo
&& sniperAmmo == other.sniperAmmo && sniperAmmo == other.sniperAmmo
&& heavyAmmo == other.heavyAmmo && heavyAmmo == other.heavyAmmo
&& bowPullHold == other.bowPullHold
&& bowPull == other.bowPull
&& playerDoubleJump == other.playerDoubleJump && playerDoubleJump == other.playerDoubleJump
&& tacticalSprint == other.tacticalSprint && tacticalSprint == other.tacticalSprint
// && tacticalSprintTime == other.tacticalSprintTime
&& tacticalSprintExhaustion == other.tacticalSprintExhaustion && tacticalSprintExhaustion == other.tacticalSprintExhaustion
&& breath == other.breath
// && breathTime == other.breathTime
&& breathExhaustion == other.breathExhaustion
&& edit == other.edit; && edit == other.edit;
} }

View file

@ -275,7 +275,7 @@ public class ClickHandler {
} }
if (key == ModKeyMappings.BREATH.getKey().getValue()) { if (key == ModKeyMappings.BREATH.getKey().getValue()) {
PacketDistributor.sendToServer(new BreathMessage(true)); // PacketDistributor.sendToServer(new BreathMessage(true));
} }
} else { } else {
if (player.hasEffect(ModMobEffects.SHOCK)) return; if (player.hasEffect(ModMobEffects.SHOCK)) return;
@ -293,7 +293,7 @@ public class ClickHandler {
} }
if (event.getAction() == GLFW.GLFW_RELEASE && key == ModKeyMappings.BREATH.getKey().getValue()) { if (event.getAction() == GLFW.GLFW_RELEASE && key == ModKeyMappings.BREATH.getKey().getValue()) {
PacketDistributor.sendToServer(new BreathMessage(false)); // PacketDistributor.sendToServer(new BreathMessage(false));
} }
} }
} }
@ -343,14 +343,12 @@ public class ClickHandler {
ClientEventHandler.burstFireAmount = data.burstAmount(); ClientEventHandler.burstFireAmount = data.burstAmount();
} }
} else { } else {
if (!stack.is(ModItems.BOCEK.get())) {
ClientEventHandler.holdFire = true; ClientEventHandler.holdFire = true;
} }
} }
} }
} }
} }
}
public static void handleWeaponFireRelease() { public static void handleWeaponFireRelease() {
PacketDistributor.sendToServer(new FireMessage(1)); PacketDistributor.sendToServer(new FireMessage(1));

View file

@ -1,7 +1,6 @@
package com.atsuishio.superbwarfare.entity; package com.atsuishio.superbwarfare.entity;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.init.ModAttachments;
import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.tools.FormatTool; import com.atsuishio.superbwarfare.tools.FormatTool;
@ -145,13 +144,11 @@ public class TargetEntity extends LivingEntity implements GeoEntity {
player.addItem(new ItemStack(ModItems.TARGET_DEPLOYER.get())); player.addItem(new ItemStack(ModItems.TARGET_DEPLOYER.get()));
} }
} else { } else {
if (!player.getData(ModAttachments.PLAYER_VARIABLE).zoom) {
this.lookAt(EntityAnchorArgument.Anchor.EYES, new Vec3((player.getX()), this.getY(), (player.getZ()))); this.lookAt(EntityAnchorArgument.Anchor.EYES, new Vec3((player.getX()), this.getY(), (player.getZ())));
this.setXRot(0); this.setXRot(0);
this.xRotO = this.getXRot(); this.xRotO = this.getXRot();
this.entityData.set(DOWN_TIME, 0); this.entityData.set(DOWN_TIME, 0);
} }
}
return InteractionResult.sidedSuccess(this.level().isClientSide()); return InteractionResult.sidedSuccess(this.level().isClientSide());
} }

View file

@ -123,6 +123,7 @@ public class ClientEventHandler {
public static boolean holdFire = false; public static boolean holdFire = false;
public static boolean zoom = false; public static boolean zoom = false;
public static boolean breath = false;
public static boolean holdFireVehicle = false; public static boolean holdFireVehicle = false;
public static boolean zoomVehicle = false; public static boolean zoomVehicle = false;
@ -630,7 +631,7 @@ public class ClientEventHandler {
if (!stack.is(ModTags.Items.GUN)) return; if (!stack.is(ModTags.Items.GUN)) return;
var data = GunData.from(stack); var data = GunData.from(stack);
PacketDistributor.sendToServer(new ShootMessage(gunSpread)); PacketDistributor.sendToServer(new ShootMessage(gunSpread, zoom));
fireRecoilTime = 10; fireRecoilTime = 10;
var gunRecoilY = data.recoilY() * 10; var gunRecoilY = data.recoilY() * 10;
@ -848,9 +849,7 @@ public class ClientEventHandler {
double customWeight = data.customWeight(); double customWeight = data.customWeight();
var cap = player.getData(ModAttachments.PLAYER_VARIABLE); if (!breath && zoom) {
if (!cap.breath && cap.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)); 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.setXRot(newPitch);
player.xRotO = player.getXRot(); player.xRotO = player.getXRot();
@ -1268,7 +1267,6 @@ public class ClientEventHandler {
private static void handlePlayerBreath(LivingEntity entity) { private static void handlePlayerBreath(LivingEntity entity) {
float times = (float) Math.min(Minecraft.getInstance().getTimer().getRealtimeDeltaTicks(), 0.8); 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); breathTime = Mth.lerp(0.2f * times, breathTime, breath ? 1 : 0);
} }
@ -1339,7 +1337,7 @@ public class ClientEventHandler {
private static void handleBowPullAnimation(LivingEntity entity) { private static void handleBowPullAnimation(LivingEntity entity) {
float times = 4 * (float) Math.min(Minecraft.getInstance().getTimer().getRealtimeDeltaTicks(), 0.8); 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); pullTimer = Math.min(pullTimer + 0.024 * times, 1.4);
bowTimer = Math.min(bowTimer + 0.018 * times, 1); bowTimer = Math.min(bowTimer + 0.018 * times, 1);
handTimer = Math.min(handTimer + 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) { public static void aimAtVillager(Player player) {
if (aimVillagerCountdown > 0) return; if (aimVillagerCountdown > 0) return;
if (player.getData(ModAttachments.PLAYER_VARIABLE).zoom) { if (zoom) {
Entity entity = TraceTool.findLookingEntity(player, 10); Entity entity = TraceTool.findLookingEntity(player, 10);
if (entity instanceof AbstractVillager villager) { if (entity instanceof AbstractVillager villager) {
List<Entity> entities = SeekTool.seekLivingEntities(villager, villager.level(), 16, 120); List<Entity> entities = SeekTool.seekLivingEntities(villager, villager.level(), 16, 120);

View file

@ -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(); var stack = data.stack();
if (!player.level().isClientSide()) { if (!player.level().isClientSide()) {
@ -178,7 +178,6 @@ public class GunEventHandler {
float velocity = (float) (data.velocity() * perkSpeed(data)); float velocity = (float) (data.velocity() * perkSpeed(data));
int projectileAmount = data.projectileAmount(); int projectileAmount = data.projectileAmount();
float bypassArmorRate = (float) data.bypassArmor(); float bypassArmorRate = (float) data.bypassArmor();
boolean zoom = player.getData(ModAttachments.PLAYER_VARIABLE).zoom;
var perkInstance = data.perk.getInstance(Perk.Type.AMMO); var perkInstance = data.perk.getInstance(Perk.Type.AMMO);
var perk = perkInstance != null ? perkInstance.perk() : null; var perk = perkInstance != null ? perkInstance.perk() : null;

View file

@ -382,11 +382,6 @@ public class LivingEventHandler {
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch(); var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
cap.edit = false; cap.edit = false;
if (oldStack.is(ModItems.BOCEK)) {
oldData.data().putInt("Power", 0);
cap.bowPullHold = false;
}
player.setData(ModAttachments.PLAYER_VARIABLE, cap); player.setData(ModAttachments.PLAYER_VARIABLE, cap);
cap.sync(player); cap.sync(player);
@ -421,10 +416,6 @@ public class LivingEventHandler {
} }
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch(); 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); int level = newData.perk.getLevel(ModPerks.KILLING_TALLY);
if (level != 0) { if (level != 0) {

View file

@ -4,12 +4,14 @@ import com.atsuishio.superbwarfare.config.common.GameplayConfig;
import com.atsuishio.superbwarfare.config.server.MiscConfig; import com.atsuishio.superbwarfare.config.server.MiscConfig;
import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModAttachments;
import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModItems;
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.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.data.GunData;
import com.atsuishio.superbwarfare.network.message.receive.SimulationDistanceMessage; 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.ServerLevel;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundEvents;
@ -57,7 +59,6 @@ public class PlayerEventHandler {
Player player = event.getEntity(); Player player = event.getEntity();
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch(); var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
cap.zoom = false;
cap.tacticalSprintExhaustion = false; cap.tacticalSprintExhaustion = false;
cap.tacticalSprintTime = 600; cap.tacticalSprintTime = 600;
player.setData(ModAttachments.PLAYER_VARIABLE, cap); player.setData(ModAttachments.PLAYER_VARIABLE, cap);
@ -87,37 +88,14 @@ public class PlayerEventHandler {
if (stack.is(ModTags.Items.GUN)) { if (stack.is(ModTags.Items.GUN)) {
handlePlayerSprint(player); handlePlayerSprint(player);
handleSpecialWeaponAmmo(player); handleSpecialWeaponAmmo(player);
handleBocekPulling(player);
} }
handleGround(player); handleGround(player);
handleTacticalSprint(player); handleTacticalSprint(player);
handleBreath(player);
variable.sync(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) { private static void handleTacticalSprint(Player player) {
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch(); var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
@ -171,23 +149,23 @@ public class PlayerEventHandler {
* 判断玩家是否在奔跑 * 判断玩家是否在奔跑
*/ */
private static void handlePlayerSprint(Player player) { 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); player.getPersistentData().putDouble("noRun", 10);
} }
if (player.isShiftKeyDown() if (player.isShiftKeyDown()
|| player.isPassenger() || player.isPassenger()
|| player.isInWater() || player.isInWater()
|| cap.zoom || ClientEventHandler.zoom
) player.getPersistentData().putDouble("noRun", 3); ) player.getPersistentData().putDouble("noRun", 3);
if (player.getPersistentData().getDouble("noRun") > 0) { if (player.getPersistentData().getDouble("noRun") > 0) {
player.getPersistentData().putDouble("noRun", (player.getPersistentData().getDouble("noRun") - 1)); player.getPersistentData().putDouble("noRun", (player.getPersistentData().getDouble("noRun") - 1));
} }
if (cap.zoom || cap.holdFire) { if (ClientEventHandler.zoom || ClientEventHandler.holdFire) {
player.setSprinting(false); 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) { private static void handleSimulationDistance(Player player) {
if (player.level() instanceof ServerLevel serverLevel && player instanceof ServerPlayer serverPlayer) { if (player.level() instanceof ServerLevel serverLevel && player instanceof ServerPlayer serverPlayer) {
var distance = serverLevel.getChunkSource().chunkMap.serverViewDistance; var distance = serverLevel.getChunkSource().chunkMap.serverViewDistance;

View file

@ -16,7 +16,7 @@ public interface SpecialFireWeapon {
* @param player 玩家 * @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 玩家 * @param player 玩家
*/ */
default void fireOnRelease(Player player, final GunData data) { default void fireOnRelease(Player player, final GunData data, double power, boolean zoom) {
} }
} }

View file

@ -294,7 +294,7 @@ public class JavelinItem extends GunItem implements GeoItem, SpecialFireWeapon {
} }
@Override @Override
public void fireOnRelease(Player player, final GunData data) { public void fireOnRelease(Player player, final GunData data, double power, boolean zoom) {
fire(player); fire(player);
var tag = data.tag(); var tag = data.tag();
tag.putBoolean("Seeking", false); tag.putBoolean("Seeking", false);
@ -307,10 +307,10 @@ public class JavelinItem extends GunItem implements GeoItem, SpecialFireWeapon {
} }
@Override @Override
public void fireOnPress(Player player, final GunData data) { public void fireOnPress(Player player, final GunData data, boolean zoom) {
var tag = data.tag(); 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); Entity seekingEntity = SeekTool.seekEntity(player, player.level(), 512, 8);

View file

@ -5,7 +5,10 @@ import com.atsuishio.superbwarfare.client.renderer.item.M79ItemRenderer;
import com.atsuishio.superbwarfare.client.tooltip.component.LauncherImageComponent; import com.atsuishio.superbwarfare.client.tooltip.component.LauncherImageComponent;
import com.atsuishio.superbwarfare.entity.projectile.GunGrenadeEntity; import com.atsuishio.superbwarfare.entity.projectile.GunGrenadeEntity;
import com.atsuishio.superbwarfare.event.ClientEventHandler; 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.GunItem;
import com.atsuishio.superbwarfare.item.gun.SpecialFireWeapon; import com.atsuishio.superbwarfare.item.gun.SpecialFireWeapon;
import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.data.GunData;
@ -165,12 +168,11 @@ public class M79Item extends GunItem implements GeoItem, SpecialFireWeapon {
} }
@Override @Override
public void fireOnPress(Player player, final GunData data) { public void fireOnPress(Player player, final GunData data, boolean zoom) {
if (data.reloading()) return; if (data.reloading()) return;
ItemStack stack = data.stack(); ItemStack stack = data.stack();
if (player.getCooldowns().isOnCooldown(stack.getItem()) || data.ammo() <= 0) return; if (player.getCooldowns().isOnCooldown(stack.getItem()) || data.ammo() <= 0) return;
boolean zooming = player.getData(ModAttachments.PLAYER_VARIABLE).zoom;
double spread = data.spread(); double spread = data.spread();
if (player.level() instanceof ServerLevel serverLevel) { 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.setPos(player.getX(), player.getEyeY() - 0.1, player.getZ());
gunGrenadeEntity.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, velocity, 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); serverLevel.addFreshEntity(gunGrenadeEntity);
ParticleTool.sendParticle(serverLevel, ParticleTypes.CLOUD, player.getX() + 1.8 * player.getLookAngle().x, ParticleTool.sendParticle(serverLevel, ParticleTypes.CLOUD, player.getX() + 1.8 * player.getLookAngle().x,

View file

@ -5,7 +5,10 @@ import com.atsuishio.superbwarfare.client.renderer.item.RpgItemRenderer;
import com.atsuishio.superbwarfare.client.tooltip.component.LauncherImageComponent; import com.atsuishio.superbwarfare.client.tooltip.component.LauncherImageComponent;
import com.atsuishio.superbwarfare.entity.projectile.RpgRocketEntity; import com.atsuishio.superbwarfare.entity.projectile.RpgRocketEntity;
import com.atsuishio.superbwarfare.event.ClientEventHandler; 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.GunItem;
import com.atsuishio.superbwarfare.item.gun.SpecialFireWeapon; import com.atsuishio.superbwarfare.item.gun.SpecialFireWeapon;
import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.data.GunData;
@ -178,7 +181,7 @@ public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon {
} }
@Override @Override
public void fireOnPress(Player player, final GunData data) { public void fireOnPress(Player player, final GunData data, boolean zoom) {
Level level = player.level(); Level level = player.level();
ItemStack stack = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
@ -187,7 +190,6 @@ public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon {
|| data.ammo() <= 0 || data.ammo() <= 0
) return; ) return;
boolean zoom = player.getData(ModAttachments.PLAYER_VARIABLE).zoom;
double spread = data.spread(); double spread = data.spread();
if (player.level() instanceof ServerLevel serverLevel) { if (player.level() instanceof ServerLevel serverLevel) {

View file

@ -266,18 +266,17 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, SpecialFireW
} }
@Override @Override
public void fireOnPress(Player player, final GunData data) { public void fireOnPress(Player player, final GunData data, boolean zoom) {
if (data.reloading()) return; if (data.reloading()) return;
ItemStack stack = data.stack(); ItemStack stack = data.stack();
if (player.getCooldowns().isOnCooldown(stack.getItem()) || data.ammo() <= 0) return; if (player.getCooldowns().isOnCooldown(stack.getItem()) || data.ammo() <= 0) return;
boolean zooming = player.getData(ModAttachments.PLAYER_VARIABLE).zoom;
double spread = data.spread(); double spread = data.spread();
var stackCap = stack.getCapability(Capabilities.EnergyStorage.ITEM); var stackCap = stack.getCapability(Capabilities.EnergyStorage.ITEM);
var hasEnoughEnergy = stackCap != null && stackCap.getEnergyStored() >= 3000; var hasEnoughEnergy = stackCap != null && stackCap.getEnergyStored() >= 3000;
boolean isChargedFire = zooming && hasEnoughEnergy; boolean isChargedFire = zoom && hasEnoughEnergy;
if (player.level() instanceof ServerLevel serverLevel) { if (player.level() instanceof ServerLevel serverLevel) {
GunGrenadeEntity gunGrenadeEntity = new GunGrenadeEntity(player, 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.setPos(player.getX(), player.getEyeY() - 0.1, player.getZ());
gunGrenadeEntity.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, (isChargedFire ? 4 : 1) * velocity, 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); serverLevel.addFreshEntity(gunGrenadeEntity);
ParticleTool.sendParticle(serverLevel, ParticleTypes.CLOUD, player.getX() + 1.8 * player.getLookAngle().x, ParticleTool.sendParticle(serverLevel, ParticleTypes.CLOUD, player.getX() + 1.8 * player.getLookAngle().x,

View file

@ -4,11 +4,13 @@ import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.renderer.item.BocekItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.BocekItemRenderer;
import com.atsuishio.superbwarfare.client.tooltip.component.BocekImageComponent; import com.atsuishio.superbwarfare.client.tooltip.component.BocekImageComponent;
import com.atsuishio.superbwarfare.event.ClientEventHandler; 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.GunItem;
import com.atsuishio.superbwarfare.item.gun.SpecialFireWeapon; import com.atsuishio.superbwarfare.item.gun.SpecialFireWeapon;
import com.atsuishio.superbwarfare.item.gun.data.GunData; 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.AmmoPerk;
import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.tools.GunsTool; 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.Items;
import net.minecraft.world.item.Rarity; import net.minecraft.world.item.Rarity;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.neoforged.neoforge.network.PacketDistributor;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import software.bernie.geckolib.animatable.GeoItem; import software.bernie.geckolib.animatable.GeoItem;
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
@ -164,29 +165,22 @@ public class BocekItem extends GunItem implements GeoItem, SpecialFireWeapon {
} }
@Override @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; if (player.level().isClientSide()) return;
var tag = data.tag(); var tag = data.tag();
var stack = data.stack(); var stack = data.stack();
var perk = data.perk.get(Perk.Type.AMMO); var perk = data.perk.get(Perk.Type.AMMO);
if (player instanceof ServerPlayer serverPlayer) { if (power * 12 >= 6) {
SoundTool.stopSound(serverPlayer, ModSounds.BOCEK_PULL_1P.getId(), SoundSource.PLAYERS); if (zoom) {
SoundTool.stopSound(serverPlayer, ModSounds.BOCEK_PULL_3P.getId(), SoundSource.PLAYERS); spawnBullet(player, tag, power, true);
PacketDistributor.sendToPlayer(serverPlayer, new ShootClientMessage(10));
}
if (GunsTool.getGunDoubleTag(tag, "Power") >= 6) {
if (player.getData(ModAttachments.PLAYER_VARIABLE).zoom) {
spawnBullet(player, tag);
SoundTool.playLocalSound(player, ModSounds.BOCEK_ZOOM_FIRE_1P.get(), 10, 1); SoundTool.playLocalSound(player, ModSounds.BOCEK_ZOOM_FIRE_1P.get(), 10, 1);
player.playSound(ModSounds.BOCEK_ZOOM_FIRE_3P.get(), 2, 1); player.playSound(ModSounds.BOCEK_ZOOM_FIRE_3P.get(), 2, 1);
} else { } else {
for (int i = 0; i < (perk instanceof AmmoPerk ammoPerk && ammoPerk.slug ? 1 : 10); i++) { 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); 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); player.getCooldowns().addCooldown(stack.getItem(), 7);
GunsTool.setGunIntTag(tag, "ArrowEmpty", 7); GunsTool.setGunIntTag(tag, "ArrowEmpty", 7);
GunsTool.setGunDoubleTag(tag, "Power", 0);
if (!InventoryTool.hasCreativeAmmoBox(player) && !player.isCreative()) { if (!InventoryTool.hasCreativeAmmoBox(player) && !player.isCreative()) {
player.getInventory().clearOrCountMatchingItems(p -> Items.ARROW == p.getItem(), 1, player.inventoryMenu.getCraftSlots()); 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 @Override
public void fireOnPress(Player player, final GunData data) { public void fireOnPress(Player player, final GunData data, boolean zoom) {
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch(); if (player instanceof ServerPlayer serverPlayer) {
cap.bowPullHold = true; SoundTool.stopSound(serverPlayer, ModSounds.BOCEK_PULL_1P.getId(), SoundSource.PLAYERS);
player.setData(ModAttachments.PLAYER_VARIABLE, cap); SoundTool.stopSound(serverPlayer, ModSounds.BOCEK_PULL_3P.getId(), SoundSource.PLAYERS);
cap.sync(player); }
} }
} }

View file

@ -5,7 +5,10 @@ import com.atsuishio.superbwarfare.client.renderer.item.TaserItemRenderer;
import com.atsuishio.superbwarfare.client.tooltip.component.EnergyImageComponent; import com.atsuishio.superbwarfare.client.tooltip.component.EnergyImageComponent;
import com.atsuishio.superbwarfare.entity.projectile.TaserBulletEntity; import com.atsuishio.superbwarfare.entity.projectile.TaserBulletEntity;
import com.atsuishio.superbwarfare.event.ClientEventHandler; 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.EnergyStorageItem;
import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
import com.atsuishio.superbwarfare.item.gun.SpecialFireWeapon; import com.atsuishio.superbwarfare.item.gun.SpecialFireWeapon;
@ -217,7 +220,7 @@ public class TaserItem extends GunItem implements GeoItem, SpecialFireWeapon, En
} }
@Override @Override
public void fireOnPress(Player player, final GunData data) { public void fireOnPress(Player player, final GunData data, boolean zoom) {
if (data.reloading()) return; if (data.reloading()) return;
ItemStack stack = data.stack(); ItemStack stack = data.stack();
@ -233,7 +236,6 @@ public class TaserItem extends GunItem implements GeoItem, SpecialFireWeapon, En
player.getCooldowns().addCooldown(stack.getItem(), 5); player.getCooldowns().addCooldown(stack.getItem(), 5);
if (player instanceof ServerPlayer serverPlayer) { if (player instanceof ServerPlayer serverPlayer) {
boolean zoom = player.getData(ModAttachments.PLAYER_VARIABLE).zoom;
double spread = data.spread(); double spread = data.spread();
int volt = data.perk.getLevel(ModPerks.VOLT_OVERLOAD); int volt = data.perk.getLevel(ModPerks.VOLT_OVERLOAD);

View file

@ -24,7 +24,6 @@ public class NetworkRegistry {
registrar.playToClient(SimulationDistanceMessage.TYPE, SimulationDistanceMessage.STREAM_CODEC, SimulationDistanceMessage::handler); registrar.playToClient(SimulationDistanceMessage.TYPE, SimulationDistanceMessage.STREAM_CODEC, SimulationDistanceMessage::handler);
registrar.playToServer(LaserShootMessage.TYPE, LaserShootMessage.STREAM_CODEC, LaserShootMessage::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(ShootMessage.TYPE, ShootMessage.STREAM_CODEC, ShootMessage::handler);
registrar.playToServer(DoubleJumpMessage.TYPE, DoubleJumpMessage.STREAM_CODEC, DoubleJumpMessage::handler); registrar.playToServer(DoubleJumpMessage.TYPE, DoubleJumpMessage.STREAM_CODEC, DoubleJumpMessage::handler);
registrar.playToServer(VehicleMovementMessage.TYPE, VehicleMovementMessage.STREAM_CODEC, VehicleMovementMessage::handler); registrar.playToServer(VehicleMovementMessage.TYPE, VehicleMovementMessage.STREAM_CODEC, VehicleMovementMessage::handler);

View file

@ -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<BreathMessage> TYPE = new Type<>(Mod.loc("breath"));
public static final StreamCodec<ByteBuf, BreathMessage> 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<? extends CustomPacketPayload> type() {
return TYPE;
}
}

View file

@ -2,15 +2,16 @@ package com.atsuishio.superbwarfare.network.message.send;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.event.GunEventHandler; import com.atsuishio.superbwarfare.event.GunEventHandler;
import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModAttachments;
import com.atsuishio.superbwarfare.init.ModPerks; import com.atsuishio.superbwarfare.init.ModPerks;
import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.gun.SpecialFireWeapon; import com.atsuishio.superbwarfare.item.gun.SpecialFireWeapon;
import com.atsuishio.superbwarfare.item.gun.data.GunData; 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.AmmoPerk;
import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.tools.GunsTool;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
@ -63,18 +64,15 @@ public record FireMessage(int msgType) implements CustomPacketPayload {
cap.sync(player); cap.sync(player);
return; return;
} }
specialFireWeapon.fireOnPress(player, data); specialFireWeapon.fireOnPress(player, data, ClientEventHandler.zoom);
cap.holdFire = true;
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
} else if (type == 1) { } else if (type == 1) {
cap.bowPullHold = false;
cap.holdFire = false;
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
// 松开开火 // 松开开火
if (stack.getItem() instanceof SpecialFireWeapon specialFireWeapon) { 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); 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) { public static double perkSpeed(Perk perk) {
if (perk instanceof AmmoPerk ammoPerk) { if (perk instanceof AmmoPerk ammoPerk) {
return ammoPerk.speedRate; return ammoPerk.speedRate;
@ -107,29 +112,26 @@ public record FireMessage(int msgType) implements CustomPacketPayload {
return 1; 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(); ItemStack stack = player.getMainHandItem();
if (player.level().isClientSide()) return; if (player.level().isClientSide()) return;
var data = GunData.from(stack); var data = GunData.from(stack);
var perk = data.perk.get(Perk.Type.AMMO); var perk = data.perk.get(Perk.Type.AMMO);
float headshot = (float) data.headshot(); 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(); float bypassArmorRate = (float) data.bypassArmor();
double damage; double damage;
boolean zoom = player.getData(ModAttachments.PLAYER_VARIABLE).zoom;
float spread; float spread;
if (zoom) { if (zoom) {
spread = 0.01f; spread = 0.01f;
damage = 0.08333333 * data.damage() * damage = 0.08333333 * data.damage() *
GunsTool.getGunDoubleTag(tag, "Power", 6); 12 * power * perkDamage(perk);
} 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) *
data.damage() * data.damage() * 12 * power * perkDamage(perk);
GunsTool.getGunDoubleTag(tag, "Power", 6);
} }
ProjectileEntity projectile = new ProjectileEntity(player.level()) ProjectileEntity projectile = new ProjectileEntity(player.level())

View file

@ -23,21 +23,23 @@ import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.network.handling.IPayloadContext; import net.neoforged.neoforge.network.handling.IPayloadContext;
import org.jetbrains.annotations.NotNull; 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<ShootMessage> TYPE = new Type<>(Mod.loc("shoot")); public static final Type<ShootMessage> TYPE = new Type<>(Mod.loc("shoot"));
public static final StreamCodec<ByteBuf, ShootMessage> STREAM_CODEC = StreamCodec.composite( public static final StreamCodec<ByteBuf, ShootMessage> STREAM_CODEC = StreamCodec.composite(
ByteBufCodecs.DOUBLE, ByteBufCodecs.DOUBLE,
ShootMessage::spread, ShootMessage::spread,
ByteBufCodecs.BOOL,
ShootMessage::zoom,
ShootMessage::new ShootMessage::new
); );
public static void handler(final ShootMessage message, final IPayloadContext context) { 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(); ItemStack stack = player.getMainHandItem();
var data = GunData.from(stack); var data = GunData.from(stack);
var tag = data.tag(); var tag = data.tag();
@ -86,7 +88,7 @@ public record ShootMessage(double spread) implements CustomPacketPayload {
var perk = data.perk.get(Perk.Type.AMMO); var perk = data.perk.get(Perk.Type.AMMO);
for (int index0 = 0; index0 < (perk instanceof AmmoPerk ammoPerk && ammoPerk.slug ? 1 : projectileAmount); index0++) { 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); 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)) { if (!InventoryTool.hasCreativeAmmoBox(player)) {
cap.rifleAmmo = cap.rifleAmmo - 1; cap.rifleAmmo = cap.rifleAmmo - 1;
player.setData(ModAttachments.PLAYER_VARIABLE, cap); player.setData(ModAttachments.PLAYER_VARIABLE, cap);

View file

@ -35,7 +35,6 @@ public record ZoomMessage(int msgType) implements CustomPacketPayload {
var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch(); var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch();
if (message.msgType == 0) { if (message.msgType == 0) {
cap.zoom = true;
cap.edit = false; cap.edit = false;
player.setData(ModAttachments.PLAYER_VARIABLE, cap); player.setData(ModAttachments.PLAYER_VARIABLE, cap);
cap.sync(player); cap.sync(player);
@ -50,11 +49,6 @@ public record ZoomMessage(int msgType) implements CustomPacketPayload {
} }
} else if (message.msgType == 1) { } else if (message.msgType == 1) {
cap.zoom = false;
cap.breath = false;
player.setData(ModAttachments.PLAYER_VARIABLE, cap);
cap.sync(player);
if (player.isPassenger() if (player.isPassenger()
&& vehicle instanceof WeaponVehicleEntity weaponEntity && vehicle instanceof WeaponVehicleEntity weaponEntity
&& vehicle instanceof VehicleEntity vehicleEntity && vehicle instanceof VehicleEntity vehicleEntity