---- Minecraft Crash Report ----
// Oh - I know what I did wrong!
Time: 11/5/13 7:08 PM
Description: Reading NBT data
java.lang.ClassCastException: net.minecraft.nbt.NBTTagByte cannot be cast to net.minecraft.nbt.NBTTagInt
at net.minecraft.nbt.NBTTagCompound.getInteger(NBTTagCompound.java:233)
at Vikymod.Vikydronemod.InventoryItem.readFromNBT(InventoryItem.java:162)
at Vikymod.Vikydronemod.InventoryItem.<init>(InventoryItem.java:34)
at Vikymod.Vikydronemod.CommonProxy.getServerGuiElement(CommonProxy.java:29)
at cpw.mods.fml.common.network.NetworkRegistry.openRemoteGui(NetworkRegistry.java:308)
at cpw.mods.fml.common.network.FMLNetworkHandler.openGui(FMLNetworkHandler.java:352)
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2480)
at Vikymod.Vikydronemod.Vikydronearmor.onItemRightClick(Vikydronearmor.java:59)
at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:176)
at net.minecraft.item.ItemInWorldManager.tryUseItem(ItemInWorldManager.java:353)
at net.minecraft.network.NetServerHandler.handlePlace(NetServerHandler.java:542)
at net.minecraft.network.packet.Packet15Place.processPacket(Packet15Place.java:79)
at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89)
at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141)
at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54)
at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:691)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:587)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:129)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:484)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)
A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------
-- Corrupt NBT tag --
Details:
Tag type found: BYTE
Tag type expected: INT
Tag name: Slot
Stacktrace:
at net.minecraft.nbt.NBTTagCompound.getInteger(NBTTagCompound.java:233)
at Vikymod.Vikydronemod.InventoryItem.readFromNBT(InventoryItem.java:162)
at Vikymod.Vikydronemod.InventoryItem.<init>(InventoryItem.java:34)
at Vikymod.Vikydronemod.CommonProxy.getServerGuiElement(CommonProxy.java:29)
at cpw.mods.fml.common.network.NetworkRegistry.openRemoteGui(NetworkRegistry.java:308)
at cpw.mods.fml.common.network.FMLNetworkHandler.openGui(FMLNetworkHandler.java:352)
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2480)
at Vikymod.Vikydronemod.Vikydronearmor.onItemRightClick(Vikydronearmor.java:59)
at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:176)
at net.minecraft.item.ItemInWorldManager.tryUseItem(ItemInWorldManager.java:353)
at net.minecraft.network.NetServerHandler.handlePlace(NetServerHandler.java:542)
at net.minecraft.network.packet.Packet15Place.processPacket(Packet15Place.java:79)
at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89)
at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141)
-- Ticking connection --
Details:
Connection: [email protected]
Stacktrace:
at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54)
at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:691)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:587)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:129)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:484)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)
-- System Details --
Details:
Minecraft Version: 1.6.4
Operating System: Windows XP (x86) version 5.1
Java Version: 1.7.0_25, Oracle Corporation
Java VM Version: Java HotSpot(TM) Client VM (mixed mode, sharing), Oracle Corporation
Memory: 50029112 bytes (47 MB) / 213958656 bytes (204 MB) up to 259522560 bytes (247 MB)
JVM Flags: 0 total;
AABB Pool Size: 4767 (266952 bytes; 0 MB) allocated, 4262 (238672 bytes; 0 MB) used
Suspicious classes: FML and Forge are installed
IntCache: cache: 1, tcache: 0, allocated: 1, tallocated: 63
FML: MCP v8.11 FML v6.4.3.883 Minecraft Forge 9.11.0.883 4 mods loaded, 4 mods active
mcp{8.09} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
FML{6.4.3.883} [Forge Mod Loader] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Forge{9.11.0.883} [Minecraft Forge] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
vikydronemod{1.1} [vikydronemod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Profiler Position: N/A (disabled)
Vec3 Pool Size: 3513 (196728 bytes; 0 MB) allocated, 3358 (188048 bytes; 0 MB) used
Player Count: 1 / 8; [EntityPlayerMP['Player369'/196, l='new mod', x=-309.80, y=63.00, z=10.66]]
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'
here's my Inventory Item code :
package Vikymod.Vikydronemod;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
public class InventoryItem extends TileEntity implements IInventory
{
private String name = "Inventory Item";
/** Provides NBT Tag Compound to reference */
private final ItemStack stack;
/** Defining your inventory size this way is handy */
public static final int INV_SIZE = 8;
/** Inventory's size must be same as number of slots you add to the Container class */
ItemStack[] inventory = new ItemStack[INV_SIZE];
/**
* @param itemstack - the ItemStack to which this inventory belongs
*/
public InventoryItem(ItemStack itemstack)
{
this.stack = itemstack;
// Create a new NBT Tag Compound if one doesn't already exist, or you will crash
if (!this.stack.hasTagCompound()) { this.stack.setTagCompound(new NBTTagCompound()); }
// Read the inventory contents from NBT
readFromNBT(this.stack.getTagCompound());
}
@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);
// Don't forget this line or your inventory will not be saved!
this.onInventoryChanged();
}
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 itemstack)
{
this.inventory[slot] = itemstack;
if (itemstack != null && itemstack.stackSize > this.getInventoryStackLimit())
{
itemstack.stackSize = this.getInventoryStackLimit();
}
// Don't forget this line or your inventory will not be saved!
this.onInventoryChanged();
}
@Override
public String getInvName()
{
return name;
}
@Override
public boolean isInvNameLocalized()
{
return name.length() > 0;
}
@Override
public int getInventoryStackLimit()
{
return 64;
}
/**
* This is the method that will handle saving the inventory contents, as it is called (or should be called!)
* anytime the inventory changes. Perfect. Much better than using onUpdate in an Item, as this will also
* let you change things in your inventory without ever opening a Gui, if you want.
*/
@Override
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);
}
// This line here does the work:
this.writeToNBT(this.stack.getTagCompound());
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer)
{
return true;
}
@Override
public void openChest() {}
@Override
public void closeChest() {}
/**
* 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)
{
// Don't want to be able to store the inventory item within itself
// Bad things will happen, like losing your inventory
// Actually, this needs a custom Slot to work
return !(itemstack.getItem() instanceof Vikydronearmor);
}
/**
* A custom method to read our inventory from an ItemStack's NBT compound
*/
public void readFromNBT(NBTTagCompound compound)
{
// Gets the custom taglist we wrote to this compound, if any
NBTTagList items = compound.getTagList("ItemInventory");
for (int i = 0; i < items.tagCount(); ++i)
{
NBTTagCompound item = (NBTTagCompound) items.tagAt(i);
int slot = item.getInteger("Slot");
// Just double-checking that the saved slot index is within our inventory array bounds
if (slot >= 0 && slot < getSizeInventory())
{
setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(item));
}
}
}
/**
* A custom method to write our inventory to an ItemStack's NBT compound
*/
public void writeToNBT(NBTTagCompound compound)
{
// Create a new NBT Tag List to store itemstacks as NBT Tags
NBTTagList items= new NBTTagList();
for (int i = 0; i < getSizeInventory(); ++i)
{
// Only write stacks that contain items
if (getStackInSlot(i) != null)
{
// Make a new NBT Tag Compound to write the itemstack and slot index to
NBTTagCompound item = new NBTTagCompound();
item.setInteger("Slot", i);
// Writes the itemstack in slot(i) to the Tag Compound we just made
getStackInSlot(i).writeToNBT(item);
// add the tag compound to our tag list
items.appendTag(item);
}
}
// Add the TagList to the ItemStack's Tag Compound with the name "ItemInventory"
compound.setTag("ItemInventory", items);
}
}
While reading from NBT it was looking for an INTEGER, as that's what you specified in your code, but it found a BYTE for some reason. Did you perhaps change the code from setting a Byte to an Integer and then load an old world save? Try creating a new world or at least get rid of the item you currently have and get a new one. See if that works.
While reading from NBT it was looking for an INTEGER, as that's what you specified in your code, but it found a BYTE for some reason. Did you perhaps change the code from setting a Byte to an Integer and then load an old world save? Try creating a new world or at least get rid of the item you currently have and get a new one. See if that works.
Wow,Thanks dude !!! it really works i forgot to add some methods...
Wow,Thanks dude !!! it really works i forgot to add some methods...
No problem It's pretty common when working with NBT to mess up your world saves, so it's always best to start fresh any time you change the way something saves or loads.
ive got this to work and everything, but is there a way to test what is in the slot?
Could you be more specific? If you only want to be able to place certain items in the custom slots, you need to create a custom Slot class and use that in your Container.
Could you be more specific? If you only want to be able to place certain items in the custom slots, you need to create a custom Slot class and use that in your Container.
i have the item that opens up the inventory, and i also have the custom slot that only allows certain items to place inside. im trying to make it so the texture of the item that opens the inventory changes when a certain item is in. i want it to test which item is in the slot, probably just a simple if statement, but idk....if that also doesnt make sense just say so
i have the item that opens up the inventory, and i also have the custom slot that only allows certain items to place inside. im trying to make it so the texture of the item that opens the inventory changes when a certain item is in. i want it to test which item is in the slot, probably just a simple if statement, but idk....
if that also doesnt make sense just say so
If you coded your IInventory well, then you could probably just add your check to the 'onInventoryChanged' method; it iterates through all of the slots already, so you could check if any of the slots contain your item and then figure out how you want to change the texture from there.
If you coded your IInventory well, then you could probably just add your check to the 'onInventoryChanged' method; it iterates through all of the slots already, so you could check if any of the slots contain your item and then figure out how you want to change the texture from there.
oh i see.... i was going through the container i created XD
thanks a ton and awesome tutorial, just what i needed!
ok so i have this
if(SlotCustom.contains(ItemEarthcCrystal)){
mod_ECrystals.Pendant = "texture98978";
}
and i put it in the 'onInventoryChanged' meathod but when i open up the inventory, it imediately crashes, and the crash report says the error was in like 125, which is the
ok so i have this
if(SlotCustom.contains(ItemEarthcCrystal)){
mod_ECrystals.Pendant = "texture98978";
}
and i put it in the 'onInventoryChanged' meathod but when i open up the inventory, it imediately crashes, and the crash report says the error was in like 125, which is the
if(SlotCustom.contains(ItemEarthcCrystal)){
line
Well, first off you're using a static method from the looks of it, so there isn't an instance of SlotCustom to check if it contains an item. You shouldn't make a method like that static. Secondly, what is 'ItemEarthCrystal'? Is it an ItemStack, an Item, what?
Lastly, a slick method of having multiple textures is to use damage values and override the getIconFromDamage method in your Item to return different textures - you should probably register all your textures in the registerIcons method, and store them in a client-side array.
Would you mind posting your Slot class and inventory code? (in [ SPOILER ] tags please)
Well, first off you're using a static method from the looks of it, so there isn't an instance of SlotCustom to check if it contains an item. You shouldn't make a method like that static. Secondly, what is 'ItemEarthCrystal'? Is it an ItemStack, an Item, what?
Lastly, a slick method of having multiple textures is to use damage values and override the getIconFromDamage method in your Item to return different textures - you should probably register all your textures in the registerIcons method, and store them in a client-side array.
Would you mind posting your Slot class and inventory code? (in [ SPOILER ] tags please)
public class SlotCustom extends Slot
{
public SlotCustom(IInventory inventory, int par2, int par3, int par4)
{
super(inventory, par2, par3, par4);
}
/**
* Check if the stack is a valid item for this slot. Always true beside for the armor slots
* (and now also not always true for our custom inventory slots)
*/
@Override
public boolean isItemValid(ItemStack itemstack)
{
// We only want our custom item to be storable in this slot
return itemstack.getItem() instanceof ItemEarthCrystal;
idk why, but eclipse automatically turned the "SlotCustom" into a string at the top, and it gave me that, which was weird, so i deleted that and im trying to figure it out now
idk why, but eclipse automatically turned the "SlotCustom" into a string at the top, and it gave me that, which was weird, so i deleted that and im trying to figure it out now
Like I mentioned earlier, checking if the stack in a slot is your custom item should be easy from the onInventoryChanged method, regardless of how big your inventory is:
// you should already be iterating through the entire inventory in onInventoryChanged
for (int i = 0; i < getSizeInventory(); ++i)
{
if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0) { inventory[i] = null; }
// after setting to null if necessary, you can now check if the stack is your item using one of the following:
1. if (getStackInSlot(i) instanceof YourItem) { // change texture }
2. if (getStackInSlot(i) != null && getStackInSlot(i).itemID == YourMod.yourItem.itemID) { // change textures }
}
Like I mentioned earlier, checking if the stack in a slot is your custom item should be easy from the onInventoryChanged method, regardless of how big your inventory is:
// you should already be iterating through the entire inventory in onInventoryChanged
for (int i = 0; i < getSizeInventory(); ++i)
{
if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0) { inventory[i] = null; }
// after setting to null if necessary, you can now check if the stack is your item using one of the following:
1. if (getStackInSlot(i) instanceof YourItem) { // change texture }
2. if (getStackInSlot(i) != null && getStackInSlot(i).itemID == YourMod.yourItem.itemID) { // change textures }
}
idk what in the heck it is, but the games crashes when i run it still, or it doesnt work, nothing changes. here is the code for when it crashes
@Override
public void onInventoryChanged()
{
for (int i = 0; i < this.getSizeInventory(); ++i)
{
if (this.getStackInSlot(i) != null && this.getStackInSlot(i).stackSize == 0)
if (getStackInSlot(i) != null && getStackInSlot(i).itemID == mod_ECrystals.EarthCrystal.itemID) {
mod_ECrystals.Pendant = "texture";
}
this.setInventorySlotContents(i, null);
}
// This line here does the work:
this.writeToNBT(this.stack.getTagCompound());
}
and here is the code that makes nothing happen
@Override
public void onInventoryChanged()
{
for (int i = 0; i < this.getSizeInventory(); ++i)
{
if (this.getStackInSlot(i) != null && this.getStackInSlot(i).stackSize == 0)
if (getStackInSlot(i) != null && getStackInSlot(i).itemID == mod_ECrystals.EarthCrystal.itemID) {
mod_ECrystals.Pendant = "texture";
}
}
// This line here does the work:
this.writeToNBT(this.stack.getTagCompound());
}
Firstly, you've got the if statements all messed up in your onInventoryChanged() method's for loop. Pay close attention to the brackets I use in my example above.
Secondly, what does the crash log say? What line specifically is causing the crash?
Thirdly, using something like 'mod_ECrystals.Pendant = "texture";' will set the texture for EVERYONE, not just the player with the item in their inventory. You need to write the current texture you want the itemstack to use to the stack's nbt, or use the ItemStack's damage value as an indicator of which texture to use.
Take a look at ItemDye for an example of how to return different icons based on an ItemStack's damage value. You can ignore the getSubItems part if you don't need the item to truly have subtypes, but be sure you set hasSubtypes to true so that you don't get the damage bar showing up under the itemstack.
package Vikymod.Vikydronemod; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; public class InventoryItem extends TileEntity implements IInventory { private String name = "Inventory Item"; /** Provides NBT Tag Compound to reference */ private final ItemStack stack; /** Defining your inventory size this way is handy */ public static final int INV_SIZE = 8; /** Inventory's size must be same as number of slots you add to the Container class */ ItemStack[] inventory = new ItemStack[INV_SIZE]; /** * @param itemstack - the ItemStack to which this inventory belongs */ public InventoryItem(ItemStack itemstack) { this.stack = itemstack; // Create a new NBT Tag Compound if one doesn't already exist, or you will crash if (!this.stack.hasTagCompound()) { this.stack.setTagCompound(new NBTTagCompound()); } // Read the inventory contents from NBT readFromNBT(this.stack.getTagCompound()); } @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); // Don't forget this line or your inventory will not be saved! this.onInventoryChanged(); } 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 itemstack) { this.inventory[slot] = itemstack; if (itemstack != null && itemstack.stackSize > this.getInventoryStackLimit()) { itemstack.stackSize = this.getInventoryStackLimit(); } // Don't forget this line or your inventory will not be saved! this.onInventoryChanged(); } @Override public String getInvName() { return name; } @Override public boolean isInvNameLocalized() { return name.length() > 0; } @Override public int getInventoryStackLimit() { return 64; } /** * This is the method that will handle saving the inventory contents, as it is called (or should be called!) * anytime the inventory changes. Perfect. Much better than using onUpdate in an Item, as this will also * let you change things in your inventory without ever opening a Gui, if you want. */ @Override 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); } // This line here does the work: this.writeToNBT(this.stack.getTagCompound()); } @Override public boolean isUseableByPlayer(EntityPlayer entityplayer) { return true; } @Override public void openChest() {} @Override public void closeChest() {} /** * 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) { // Don't want to be able to store the inventory item within itself // Bad things will happen, like losing your inventory // Actually, this needs a custom Slot to work return !(itemstack.getItem() instanceof Vikydronearmor); } /** * A custom method to read our inventory from an ItemStack's NBT compound */ public void readFromNBT(NBTTagCompound compound) { // Gets the custom taglist we wrote to this compound, if any NBTTagList items = compound.getTagList("ItemInventory"); for (int i = 0; i < items.tagCount(); ++i) { NBTTagCompound item = (NBTTagCompound) items.tagAt(i); int slot = item.getInteger("Slot"); // Just double-checking that the saved slot index is within our inventory array bounds if (slot >= 0 && slot < getSizeInventory()) { setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(item)); } } } /** * A custom method to write our inventory to an ItemStack's NBT compound */ public void writeToNBT(NBTTagCompound compound) { // Create a new NBT Tag List to store itemstacks as NBT Tags NBTTagList items= new NBTTagList(); for (int i = 0; i < getSizeInventory(); ++i) { // Only write stacks that contain items if (getStackInSlot(i) != null) { // Make a new NBT Tag Compound to write the itemstack and slot index to NBTTagCompound item = new NBTTagCompound(); item.setInteger("Slot", i); // Writes the itemstack in slot(i) to the Tag Compound we just made getStackInSlot(i).writeToNBT(item); // add the tag compound to our tag list items.appendTag(item); } } // Add the TagList to the ItemStack's Tag Compound with the name "ItemInventory" compound.setTag("ItemInventory", items); } }-
View User Profile
-
View Posts
-
Send Message
Curse PremiumWhile reading from NBT it was looking for an INTEGER, as that's what you specified in your code, but it found a BYTE for some reason. Did you perhaps change the code from setting a Byte to an Integer and then load an old world save? Try creating a new world or at least get rid of the item you currently have and get a new one. See if that works.
Wow,Thanks dude !!! it really works i forgot to add some methods...
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumNo problem
http://www.planetminecraft.com/mod/couple-of-new-mobs/
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumCould you be more specific? If you only want to be able to place certain items in the custom slots, you need to create a custom Slot class and use that in your Container.
i have the item that opens up the inventory, and i also have the custom slot that only allows certain items to place inside. im trying to make it so the texture of the item that opens the inventory changes when a certain item is in. i want it to test which item is in the slot, probably just a simple if statement, but idk....if that also doesnt make sense just say so
http://www.planetminecraft.com/mod/couple-of-new-mobs/
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumIf you coded your IInventory well, then you could probably just add your check to the 'onInventoryChanged' method; it iterates through all of the slots already, so you could check if any of the slots contain your item and then figure out how you want to change the texture from there.
oh i see.... i was going through the container i created XD
thanks a ton and awesome tutorial, just what i needed!
http://www.planetminecraft.com/mod/couple-of-new-mobs/
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumThanks
if(SlotCustom.contains(ItemEarthcCrystal)){
mod_ECrystals.Pendant = "texture98978";
}
and i put it in the 'onInventoryChanged' meathod but when i open up the inventory, it imediately crashes, and the crash report says the error was in like 125, which is the
if(SlotCustom.contains(ItemEarthcCrystal)){
line
http://www.planetminecraft.com/mod/couple-of-new-mobs/
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumWell, first off you're using a static method from the looks of it, so there isn't an instance of SlotCustom to check if it contains an item. You shouldn't make a method like that static. Secondly, what is 'ItemEarthCrystal'? Is it an ItemStack, an Item, what?
Lastly, a slick method of having multiple textures is to use damage values and override the getIconFromDamage method in your Item to return different textures - you should probably register all your textures in the registerIcons method, and store them in a client-side array.
Would you mind posting your Slot class and inventory code? (in [ SPOILER ] tags please)
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemEarthCrystal;
import net.minecraft.item.ItemStack;
public class SlotCustom extends Slot
{
public SlotCustom(IInventory inventory, int par2, int par3, int par4)
{
super(inventory, par2, par3, par4);
}
/**
* Check if the stack is a valid item for this slot. Always true beside for the armor slots
* (and now also not always true for our custom inventory slots)
*/
@Override
public boolean isItemValid(ItemStack itemstack)
{
// We only want our custom item to be storable in this slot
return itemstack.getItem() instanceof ItemEarthCrystal;
}
}
http://www.planetminecraft.com/mod/couple-of-new-mobs/
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumSo where do you define the method 'SlotCustom.contains(ItemEarthcCrystal)'? It's not in your SlotCustom class.
http://www.planetminecraft.com/mod/couple-of-new-mobs/
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumLike I mentioned earlier, checking if the stack in a slot is your custom item should be easy from the onInventoryChanged method, regardless of how big your inventory is:
// you should already be iterating through the entire inventory in onInventoryChanged for (int i = 0; i < getSizeInventory(); ++i) { if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0) { inventory[i] = null; } // after setting to null if necessary, you can now check if the stack is your item using one of the following: 1. if (getStackInSlot(i) instanceof YourItem) { // change texture } 2. if (getStackInSlot(i) != null && getStackInSlot(i).itemID == YourMod.yourItem.itemID) { // change textures } }idk what in the heck it is, but the games crashes when i run it still, or it doesnt work, nothing changes. here is the code for when it crashes
public void onInventoryChanged()
{
for (int i = 0; i < this.getSizeInventory(); ++i)
{
if (this.getStackInSlot(i) != null && this.getStackInSlot(i).stackSize == 0)
if (getStackInSlot(i) != null && getStackInSlot(i).itemID == mod_ECrystals.EarthCrystal.itemID) {
mod_ECrystals.Pendant = "texture";
}
this.setInventorySlotContents(i, null);
}
// This line here does the work:
this.writeToNBT(this.stack.getTagCompound());
}
and here is the code that makes nothing happen
public void onInventoryChanged()
{
for (int i = 0; i < this.getSizeInventory(); ++i)
{
if (this.getStackInSlot(i) != null && this.getStackInSlot(i).stackSize == 0)
if (getStackInSlot(i) != null && getStackInSlot(i).itemID == mod_ECrystals.EarthCrystal.itemID) {
mod_ECrystals.Pendant = "texture";
}
}
// This line here does the work:
this.writeToNBT(this.stack.getTagCompound());
}
http://www.planetminecraft.com/mod/couple-of-new-mobs/
http://www.planetminecraft.com/mod/couple-of-new-mobs/
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumSecondly, what does the crash log say? What line specifically is causing the crash?
Thirdly, using something like 'mod_ECrystals.Pendant = "texture";' will set the texture for EVERYONE, not just the player with the item in their inventory. You need to write the current texture you want the itemstack to use to the stack's nbt, or use the ItemStack's damage value as an indicator of which texture to use.
Take a look at ItemDye for an example of how to return different icons based on an ItemStack's damage value. You can ignore the getSubItems part if you don't need the item to truly have subtypes, but be sure you set hasSubtypes to true so that you don't get the damage bar showing up under the itemstack.