forked from phildier/dat_converter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.MVInv.php
106 lines (97 loc) · 2.54 KB
/
class.MVInv.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
class MVInv
{
public $SURVIVAL = null;
public function __construct()
{
$this->SURVIVAL = new StdClass();
}
public function addItem(ItemStack $item,$slot=null)
{
if(is_null($slot)) {
$this->SURVIVAL->inventoryContents[] = $item;
} else {
$this->SURVIVAL->inventoryContents->$slot = $item;
}
}
public function addArmor(ItemStack $armor)
{
list($mat,$type) = explode("_",$armor->type);
switch($type)
{
case "helmet":
$slot = 3;
break;
case "chestplate":
$slot = 2;
break;
case "leggings":
$slot = 1;
break;
case "boots":
$slot = 0;
break;
}
$this->SURVIVAL->armorContents->$slot = $armor;
}
public function addEnderChest(ItemStack $item, $slot=null)
{
if(is_null($slot)) {
$this->SURVIVAL->enderChestContents[] = $item;
} else {
$this->SURVIVAL->enderChestContents->$slot = $item;
}
}
public function loadInv($inventory)
{
print "MVInv: loading ".count($inventory)." items...\n";
foreach($inventory as $item) {
$itemstack = new ItemStack($item->id,$item->count,$item->damage);
if(!is_null($item->tag) && !is_null($item->tag->enchantments)) {
foreach($item->tag->enchantments as $ench) {
$itemstack->enchant($ench->id,$ench->level);
}
}
if(!is_null($item->tag) && !is_null($item->tag->stored_enchantments)) {
foreach($item->tag->stored_enchantments as $ench) {
$itemstack->enchantStored($ench->id,$ench->level);
}
}
if(!is_null($item->tag) && !is_null($item->tag->display)) {
$itemstack->display($item->tag->display);
}
if($item->slot < 100) {
$this->addItem($itemstack,$item->slot);
} else {
$this->addArmor($itemstack,($item->slot-100));
}
}
}
public function loadEnderInv($inventory)
{
print "MVInv: enderloading ".count($inventory)." items...\n";
foreach($inventory as $item) {
$itemstack = new ItemStack($item->id,$item->count,$item->damage);
if(!is_null($item->tag) && !is_null($item->tag->enchantments)) {
foreach($item->tag->enchantments as $ench) {
$itemstack->enchant($ench->id,$ench->level);
}
}
if(!is_null($item->tag) && !is_null($item->tag->stored_enchantments)) {
foreach($item->tag->stored_enchantments as $ench) {
$itemstack->enchantStored($ench->id,$ench->level);
}
}
if(!is_null($item->tag) && !is_null($item->tag->display)) {
$itemstack->display($item->tag->display);
}
if($item->slot < 100) {
$this->addEnderChest($itemstack,$item->slot);
}
}
}
public function writeJSON($json_file)
{
file_put_contents($json_file,json_encode($this));
}
}