优化后坐力写法
This commit is contained in:
parent
5e20e54367
commit
73752fd1be
1 changed files with 20 additions and 22 deletions
|
@ -397,15 +397,14 @@ public class PlayerEventHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void handleGunRecoil(Player player) {
|
private static void handleGunRecoil(Player player) {
|
||||||
ItemStack stack = player.getMainHandItem();
|
if (!player.getMainHandItem().is(TargetModTags.Items.GUN)) return;
|
||||||
|
|
||||||
if (!stack.is(TargetModTags.Items.GUN)) {
|
CompoundTag tag = player.getMainHandItem().getOrCreateTag();
|
||||||
return;
|
float recoilX = (float) tag.getDouble("recoilx");
|
||||||
}
|
float recoilY = (float) tag.getDouble("recoily");
|
||||||
|
|
||||||
float recoilX = (float) stack.getOrCreateTag().getDouble("recoilx");
|
var capability = player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null);
|
||||||
float recoilY = (float) stack.getOrCreateTag().getDouble("recoily");
|
float recoilYaw = capability.map(c -> c.recoilHorizon).orElse(0d).floatValue();
|
||||||
float recoilYaw = (float) (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).recoilHorizon;
|
|
||||||
|
|
||||||
double[] recoilTimer = {0};
|
double[] recoilTimer = {0};
|
||||||
double totalTime = 100;
|
double totalTime = 100;
|
||||||
|
@ -414,13 +413,12 @@ public class PlayerEventHandler {
|
||||||
|
|
||||||
Runnable recoilRunnable = () -> {
|
Runnable recoilRunnable = () -> {
|
||||||
while (recoilTimer[0] < recoilDuration) {
|
while (recoilTimer[0] < recoilDuration) {
|
||||||
float rx;
|
float rx, ry;
|
||||||
float ry;
|
|
||||||
if (player.isShiftKeyDown() && player.getBbHeight() >= 1 && player.getPersistentData().getDouble("prone") == 0) {
|
if (player.isShiftKeyDown() && player.getBbHeight() >= 1 && player.getPersistentData().getDouble("prone") == 0) {
|
||||||
rx = 0.7f;
|
rx = 0.7f;
|
||||||
ry = 0.8f;
|
ry = 0.8f;
|
||||||
} else if (player.getPersistentData().getDouble("prone") > 0) {
|
} else if (player.getPersistentData().getDouble("prone") > 0) {
|
||||||
if (stack.getOrCreateTag().getDouble("bipod") == 1) {
|
if (tag.getDouble("bipod") == 1) {
|
||||||
rx = 0.05f;
|
rx = 0.05f;
|
||||||
ry = 0.1f;
|
ry = 0.1f;
|
||||||
} else {
|
} else {
|
||||||
|
@ -432,20 +430,14 @@ public class PlayerEventHandler {
|
||||||
ry = 1f;
|
ry = 1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).recoil >= 1) {
|
double recoil = capability.map(c -> c.recoil).orElse(0d);
|
||||||
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
|
||||||
capability.recoil = 0;
|
|
||||||
capability.syncPlayerVariables(player);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).recoil > 0) {
|
if (recoil >= 1) recoil = 0d;
|
||||||
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
|
||||||
capability.recoil = (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).recoil + 0.0025;
|
|
||||||
capability.syncPlayerVariables(player);
|
|
||||||
});
|
|
||||||
|
|
||||||
double sinRes = Math.sin(2 * Math.PI * (1.03f * (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).recoil - 0.032047110911)) + 0.2;
|
if (recoil > 0) {
|
||||||
|
recoil += 0.0025;
|
||||||
|
|
||||||
|
double sinRes = Math.sin(2 * Math.PI * (1.03f * recoil - 0.032047110911)) + 0.2;
|
||||||
|
|
||||||
float newPitch = ((float) (player.getXRot() - 1.5f * recoilY * ry * sinRes));
|
float newPitch = ((float) (player.getXRot() - 1.5f * recoilY * ry * sinRes));
|
||||||
player.setXRot(newPitch);
|
player.setXRot(newPitch);
|
||||||
|
@ -456,6 +448,12 @@ public class PlayerEventHandler {
|
||||||
player.yRotO = player.getYRot();
|
player.yRotO = player.getYRot();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double finalRecoil = recoil;
|
||||||
|
capability.ifPresent(c -> {
|
||||||
|
c.recoil = finalRecoil;
|
||||||
|
c.syncPlayerVariables(player);
|
||||||
|
});
|
||||||
|
|
||||||
recoilTimer[0]++;
|
recoilTimer[0]++;
|
||||||
try {
|
try {
|
||||||
Thread.sleep(sleepTime);
|
Thread.sleep(sleepTime);
|
||||||
|
|
Loading…
Add table
Reference in a new issue