Jump to content

Recommended Posts

Posted

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

 

Posted

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!

Posted

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

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello all. I'm currently grappling with the updateShape method in a custom class extending Block.  My code currently looks like this: The conditionals in CheckState are there to switch blockstate properties, which is working fine, as it functions correctly every time in getStateForPlacement.  The problem I'm running into is that when I update a state, the blocks seem to call CheckState with the position of the block which was changed updated last.  If I build a wall I can see the same change propagate across. My question thus is this: is updateShape sending its return to the neighbouring block?  Is each block not independently executing the updateShape method, thus inserting its own current position?  The first statement appears to be true, and the second false (each block is not independently executing the method). I have tried to fix this by saving the block's own position to a variable myPos at inception, and then feeding this in as CheckState(myPos) but this causes a worse outcome, where all blocks take the update of the first modified block, rather than just their neighbour.  This raises more questions than it answers, obviously: how is a different instance's variable propagating here?  I also tried changing it so that CheckState did not take a BlockPos, but had myPos built into the body - same problem. I have previously looked at neighbourUpdate and onNeighbourUpdate, but could not find a way to get this to work at all.  One post on here about updatePostPlacement and other methods has proven itself long superceded.  All other sources on the net seem to be out of date. Many thanks in advance for any help you might offer me, it's been several days now of trying to get this work and several weeks of generally trying to get round this roadblock.  - Sandermall
    • sorry, I might be stupid, but how do I open it? because the only options I have are too X out, copy it, which doesn't work and send crash report, which doesn't show it to me, also, sorry for taking so long.
    • Can you reproduce this with version 55.0.21? A whole lot of plant placement issues were just fixed in this PR.
    • Necro'ing that thread to ask if you found a solution ? I'm encountering the same crash on loading the world. I created the world in Creative to test my MP, went into survival to test combat, died, crashed on respawn and since then crash on loading the world. Deactivating Oculus isn't fixing it either, and I don't have Optifine (Twilight forest is incompatible)
  • Topics

×
×
  • Create New...

Important Information

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