-
Notifications
You must be signed in to change notification settings - Fork 18
/
MixedDyedBottleItem.java
61 lines (54 loc) · 1.98 KB
/
MixedDyedBottleItem.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
package knightminer.inspirations.recipes.item;
import knightminer.inspirations.common.Config;
import knightminer.inspirations.common.item.HidableItem;
import knightminer.inspirations.library.Util;
import knightminer.inspirations.recipes.InspirationsRecipes;
import net.minecraft.item.DyeColor;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraftforge.common.util.Constants;
public class MixedDyedBottleItem extends HidableItem {
private static final String TAG_COLOR = "color";
public MixedDyedBottleItem(Properties props) {
super(props, Config::enableCauldronDyeing);
}
/**
* Get a dye bottle with the specified color.
* @param color Armor-style dye color
* @return A single bottle.
*/
public static ItemStack bottleFromDye(int color) {
DyeColor dyeColor = Util.getDyeForColor(color);
if (dyeColor != null) {
return new ItemStack(InspirationsRecipes.simpleDyedWaterBottle.get(dyeColor));
}
ItemStack result = new ItemStack(InspirationsRecipes.mixedDyedWaterBottle);
CompoundNBT tags = new CompoundNBT();
CompoundNBT display = new CompoundNBT();
display.putInt(TAG_COLOR, color);
tags.put("display", display);
result.setTag(tags);
return result;
}
/**
* Return the color for this bottle, if it has one.
* @param bottle A stack holding a dye bottle
* @return The armor-style color, or -1 if not a bottle.
*/
public static int dyeFromBottle(ItemStack bottle) {
Item item = bottle.getItem();
if (item instanceof SimpleDyedBottleItem) {
return ((SimpleDyedBottleItem)item).getColor().colorValue;
} else if (item == InspirationsRecipes.mixedDyedWaterBottle) {
CompoundNBT tags = bottle.getTag();
if (tags != null) {
CompoundNBT display = tags.getCompound("display");
if (display.contains(TAG_COLOR, Constants.NBT.TAG_INT)) {
return display.getInt(TAG_COLOR);
}
}
}
return -1;
}
}