From d6da3afd7c2caab32a57243433b83c14ea87d566 Mon Sep 17 00:00:00 2001 From: Light_Quanta Date: Thu, 16 May 2024 00:58:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=91=BD=E4=BB=A4=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...{BigexpCommand.java => BigExpCommand.java} | 2 +- ...mexpCommand.java => MediumExpCommand.java} | 2 +- .../target/command/PVPModeCommand.java | 37 ++++++++++++++ .../target/command/PvPmodeCommand.java | 49 ------------------- .../target/procedures/PressFireProcedure.java | 18 ++++--- 5 files changed, 50 insertions(+), 58 deletions(-) rename src/main/java/net/mcreator/target/command/{BigexpCommand.java => BigExpCommand.java} (97%) rename src/main/java/net/mcreator/target/command/{MediumexpCommand.java => MediumExpCommand.java} (96%) create mode 100644 src/main/java/net/mcreator/target/command/PVPModeCommand.java delete mode 100644 src/main/java/net/mcreator/target/command/PvPmodeCommand.java diff --git a/src/main/java/net/mcreator/target/command/BigexpCommand.java b/src/main/java/net/mcreator/target/command/BigExpCommand.java similarity index 97% rename from src/main/java/net/mcreator/target/command/BigexpCommand.java rename to src/main/java/net/mcreator/target/command/BigExpCommand.java index e15feacf9..35c105d37 100644 --- a/src/main/java/net/mcreator/target/command/BigexpCommand.java +++ b/src/main/java/net/mcreator/target/command/BigExpCommand.java @@ -8,7 +8,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @Mod.EventBusSubscriber -public class BigexpCommand { +public class BigExpCommand { @SubscribeEvent public static void registerCommand(RegisterCommandsEvent event) { event.getDispatcher().register(Commands.literal("target:bigexp") diff --git a/src/main/java/net/mcreator/target/command/MediumexpCommand.java b/src/main/java/net/mcreator/target/command/MediumExpCommand.java similarity index 96% rename from src/main/java/net/mcreator/target/command/MediumexpCommand.java rename to src/main/java/net/mcreator/target/command/MediumExpCommand.java index 9701bfbf5..5f5742cd5 100644 --- a/src/main/java/net/mcreator/target/command/MediumexpCommand.java +++ b/src/main/java/net/mcreator/target/command/MediumExpCommand.java @@ -8,7 +8,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @Mod.EventBusSubscriber -public class MediumexpCommand { +public class MediumExpCommand { @SubscribeEvent public static void registerCommand(RegisterCommandsEvent event) { event.getDispatcher().register(Commands.literal("target:mediumexp") diff --git a/src/main/java/net/mcreator/target/command/PVPModeCommand.java b/src/main/java/net/mcreator/target/command/PVPModeCommand.java new file mode 100644 index 000000000..02d7840bf --- /dev/null +++ b/src/main/java/net/mcreator/target/command/PVPModeCommand.java @@ -0,0 +1,37 @@ + +package net.mcreator.target.command; + +import net.mcreator.target.network.TargetModVariables; +import net.minecraft.commands.Commands; +import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; +import net.minecraftforge.common.util.FakePlayerFactory; +import net.minecraftforge.event.RegisterCommandsEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; + +@Mod.EventBusSubscriber +public class PVPModeCommand { + @SubscribeEvent + public static void registerCommand(RegisterCommandsEvent event) { + event.getDispatcher().register(Commands.literal("target:pvpmode").requires(s -> s.hasPermission(4)).executes(arguments -> { + Level world = arguments.getSource().getUnsidedLevel(); + Entity entity = arguments.getSource().getEntity(); + if (entity == null && world instanceof ServerLevel server) { + entity = FakePlayerFactory.getMinecraft(server); + } + + var mapVariables = TargetModVariables.MapVariables.get(world); + mapVariables.pvpMode = !mapVariables.pvpMode; + mapVariables.syncData(world); + + if (entity instanceof Player player && !player.level().isClientSide()) { + player.displayClientMessage(Component.literal("PVPMODE:" + (mapVariables.pvpMode ? "ON" : "OFF")), false); + } + return 0; + })); + } +} diff --git a/src/main/java/net/mcreator/target/command/PvPmodeCommand.java b/src/main/java/net/mcreator/target/command/PvPmodeCommand.java deleted file mode 100644 index 5c4df9116..000000000 --- a/src/main/java/net/mcreator/target/command/PvPmodeCommand.java +++ /dev/null @@ -1,49 +0,0 @@ - -package net.mcreator.target.command; - -import net.mcreator.target.network.TargetModVariables; -import net.minecraft.commands.Commands; -import net.minecraft.core.Direction; -import net.minecraft.network.chat.Component; -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.Level; -import net.minecraftforge.common.util.FakePlayerFactory; -import net.minecraftforge.event.RegisterCommandsEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; - -@Mod.EventBusSubscriber -public class PvPmodeCommand { - @SubscribeEvent - public static void registerCommand(RegisterCommandsEvent event) { - event.getDispatcher().register(Commands.literal("target:pvpmode").requires(s -> s.hasPermission(4)).executes(arguments -> { - Level world = arguments.getSource().getUnsidedLevel(); - double x = arguments.getSource().getPosition().x(); - double y = arguments.getSource().getPosition().y(); - double z = arguments.getSource().getPosition().z(); - Entity entity = arguments.getSource().getEntity(); - if (entity == null && world instanceof ServerLevel _servLevel) - entity = FakePlayerFactory.getMinecraft(_servLevel); - Direction direction = Direction.DOWN; - if (entity != null) - direction = entity.getDirection(); - - if (TargetModVariables.MapVariables.get(world).pvpMode == true) { - TargetModVariables.MapVariables.get(world).pvpMode = false; - TargetModVariables.MapVariables.get(world).syncData(world); - if (entity instanceof Player _player && !_player.level().isClientSide()) - _player.displayClientMessage(Component.literal("PVPMODE:OFF"), false); - - } else { - TargetModVariables.MapVariables.get(world).pvpMode = true; - TargetModVariables.MapVariables.get(world).syncData(world); - if (entity instanceof Player _player && !_player.level().isClientSide()) - _player.displayClientMessage(Component.literal("PVPMODE:ON"), false); - - } - return 0; - })); - } -} diff --git a/src/main/java/net/mcreator/target/procedures/PressFireProcedure.java b/src/main/java/net/mcreator/target/procedures/PressFireProcedure.java index 0a71208f3..76f46021b 100644 --- a/src/main/java/net/mcreator/target/procedures/PressFireProcedure.java +++ b/src/main/java/net/mcreator/target/procedures/PressFireProcedure.java @@ -22,17 +22,21 @@ public class PressFireProcedure { M870fireProcedure.execute(player); VectorFireProcedure.execute(player); player.getPersistentData().putDouble("firing", 1); - if (player.getMainHandItem().is(ItemTags.create(new ResourceLocation("target:gun"))) - && !(player.getMainHandItem().getItem() == TargetModItems.BOCEK.get()) - && !(player.getMainHandItem().getItem() == TargetModItems.MINIGUN.get()) - && player.getMainHandItem().getOrCreateTag().getDouble("ammo") == 0 - && player.getMainHandItem().getOrCreateTag().getDouble("reloading") != 1) { + + var mainHandItem = player.getMainHandItem(); + var tag = mainHandItem.getOrCreateTag(); + + if (mainHandItem.is(ItemTags.create(new ResourceLocation("target:gun"))) + && !(mainHandItem.getItem() == TargetModItems.BOCEK.get()) + && !(mainHandItem.getItem() == TargetModItems.MINIGUN.get()) + && tag.getDouble("ammo") == 0 + && tag.getDouble("reloading") != 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:triggerclick player @s ~ ~ ~ 10 1"); } } - if (player.getMainHandItem().getItem() == TargetModItems.MINIGUN.get() + if (mainHandItem.getItem() == TargetModItems.MINIGUN.get() && (player.getCapability(TargetModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new TargetModVariables.PlayerVariables())).rifleAmmo == 0) { if (!player.level().isClientSide() && player.getServer() != null) { player.getServer().getCommands().performPrefixedCommand(new CommandSourceStack(CommandSource.NULL, player.position(), player.getRotationVector(), (ServerLevel) player.level(), 4, @@ -43,7 +47,7 @@ public class PressFireProcedure { capability.bowPullHold = true; capability.syncPlayerVariables(player); }); - if (player.getMainHandItem().getOrCreateTag().getDouble("ammo") == 0) { + if (tag.getDouble("ammo") == 0) { PlayerReloadProcedure.execute(player); } }