Jump to content

[SOLVED]GUI Problem


shucke

Recommended Posts

As the title says it i have a small issue with my gui's.

Since i recently updated to forge 4.1.1 i have no clue how to work with networking or anything else.

but my problem is that i cant pickup items from my custom gui.

when i do it imidiatly  puts it back in place it was in before.

 

this worked in minecraft 1.2.5.

 

i have registerd my proxy, guiHandler and Tile Entity.

i have also used the getServerGuiElement & getClientGuiElement function in my CommonProxy.class.

i used the openGui function instead of the modloader one.

 

Here is my code:

 

Main Class

@Mod(modid = "RocketEngineering", name = "Rocket Engineering", version = "0.1")
@NetworkMod(clientSideRequired = true, serverSideRequired = false, versionBounds = "[0.1]")

public class BaseRocketEngineering {
public static int renderId;
@SidedProxy(clientSide = "rocketengineering.client.ClientProxy", serverSide = "rocketengineering.common.CommonProxy")
public static CommonProxy proxy;
@Instance
public static BaseRocketEngineering instance;

public class RocketEngineering{

}

@Init
public void Load(FMLInitializationEvent evt){
	proxy.registerRenderInformation();
	//ClientProxy.registerRenderInformation();
	NetworkRegistry.instance().registerGuiHandler(instance, proxy);
}

 

CommonProxy

public class CommonProxy implements IGuiHandler{
public void registerRenderInformation(){
	//Keep Clear on Server
	RegisterBlocks();
	AddSmelting();
	RegisterTileEntitys();
}

public static void RegisterTileEntitys() {
	GameRegistry.registerTileEntity(TileEntityDataCable.class, "Tile Entity Data Cable");
	GameRegistry.registerTileEntity(TileEntityRocketAssembly.class, "Tile Entity Rocket Assembly");
}
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	TileEntity te = world.getBlockTileEntity(x, y, z);
	if(te != null){
		switch(ID){
			case 0: return new ContainerRocketAssembly(player.inventory, (TileEntityRocketAssembly)te);
		}
	}
	return null;
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	TileEntity te = world.getBlockTileEntity(x, y, z);
	if (te != null){
		switch(ID){
			case 0: return GuiRocketAssembly.buildGUI(player.inventory, (TileEntityRocketAssembly) te);		
		}
	}
	return null;
}
public World getClientWorld() {
	return null;
}
}

 

Block Code:

public class BlockRocketAssembly extends BlockContainer{
protected BlockRocketAssembly(int i){
	super(i, Material.rock);
	this.setCreativeTab(CreativeTabs.tabDeco);
}
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9){
	if(!par1World.isRemote){
		return true;
	}
	Object obj = (TileEntityRocketAssembly)par1World.getBlockTileEntity(par2, par3, par4);
	//ModLoader.openGUI(par5EntityPlayer, new GuiRocketAssembly(par5EntityPlayer.inventory, (TileEntityRocketAssembly)(obj)));
	par5EntityPlayer.openGui((Object)BaseRocketEngineering.instance, 0, par1World, par2, par3, par4);
	return true;
 }

@Override
public TileEntity createNewTileEntity(World var1) {
	return new TileEntityRocketAssembly();
}
}

 

Tile Entity:

package rocketengineering.common;

import net.minecraft.src.EntityPlayer;
import net.minecraft.src.IInventory;
import net.minecraft.src.ItemStack;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.NBTTagList;
import net.minecraft.src.TileEntity;
import net.minecraftforge.common.ISidedInventory;
import net.minecraftforge.common.ForgeDirection;
import cpw.mods.fml.common.registry.GameRegistry;

import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;

public class TileEntityRocketAssembly extends TileEntity implements IInventory, ISidedInventory
{
    /**
     * The ItemStacks that hold the items currently being used in the furnace
     */
    private ItemStack[] furnaceItemStacks = new ItemStack[3];

    public int getSizeInventory()
    {
        return this.furnaceItemStacks.length;
    }

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

    public ItemStack decrStackSize(int par1, int par2)
    {
        if (this.furnaceItemStacks[par1] != null)
        {
            ItemStack var3;

            if (this.furnaceItemStacks[par1].stackSize <= par2)
            {
                var3 = this.furnaceItemStacks[par1];
                this.furnaceItemStacks[par1] = null;
                return var3;
            }
            else
            {
                var3 = this.furnaceItemStacks[par1].splitStack(par2);

                if (this.furnaceItemStacks[par1].stackSize == 0)
                {
                    this.furnaceItemStacks[par1] = null;
                }

                return var3;
            }
        }
        else
        {
            return null;
        }
    }

    public ItemStack getStackInSlotOnClosing(int par1)
    {
        if (this.furnaceItemStacks[par1] != null)
        {
            ItemStack var2 = this.furnaceItemStacks[par1];
            this.furnaceItemStacks[par1] = null;
            return var2;
        }
        else
        {
            return null;
        }
    }


    public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
    {
        this.furnaceItemStacks[par1] = par2ItemStack;

        if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit())
        {
            par2ItemStack.stackSize = this.getInventoryStackLimit();
        }
    }

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


    public void readFromNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.readFromNBT(par1NBTTagCompound);
        NBTTagList var2 = par1NBTTagCompound.getTagList("Items");
        this.furnaceItemStacks = new ItemStack[this.getSizeInventory()];

        for (int var3 = 0; var3 < var2.tagCount(); ++var3)
        {
            NBTTagCompound var4 = (NBTTagCompound)var2.tagAt(var3);
            byte var5 = var4.getByte("Slot");

            if (var5 >= 0 && var5 < this.furnaceItemStacks.length)
            {
                this.furnaceItemStacks[var5] = ItemStack.loadItemStackFromNBT(var4);
            }
        }
    }

    /**
     * Writes a tile entity to NBT.
     */
    public void writeToNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.writeToNBT(par1NBTTagCompound);
        NBTTagList var2 = new NBTTagList();

        for (int var3 = 0; var3 < this.furnaceItemStacks.length; ++var3)
        {
            if (this.furnaceItemStacks[var3] != null)
            {
                NBTTagCompound var4 = new NBTTagCompound();
                var4.setByte("Slot", (byte)var3);
                this.furnaceItemStacks[var3].writeToNBT(var4);
                var2.appendTag(var4);
            }
        }

        par1NBTTagCompound.setTag("Items", var2);
    }

    /**
     * Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended. *Isn't
     * this more of a set than a get?*
     */
    public int getInventoryStackLimit()
    {
        return 64;
    }
    

    public void updateEntity(){
    }
    /**
     * Do not make give this method the name canInteractWith because it clashes with Container
     */
    public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer)
    {
        return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : par1EntityPlayer.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D;
    }

    public void openChest() {}

    public void closeChest() {}

    @Override
    public int getStartInventorySide(ForgeDirection side)
    {
        if (side == ForgeDirection.DOWN) return 1;
        if (side == ForgeDirection.UP) return 0; 
        return 2;
    }

    @Override
    public int getSizeInventorySide(ForgeDirection side)
    {
        return 1;
    }
}

 

Gui:

package rocketengineering.common;

import net.minecraft.src.GuiContainer;
import net.minecraft.src.IInventory;
import net.minecraft.src.InventoryPlayer;
import net.minecraft.src.StatCollector;

import org.lwjgl.opengl.GL11;

public class GuiRocketAssembly extends GuiContainer
{
    private TileEntityRocketAssembly assemblyInventory;

    public GuiRocketAssembly(InventoryPlayer par1InventoryPlayer, TileEntityRocketAssembly par2TileEntityRocketAssembly)
    {
        super(new ContainerRocketAssembly(par1InventoryPlayer, par2TileEntityRocketAssembly));
        this.assemblyInventory = par2TileEntityRocketAssembly;
    }
    
    public static GuiRocketAssembly buildGUI(InventoryPlayer playerInventory, TileEntityRocketAssembly assemblyInventory) {
	return new GuiRocketAssembly(playerInventory, assemblyInventory);
}
    /**
     * Draw the foreground layer for the GuiContainer (everythin in front of the items)
     */
    protected void drawGuiContainerForegroundLayer()
    {
    	this.fontRenderer.drawString(StatCollector.translateToLocal("Rocket Assembly"), 30, 6, 4210752);
        this.fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
    }

    /**
     * Draw the background layer for the GuiContainer (everything behind the items)
     */
    protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
    {
    	drawDefaultBackground();
        int var4 = this.mc.renderEngine.getTexture("/rocketengineering/resources/gui/rocketAssembly.png");
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.mc.renderEngine.bindTexture(var4);
        int var5 = (this.width - this.xSize) / 2;
        int var6 = (this.height - this.ySize) / 2;
        this.drawTexturedModalRect(var5, var6, 0, 0, this.xSize, this.ySize);
        int var7;
    }
}

 

Container:

package rocketengineering.common;

import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;
import java.util.Iterator;
import net.minecraft.src.Container;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.ICrafting;
import net.minecraft.src.InventoryPlayer;
import net.minecraft.src.ItemStack;
import net.minecraft.src.Slot;

public class ContainerRocketAssembly extends Container
{
    private TileEntityRocketAssembly assembly;
    private int lastCookTime = 0;
    private int lastBurnTime = 0;
    private int lastItemBurnTime = 0;

    public ContainerRocketAssembly(InventoryPlayer par1InventoryPlayer, TileEntityRocketAssembly par2)
    {
        this.assembly = par2;
        this.addSlotToContainer(new Slot(par2, 0, 26, 55));
        this.addSlotToContainer(new Slot(par2, 0, 26, 35));
        this.addSlotToContainer(new Slot(par2, 0, 26, 15));
        int var3;

        for (var3 = 0; var3 < 3; ++var3)
        {
            for (int var4 = 0; var4 < 9; ++var4)
            {
                this.addSlotToContainer(new Slot(par1InventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18));
            }
        }

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

    public void addCraftingToCrafters(ICrafting par1ICrafting)
    {
        super.addCraftingToCrafters(par1ICrafting);
    }

    /**
     * Updates crafting matrix; called from onCraftMatrixChanged. Args: none
     */
    public void updateCraftingResults()
    {
        super.updateCraftingResults();
    }

    public boolean canInteractWith(EntityPlayer par1EntityPlayer)
    {
        return this.assembly.isUseableByPlayer(par1EntityPlayer);
    }

    /**
     * Called to transfer a stack from one inventory to the other eg. when shift clicking.
     */
    public ItemStack transferStackInSlot(int par1)
    {
        ItemStack var2 = null;
        return var2;
    }
}

 

I really hope someone can help me with this issue because i have been trying to solve it for quite a while now but nothing i tried seemed to work.

Link to comment
Share on other sites

From a quick glance:

 

You are only opening your GUI on one side.

 

The correct call for opening GUIs is FMLNetworkHandler.openGui(EntityPlayer player, <mod_class> mod.instance, int GuiID, World world, int x, int y,int  z);

 

It must be called both client AND server side simultaneously (or as close as possible) in order for the GUIs to open, and the server to be aware of what GUI you are interacting with (populate the proper containers for both client/server side).

 

So..in your block class..change

 

public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9){
	if(!par1World.isRemote){
		return true;
	}
	Object obj = (TileEntityRocketAssembly)par1World.getBlockTileEntity(par2, par3, par4);
	//ModLoader.openGUI(par5EntityPlayer, new GuiRocketAssembly(par5EntityPlayer.inventory, (TileEntityRocketAssembly)(obj)));
	par5EntityPlayer.openGui((Object)BaseRocketEngineering.instance, 0, par1World, par2, par3, par4);
	return true;
}

 

 

to:

 

public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
  {
  TileEntityRocketAssembly obj = (TileEntityRocketAssembly)par1World.getBlockTileEntity(par2, par3, par4);
  if(obj!=null)
    {
    FMLNetworkHandler.openGui(par5EntityPlayer, BaseRocketEngineering.instance, 0, par1World, par2, par3, par4);
    }
  return true;
  }

 

 

Hope that helps.

 

I recently fought with this issue myself with multiple different GUIs.  Now--I think I've a pretty good idea on whats going on.

 

Shadowmage

 

Link to comment
Share on other sites

i don't know what i'm doing wrong, when i open the gui, it says ""my tile entity class is missing a mapping, this is a bug"...

 

You need to register your TileEntity using GameRegistry.registerTileEntity(par1TileEntity) somewhere. Not sure about the method name/place, but you should be able to find it somewhere.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • https://drive.google.com/file/d/1fPISu1m5Ica8CKDWj3PWVYPNgn85w2dk/view?usp=drive_link
    • @TileEntity no, the problem must be somewhere else, yes, we know that it eats a lot of frames, but it must be caused by something else, probably a mod or something, because for the first 10 days I played this modpack without problems on 4gb of ram, no problem, 200 fps, suddenly now when I start minecraft, minecraft runs for the first 2 minutes to 200 fps and suddenly the frame starts to be stretched very much. I assigned 8, then 12, then 16, and 24 gb of ram is just one amount. I always assign it after a different time, usually within 5 minutes, the game crashes due to lack of frame. the problem must be somewhere else, not only in the frame but in some mode or something strange, but it worked for me before and it works normally for my friends.
    • If you are using AMD/ATI, get the latest drivers from their website - do not update via system
    • So I don't have any other mods and I try to install my first mod. At first I tried turning on Forge but it didn't work for me. I entered into these logs and this is what debug I found.   [05maj2024 19:29:16.383] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--username, kod00, --version, 1.20.1-forge-47.2.30, --gameDir, C:\Users\Tadeusz\AppData\Roaming\.minecraft, --assetsDir, C:\Users\Tadeusz\AppData\Roaming\.minecraft\assets, --assetIndex, 5, --uuid, 0b6cb7d0d9794ea3995565e2c9e6961f, --accessToken, ????????, --clientId, ZmVhZDQ5MDEtODA2ZC00OTZhLTg1NWEtNDAzYzhmZGVhYzAx, --xuid, 2535448611541717, --userType, msa, --versionType, release, --quickPlayPath, C:\Users\Tadeusz\AppData\Roaming\.minecraft\quickPlay\java\1714930153126.json, --launchTarget, forgeclient, --fml.forgeVersion, 47.2.30, --fml.mcVersion, 1.20.1, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20230612.114412] [05maj2024 19:29:16.393] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 10.0.9+10.0. 9+main.dcd20f30 starting: java version 17.0.8 by Microsoft; OS Windows 10 arch amd64 version 10.0 [05maj2024 19:29:16.557] [main/INFO] [net.minecraftforge.fml.loading.ImmediateWindowHandler/]: Loading ImmediateWindowProvider fmlearlywindow [05maj2024 19:29:16.668] [main/INFO] [EARLYDISPLAY/]: Trying GL version 4.6   -------------------------------------------------------------   [05maj2024 19:29:16.383] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--username, kod00, --version, 1.20.1-forge-47.2.30, --gameDir, C:\Users\Tadeusz\AppData\Roaming\.minecraft, --assetsDir, C:\Users\Tadeusz\AppData\Roaming\.minecraft\assets, --assetIndex, 5, --uuid, 0b6cb7d0d9794ea3995565e2c9e6961f, --accessToken, ????????, --clientId, ZmVhZDQ5MDEtODA2ZC00OTZhLTg1NWEtNDAzYzhmZGVhYzAx, --xuid, 2535448611541717, --userType, msa, --versionType, release, --quickPlayPath, C:\Users\Tadeusz\AppData\Roaming\.minecraft\quickPlay\java\1714930153126.json, --launchTarget, forgeclient, --fml.forgeVersion, 47.2.30, --fml.mcVersion, 1.20.1, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20230612.114412] [05maj2024 19:29:16.393] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 10.0.9+10.0.9+main.dcd20f30 starting: java version 17.0.8 by Microsoft; OS Windows 10 arch amd64 version 10.0 [05maj2024 19:29:16.428] [main/DEBUG] [cpw.mods.modlauncher.LaunchServiceHandler/MODLAUNCHER]: Found launch services [fmlclientdev,forgeclient,minecraft,forgegametestserverdev,fmlserveruserdev,fmlclient,fmldatauserdev,forgeserverdev,forgeserveruserdev,forgeclientdev,forgeclientuserdev,forgeserver,forgedatadev,fmlserver,fmlclientuserdev,fmlserverdev,forgedatauserdev,testharness,forgegametestserveruserdev] [05maj2024 19:29:16.448] [main/DEBUG] [cpw.mods.modlauncher.NameMappingServiceHandler/MODLAUNCHER]: Found naming services : [srgtomcp] [05maj2024 19:29:16.468] [main/DEBUG] [cpw.mods.modlauncher.LaunchPluginHandler/MODLAUNCHER]: Found launch plugins: [mixin,eventbus,slf4jfixer,object_holder_definalize,runtime_enum_extender,capability_token_subclass,accesstransformer,runtimedistcleaner] [05maj2024 19:29:16.485] [main/DEBUG] [cpw.mods.modlauncher.TransformationServicesHandler/MODLAUNCHER]: Discovering transformation services [05maj2024 19:29:16.495] [main/DEBUG] [net.minecraftforge.fml.loading.FMLPaths/CORE]: Path GAMEDIR is C:\Users\Tadeusz\AppData\Roaming\.minecraft [05maj2024 19:29:16.495] [main/DEBUG] [net.minecraftforge.fml.loading.FMLPaths/CORE]: Path MODSDIR is C:\Users\Tadeusz\AppData\Roaming\.minecraft\mods [05maj2024 19:29:16.495] [main/DEBUG] [net.minecraftforge.fml.loading.FMLPaths/CORE]: Path CONFIGDIR is C:\Users\Tadeusz\AppData\Roaming\.minecraft\config [05maj2024 19:29:16.495] [main/DEBUG] [net.minecraftforge.fml.loading.FMLPaths/CORE]: Path FMLCONFIG is C:\Users\Tadeusz\AppData\Roaming\.minecraft\config\fml.toml [05maj2024 19:29:16.550] [main/DEBUG] [cpw.mods.modlauncher.TransformationServicesHandler/MODLAUNCHER]: Found additional transformation services from discovery services:  [05maj2024 19:29:16.557] [main/INFO] [net.minecraftforge.fml.loading.ImmediateWindowHandler/]: Loading ImmediateWindowProvider fmlearlywindow [05maj2024 19:29:16.668] [main/INFO] [EARLYDISPLAY/]: Trying GL version 4.6   Can you help me with this?
  • Topics

×
×
  • Create New...

Important Information

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