Jump to content

[1.7.2][SOLVED]Gui is not opening?


robertcars

Recommended Posts

So I am trying to get my GUI to open and its not and I'm not sure why can someone please help me other thanks.

 

My main mod class

 

package com.robertcars.generaltech.core;

import com.robertcars.generaltech.blocks.ModBlocks;
import com.robertcars.generaltech.gui.GuiHandler;
import com.robertcars.generaltech.items.ModItems;
import com.robertcars.generaltech.lib.Reference;
import com.robertcars.generaltech.proxy.CommonProxy;
import com.robertcars.generaltech.tileentity.ModTileEntitys;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler; // used in 1.6.2
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;

@Mod(modid=Reference.MOD_ID, name=Reference.MOD_NAME, version=Reference.VERSION)

public class GeneralTech {

@Instance(value = Reference.MOD_ID)
        public static GeneralTech instance;
        
        @SidedProxy(clientSide="com.robertcars.generaltech.proxy.ClientProxy", serverSide="com.robertcars.generaltech.proxy.CommonProxy")
        public static CommonProxy proxy;
        
        @EventHandler
        public void preInit(FMLPreInitializationEvent event) {
        	ModItems.init();
        	ModBlocks.init();
        	ModTileEntitys.init();
        }
        
        @EventHandler
        public void load(FMLInitializationEvent event) {
                proxy.registerRenderers();
            	NetworkRegistry.INSTANCE.registerGuiHandler(this, new GuiHandler());
        }
        
        @EventHandler
        public void postInit(FMLPostInitializationEvent event) {

        }
}

 

 

GuiHandler

 

 

package com.robertcars.generaltech.gui;

import com.robertcars.generaltech.container.ContainerTeleporter;
import com.robertcars.generaltech.lib.GuiIDS;
import com.robertcars.generaltech.tileentity.TileEntityTeleporter;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.IGuiHandler;

public class GuiHandler implements IGuiHandler {

public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {

	TileEntity entity = world.getTileEntity(x, y, z);

	if(entity != null) {
		switch (ID) {
		case GuiIDS.guiIDTeleporter:
			if(entity instanceof TileEntityTeleporter) {
				return new ContainerTeleporter(player.inventory, (TileEntityTeleporter) entity);
			}
		}
	}

	return null;
}

public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {

	TileEntity entity = world.getTileEntity(x, y, z);

	if(entity != null) {
		switch (ID) {
		case GuiIDS.guiIDTeleporter:
			if(entity instanceof TileEntityTeleporter) {
				return new GuiTeleporter(player.inventory, (TileEntityTeleporter) entity);
			}
		}
	}

	return null;
}

}

 

 

Gui class

 

 

package com.robertcars.generaltech.gui;

import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;

import com.robertcars.generaltech.container.ContainerTeleporter;
import com.robertcars.generaltech.tileentity.TileEntityTeleporter;

public class GuiTeleporter extends GuiContainer {

public TileEntityTeleporter teleporter;

public GuiTeleporter(InventoryPlayer inventoryPlayer, TileEntityTeleporter entity) {
	super(new ContainerTeleporter(inventoryPlayer, entity));

	this.teleporter = entity;
}

//draw text
public void drawGuiContainerForegroundLayer(int par1, int par2) {

}

//draw images
public void drawGuiContainerBackgroundLayer(float f, int i, int j) {

	this.drawDefaultBackground();

}

}

 

 

Container

 

 

package com.robertcars.generaltech.container;


import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;

import com.robertcars.generaltech.tileentity.TileEntityTeleporter;

public class ContainerTeleporter extends Container{

private TileEntityTeleporter teleporter;


public ContainerTeleporter(InventoryPlayer inventory, TileEntityTeleporter tileentity) {
	this.teleporter = tileentity;

}

public boolean canInteractWith(EntityPlayer var1) {
	return this.teleporter.isUseableByPlayer(var1);
}

}

 

 

TileEntity

 

 

package com.robertcars.generaltech.tileentity;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;

public class TileEntityTeleporter extends TileEntity {

public String pass;
public int pa;

    public void readFromNBT(NBTTagCompound p_145839_1_) {
        super.readFromNBT(p_145839_1_);
    }

    public void writeToNBT(NBTTagCompound p_145841_1_){
    }

public boolean isUseableByPlayer(EntityPlayer entityplayer) {
	return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : entityplayer.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5F, (double)this.zCoord + 0.5D) <= 64.0D;
}
}

 

 

Block

 

 

package com.robertcars.generaltech.blocks;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

import com.robertcars.generaltech.core.GeneralTech;
import com.robertcars.generaltech.lib.GuiIDS;
import com.robertcars.generaltech.tileentity.TileEntityTeleporter;

import cpw.mods.fml.common.network.internal.FMLNetworkHandler;


public class BlockTeleporter extends BasicBlock {

    public BlockTeleporter() {
        super();
    }
    
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, GeneralTech.instance, GuiIDS.guiIDTeleporter, world, x, y, z);
	}

	return true;
}

    
    public TileEntity createTileEntity(World world, int metadata) {
       return new TileEntityTeleporter();
    }
}

 

Link to comment
Share on other sites

I think you are missing the IGuiHandler.

 

Im sorry I must have messed up putting my code in.

here is my guihandler

package com.robertcars.generaltech.gui;

 

import com.robertcars.generaltech.container.ContainerTeleporter;

import com.robertcars.generaltech.lib.GuiIDS;

import com.robertcars.generaltech.tileentity.TileEntityTeleporter;

 

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.world.World;

import cpw.mods.fml.common.network.IGuiHandler;

 

public class GuiHandler implements IGuiHandler {

 

public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {

 

TileEntity entity = world.getTileEntity(x, y, z);

 

if(entity != null) {

switch (ID) {

case GuiIDS.guiIDTeleporter:

if(entity instanceof TileEntityTeleporter) {

return new ContainerTeleporter(player.inventory, (TileEntityTeleporter) entity);

}

}

}

 

return null;

}

 

public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {

 

TileEntity entity = world.getTileEntity(x, y, z);

 

if(entity != null) {

switch (ID) {

case GuiIDS.guiIDTeleporter:

if(entity instanceof TileEntityTeleporter) {

return new GuiTeleporter(player.inventory, (TileEntityTeleporter) entity);

}

}

}

 

return null;

}

 

}

 

Link to comment
Share on other sites

Yes right here

 

 

package com.robertcars.generaltech.tileentity;

import cpw.mods.fml.common.registry.GameRegistry;

public class ModTileEntitys {

public static void init() {
	GameRegistry.registerTileEntity(TileEntityTeleporter.class, "tileEntityTeleporter");
}

}

 

 

I did notice i don't know if this helps but when I put System.out.println("test"); in my Guihandler in the getClientGuiElement and try to open the GUI it doesn't print. But im not sure if even if it was working if it would print either.

Link to comment
Share on other sites

if you are what you may want to do is change

 

FMLNetworkHandler.openGui(player, GeneralTech.instance, GuiIDS.guiIDTeleporter, world, x, y, z);

 

to

 

player.openGui(GeneralTech.instance, GuiIDS.guiIDTeleporter, world, x, y, z

it still didnt work after changing that
Link to comment
Share on other sites

Yes right here

 

 

package com.robertcars.generaltech.tileentity;

import cpw.mods.fml.common.registry.GameRegistry;

public class ModTileEntitys {

public static void init() {
	GameRegistry.registerTileEntity(TileEntityTeleporter.class, "tileEntityTeleporter");
}

}

 

 

I did notice i don't know if this helps but when I put System.out.println("test"); in my Guihandler in the getClientGuiElement and try to open the GUI it doesn't print. But im not sure if even if it was working if it would print either.

 

it should work it is usually just very hard to see in the console

Link to comment
Share on other sites

Yes right here

 

 

package com.robertcars.generaltech.tileentity;

import cpw.mods.fml.common.registry.GameRegistry;

public class ModTileEntitys {

public static void init() {
	GameRegistry.registerTileEntity(TileEntityTeleporter.class, "tileEntityTeleporter");
}

}

 

 

I did notice i don't know if this helps but when I put System.out.println("test"); in my Guihandler in the getClientGuiElement and try to open the GUI it doesn't print. But im not sure if even if it was working if it would print either.

 

it should work it is usually just very hard to see in the console

Well it doesnt atleast not here

 

package com.robertcars.generaltech.gui;

import com.robertcars.generaltech.container.ContainerTeleporter;
import com.robertcars.generaltech.lib.GuiIDS;
import com.robertcars.generaltech.tileentity.TileEntityTeleporter;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.IGuiHandler;

public class GuiHandler implements IGuiHandler {

public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {

	TileEntity entity = world.getTileEntity(x, y, z);

	if(entity != null) {
		switch (ID) {
		case GuiIDS.guiIDTeleporter:
			if(entity instanceof TileEntityTeleporter) {
				return new ContainerTeleporter(player.inventory, (TileEntityTeleporter) entity);
			}
		}
	}

	return null;
}

public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	System.out.println("Test");
	TileEntity entity = world.getTileEntity(x, y, z);

	if(entity != null) {
		switch (ID) {
		case GuiIDS.guiIDTeleporter:
			if(entity instanceof TileEntityTeleporter) {
				return new GuiTeleporter(player.inventory, (TileEntityTeleporter) entity);
			}
		}
	}

	return null;
}

}

 

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.