Jump to content

openGui on block crashes my game!


BRHSM

Recommended Posts

I have made a block which must act like a furnace but it doesn't work. When I right click the block the game crashes: http://pastebin.com/w95m2sfR

 

I have this code to open the GUI:

 

public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){
	player.openGui(MainRegistry.modInstance, 0, world, x, y, z);
	return true;
}

 

and here are my guihandler and gui code:

 

package Com.BRHSM.Mod.Handler;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import Com.BRHSM.Mod.Container.ContainerTutFurnace;
import Com.BRHSM.Mod.Gui.GuiTutFurnace;
import Com.BRHSM.Mod.TileEntities.TileEntityGemSmelter;



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

public class GuiHandler implements IGuiHandler {

public GuiHandler (){

}

@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	if(ID == 0){
		TileEntityGemSmelter tileEntityFurnace = (TileEntityGemSmelter) world.getTileEntity(x, y, z);
		return new ContainerTutFurnace(player.inventory, tileEntityFurnace);
	}
	return null;
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	if(ID == 0){
		TileEntityGemSmelter tileEntityTestContainer = (TileEntityGemSmelter) world.getTileEntity(x, y, z);
		return new GuiTutFurnace(player.inventory, tileEntityTestContainer);
	}
	return null;
}

}

 

package Com.BRHSM.Mod.Gui;

import org.lwjgl.opengl.GL11;

import Com.BRHSM.Mod.Container.ContainerTutFurnace;
import Com.BRHSM.Mod.TileEntities.TileEntityGemSmelter;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;


import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class GuiTutFurnace extends GuiContainer{

private static final ResourceLocation furnaceGuiTextures = new ResourceLocation("textures/gui/container/furnace.png");
private TileEntityGemSmelter tileFurnace;

public GuiTutFurnace(InventoryPlayer invPlayer, TileEntityGemSmelter tile) {
	super(new ContainerTutFurnace(invPlayer, tile));
	this.tileFurnace = tile;

}

protected void drawGuiContainerForegroundLayer(int par1, int par2){
	String string = this.tileFurnace.hasCustomInventoryName() ? this.tileFurnace.getInventoryName() : I18n.format(this.tileFurnace.getInventoryName(), new Object[0]);
	this.fontRendererObj.drawString(string, this.xSize / 2 - this.fontRendererObj.getStringWidth(string), 6, 4210752);
	this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 94, 4210752);
}

@Override
protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) {
	 GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.mc.getTextureManager().bindTexture(furnaceGuiTextures);
        int k = (this.width - this.xSize) / 2;
        int l = (this.height - this.ySize) / 2;
        this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
        int i1;

        if (this.tileFurnace.isBurning())
        {
            i1 = this.tileFurnace.getBurnTimeRemainingScaled(12);
            this.drawTexturedModalRect(k + 56, l + 36 + 12 - i1, 176, 12 - i1, 14, i1 + 2);
        }

        i1 = this.tileFurnace.getCookProgressScaled(24);
        this.drawTexturedModalRect(k + 79, l + 34, 176, 14, i1 + 1, 16);
}

}

 

what is causing the crach and how do i keep it from happening?

Link to comment
Share on other sites

Here is the part with the modinctance, I beleve this is correct though

 

@Mod(modid = MainRegistry.MODID, version = MainRegistry.VERSION)
public class MainRegistry {
public static final String MODID = "yarritecraftmod";
public static final String VERSION = "1.0.0 (Alpha)";

@SidedProxy(clientSide = "Com.BRHSM.Mod.Registry.ClientProxy",serverSide = "Com.BRHSM.Mod.Registry.ServerProxy")
public static ServerProxy Proxy;

@Instance(MODID)
public static MainRegistry modInstance;

@Metadata
public static ModMetadata meta;

Link to comment
Share on other sites

Show where you register your IGuiHandler. And you should only be opening the GUI on the server.

 

Like this???

 

public void registerNetworkStuff(){
	NetworkRegistry.INSTANCE.registerGuiHandler(MainRegistry.modInstance, new GuiHandler());
}

 

within the server proxy?

 

Here is the full server proxy class:

 

public class ServerProxy implements IGuiHandler {
public void registerRenderThings() {

}

public int addArmor(String armor) {
	return 0;
}

public void registerNetworkStuff(){
	NetworkRegistry.INSTANCE.registerGuiHandler(MainRegistry.modInstance, new GuiHandler());
}

public void registerTileEntities(){
	GameRegistry.registerTileEntity(TileEntityGemSmelter.class, MainRegistry.MODID);
}

@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world,
		int x, int y, int z) {
	// TODO Auto-generated method stub
	return null;
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world,
		int x, int y, int z) {
	// TODO Auto-generated method stub
	return null;
}

 

I don't realy know what to do with the last two methots, so i left them blank for now, Is that the problem?

Link to comment
Share on other sites

Show where you register your IGuiHandler. And you should only be opening the GUI on the server.

 

Like this???

 

public void registerNetworkStuff(){
	NetworkRegistry.INSTANCE.registerGuiHandler(MainRegistry.modInstance, new GuiHandler());
}

 

within the server proxy?

 

Here is the full server proxy class:

 

public class ServerProxy implements IGuiHandler {
public void registerRenderThings() {

}

public int addArmor(String armor) {
	return 0;
}

public void registerNetworkStuff(){
	NetworkRegistry.INSTANCE.registerGuiHandler(MainRegistry.modInstance, new GuiHandler());
}

public void registerTileEntities(){
	GameRegistry.registerTileEntity(TileEntityGemSmelter.class, MainRegistry.MODID);
}

@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world,
		int x, int y, int z) {
	// TODO Auto-generated method stub
	return null;
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world,
		int x, int y, int z) {
	// TODO Auto-generated method stub
	return null;
}

 

I don't realy know what to do with the last two methots, so i left them blank for now, Is that the problem?

 

What.. Gui Handler Should be on the Both Side! But you implement the interface on ServerProxy..

You should make an independent class implementing IGuiHandler.

+ And you hadn't ever set up the handler, it shouldn't be just returning null! So the exception is a matter of course.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

Yeah I fugured that was the problem but i had to create the methodes otherwise i had to make serverproxy abstract, i don't think that should be done either.

 

what exactly do you mean with the "Both Side"?

You should understand what you are doing before coding...

GuiHandler should exist on both Server side and Client side. So you should not have it in your ServerProxy..

I already said, you should make an independent GuiHandler class implementing IGuiHandler.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

It's because it is not enough. You should set up your own Container class and Gui class,

and You should make the GuiHandler give the Container in getServerGuiElement, and the Gui in getClientGuiElement!

 

Seriously, did you look into any Gui tutorial?

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

It's because it is not enough. You should set up your own Container class and Gui class,

and You should make the GuiHandler give the Container in getServerGuiElement, and the Gui in getClientGuiElement!

 

Seriously, did you look into any Gui tutorial?

 

Yes I did, I have those classes:

 

package Com.BRHSM.Mod.Gui;

import org.lwjgl.opengl.GL11;

import Com.BRHSM.Mod.Container.ContainerTutFurnace;
import Com.BRHSM.Mod.TileEntities.TileEntityGemSmelter;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;


import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class GuiTutFurnace extends GuiContainer{

private static final ResourceLocation furnaceGuiTextures = new ResourceLocation("textures/gui/container/furnace.png");
private TileEntityGemSmelter tileFurnace;

public GuiTutFurnace(InventoryPlayer invPlayer, TileEntityGemSmelter tile) {
	super(new ContainerTutFurnace(invPlayer, tile));
	this.tileFurnace = tile;

}

protected void drawGuiContainerForegroundLayer(int par1, int par2){
	String string = this.tileFurnace.hasCustomInventoryName() ? this.tileFurnace.getInventoryName() : I18n.format(this.tileFurnace.getInventoryName(), new Object[0]);
	this.fontRendererObj.drawString(string, this.xSize / 2 - this.fontRendererObj.getStringWidth(string), 6, 4210752);
	this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 94, 4210752);
}

@Override
protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) {
	 GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.mc.getTextureManager().bindTexture(furnaceGuiTextures);
        int k = (this.width - this.xSize) / 2;
        int l = (this.height - this.ySize) / 2;
        this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
        int i1;

        if (this.tileFurnace.isBurning())
        {
            i1 = this.tileFurnace.getBurnTimeRemainingScaled(12);
            this.drawTexturedModalRect(k + 56, l + 36 + 12 - i1, 176, 12 - i1, 14, i1 + 2);
        }

        i1 = this.tileFurnace.getCookProgressScaled(24);
        this.drawTexturedModalRect(k + 79, l + 34, 176, 14, i1 + 1, 16);
}

}

 

Container:

 

package Com.BRHSM.Mod.Container;

import Com.BRHSM.Mod.TileEntities.TileEntityGemSmelter;
import net.minecraft.block.BlockContainer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotFurnace;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;


public class ContainerTutFurnace extends Container{

private TileEntityGemSmelter tileFurnace;
private int lastCookTime;
private int lastBurnTime;
private int lastItemBurnTime;

public ContainerTutFurnace(InventoryPlayer player, TileEntityGemSmelter tileEntityFurnace){
	this.tileFurnace = tileEntityFurnace;
	this.addSlotToContainer(new Slot(tileEntityFurnace, 0, 56, 17));
	this.addSlotToContainer(new Slot(tileEntityFurnace, 1, 56, 53));
	this.addSlotToContainer(new SlotFurnace(player.player, tileEntityFurnace, 2, 116, 35));
	int i;

	for(i = 0; i < 3; ++i){
		for(int j = 0; j < 9; ++j){
			this.addSlotToContainer(new Slot(player, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
		}
	}

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

public void addCraftingToCrafters(ICrafting craft){
	super.addCraftingToCrafters(craft);
	craft.sendProgressBarUpdate(this, 0, this.tileFurnace.GemSmelterCookTime);
	craft.sendProgressBarUpdate(this, 1, this.tileFurnace.GemSmelterBurnTime);
	craft.sendProgressBarUpdate(this, 2, this.tileFurnace.GemSmelterCurrentTime);
}

public void detectAndSendChanges(){
	super.detectAndSendChanges();
	for(int i = 0; i < this.crafters.size(); ++i){
		ICrafting craft = (ICrafting) this.crafters.get(i);

		if(this.lastCookTime != this.tileFurnace.GemSmelterCookTime){
			craft.sendProgressBarUpdate(this, 0, this.tileFurnace.GemSmelterCookTime);
		}

		if(this.lastBurnTime != this.tileFurnace.GemSmelterBurnTime){
			craft.sendProgressBarUpdate(this, 1, this.tileFurnace.GemSmelterBurnTime);
		}

		if(this.lastItemBurnTime != this.tileFurnace.GemSmelterCurrentTime){
			craft.sendProgressBarUpdate(this, 2, this.tileFurnace.GemSmelterCurrentTime);
		}
	}

	this.lastBurnTime = this.tileFurnace.GemSmelterBurnTime;
	this.lastCookTime = this.tileFurnace.GemSmelterCookTime;
	this.lastItemBurnTime = this.tileFurnace.GemSmelterCurrentTime;
}

@SideOnly(Side.CLIENT)
public void updateProgressBar(int par1, int par2){
	if(par1 == 0){
		this.tileFurnace.GemSmelterCookTime = par2;
	}

	if(par1 == 1){
		this.tileFurnace.GemSmelterBurnTime = par2;
	}

	if(par1 == 2){
		this.tileFurnace.GemSmelterCurrentTime = par2;
	}
}

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

public ItemStack transferStackInSlot(EntityPlayer player, int par2){
	ItemStack itemstack = null;
	Slot slot = (Slot) this.inventorySlots.get(par2);

	if(slot != null && slot.getHasStack()){
		ItemStack itemstack1 = slot.getStack();
		itemstack = itemstack1.copy();

		if(par2 == 2){
			if(!this.mergeItemStack(itemstack1, 3, 39, true)){
				return null;
			}
			slot.onSlotChange(itemstack1, itemstack);
		}else if(par2 != 1 && par2 != 0){
			if(FurnaceRecipes.smelting().getSmeltingResult(itemstack1) != null){
				if(!this.mergeItemStack(itemstack1, 0, 1, false)){
					return null;
				}
			}else if(TileEntityGemSmelter.isItemFuel(itemstack1)){
				if(!this.mergeItemStack(itemstack1, 1, 2, false)){
					return null;
				}
			}else if(par2 >=3 && par2 < 30){
				if(!this.mergeItemStack(itemstack1, 30, 39, false)){
					return null;
				}
			}else if(par2 >= 30 && par2 < 39 && !this.mergeItemStack(itemstack1, 3, 30, false)){
				return null;
			}
		}else if(!this.mergeItemStack(itemstack1, 3, 39, false)){
			return null;
		}
		if(itemstack1.stackSize == 0){
			slot.putStack((ItemStack)null);
		}else{
			slot.onSlotChanged();
		}
		if(itemstack1.stackSize == itemstack.stackSize){
			return null;
		}
		slot.onPickupFromSlot(player, itemstack1);
	}
	return itemstack;
}
}

Link to comment
Share on other sites

The important thing is : You have to set up your own Gui Handler and let it give the Container in getServerGuiElement, and the Gui in getClientGuiElement...

How many times should I say this;

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

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.