Jump to content

Generating Structures - Getting position problem


M1kep

Recommended Posts

Ok, so I am trying to get a feel of structure generations and what can be done with it and im trying to generate a village for example when you right click with an item called Generator1. Any suggestions on how to go about doing that?

Link to comment
Share on other sites

The basic is simple :)

 

    public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
    {
                   par1World.setBlock(par2, par3, par4, BlockID);
     }

 

par2 is your X coordinate of your block

par3 is your Y coordinate of your block

par4 is your Z coordinate of your block

BlockId is the block you want to place at that coordinate :)

 

Here is some example code im using in my mod to build a small tent :)

 

public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
    {
    	par1World.spawnParticle("smoke", par2, par3, par4, 0.1F, 0.1F, 0.1F);
    	
    	par1World.setBlock(par2, par3, par4,61);
    	par1World.setBlock(par2, par3+1, par4,61);
    	par1World.setBlock(par2, par3+2, par4,35);
    	
    	par1World.setBlock(par2-1, par3, par4,58);
    	par1World.setBlock(par2-2, par3, par4,35);
    	par1World.setBlock(par2-1, par3+1, par4,35);

    	par1World.setBlock(par2+1, par3, par4,58);
    	par1World.setBlock(par2+2, par3, par4,35);
    	par1World.setBlock(par2+1, par3+1, par4,35);
    	
    	par1World.setBlock(par2-1, par3, par4-1,85);
    	par1World.setBlock(par2-2, par3, par4-1,35);
    	par1World.setBlock(par2-1, par3+1, par4-1,35);
    	par1World.setBlock(par2+1, par3, par4-1,85);
    	par1World.setBlock(par2+2, par3, par4-1,35);
    	par1World.setBlock(par2+1, par3+1, par4-1,35);
    	par1World.setBlock(par2, par3, par4-1,85);
    	par1World.setBlock(par2, par3+1, par4-1,85);
    	par1World.setBlock(par2, par3+2, par4-1,35);  	
    	
    	par1World.setBlock(par2-2, par3, par4+1,35);
    	par1World.setBlock(par2-1, par3+1, par4+1,35);
    	par1World.setBlock(par2+2, par3, par4+1,35);
    	par1World.setBlock(par2+1, par3+1, par4+1,35);
    	par1World.setBlock(par2, par3+2, par4+1,35); 
    	
    	return true;
    };

Link to comment
Share on other sites

Now i am running into a problem where it is returning both feet post, and eye pos.

 public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
  {
	World world = par3World;
	EntityPlayer ply = par2EntityPlayer;
	double posX = ply.lastTickPosX;
	double posY = ply.lastTickPosY;
	double posZ = ply.lastTickPosZ;
	System.out.println("X: " + posX);
	System.out.println("Y: " + posY);
	System.out.println("Z: " + posZ);
	System.out.println("Int 1: " + par4);
	System.out.println("Int 2: " + par5);
	System.out.println("Int 3: " + par6);
	System.out.println("Int 4: " + par7);
	System.out.println("Float 1: " + par8);
	System.out.println("Float 2: " + par9);
	System.out.println("Float 3: " + par10);

	return true;
}

This is what it outputs:

2013-05-12 15:02:17 [iNFO] [sTDOUT] X: 1573.8539209767246
2013-05-12 15:02:17 [iNFO] [sTDOUT] Y: 8.485128304470969
2013-05-12 15:02:17 [iNFO] [sTDOUT] Z: 35.771595298500344
2013-05-12 15:02:17 [iNFO] [sTDOUT] Int 1: 1574
2013-05-12 15:02:17 [iNFO] [sTDOUT] Int 2: 3
2013-05-12 15:02:17 [iNFO] [sTDOUT] Int 3: 35
2013-05-12 15:02:17 [iNFO] [sTDOUT] Int 4: 1
2013-05-12 15:02:17 [iNFO] [sTDOUT] Float 1: 0.03881836
2013-05-12 15:02:17 [iNFO] [sTDOUT] Float 2: 1.0
2013-05-12 15:02:17 [iNFO] [sTDOUT] Float 3: 0.87386703
2013-05-12 15:02:17 [iNFO] [sTDOUT] X: 1573.8539209767246
2013-05-12 15:02:17 [iNFO] [sTDOUT] Y: 6.865128299702597
2013-05-12 15:02:17 [iNFO] [sTDOUT] Z: 35.771595298500344
2013-05-12 15:02:17 [iNFO] [sTDOUT] Int 1: 1574
2013-05-12 15:02:17 [iNFO] [sTDOUT] Int 2: 3
2013-05-12 15:02:17 [iNFO] [sTDOUT] Int 3: 35
2013-05-12 15:02:17 [iNFO] [sTDOUT] Int 4: 1
2013-05-12 15:02:17 [iNFO] [sTDOUT] Float 1: 0.03881836
2013-05-12 15:02:17 [iNFO] [sTDOUT] Float 2: 1.0
2013-05-12 15:02:17 [iNFO] [sTDOUT] Float 3: 0.87386703

Link to comment
Share on other sites

You can find the block right clicked on with a Forge event. Heres some code:

@ForgeSubscribe
public void buildVillage(PlayerInteractEvent event)	
{
if (Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem() == youritemid)
  {
    //event.x, event.y,event.z are the block coordinates for the block you right clicked on
    
  //your code for generating
  }
}

Link to comment
Share on other sites

Oh, thank you :D, i will for sure try that out :D

 

Wait, how would i get my item in the if statement? Its probably obvious but im drawing a blank. Because it is asking for an itemstack but my item is an item...

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.