移除minigun procedure

This commit is contained in:
17146 2024-05-19 20:23:47 +08:00
parent 493c3df415
commit 45b43a296b
4 changed files with 82 additions and 110 deletions

View file

@ -4,6 +4,7 @@ import net.mcreator.target.init.TargetModItems;
import net.mcreator.target.init.TargetModSounds; import net.mcreator.target.init.TargetModSounds;
import net.mcreator.target.init.TargetModTags; import net.mcreator.target.init.TargetModTags;
import net.mcreator.target.network.TargetModVariables; import net.mcreator.target.network.TargetModVariables;
import net.mcreator.target.tools.GunsTool;
import net.minecraft.commands.CommandSource; import net.minecraft.commands.CommandSource;
import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.CommandSourceStack;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -67,6 +68,7 @@ public class PlayerEventHandler {
handleRenderDamageIndicator(player); handleRenderDamageIndicator(player);
handleBocekPulling(player); handleBocekPulling(player);
handleGunRecoil(player); handleGunRecoil(player);
handleMiniGunFire(player);
} }
} }
@ -436,4 +438,70 @@ public class PlayerEventHandler {
Thread recoilThread = new Thread(recoilRunnable); Thread recoilThread = new Thread(recoilRunnable);
recoilThread.start(); 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);
}
}
} }

View file

@ -1,83 +0,0 @@
package net.mcreator.target.procedures;
import net.mcreator.target.init.TargetModItems;
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.server.level.ServerLevel;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@Mod.EventBusSubscriber
public class MinigunautofireProcedure {
@SubscribeEvent
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
if (event.phase == TickEvent.Phase.END) {
execute(event.player);
}
}
private static void execute(Player player) {
ItemStack usehand;
usehand = player.getMainHandItem();
if (usehand.getItem() == TargetModItems.MINIGUN.get()) {
if (player.getPersistentData().getDouble("mini_firing") == 1 && !player.isSprinting()) {
if (usehand.getOrCreateTag().getDouble("rot") < 10) {
usehand.getOrCreateTag().putDouble("rot", (usehand.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 (usehand.getOrCreateTag().getDouble("rot") > 0) {
usehand.getOrCreateTag().putDouble("rot", (usehand.getOrCreateTag().getDouble("rot") - 0.5));
}
}
if (usehand.getItem() == TargetModItems.MINIGUN.get() && usehand.getOrCreateTag().getDouble("overheat") == 0
&& (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).rifleAmmo > 0
&& !(player.getCooldowns().isOnCooldown(usehand.getItem())) && usehand.getOrCreateTag().getDouble("rot") >= 10) {
usehand.getOrCreateTag().putDouble("heat", (usehand.getOrCreateTag().getDouble("heat") + 1));
if (usehand.getOrCreateTag().getDouble("heat") >= 50.5) {
usehand.getOrCreateTag().putDouble("overheat", 40);
player.getCooldowns().addCooldown(usehand.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 (usehand.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 - usehand.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 - usehand.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 - usehand.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 - usehand.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);
});
usehand.getOrCreateTag().putInt("fire_animation", 2);
}
}
}

View file

@ -1,18 +0,0 @@
package net.mcreator.target.procedures;
import net.mcreator.target.init.TargetModItems;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
public class MinigunfireProcedure {
public static void execute(Entity entity) {
if (entity == null) return;
if (entity instanceof Player player && !player.isSpectator()) {
ItemStack usehand = player.getMainHandItem();
if (usehand.getItem() == TargetModItems.MINIGUN.get()) {
entity.getPersistentData().putDouble("mini_firing", 1);
}
}
}
}

View file

@ -14,7 +14,7 @@ public class PressFireProcedure {
TaserfireProcedure.execute(player); TaserfireProcedure.execute(player);
M79fireProcedure.execute(player); M79fireProcedure.execute(player);
RpgFireProcedure.execute(player); RpgFireProcedure.execute(player);
MinigunfireProcedure.execute(player);
MarlinfireProcedure.execute(player); MarlinfireProcedure.execute(player);
M870fireProcedure.execute(player); M870fireProcedure.execute(player);
VectorFireProcedure.execute(player); VectorFireProcedure.execute(player);
@ -33,23 +33,28 @@ public class PressFireProcedure {
player.getName().getString(), player.getDisplayName(), player.level().getServer(), player), "playsound target:triggerclick player @s ~ ~ ~ 10 1"); player.getName().getString(), player.getDisplayName(), player.level().getServer(), player), "playsound target:triggerclick player @s ~ ~ ~ 10 1");
} }
} }
if (mainHandItem.getItem() == TargetModItems.MINIGUN.get()
&& (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).rifleAmmo == 0) { if (mainHandItem.getItem() == TargetModItems.MINIGUN.get()) {
player.getPersistentData().putDouble("mini_firing", 1);
if ((player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).rifleAmmo == 0) {
if (!player.level().isClientSide() && player.getServer() != null) { if (!player.level().isClientSide() && player.getServer() != null) {
player.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, player.position(), player.getRotationVector(), (ServerLevel) player.level(), 4, 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:triggerclick player @s ~ ~ ~ 10 1"); player.getName().getString(), player.getDisplayName(), player.level().getServer(), player), "playsound target:triggerclick player @s ~ ~ ~ 10 1");
} }
} }
}
player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> {
capability.bowPullHold = true; capability.bowPullHold = true;
capability.syncPlayerVariables(player); capability.syncPlayerVariables(player);
}); });
if (tag.getInt("ammo") == 0) { if (tag.getInt("ammo") == 0) {
PlayerReloadProcedure.execute(player); PlayerReloadProcedure.execute(player);
} }
/**
* 栓动武器左键手动拉栓 // 栓动武器左键手动拉栓
*/
if (mainHandItem.is(TargetModTags.Items.GUN) && tag.getDouble("bolt_action_time") > 0 && tag.getInt("ammo") > 0) { if (mainHandItem.is(TargetModTags.Items.GUN) && tag.getDouble("bolt_action_time") > 0 && tag.getInt("ammo") > 0) {
if (!player.getCooldowns().isOnCooldown(mainHandItem.getItem()) && mainHandItem.getOrCreateTag().getDouble("need_bolt_action") == 1) { if (!player.getCooldowns().isOnCooldown(mainHandItem.getItem()) && mainHandItem.getOrCreateTag().getDouble("need_bolt_action") == 1) {
mainHandItem.getOrCreateTag().putDouble("bolt_action_anim", mainHandItem.getOrCreateTag().getDouble("bolt_action_time")); mainHandItem.getOrCreateTag().putDouble("bolt_action_anim", mainHandItem.getOrCreateTag().getDouble("bolt_action_time"));