Jump to content

Custom Inventory not working correctly


Kwibble

Recommended Posts

I have been trying to implement my own custom inventory, and lets just say the results aren't very satisfactory. I am displaying the inventory and everything is there correctly. Then I try and move an item. Nothing happens. I have all the flags (I think) that I need to call saying that the player can interact with the inventory.

 

So without further ka fluffle.

 

GuiDendrikBeltInventory:

package com.kwibble.dendri.client.gui.inventory;

import com.kwibble.dendri.ModuleDendri;
import com.kwibble.dendri.inventory.ContainerDendrikBeltInventory;
import com.kwibble.dendri.entity.dendri.EntityDendri;
import com.kwibble.dendri.entity.player.PlayerInformation;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

public class GuiDendrikBeltInventory extends GuiContainer
{
/**
 * x size of the inventory window in pixels. Defined as  float, passed as int
 */
private float xSizeFloat;
/**
 * y size of the inventory window in pixels. Defined as  float, passed as int.
 */
private float ySizeFloat;

private ResourceLocation tab_main, tab_dendri;

private PlayerInformation playerinfo;

public GuiDendrikBeltInventory(EntityPlayer player, PlayerInformation playerinfo)
{
	super(new ContainerDendrikBeltInventory(player.inventory, player));
	this.allowUserInput = true;

	this.playerinfo = playerinfo;
	this.tab_main = new ResourceLocation(ModuleDendri.MODID, "textures/gui/dendrikbeltinventory/tab_main.png");
	this.tab_dendri = new ResourceLocation(ModuleDendri.MODID, "textures/gui/dendrikbeltinventory/tab_dendri.png");
}

@Override
public void initGui()
{
	this.buttonList.clear();

	super.initGui();
}

@Override
public void drawScreen(int par1, int par2, float par3)
{
	super.drawScreen(par1, par2, par3);
	this.xSizeFloat = (float)par1;
	this.ySizeFloat = (float)par2;
}

@Override
protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_)
{
	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
	this.mc.getTextureManager().bindTexture(this.tab_main);
	int k = this.guiLeft;
	int l = this.guiTop;
	this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
	func_147046_a(k + 34, l + 75, 30, (float)(k + 34) - this.xSizeFloat, (float)(l + 75 - 50) - this.ySizeFloat, this.mc.thePlayer);
}

public static void func_147046_a(int p_147046_0_, int p_147046_1_, int p_147046_2_, float p_147046_3_, float p_147046_4_, EntityLivingBase p_147046_5_)
{
	GL11.glEnable(GL11.GL_COLOR_MATERIAL);
	GL11.glPushMatrix();
	GL11.glTranslatef((float)p_147046_0_, (float)p_147046_1_, 50.0F);
	GL11.glScalef((float)(-p_147046_2_), (float)p_147046_2_, (float)p_147046_2_);
	GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
	float f2 = p_147046_5_.renderYawOffset;
	float f3 = p_147046_5_.rotationYaw;
	float f4 = p_147046_5_.rotationPitch;
	float f5 = p_147046_5_.prevRotationYawHead;
	float f6 = p_147046_5_.rotationYawHead;
	GL11.glRotatef(135.0F, 0.0F, 1.0F, 0.0F);
	RenderHelper.enableStandardItemLighting();
	GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F);
	GL11.glRotatef(-((float)Math.atan((double)(p_147046_4_ / 40.0F))) * 20.0F, 1.0F, 0.0F, 0.0F);
	p_147046_5_.renderYawOffset = (float)Math.atan((double)(p_147046_3_ / 40.0F)) * 20.0F;
	p_147046_5_.rotationYaw = (float)Math.atan((double)(p_147046_3_ / 40.0F)) * 40.0F;
	p_147046_5_.rotationPitch = -((float)Math.atan((double)(p_147046_4_ / 40.0F))) * 20.0F;
	p_147046_5_.rotationYawHead = p_147046_5_.rotationYaw;
	p_147046_5_.prevRotationYawHead = p_147046_5_.rotationYaw;
	GL11.glTranslatef(0.0F, p_147046_5_.yOffset, 0.0F);
	RenderManager.instance.playerViewY = 180.0F;
	RenderManager.instance.renderEntityWithPosYaw(p_147046_5_, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F);
	p_147046_5_.renderYawOffset = f2;
	p_147046_5_.rotationYaw = f3;
	p_147046_5_.rotationPitch = f4;
	p_147046_5_.prevRotationYawHead = f5;
	p_147046_5_.rotationYawHead = f6;
	GL11.glPopMatrix();
	RenderHelper.disableStandardItemLighting();
	GL11.glDisable(GL12.GL_RESCALE_NORMAL);
	OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
	GL11.glDisable(GL11.GL_TEXTURE_2D);
	OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
}
}

 

ContainerDendrikBeltInventory:

package com.kwibble.dendri.inventory;

import com.kwibble.dendri.entity.player.PlayerInformation;
import com.kwibble.dendri.network.DendriNetwork;
import com.kwibble.dendri.network.message.MessageClientPlayerInfo;
import com.kwibble.dendri.network.message.MessageServerRequestPlayerInfo;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;

/**
* Created by Kwibble on 25/06/14.
*/
public class ContainerDendrikBeltInventory extends Container
{
private static final int INV_START = 3, INV_END = INV_START+26, HOTBAR_START = INV_END+1, HOTBAR_END = HOTBAR_START+8;
public ContainerDendrikBeltInventory(final InventoryPlayer inventoryPlayer, final EntityPlayer player)
{
	PlayerInformation playerinfo = PlayerInformation.forPlayer(player);
	if (!player.worldObj.isRemote)
		DendriNetwork.dendriNetwork.sendTo(new MessageClientPlayerInfo(playerinfo), ( EntityPlayerMP ) player);
	int i;
	int j;

	this.addSlotToContainer(new SlotDendrikBelt(playerinfo, 0, 62, );

	for (i = 0; i < 4; ++i)
	{
		int x = 27;
		int y = 0;
		if (i > 0)
		{
			x = 28;
			y = 1;
		}
		this.addSlotToContainer(new SlotMistBottle(playerinfo.getInventoryDendrikBelt(), 1 + i, 68 + (i * x) - y, 45));
	}

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

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

@Override
public boolean canInteractWith(EntityPlayer player)
{
	return true;
}

/**
 * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
 */
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 < INV_START)
		{
			if (!this.mergeItemStack(itemstack1, INV_START, HOTBAR_END + 1, true))
			{
				return null;
			}

			slot.onSlotChange(itemstack1, itemstack);
		}
		else
		{
			if (par2 >= INV_START && par2 < HOTBAR_START)
			{

				if (!this.mergeItemStack(itemstack1, HOTBAR_START, HOTBAR_END + 1, false))
				{
					return null;
				}
			}

			else if (par2 >= HOTBAR_START && par2 < HOTBAR_END + 1)
			{
				if (!this.mergeItemStack(itemstack1, INV_START, INV_END + 1, 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;
}
}

 

InventoryDendrikBelt:

package com.kwibble.dendri.inventory;

import com.kwibble.dendri.item.ItemDendrikBelt;
import com.kwibble.dendri.network.DendriNetwork;
import com.kwibble.dendri.network.message.MessageServerRequestPlayerInfo;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;

/**
* Created by Kwibble on 25/06/14.
*/
public class InventoryDendrikBelt implements IInventory
{
public ItemStack[] mainInventory = new ItemStack[1];

public void setCurrentDendrikBelt(ItemStack par1ItemStack)
{
	this.mainInventory[0] = par1ItemStack;
}

public Item getCurrentDendrikBelt()
{
	return this.mainInventory[0] != null ? this.mainInventory[0].getItem() : new ItemStack(Blocks.stone).getItem();
}

/**
 * Returns the stack in slot i
 *
 * @param slot
 */
@Override
public ItemStack getStackInSlot(int slot) {
	if (slot > 0) return null;
	return this.mainInventory[slot];
}

/**
 * Removes from an inventory slot (first arg) up to a specified number (second arg) of items and returns them in a
 * new stack.
 *
 * @param slot
 * @param amount
 */
@Override
public ItemStack decrStackSize(int slot, int amount) {
	ItemStack stack = getStackInSlot(slot);

	if (stack != null){

		if (stack.stackSize > amount){
			stack = stack.splitStack(amount);

			if (stack.stackSize == 0){
				setInventorySlotContents(slot, null);
			}
		} else {
			setInventorySlotContents(slot, null);
		}
		this.markDirty();
	}

	return stack;
}

/**
 * When some containers are closed they call this on each slot, then drop whatever it returns as an EntityItem -
 * like when you close a workbench GUI.
 *
 * @param par1
 */
@Override
public ItemStack getStackInSlotOnClosing(int par1)
{
	return null;
}

/**
 * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
 *
 * @param slotID
 * @param itemstack
 */
@Override
public void setInventorySlotContents(int slotID, ItemStack itemstack) {
	this.mainInventory[slotID] = itemstack;

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

	this.markDirty();
}

/**
 * Returns the name of the inventory
 */
@Override
public String getInventoryName()
{
	return "dendrikbeltinventory";
}

/**
 * Returns if the inventory is named
 */
@Override
public boolean hasCustomInventoryName()
{
	return true;
}

/**
 * Returns the maximum stack size for a inventory slot.
 */
@Override
public int getInventoryStackLimit()
{
	return 1;
}

/**
 * For tile entities, ensures the chunk containing the tile entity is saved to disk later - the game won't think it
 * hasn't changed and skip it.
 */
@Override
public void markDirty()
{
	// Something is supposed to go here... 
}

/**
 * Do not make give this method the name canInteractWith because it clashes with Container
 *
 * @param par1EntityPlayer
 */
@Override
public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer)
{
	return true;
}

@Override
public void openInventory()
{}

@Override
public void closeInventory()
{}

/**
 * Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot.
 *
 * @param slotID
 * @param par2ItemStack
 */
@Override
public boolean isItemValidForSlot(int slotID, ItemStack par2ItemStack)
{
	return (slotID == 0 && par2ItemStack.getItem() instanceof ItemDendrikBelt);
}

/**
 * Returns the number of slots in the inventory.
 */
@Override
public int getSizeInventory()
{
	return this.mainInventory.length;
}

public void writeToNBT(NBTTagCompound nbt)
{
	Item item = this.getCurrentDendrikBelt();
	if (item instanceof ItemDendrikBelt)
	{
		((ItemDendrikBelt) this.getCurrentDendrikBelt()).saveDendrikBeltStorage(nbt);
	}
}

public void readFromNBT(NBTTagCompound nbt)
{
	if (this.getCurrentDendrikBelt() instanceof ItemDendrikBelt)
		((ItemDendrikBelt) this.getCurrentDendrikBelt()).loadDendrikBeltStorage(nbt);
}
}

 

SlotDendrikBelt:

package com.kwibble.dendri.inventory;

import com.kwibble.dendri.ModuleDendri;
import com.kwibble.dendri.entity.player.PlayerInformation;
import com.kwibble.dendri.item.ItemDendrikBelt;
import com.kwibble.dendri.network.DendriNetwork;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;

/**
* Created by Kwibble on 25/06/14.
*/
public class SlotDendrikBelt extends Slot
{
private PlayerInformation playerinfo;

private final ResourceLocation backgroundIcon = new ResourceLocation(ModuleDendri.MODID, "textures/items/master_dendrik_belt.png");

public SlotDendrikBelt(PlayerInformation playerinfo, int par2, int par3, int par4)
{
	super(playerinfo.getInventoryDendrikBelt(), par2, par3, par4);
	this.inventory.setInventorySlotContents(0, new ItemStack(playerinfo.getCurrentDendrikBelt()));

	this.playerinfo = playerinfo;
}

/**
 * Helper method to put a stack in the slot.
 *
 * @param par1ItemStack
 */
@Override
public void putStack(ItemStack par1ItemStack)
{
	super.putStack(par1ItemStack);
}

/**
 * Check if the stack is a valid item for this slot. Always true beside for the armor slots.
 *
 * @param par1ItemStack
 */
@Override
public boolean isItemValid(ItemStack par1ItemStack)
{
	return (par1ItemStack.getItem() instanceof ItemDendrikBelt);
}
}

 

SlotMistBottle:

package com.kwibble.dendri.inventory;

import com.kwibble.dendri.ModuleDendri;
import com.kwibble.dendri.item.ItemMistBottle;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;

/**
* Created by Kwibble on 25/06/14.
*/
public class SlotMistBottle extends Slot
{
public SlotMistBottle(InventoryDendrikBelt inventoryDendrikBelt, int par2, int par3, int par4)
{
	super(inventoryDendrikBelt, par2, par3, par4);
	this.setBackgroundIconTexture(new ResourceLocation(ModuleDendri.MODID, "textures/items/master_dendrik_belt.png"));
}

/**
 * Helper method to put a stack in the slot.
 *
 * @param par1ItemStack
 */
@Override
public void putStack(ItemStack par1ItemStack)
{
	super.putStack(par1ItemStack);
}

/**
 * Check if the stack is a valid item for this slot. Always true beside for the armor slots.
 *
 * @param par1ItemStack
 */
@Override
public boolean isItemValid(ItemStack par1ItemStack)
{
	return (par1ItemStack.getItem() instanceof ItemMistBottle);
}
}

 

 

And if you need where I am saving my inventory... Here it is in my PlayerInformation (IExtendedEntityProperties):

package com.kwibble.dendri.entity.player;

import com.kwibble.dendri.ModuleDendri;
import com.kwibble.dendri.inventory.InventoryDendrikBelt;
import com.kwibble.dendri.item.ItemDendrikBelt;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import net.minecraftforge.common.IExtendedEntityProperties;

public class PlayerInformation implements IExtendedEntityProperties
{
public static final String IDENTIFIER = ModuleDendri.MODID + "_playerProperties";

private static final String SHOULD_DISPLAY_OVERLAY_IDENTIFIER = IDENTIFIER + "_shouldDisplayOverlay";
private static final String IS_OVERLAY_MINIMIZED_IDENTIFIER = IDENTIFIER + "_isOverlayMinimized";
private static final String CURRENT_DENDRIK_BELT_IDENTIFIER = IDENTIFIER + "_currentDendrikbelt";

public static PlayerInformation forPlayer(Entity player)
{
	return (PlayerInformation) player.getExtendedProperties(IDENTIFIER);
}

private EntityPlayer player;

private boolean isOverlayMinimized;

private boolean shouldDisplayOverlay;

private InventoryDendrikBelt inventoryDendrikBelt = new InventoryDendrikBelt();

public PlayerInformation(EntityPlayer player)
{
	this.player = player;
}

@Override
public void init(Entity entity, World world)
{

}

@Override
public void saveNBTData(NBTTagCompound nbt)
{
	if (this.getCurrentDendrikBelt() == null)
	{
		this.setShouldDisplayOverlay(false);
	}

	NBTTagCompound compound = new NBTTagCompound();
	System.out.println("Saving NBT Data:");
	compound.setBoolean(IS_OVERLAY_MINIMIZED_IDENTIFIER, this.isOverlayMinimized);
	System.out.println("Saved isOverlayMinimized with value of: " + this.isOverlayMinimized);
	compound.setBoolean(SHOULD_DISPLAY_OVERLAY_IDENTIFIER, this.shouldDisplayOverlay);
	System.out.println("Saved shouldDisplayOverlay with value of: " + this.shouldDisplayOverlay);
	this.inventoryDendrikBelt.writeToNBT(compound);
	System.out.println("Saved currentDendrikBelt with value of: " + this.getCurrentDendrikBelt());
	System.out.println("NBT Data Saved");
	nbt.setTag(IDENTIFIER, compound);
}

@Override
public void loadNBTData(NBTTagCompound nbt)
{
	NBTTagCompound compound = nbt.getCompoundTag(IDENTIFIER);
	System.out.println("Loading NBT Data:");
	this.isOverlayMinimized = compound.getBoolean(IS_OVERLAY_MINIMIZED_IDENTIFIER);
	System.out.println("Loaded isOverlayMinimized with value of: " + this.isOverlayMinimized);
	this.shouldDisplayOverlay = compound.getBoolean(SHOULD_DISPLAY_OVERLAY_IDENTIFIER);
	System.out.println("Loaded shouldDisplayOverlay with value of: " + this.shouldDisplayOverlay);
	this.inventoryDendrikBelt.readFromNBT(compound);
	System.out.println("Loaded currentDendrikBelt with value of: " + this.getCurrentDendrikBelt());
	System.out.println("Loaded NBT Data");

	if (this.getCurrentDendrikBelt() == null)
	{
		this.setShouldDisplayOverlay(false);
	}
}

public void setCurrentDendrikBelt(Item belt)
{
	if (belt instanceof ItemDendrikBelt)
		this.inventoryDendrikBelt.setCurrentDendrikBelt(new ItemStack(belt));
	else
		System.out.println("A Dendrik Belt was not passed in");
}

public Item getCurrentDendrikBelt()
{
	return this.inventoryDendrikBelt.getCurrentDendrikBelt();
}

public void setIsOverlayMinimized(boolean isOverlayMinimized)
{
	this.isOverlayMinimized = isOverlayMinimized;
}

public boolean getIsOverlayMinimized()
{
	return this.isOverlayMinimized;
}

public void setShouldDisplayOverlay(boolean shouldDisplayOverlay)
{
	this.shouldDisplayOverlay = shouldDisplayOverlay;
}

public boolean getShouldDisplayOverlay()
{
	return this.shouldDisplayOverlay;
}

public InventoryDendrikBelt getInventoryDendrikBelt()
{
	return this.inventoryDendrikBelt;
}
}

 

 

Any and all help is appreciated, thanks!

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Link to comment
Share on other sites

Well... In case I haven't explained the problem well enough:

 

By nothing happens I mean that I click on an item and it gets put right back in the slot I picked it up from. It sounds like I haven't called all the right flags. So I have no idea what the issue is.

 

Any help it's appreciated.

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Link to comment
Share on other sites

That would be in my CommonProxy... When you say keep the client/server in sync, I am not sending packets anywhere. Only to open the GUI. How do I keep it in sync?

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Link to comment
Share on other sites

If you have your Handler setup right, it does it all for you.  If you don't, wierd thing happen like you are describing.  If you are only registering it on your CommonProxy (depending on your setup), that makes me think you are only registering it on your server side.

 

Anyhow, if you have it registered, you have it opened on your serverside and everything happens on client/server seemlessly.  If you try to open it on the client and server manually or with something not quite right, it does wierd stuff.

 

There are tutorials on this if my rambling doesn't help.

 

I don't have access to any of my new stuff from work, but if this doesn't help you, I can post somethign else tonight.  This is my handler class.  Don't pay attention to the horrible coding, this was from years ago. 

 

 

 

public class MyGuiHandler implements IGuiHandler {

 

// Setup Variables

WW_Zombie instance = WW_Zombie.instance;

boolean key_memory = false;

boolean flip = false;

 

public MyFurnace myfurnace;

 

@Override

public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {

 

//instance.logger.log(Level.INFO, "[MyGuiHandler]" + "[GetServerGuiElement]" + " : " + "initialize at side " + FMLCommonHandler.instance().getSide());

//instance.logger.log(Level.INFO, "[MyGuiHandler]" + "[GetServerGuiElement]" + " : " + "Initialize for type " + ID);

 

if (ID == 0) {

return new MyContainer(player);

} else if (ID == 1) {

TileEntity tileEntity = world.getBlockTileEntity(x, y, z);

        if(tileEntity instanceof FirePit_Tile){

        return new FirePit_Container(player.inventory, (FirePit_Tile) tileEntity);

        }

} else if (ID == 2) {

TileEntity tileEntity = world.getBlockTileEntity(x, y, z);

        if(tileEntity instanceof Tent_Tile){

        //instance.logger.log(Level.INFO, "[MyGuiHandler]" + "[GetServerGuiElement]" + " : " + "  Pass");

        return new Tent_Container(player, (Tent_Tile) tileEntity);

        }

}

//default case

//instance.logger.log(Level.INFO, "[MyGuiHandler]" + "[GetServerGuiElement]" + " : " + "  Fail");

return null;

 

}

 

@Override

public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {

 

//instance.logger.log(Level.INFO, "[MyGuiHandler]" + "[GetClientGuiElement]" + " : " + "initialize at side " + FMLCommonHandler.instance().getSide());

//instance.logger.log(Level.INFO, "[MyGuiHandler]" + "[GetClientGuiElement]" + " : " + "Initialize for type " + ID);

 

if (ID == 0) {

return new MyInventory(new MyContainer(player));

} else if (ID == 1) {

TileEntity tileEntity = world.getBlockTileEntity(x, y, z);

        if(tileEntity instanceof FirePit_Tile){

        myfurnace = new MyFurnace(player.inventory, (FirePit_Tile) tileEntity);

                return myfurnace;

        }

} else if (ID == 2) {

TileEntity tileEntity = world.getBlockTileEntity(x, y, z);

        if(tileEntity instanceof Tent_Tile){

        //instance.logger.log(Level.INFO, "[MyGuiHandler]" + "[GetClientGuiElement]" + " : " + "  Pass");

        return new Tent_GUI(player, (Tent_Tile) tileEntity);

        }

}

//default case

//instance.logger.log(Level.INFO, "[MyGuiHandler]" + "[GetClientGuiElement]" + " : " + "  Fail");

return null;

 

}

 

 

 

 

 

 

In your main class for the FMLInitializationEvent, you register it.

 

NetworkRegistry.INSTANCE.registerGuiHandler(this, myguihandler);

 

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

Well...

:/

 

Here is my common proxy:

package com.kwibble.dendri;

import com.kwibble.dendri.block.BlockDendri;
import com.kwibble.dendri.client.gui.EnumGui;
import com.kwibble.dendri.client.gui.inventory.GuiDendrikBeltInventory;
import com.kwibble.dendri.entity.dendri.DendriRegistry;
import com.kwibble.dendri.entity.player.PlayerInformation;
import com.kwibble.dendri.handlers.DendriExperienceHandler;
import com.kwibble.dendri.handlers.GenericEventHandler;
import com.kwibble.dendri.inventory.ContainerDendrikBeltInventory;
import com.kwibble.dendri.item.ItemDendri;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;

public class CommonProxy implements IGuiHandler
{
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
	if (ID == EnumGui.DENDRIK_BELT_INVENTORY.getGuiID())
		return new ContainerDendrikBeltInventory(player.inventory, player);

	return null;
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
	PlayerInformation playerinfo = PlayerInformation.forPlayer(player);
	if (ID == EnumGui.DENDRIK_BELT_INVENTORY.getGuiID())
		return new GuiDendrikBeltInventory(player, playerinfo);

	return null;
}

public void initializeMod()
{
	BlockDendri.registerBlocks();
	ItemDendri.registerItems();

	registerEvents();

	registerEntities();
	registerRenders();

	registerKeyBindings();
}

protected void registerEvents()
{
	MinecraftForge.EVENT_BUS.register(new DendriExperienceHandler());
	MinecraftForge.EVENT_BUS.register(new GenericEventHandler());
}

private void registerEntities()
{
	DendriRegistry.registerAllDendri();
	registerTileEntities();
}

/*
 * Actual functionality in ClientProxy
 */
public void registerRenders()
{}

/*
 * Actual functionality in ClientProxy
 */
public void registerDendriRender(Class<? extends Entity> dendriClass, Render dendriRender)
{}

/*
 * Actual functionality in ClientProxy
 */
protected void registerMobEntityRenders()
{}

/*
 * Actual functionality in ClientProxy
 */
protected void registerTileEntityRenders()
{}

/*
 * Actual functionality in ClientProxy
 */
protected void registerTileEntities()
{}

/*
 * Actual functionality in ClientProxy
 */
protected void registerKeyBindings()
{}

public EntityPlayer getPlayerFromMessageContext(MessageContext ctx)
{
	return ctx.getServerHandler().playerEntity;
}

public EntityPlayer getPlayer(String username)
{
	return MinecraftServer.getServer().getConfigurationManager().getPlayerForUsername(username);
}

public GuiScreen getCurrentScreen()
{
	return null;
}
}

 

Here is my mod file:

package com.kwibble.dendri;

import com.kwibble.dendri.network.DendriNetwork;
import cpw.mods.fml.common.Mod;
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;

import java.util.ArrayList;
import java.util.List;

@Mod (modid = ModuleDendri.MODID, name = ModuleDendri.NAME, version = ModuleDendri.VERSION)
public class ModuleDendri
{
public static final String NAME = "Dendri";
public static final String MODID = "dendri";
public static final String VERSION = "1.7.2_0.0.1";

@Instance (ModuleDendri.MODID)
public static ModuleDendri instance;

@SidedProxy (clientSide = "com.kwibble.dendri.client.ClientProxy", serverSide = "com.kwibble.dendri.CommonProxy")
public static CommonProxy proxy;

@Mod.EventHandler
public void on(FMLPreInitializationEvent event)
{
	DendriNetwork.registerNetwork();

	NetworkRegistry.INSTANCE.registerGuiHandler(this, proxy);

	proxy.initializeMod();
}

@Mod.EventHandler
public void on(FMLInitializationEvent event)
{

}

@Mod.EventHandler
public void on(FMLPostInitializationEvent event)
{

}
}

 

I have it being registered pre unit.. Surely that shouldn't make a difference?

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Link to comment
Share on other sites

I've never liked that method of doing this using your Common/Client Proxies, but it is a coding style thing.

 

 

I'm assuming in your client proxy, you are not overriding your get GUI elements.

 

As far as the Pre-Init or Init, I don't think it matters, but move it and see what happens.

 

Lastly, how are you opening the GUI?  Exact details.  Are you sending a packet to the server and that is what is taking action or...

 

 

Also, back to your original post.  When you say nothing, you can't pick it up with the cursor - which slots can't you pickup?  your custom ones, the original player inventory??  If you can pick it up, it isn't saving or it doesn't deposit anywhere?

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

I can't pick it up from ANY slot - custom are generic.

 

No...I don't override it in client proxy. I'll change that and the init bit.

 

I open the GUI via a key bind that calls a packet that opens the GUI:

Here's the packet:

package com.kwibble.dendri.network.message;

import com.kwibble.dendri.ModuleDendri;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;

/**
* Created by Kwibble on 24/06/14.
*/
public class MessageServerRequestGuiOpen implements IMessage
{
private int guiID;

public MessageServerRequestGuiOpen()
{}

public MessageServerRequestGuiOpen(int guiID) {
	this.guiID = guiID;
}

@Override
public void fromBytes(ByteBuf buf)
{
	buf.readInt();
}

@Override
public void toBytes(ByteBuf buf)
{
	buf.writeInt(this.guiID);
}

public static class Handler implements IMessageHandler<MessageServerRequestGuiOpen, IMessage>
{
	@Override
	public IMessage onMessage(MessageServerRequestGuiOpen message, MessageContext ctx)
	{
		EntityPlayer player = ModuleDendri.proxy.getPlayerFromMessageContext(ctx);
		player.openGui(ModuleDendri.instance, message.guiID, player.worldObj, 0, 0, 0);
		return null;
	}
}
}

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Link to comment
Share on other sites

"No...I don't override it in client proxy. I'll change that and the init bit."

 

Hope I didn't mislead, was making sure you were not overriding.  As long as you extend your common to client and don't override, that should be fine.

 

I'm going to go back and re-read your stuff in depth and see if I can spot something I missed last time.

 

In the meanwhile, you might add some preint statements to your custom slot to see when it is called and what it thinks it has in it at the time.  That should be revealing.

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

Some of you are handling where the invenotry is at is going to have issues for saving, but that would cause an issue the next time you open it, not stopping you from clicking on it.

 

Ok, one other thing, are you sure your graphics and your container are lined up right?

 

When you mouse over the item image, doest it color whitish?  have you tried clicking aroudn the screen and seeing if you magically pick up the item from somwether the item isn't?  I've done that before.

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

Yeah, it is all correct. * I think *

 

[EDIT]

Well, I tried moving the registry and that didn't work... Its freaking annoying me.

 

I guess next I will copy-paste vanilla inventory code and see if that works. If it does, then we have a big problem.

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Link to comment
Share on other sites

I just copied the ContainerPlayer code, it worked perfectly fine. So It is somewhere in my code...

 

[EDIT]

I am trying to remove the crafting slots and that seems to break it O.o

 

[EDIT 2]

So I tried leaving the crafting and only removing the armour slots... Still no luck O.o

 

This thing hates me. Even tweaking the vanilla code breaks.

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Link to comment
Share on other sites

What was really weird though -> I could replace the crafting slots with own custom ones without a problem. As soon as I changed their position though... Nope

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Link to comment
Share on other sites

That really sounds like the one theory I had.  I don't think you have the graphics and the slots lined up.

 

When you made your graphic, which minecraft graphic did you start with?  Did you delete the 'extra' space around the sides?

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

I don't know how the graphics could effect the slots O.o

 

But I copied the player inventory. The image size is 256x256 and the actual bit thelat gets rendered is the 176x166 (I think. Whatever it is)

 

So I have no clue... And I don't think the graphic has anything to do with it. I copied the ContainerPlayer code as my container code, my graphic was my custom one and my custom GUI. So I have no clue.

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Link to comment
Share on other sites

So now am I absolutely miffed. What the heck is going wrong? Does diesieben07 have any input that could probably save the day?

 

This is really aggregating me because while there are other ways to do this... This is the best and most user friendly.

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Link to comment
Share on other sites

Ok, this is probably a dumb question.  How do you get the stupid buttons on a post to work?

 

All of a sudden I can't use the insert picture, spoiler, ect buttons.  Makes it really hard to send a PM that won't be annoying as hell.

Long time Bukkit & Forge Programmer

Happy to try and help

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.