Jump to content

[1.7.10] IInventory openInventory() and closeInventory() not working.


Manslaughter777

Recommended Posts

It seems that the methods openInventory() and closeInventory() are not working. I have made it print when i open the inventory but it doesnt print anything....

 

The IInventory class:

 

 

package com.manslaughter777.moondimension.inventory;

import com.manslaughter777.moondimension.Main;
import com.manslaughter777.moondimension.items.ItemToolUpgrade;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.Constants;

public class InventoryTool implements IInventory {
private String name;

public static boolean check;

/** Defining your inventory size this way is handy */
public static final int INV_SIZE = 4;

/**
 * Inventory's size must be same as number of slots you add to the Container
 * class
 */
private ItemStack[] slots = new ItemStack[iNV_SIZE];

/** Provides NBT Tag Compound to reference */
public final ItemStack invItem;

/**
 * @param itemstack
 *            - the ItemStack to which this inventory belongs
 */
public InventoryTool(ItemStack stack) {
	this.invItem = stack;

	this.name = stack.getDisplayName();

	if (!stack.hasTagCompound()) {
		stack.setTagCompound(new NBTTagCompound());
	}

	readFromNBT(stack.getTagCompound());
}

public void checkContents() {
	if(this.getStackInSlot(0) != null && this.getStackInSlot(0).getItem() == Main.autoRepair) {
		check = true;
	} else check = false;

	System.out.println("YO");
}

@Override
public int getSizeInventory() {
	return slots.length;
}

@Override
public ItemStack getStackInSlot(int slot) {
	return slots[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);
	if (stack != null) {
		setInventorySlotContents(slot, null);
	}
	return stack;
}

@Override
public void setInventorySlotContents(int slot, ItemStack itemstack) {
	this.slots[slot] = itemstack;

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


	markDirty();
}

@Override
public String getInventoryName() {
	return name;
}

@Override
public boolean hasCustomInventoryName() {
	return name.length() > 0;
}

@Override
public int getInventoryStackLimit() {
	return 1;
}

@Override
public void markDirty() {
	for (int i = 0; i < getSizeInventory(); ++i) {
		if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0)
			slots[i] = null;
	}

	writeToNBT(invItem.getTagCompound());
}

@Override
public boolean isUseableByPlayer(EntityPlayer player) {

	return player.getHeldItem() == invItem;
}

@Override
public void openInventory() {
	checkContents();

	System.out.println("YEAH");
}

@Override
public void closeInventory() {
	checkContents();
}

/**
 * This method doesn't seem to do what it claims to do, as items can still
 * be left-clicked and placed in the inventory even when this returns false
 */
@Override
public boolean isItemValidForSlot(int slot, ItemStack itemstack) {

	return itemstack.getItem() instanceof ItemToolUpgrade;
}

/**
 * A custom method to read our inventory from an ItemStack's NBT compound
 */
public void readFromNBT(NBTTagCompound compound) {
	NBTTagList items = compound.getTagList("ItemInventory", Constants.NBT.TAG_COMPOUND);

	for (int i = 0; i < items.tagCount(); ++i) {
		NBTTagCompound item = (NBTTagCompound) items.getCompoundTagAt(i);
		byte slot = item.getByte("Slot");

		if (slot >= 0 && slot < getSizeInventory()) {
			slots[slot] = ItemStack.loadItemStackFromNBT(item);
		}
	}
}

/**
 * A custom method to write our inventory to an ItemStack's NBT compound
 */
public void writeToNBT(NBTTagCompound tagcompound) {
	NBTTagList items = new NBTTagList();

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

		if (getStackInSlot(i) != null) {

			NBTTagCompound item = new NBTTagCompound();
			item.setInteger("Slot", i);

			getStackInSlot(i).writeToNBT(item);

			items.appendTag(item);
		}
	}

	tagcompound.setTag("ItemInventory", items);
}
}

 

 

Link to comment
Share on other sites

It wouldn't be called automatically unless you call it yourself.

 

So.. What is the purpose of the InventoryTool class? If it is from some container,

you should call openInventory/closeInventory there.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Forge 1.16.5 doesnt install, i re downloaded lots of times the installer, i restarted my PC, my modem, i reinstalled my .minecraft and nothing, always the same error: https://pastebin.com/6SPdEQPh
    • ya ya i get it boolean find = false; int count = 0; BlockState dblkstate; BlockPos bpos = null; BlockPos dpos = null; for(BlockPos cursor : todos_los_blockes ){ dpos = cursor; target.particle(cursor.getCenter()); dblkstate = warudo.getBlockState(cursor); if( !dblkstate.canBeReplaced() ){  //<---------- //if( dblkstate .getBlock() instanceof tubo ){ find = true; break; } bpos = cursor; count ++; } for this case setting blocks i can know discrimaniting by the  canbereplaced tag      thanks 
    • can we have a example of that for item    inever could make it work for item  for blocks i got this  
    • When opening I am directed to a log called ´´forge-1.20.1-47.2.20-installer.jar.log´´ below the following error is written: JVM info: Oracle Corporation - 21.0.2 - 21.0.2+13- LTS-58 java.net.preferIPv4Stack=true Current Time: 02/27/2024 16:58:33 Host: files.minecraftforge.net [51.79.83.165] Host: maven.minecraftforge.net [51.79.83.165] Host: libraries.minecraft.net [13.107.246.33, 13.107.213.33] Host: launchermeta.mojang.com [13.107.246.33, 13.107.213.33] Host: piston-meta.mojang.com [13.107.246.33, 13.107.213.33] java.net.UnknownHostException: This host is not known (authserver.mojang.com) at java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) at java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:52) at java.base/java.net.InetAddress$PlatformResolver.lookupByName(InetAddress.java:1211) at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1828) at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:1139) at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1818) at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1688) at net.minecraftforge.installer.DownloadUtils.getIps(DownloadUtils.java:290) at net.minecraftforge.installer.SimpleInstaller.main(SimpleInstaller.java:120) Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.util.List.stream()" because the return value of "net.minecraftforge.installer.DownloadUtils.getIps(String)" is null at net.minecraftforge.installer.SimpleInstaller.main(SimpleInstaller.java:120)
    • I have downloaded forge version 1.20.4 and I have Java 17 installed but my .jar will not open and the error log text file below is created     JVM info: Oracle Corporation - 17.0.10 - 17.0.10+11-LTS-240 java.net.preferIPv4Stack=true Current Time: 27/02/2024 19:43:19 Host: files.minecraftforge.net [51.79.83.165, 2607:5300:203:65a5:0:0:0:0] Host: maven.minecraftforge.net [51.79.83.165, 2607:5300:203:65a5:0:0:0:0] Host: libraries.minecraft.net [13.107.246.64, 13.107.213.64, 2620:1ec:46:0:0:0:0:64, 2620:1ec:bdf:0:0:0:0:64] Host: launchermeta.mojang.com [13.107.213.64, 13.107.246.64, 2620:1ec:bdf:0:0:0:0:64, 2620:1ec:46:0:0:0:0:64] Host: piston-meta.mojang.com [13.107.213.64, 13.107.246.64, 2620:1ec:46:0:0:0:0:64, 2620:1ec:bdf:0:0:0:0:64] java.net.UnknownHostException: No such host is known (authserver.mojang.com)     at java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)     at java.base/java.net.InetAddress$PlatformNameService.lookupAllHostAddr(InetAddress.java:933)     at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1543)     at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:852)     at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1532)     at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1384)     at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1305)     at net.minecraftforge.installer.DownloadUtils.getIps(DownloadUtils.java:290)     at net.minecraftforge.installer.SimpleInstaller.main(SimpleInstaller.java:120) Exception in thread "main"  java.lang.NullPointerException: Cannot invoke "java.util.List.stream()" because the return value of "net.minecraftforge.installer.DownloadUtils.getIps(String)" is null     at net.minecraftforge.installer.SimpleInstaller.main(SimpleInstaller.java:120)  
  • Topics

×
×
  • Create New...

Important Information

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