Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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

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

  • Author

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);
            }
       }
    }

 

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

  • Author

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.