SSK去营业妨碍化,重新添加后坐力流程

This commit is contained in:
Atsuihsio 2024-05-14 02:40:39 +08:00
parent 8bdc39a849
commit c22798b2b7
8 changed files with 8558 additions and 10693 deletions

View file

@ -68,7 +68,7 @@ public class PlayerEventHandler {
handleDistantRange(player); handleDistantRange(player);
handleRenderDamageIndicator(player); handleRenderDamageIndicator(player);
handleBocekPulling(player); handleBocekPulling(player);
handleGunRecoil(player); // handleGunRecoil(player);
} }
} }
@ -396,76 +396,76 @@ public class PlayerEventHandler {
} }
} }
private static void handleGunRecoil(Player player) { // private static void handleGunRecoil(Player player) {
ItemStack stack = player.getMainHandItem(); // ItemStack stack = player.getMainHandItem();
if (!stack.is(TargetModTags.Items.GUN)) { // if (!stack.is(TargetModTags.Items.GUN)) {
return; // return;
} // }
float recoilX = (float) stack.getOrCreateTag().getDouble("recoilx"); // float recoilX = (float) stack.getOrCreateTag().getDouble("recoilx");
float recoilY = (float) stack.getOrCreateTag().getDouble("recoily"); // float recoilY = (float) stack.getOrCreateTag().getDouble("recoily");
float recoilYaw = (float) (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).recoilHorizon; // 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;
int sleepTime = 2; // int sleepTime = 2;
double recoilDuration = totalTime / sleepTime; // double recoilDuration = totalTime / sleepTime;
Runnable recoilRunnable = () -> { // Runnable recoilRunnable = () -> {
while (recoilTimer[0] < recoilDuration) { // while (recoilTimer[0] < recoilDuration) {
float rx; // float rx;
float 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 (stack.getOrCreateTag().getDouble("bipod") == 1) {
rx = 0.05f; // rx = 0.05f;
ry = 0.1f; // ry = 0.1f;
} else { // } else {
rx = 0.5f; // rx = 0.5f;
ry = 0.7f; // ry = 0.7f;
} // }
} else { // } else {
rx = 1f; // rx = 1f;
ry = 1f; // ry = 1f;
} // }
double recoil = (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).recoil; // double recoil = (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).recoil;
if (recoil >= 1) { // if (recoil >= 1) {
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { // player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.recoil = 0; // capability.recoil = 0;
capability.syncPlayerVariables(player); // capability.syncPlayerVariables(player);
}); // });
} // }
if (recoil > 0) { // if (recoil > 0) {
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { // player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.recoil = recoil + 0.0025; // capability.recoil = recoil + 0.0025;
capability.syncPlayerVariables(player); // capability.syncPlayerVariables(player);
}); // });
double sinRes = Math.sin(2 * Math.PI * (1.03f * recoil - 0.032047110911)) + 0.2; // 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);
player.xRotO = player.getXRot(); // player.xRotO = player.getXRot();
float newYaw = ((float) (player.getYRot() - 1.0f * recoilYaw * recoilX * rx * sinRes)); // float newYaw = ((float) (player.getYRot() - 1.0f * recoilYaw * recoilX * rx * sinRes));
player.setYRot(newYaw); // player.setYRot(newYaw);
player.yRotO = player.getYRot(); // player.yRotO = player.getYRot();
} // }
recoilTimer[0]++; // recoilTimer[0]++;
try { // try {
Thread.sleep(sleepTime); // Thread.sleep(sleepTime);
} catch (InterruptedException e) { // } catch (InterruptedException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
} // }
}; // };
Thread recoilThread = new Thread(recoilRunnable); // Thread recoilThread = new Thread(recoilRunnable);
recoilThread.start(); // recoilThread.start();
} // }
} }

View file

@ -0,0 +1,105 @@
package net.mcreator.target.procedures;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.event.TickEvent;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Entity;
import net.mcreator.target.network.TargetModVariables;
import net.mcreator.target.init.TargetModMobEffects;
import javax.annotation.Nullable;
@Mod.EventBusSubscriber
public class GunRecoilProcedure {
@SubscribeEvent
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
if (event.phase == TickEvent.Phase.END) {
execute(event, event.player);
}
}
public static void execute(Entity entity) {
execute(null, entity);
}
private static void execute(@Nullable Event event, Entity entity) {
float recoilx = ((float) (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("recoilx"));
float recoily = ((float) (entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("recoily"));
float recoilyaw = ((float) (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).recoilHorizon);
double[] recoilTimer = {0};
double totalTime = 100;
int sleepTime = 2;
double recoilDuration = totalTime / sleepTime;
Runnable recoilRunnable = () -> {
while (recoilTimer[0] < recoilDuration) {
if (entity == null)
return;
float rx = 0;
float ry = 0;
if (entity.isShiftKeyDown() && entity.getBbHeight() >= 1 && entity.getPersistentData().getDouble("prone") == 0) {
rx = 0.7f;
ry = 0.8f;
} else if (entity.getPersistentData().getDouble("prone") > 0) {
if ((entity instanceof LivingEntity _livEnt ? _livEnt.getMainHandItem() : ItemStack.EMPTY).getOrCreateTag().getDouble("bipod") == 1) {
rx = 0.05f;
ry = 0.1f;
} else {
rx = 0.5f;
ry = 0.7f;
}
} else {
rx = 1f;
ry = 1f;
}
if ((entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).recoil >= 1) {
{
double _setval = 0;
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.recoil = _setval;
capability.syncPlayerVariables(entity);
});
}
}
if ((entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).recoil > 0) {
{
double _setval = (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).recoil + 0.0025;
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.recoil = _setval;
capability.syncPlayerVariables(entity);
});
}
float newPitch = ((float) (entity.getXRot() - 1.5f * recoily * ry * (Math.sin(2 * Math.PI * (1.03f * (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).recoil - 0.032047110911)) + 0.2)));
entity.setXRot(newPitch);
entity.xRotO = entity.getXRot();
float newYaw = ((float) (entity.getYRot() - 1.0f * recoilyaw * recoilx * rx * (Math.sin(2 * Math.PI * (1.03f * (entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).recoil - 0.032047110911)) + 0.2)));
entity.setYRot(newYaw);
entity.yRotO = entity.getYRot();
}
recoilTimer[0]++;
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
Thread recoilThread = new Thread(recoilRunnable);
recoilThread.start();
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
{ {
"parent": "item/generated", "parent": "item/generated",
"textures": { "textures": {
"layer0": "target:item/akicon" "layer0": "target:item/sks_icon"
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 118 KiB

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB