Posted February 5, 201510 yr I'm trying to make an item place a torch on rightclick. package com.FirstArchon.RedStoneium.item; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntitySnowball; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemPickaxe; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import com.FirstArchon.RedStoneium.item.ItemRedDiamondPick; import com.FirstArchon.RedStoneium.CreativeTabRS; import com.FirstArchon.RedStoneium.reference.Reference; import com.FirstArchon.RedStoneium.utility.LogHelper; import net.minecraft.world.World; public class ItemRedDiamondPick extends ItemPickaxe { public ItemRedDiamondPick(ToolMaterial material) { super(material); this.setUnlocalizedName("ItemRedDiamondPick"); this.setTextureName(Reference.MOD_ID + ":" + "ItemRedDiamondPick"); this.setCreativeTab(CreativeTabRS.RS_TAB); } public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par3EntityPlayer, World par2World, int p_77648_4_, int p_77648_5_, int p_77648_6_, int p_77648_7_, float p_77648_8_, float p_77648_9_, float p_77648_10_) { if(par3EntityPlayer.capabilities.isCreativeMode||par3EntityPlayer.inventory.consumeInventoryItem(Item.getItemFromBlock(Blocks.torch))) { setBlock(p_77648_4_, p_77648_5_, p_77648_6_, Blocks.torch); return true; } } } the problem is the setBlock(p_77648_4_, p_77648_5_, p_77648_6_, Blocks.torch); this is copied from the flint and steel class and I I'm using the import statement to import the setBlock method but it still won't recognize that this class exists.
February 5, 201510 yr Author ty that fixed it. small problem though. this is deleting the clicked block and isn't placing the torch on the block as i anticipated. is their a way to place a item on the face you clicked instead of setting the block (this creates a break bedrock glitch )?
February 5, 201510 yr Author what exactly does ForgeDirection.getOrientation. return? is it a integer? ie. top = 1 botom = 2 etc?
February 5, 201510 yr Author so I need to do p_77648_10_ ForgeDirection.getOrientation this returns a "ForgeDirection" object. and then I need an if statement that interprets the forge direction object and increments or decrements the x y or z vallue based on the ForgeDirection objects value?
February 5, 201510 yr Author so the xOffset, yOffset and zOffset. should be the arguments of the set block command? this might be a noobish question but how do I get these values? public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par3EntityPlayer, World par2World, int p_77648_4_, int p_77648_5_, int p_77648_6_, int p_77648_7_, float p_77648_8_, float p_77648_9_, float p_77648_10_) { if(par3EntityPlayer.capabilities.isCreativeMode||par3EntityPlayer.inventory.consumeInventoryItem(Item.getItemFromBlock(Blocks.torch))) { ForgeDirection.getOrientation(p_77648_7_); par2World.setBlock(p_77648_4_, p_77648_5_, p_77648_6_, Blocks.torch); } return true; } this is what I have this now. ForgeDirection.getOrientation(p_77648_7_); translates the face into a forge direction object. how do I use the fields of the object? are they just variables I can refer to now? (If this is a derp question I'm sorry but I don't understand how this is supposed to work)
February 5, 201510 yr Author I would say that I do know basic java (albeit with a few holes) could you please link to a resource that will help me understand or show me some example code that I can examine? I know what an object is but I have never heard the world "field" before. If I were to set it to a variable I would assume it would be something like this. { ForgeDirection x = ForgeDirection.getOrientation(p_77648_7_); par2World.setBlock(p_77648_4_, p_77648_5_, p_77648_6_, Blocks.torch); } (this much I admit should have been obvious when you said it was an object, but I never though of needing a constructor) but I'm still not sure how to get at these "fields"...?
February 6, 201510 yr I would say that I do know basic java (albeit with a few holes) could you please link to a resource that will help me understand or show me some example code that I can examine? I know what an object is but I have never heard the world "field" before. If I were to set it to a variable I would assume it would be something like this. { ForgeDirection x = ForgeDirection.getOrientation(p_77648_7_); par2World.setBlock(p_77648_4_, p_77648_5_, p_77648_6_, Blocks.torch); } (this much I admit should have been obvious when you said it was an object, but I never though of needing a constructor) but I'm still not sure how to get at these "fields"...? Asking diesieben for example code, is as bad as sticking your hand in a lions cage. A tutorial for getting a variable from another class. http://www.homeandlearn.co.uk/java/accessing_class_variables.html I'm back from being gone for... I think its been about a year. I'm pretty sure nobody remembers me, but hello anybody who does!
February 6, 201510 yr Author thankyou starwarsmace for that link (also I figured out a field is and I still don't understand it. a field is a variable in a class but don't all variables (all code even) have to be in a class?) { int x; int y; int z; ForgeDirection direct = ForgeDirection.getOrientation(p_77648_7_); x = direct.offsetX; y = direct.offsetY; z = direct.offsetZ; //par2World.setBlock(p_77648_4_, p_77648_5_, p_77648_6_, Blocks.torch); par2World.setBlock(x, y, z, Blocks.torch); } this seems to be working but I think I'm calling the cords in the wrong order because when I right click it takes a torch out of my inventory but no torch appears.
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.