Last active
February 6, 2021 15:23
-
-
Save 06Games/c47e18c3729f3bc26a0518a02ebd03f4 to your computer and use it in GitHub Desktop.
Generate RP for Minecraft Bedrock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Init | |
| param ( | |
| [string]$pack = "Vanilla Raytraced", | |
| [string]$temp = "./.temp", | |
| [string]$vanilla = $($temp + "/vanilla"), | |
| [string]$tempPack = $($temp + "/pack"), | |
| [string]$export = $($temp + "/export"), | |
| [int]$verbose = 0 | |
| ) | |
| $host.ui.rawui.windowtitle="Generate" | |
| $debug = [bool]$verbose | |
| #---------------------# | |
| # Temp folder # | |
| #---------------------# | |
| Write-Host "`nCreating temp folder" -NoNewline | |
| if(Test-Path -Path $tempPack) { Remove-Item -Path $tempPack -Recurse -Force } | |
| Copy-Item -Path $("./" + $pack) -Destination $tempPack -Recurse -Force -Exclude "*~.*" | |
| Write-Host " (Done)" -ForegroundColor Green | |
| $subpacks = @(Get-Item $tempPack) | |
| if(Test-Path -Path $($tempPack + "/subpacks")) { $subpacks = (Get-ChildItem $($tempPack + "/subpacks") -Directory) } | |
| for($i=0; $i -lt $subpacks.length; $i++){ | |
| $subpack = $subpacks[$i] | |
| $packAbs = $subpack.FullName | |
| $tempSubpack = $tempPack + $packAbs.Replace($(Get-Item $tempPack).FullName, "") | |
| $vanillaAbs = (Get-Item $vanilla).FullName | |
| Write-Host $("`nWorking on the sub-pack named """ + $subpack.Name + """ (" + $($i+1) + "/" + $subpacks.length + ")") | |
| #---------------------# | |
| # Duplicated Files # | |
| #---------------------# | |
| Write-Host "`n`tFinding duplicate files" -NoNewline | |
| if($debug) { Write-Host "" } | |
| $duplicated = 0; | |
| foreach ($vanillaF in $(Get-ChildItem $vanilla -Recurse -File -Force)) { | |
| $packFpath = $vanillaF.FullName.Replace($vanillaAbs, $packAbs); | |
| if($debug) { Write-Host "`t`t" $vanillaF.FullName.Replace($vanillaAbs, "") -NoNewline; } | |
| if(Test-Path -Path $packFpath){ | |
| $packF = Get-Item $packFpath | |
| if($(Get-FileHash $vanillaF).Hash -eq $(Get-FileHash $packF).Hash){ | |
| Remove-Item -Path $packFpath -Force | |
| $duplicated += 1 | |
| if($debug) { Write-Host " (Duplicated)" -ForegroundColor Red } | |
| } | |
| elseif($debug) { Write-Host " (Not duplicated)" -ForegroundColor Green } | |
| } | |
| elseif($debug) { Write-Host " (Missing)" -ForegroundColor Yellow } | |
| } | |
| if($debug) { Write-Host "`t" -NoNewline -ForegroundColor Green } | |
| else { Write-Host " (" -NoNewline -ForegroundColor Green } | |
| Write-Host $("Removed " + $duplicated.ToString() + " files") -NoNewline -ForegroundColor Green | |
| if($debug) { Write-Host "" } else { Write-Host ")" -ForegroundColor Green } | |
| #---------------------# | |
| # Texture Set # | |
| #---------------------# | |
| Write-Host "`n`tList textures" -NoNewline | |
| $files = Get-ChildItem $vanilla\textures -Include *.png,*.tga,*.jpg,*.jpeg -Recurse -File -Force | |
| Write-Host $(" (" + $files.Length + " files found)") -ForegroundColor Green | |
| Write-Host "`n`tGenerating texture set files" -NoNewline | |
| if($debug) { Write-Host "" } | |
| foreach ($file in $files) { | |
| $tempRelative = $file.FullName.Replace($vanillaAbs, "").Replace($file.Extension, "") | |
| if($debug) { Write-Host "`t`t" $tempRelative -NoNewline; } | |
| $tempRelative = $tempSubpack + $tempRelative | |
| if ((Test-Path -Path $($tempRelative + "_mer.png")) -or (Test-Path -Path $($tempRelative + "_normal.png"))) { | |
| if (!$(Test-Path -Path $($tempRelative + ".png"))) { | |
| Copy-Item -Path $file -Destination $($tempRelative + ".png") -Force | |
| } | |
| $texture_set = "{`n`t""format_version"": ""1.16.100"",`n`t""minecraft:texture_set"": {" | |
| $texture_set += "`n`t`t""color"": """ + $file.Basename + """," | |
| if (Test-Path -Path $($tempRelative+ "_mer.png")) { $texture_set += "`n`t`t""metalness_emissive_roughness"": """ + $file.Basename + "_mer""" } | |
| if ((Test-Path -Path $($tempRelative + "_mer.png")) -and (Test-Path -Path $($tempRelative + "_normal.png"))) { $texture_set += "," } | |
| if (Test-Path -Path $($tempRelative+ "_normal.png")) { $texture_set += "`n`t`t""normal"": """ + $file.Basename + "_normal""" } | |
| $texture_set += "`n`t}`n}" | |
| Set-Content -Path $($tempRelative + ".texture_set.json") -Value $texture_set | |
| if($debug) { Write-Host " (Done)" -ForegroundColor Green } | |
| } elseif($debug) { Write-Host " (Ignored): No mer or normal file" -ForegroundColor Yellow } | |
| } | |
| if(!$debug) { Write-Host " (Done)" -ForegroundColor Green } | |
| } | |
| #---------------------# | |
| # .Mcpack # | |
| #---------------------# | |
| Write-Host "`nGenerating the .mcpack" -NoNewline | |
| New-Item -Path $export -ItemType Directory -Force | Out-Null | |
| Compress-Archive -Path $($temp + "/pack/*") -DestinationPath $($temp + "/export/export.zip") -Force | |
| Move-Item -Path $($temp + "/export/export.zip") -Destination $($temp + "/export/" + $pack + ".mcpack") -Force | |
| Write-Host " (Done)" -ForegroundColor Green | |
| #Done | |
| $host.ui.rawui.windowtitle="Generate (Done)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment