Jump to content

Recommended Posts

Posted

When i click on the item and place it into the slot it will place it into the slot but also still have it in my mouse so now there is 2 of the item, and if i shift click into the slot it will still be in the same slot but will be in the slot it is sepost to be in also.. i looked over most of the code and classes but i cannot find the cause of this..

 

 

public class GuiEotInventory extends GuiContainer{

 

private static final ResourceLocation background = new ResourceLocation(References.MODID, "textures/gui/eotInventory.png");

 

private float xSize_lo;

private float ySize_lo;

 

private final InventoryEotInventory inventory;

 

public GuiEotInventory(EntityPlayer player,InventoryPlayer inventoryplayer, InventoryEotInventory holder) {

super(new ContainterEotInventory(player, inventoryplayer, holder));

this.inventory = holder;

}

 

@Override

public void initGui ()

{

super.initGui();

 

int cornerX = guiLeft;

int cornerY = guiTop;

this.buttonList.clear();

 

TabRegistry.updateTabValues(cornerX, cornerY, InventoryTabEot.class);

TabRegistry.addTabsToList(this.buttonList);

}

 

@Override

public void drawScreen (int par1, int par2, float par3){

super.drawScreen(par1, par2, par3);

this.xSize_lo = (float) par1;

this.ySize_lo = (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(background);

int cornerX = guiLeft;

int cornerY = guiTop;

drawTexturedModalRect(cornerX, guiTop, 0, 0, xSize, ySize);

 

cornerX = this.guiLeft;

cornerY = this.guiTop;

drawPlayerOnGui(this.mc, cornerX + 89, cornerY + 75, 30, (float) (cornerX + 51) - this.xSize_lo, (float) (cornerY + 75 - 50) - this.ySize_lo);

}

 

public static void drawPlayerOnGui (Minecraft par0Minecraft, int par1, int par2, int par3, float par4, float par5)

{

GL11.glEnable(GL11.GL_COLOR_MATERIAL);

GL11.glPushMatrix();

GL11.glTranslatef((float) par1, (float) par2, 50.0F);

GL11.glScalef((float) (-par3), (float) par3, (float) par3);

GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);

float f2 = par0Minecraft.thePlayer.renderYawOffset;

float f3 = par0Minecraft.thePlayer.rotationYaw;

float f4 = par0Minecraft.thePlayer.rotationPitch;

par4 -= 19;

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) (par5 / 40.0F))) * 20.0F, 1.0F, 0.0F, 0.0F);

par0Minecraft.thePlayer.renderYawOffset = (float) Math.atan((double) (par4 / 40.0F)) * 20.0F;

par0Minecraft.thePlayer.rotationYaw = (float) Math.atan((double) (par4 / 40.0F)) * 40.0F;

par0Minecraft.thePlayer.rotationPitch = -((float) Math.atan((double) (par5 / 40.0F))) * 20.0F;

par0Minecraft.thePlayer.rotationYawHead = par0Minecraft.thePlayer.rotationYaw;

GL11.glTranslatef(0.0F, par0Minecraft.thePlayer.yOffset, 0.0F);

RenderManager.instance.playerViewY = 180.0F;

RenderManager.instance.renderEntityWithPosYaw(par0Minecraft.thePlayer, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F);

par0Minecraft.thePlayer.renderYawOffset = f2;

par0Minecraft.thePlayer.rotationYaw = f3;

par0Minecraft.thePlayer.rotationPitch = f4;

GL11.glPopMatrix();

RenderHelper.disableStandardItemLighting();

GL11.glDisable(GL12.GL_RESCALE_NORMAL);

OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);

GL11.glDisable(GL11.GL_TEXTURE_2D);

OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);

}

 

}

 

 

 

 

 

public class ContainterEotInventory extends Container{

 

private static final int ARMOR_START = InventoryEotInventory.INV_SIZE,

ARMOR_END = ARMOR_START + 3, INV_START = ARMOR_END + 1,

INV_END = INV_START + 26, HOTBAR_START = INV_END + 1,

HOTBAR_END = HOTBAR_START + 8;

 

public ContainterEotInventory(EntityPlayer player, InventoryPlayer inventoryPlayer, InventoryEotInventory eotInventory) {

int i;

this.addSlotToContainer(new SlotBag(eotInventory, 0, 152, 8));

 

for (i = 0; i < 4; ++i) {

this.addSlotToContainer(new SlotArmor(player, inventoryPlayer,

inventoryPlayer.getSizeInventory() - 1 - i, 44, 8 + i * 18,

i));

}

 

for (i = 0; i < 3; ++i) {

for (int j = 0; j < 9; ++j) {

this.addSlotToContainer(new Slot(inventoryPlayer,

j + i * 9 + 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;

}

 

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 < INV_START){

 

 

if (!this.mergeItemStack(itemstack1, INV_START, HOTBAR_END + 1, true)){

return null;

}

slot.onSlotChange(itemstack1, itemstack);

}else{

 

if (itemstack1.getItem() instanceof ItemTier1Bag){

if (!this.mergeItemStack(itemstack1, 0,InventoryEotInventory.INV_SIZE, false)){

return null;

}

 

}else if (itemstack1.getItem() instanceof ItemArmor){

int type = ((ItemArmor) itemstack1.getItem()).armorType;

if (!this.mergeItemStack(itemstack1, ARMOR_START + type, ARMOR_START + type + 1, false)){

return null;

}

}else if (par2 >= INV_START && par2 < HOTBAR_START){

if (!this.mergeItemStack(itemstack1, HOTBAR_START,HOTBAR_START + 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(player, itemstack1);

}

return itemstack;

}

}

 

 

 

 

public class InventoryEotInventory implements IInventory {

 

private final String name = "Eot Inventory";

public WeakReference<EntityPlayer> parent;

private final String tagName = "eotInvetoryTag";

 

/** Define the inventory size here for easy reference */

 

public static final int INV_SIZE = 1;

 

public static ItemStack[] inventory = new ItemStack[iNV_SIZE];

 

public void init (EntityPlayer player){

parent = new WeakReference<EntityPlayer>(player);

}

 

public InventoryEotInventory(){

}

 

@Override

public int getSizeInventory(){

return inventory.length;

}

 

@Override

public ItemStack getStackInSlot(int slot){

return inventory[slot];

}

 

@Override

public ItemStack decrStackSize(int slot, int amount){

ItemStack stack = getStackInSlot(slot);

if (stack != null) {

if (stack.stackSize > amount) {

stack = stack.splitStack(amount);

markDirty();

} else {

setInventorySlotContents(slot, null);

}

}

 

return stack;

}

 

@Override

public ItemStack getStackInSlotOnClosing(int slot){

ItemStack stack = getStackInSlot(slot);

setInventorySlotContents(slot, null);

return stack;

}

 

@Override

public void setInventorySlotContents(int slot, ItemStack stack) {

inventory[slot] = stack;

if (stack != null && stack.stackSize > getInventoryStackLimit()) {

stack.stackSize = getInventoryStackLimit();

}

markDirty();

}

 

public void onInventoryChanged(){

for (int i = 0; i < this.getSizeInventory(); ++i){

if (this.getStackInSlot(i) != null && this.getStackInSlot(i).stackSize == 0)

this.setInventorySlotContents(i, null);

}

}

 

@Override

public String getInventoryName(){

return name;

}

 

@Override

public boolean hasCustomInventoryName(){

return name.length() > 0;

 

}

 

/**

*

* Our custom slots are similar to armor - only one item per slot

*/

 

@Override

public int getInventoryStackLimit(){

return 1;

}

 

@Override

public boolean isUseableByPlayer(EntityPlayer entityplayer){

return true;

}

 

@Override

public void markDirty() {

for (int i = 0; i < getSizeInventory(); ++i) {

if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0) {

inventory = null;

}

}

}

 

@Override

public void openInventory() {}

 

@Override

public void closeInventory() {}

 

@Override

public boolean isItemValidForSlot(int slot, ItemStack itemstack){

if (slot == 0 && itemstack.getItem() instanceof ItemTier1Bag)return true;

return false;

}

 

public void writeToNBT(NBTTagCompound tagcompound){

NBTTagList nbttaglist = new NBTTagList();

 

for (int i = 0; i < this.getSizeInventory(); ++i){

 

if (this.getStackInSlot(i) != null){

NBTTagCompound nbttagcompound1 = new NBTTagCompound();

nbttagcompound1.setByte("Slot", (byte) i);

this.getStackInSlot(i).writeToNBT(nbttagcompound1);

nbttaglist.appendTag(nbttagcompound1);

}

}

tagcompound.setTag(tagName, nbttaglist);

}

 

public void readFromNBT(NBTTagCompound compound) {

NBTTagList items = compound.getTagList(tagName, compound.getId());

 

for (int i = 0; i < items.tagCount(); ++i) {

NBTTagCompound item = items.getCompoundTagAt(i);

byte slot = item.getByte("Slot");

 

if (slot >= 0 && slot < getSizeInventory()) {

 

setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(item));

}

}

}

public void dropItems (){

EntityPlayer player = parent.get();

 

for (int i = 0; i < 4; ++i){

if (this.inventory != null){

player.func_146097_a(this.inventory, true, false);

this.inventory = null;

}

}

}

 

public void copy(InventoryEotInventory inv) {

for (int i = 0; i < inv.getSizeInventory(); ++i) {

ItemStack stack = inv.getStackInSlot(i);

inventory = (stack == null ? null : stack.copy());

}

markDirty();

}

 

 

 

 

public class SlotBag extends Slot{

 

public SlotBag(IInventory inventory, int index, int xPos, int yPos){

super(inventory, index, xPos, yPos);

}

 

public boolean isItemValid(ItemStack itemstack){

return itemstack.getItem() instanceof ItemTier1Bag;

}

 

}

 

 

Posted

 

public class EotGuiHandler implements IGuiHandler {

 

    public EntityPlayer getPlayerEntity(MessageContext ctx) {

return ctx.getServerHandler().playerEntity;

}

   

    @Override

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

        if (ID == GuiIds.eotInventory){

            return new ContainterEotInventory(player, player.inventory, EotExtendedPlayer.get(player).inventoryEot);

        }

        if (ID == GuiIds.tier1Bag){

            return new ContainerTier1Bag(player, player.inventory, EotExtendedPlayer.get(player).inventoryTier1Bag);

        }else{

        return null;

        }

    }

   

    @Override

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

 

    if (ID == GuiIds.eotInventory) {

return new GuiEotInventory(player, player.inventory, EotExtendedPlayer.get(player).inventoryEot);

        }if (ID == GuiIds.tier1Bag) {

return new GuiTier1Bag(player, player.inventory, EotExtendedPlayer.get(player).inventoryTier1Bag);

        }else{

        return null;

        }

    }

 

}

 

 

public class EotExtendedPlayer implements IExtendedEntityProperties

{

public final static String EXT_PROP_NAME = "ExtendedPlayer";

 

public final InventoryEotInventory inventoryEot = new InventoryEotInventory();

public final InventoryTier1Bag inventoryTier1Bag = new InventoryTier1Bag();

 

private final EntityPlayer player;

 

public EotExtendedPlayer(EntityPlayer player) {

this.player = player;

}

 

/**

* Used to register these extended properties for the player during EntityConstructing event

*/

public static final void register(EntityPlayer player) {

player.registerExtendedProperties(EotExtendedPlayer.EXT_PROP_NAME, new EotExtendedPlayer(player));

}

 

/**

* Returns ExtendedPlayer properties for player

*/

public static final EotExtendedPlayer get(EntityPlayer player) {

return (EotExtendedPlayer) player.getExtendedProperties(EXT_PROP_NAME);

}

 

/**

* Copies additional player data from the given ExtendedPlayer instance

* Avoids NBT disk I/O overhead when cloning a player after respawn

*/

public void copy(EotExtendedPlayer props) {

inventoryEot.copy(props.inventoryEot);

inventoryTier1Bag.copy(props.inventoryTier1Bag);

}

 

@Override

public final void saveNBTData(NBTTagCompound compound) {

NBTTagCompound properties = new NBTTagCompound();

compound.setTag(EXT_PROP_NAME, properties);

this.inventoryEot.writeToNBT(properties);

this.inventoryTier1Bag.writeToNBT(properties);

}

 

@Override

public final void loadNBTData(NBTTagCompound compound) {

NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME);

this.inventoryEot.readFromNBT(properties);

this.inventoryTier1Bag.readFromNBT(properties);

}

 

@Override

public void init(Entity entity, World world) {}

}

 

Posted

Why the f*** is this static?

See the whole history and you'll understand... I've tried explaining.

 

Apart from that: Your IExtendedEntityProperties identifier is horrible.

For my extended player and my packet i fallowed someone's  tutorial

And the tutorial IEEP identifier IS horrible for a reason - it EXPLICITLY tells you to come up with a more unique name:

/**
Note that a single entity can have multiple extended properties, so each property should have a unique name. Try to come up with something more unique than the tutorial example.
*/
public final static String EXT_PROP_NAME = "ExtendedPlayer";

Why bother to use a tutorial if you aren't going to READ it?

Posted

Everything in that class,came from the tutorial .... i didnt change  anything  in the tutorial

 

Edit : i looked back over at ur git hub tutorial n u changed it n fixed it ..... thanks for making me seem stupid ^^ i love it sooo much everything i used is from ur tutorial all i did was delete everything  involving ur mana so dont say im wrong :/ i came here for someone to help me with what u gave me..

Posted

Everything in that class,came from the tutorial .... i didnt change  anything  in the tutorial

That's my point: you SHOULD change things from the tutorial, because the tutorial is there to TEACH you about a subject, not provide you with a copy/paste solution. I'm going to rewrite my tutorials so the code doesn't even compile, just to avoid situations like this.

Posted

All tue code was from the hit hub under the 1.7.10 i read everything u used in the /* */ // the whole reason i went to ur gir hub was becauae,ur regular  tutorial  format  was hard to read, and i couldnt copy paste  it because  even of i did would have error and would end up spending 5 minuts on each class prettying it up because minecraft doesnt like java code you 1.7.10 code was what i used and then if u look at the main one i think u made it mainly for 1.8 it has every change  that the 1.7.10 was sepost to have

Posted

Yea he pointee something out that i missed when i wae cleaning up the code... sorry for ranting i just alot of stuff in life have me stressing so i cannot think clearly, but i do try and solve  the problem my self sometimes  someone else can see something  i cannot it is usualy why i ask for help

Posted

would it be a good idea to put my gui handler like you have it or keep it as a separate class

Simpler is better, in my opinion. I don't see any reason to make your IGuiHandler as complicated as you have unless you have a LOT of guis, and even then it might not be worth it.

 

If you consolidate it into one class, it's much easier for both you and us to quickly see what's going on, and then you can also put all of your gui IDs in there, getting rid of your GuiRefs class (or whatever it was called, don't remember).

 

But it's totally up to you - the way you have it set up is not technically wrong, just unnecessarily complex.

Posted

im a little bit confused is there a way to access .. public ItemStack[] inventory = new ItemStack[iNV_SIZE];

 

when it was static this worked perfectly

 

@Override

    public boolean shouldAddToList (){

        return InventoryEotInventory.inventory[0] != null && InventoryEotInventory.inventory[0].getItem() == ModItems.tier1Bag;

}

 

now since i took it off to get it to work it wants me to change it to static... is here anyother way i can cheek if there is a item in that slot ? because ive tried to fix it myself for the past hour and i cannot figure out how..

 

 

Posted

In Java and probably every language with classes, you need an instance of the class to access a non-static class field, because the field is different for every single class (that's the whole point). E.g.

public class Example {
public int value;
public Example(int value) {
this.value = value;
}
}

Example a = new Example(1);
Example b = new Example(2);
System.out.println("A = " + a.value + " | B = " + b.value);

That's what I mean by 'you need an instance of the class' - both 'a' and 'b' are specific instances of Example, and thus each can have an independent value for 'this.value', whereas if you make 'value' static, the value will NOT be independent: 'a' and 'b' cannot have different values.

 

Don't you have a class field to store an instance of your inventory? That's what you need to use to access the contents of the inventory, because nothing else makes sense.

 

And that's why I've been so adamant that you spend some time learning about this stuff. These are not really Minecraft questions - they are Java questions.

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.