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.
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...
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.
http://www.planetminecraft.com/mod/couple-of-new-mobs/
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
http://www.planetminecraft.com/mod/couple-of-new-mobs/
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!
http://www.planetminecraft.com/mod/couple-of-new-mobs/
Thanks
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/
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)
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/
So 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/
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:
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/
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.
if (getStackInSlot(i) != null && getStackInSlot(i).itemID == mod_ECrystals.EarthCrystal.itemID) {
i will certainly look at the ItemDye, thanks for the idea
http://www.planetminecraft.com/mod/couple-of-new-mobs/