Jump to content

Open a gui?


KeeganDeathman
 Share

Recommended Posts

Hi im having trouble opening my gui. I have it set so that when the block is right clicked it calls this:

player.openGui(Lyoko.instance, 1, world, x, y, z);

and that leads to this i think in my main mod file:

NetworkRegistry.instance().registerGuiHandler(this, new GuiHandler());

and my guihandler looks like this

 

package codelyoko;

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 {
//returns an instance of the Container you made earlier
@Override
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
{
	TileEntity tileEntity = world.getBlockTileEntity(x, y, z);

	if(tileEntity instanceof TileEntityTowerConsole)
	{
		return new ContainerTowerConsole(player.inventory, (TileEntityTowerConsole) tileEntity);
	}
	return null;
}

//returns an instance of the Gui you made earlier
@Override
public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
{
	TileEntity tileEntity = world.getBlockTileEntity(x, y, z);

	if(tileEntity instanceof TileEntityTowerConsole)
	{
		return new GuiTowerConsole();
	}
	return null;
}
}

 

 

and my gui looks like this:

 

package codelyoko;

import org.lwjgl.input.Keyboard;

import net.minecraft.client.gui.*;
import net.minecraft.client.resources.I18n;

public class GuiTowerConsole extends GuiScreen {
private GuiTextField codeTextField;
private GuiButton doneBtn;

public void initGui()
    {
        Keyboard.enableRepeatEvents(true);
        this.buttonList.clear();
        this.buttonList.add(this.doneBtn = new GuiButton(1, this.width / 2 - 100, this.height / 4 + 96 + 12, I18n.func_135053_a("gui.done")));
        this.codeTextField = new GuiTextField(this.fontRenderer, this.width / 2 - 150, 60, 300, 20);
        this.codeTextField.setMaxStringLength(32767);
        this.codeTextField.setFocused(true);
    }
/**
 * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
 */
protected void actionPerformed(GuiButton par1GuiButton)
{
	switch (par1GuiButton.id)
	{
	case 1:
		this.mc.displayGuiScreen((GuiScreen)null);
		this.mc.setIngameFocus();
		this.mc.sndManager.resumeAllSounds();
		break;
	}
}

/**
 * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
 */
protected void keyTyped(char par1, int par2)
    {
        this.codeTextField.textboxKeyTyped(par1, par2);
        this.doneBtn.enabled = this.codeTextField.getText().trim().length() > 0;

        if (par2 == 28)
        {
            this.actionPerformed(this.doneBtn);
        }
    }
/**
 * Draws the screen and all the components in it.
 */
public void drawScreen(int par1, int par2, float par3)
{
	this.drawDefaultBackground();
	this.drawCenteredString(this.fontRenderer, "CODE:", this.width / 2, this.height / 4 - 60 + 20, 16777215);
	this.codeTextField.drawTextBox();
	super.drawScreen(par1, par2, par3);
}
}

 

and my Tile Entity looks like this:

 

package codelyoko;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;

public class TileEntityTowerConsole extends TileEntity implements IInventory{

protected String customName;

@Override
public void writeToNBT(NBTTagCompound par1)
{
	super.writeToNBT(par1);
}

@Override
public void readFromNBT(NBTTagCompound par1)
{
	super.readFromNBT(par1);
}

@Override
public int getSizeInventory() {
	// TODO Auto-generated method stub
	return 0;
}

@Override
public ItemStack getStackInSlot(int i) {
	// TODO Auto-generated method stub
	return null;
}

@Override
public ItemStack decrStackSize(int i, int j) {
	// TODO Auto-generated method stub
	return null;
}

@Override
public ItemStack getStackInSlotOnClosing(int i) {
	// TODO Auto-generated method stub
	return null;
}

@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
	// TODO Auto-generated method stub

}

@Override
public String getInvName()
    {
        return this.isInvNameLocalized() ? this.customName : "codelyoko:TowerConsoleTileEntity";
    }

    public void setCustomName(String par1Str)
    {
        this.customName = par1Str;
    }
@Override
public boolean isInvNameLocalized() {
	// TODO Auto-generated method stub
	return false;
}

@Override
public int getInventoryStackLimit() {
	// TODO Auto-generated method stub
	return 0;
}

@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
	// TODO Auto-generated method stub
	return false;
}

@Override
public void openChest() {
	// TODO Auto-generated method stub

}

@Override
public void closeChest() {
	// TODO Auto-generated method stub

}

@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
	// TODO Auto-generated method stub
	return false;
}

}

 

and my container looks like this:

 

package codelyoko;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;

public class ContainerTowerConsole extends Container {

        protected TileEntityTowerConsole tileEntity;

        public ContainerTowerConsole (InventoryPlayer inventoryPlayer, TileEntityTowerConsole te){
                tileEntity = te;

                //the Slot constructor takes the IInventory and the slot number in that it binds to
                //and the x-y coordinates it resides on-screen
                for (int i = 0; i < 3; i++) {
                        for (int j = 0; j < 3; j++) {
                                addSlotToContainer(new Slot(tileEntity, j + i * 3, 62 + j * 18, 17 + i * 18));
                        }
                }

                //commonly used vanilla code that adds the player's inventory
                bindPlayerInventory(inventoryPlayer);
        }

        @Override
        public boolean canInteractWith(EntityPlayer player) {
                return tileEntity.isUseableByPlayer(player);
        }


        protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) {
                for (int i = 0; i < 3; i++) {
                        for (int j = 0; j < 9; j++) {
                                addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9,
                                                8 + j * 18, 84 + i * 18));
                        }
                }

                for (int i = 0; i < 9; i++) {
                        addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142));
                }
        }

        @Override
        public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
                ItemStack stack = null;
                Slot slotObject = (Slot) inventorySlots.get(slot);

                //null checks and checks if the item can be stacked (maxStackSize > 1)
                if (slotObject != null && slotObject.getHasStack()) {
                        ItemStack stackInSlot = slotObject.getStack();
                        stack = stackInSlot.copy();

                        //merges the item into player inventory since its in the tileEntity
                        if (slot < 9) {
                                if (!this.mergeItemStack(stackInSlot, 0, 35, true)) {
                                        return null;
                                }
                        }
                        //places it into the tileEntity is possible since its in the player inventory
                        else if (!this.mergeItemStack(stackInSlot, 0, 9, false)) {
                                return null;
                        }

                        if (stackInSlot.stackSize == 0) {
                                slotObject.putStack(null);
                        } else {
                                slotObject.onSlotChanged();
                        }

                        if (stackInSlot.stackSize == stack.stackSize) {
                                return null;
                        }
                        slotObject.onPickupFromSlot(player, stackInSlot);
                }
                return stack;
        }
}

 

but when i right click the block, absolutley nothing happens.

Help?

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

Link to comment
Share on other sites

Okay...

 

package codelyoko;

import net.minecraft.block.*;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.src.ModLoader;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockTowerConsole extends BlockContainer
implements ITileEntityProvider{

public BlockTowerConsole(int par1, Material par2Material) {
	super(par1, par2Material);
}

@Override
public TileEntity createNewTileEntity(World world) {
	return new TileEntityTowerConsoleBlock();
}

public boolean shouldSideBeRendered(IBlockAccess iblockaccess, int i, int j, int k, int l)
{
	return false;
}

//And this tell it that you can see through this block, and neighbor blocks should be rendered.
public boolean isOpaqueCube()
{
	return false;
}

 @Override
    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
    {
        TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
        if (tileEntity == null || player.isSneaking())
        {
            return false;
        }
        else
        {
            player.openGui(Lyoko.instance, 1, world, x, y, z);
            return true;
        }
    }
}

 

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

Link to comment
Share on other sites

okay here it is, I've gotten rid off the stuff that has almost nothing to do with the gui.

 

package codelyoko;

import codelyoko.Client.ItemRenderWilliamSword;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.gui.Gui;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.*;
import net.minecraftforge.client.IItemRenderer;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.common.EnumHelper;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
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.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid= "codelyoko", name="Code: CRAFT", version="1.2")
@NetworkMod(clientSideRequired=true, serverSideRequired=false)
public class Lyoko {


@Instance("codelyoko")
public static Lyoko instance;

//Blocks
public static Block TowerConsoleBlock;

public static Gui GUITowerConsole;


public static final String modID = "codelyoko";
public static final String TC = "codelyoko:TowerConsole";



@EventHandler
public void PreInit(FMLPreInitializationEvent event){
	//Blocks    
	TowerConsoleBlock = new BlockTowerConsole(506, Material.glass).setUnlocalizedName(TC).setBlockUnbreakable().setResistance(600000000.0F).setStepSound(Block.soundGlassFootstep);
	//Items

		}

@EventHandler
public void load(FMLInitializationEvent event) {


	//GameRegisteryS
	GameRegistry.registerTileEntity(TileEntityTowerConsole.class, "TileEntityTowerConsole");
	//Names   
	LanguageRegistry.addName(itemTowerConsole, "Tower Interface");

	//Other
	NetworkRegistry.instance().registerGuiHandler(this, new GuiHandler());


}

}

 

 

need anything else?

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

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
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.

 Share



×
×
  • Create New...

Important Information

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