Jump to content

[SOLVED][1.8] Gui not opening


Guest

Recommended Posts

Hi, I am making a custom crafting table (4x4) and have a problem with opening the Gui. What the problem looks like is that in the GuiSCT (gui for my crafting table) it doesn't look like the drawGuiContainerForegroundLayer or the drawGuiContainerBackgrounLayer functions are not getting called. Since all the System.out.println() in my code works except the two in these functions.. Anyone have a idea why this is not called?

 

Main:

 

package com.tommywithatiger.extendedcrafting.core;

import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry;

import com.tommywithatiger.extendedcrafting.ECCraftingManager;
import com.tommywithatiger.extendedcrafting.blocks.small_crafting_table.BlockSCT;
import com.tommywithatiger.extendedcrafting.core.proxy.CommonProxy;
import com.tommywithatiger.extendedcrafting.handler.GuiHandler;

@Mod(modid=Reference.MOD_ID, name=Reference.MOD_NAME, version=Reference.VERSION)

public class ExtendedCrafting {

@SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.SERVER_PROXY_CLASS)
public static CommonProxy proxy;

@Instance(Reference.MOD_ID)
public static ExtendedCrafting instance;

//Items
public static Item building_part_stone;
public static Item building_part_wood;

//Blocks
public static Block BlockSCT;




@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
	//Items
	building_part_stone = new Item().setUnlocalizedName("building_part_stone");
	building_part_wood = new Item().setUnlocalizedName("building_part_wood");

    //Blocks
	BlockSCT = new BlockSCT().setHardness(1.5F).setUnlocalizedName("small_crafting_table").setCreativeTab(CreativeTabs.tabAllSearch);

	//Items
	GameRegistry.registerItem(building_part_stone, building_part_stone.getUnlocalizedName().substring(5));
	GameRegistry.registerItem(building_part_wood, building_part_wood.getUnlocalizedName().substring(5));

	//Blocks
	GameRegistry.registerBlock(BlockSCT, "small_crafting_table");

	NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler());
}

    @EventHandler
public void init(FMLInitializationEvent event)
{
    	proxy.registerRenders();
	ECCraftingManager.crafting();

}

    @EventHandler
public void postInit(FMLPostInitializationEvent event)
{
    	
}


}

 

 

Reference:

 

package com.tommywithatiger.extendedcrafting.core;

public class Reference {

public static final String MOD_ID = "ec";
public static final String MOD_NAME = "Extended Crafting";
public static final String VERSION = "0.0.0";
public static final String CLIENT_PROXY_CLASS = "com.tommywithatiger.extendedcrafting.core.proxy.ClientProxy";
public static final String SERVER_PROXY_CLASS = "com.tommywithatiger.extendedcrafting.core.proxy.CommonProxy";
}

 

 

BlockSCT:

 

package com.tommywithatiger.extendedcrafting.blocks.small_crafting_table;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;

import com.tommywithatiger.extendedcrafting.core.ExtendedCrafting;


public class BlockSCT extends Block{

 public BlockSCT()
    {
        super(Material.wood);
    }

public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
    {
        if (worldIn.isRemote)
        {
            return true;
        }
        else
        {
        	System.out.println("test");
        	playerIn.openGui(ExtendedCrafting.instance, 1, worldIn, pos.getX(), pos.getY(), pos.getZ());
            return true;
        }
    }

}

 

 

ContainerSCT:

 

package com.tommywithatiger.extendedcrafting.blocks.small_crafting_table;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCraftResult;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;

import com.tommywithatiger.extendedcrafting.core.ExtendedCrafting;

public class ContainerSCT extends Container {

public InventoryCrafting craftMatrix;
public IInventory craftResult;
private World worldObj;
private int posX;
private int posY;
private int posZ;

public ContainerSCT(InventoryPlayer invPlayer, World world, int x, int y, int z){
	craftMatrix = new InventoryCrafting(this, 4, 4);
	craftResult = new InventoryCraftResult();
	worldObj = world;
	posX = x;
	posY = y;
	posZ = z;
	System.out.println("ContainerSCT");
	this.addSlotToContainer(new SlotCrafting(invPlayer.player, craftMatrix, craftResult, 0, 145, 47));

	for (int i = 0; i < 4; i++){
		 for (int k = 0; k < 4; k++){
			 this.addSlotToContainer(new Slot(craftMatrix, k + i * 4, 4 + k*18, 3 + i * 18));
		 }
	}

	for (int i = 0; i < 3; i++){
		for(int k = 0; k < 9; k++){
			this.addSlotToContainer(new Slot(invPlayer, k + i * 9 + 9, 8 + k * 10, 94 + i * 18));
		}
	}

	for (int i = 0; i < 9; i++){
		this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 10, 148));
	}

	onCraftMatrixChanged(craftMatrix);
}

public void onCraftMatrixChanged(IInventory iinventory){
	//craftResult.setInventorySlotContents(0, SCTCraftingManager.getInstance().findMatchingRecipe(craftMatrix, worldObj));
}

@Override
public boolean canInteractWith(EntityPlayer player) {
	if (worldObj.getBlockState(new BlockPos(posX, posY, posZ)) != ExtendedCrafting.BlockSCT){
		return false;
	} else {
		return player.getDistanceSq((double)posX + 0.5D, (double)posY + 0.5D, (double)posZ + 0.5D) <= 64.0D;
	}
}

public void onContainerClosed(EntityPlayer par1EntityPlayer) {
        super.onContainerClosed(par1EntityPlayer);

        if (!this.worldObj.isRemote)
        {
            for (int i = 0; i < 9; ++i)
            {
                ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i);

                if (itemstack != null)
                {
                    par1EntityPlayer.dropPlayerItemWithRandomChoice(itemstack, false);
                }
            }
        }
    }

public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, 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 == 0)
            {
                if (!this.mergeItemStack(itemstack1, 10, 46, true))
                {
                    return null;
                }

                slot.onSlotChange(itemstack1, itemstack);
            }
            else if (par2 >= 10 && par2 < 37)
            {
                if (!this.mergeItemStack(itemstack1, 37, 46, false))
                {
                    return null;
                }
            }
            else if (par2 >= 37 && par2 < 46)
            {
                if (!this.mergeItemStack(itemstack1, 10, 37, false))
                {
                    return null;
                }
            }
            else if (!this.mergeItemStack(itemstack1, 10, 46, false))
            {
                return null;
            }

            if (itemstack1.stackSize == 0)
            {
                slot.putStack((ItemStack)null);
            }
            else
            {
                slot.onSlotChanged();
            }

            if (itemstack1.stackSize == itemstack.stackSize)
            {
                return null;
            }

            slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
        }

        return itemstack;
    }


}

 

 

GuiSCT:

 

package com.tommywithatiger.extendedcrafting.gui;

import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

import org.lwjgl.opengl.GL11;

import com.tommywithatiger.extendedcrafting.blocks.small_crafting_table.ContainerSCT;

public class GuiSCT extends GuiContainer{

private ResourceLocation texture = new ResourceLocation("ec:textures/gui/smallcraftingtable.png");

public GuiSCT(InventoryPlayer invPlayer, World world, int x, int y, int z) {
	super(new ContainerSCT(invPlayer, world, x, y, z));
	System.out.println("GuiSCT");
}

@Override
protected void drawGuiContainerForegroundLayer(int i, int j){
	this.fontRendererObj.drawString("Small Crafting Table", 10, 5, 0x990000);
	System.out.println("GuiContainer2");
}


@Override
protected void drawGuiContainerBackgroundLayer(float var1,int var2, int var3) {

	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
	this.mc.renderEngine.bindTexture(texture);

	int j = (width - xSize) / 2;
	int k = (height - ySize) / 2;

	this.drawTexturedModalRect(j, k, 0, 0, xSize, ySize);
	System.out.println("GuiContainer");
}


}

 

 

GuiHandler:

 

package com.tommywithatiger.extendedcrafting.handler;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.IGuiHandler;

import com.tommywithatiger.extendedcrafting.blocks.small_crafting_table.BlockSCT;
import com.tommywithatiger.extendedcrafting.blocks.small_crafting_table.ContainerSCT;
import com.tommywithatiger.extendedcrafting.gui.GuiSCT;

public class GuiHandler implements IGuiHandler {

@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world,	int x, int y, int z) {
	System.out.println("GUIHANDLER2");
	if(ID == 1){
		return new ContainerSCT(player.inventory, world, x , y, z);
	}

	return null;
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	System.out.println("GUIHANDLER");
	if(ID == 1){
		System.out.println("Test2");
		return new GuiSCT(player.inventory, world, x , y, z);
		}
	return null;
}

}

 

 

 

Link to comment
Share on other sites

Please post the Screenshot of the GUI. Is it ever opened?

 

Here is the GUI

 

817c4989e9.png

 

 

The GUI is opened sometimes, maybe 1 of 50. But closes after some milliseconds.

 

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.