Skip to content
This repository has been archived by the owner on Jun 26, 2022. It is now read-only.

Commit

Permalink
Constraint features.
Browse files Browse the repository at this point in the history
  • Loading branch information
Luminoso-256 committed Jan 18, 2021
1 parent b2bca41 commit c6a396b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
40 changes: 36 additions & 4 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static void Main(string[] args)

Console.WriteLine("Minecraft Earth Buildplate File Format Editor \n Version " + version + "\n Enter path to input file:");
// String targetFilePath = Console.ReadLine();
String targetFilePath = @"C:\Workspace\Programming\c#\EarthBuildplateEditor\plates\test_c.plate";
String targetFilePath = @"C:\Workspace\Programming\c#\EarthBuildplateEditor\plates\test_b.plate";
if (!File.Exists(targetFilePath))
{
Console.WriteLine("Error: File does not exist");
Expand Down Expand Up @@ -52,18 +52,22 @@ static void Main(string[] args)
//Render Data
Dictionary<int, int> chunkAirValues = new Dictionary<int, int>();
Dictionary<int, List<Texture2D>> chunkTextures = new Dictionary<int, List<Texture2D>>();
Dictionary<int, List<int>> chunkConstraintValues = new Dictionary<int, List<int>>();

//editor data
int maxSubChunk = plate.sub_chunks.Count - 1;
String selectedBlock = "dirt";
bool cursorActive = false;
bool showConstraints = true;
Texture2D cursorTexture = LoadTexture(@"C:\Workspace\Programming\c#\EarthBuildplateEditor\earth_res\textures\custom\cursor.png");


//Texture load
Texture2D entityTex = LoadTexture(@"C:\Workspace\Programming\c#\EarthBuildplateEditor\earth_res\textures\entity\entitydummy.png");
for (int subchunk = 0; subchunk < plate.sub_chunks.Count; subchunk++)
{
List<Texture2D> textures = new List<Texture2D>() { };
List<int> constraints = new List<int>() { };
//Create the textures
for (int paletteIndex = 0; paletteIndex < plate.sub_chunks[subchunk].block_palette.Count; paletteIndex++)
{
Expand All @@ -74,9 +78,14 @@ static void Main(string[] args)
{
chunkAirValues.Add(subchunk, paletteIndex);
}
if (blockName.Contains("constraint"))
{
constraints.Add(paletteIndex);
}

}
chunkTextures.Add(subchunk, textures);
chunkConstraintValues.Add(subchunk, constraints);
}


Expand All @@ -99,15 +108,20 @@ static void Main(string[] args)
int origz;


//Draw Buildplate blocks
//Draw Buildplate blocks, and place
for (int currentBlock = 0; currentBlock < 4096; currentBlock++)
{

x++;

if (x == 16) { x = 0; y += 1; }
if (y == 16) { y = 0; z += 1; }

if (plate.sub_chunks[currentSubchunk].blocks[currentBlock] != chunkAirValues[currentSubchunk])
bool shouldRender = true;
if (plate.sub_chunks[currentSubchunk].blocks[currentBlock] == chunkAirValues[currentSubchunk]) { shouldRender = false; }
if (!showConstraints && chunkConstraintValues[currentSubchunk].Contains(plate.sub_chunks[currentSubchunk].blocks[currentBlock])) { shouldRender = false; }

if (shouldRender)
{
int textureIndex = plate.sub_chunks[currentSubchunk].blocks[currentBlock]; //index

Expand All @@ -132,6 +146,19 @@ static void Main(string[] args)
y -= 1;
}

//Check if we want to place/remove a block here. If so, we want to modify this array value.
if (camera.target == new Vector3(x, y, z) && IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON) && cursorActive) {
// left = destroy
plate.sub_chunks[currentSubchunk].blocks[currentBlock] = chunkAirValues[currentSubchunk];
}
if (camera.target == new Vector3(x, y, z) && IsMouseButtonPressed(MouseButton.MOUSE_RIGHT_BUTTON))
{
// right = place
//plate.sub_chunks[currentSubchunk].blocks[currentBlock] TODO: Add palette check code and what not :D

}

//Draw
DrawCubeTexture(textures[textureIndex], new Vector3(x, y, z), 1.0f, 1.0f, 1.0f, WHITE);
x = origx;
y = origy;
Expand All @@ -149,7 +176,7 @@ static void Main(string[] args)
//Draw Selection Cursor
if (cursorActive)
{
DrawCubeTexture(LoadTexture(textureBasePath + selectedBlock + ".png"), camera.target, 0.2f, 0.2f, 0.2f, GRAY);
DrawCubeTexture(cursorTexture, camera.target, 0.2f, 0.2f, 0.2f, GRAY);
}
EndMode3D();

Expand Down Expand Up @@ -186,9 +213,14 @@ static void Main(string[] args)
{
cursorActive = !cursorActive;
}
if (IsKeyPressed(KeyboardKey.KEY_V))
{
showConstraints = !showConstraints;
}

}
CloseWindow();
}

}
}
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ Currently very early, and much spagetti code

### Notes
- To get the resources, youl need to get your hands on a copy of Minecraft Earth's resouce pack and make some modifications. Copyright prohibits distribution.
- .plate is the unencrypted json of the Minecraft Earth tile format. .plate64 is this data with base64 encryption, as this is what the Minecraft Earth server uses
- .plate is the unencrypted json of the Minecraft Earth tile format. .plate64 is this data with base64 encryption, as this is what the Minecraft Earth server uses

### screenshots

![Plate A - no constraints](https://github.com/Luminoso-256/EarthBuildplateEditor/blob/main/readme/no_constraints.png)
![Plate A - constraints](https://github.com/Luminoso-256/EarthBuildplateEditor/blob/main/readme/constraints.png)
![Plate B](https://github.com/Luminoso-256/EarthBuildplateEditor/blob/main/readme/alt_plate.png)
Binary file added readme/alt_plate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added readme/no_constraints.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added readme/show_constraints.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c6a396b

Please sign in to comment.