这个是GUi类的代码复制代码我希望右键手里的一个物品然后出现这个gui界面
这个是调用方法
复制代码是按这个教程学习的大佬教程地址
贤者遇到的问题是,我右键后,GUI界面会一闪而过,闪一下,没了,QAQ ,
是不是教师1.8.9和我这个1.12.2在这块有变化呀,
期待大佬帮忙解决
- public class GuiContainerDemo extends GuiContainer {
- private static final String TEXTURE_PATH = Begin.MOD_ID + ":" + "textures/gui/container/gui_demo.png";
- private static final ResourceLocation TEXTURE = new ResourceLocation(TEXTURE_PATH);
- public GuiContainerDemo(Container inventorySlotsIn) {
- super(inventorySlotsIn);
- this.xSize = 176;
- this.ySize = 133;
- }
- /**
- * Draws the background layer of this container (behind the items).
- *
- * @param partialTicks
- * @param mouseX
- * @param mouseY
- */
- @Override
- protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
- GlStateManager.color(1.0F, 1.0F, 1.0F);
- this.mc.getTextureManager().bindTexture(TEXTURE);
- int offsetX = (this.width-this.xSize)/2;
- int offsetY = (this.height-this.ySize)/2;
- this.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize);
- }
- }
这个是调用方法
- public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
- BlockPos blockPos = playerIn.getPosition();
- playerIn.openGui(Begin.INSTANCE, GuiElementLoader.GUI_DEMO, worldIn, blockPos.getX(), blockPos.getY(), blockPos.getZ());
- return super.onItemRightClick(worldIn, playerIn, handIn);
- }
贤者遇到的问题是,我右键后,GUI界面会一闪而过,闪一下,没了,QAQ ,
是不是教师1.8.9和我这个1.12.2在这块有变化呀,
期待大佬帮忙解决

注册 IGuiHandler 了吗?
物品右键时没有检查 !world.isRemote。
你会用调试器的单步执行吗?
物品右键时没有检查 !world.isRemote。
你会用调试器的单步执行吗?
好复杂看不懂
3TUSK 发表于 2020-6-3 08:15
注册 IGuiHandler 了吗?
物品右键时没有检查 !world.isRemote。
你会用调试器的单步执行吗? ...

- public boolean canInteractWith(EntityPlayer playerIn) {
- return true;
- }
