-
Notifications
You must be signed in to change notification settings - Fork 497
/
LibraryBlueprintTypeHandler.java
66 lines (55 loc) · 1.88 KB
/
LibraryBlueprintTypeHandler.java
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
package buildcraft.builders;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import buildcraft.BuildCraftBuilders;
import buildcraft.api.library.LibraryTypeHandlerNBT;
import buildcraft.core.blueprints.BlueprintBase;
import buildcraft.core.blueprints.LibraryId;
public class LibraryBlueprintTypeHandler extends LibraryTypeHandlerNBT {
private final boolean isBlueprint;
public LibraryBlueprintTypeHandler(boolean isBlueprint) {
super(isBlueprint ? "bpt" : "tpl");
this.isBlueprint = isBlueprint;
}
@Override
public boolean isHandler(ItemStack stack, HandlerType type) {
if (isBlueprint) {
return stack.getItem() instanceof ItemBlueprintStandard && (type == HandlerType.LOAD || ItemBlueprint.isContentReadable(stack));
} else {
return stack.getItem() instanceof ItemBlueprintTemplate && (type == HandlerType.LOAD || ItemBlueprint.isContentReadable(stack));
}
}
@Override
public int getTextColor() {
return isBlueprint ? 0x305080 : 0;
}
@Override
public String getName(ItemStack stack) {
LibraryId id = ItemBlueprint.getId(stack);
return id != null ? id.name : "<<CORRUPT>>";
}
@Override
public ItemStack load(ItemStack stack, NBTTagCompound compound) {
BlueprintBase blueprint = BlueprintBase.loadBluePrint((NBTTagCompound) compound.copy());
blueprint.id.name = compound.getString("__filename");
blueprint.id.extension = getOutputExtension();
BuildCraftBuilders.serverDB.add(blueprint.id, compound);
return blueprint.getStack();
}
@Override
public boolean store(ItemStack stack, NBTTagCompound compound) {
LibraryId id = ItemBlueprint.getId(stack);
if (id == null) {
return false;
}
NBTTagCompound nbt = BuildCraftBuilders.serverDB.load(id);
if (nbt == null) {
return false;
}
for (Object o : nbt.func_150296_c()) {
compound.setTag((String) o, nbt.getTag((String) o));
}
id.write(compound);
return true;
}
}