加入跑射延迟(大悲
This commit is contained in:
parent
1c0dd5f938
commit
99b690238e
6 changed files with 44 additions and 13 deletions
|
@ -79,6 +79,7 @@ public class ClientEventHandler {
|
|||
public static double handPos = 0;
|
||||
public static double gunSpread = 0;
|
||||
public static double fireSpread = 0;
|
||||
public static double cantFireTime = 0;
|
||||
|
||||
public static MillisTimer clientTimer = new MillisTimer();
|
||||
|
||||
|
@ -165,8 +166,18 @@ public class ClientEventHandler {
|
|||
}
|
||||
|
||||
// 开火部分
|
||||
|
||||
if (player.getPersistentData().getDouble("noRun") == 0 && player.isSprinting() && GLFW.glfwGetMouseButton(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_MOUSE_BUTTON_RIGHT) != GLFW.GLFW_PRESS) {
|
||||
cantFireTime = Mth.clamp(cantFireTime + 3 * times,0,30);
|
||||
} else {
|
||||
cantFireTime = Mth.clamp(cantFireTime - 6 * times,0,30);
|
||||
}
|
||||
|
||||
// player.displayClientMessage(Component.literal(new java.text.DecimalFormat("##").format(cantFireTime)), true);
|
||||
|
||||
if (GLFW.glfwGetMouseButton(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_MOUSE_BUTTON_LEFT) == GLFW.GLFW_PRESS
|
||||
&& (player.getMainHandItem().is(ModTags.Items.NORMAL_GUN)
|
||||
&& cantFireTime == 0
|
||||
&& !notInGame()
|
||||
|| (stack.is(ModItems.MINIGUN.get()) && !player.isSprinting() && stack.getOrCreateTag().getDouble("overheat") == 0 && !player.getCooldowns().isOnCooldown(stack.getItem()) && stack.getOrCreateTag().getDouble("minigun_rotation") >= 10
|
||||
))) {
|
||||
|
|
|
@ -83,7 +83,7 @@ public class GunEventHandler {
|
|||
|
||||
var tag = stack.getOrCreateTag();
|
||||
|
||||
if ((player.getPersistentData().getBoolean("holdFire") || (player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).zoom)) {
|
||||
if ((player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).holdFire|| (player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).zoom) {
|
||||
if (tag.getDouble("minigun_rotation") < 10) {
|
||||
tag.putDouble("minigun_rotation", (tag.getDouble("minigun_rotation") + 1));
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import net.mcreator.superbwarfare.init.ModItems;
|
|||
import net.mcreator.superbwarfare.init.ModSounds;
|
||||
import net.mcreator.superbwarfare.init.ModTags;
|
||||
import net.mcreator.superbwarfare.network.ModVariables;
|
||||
import net.mcreator.superbwarfare.network.message.ReloadMessage;
|
||||
import net.mcreator.superbwarfare.network.message.SimulationDistanceMessage;
|
||||
import net.mcreator.superbwarfare.tools.ItemNBTTool;
|
||||
import net.mcreator.superbwarfare.tools.SoundTool;
|
||||
|
@ -258,15 +257,20 @@ public class PlayerEventHandler {
|
|||
player.getPersistentData().putDouble("noRun", 20);
|
||||
}
|
||||
|
||||
if (player.isShiftKeyDown() || player.isPassenger() || player.isInWater() || (player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).zoom) {
|
||||
player.getPersistentData().putDouble("noRun", 1);
|
||||
if (player.isShiftKeyDown()
|
||||
|| player.isPassenger()
|
||||
|| player.isInWater()
|
||||
|| (player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).zoom
|
||||
|| (player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).holdFire) {
|
||||
player.getPersistentData().putDouble("noRun", 3);
|
||||
}
|
||||
|
||||
if (player.getPersistentData().getDouble("noRun") > 0) {
|
||||
player.getPersistentData().putDouble("noRun", (player.getPersistentData().getDouble("noRun") - 1));
|
||||
}
|
||||
|
||||
if ((player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).zoom) {
|
||||
if ((player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).zoom
|
||||
|| (player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).holdFire) {
|
||||
player.setSprinting(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,6 +70,7 @@ public class ModVariables {
|
|||
PlayerVariables original = event.getOriginal().getCapability(PLAYER_VARIABLES_CAPABILITY, null).orElse(new PlayerVariables());
|
||||
PlayerVariables clone = event.getEntity().getCapability(PLAYER_VARIABLES_CAPABILITY, null).orElse(new PlayerVariables());
|
||||
clone.zoom = original.zoom;
|
||||
clone.holdFire = original.holdFire;
|
||||
clone.recoil = original.recoil;
|
||||
clone.recoilHorizon = original.recoilHorizon;
|
||||
clone.firing = original.firing;
|
||||
|
@ -260,6 +261,7 @@ public class ModVariables {
|
|||
|
||||
public static class PlayerVariables {
|
||||
public boolean zoom = false;
|
||||
public boolean holdFire = false;
|
||||
public double recoil = 0;
|
||||
public double recoilHorizon = 0;
|
||||
public double firing = 0;
|
||||
|
@ -287,6 +289,7 @@ public class ModVariables {
|
|||
public Tag writeNBT() {
|
||||
CompoundTag nbt = new CompoundTag();
|
||||
nbt.putBoolean("zoom", zoom);
|
||||
nbt.putBoolean("holdFire", holdFire);
|
||||
nbt.putDouble("recoil", recoil);
|
||||
nbt.putDouble("recoil_horizon", recoilHorizon);
|
||||
nbt.putDouble("firing", firing);
|
||||
|
@ -311,6 +314,7 @@ public class ModVariables {
|
|||
public void readNBT(Tag Tag) {
|
||||
CompoundTag nbt = (CompoundTag) Tag;
|
||||
zoom = nbt.getBoolean("zoom");
|
||||
holdFire = nbt.getBoolean("holdFire");
|
||||
recoil = nbt.getDouble("recoil");
|
||||
recoilHorizon = nbt.getDouble("recoil_horizon");
|
||||
firing = nbt.getDouble("firing");
|
||||
|
@ -366,6 +370,7 @@ public class ModVariables {
|
|||
|
||||
PlayerVariables variables = entity.getCapability(PLAYER_VARIABLES_CAPABILITY, null).orElse(new PlayerVariables());
|
||||
variables.zoom = message.data.zoom;
|
||||
variables.holdFire = message.data.holdFire;
|
||||
variables.recoil = message.data.recoil;
|
||||
variables.recoilHorizon = message.data.recoilHorizon;
|
||||
variables.firing = message.data.firing;
|
||||
|
|
|
@ -71,11 +71,14 @@ public class FireMessage {
|
|||
|
||||
if (type == 0) {
|
||||
handlePlayerShoot(player);
|
||||
player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
capability.holdFire = true;
|
||||
capability.syncPlayerVariables(player);
|
||||
});
|
||||
} else if (type == 1) {
|
||||
player.getPersistentData().putBoolean("holdFire", false);
|
||||
// player.getPersistentData().putBoolean("firing", false);
|
||||
player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
capability.bowPullHold = false;
|
||||
capability.holdFire = false;
|
||||
capability.syncPlayerVariables(player);
|
||||
});
|
||||
|
||||
|
@ -134,11 +137,13 @@ public class FireMessage {
|
|||
}
|
||||
|
||||
if (tag.getInt("fire_mode") == 1) {
|
||||
player.getPersistentData().putBoolean("holdFire", false);
|
||||
player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
capability.holdFire = false;
|
||||
capability.syncPlayerVariables(player);
|
||||
});
|
||||
tag.putInt("burst_fire", (int) tag.getDouble("burst_size"));
|
||||
} else {
|
||||
player.getPersistentData().putBoolean("holdFire", true);
|
||||
}
|
||||
|
||||
if (tag.getDouble("prepare") == 0 && tag.getBoolean("reloading") && tag.getInt("ammo") > 0) {
|
||||
tag.putDouble("force_stop", 1);
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ public class ShootMessage {
|
|||
int coolDownTick = (int) Math.ceil(20 / (rpm / 60));
|
||||
double mode = stack.getOrCreateTag().getInt("fire_mode");
|
||||
|
||||
if ((player.getPersistentData().getBoolean("holdFire") || stack.getOrCreateTag().getInt("burst_fire") > 0)
|
||||
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")
|
||||
|
@ -76,13 +76,19 @@ public class ShootMessage {
|
|||
|
||||
int singleInterval = 0;
|
||||
if (mode == 0) {
|
||||
player.getPersistentData().putBoolean("holdFire", false);
|
||||
player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
capability.holdFire = false;
|
||||
capability.syncPlayerVariables(player);
|
||||
});
|
||||
singleInterval = coolDownTick;
|
||||
}
|
||||
|
||||
int burstCooldown = 0;
|
||||
if (mode == 1) {
|
||||
player.getPersistentData().putBoolean("holdFire", false);
|
||||
player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||
capability.holdFire = false;
|
||||
capability.syncPlayerVariables(player);
|
||||
});
|
||||
stack.getOrCreateTag().putInt("burst_fire", (stack.getOrCreateTag().getInt("burst_fire") - 1));
|
||||
burstCooldown = stack.getOrCreateTag().getInt("burst_fire") == 0 ? coolDownTick + 4 : 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue