Social Icons

Sunday 6 May 2012

[TUT] Auto Tree Build [TUT]

I decided to have a go at an avo tree build thingy today. It took me about 5 mins.

In this hack, your saplings must be in the first slot on the hotbar and your bonemeal on the second.

I know a version of this has been posted but its not a real tut on how to do it.

The code is a modified version of dreams floor build code.

Of, first head off to PlayerControllerMP and search for

Code:
public boolean sendPlaceBlock(EntityPlayer entityplayer, World world, ItemStack itemstack, int i, int j, int k, int l)

underneath that create an if statement for if your variable is toggled. For me this is

Code:
if(Clickmevariables.build[2] == true)

Now we are going to add this line of code

Code:
ItemStack itemstack1 = mc.thePlayer.getCurrentEquippedItem();

This basically just makes it so we dont have to type out mc.thePlayer.getCurrentEquippedItem(); a few times later on.

We are now going to initiate a for loop that will define where the blocks are placed on the z axis. A good example of this is

Code:
for (int z = -4; z < 4; z++)

We are going to now create yet another for loop to determine where the blocks will be placed on the x axis. My example of this is

Code:
for (int x = -4; x < 4; x++)

Ok, you have now basically drawn a box that will be 8*8 around you.

We now have to add these lines of code

Code:
mc.thePlayer.inventory.currentItem = 0;
netClientHandler.addToSendQueue(new Packet16BlockItemSwitch(0));

Both of these lines of code are pretty self explanatory, you are setting the current hotbar item to slot 0

You now need to write the code to place your blocks (saplings).

Code:
netClientHandler.addToSendQueue(new Packet15Place(i, j, k, 1,  itemstack1));

Up until Packet15Place the code is self explanatory. After that it can be a little confusing.

the i variable is the X coordinate of the block place, j is Y coordinate of the block place and k is the Z coordinate of the block place. itemstack1 is what we initialised earlier.

To make the blocks place in your box we need to change the x and z coordinate of the block place as defined by the for loops. to do this just simply increment i by x and k by z

Code:
netClientHandler.addToSendQueue(new Packet15Place(i+x, j, k+z, 1,  itemstack1));

We now need to set the current inventory slot to 1 (the first slot in the hotbar) to do this add this code

Code:
mc.thePlayer.inventory.currentItem = 1;
netClientHandler.addToSendQueue(new Packet16BlockItemSwitch(1));

Now we need to send the place packets again

Code:
netClientHandler.addToSendQueue(new Packet15Place(i+x, j, k+z, 1,  itemstack1));

And now set the inventory slot to 0 again

Code:
mc.thePlayer.inventory.currentItem = 0;

Feel free to correct me if I have dun goofed in my code, I do it a lot :P


working example
Code:
        if(Clickmevariables.build[2] == true)
            {
                ItemStack itemstack1 = mc.thePlayer.getCurrentEquippedItem();
                for (int z = -4; z < 4; z++)
            {
                    for (int x = -4; x < 4; x++)
                    {
                        mc.thePlayer.inventory.currentItem = 0;
                        netClientHandler.addToSendQueue(new Packet16BlockItemSwitch(0));
                        netClientHandler.addToSendQueue(new Packet15Place(i+x, j, k+z, 1,  itemstack1));
                        mc.thePlayer.inventory.currentItem = 1;
                        netClientHandler.addToSendQueue(new Packet16BlockItemSwitch(1));
                        netClientHandler.addToSendQueue(new Packet15Place(i+x, j, k+z, 1,  itemstack1));       
                        mc.thePlayer.inventory.currentItem = 0;
                    }
             
            }

1 comment: