-
Notifications
You must be signed in to change notification settings - Fork 497
/
LibraryBlueprintTypeHandler.java
59 lines (50 loc) · 1.54 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
package buildcraft.builders;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import buildcraft.BuildCraftBuilders;
import buildcraft.api.library.ILibraryTypeHandler;
import buildcraft.core.blueprints.BlueprintBase;
public class LibraryBlueprintTypeHandler implements ILibraryTypeHandler {
private final boolean isBlueprint;
public LibraryBlueprintTypeHandler(boolean isBlueprint) {
this.isBlueprint = isBlueprint;
}
@Override
public boolean isHandler(ItemStack stack, boolean store) {
if (isBlueprint) {
return stack.getItem() instanceof ItemBlueprintStandard;
} else {
return stack.getItem() instanceof ItemBlueprintTemplate;
}
}
@Override
public String getFileExtension() {
return isBlueprint ? "bpt" : "tpl";
}
@Override
public int getTextColor() {
return isBlueprint ? 0x305080 : 0;
}
@Override
public String getName(ItemStack stack) {
return ItemBlueprint.getId(stack).name;
}
@Override
public ItemStack load(ItemStack stack, NBTTagCompound compound) {
BlueprintBase blueprint = BlueprintBase.loadBluePrint(compound);
blueprint.id.name = compound.getString("__filename");
blueprint.id.extension = getFileExtension();
BuildCraftBuilders.serverDB.add(blueprint.id, compound);
return blueprint.getStack();
}
@Override
public boolean store(ItemStack stack, NBTTagCompound compound) {
BlueprintBase blueprint = ItemBlueprint.loadBlueprint(stack);
if (blueprint != null) {
blueprint.writeToNBT(compound);
blueprint.id.write(compound);
return true;
}
return false;
}
}