Skip to content

Instantly share code, notes, and snippets.

@Azenet
Created May 29, 2014 19:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Azenet/26a458928b34cb818dae to your computer and use it in GitHub Desktop.
Save Azenet/26a458928b34cb818dae to your computer and use it in GitHub Desktop.
<?php
/*
* WTFPL
*
* Utilisation :
* 1) Ouvrir minecraft moddé
* 2) Aller dans les options de Not Enough Items
* 3) Tools > Data Dumps > Blocks/Items > Dump
* 4) Dans le dossier minecraft/dumps, copier item.csv et le mettre au même endroit que ce script
* 5) Exécuter le script
* 6) ???
* 7) PROFIT
*/
$csv = explode("\n", file_get_contents("item.csv"));
$head = str_getcsv(array_shift($csv));
$ids = array();
array_pop($csv);
foreach ($csv as $line) {
$line = str_getcsv($line);
$ids[$line[0]] = array(
'id' => $line[0],
'mod' => $line[2],
);
}
$mods = array();
foreach ($ids as $id) {
if (!isset($mods[$id['mod']])) $mods[$id['mod']] = array();
$mods[$id['mod']][$id['id']] = $id;
}
var_dump($mods);
$out = "";
foreach ($mods as $mod) {
$ranges = array();
$inrange = false;
$rangestart = 0;
$name = null;
for ($i = 0; $i <= 32005; $i++) {
if (isset($mod[$i])) {
$name = $mod[$i]['mod'];
if (!$inrange) {
$inrange = true;
$rangestart = $i;
}
} else {
if ($inrange) {
$ranges[] = array(
'start' => $rangestart,
'end' => $i - 1
);
$inrange = false;
$rangestart = 0;
}
}
}
$out .= "$name: ";
$content = false;
foreach ($ranges as $range) {
if ($range['start'] == $range['end']) $out .= $range['start'] . ", ";
else $out .= $range['start'] . "-" . $range['end'] . ", ";
$content = true;
}
if ($content) $out = substr($out, 0, -2);
$out .= "\n";
}
file_put_contents('out.file', $out);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment