Jump to content

Recommended Posts

Posted

Hi everyone!

 

I have been working on making a custom GUI for an item (so that when you shift right-click with the item in hand, the GUI opens), and have run into an issue when trying to render the player's inventory inside.

Specifically, the main inventory slots work fine, however the hotbar slots do not work (if you try to pick an item up, it looks like it's about to move then returns to the original state).

I have been debugging this problem for a few hours now, and so I have decided to ask you guys for help.

 

Here is my code:

 

magnet.java

 

 

package com.toastrackenigma.loadstone;

 

import net.minecraft.client.Minecraft;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.world.World;

 

public class magnet extends Item {

 

protected magnet() {

this.setCreativeTab(loadstone.maintab);

}

 

public ItemStack onItemRightClick(ItemStack is, World world, EntityPlayer ep) {

if (ep.isSneaking()&&world.isRemote) {

Minecraft.getMinecraft().displayGuiScreen(new magnetGui(ep.inventory));

}

return is;

}

}

 

 

 

magnetGui.java

 

package com.toastrackenigma.loadstone;

 

import org.lwjgl.opengl.GL11;

 

import net.minecraft.client.renderer.InventoryEffectRenderer;

import net.minecraft.entity.player.InventoryPlayer;

import net.minecraft.util.ResourceLocation;

 

public class magnetGui extends InventoryEffectRenderer {

 

int guiWidth = 176;

int guiHeight = 166;

 

public magnetGui(InventoryPlayer ip) {

super(new magnetGuiContainer(ip));

}

 

@Override

protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) {

int guiX = (width - guiWidth) / 2;

int guiY = (height - guiHeight) / 2;

GL11.glColor4f(1, 1, 1, 1);

drawDefaultBackground();

mc.renderEngine.bindTexture(new ResourceLocation(loadstone.MODID, "textures/gui/magnet.png"));

drawTexturedModalRect(guiX, guiY, 0, 0, guiWidth, guiHeight);

fontRendererObj.drawString("Magnet", guiX+7, guiY+7, 0x404040);

 

}

 

 

}

 

 

 

magnetGuiContainer.java

 

package com.toastrackenigma.loadstone;

 

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.player.InventoryPlayer;

import net.minecraft.inventory.Container;

import net.minecraft.inventory.Slot;

 

public class magnetGuiContainer extends Container {

 

@Override

public boolean canInteractWith(EntityPlayer p_75145_1_) {

return false;

}

 

public magnetGuiContainer(InventoryPlayer ip) {

for (int i=0;i<9;i++) { //Hotbar

this.addSlotToContainer(new Slot(ip,i,8+(18*i),142));

}

for (int i=0;i<3;i++) { //Inv

for (int j=0;j<9;j++) {

this.addSlotToContainer(new Slot(ip,9+(i*9)+j,8+(18*j),84+(18*i)));

}

}

 

}

}

 

 

 

 

Thanks

Posted

This is just wrong:

 

      if (ep.isSneaking()&&world.isRemote) {
         Minecraft.getMinecraft().displayGuiScreen(new magnetGui(ep.inventory));
      }

 

You can't reference Minecraft.getMinecraft() in common code, not even if you wrap it in

world.isRemote

because the dedicated server's ClassLoader does not know that that field will never be true, so it must insure that it can load that class, and will not find it.

 

Also WTH is InventoryEffectRenderer?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

If I don't use Minecraft.getMinecraft(), then how do I call displayGuiScreen?

 

Also, I changed InventoryEffectRenderer from GuiContainer, because I was reading through forum posts of people that had had similar issues, and someone said that changing that to that fixed a similar issue. I tried it on mine and it didn't really do... anything. I guess I just forgot to change it back.

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.