Jump to content

Recommended Posts

Posted

I have this code that executes each worldtick:

 

Random random = new Random();
	int randX = random.nextInt(16);
	//int randY = random.nextInt(256);
	int randZ = random.nextInt(16);
	int randY = EAToolkit.getTopBlock(world, randX, randZ);
	int j1 = random.nextInt();

	int i2 = MathHelper.floor_double(focusPlayer.posX);
	int k2 = MathHelper.floor_double(focusPlayer.posZ);
	byte byte0 = 7;
	for(int i3 = -byte0; i3 <= byte0; i3++)
	{
		for(int k3 = -byte0; k3 <= byte0; k3++)
		{
			int l3 = i3 * 16 + i2;
			int i4 = k3 * 16 + k2;
			j1 = j1 * 3 + 0x3c6ef35f;
			int j4 = j1 >> 2;
			int k4 = j4 & 0xf;
			int l4 = j4 >> 8 & 0xf;
			int i5 = k4 + l3;
			int j5 = l4 + i4;

			if(phase >= 1)
			{
				blockBuffer++;

				if(blockBuffer >= 60)
				{
					BlockPos blk = new BlockPos(randX, randY, randZ);
					Chunk chunk = world.getChunkFromChunkCoords(i5 + (int)focusPlayer.posX, j5 + (int)focusPlayer.posZ);
					Block block = chunk.getBlock(blk);

					if(block == Blocks.grass)
					{
						chunk.setBlockState(blk, Blocks.dirt.getDefaultState());
					}

					if(block == Blocks.leaves)
					{
						chunk.setBlockState(blk, Blocks.air.getDefaultState());
					}

					blockBuffer = 0;
				}
			}
		}
	}

 

It is supposed to get a random block near the player, and if it is either leaves or grass, change the block to air or dirt.

However, the code doesn't seem to be working. I have put debug System.out.println() calls in the code for the grass, and it does work, but no grass changes.

 

Any and all help is appreciated.

Posted

The math you're doing is extremely crazy. Why are you doing all that? That one hexadecimal number you're adding is probably like way outside the entire game, it wouldn't be close to the player.

 

Why don't you just use the randX and randZ and add those to the player position. That's all you should need for random position near the player.

 

If you insist on doing that crazy math, put a system console statement after every line that prints out the value calculated and check that it is what you expect.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

int l3 = i3 * 16 + i2;
int i4 = k3 * 16 + k2;
j1 = j1 * 3 + 0x3c6ef35f;
int j4 = j1 >> 2;
int k4 = j4 & 0xf;
int l4 = j4 >> 8 & 0xf;
int i5 = k4 + l3;
int j5 = l4 + i4;

 

Hold on.

 

Is that a pseudo-random number generator?

Why?  Why for the love of god did you write your own RNG and then supply it with inputs that were already random?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Substituting the RNG for randX and randZ also does nothing.

 

By adding a println() call to the grass if() statement produces more action with the RNG than randX and randZ.

But nothing happens in the world.

Posted

I don't think you understood.

 

Also, the world already had a random number generator so no real need to create a new one each tick.

 

Next, you don't need to do anything with chunks. World is able to set blocks and get blocks directly from the world coordinates.

 

So I think your code should simply be (assumes you have event parameter from WorldTickEvent handler method):

 

      int playerPosX = MathHelper.floor_double(focusPlayer.posX);

      int playerPosY = MathHelper.floor_double(focusPlayer.posY);

      int playerPosZ = MathHelper.floor_double(focusPlayer.posZ);

      byte effectRange = 7;

      for(int xOffset = -effectRange; xOffset <= effectRange; xOffset++)

      {

          for(int zOffset = -effectRange; zOffset <= effectRange; zOffset++)

          {

            if(phase >= 1)

              {

                  blockBuffer++;

                 

                  if(blockBuffer >= 60)

                  {

                      BlockPos blockPos = new BlockPos(event.world.rand.nextInt(16)+playerPosX, playerPosY, event.world.rand.nextInt(16)+playerPosZ);

                      Block theBlock = event.world.getBlockState(blockPos).getBlock();

                     

                      if(theBlock == Blocks.grass)

                      {

                          event.world.setBlockState(blockPos, Blocks.dirt.getDefaultState());

                      }

                     

                      if(theBlock == Blocks.leaves)

                      {

                          event.world.setBlockState(blockPos, Blocks.air.getDefaultState());

                      }

                     

                      blockBuffer = 0;

                  }

              }

          }

      }

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.