I've been toying around with an idea to make a Movecraft style mod except with larger jump intervals than just 1 unit. I want to be able to build a craft and then jump it several hundreds of units away based on a user-defined co-ordinate. I have a fairly basic knowledge of object oriented Java programming and I can learn as I go, but the question I have is how much would be involved in making a selected box around something, and moving everything in that box to a different co-ordinate based on user input? I just want to start off by moving a couple blocks at a time and then moving up from there.
I did not understand half of what it sounds like a cool mod :smile.gif:
All I want to do is define an area in which all blocks inside of that area are linked, and then moved in relation to each other to a different set of co-ordinates.
for(int x = 0; x < length; x++)
{
for(int y = 0; y < height; y++)
{
for(int z = 0; z < width; z++)
{
}
}
}
This loopset would process every coordinate inside a box of the specified size.
To get the processed coordinate, simply take whatever origin of the axis you need, and add the loop variable of the axis. That means the coordinates would be originX + x, originY + y, originZ + z.
For your specific operation of copying, you could add this code inside the inner loop:
int block = world.getBlockId(originalOriginX + x, originalOriginY + y, originalOriginZ + z);
world.setBlock(targetOriginX + x, targetOriginY + y, targetOriginZ + z, block);
A replacement method would be like this:
int block = world.getBlockId(originalOriginX + x, originalOriginY + y, originalOriginZ + z);
int block2 = world.getBlockId(targetOriginX + x, targetOriginY + y, targetOriginZ + z);
world.setBlock(targetOriginX + x, targetOriginY + y, targetOriginZ + z, block);
world.setBlock(originalOriginX + x, originalOriginY + y, originalOriginZ + z, block2);
With movement of ships, I assume sometimes a ship will be moved to an area already inside its bounding box. The solution would be to first save the entire area inside a byte array.
The length of this array would be length*height*width.
Then you would need to add an integer to maintain the counting. This integer will be ++'d whenever a loop is finished. Its standard value has to be 0.
The code would be like this:
byte[] ablock = new byte[length*height*width];
int count = 0;
for(int x = 0; x < length; x++)
{
for(int y = 0; y < height; y++)
{
for(int z = 0; z < width; z++)
{
ablock[count] = world.getBlockId(originalOriginX + x, originalOriginY + y, originalOriginZ + z);
world.setBlock(originalOriginX + x, originalOriginY + y, originalOriginZ + z, 0);
count++;
}
}
}
But that's only the copying. It would require pasting as well:
count = 0;
for(int x = 0; x < length; x++)
{
for(int y = 0; y < height; y++)
{
for(int z = 0; z < width; z++)
{
world.setBlock(targetOriginX + x, targetOriginY + y, targetOriginZ + z, ablock[count]);
count++;
}
}
}
Another thought just struck me. You will have to set the metadata as well in case some of the blocks inside take use of it. The solution would be to add another array for metadata as well. I guess you have the knowledge how to now!
With movement of ships, I assume sometimes a ship will be moved to an area already inside its bounding box. The solution would be to first save the entire area inside a byte array.
The length of this array would be length*height*width.
Then you would need to add an integer to maintain the counting. This integer will be ++'d whenever a loop is finished. Its standard value has to be 0.
The code would be like this:
byte[] ablock = new byte[length*height*width];
int count = 0;
for(int x = 0; x < length; x++)
{
for(int y = 0; y < height; y++)
{
for(int z = 0; z < width; z++)
{
ablock[count] = world.getBlockId(originalOriginX + x, originalOriginY + y, originalOriginZ + z);
world.setBlock(originalOriginX + x, originalOriginY + y, originalOriginZ + z, 0);
count++;
}
}
}
But that's only the copying. It would require pasting as well:
count = 0;
for(int x = 0; x < length; x++)
{
for(int y = 0; y < height; y++)
{
for(int z = 0; z < width; z++)
{
world.setBlock(targetOriginX + x, targetOriginY + y, targetOriginZ + z, ablock[count]);
count++;
}
}
}
Another thought just struck me. You will have to set the metadata as well in case some of the blocks inside take use of it. The solution would be to add another array for metadata as well. I guess you have the knowledge how to now!
Wow, thanks! I'm still new to the whole Minecraft coding thing so I've gotta figure out how to get all this working :tongue.gif:
With a bunch of different types of blocks (Eg. Stone, Wool, Obsidian.etc), how would I be able to take ALL blocks within the selected cuboid of space to move to another place?
Also, With the example you have shown me, would it be the
The whole idea of the array is to save all the block IDs inside the selected area in the array, and then being able to paste this by getting the block IDs stored in the array. For example, a chunk contains block data for a 16x128x16 blocks, which means it has a byte array of the length 16*128*16. Using some bit shifting and logic(I won't go into this) you are able to extract a block in the specified coordinate of the chunk. You will only be using a simple counting system, however.
The user input would consist of quite a lot of variables. It would be the origin of the original on all the axes, the origin of the target on all the axes, and the length, height and width. The only connection the user input has to the byte array is clearly shown.
Alright, so lets say that I pre-define the size of the cuboid and just build my "ship" inside this cuboid. That way, all I would have to worry about is taking all of the blocks inside the cuboid and moving it to another position. If it were pre-defined (The region), would that make it easier? Keep in mind, I'm still figuring out how to do most of this stuff.
All I want to do is define an area in which all blocks inside of that area are linked, and then moved in relation to each other to a different set of co-ordinates.
This loopset would process every coordinate inside a box of the specified size.
To get the processed coordinate, simply take whatever origin of the axis you need, and add the loop variable of the axis. That means the coordinates would be originX + x, originY + y, originZ + z.
For your specific operation of copying, you could add this code inside the inner loop:
A replacement method would be like this:
The length of this array would be length*height*width.
Then you would need to add an integer to maintain the counting. This integer will be ++'d whenever a loop is finished. Its standard value has to be 0.
The code would be like this:
But that's only the copying. It would require pasting as well:
Another thought just struck me. You will have to set the metadata as well in case some of the blocks inside take use of it. The solution would be to add another array for metadata as well. I guess you have the knowledge how to now!
Wow, thanks! I'm still new to the whole Minecraft coding thing so I've gotta figure out how to get all this working :tongue.gif:
Also, With the example you have shown me, would it be the
That would be used to assign the user-input to?
The user input would consist of quite a lot of variables. It would be the origin of the original on all the axes, the origin of the target on all the axes, and the length, height and width. The only connection the user input has to the byte array is clearly shown.