内联开火procedure
This commit is contained in:
parent
e1d43284de
commit
b493526cf5
4 changed files with 181 additions and 246 deletions
|
@ -1,19 +1,16 @@
|
||||||
package net.mcreator.target.network.message;
|
package net.mcreator.target.network.message;
|
||||||
|
|
||||||
import net.mcreator.target.entity.BocekArrowEntity;
|
import net.mcreator.target.entity.*;
|
||||||
import net.mcreator.target.entity.ProjectileEntity;
|
|
||||||
import net.mcreator.target.event.GunEventHandler;
|
import net.mcreator.target.event.GunEventHandler;
|
||||||
import net.mcreator.target.init.TargetModEnchantments;
|
import net.mcreator.target.init.*;
|
||||||
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.network.TargetModVariables;
|
||||||
import net.mcreator.target.procedures.M79fireProcedure;
|
import net.mcreator.target.tools.ItemNBTTool;
|
||||||
import net.mcreator.target.procedures.RpgFireProcedure;
|
|
||||||
import net.mcreator.target.procedures.TaserfireProcedure;
|
|
||||||
import net.mcreator.target.tools.SoundTool;
|
import net.mcreator.target.tools.SoundTool;
|
||||||
|
import net.minecraft.commands.CommandSource;
|
||||||
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.sounds.SoundSource;
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
@ -59,7 +56,7 @@ public class FireMessage {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == 0) {
|
if (type == 0) {
|
||||||
handleSpecialShoot(player);
|
handlePlayerShoot(player);
|
||||||
} else if (type == 1) {
|
} else if (type == 1) {
|
||||||
player.getPersistentData().putBoolean("firing", false);
|
player.getPersistentData().putBoolean("firing", false);
|
||||||
player.getPersistentData().putDouble("minigun_firing", 0);
|
player.getPersistentData().putDouble("minigun_firing", 0);
|
||||||
|
@ -68,33 +65,45 @@ public class FireMessage {
|
||||||
capability.syncPlayerVariables(player);
|
capability.syncPlayerVariables(player);
|
||||||
});
|
});
|
||||||
|
|
||||||
handleBowShoot(player);
|
if (player.getMainHandItem().getItem() == TargetModItems.BOCEK.get()) {
|
||||||
|
handleBowShoot(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void handleSpecialShoot(Player player) {
|
private static void handlePlayerShoot(Player player) {
|
||||||
var mainHandItem = player.getMainHandItem();
|
var handItem = player.getMainHandItem();
|
||||||
var tag = mainHandItem.getOrCreateTag();
|
|
||||||
|
|
||||||
TaserfireProcedure.execute(player);
|
if (!handItem.is(TargetModTags.Items.GUN)) {
|
||||||
M79fireProcedure.execute(player);
|
return;
|
||||||
RpgFireProcedure.execute(player);
|
|
||||||
|
|
||||||
if (mainHandItem.is(TargetModTags.Items.GUN)) {
|
|
||||||
if (tag.getInt("fire_mode") == 1) {
|
|
||||||
player.getPersistentData().putBoolean("firing", false);
|
|
||||||
tag.putInt("burst_fire", (int) tag.getDouble("burst_size"));
|
|
||||||
} else {
|
|
||||||
player.getPersistentData().putBoolean("firing", true);
|
|
||||||
}
|
|
||||||
if (tag.getDouble("force_stop_reloading") == 1 && tag.getBoolean("reloading") && tag.getDouble("prepare") == 0 && tag.getInt("ammo") > 0) {
|
|
||||||
tag.putDouble("force_stop", 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mainHandItem.is(TargetModTags.Items.GUN)
|
var tag = handItem.getOrCreateTag();
|
||||||
&& !(mainHandItem.getItem() == TargetModItems.BOCEK.get())
|
|
||||||
&& !(mainHandItem.getItem() == TargetModItems.MINIGUN.get())
|
if (handItem.getItem() == TargetModItems.TASER.get()) {
|
||||||
|
handleTaserFire(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handItem.getItem() == TargetModItems.M_79.get()) {
|
||||||
|
handleM79Fire(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handItem.getItem() == TargetModItems.RPG.get()) {
|
||||||
|
handleRpgFire(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag.getInt("fire_mode") == 1) {
|
||||||
|
player.getPersistentData().putBoolean("firing", false);
|
||||||
|
tag.putInt("burst_fire", (int) tag.getDouble("burst_size"));
|
||||||
|
} else {
|
||||||
|
player.getPersistentData().putBoolean("firing", true);
|
||||||
|
}
|
||||||
|
if (tag.getDouble("force_stop_reloading") == 1 && tag.getBoolean("reloading") && tag.getDouble("prepare") == 0 && tag.getInt("ammo") > 0) {
|
||||||
|
tag.putDouble("force_stop", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (handItem.getItem() != TargetModItems.BOCEK.get()
|
||||||
|
&& handItem.getItem() != TargetModItems.MINIGUN.get()
|
||||||
&& tag.getInt("ammo") == 0
|
&& tag.getInt("ammo") == 0
|
||||||
&& !tag.getBoolean("reloading")) {
|
&& !tag.getBoolean("reloading")) {
|
||||||
if (!player.level().isClientSide()) {
|
if (!player.level().isClientSide()) {
|
||||||
|
@ -102,7 +111,7 @@ public class FireMessage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mainHandItem.getItem() == TargetModItems.MINIGUN.get()) {
|
if (handItem.getItem() == TargetModItems.MINIGUN.get()) {
|
||||||
if ((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).rifleAmmo == 0) {
|
if ((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).rifleAmmo == 0) {
|
||||||
if (!player.level().isClientSide()) {
|
if (!player.level().isClientSide()) {
|
||||||
SoundTool.playLocalSound(player, TargetModSounds.TRIGGER_CLICK.get(), 10, 1);
|
SoundTool.playLocalSound(player, TargetModSounds.TRIGGER_CLICK.get(), 10, 1);
|
||||||
|
@ -116,9 +125,9 @@ public class FireMessage {
|
||||||
});
|
});
|
||||||
|
|
||||||
// 栓动武器左键手动拉栓
|
// 栓动武器左键手动拉栓
|
||||||
if (mainHandItem.is(TargetModTags.Items.GUN) && tag.getInt("bolt_action_time") > 0 && tag.getInt("ammo") > 0 && tag.getInt("bolt_action_anim") == 0) {
|
if (tag.getInt("bolt_action_time") > 0 && tag.getInt("ammo") > 0 && tag.getInt("bolt_action_anim") == 0) {
|
||||||
if (!player.getCooldowns().isOnCooldown(mainHandItem.getItem()) && mainHandItem.getOrCreateTag().getDouble("need_bolt_action") == 1) {
|
if (!player.getCooldowns().isOnCooldown(handItem.getItem()) && handItem.getOrCreateTag().getDouble("need_bolt_action") == 1) {
|
||||||
mainHandItem.getOrCreateTag().putInt("bolt_action_anim", mainHandItem.getOrCreateTag().getInt("bolt_action_time"));
|
handItem.getOrCreateTag().putInt("bolt_action_anim", handItem.getOrCreateTag().getInt("bolt_action_time"));
|
||||||
GunEventHandler.playGunBoltSounds(player);
|
GunEventHandler.playGunBoltSounds(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,10 +136,6 @@ public class FireMessage {
|
||||||
private static void handleBowShoot(Player player) {
|
private static void handleBowShoot(Player player) {
|
||||||
ItemStack stack = player.getMainHandItem();
|
ItemStack stack = player.getMainHandItem();
|
||||||
|
|
||||||
if (stack.getItem() != TargetModItems.BOCEK.get()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
double power = stack.getOrCreateTag().getDouble("power");
|
double power = stack.getOrCreateTag().getDouble("power");
|
||||||
|
|
||||||
if (player instanceof ServerPlayer serverPlayer) {
|
if (player instanceof ServerPlayer serverPlayer) {
|
||||||
|
@ -224,4 +229,141 @@ public class FireMessage {
|
||||||
player.level().addFreshEntity(projectile);
|
player.level().addFreshEntity(projectile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void handleTaserFire(Player player) {
|
||||||
|
if (player.isSpectator()) return;
|
||||||
|
|
||||||
|
ItemStack stack = player.getMainHandItem();
|
||||||
|
if (!stack.getOrCreateTag().getBoolean("reloading")) {
|
||||||
|
if (!player.getCooldowns().isOnCooldown(stack.getItem()) && stack.getOrCreateTag().getInt("ammo") > 0
|
||||||
|
&& ItemNBTTool.getInt(stack, "Power", 1200) > 400) {
|
||||||
|
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||||
|
capability.recoilHorizon = Math.random() < 0.5 ? -1 : 1;
|
||||||
|
capability.recoil = 0.1;
|
||||||
|
capability.firing = 1;
|
||||||
|
capability.syncPlayerVariables(player);
|
||||||
|
});
|
||||||
|
player.getCooldowns().addCooldown(stack.getItem(), 5);
|
||||||
|
|
||||||
|
if (player instanceof ServerPlayer serverPlayer) {
|
||||||
|
SoundTool.playLocalSound(serverPlayer, TargetModSounds.TASER_FIRE_1P.get(), 1, 1);
|
||||||
|
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), TargetModSounds.TASER_FIRE_3P.get(), SoundSource.PLAYERS, 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int volt = EnchantmentHelper.getTagEnchantmentLevel(TargetModEnchantments.VOLT_OVERLOAD.get(), stack);
|
||||||
|
int wire_length = EnchantmentHelper.getTagEnchantmentLevel(TargetModEnchantments.LONGER_WIRE.get(), stack);
|
||||||
|
|
||||||
|
Level level = player.level();
|
||||||
|
if (!level.isClientSide()) {
|
||||||
|
TaserBulletProjectileEntity taserBulletProjectile = new TaserBulletProjectileEntity(player, level, (float) stack.getOrCreateTag().getDouble("damage"), volt, wire_length);
|
||||||
|
|
||||||
|
taserBulletProjectile.setPos(player.getX(), player.getEyeY() - 0.1, player.getZ());
|
||||||
|
taserBulletProjectile.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, (float) stack.getOrCreateTag().getDouble("velocity"),
|
||||||
|
(float) player.getAttributeBaseValue(TargetModAttributes.SPREAD.get()));
|
||||||
|
level.addFreshEntity(taserBulletProjectile);
|
||||||
|
}
|
||||||
|
|
||||||
|
stack.getOrCreateTag().putInt("fire_animation", 4);
|
||||||
|
stack.getOrCreateTag().putInt("ammo", (stack.getOrCreateTag().getInt("ammo") - 1));
|
||||||
|
ItemNBTTool.setInt(stack, "Power", ItemNBTTool.getInt(stack, "Power", 1200) - 400);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void handleM79Fire(Player player) {
|
||||||
|
if (player.isSpectator()) return;
|
||||||
|
|
||||||
|
ItemStack stack = player.getMainHandItem();
|
||||||
|
if (!stack.getOrCreateTag().getBoolean("reloading")) {
|
||||||
|
if (!player.getCooldowns().isOnCooldown(stack.getItem()) && stack.getOrCreateTag().getInt("ammo") > 0) {
|
||||||
|
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||||
|
capability.recoilHorizon = Math.random() < 0.5 ? -1 : 1;
|
||||||
|
capability.recoil = 0.1;
|
||||||
|
capability.firing = 1;
|
||||||
|
capability.syncPlayerVariables(player);
|
||||||
|
});
|
||||||
|
|
||||||
|
Level level = player.level();
|
||||||
|
if (!level.isClientSide()) {
|
||||||
|
int monsterMultiple = EnchantmentHelper.getTagEnchantmentLevel(TargetModEnchantments.MONSTER_HUNTER.get(), stack);
|
||||||
|
GunGrenadeEntity gunGrenadeEntity = new GunGrenadeEntity(player, level, (float) stack.getOrCreateTag().getDouble("damage") * (float) stack.getOrCreateTag().getDouble("damageadd"), monsterMultiple);
|
||||||
|
|
||||||
|
gunGrenadeEntity.setPos(player.getX(), player.getEyeY() - 0.1, player.getZ());
|
||||||
|
gunGrenadeEntity.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, (float) stack.getOrCreateTag().getDouble("velocity"),
|
||||||
|
(float) player.getAttributeBaseValue(TargetModAttributes.SPREAD.get()));
|
||||||
|
level.addFreshEntity(gunGrenadeEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO 移除指令
|
||||||
|
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.getServer(), player),
|
||||||
|
("particle minecraft:cloud" + (" " + (player.getX() + 1.8 * player.getLookAngle().x)) + (" " + (player.getY() + player.getBbHeight() - 0.1 + 1.8 * player.getLookAngle().y))
|
||||||
|
+ (" " + (player.getZ() + 1.8 * player.getLookAngle().z)) + " 0.1 0.1 0.1 0.002 4 force @s"));
|
||||||
|
}
|
||||||
|
player.getCooldowns().addCooldown(stack.getItem(), 2);
|
||||||
|
|
||||||
|
if (player instanceof ServerPlayer serverPlayer) {
|
||||||
|
SoundTool.playLocalSound(serverPlayer, TargetModSounds.M_79_FIRE_1P.get(), 2, 1);
|
||||||
|
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), TargetModSounds.M_79_FIRE_3P.get(), SoundSource.PLAYERS, 4, 1);
|
||||||
|
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), TargetModSounds.M_79_FAR.get(), SoundSource.PLAYERS, 6, 1);
|
||||||
|
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), TargetModSounds.M_79_VERYFAR.get(), SoundSource.PLAYERS, 12, 1);
|
||||||
|
}
|
||||||
|
stack.getOrCreateTag().putInt("fire_animation", 2);
|
||||||
|
stack.getOrCreateTag().putInt("ammo", (stack.getOrCreateTag().getInt("ammo") - 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void handleRpgFire(Player player) {
|
||||||
|
if (player.isSpectator()) return;
|
||||||
|
|
||||||
|
Level level = player.level();
|
||||||
|
ItemStack mainHandItem = player.getMainHandItem();
|
||||||
|
CompoundTag tag = mainHandItem.getOrCreateTag();
|
||||||
|
|
||||||
|
if (!tag.getBoolean("reloading") && !player.getCooldowns().isOnCooldown(mainHandItem.getItem()) && tag.getInt("ammo") > 0) {
|
||||||
|
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
||||||
|
capability.recoilHorizon = Math.random() < 0.5 ? -1 : 1;
|
||||||
|
capability.recoil = 0.1;
|
||||||
|
capability.firing = 1;
|
||||||
|
capability.syncPlayerVariables(player);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!level.isClientSide()) {
|
||||||
|
int monsterMultiple = EnchantmentHelper.getTagEnchantmentLevel(TargetModEnchantments.MONSTER_HUNTER.get(), mainHandItem);
|
||||||
|
RpgRocketEntity rocketEntity = new RpgRocketEntity(player, level, (float) tag.getDouble("damage") * (float) tag.getDouble("damageadd"), monsterMultiple);
|
||||||
|
rocketEntity.setPos(player.getX(), player.getEyeY() - 0.1, player.getZ());
|
||||||
|
rocketEntity.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, (float) tag.getDouble("velocity"),
|
||||||
|
(float) player.getAttributeBaseValue(TargetModAttributes.SPREAD.get()));
|
||||||
|
level.addFreshEntity(rocketEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO 移除指令
|
||||||
|
if (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),
|
||||||
|
("particle minecraft:cloud" + (" " + (player.getX() + 1.8 * player.getLookAngle().x)) + (" " + (player.getY() + player.getBbHeight() - 0.1 + 1.8 * player.getLookAngle().y))
|
||||||
|
+ (" " + (player.getZ() + 1.8 * player.getLookAngle().z)) + " 0.4 0.4 0.4 0.005 30 force @s"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag.getInt("ammo") == 1) {
|
||||||
|
tag.putBoolean("empty", true);
|
||||||
|
tag.putBoolean("close_hammer", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
player.getCooldowns().addCooldown(mainHandItem.getItem(), 10);
|
||||||
|
|
||||||
|
if (player instanceof ServerPlayer serverPlayer) {
|
||||||
|
SoundTool.playLocalSound(serverPlayer, TargetModSounds.RPG_FIRE_1P.get(), 2, 1);
|
||||||
|
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), TargetModSounds.RPG_FIRE_3P.get(), SoundSource.PLAYERS, 4, 1);
|
||||||
|
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), TargetModSounds.RPG_FAR.get(), SoundSource.PLAYERS, 8, 1);
|
||||||
|
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), TargetModSounds.RPG_VERYFAR.get(), SoundSource.PLAYERS, 16, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
tag.putInt("fire_animation", 2);
|
||||||
|
tag.putInt("ammo", tag.getInt("ammo") - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,69 +0,0 @@
|
||||||
package net.mcreator.target.procedures;
|
|
||||||
|
|
||||||
import net.mcreator.target.entity.GunGrenadeEntity;
|
|
||||||
import net.mcreator.target.init.TargetModAttributes;
|
|
||||||
import net.mcreator.target.init.TargetModEnchantments;
|
|
||||||
import net.mcreator.target.init.TargetModItems;
|
|
||||||
import net.mcreator.target.init.TargetModSounds;
|
|
||||||
import net.mcreator.target.network.TargetModVariables;
|
|
||||||
import net.mcreator.target.tools.SoundTool;
|
|
||||||
import net.minecraft.commands.CommandSource;
|
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
|
||||||
import net.minecraft.server.level.ServerLevel;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
|
|
||||||
// TODO 内联这个类
|
|
||||||
public class M79fireProcedure {
|
|
||||||
public static void execute(Entity entity) {
|
|
||||||
if (entity == null) return;
|
|
||||||
if (entity instanceof Player player && !player.isSpectator()) {
|
|
||||||
ItemStack stack = player.getMainHandItem();
|
|
||||||
if (stack.getItem() == TargetModItems.M_79.get() && !stack.getOrCreateTag().getBoolean("reloading")) {
|
|
||||||
Player _plrCldCheck4 = (Player) entity;
|
|
||||||
if (!_plrCldCheck4.getCooldowns().isOnCooldown(stack.getItem()) && stack.getOrCreateTag().getInt("ammo") > 0) {
|
|
||||||
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
|
||||||
capability.recoilHorizon = Math.random() < 0.5 ? -1 : 1;
|
|
||||||
capability.recoil = 0.1;
|
|
||||||
capability.firing = 1;
|
|
||||||
capability.syncPlayerVariables(entity);
|
|
||||||
});
|
|
||||||
|
|
||||||
Level level = entity.level();
|
|
||||||
if (!level.isClientSide()) {
|
|
||||||
int monsterMultiple = EnchantmentHelper.getTagEnchantmentLevel(TargetModEnchantments.MONSTER_HUNTER.get(), stack);
|
|
||||||
GunGrenadeEntity gunGrenadeEntity = new GunGrenadeEntity(player, level, (float) stack.getOrCreateTag().getDouble("damage") * (float) stack.getOrCreateTag().getDouble("damageadd"), monsterMultiple);
|
|
||||||
|
|
||||||
gunGrenadeEntity.setPos(entity.getX(), entity.getEyeY() - 0.1, entity.getZ());
|
|
||||||
gunGrenadeEntity.shoot(entity.getLookAngle().x, entity.getLookAngle().y, entity.getLookAngle().z, (float) stack.getOrCreateTag().getDouble("velocity"),
|
|
||||||
(float) ((LivingEntity) entity).getAttribute(TargetModAttributes.SPREAD.get()).getBaseValue());
|
|
||||||
level.addFreshEntity(gunGrenadeEntity);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!entity.level().isClientSide() && entity.getServer() != null) {
|
|
||||||
entity.getServer().getCommands().performPrefixedCommand(
|
|
||||||
new CommandSourceStack(CommandSource.NULL, entity.position(), entity.getRotationVector(), (ServerLevel) entity.level(), 4, entity.getName().getString(), entity.getDisplayName(),
|
|
||||||
entity.getServer(), entity),
|
|
||||||
("particle minecraft:cloud" + (" " + (entity.getX() + 1.8 * entity.getLookAngle().x)) + (" " + (entity.getY() + entity.getBbHeight() - 0.1 + 1.8 * entity.getLookAngle().y))
|
|
||||||
+ (" " + (entity.getZ() + 1.8 * entity.getLookAngle().z)) + " 0.1 0.1 0.1 0.002 4 force @s"));
|
|
||||||
}
|
|
||||||
player.getCooldowns().addCooldown(stack.getItem(), 2);
|
|
||||||
|
|
||||||
if (entity instanceof ServerPlayer) {
|
|
||||||
SoundTool.playLocalSound(player, TargetModSounds.M_79_FIRE_1P.get(), 2, 1);
|
|
||||||
SoundTool.playLocalSound(player, TargetModSounds.M_79_FIRE_3P.get(), 4, 1);
|
|
||||||
SoundTool.playLocalSound(player, TargetModSounds.M_79_FAR.get(), 6, 1);
|
|
||||||
SoundTool.playLocalSound(player, TargetModSounds.M_79_VERYFAR.get(), 12, 1);
|
|
||||||
}
|
|
||||||
stack.getOrCreateTag().putInt("fire_animation", 2);
|
|
||||||
stack.getOrCreateTag().putInt("ammo", (stack.getOrCreateTag().getInt("ammo") - 1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,75 +0,0 @@
|
||||||
package net.mcreator.target.procedures;
|
|
||||||
|
|
||||||
import net.mcreator.target.entity.RpgRocketEntity;
|
|
||||||
import net.mcreator.target.init.TargetModAttributes;
|
|
||||||
import net.mcreator.target.init.TargetModEnchantments;
|
|
||||||
import net.mcreator.target.init.TargetModItems;
|
|
||||||
import net.mcreator.target.init.TargetModSounds;
|
|
||||||
import net.mcreator.target.network.TargetModVariables;
|
|
||||||
import net.minecraft.commands.CommandSource;
|
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
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.enchantment.EnchantmentHelper;
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
|
|
||||||
// TODO 内联这个类
|
|
||||||
public class RpgFireProcedure {
|
|
||||||
public static void execute(Player player) {
|
|
||||||
if (player.isSpectator()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Level level = player.level();
|
|
||||||
ItemStack mainHandItem = player.getMainHandItem();
|
|
||||||
CompoundTag tag = mainHandItem.getOrCreateTag();
|
|
||||||
|
|
||||||
if (mainHandItem.getItem() == TargetModItems.RPG.get() && !tag.getBoolean("reloading") && !player.getCooldowns().isOnCooldown(mainHandItem.getItem())
|
|
||||||
&& tag.getInt("ammo") > 0) {
|
|
||||||
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
|
||||||
capability.recoilHorizon = Math.random() < 0.5 ? -1 : 1;
|
|
||||||
capability.recoil = 0.1;
|
|
||||||
capability.firing = 1;
|
|
||||||
capability.syncPlayerVariables(player);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
if (!level.isClientSide()) {
|
|
||||||
int monsterMultiple = EnchantmentHelper.getTagEnchantmentLevel(TargetModEnchantments.MONSTER_HUNTER.get(), mainHandItem);
|
|
||||||
RpgRocketEntity rocketEntity = new RpgRocketEntity(player, level, (float) tag.getDouble("damage") * (float) tag.getDouble("damageadd"), monsterMultiple);
|
|
||||||
rocketEntity.setPos(player.getX(), player.getEyeY() - 0.1, player.getZ());
|
|
||||||
rocketEntity.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, (float) tag.getDouble("velocity"),
|
|
||||||
(float) player.getAttribute(TargetModAttributes.SPREAD.get()).getBaseValue());
|
|
||||||
level.addFreshEntity(rocketEntity);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (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),
|
|
||||||
("particle minecraft:cloud" + (" " + (player.getX() + 1.8 * player.getLookAngle().x)) + (" " + (player.getY() + player.getBbHeight() - 0.1 + 1.8 * player.getLookAngle().y))
|
|
||||||
+ (" " + (player.getZ() + 1.8 * player.getLookAngle().z)) + " 0.4 0.4 0.4 0.005 30 force @s"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tag.getInt("ammo") == 1) {
|
|
||||||
tag.putBoolean("empty", true);
|
|
||||||
tag.putBoolean("close_hammer", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
player.getCooldowns().addCooldown(mainHandItem.getItem(), 10);
|
|
||||||
|
|
||||||
if (!player.level().isClientSide() && player.getServer() != null) {
|
|
||||||
player.level().playSound(null, player.blockPosition(), TargetModSounds.RPG_FIRE_1P.get(), SoundSource.PLAYERS, 2, 1);
|
|
||||||
player.level().playSound(null, player.blockPosition(), TargetModSounds.RPG_FIRE_3P.get(), SoundSource.PLAYERS, 4, 1);
|
|
||||||
player.level().playSound(null, player.blockPosition(), TargetModSounds.RPG_FAR.get(), SoundSource.PLAYERS, 8, 1);
|
|
||||||
player.level().playSound(null, player.blockPosition(), TargetModSounds.RPG_VERYFAR.get(), SoundSource.PLAYERS, 16, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
tag.putInt("fire_animation", 2);
|
|
||||||
tag.putInt("ammo", tag.getInt("ammo") - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,63 +0,0 @@
|
||||||
package net.mcreator.target.procedures;
|
|
||||||
|
|
||||||
import net.mcreator.target.entity.TaserBulletProjectileEntity;
|
|
||||||
import net.mcreator.target.init.TargetModAttributes;
|
|
||||||
import net.mcreator.target.init.TargetModEnchantments;
|
|
||||||
import net.mcreator.target.init.TargetModItems;
|
|
||||||
import net.mcreator.target.init.TargetModSounds;
|
|
||||||
import net.mcreator.target.network.TargetModVariables;
|
|
||||||
import net.mcreator.target.tools.ItemNBTTool;
|
|
||||||
import net.mcreator.target.tools.SoundTool;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
import net.minecraft.sounds.SoundSource;
|
|
||||||
import net.minecraft.world.entity.Entity;
|
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
|
||||||
import net.minecraft.world.entity.player.Player;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
|
||||||
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
|
||||||
import net.minecraft.world.level.Level;
|
|
||||||
|
|
||||||
// TODO 内联这个类
|
|
||||||
public class TaserfireProcedure {
|
|
||||||
public static final String TAG_POWER = "Power";
|
|
||||||
public static void execute(Entity entity) {
|
|
||||||
if (entity == null) return;
|
|
||||||
if (entity instanceof Player player && !player.isSpectator()) {
|
|
||||||
ItemStack stack = player.getMainHandItem();
|
|
||||||
if (stack.getItem() == TargetModItems.TASER.get() && !stack.getOrCreateTag().getBoolean("reloading")) {
|
|
||||||
Player _plrCldCheck4 = (Player) entity;
|
|
||||||
if (!_plrCldCheck4.getCooldowns().isOnCooldown(stack.getItem()) && stack.getOrCreateTag().getInt("ammo") > 0 && ItemNBTTool.getInt(stack, TAG_POWER, 1200) > 400) {
|
|
||||||
|
|
||||||
entity.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
|
|
||||||
capability.recoilHorizon = Math.random() < 0.5 ? -1 : 1;
|
|
||||||
capability.recoil = 0.1;
|
|
||||||
capability.firing = 1;
|
|
||||||
capability.syncPlayerVariables(entity);
|
|
||||||
});
|
|
||||||
player.getCooldowns().addCooldown(stack.getItem(), 5);
|
|
||||||
|
|
||||||
if (entity instanceof ServerPlayer serverPlayer) {
|
|
||||||
SoundTool.playLocalSound(serverPlayer, TargetModSounds.TASER_FIRE_1P.get(), 1, 1);
|
|
||||||
serverPlayer.level().playSound(null, serverPlayer.getOnPos(), TargetModSounds.TASER_FIRE_3P.get(), SoundSource.PLAYERS, 1, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int volt = EnchantmentHelper.getTagEnchantmentLevel(TargetModEnchantments.VOLT_OVERLOAD.get(), stack);
|
|
||||||
int wire_length = EnchantmentHelper.getTagEnchantmentLevel(TargetModEnchantments.LONGER_WIRE.get(), stack);
|
|
||||||
|
|
||||||
Level level = entity.level();
|
|
||||||
if (!level.isClientSide()) {
|
|
||||||
TaserBulletProjectileEntity taserBulletProjectile = new TaserBulletProjectileEntity(player, level, (float) stack.getOrCreateTag().getDouble("damage"), volt, wire_length);
|
|
||||||
|
|
||||||
taserBulletProjectile.setPos(entity.getX(), entity.getEyeY() - 0.1, entity.getZ());
|
|
||||||
taserBulletProjectile.shoot(entity.getLookAngle().x, entity.getLookAngle().y, entity.getLookAngle().z, (float) stack.getOrCreateTag().getDouble("velocity"),
|
|
||||||
(float) ((LivingEntity) entity).getAttribute(TargetModAttributes.SPREAD.get()).getBaseValue());
|
|
||||||
level.addFreshEntity(taserBulletProjectile);
|
|
||||||
}
|
|
||||||
stack.getOrCreateTag().putInt("fire_animation", 4);
|
|
||||||
stack.getOrCreateTag().putInt("ammo", (stack.getOrCreateTag().getInt("ammo") - 1));
|
|
||||||
ItemNBTTool.setInt(stack, TAG_POWER, ItemNBTTool.getInt(stack, TAG_POWER, 1200) - 400);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue