I don't know what you're doing wrong, since the method is used from several vanilla Item subclasses. You're definitely calling Item#rayTrace(World, EntityPlayer, boolean) from a subclass of Item?
Post your code using Gist/GitHub, there may be something you're missing.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Your Item class should assume that any ItemStack it receives as an argument contains itself unless there's a reason not to. Don't call methods on the ItemStack's Item, call methods on this.
Your lightTorch method is broken and doesn't properly support the off hand. Use EntityLivingBase#getHeldItem/setHeldItem to get/set the player's held items, InventoryPlayer#getCurrentItem only gives you the main hand.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Your Item class should assume that any ItemStack it receives as an argument contains itself unless there's a reason not to. Don't call methods on the ItemStack's Item, call methods on this.
Your lightTorch method is broken and doesn't properly support the off hand. Use EntityLivingBase#getHeldItem/setHeldItem to get/set the player's held items, InventoryPlayer#getCurrentItem only gives you the main hand.
Could you explain the first part a bit more? It worked, but why?
I switched part of it to use the hand, but what would I do for this method? Is there a way to have an offhand slot and get the slot from the hand?
playerIn.inventory.setInventorySlotContents(slot, new ItemStack(torch1, count, oldFuel));
Could you explain the first part a bit more? It worked, but why?
See this StackOverflow answer. ItemTorchBasic can only access protected members of Item on instances of ItemTorchBasic or its subclasses, not on any Item instance.
Casting the ItemStack's Item to ItemTorchBasic before calling the protected method on it would work, but it makes more sense to call the method on this instead (since the ItemStack's Item should always be this).
I switched part of it to use the hand, but what would I do for this method? Is there a way to have an offhand slot and get the slot from the hand?
playerIn.inventory.setInventorySlotContents(slot, new ItemStack(torch1, count, oldFuel));
Use the getter/setter methods I mentioned in my previous post. They will get/set the item in each hand's slot (using the currently selected hotbar slot as the main hand).
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
See this StackOverflow answer. ItemTorchBasic can only access protected members of Item on instances of ItemTorchBasic or its subclasses, not on any Item instance.
Casting the ItemStack's Item to ItemTorchBasic before calling the protected method on it would work, but it makes more sense to call the method on this instead (since the ItemStack's Item should always be this).
Use the getter/setter methods I mentioned in my previous post. They will get/set the item in each hand's slot (using the currently selected hotbar slot as the main hand).
OK, so if I understand correctly, I'm trying to call it on an Item variable from ItemTorchBasic, and I can only call it on an ItemTorchBasic variable?
Ah, oops. I didn't see those.
My only problem now is onItemRightClick(). It need some sort of return value, but I don't know what each of them mean. There is FAIL, PASS, and SUCCESS, but no Javadoc for any of them. How would I make it so a block isn't placed when my conditions for lightTorch() are met, as right now the lightTorch() method is only being called if the block cannot be placed.
My only problem now is onItemRightClick(). It need some sort of return value, but I don't know what each of them mean. There is FAIL, PASS, and SUCCESS, but no Javadoc for any of them. How would I make it so a block isn't placed when my conditions for lightTorch() are met, as right now the lightTorch() method is only being called if the block cannot be placed.
Return SUCCESS if the action succeeded and processing should stop with this hand. Return FAIL if it failed or PASS if nothing was attempted, these will allow processing to continue to the other hand.
When the player right clicks, Item#onItemUse is called if they right clicked a block. If this returns SUCCESS, nothing else happens. If it returns FAIL or PASS or the player right clicked air, Item#onItemRightClick is called.
If you want torch lighting to take priority over block placement, override Item#onItemUse to light the torch if possible or call the super method if not.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
I assume from your comment this means I have to override onItemUse(), since it determines if onItemRightClick() is called. But when I put the code in there instead, as in the Gist, it doesn't seem to be called under certain conditions. In this case, the method is only called if the ItemBlock is placed in a valid location. It cancels the placement of the block and lights the torch, but not if I, for example, right click the top of the torch. If I do this, I don't even get the "Called onItemUse()" message.
Is there yet another method that is called before onItemUse() and determines if it is called, or am I misunderstanding your comment?
There's no point in raytracing along the player's look vector for their reach distance (which is what Item#rayTrace does) from Item#onItemUse, it only gets called when the client has already done that and found a block. That block and its position are passed as arguments to Item#onItemUse.
If the player right clicks air, Item#onItemUse isn't called at all; only Item#onItemRightClick is.
Override Item#onItemUse to check that the player isn't sneaking and the clicked block is a lighter block. If this is true, light the torch and return SUCCESS. If this is false, call the super method and return the result.
Also override Item#onItemRightClick to light the torch and return SUCCESS.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
There's no point in raytracing along the player's look vector for their reach distance (which is what Item#rayTrace does) from Item#onItemUse, it only gets called when the client has already done that and found a block. That block and its position are passed as arguments to Item#onItemUse.
If the player right clicks air, Item#onItemUse isn't called at all; only Item#onItemRightClick is.
Override Item#onItemUse to check that the player isn't sneaking and the clicked block is a lighter block. If this is true, light the torch and return SUCCESS. If this is false, call the super method and return the result.
Also override Item#onItemRightClick to light the torch and return SUCCESS.
Okay, so the raytrace is already done, and the position of that block is paseed in to onItemUse(). I have done everything else in this post, and it looks like my code is working, but ONLY if the block was placed. I added a sysout, and it looks like onItemUse() is only being called on block placement, not on right clicking a block. But I am actually going to make a new thread for this problem, since it's long since changed from the original issue.
I don't know what you're doing wrong, since the method is used from several vanilla Item subclasses. You're definitely calling Item#rayTrace(World, EntityPlayer, boolean) from a subclass of Item?
Post your code using Gist/GitHub, there may be something you're missing.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
OK, I committed everything so this should be the most recent code: https://github.com/WolfieWaffle/Survivalist-Lighting
Your Item class should assume that any ItemStack it receives as an argument contains itself unless there's a reason not to. Don't call methods on the ItemStack's Item, call methods on this.
Your lightTorch method is broken and doesn't properly support the off hand. Use EntityLivingBase#getHeldItem/setHeldItem to get/set the player's held items, InventoryPlayer#getCurrentItem only gives you the main hand.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Could you explain the first part a bit more? It worked, but why?
I switched part of it to use the hand, but what would I do for this method? Is there a way to have an offhand slot and get the slot from the hand?
See this StackOverflow answer. ItemTorchBasic can only access protected members of Item on instances of ItemTorchBasic or its subclasses, not on any Item instance.
Casting the ItemStack's Item to ItemTorchBasic before calling the protected method on it would work, but it makes more sense to call the method on this instead (since the ItemStack's Item should always be this).
Use the getter/setter methods I mentioned in my previous post. They will get/set the item in each hand's slot (using the currently selected hotbar slot as the main hand).
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
OK, so if I understand correctly, I'm trying to call it on an Item variable from ItemTorchBasic, and I can only call it on an ItemTorchBasic variable?
Ah, oops. I didn't see those.
My only problem now is onItemRightClick(). It need some sort of return value, but I don't know what each of them mean. There is FAIL, PASS, and SUCCESS, but no Javadoc for any of them. How would I make it so a block isn't placed when my conditions for lightTorch() are met, as right now the lightTorch() method is only being called if the block cannot be placed.
Yes.
Return SUCCESS if the action succeeded and processing should stop with this hand. Return FAIL if it failed or PASS if nothing was attempted, these will allow processing to continue to the other hand.
When the player right clicks, Item#onItemUse is called if they right clicked a block. If this returns SUCCESS, nothing else happens. If it returns FAIL or PASS or the player right clicked air, Item#onItemRightClick is called.
If you want torch lighting to take priority over block placement, override Item#onItemUse to light the torch if possible or call the super method if not.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Such as this?
I assume from your comment this means I have to override onItemUse(), since it determines if onItemRightClick() is called. But when I put the code in there instead, as in the Gist, it doesn't seem to be called under certain conditions. In this case, the method is only called if the ItemBlock is placed in a valid location. It cancels the placement of the block and lights the torch, but not if I, for example, right click the top of the torch. If I do this, I don't even get the "Called onItemUse()" message.
Is there yet another method that is called before onItemUse() and determines if it is called, or am I misunderstanding your comment?
There's no point in raytracing along the player's look vector for their reach distance (which is what Item#rayTrace does) from Item#onItemUse, it only gets called when the client has already done that and found a block. That block and its position are passed as arguments to Item#onItemUse.
If the player right clicks air, Item#onItemUse isn't called at all; only Item#onItemRightClick is.
Override Item#onItemUse to check that the player isn't sneaking and the clicked block is a lighter block. If this is true, light the torch and return SUCCESS. If this is false, call the super method and return the result.
Also override Item#onItemRightClick to light the torch and return SUCCESS.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Okay, so the raytrace is already done, and the position of that block is paseed in to onItemUse(). I have done everything else in this post, and it looks like my code is working, but ONLY if the block was placed. I added a sysout, and it looks like onItemUse() is only being called on block placement, not on right clicking a block. But I am actually going to make a new thread for this problem, since it's long since changed from the original issue.