Jump to content

setBlock not working?


firstarchon

Recommended Posts

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.

Link to comment
Share on other sites

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)

 

Link to comment
Share on other sites

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"...?

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

 

 

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.

Announcements



×
×
  • Create New...

Important Information

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