Jump to content

Gui help


hkiller1

Recommended Posts

I am trying to add a custom Gui, i followed the tutorial but now when I start minecraft the block has a stone texture insted of the one I added and the gui wont open. Here is the code I have currently.

 

Economy.java

package economy.common;

import java.io.File;
import java.util.List;

import net.minecraft.src.*;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.Mod.ServerStarting;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
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 = "Hunter_Economy", name = "Economy", version = "1.0")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Economy {

@Instance("Hunter_Economy")
public static Economy instance;

public static Block AtmBlock;
public static Boolean test;
public static int AtmBlockID;
public static String blockname;
public static MinecraftServer server;

    @PreInit
    public void preInit(FMLPreInitializationEvent event) {
    	//minecraft config
    	Configuration config = new Configuration(event.getSuggestedConfigurationFile());
    	
    	config.load();
    	
    	AtmBlockID = config.getBlock("AtmBlock", 201).getInt();
    	
    	test = config.get(Configuration.CATEGORY_GENERAL, "test", false).getBoolean(false);
    	
    	config.save();
    }
    
@SidedProxy(clientSide = "economy.client.ClientProxyEconomy", serverSide = "economy.common.CommonProxyEconomy")
public static CommonProxyEconomy proxy;

@Init
public void load(FMLInitializationEvent event) {

	proxy.registerRenderThings();

	NetworkRegistry.instance().registerGuiHandler(instance, proxy);

	proxy.initTileEntities();

	AtmBlock = new AtmBlock(AtmBlockID, 0, Material.iron);

	GameRegistry.registerBlock(AtmBlock);

	LanguageRegistry.addName(AtmBlock, "Atm");

	GameRegistry.addRecipe(new ItemStack(this.AtmBlock), new Object[]{
		"III",
		"IIG",
		"III",
		'I', Item.ingotIron,
		'G', Block.glass});

	}

@ServerStarting
public void serverStarting(FMLServerStartingEvent event) {

    	//minecraft config
	File file = new File("config/Economy_Acounts.cfg");
    	Configuration config = new Configuration(file);
    	
    	config.load();
    	config.save();

	server = ModLoader.getMinecraftServerInstance();

	ICommandManager commandManager = server.getCommandManager();
	ServerCommandManager manager = ((ServerCommandManager) commandManager);

	manager.registerCommand(new economy.common.command.Money());
	manager.registerCommand(new economy.common.command.SetMoney());

	}

}

 

AtmBlock.java

package economy.common;

import java.util.Random;

import net.minecraft.src.*;

public class AtmBlock extends BlockContainer {

public AtmBlock(int i, int j, Material m) {
	super(i, j, m);
	this.setCreativeTab(CreativeTabs.tabBlock);
	this.setHardness(10.0F);
        this.setResistance(10.0F);
        this.setStepSound(Block.soundMetalFootstep);
        this.setBlockName("Atm");
}

    public int getBlockTextureFromSideAndMetadata(int i, int j)
    {
       switch(i) {
       case 0: return 1;
       case 1: return 1;
       case 2: return 1;
       case 3: return 0;
       case 4: return 1;
       case 5: return 1;
       default: return 1;
       }
    }
    
@Override
public TileEntity createNewTileEntity(World var1) {
	return new TileAtm();
}

    @Override
    public boolean onBlockActivated(World world, int x, int y, int z,
                    EntityPlayer player, int idk, float what, float these, float are) {
            TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
            if (tileEntity == null || player.isSneaking()) {
                    return false;
            }
            
            player.openGui(Economy.instance, 0, world, x, y, z);
            return true;
    }

}

 

TileAtm.java

package economy.common;

import economy.common.AtmBlock;
import net.minecraft.src.*;

public class TileAtm extends TileEntity implements IInventory {

private ItemStack[] atmItemStacks = new ItemStack[3];

    public void readFromNBT(NBTTagCompound nbtTagCompound) {
super.readFromNBT(nbtTagCompound);

// Read in the ItemStacks in the inventory from NBT
NBTTagList tagList = nbtTagCompound.getTagList("Items");
        this.atmItemStacks = new ItemStack[this.getSizeInventory()];
        for (int i = 0; i < tagList.tagCount(); ++i) {
            NBTTagCompound tagCompound = (NBTTagCompound)tagList.tagAt(i);
            byte slot = tagCompound.getByte("Slot");
            if (slot >= 0 && slot < this.atmItemStacks.length) {
                this.atmItemStacks[slot] = ItemStack.loadItemStackFromNBT(tagCompound);
            }
        }

}

public void writeToNBT(NBTTagCompound nbtTagCompound) {
super.writeToNBT(nbtTagCompound);

// Write the ItemStacks in the inventory to NBT
NBTTagList tagList = new NBTTagList();
        for (int currentIndex = 0; currentIndex < this.atmItemStacks.length; ++currentIndex) {
            if (this.atmItemStacks[currentIndex] != null) {
                NBTTagCompound tagCompound = new NBTTagCompound();
                tagCompound.setByte("Slot", (byte)currentIndex);
                this.atmItemStacks[currentIndex].writeToNBT(tagCompound);
                tagList.appendTag(tagCompound);
            }
        }
        nbtTagCompound.setTag("Items", tagList);
        
}

/**
* Returns the number of slots in the inventory.
*/
public int getSizeInventory() {
return this.atmItemStacks.length;
}

/**
* Returns the stack in slot i
*/
public ItemStack getStackInSlot(int i) {
return this.atmItemStacks[i];
}

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

public ItemStack getStackInSlotOnClosing(int i) {
return null;
}

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

}

public String getInvName() {
return "container.atm";
}

public int getInventoryStackLimit() {
return 64;
}

public void openChest() { }
public void closeChest() { }

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

}

 

ContainerAtm.java

package economy.common;

import net.minecraft.src.*;
import economy.common.TileAtm;

public class ContainerAtm extends Container {

    private TileAtm atm;
    
    public ContainerAtm(InventoryPlayer inventoryPlayer, TileAtm atm) {
    	
    	this.atm = atm;
    
        this.addSlotToContainer(new Slot(atm, 0, 56, 17));
        
        this.addSlotToContainer(new Slot(atm, 1, 56, 62));
        
        for (int inventoryRowIndex = 0; inventoryRowIndex < 3; ++inventoryRowIndex)
        {
            for (int inventoryColumnIndex = 0; inventoryColumnIndex < 9; ++inventoryColumnIndex)
            {
                this.addSlotToContainer(new Slot(inventoryPlayer, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 8 + inventoryColumnIndex * 18, 94 + inventoryRowIndex * 18));
            }
        }

        // Add the player's action bar slots to the container
        for (int actionBarSlotIndex = 0; actionBarSlotIndex < 9; ++actionBarSlotIndex)
        {
            this.addSlotToContainer(new Slot(inventoryPlayer, actionBarSlotIndex, 8 + actionBarSlotIndex * 18, 152));
        }
    }
    
    public boolean canInteractWith(EntityPlayer player) {
        //return atm.isUseableByPlayer(player);
     return true;
    }
    
}

 

CommonProxyEconomy.java

package economy.common;

import net.minecraft.src.*;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.common.registry.GameRegistry;
import economy.client.GuiAtm;
import economy.common.ContainerAtm;
import economy.common.TileAtm;

public class CommonProxyEconomy implements IGuiHandler {
    
    public void initTileEntities() {
     GameRegistry.registerTileEntity(TileAtm.class, "tileAtm");
    }
    
    @Override
    public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    	
        if (ID == 201) {
            TileAtm atm = (TileAtm)world.getBlockTileEntity(x, y, z);
            return new ContainerAtm(player.inventory, atm);
        }
        
        return null;
    }

    @Override
    public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    	
        if (ID == 201) {
            TileAtm atm = (TileAtm)world.getBlockTileEntity(x, y, z);
            return new GuiAtm(player.inventory, atm);
        }
        
        return null;
    }

public void registerRenderThings() {
}

}

 

ClientProxyEconomy.java

package economy.client;

import net.minecraftforge.client.MinecraftForgeClient;
import economy.common.CommonProxyEconomy;

public class ClientProxyEconomy extends CommonProxyEconomy {

@Override
public void registerRenderThings() {

	MinecraftForgeClient.preloadTexture("economy/SpriteSheet.png");

}

}

 

GuiAtm.java

package economy.client;

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;
import cpw.mods.fml.common.registry.LanguageRegistry;
import economy.common.ContainerAtm;
import economy.common.TileAtm;
import net.minecraft.src.*;

public class GuiAtm extends GuiContainer {

    public GuiAtm (InventoryPlayer inventoryPlayer, TileAtm tileAtm) {
    super(new ContainerAtm(inventoryPlayer, tileAtm));
}

protected void drawGuiContainerForegroundLayer() {

    fontRenderer.drawString("Atm", 8, 6, 4210752);
    fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 2, 4210752);
}

@Override
protected void drawGuiContainerBackgroundLayer(float par1, int par2,
            int par3) {

    int texture = mc.renderEngine.getTexture("economy/AtmGui.png");
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    this.mc.renderEngine.bindTexture(texture);
    int x = (width - xSize) / 2;
    int y = (height - ySize) / 2;
    this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
}
    
}

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.