Jump to content

Recommended Posts

Posted

What I'm trying to do is set the blocks in a chunk to be stone based  on the users Y level. I think I have the right code, I just can't seem to find how to get the max X & Z and the Min X & Z. Any help would be great!

 

Chunk Chunk = par2World.getChunkFromBlockCoords((int)par3EntityPlayer.posX, (int)par3EntityPlayer.posZ);

        int X1 = Chunk.xPosition;

        int Z1 = Chunk.zPosition;

        int X2 = Chunk.xPosition + 15;

        int Z2 = Chunk.zPosition + 15;

 

This is what I have at the moment to get the Chunk Max X & Z & Min X & Z

Posted

Hi

 

I don't really understand what you mean "set blocks in a chunk based on the user's Y level".  And why do you need to access the chunk directly, why not just use the world instead?

 

-TGG

 

Well, the idea is that, when you are in the chunk, when the item is used, the chunk will get a layer of stone underneath the player.

 

Here's the code:

 

public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    {
    	if(!par2World.isRemote){
        par2World.setBlock((int)par3EntityPlayer.posX, (int)par3EntityPlayer.posY -1, (int)par3EntityPlayer.posZ - 1, Blocks.stone);

        Chunk Chunk = par2World.getChunkFromBlockCoords((int)par3EntityPlayer.posX, (int)par3EntityPlayer.posZ);
        int X1 = Chunk.xPosition;
        int Z1 = Chunk.zPosition;
        Reference.printGame(String.valueOf(Chunk.xPosition), par3EntityPlayer);
        Reference.printGame(String.valueOf(Chunk.zPosition), par3EntityPlayer);
        int X2 = Chunk.xPosition + 15;
        int Z2 = Chunk.zPosition + 15;
        
        if(!par2World.isRemote){
        Reference.fillChunk(X2, Z2, par2World, par3EntityPlayer, Blocks.stone);
        
        par2World.setBlock(X1, (int) par3EntityPlayer.posY - 1, Z1, Blocks.stone);
        }
        
    	}
       	return par1ItemStack;
    }

 

        par2World.setBlock((int)par3EntityPlayer.posX, (int)par3EntityPlayer.posY -1, (int)par3EntityPlayer.posZ - 1, Blocks.stone);

This piece of code was to get the block placing function right

 

    public static void fillChunk(int X, int Z, World par1World, Entity Player, Block Block){
        for(int i=1; i<17; i++){
        	printConsole("Count is: " + i);
        	par1World.setBlock(X, (int)Player.posY -1, Z, Block);
            for(int j=1; j<17; j++){
            	printConsole("Count is: " + String.valueOf(i) + j);
            	par1World.setBlock(X, (int)Player.posY -1, Z, Block);
            }
       }
    }

 

Posted

Hi

 

OK I understand now.

 

If you want to find the 16 x 16 blocks in a chunk, you can calculate it from the player x,z position using code something like this

 

minWX = playerXpos & ~0x0f;  // throws away the bottom four bits, i.e. truncates to the next lowest multiple of 16, eg 32, 16, 0, -16, -32 etc
minWZ = playerZpos & ~0x0f;
maxWX = minWX + 15;
maxWZ = minWZ + 15;

for (wx = minWX; wx <= maxWX; ++wx) {
  for (wz = minWZ; wz <= mazWZ; ++wz) {
     // setblock (wx, playerYpos - 1, wz)

 

-TGG

Posted

Hi

 

OK I understand now.

 

If you want to find the 16 x 16 blocks in a chunk, you can calculate it from the player x,z position using code something like this

 

minWX = playerXpos & ~0x0f;  // throws away the bottom four bits, i.e. truncates to the next lowest multiple of 16, eg 32, 16, 0, -16, -32 etc
minWZ = playerZpos & ~0x0f;
maxWX = minWX + 15;
maxWZ = minWZ + 15;

for (wx = minWX; wx <= maxWX; ++wx) {
  for (wz = minWZ; wz <= mazWZ; ++wz) {
     // setblock (wx, playerYpos - 1, wz)

 

-TGG

 

Thanks TGG :D You're a massive help!

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.