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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • so basically another rundown of my probelm. Im the admin of a 1.20.1 modded server. Were using forge 47.2.0 but tested this issue in other forge versions too on sevrer and client side. so the forge version isnt the issue. The bug happens in following instances. Were using the attacks of the jujutsucraft mod by orca normally. And for everyone that stands there nothing changes. But everyone who wasnt in the chunks before or who relogins again those chunks will appear invisible for the most part. I tried fixing this be removing and adding following mods in many combinations. Embeddium, canary, memoryleakfix, ai improvements, Krypton reforges, better chunkloading, radium reforged, embeddium plus, farsight, betterchunkloading, oculus I tested most of these mods alone and in differents combinations with each other and without the mods. What i noticed is zhat when i removed  . most invisible chunks will return or semi return. and only ine or two chunks stay invisible. I rechanged those mids mostly on the cöient side but also some in the serveside. Ir most likely isnt an issue with another non performance mod since i noticed this thing with embeddium. Ans also the problem wasnt there im the beginning of the server. Granted since then we updated some of the mods that add content and their lib mod. But i went to every big mods discord and community that we have and i didnt find someone else havinf that chunk problem. Heres the link to a video of the Problem. https://streamable.com/9v1if2     heres the link to the modlist: https://ibb.co/myF8dtX     Pleaee im foghting for months with this problem. All the performance mods kn the modlist are for sure not the issue i tested without all of them.
    • It looks like you're only setting the health if the thing you are hitting is a player.  
    • It sounds like you accidentally have two items that are both named "orange". Ensure that you give items unique names in the string when you register them. That's one of the more annoying errors to track down if you don't know what's causing it, though.
    • when i tried downloading blockfront from curseforge for version 1.20.1 i get the winrar file  and that i extract and i just get the "manifest.json" file no mod when exctracted
    • I have managed to implement your code after finally managing to sort out my error with exporting to .zip, though when the game launches, it will not allow me to proceed further and gives this error:   Caused by: java.lang.IllegalArgumentException: Duplicate registration orange   I have checked over my code and no errors or warnings are present that would affect my orange item. I am not sure what to do here. (It is only registered in the ModItems, as it should be).
  • Topics

×
×
  • Create New...

Important Information

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