优化命令实现

This commit is contained in:
Light_Quanta 2024-05-16 00:58:58 +08:00
parent 3f0698cf6e
commit d6da3afd7c
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
5 changed files with 50 additions and 58 deletions

View file

@ -8,7 +8,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
@Mod.EventBusSubscriber @Mod.EventBusSubscriber
public class BigexpCommand { public class BigExpCommand {
@SubscribeEvent @SubscribeEvent
public static void registerCommand(RegisterCommandsEvent event) { public static void registerCommand(RegisterCommandsEvent event) {
event.getDispatcher().register(Commands.literal("target:bigexp") event.getDispatcher().register(Commands.literal("target:bigexp")

View file

@ -8,7 +8,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
@Mod.EventBusSubscriber @Mod.EventBusSubscriber
public class MediumexpCommand { public class MediumExpCommand {
@SubscribeEvent @SubscribeEvent
public static void registerCommand(RegisterCommandsEvent event) { public static void registerCommand(RegisterCommandsEvent event) {
event.getDispatcher().register(Commands.literal("target:mediumexp") event.getDispatcher().register(Commands.literal("target:mediumexp")

View file

@ -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;
}));
}
}

View file

@ -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;
}));
}
}

View file

@ -22,17 +22,21 @@ public class PressFireProcedure {
M870fireProcedure.execute(player); M870fireProcedure.execute(player);
VectorFireProcedure.execute(player); VectorFireProcedure.execute(player);
player.getPersistentData().putDouble("firing", 1); player.getPersistentData().putDouble("firing", 1);
if (player.getMainHandItem().is(ItemTags.create(new ResourceLocation("target:gun")))
&& !(player.getMainHandItem().getItem() == TargetModItems.BOCEK.get()) var mainHandItem = player.getMainHandItem();
&& !(player.getMainHandItem().getItem() == TargetModItems.MINIGUN.get()) var tag = mainHandItem.getOrCreateTag();
&& player.getMainHandItem().getOrCreateTag().getDouble("ammo") == 0
&& player.getMainHandItem().getOrCreateTag().getDouble("reloading") != 1) { 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) { 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");
} }
} }
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) { && (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,
@ -43,7 +47,7 @@ public class PressFireProcedure {
capability.bowPullHold = true; capability.bowPullHold = true;
capability.syncPlayerVariables(player); capability.syncPlayerVariables(player);
}); });
if (player.getMainHandItem().getOrCreateTag().getDouble("ammo") == 0) { if (tag.getDouble("ammo") == 0) {
PlayerReloadProcedure.execute(player); PlayerReloadProcedure.execute(player);
} }
} }