gpt4 book ai didi

java - Minecraft Forge Mod 命令不起作用?

转载 作者:行者123 更新时间:2023-12-01 17:45:25 25 4
gpt4 key购买 nike

我为《我的世界》1.8.9编写了一个锻造模组,如果玩家输入命令,它每20秒发送一条消息,当我在单人游戏中输入命令时,它正在工作,但如果我在多人游戏中输入命令,它会发送一条消息说:“未知命令。输入“help”寻求帮助”。这是命令类的代码:

package AutoAd;

import java.util.Timer;
import java.util.TimerTask;

import net.minecraft.client.Minecraft;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatComponentText;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;

public class CommandAutoAD extends CommandBase{

@Override
public String getCommandName() {
return "startAutoad";
}

@Override
public String getCommandUsage(ICommandSender sender) {
return "/startAutoad";
}

@Override
public void processCommand(final ICommandSender sender, String[] args) throws CommandException {
if(sender instanceof EntityPlayer) {
Thread t = new Thread() {
public void run() {
EntityPlayer player = (EntityPlayer) sender;
for(int i = 0; i<=20; i++) {
MSG(player, "Beacons, Karten, Banner und mehr bei /p h 5ty1ne");
try {
Thread.sleep(20000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
MSG(player, "Karten, Banner, stackweise Eisenblöcke, Emeraldblöcke und mehr bei /p h 5ty1ne");
try {
Thread.sleep(20000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
MSG(player, "Shop bei /p h 5ty1ne");
try {
Thread.sleep(20000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
MSG(player, "Günstig für deinen Shop einkaufen? /p h 5ty1ne");
try {
Thread.sleep(20000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
};
t.start();
}
else {
sender.addChatMessage(new ChatComponentText("In der Konsole nicht verfügbar."));
}
}

public void MSG(EntityPlayer player, String message) {
Minecraft.getMinecraft().thePlayer.sendChatMessage(message);
}
}

这是主要代码:

package AutoAd;

import net.minecraft.command.ServerCommandManager;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.ModMetadata;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import proxy.ServerProxy;

@Mod(modid = AutoAD.MODID)

public class AutoAD {


public static final String MODID = "autoad";
@SidedProxy(clientSide = "proxy.ClientProxy", serverSide = "proxy.ServerProxy")
public static ServerProxy proxy;

@EventHandler
public void preInit(FMLPreInitializationEvent event) {

}

@EventHandler
public void init(FMLInitializationEvent event) {

}

@EventHandler
public void postInit(FMLPostInitializationEvent event) {

}
@EventHandler
public void registerCommands(FMLServerStartingEvent event) {
ServerCommandManager manager = (ServerCommandManager) event.getServer().getCommandManager();
manager.registerCommand(new CommandAutoAD());
}
}

最佳答案

我想你已经在你的 Minecraft 客户端上安装了这个模组,但没有在你的服务器上安装。您可以使用 Minecraft Forge gradle 启动本地开发服务器,或者编译成 JAR 并将该 JAR 拖放到 Minecraft Forge 服务器的 /mods 文件夹中。

关于java - Minecraft Forge Mod 命令不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60873780/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com