小心后门
  1. public void NoItemNull() {
  2.                 try {
  3.                 if(Minecraft.getMinecraft().thePlayer.getHeldItem().getItem() != null) {//问题来源
  4.                         Minecraft.getMinecraft().fontRendererObj.drawString(Minecraft.getMinecraft().thePlayer.getHeldItem().getItem().getRegistryName(), 20, 70, Color.BLACK.getRGB());//获得并渲染玩家手速拿的物品的注册名字
  5.                 }
  6.                 }catch(Exception e) {e.printStackTrace();}
  7.         }
复制代码
疑问:进入游戏会导致游戏崩溃


我是想要他用RenderGameOverlayEvent.Text事件渲染文字在游戏页面

我试了很多次 可能会发生的错误

但是无法解决这个问题 *可能我比较菜

问题来源就是这个try断点里面


?1.12.2获取物品不见有问题

1.8就有问题了? 各位这是怎么回事?

求解

附上错误报告:没不出来他说什么错误
  1. [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]: java.lang.NullPointerException
  2. [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]:         at io.github.enaiLusoaix.minecraft.qaq.NoItemNull(qaq.java:87)
  3. [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]:         at io.github.enaiLusoaix.minecraft.qaq.base(qaq.java:65)
  4. [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]:         at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_11_qaq_base_PlayerTickEvent.invoke(.dynamic)
  5. [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]:         at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:49)
  6. [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]:         at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:140)
  7. [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]:         at net.minecraftforge.fml.common.FMLCommonHandler.onPlayerPreTick(FMLCommonHandler.java:352)
  8. [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]:         at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:248)
  9. [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]:         at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:366)
  10. [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]:         at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:347)
  11. [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]:         at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:36)
  12. [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]:         at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:10)
  13. [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]:         at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:15)
  14. [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]:         at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
  15. [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]:         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
  16. [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]:         at net.minecraft.util.Util.runTask(Util.java:22)
  17. [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]:         at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:736)
  18. [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]:         at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:681)
  19. [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]:         at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:159)
  20. [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]:         at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:548)
  21. [01:03:07] [Server thread/INFO] [STDERR]: [io.github.enaiLusoaix.minecraft.qaq:NoItemNull:92]:         at java.lang.Thread.run(Thread.java:748)
复制代码




粘兽
getHeldItem().getItem() != null
改为
getHeldItem() != null
试试

第一页 上一页 下一页 最后一页