Jump to content

[1.6.4] Custom GUI not Opening.


charismax

Recommended Posts

Hey everyone, well, this is my first time modding (also my first post on the forum). I've seen some tutorials, but somehow i cant get my GUI to Open, it causes no error on the console. Also, i've checked various similar problems in the forums, but none of them help me.

 

Instance in my main class

 

 

@Mod( modid = InfoDelMod.ID, name = InfoDelMod.Nombre, version = InfoDelMod.Version ) 
@NetworkMod( channels = {InfoDelMod.Canal}, clientSideRequired = true, serverSideRequired = true )

public class AntiOres {
  
  @Instance(InfoDelMod.ID)
  public static AntiOres instance;  

 

 

 

Registering Tile Entity

 

 

public class TileEntities {
  
  public static void init() {
    GameRegistry.registerTileEntity(TileEntityAntiFurnace.class, Nombres.tileEntityAntiFurnace_ID);
    
    LanguageRegistry.instance().addStringLocalization("container.antiFurnace", "Anti Furnace");
  }

}

 

 

 

initializing it in my main class

 

 

  @EventHandler
  public static void init(FMLInitializationEvent event)
  {
     TileEntities.init();
     ...

 

 

 

Gui Class

 

 

package antiores.gui;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;

import org.lwjgl.opengl.GL11;

import antiores.container.ContainerAntiFurnace;
import antiores.lib.InfoDelMod;
import antiores.tilentities.TileEntityAntiFurnace;

public class GuiAntiFurnace extends GuiContainer {
  
  public static final ResourceLocation gui = new ResourceLocation(InfoDelMod.ID.toLowerCase() + "textures/gui/antiFurnace.png");
  
  public TileEntityAntiFurnace antiFurnace;

  public GuiAntiFurnace(InventoryPlayer inventoryPlayer, TileEntityAntiFurnace entity) {
    super(new ContainerAntiFurnace(inventoryPlayer, entity));
    
    this.xSize = 176;
    this.ySize = 166;
    
    this.antiFurnace = entity;
  }

  public void drawGuiContainerForegroundLayer(int par1, int par2) {
    String name = this.antiFurnace.isInvNameLocalized() ? this.antiFurnace.getInvName() : I18n.getString(this.antiFurnace.getInvName());
    
    
    this.fontRenderer.drawString(name, this.xSize / 2 - this.fontRenderer.getStringWidth(name) / 2  , 6, 4210752); 
    this.fontRenderer.drawString(I18n.getString("container.inventory"), 8, this.ySize - 96, 4210752); 
  }
  
  public void drawGuiContainerBackgroundLayer(float f, int i, int j) {
    GL11.glColor4f(1F, 1F, 1F, 1F); 
    
    Minecraft.getMinecraft().getTextureManager().bindTexture(gui);
    
    drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize );
    
    if (this.antiFurnace.isBurning()) {
      int k = this.antiFurnace.getBurnTimeRemainingScaled(12);
      drawTexturedModalRect(guiLeft + 56, guiTop + 36 + 12 - k, 176, 12- k , 14, k + 2);
}
    
    int k = this.antiFurnace.getCookProgressScaled(24);
    drawTexturedModalRect(guiLeft +79 , guiTop + 34, 176, 14 , k+1, 16 );
        
  }

}

 

 

 

GuiHandler Class

 

 

package antiores.gui;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import antiores.AntiOres;
import antiores.container.ContainerAntiFurnace;
import antiores.lib.Ids;
import antiores.tilentities.TileEntityAntiFurnace;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.common.network.NetworkRegistry;

public class GuiHandler implements IGuiHandler {
  
  public GuiHandler(){
    NetworkRegistry.instance().registerGuiHandler(AntiOres.instance, this);
  }

  
  public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    TileEntity entity = world.getBlockTileEntity(x, y, z); 
    if (entity !=null) { //detecta si hay una entidad
      switch(ID){
        case Ids.tileEntityAntiFurnace_default: 
          if(entity instanceof TileEntityAntiFurnace){
            return new ContainerAntiFurnace(player.inventory, (TileEntityAntiFurnace) entity);
          }
      }
    }
    return null;
  }

  public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    TileEntity entity = world.getBlockTileEntity(x, y, z); 
    if (entity !=null) { 
      switch(ID){
        case Ids.tileEntityAntiFurnace_default:
          if(entity instanceof TileEntityAntiFurnace){
            return new GuiAntiFurnace(player.inventory, (TileEntityAntiFurnace) entity); 
          }
      }
    }
    return null;
  }
  
}

 

 

 

onBlockActivated function in my Block's class

 

 

public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ){
    if(!world.isRemote){
      FMLNetworkHandler.openGui(player, AntiOres.instance, Ids.guiIdAntiFurnace, world, x, y, z);
    }
    
    return true;
  }

 

 

 

writeToNBT function in my Tile Entity Class

 

public void writeToNBT(NBTTagCompound nbt) {
    super.writeToNBT(nbt);
    
    nbt.setShort("burnTime", (short)this.burnTime);
    nbt.setShort("cookTime", (short)this.cookTime);
    NBTTagList list = new NBTTagList();
    
    for(int i=0; i< this.slots.length; i++) {
      if (this.slots[i] != null) {
        NBTTagCompound compound = new NBTTagCompound();
        compound.setByte("Slot", (byte)i);
        this.slots[i].writeToNBT(compound);
        list.appendTag(compound);
      }
    }
    
    nbt.setTag("Items", list);
    
    if(this.isInvNameLocalized()){
      nbt.setString("Name", this.localizedName);
    }

  }

 

 

readFromNBT funcion in my Tile Entity Class

 

public void readFromNBT(NBTTagCompound nbt) {
    super.readFromNBT(nbt);
    
    NBTTagList list = nbt.getTagList("Items");
    this.slots = new ItemStack[this.getSizeInventory()];
    
    for(int i=0; i<list.tagCount(); i++) {
      NBTTagCompound compound = (NBTTagCompound) list.tagAt(i);
      byte b = compound.getByte("Slot");
      
      if (b >= 0 && b < this.slots.length) {
        this.slots[b] = ItemStack.loadItemStackFromNBT(compound);
      }
    }
    
    this.burnTime = nbt.getShort("burnTime");
    this.cookTime = nbt.getShort("cookTime");
    this.currentItemBurnTime = getItemBurnTime(this.slots[1]);
    
    if(nbt.hasKey("Name")){
      this.localizedName = nbt.getString("Name");
    }
    
  }

 

 

Sorry for my english, it's not my native language.

Also sorry if you see some of my random non-english anotations, i dont know if i manage to delete it all.

I dont know if i am missing something important here, or if you need more info to tell what am i doing wrong.

My minecraft version is 1.6.4 and my forge version is 9.11.1.965

 

Link to comment
Share on other sites

You want to open the gui on both server and client. I know it sounds strange, but it is for the container and all.

Your code only opens the container of the GUI

[spoiler=so, this code]

public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ){
    if(!world.isRemote){
      FMLNetworkHandler.openGui(player, AntiOres.instance, Ids.guiIdAntiFurnace, world, x, y, z);
    }
    
    return true;
  }

 

 

Dont check for a side:

@Override
public boolean onBlockActivated(World, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{
     player.openGui(AntiOres.instance, Ids.guiIdAntiFurnace, world, x, y, z) //Same as: FMLNetworkHandler.openGui(player, AntiOres.instance, Ids.guiIdAntiFurnace, world, x, y, z); though one less import 
     return true;
}

I am fairly new to Java and modding, so my answers are not always 100% correct. Sorry for that!

Link to comment
Share on other sites

I suspect

Ids.tileEntityAntiFurnace_default

is not the same Id as

Ids.guiIdAntiFurnace

.

 

They aren't, do they have to be the same?

 

edit: Well, I tried that, thank you so much. Now i'm only getting a texture error but i thin i can manage that.

 

I though that if the ids were the same then i'd got an error

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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