Jump to content

[1.7.2]Gui not opening, searched helps, nothing found.


lorizz

Recommended Posts

Hi guys, it's me, lorizz.

Yesterday I started creating a mod for the 1.7.2 version and I'm at the point to make a custom Crafting Table, I know how to do it but the problem is.

 

I followed a 1.6.4 tutorial on making a Gui/Container with the GuiHandler class and updated all functions/method to 1.7.2, no errors were found.

 

But the problem is that everytime I try to right click on my custom block, the gui doesn't show, no crash, nothing happens.

I searched a lot on this forum and someone found a way to fix it without explaining how.

Those are all my classes:

 

Main class:

 

package it.edennetwork.alum.main;

import it.edennetwork.alum.handlers.GuiHandler;
import it.edennetwork.alum.player.PlayerEventHandler;
import it.edennetwork.alum.registries.RegBlock;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
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 = AncientLumendell.modid, name = "Ancient Lumendell", version = "Alpha 1.0")
public class AncientLumendell {

public static final String modid = "gm_alum_alpha";

@Instance(value = AncientLumendell.modid)
public static AncientLumendell instance;

@SidedProxy(clientSide = "it.edennetwork.alum.main.ClientProxy", serverSide = "it.edennetwork.alum.main.ServerProxy")
public static ServerProxy proxy;

@EventHandler
public void onPreLoad(FMLPreInitializationEvent e) {

}

@EventHandler
public void onLoad(FMLInitializationEvent e) {
	proxy.initRenderers();
	proxy.initSounds();

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

	RegBlock.init();
	RegBlock.registerBlocks();
	RegBlock.addNames();

	MinecraftForge.EVENT_BUS.register(new PlayerEventHandler());
}

@EventHandler
public void onPostLoad(FMLPostInitializationEvent e) {

}
}

 

 

Gui Handler:

 

package it.edennetwork.alum.handlers;

import it.edennetwork.alum.containers.ContainerFoundry;
import it.edennetwork.alum.guis.GuiFoundry;
import it.edennetwork.alum.main.AncientLumendell;
import it.edennetwork.alum.tileentities.TileEntityFoundry;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.common.network.NetworkRegistry;

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 GuiFoundry.id:
			if (entity instanceof TileEntityFoundry) {
				return new ContainerFoundry(player.inventory,
						(TileEntityFoundry) 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 GuiFoundry.id:
			if (entity instanceof TileEntityFoundry) {
				return new GuiFoundry(player.inventory,
						(TileEntityFoundry) entity);
			}
		}
	}

	return null;
}
}

 

 

GuiFoundry:

 

package it.edennetwork.alum.guis;

import it.edennetwork.alum.containers.ContainerFoundry;
import it.edennetwork.alum.main.AncientLumendell;
import it.edennetwork.alum.tileentities.TileEntityFoundry;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;

import org.lwjgl.opengl.GL11;

public class GuiFoundry extends GuiContainer {

public static final int id = 0;

public static final ResourceLocation guiTexture = new ResourceLocation(
		AncientLumendell.modid, "textures/guis/gui_foundry.png");

public TileEntityFoundry foundry;

public GuiFoundry(InventoryPlayer invPlayer,
		TileEntityFoundry entity) {
	super(new ContainerFoundry(invPlayer, entity));

	this.foundry = entity;

	xSize = 344;
	ySize = 310;
}

@Override
public void drawGuiContainerBackgroundLayer(float f, int j, int i) {
	GL11.glColor4f(1F, 1F, 1F, 1F);
	Minecraft.getMinecraft().renderEngine.bindTexture(guiTexture);
	drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
}
}

 

 

ContainerFoundry:

 

package it.edennetwork.alum.containers;

import it.edennetwork.alum.tileentities.TileEntityFoundry;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;

public class ContainerFoundry extends Container {

private TileEntityFoundry foundry;

public ContainerFoundry(InventoryPlayer invPlayer, TileEntityFoundry entity) {
	this.foundry = entity;
}

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

 

 

TileEntityFoundry:

 

package it.edennetwork.alum.tileentities;

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 TileEntityFoundry extends TileEntity implements IInventory {

private ItemStack[] inventory;

public TileEntityFoundry() {
	inventory = new ItemStack[1];
}

@Override
public int getSizeInventory() {
	return inventory.length;
}

@Override
public ItemStack getStackInSlot(int i) {
	return inventory[i];
}

@Override
public ItemStack decrStackSize(int slot, int count) {
	ItemStack itemstack = getStackInSlot(slot);

	if (itemstack != null) {
		if (itemstack.stackSize <= count) {
			setInventorySlotContents(slot, null);
		} else {
			itemstack = itemstack.splitStack(count);
			updateEntity();
		}
	}
	return itemstack;
}

@Override
public ItemStack getStackInSlotOnClosing(int slot) {
	ItemStack itemstack = getStackInSlot(slot);
	setInventorySlotContents(slot, null);
	return itemstack;
}

@Override
public void setInventorySlotContents(int slot, ItemStack itemstack) {
	inventory[slot] = itemstack;

	if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) {
		itemstack.stackSize = getInventoryStackLimit();
	}
	updateEntity();
}

@Override
public String getInventoryName() {
	return "Fonderia";
}

@Override
public boolean hasCustomInventoryName() {
	return true;
}

@Override
public int getInventoryStackLimit() {
	return 64;
}

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

@Override
public void openInventory() {

}

@Override
public void closeInventory() {

}

@Override
public boolean isItemValidForSlot(int slot, ItemStack itemstack) {
	return true;
}

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

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

 

 

BlockFoundry:

 

package it.edennetwork.alum.blocks;

import it.edennetwork.alum.guis.GuiFoundry;
import it.edennetwork.alum.main.AncientLumendell;
import it.edennetwork.alum.tileentities.TileEntityFoundry;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockFoundry extends Block {

public BlockFoundry(Material material) {
	super(material);
	this.setBlockName("block_foundry");
	this.setCreativeTab(CreativeTabs.tabDecorations);
	this.setHardness(5F);
	this.setResistance(10F);
}

@Override
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, AncientLumendell.instance,
				GuiFoundry.id, world, x, y, z);
	}
	return true;
}

@SideOnly(Side.CLIENT)
public static IIcon topIcon;
@SideOnly(Side.CLIENT)
public static IIcon frontIcon;
@SideOnly(Side.CLIENT)
public static IIcon sideIcon;

@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister icon) {
	topIcon = icon.registerIcon(AncientLumendell.modid + ":"
			+ "block_foundry_top");
	frontIcon = icon.registerIcon(AncientLumendell.modid + ":"
			+ "block_foundry_front");
	sideIcon = icon.registerIcon(AncientLumendell.modid + ":"
			+ "block_foundry_side");
}

@Override
public IIcon getIcon(int side, int meta) {
	if (side == 0 || side == 1) {
		return topIcon;
	} else if (side == 2) {
		return frontIcon;
	} else {
		return sideIcon;
	}
}

@Override
public void onBlockAdded(World world, int x, int y, int z) {
	super.onBlockAdded(world, x, y, z);
	this.setDefaultDirection(world, x, y, z);
}

private void setDefaultDirection(World world, int x, int y, int z) {
	if (!world.isRemote) {
		Block block = world.getBlock(x, y, z - 1);
		Block block1 = world.getBlock(x, y, z + 1);
		Block block2 = world.getBlock(x - 1, y, z);
		Block block3 = world.getBlock(x + 1, y, z);
		byte b0 = 3;

		if (block.func_149730_j() && !block1.func_149730_j()) {
			b0 = 3;
		}

		if (block1.func_149730_j() && !block.func_149730_j()) {
			b0 = 2;
		}

		if (block2.func_149730_j() && !block3.func_149730_j()) {
			b0 = 5;
		}

		if (block3.func_149730_j() && !block2.func_149730_j()) {
			b0 = 4;
		}

		world.setBlockMetadataWithNotify(x, y, z, b0, 2);
	}
}

@Override
public void onBlockPlacedBy(World world, int x, int y, int z,
		EntityLivingBase entity, ItemStack itemstack) {
	int rotation = MathHelper
			.floor_double((double) (entity.rotationYaw * 4F / 360F) + 0.5D) & 3;

	if (rotation == 0) {
		world.setBlockMetadataWithNotify(x, y, z, 2, 2);
	}

	if (rotation == 1) {
		world.setBlockMetadataWithNotify(x, y, z, 5, 2);
	}

	if (rotation == 2) {
		world.setBlockMetadataWithNotify(x, y, z, 3, 2);
	}

	if (rotation == 3) {
		world.setBlockMetadataWithNotify(x, y, z, 4, 2);
	}
}

@Override
public TileEntity createTileEntity(World var1, int var2) {
	// TODO Auto-generated method stub
	return new TileEntityFoundry();
}

@Override
public boolean hasTileEntity() {
	return true;
}
}

 

 

And finally the method I use to register the TileEntity:

public void initRenderers() {
GameRegistry.registerTileEntity(TileEntityFoundry.class, "alum_te_foundry");
}

 

Why the gui is not working? Thanks!

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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