Jump to content

Recommended Posts

Posted

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.

Posted

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

 

Posted

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.

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.