519 lines
26 KiB
Java
519 lines
26 KiB
Java
package net.mcreator.target.event;
|
|
|
|
import net.mcreator.target.init.TargetModItems;
|
|
import net.mcreator.target.init.TargetModSounds;
|
|
import net.mcreator.target.init.TargetModTags;
|
|
import net.mcreator.target.network.TargetModVariables;
|
|
import net.mcreator.target.tools.GunsTool;
|
|
import net.minecraft.commands.CommandSource;
|
|
import net.minecraft.commands.CommandSourceStack;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.nbt.CompoundTag;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.sounds.SoundSource;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.item.Items;
|
|
import net.minecraft.world.level.ClipContext;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.phys.Vec3;
|
|
import net.minecraftforge.event.TickEvent;
|
|
import net.minecraftforge.event.entity.player.PlayerEvent;
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
import net.minecraftforge.fml.common.Mod;
|
|
|
|
@Mod.EventBusSubscriber
|
|
public class PlayerEventHandler {
|
|
|
|
@SubscribeEvent
|
|
public static void onPlayerRespawned(PlayerEvent.PlayerRespawnEvent event) {
|
|
Player player = event.getEntity();
|
|
|
|
if (player == null) {
|
|
return;
|
|
}
|
|
|
|
if (!TargetModVariables.MapVariables.get(player.level()).pvpMode) {
|
|
return;
|
|
}
|
|
|
|
for (ItemStack stack : player.getInventory().items) {
|
|
if (stack.is(TargetModTags.Items.GUN)) {
|
|
stack.getOrCreateTag().putInt("ammo", stack.getOrCreateTag().getInt("mag"));
|
|
}
|
|
}
|
|
}
|
|
|
|
@SubscribeEvent
|
|
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
|
|
Player player = event.player;
|
|
|
|
if (player == null) {
|
|
return;
|
|
}
|
|
|
|
if (event.phase == TickEvent.Phase.END) {
|
|
handleAiming(player);
|
|
handlePlayerProne(player);
|
|
handlePlayerSprint(player);
|
|
handleWeaponLevel(player);
|
|
handleWeaponSway(player);
|
|
handleAmmoCount(player);
|
|
handleFireTime(player);
|
|
handleGround(player);
|
|
handlePrepareZoom(player);
|
|
handleSpecialWeaponAmmo(player);
|
|
handleChangeFireRate(player);
|
|
handleDistantRange(player);
|
|
handleRenderDamageIndicator(player);
|
|
handleBocekPulling(player);
|
|
handleGunRecoil(player);
|
|
handleMiniGunFire(player);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 判断玩家是否瞄准
|
|
*/
|
|
private static void handleAiming(Player player) {
|
|
ItemStack itemstack = player.getMainHandItem();
|
|
|
|
if (itemstack.is(TargetModTags.Items.GUN)) {
|
|
itemstack.getOrCreateTag().putBoolean("aiming", player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables()).zooming);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 判断玩家是否趴下
|
|
*/
|
|
private static void handlePlayerProne(Player player) {
|
|
Level level = player.level();
|
|
|
|
if (player.getBbHeight() <= 1) {
|
|
player.getPersistentData().putDouble("prone", 3);
|
|
}
|
|
|
|
if (player.isShiftKeyDown() && level.getBlockState(BlockPos.containing(player.getX() + 0.7 * player.getLookAngle().x, player.getY() + 0.5, player.getZ() + 0.7 * player.getLookAngle().z)).canOcclude()
|
|
&& !level.getBlockState(BlockPos.containing(player.getX() + 0.7 * player.getLookAngle().x, player.getY() + 1.5, player.getZ() + 0.7 * player.getLookAngle().z)).canOcclude()) {
|
|
player.getPersistentData().putDouble("prone", 3);
|
|
}
|
|
|
|
if (player.getPersistentData().getDouble("prone") > 0) {
|
|
player.getPersistentData().putDouble("prone", (player.getPersistentData().getDouble("prone") - 1));
|
|
}
|
|
|
|
boolean flag = !(player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).refresh;
|
|
|
|
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
|
capability.refresh = flag;
|
|
capability.syncPlayerVariables(player);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 判断玩家是否在奔跑
|
|
*/
|
|
private static void handlePlayerSprint(Player player) {
|
|
if (player.getMainHandItem().getOrCreateTag().getInt("flash_time") > 0) {
|
|
player.getPersistentData().putDouble("noRun", 20);
|
|
}
|
|
|
|
if (player.isShiftKeyDown() || player.isPassenger() || player.isInWater() || (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).zooming) {
|
|
player.getPersistentData().putDouble("noRun", 1);
|
|
}
|
|
|
|
if (player.getPersistentData().getDouble("noRun") > 0) {
|
|
player.getPersistentData().putDouble("noRun", (player.getPersistentData().getDouble("noRun") - 1));
|
|
}
|
|
|
|
if ((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).zooming) {
|
|
player.setSprinting(false);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 处理武器等级
|
|
*/
|
|
private static void handleWeaponLevel(Player player) {
|
|
ItemStack stack = player.getMainHandItem();
|
|
if (stack.is(TargetModTags.Items.GUN)) {
|
|
var tag = stack.getOrCreateTag();
|
|
if (tag.getInt("level") == 0) {
|
|
tag.putDouble("exp2", 20);
|
|
} else {
|
|
tag.putDouble("exp2", (tag.getDouble("exp1") + tag.getInt("level") * 500));
|
|
}
|
|
if (tag.getDouble("damagetotal") >= tag.getDouble("exp2")) {
|
|
tag.putDouble("exp1", (tag.getDouble("exp2")));
|
|
tag.putInt("level", tag.getInt("level") + 1);
|
|
}
|
|
tag.putDouble("damagenow", (tag.getDouble("damagetotal") - tag.getDouble("exp1")));
|
|
tag.putDouble("damageneed", (tag.getDouble("exp2") - tag.getDouble("exp1")));
|
|
}
|
|
}
|
|
|
|
private static void handleWeaponSway(Player player) {
|
|
double[] recoilTimer = {0};
|
|
double totalTime = 10;
|
|
int sleepTime = 2;
|
|
double recoilDuration = totalTime / sleepTime;
|
|
|
|
Runnable recoilRunnable = () -> {
|
|
while (recoilTimer[0] < recoilDuration) {
|
|
if (player == null)
|
|
return;
|
|
double pose;
|
|
var data = player.getPersistentData();
|
|
if (player.isShiftKeyDown() && player.getBbHeight() >= 1 && data.getDouble("prone") == 0) {
|
|
pose = 0.85;
|
|
} else if (data.getDouble("prone") > 0) {
|
|
if (player.getMainHandItem().getOrCreateTag().getDouble("bipod") == 1) {
|
|
pose = 0;
|
|
} else {
|
|
pose = 0.25;
|
|
}
|
|
} else {
|
|
pose = 1;
|
|
}
|
|
data.putDouble("time", (data.getDouble("time") + 0.015));
|
|
data.putDouble("x", (pose * -0.008 * Math.sin(data.getDouble("time")) * (1 - 0.9 * data.getDouble("zoom_time"))));
|
|
data.putDouble("y", (pose * 0.125 * Math.sin(data.getDouble("time") - 1.585) * (1 - 0.9 * data.getDouble("zoom_time"))));
|
|
|
|
recoilTimer[0]++;
|
|
try {
|
|
Thread.sleep(sleepTime);
|
|
} catch (InterruptedException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
};
|
|
|
|
Thread recoilThread = new Thread(recoilRunnable);
|
|
recoilThread.start();
|
|
}
|
|
|
|
public static void handleAmmoCount(Player player) {
|
|
ItemStack stack = player.getMainHandItem();
|
|
|
|
if (stack.is(TargetModTags.Items.RIFLE)) {
|
|
stack.getOrCreateTag().putInt("max_ammo",
|
|
((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).rifleAmmo));
|
|
}
|
|
if (stack.is(TargetModTags.Items.HANDGUN) || stack.is(TargetModTags.Items.SMG)) {
|
|
stack.getOrCreateTag().putInt("max_ammo",
|
|
((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).handgunAmmo));
|
|
}
|
|
if (stack.is(TargetModTags.Items.SHOTGUN)) {
|
|
stack.getOrCreateTag().putInt("max_ammo",
|
|
((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).shotgunAmmo));
|
|
}
|
|
if (stack.is(TargetModTags.Items.SNIPER_RIFLE)) {
|
|
stack.getOrCreateTag().putInt("max_ammo",
|
|
((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).sniperAmmo));
|
|
}
|
|
}
|
|
|
|
private static void handleFireTime(Player player) {
|
|
double[] recoilTimer = {0};
|
|
double totalTime = 50;
|
|
int sleepTime = 2;
|
|
double recoilDuration = totalTime / sleepTime;
|
|
Runnable recoilRunnable = () -> {
|
|
while (recoilTimer[0] < recoilDuration) {
|
|
if (player == null) {
|
|
return;
|
|
}
|
|
if ((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).firing > 0) {
|
|
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
|
capability.firing = (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).firing - 0.05;
|
|
capability.syncPlayerVariables(player);
|
|
});
|
|
}
|
|
recoilTimer[0]++;
|
|
try {
|
|
Thread.sleep(sleepTime);
|
|
} catch (InterruptedException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
};
|
|
Thread recoilThread = new Thread(recoilRunnable);
|
|
recoilThread.start();
|
|
}
|
|
|
|
private static void handleGround(Player player) {
|
|
if (player.onGround()) {
|
|
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
|
capability.playerDoubleJump = false;
|
|
capability.syncPlayerVariables(player);
|
|
});
|
|
}
|
|
}
|
|
|
|
private static void handlePrepareZoom(Player player) {
|
|
ItemStack stack = player.getMainHandItem();
|
|
|
|
if (stack.is(TargetModTags.Items.GUN) && !stack.getOrCreateTag().getBoolean("reloading") && !player.isSpectator()) {
|
|
if (player.getMainHandItem().getItem() != TargetModItems.MINIGUN.get()) {
|
|
if ((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).zoom) {
|
|
player.setSprinting(false);
|
|
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
|
capability.zooming = true;
|
|
capability.syncPlayerVariables(player);
|
|
});
|
|
|
|
if (player.getPersistentData().getInt("zoom_animation_time") < 10) {
|
|
player.getPersistentData().putInt("zoom_animation_time", player.getPersistentData().getInt("zoom_animation_time") + 1);
|
|
}
|
|
} else {
|
|
player.getPersistentData().putInt("zoom_animation_time", 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void handleSpecialWeaponAmmo(Player player) {
|
|
ItemStack stack = player.getMainHandItem();
|
|
|
|
if (stack.getItem() == TargetModItems.RPG.get() && stack.getOrCreateTag().getInt("ammo") == 1) {
|
|
stack.getOrCreateTag().putDouble("empty", 0);
|
|
}
|
|
if (stack.getItem() == TargetModItems.BOCEK.get() && stack.getOrCreateTag().getInt("ammo") == 1) {
|
|
stack.getOrCreateTag().putDouble("empty", 0);
|
|
}
|
|
}
|
|
|
|
private static void handleChangeFireRate(Player player) {
|
|
ItemStack stack = player.getMainHandItem();
|
|
if (stack.is(TargetModTags.Items.GUN)) {
|
|
if (stack.getOrCreateTag().getDouble("cg") > 0) {
|
|
stack.getOrCreateTag().putDouble("cg", (stack.getOrCreateTag().getDouble("cg") - 1));
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 望远镜瞄准时显示距离
|
|
*/
|
|
private static void handleDistantRange(Player player) {
|
|
ItemStack stack = player.getUseItem();
|
|
if (stack.getItem() == Items.SPYGLASS) {
|
|
if (player.position().distanceTo((Vec3.atLowerCornerOf(player.level().clip(
|
|
new ClipContext(player.getEyePosition(), player.getEyePosition().add(player.getLookAngle().scale(1024)),
|
|
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player)).getBlockPos()))) <= 512) {
|
|
if (!player.level().isClientSide())
|
|
player.displayClientMessage(Component.literal((new java.text.DecimalFormat("##.#")
|
|
.format(player.position().distanceTo((Vec3.atLowerCornerOf(
|
|
player.level().clip(new ClipContext(player.getEyePosition(), player.getEyePosition().add(player.getLookAngle().scale(768)), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player)).getBlockPos()))))
|
|
+ "M")), true);
|
|
} else {
|
|
if (player.level().isClientSide())
|
|
player.displayClientMessage(Component.literal("---M"), true);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private static void handleRenderDamageIndicator(Player player) {
|
|
double[] recoilTimer = {0};
|
|
double totalTime = 10;
|
|
int sleepTime = 2;
|
|
double recoilDuration = totalTime / sleepTime;
|
|
Runnable recoilRunnable = () -> {
|
|
while (recoilTimer[0] < recoilDuration) {
|
|
if (player == null) return;
|
|
|
|
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
|
capability.headIndicator = Math.max(0, capability.headIndicator - 1);
|
|
capability.hitIndicator = Math.max(0, capability.hitIndicator - 1);
|
|
capability.killIndicator = Math.max(0, capability.killIndicator - 1);
|
|
|
|
capability.syncPlayerVariables(player);
|
|
});
|
|
|
|
recoilTimer[0]++;
|
|
try {
|
|
Thread.sleep(sleepTime);
|
|
} catch (InterruptedException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
};
|
|
Thread recoilThread = new Thread(recoilRunnable);
|
|
recoilThread.start();
|
|
}
|
|
|
|
private static void handleBocekPulling(Player player) {
|
|
ItemStack mainHandItem = player.getMainHandItem();
|
|
CompoundTag tag = mainHandItem.getOrCreateTag();
|
|
|
|
if ((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).bowPullHold) {
|
|
if (mainHandItem.getItem() == TargetModItems.BOCEK.get()
|
|
&& tag.getInt("max_ammo") > 0
|
|
&& !player.getCooldowns().isOnCooldown(mainHandItem.getItem())
|
|
&& tag.getDouble("power") < 12
|
|
) {
|
|
tag.putDouble("power", tag.getDouble("power") + 1);
|
|
|
|
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
|
capability.bowPull = true;
|
|
capability.syncPlayerVariables(player);
|
|
});
|
|
}
|
|
if (tag.getDouble("power") == 1) {
|
|
if (!player.level().isClientSide() && player.getServer() != null) {
|
|
// TODO 修改为正确的音效播放
|
|
player.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, player.position(), player.getRotationVector(), player.level() instanceof ServerLevel ? (ServerLevel) player.level() : null, 4,
|
|
player.getName().getString(), player.getDisplayName(), player.level().getServer(), player), "playsound target:bocek_pull_1p player @s ~ ~ ~ 2 1");
|
|
|
|
player.level().playSound(null, player.blockPosition(), TargetModSounds.BOCEK_PULL_3P.get(), SoundSource.PLAYERS, 0.5f, 1);
|
|
}
|
|
}
|
|
} else {
|
|
if (mainHandItem.getItem() == TargetModItems.BOCEK.get()) {
|
|
tag.putDouble("power", 0);
|
|
}
|
|
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
|
capability.bowPull = false;
|
|
capability.syncPlayerVariables(player);
|
|
});
|
|
}
|
|
}
|
|
|
|
private static void handleGunRecoil(Player player) {
|
|
if (!player.getMainHandItem().is(TargetModTags.Items.GUN)) return;
|
|
|
|
CompoundTag tag = player.getMainHandItem().getOrCreateTag();
|
|
float recoilX = (float) tag.getDouble("recoil_x");
|
|
float recoilY = (float) tag.getDouble("recoil_y");
|
|
|
|
var capability = player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null);
|
|
float recoilYaw = capability.map(c -> c.recoilHorizon).orElse(0d).floatValue();
|
|
|
|
double[] recoilTimer = {0};
|
|
double totalTime = 100;
|
|
int sleepTime = 2;
|
|
double recoilDuration = totalTime / sleepTime;
|
|
|
|
Runnable recoilRunnable = () -> {
|
|
while (recoilTimer[0] < recoilDuration) {
|
|
float rx, ry;
|
|
if (player.isShiftKeyDown() && player.getBbHeight() >= 1 && player.getPersistentData().getDouble("prone") == 0) {
|
|
rx = 0.7f;
|
|
ry = 0.8f;
|
|
} else if (player.getPersistentData().getDouble("prone") > 0) {
|
|
if (tag.getDouble("bipod") == 1) {
|
|
rx = 0.05f;
|
|
ry = 0.1f;
|
|
} else {
|
|
rx = 0.5f;
|
|
ry = 0.7f;
|
|
}
|
|
} else {
|
|
rx = 1f;
|
|
ry = 1f;
|
|
}
|
|
|
|
double recoil = capability.map(c -> c.recoil).orElse(0d);
|
|
|
|
if (recoil >= 1) recoil = 0d;
|
|
|
|
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));
|
|
player.setXRot(newPitch);
|
|
player.xRotO = player.getXRot();
|
|
|
|
float newYaw = ((float) (player.getYRot() - 1.0f * recoilYaw * recoilX * rx * sinRes));
|
|
player.setYRot(newYaw);
|
|
player.yRotO = player.getYRot();
|
|
}
|
|
|
|
double finalRecoil = recoil;
|
|
capability.ifPresent(c -> {
|
|
c.recoil = finalRecoil;
|
|
c.syncPlayerVariables(player);
|
|
});
|
|
|
|
recoilTimer[0]++;
|
|
try {
|
|
Thread.sleep(sleepTime);
|
|
} catch (InterruptedException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
};
|
|
Thread recoilThread = new Thread(recoilRunnable);
|
|
recoilThread.start();
|
|
}
|
|
|
|
private static void handleMiniGunFire(Player player) {
|
|
ItemStack stack = player.getMainHandItem();
|
|
|
|
if (stack.getItem() != TargetModItems.MINIGUN.get()) {
|
|
return;
|
|
}
|
|
|
|
|
|
if (player.getPersistentData().getDouble("mini_firing") == 1 && !player.isSprinting()) {
|
|
if (stack.getOrCreateTag().getDouble("rot") < 10) {
|
|
stack.getOrCreateTag().putDouble("rot", (stack.getOrCreateTag().getDouble("rot") + 1));
|
|
}
|
|
if (!player.level().isClientSide() && player.getServer() != null) {
|
|
player.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, player.position(), player.getRotationVector(), (ServerLevel) player.level(), 4,
|
|
player.getName().getString(), player.getDisplayName(), player.level().getServer(), player), "playsound target:minigun_rot player @s ~ ~ ~ 2 1");
|
|
}
|
|
} else if (stack.getOrCreateTag().getDouble("rot") > 0) {
|
|
stack.getOrCreateTag().putDouble("rot", (stack.getOrCreateTag().getDouble("rot") - 0.5));
|
|
}
|
|
|
|
if (stack.getOrCreateTag().getDouble("overheat") == 0
|
|
&& (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).rifleAmmo > 0
|
|
&& !(player.getCooldowns().isOnCooldown(stack.getItem())) && stack.getOrCreateTag().getDouble("rot") >= 10) {
|
|
stack.getOrCreateTag().putDouble("heat", (stack.getOrCreateTag().getDouble("heat") + 1));
|
|
if (stack.getOrCreateTag().getDouble("heat") >= 50.5) {
|
|
stack.getOrCreateTag().putDouble("overheat", 40);
|
|
player.getCooldowns().addCooldown(stack.getItem(), 40);
|
|
if (!player.level().isClientSide() && player.getServer() != null) {
|
|
player.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, player.position(), player.getRotationVector(), (ServerLevel) player.level(), 4,
|
|
player.getName().getString(), player.getDisplayName(), player.level().getServer(), player), "playsound target:minigun_overheat player @s ~ ~ ~ 2 1");
|
|
}
|
|
}
|
|
|
|
if (!player.level().isClientSide() && player.getServer() != null) {
|
|
if (stack.getOrCreateTag().getDouble("heat") <= 40) {
|
|
player.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, player.position(), player.getRotationVector(), (ServerLevel) player.level(), 4,
|
|
player.getName().getString(), player.getDisplayName(), player.level().getServer(), player), "playsound target:minigun_fire_1p player @s ~ ~ ~ 2 1");
|
|
player.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, player.position(), player.getRotationVector(), (ServerLevel) player.level(), 4,
|
|
player.getName().getString(), player.getDisplayName(), player.level().getServer(), player), "playsound target:minigun_fire_3p player @a ~ ~ ~ 4 1");
|
|
player.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, player.position(), player.getRotationVector(), (ServerLevel) player.level(), 4,
|
|
player.getName().getString(), player.getDisplayName(), player.level().getServer(), player), "playsound target:minigun_far player @a ~ ~ ~ 12 1");
|
|
player.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, player.position(), player.getRotationVector(), (ServerLevel) player.level(), 4,
|
|
player.getName().getString(), player.getDisplayName(), player.level().getServer(), player), "playsound target:minigun_veryfar player @a ~ ~ ~ 24 1");
|
|
} else {
|
|
player.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, player.position(), player.getRotationVector(), (ServerLevel) player.level(), 4,
|
|
player.getName().getString(), player.getDisplayName(), player.level().getServer(), player), ("playsound target:minigun_fire_1p player @s ~ ~ ~ 2 " + (1 - 0.025 * Math.abs(40 - stack.getOrCreateTag().getDouble("heat")))));
|
|
player.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, player.position(), player.getRotationVector(), (ServerLevel) player.level(), 4,
|
|
player.getName().getString(), player.getDisplayName(), player.level().getServer(), player), ("playsound target:minigun_fire_3p player @a ~ ~ ~ 4 " + (1 - 0.025 * Math.abs(40 - stack.getOrCreateTag().getDouble("heat")))));
|
|
player.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, player.position(), player.getRotationVector(), (ServerLevel) player.level(), 4,
|
|
player.getName().getString(), player.getDisplayName(), player.level().getServer(), player), ("playsound target:minigun_far player @a ~ ~ ~ 12 " + (1 - 0.025 * Math.abs(40 - stack.getOrCreateTag().getDouble("heat")))));
|
|
player.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, player.position(), player.getRotationVector(), (ServerLevel) player.level(), 4,
|
|
player.getName().getString(), player.getDisplayName(), player.level().getServer(), player), ("playsound target:minigun_veryfar player @a ~ ~ ~ 24 " + (1 - 0.025 * Math.abs(40 - stack.getOrCreateTag().getDouble("heat")))));
|
|
}
|
|
}
|
|
|
|
GunsTool.spawnBullet(player);
|
|
|
|
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
|
capability.rifleAmmo = player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables()).rifleAmmo - 1;
|
|
capability.syncPlayerVariables(player);
|
|
});
|
|
|
|
stack.getOrCreateTag().putInt("fire_animation", 2);
|
|
}
|
|
}
|
|
}
|