-
Notifications
You must be signed in to change notification settings - Fork 18
/
PotionContentType.java
88 lines (79 loc) · 3.16 KB
/
PotionContentType.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package knightminer.inspirations.recipes.recipe.cauldron.contents;
import knightminer.inspirations.library.recipe.cauldron.contents.RegistryContentType;
import net.minecraft.ChatFormatting;
import net.minecraft.Util;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffectUtil;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.alchemy.PotionUtils;
import net.minecraftforge.registries.ForgeRegistries;
import javax.annotation.Nullable;
import java.util.List;
/**
* Potion content type
*/
@Deprecated
public class PotionContentType extends RegistryContentType<Potion> {
private static final String PREFIX = "item.minecraft.potion.effect.";
private final ResourceLocation textureName;
@Nullable
private final String wrapName;
/**
* Creates a new instance
* @param textureName Name of the texture for this type
* @param wrapName If true, name will be wrapped using a translation key from the texture name
*/
public PotionContentType(ResourceLocation textureName, boolean wrapName) {
super(ForgeRegistries.POTIONS);
this.textureName = textureName;
if (wrapName) {
this.wrapName = Util.makeDescriptionId("cauldron_contents", textureName);
} else {
this.wrapName = null;
}
}
@Override
public ResourceLocation getTexture(Potion value) {
return textureName;
}
@Override
public int getColor(Potion value) {
return PotionUtils.getColor(value);
}
@Override
public Component getDisplayName(Potion value) {
Component component = new TranslatableComponent(value.getName(PREFIX));
if (wrapName != null) {
return new TranslatableComponent(wrapName, component);
}
return component;
}
@Override
public void addInformation(Potion potion, List<Component> tooltip, TooltipFlag tooltipFlag) {
// strongly based on PotionUtil version, but takes a potion instead of a stack. main difference is it skips the no effects tooltip
for (MobEffectInstance instance : potion.getEffects()) {
MutableComponent effectString = new TranslatableComponent(instance.getEffect().getDescriptionId());
MobEffect effect = instance.getEffect();
if (instance.getAmplifier() > 0) {
effectString.append(" ");
effectString.append(new TranslatableComponent("potion.potency." + instance.getAmplifier()));
}
if (instance.getDuration() > 20) {
effectString.append(new TextComponent(" (" + MobEffectUtil.formatDuration(instance, 1.0f) + ")"));
}
effectString.withStyle(effect.isBeneficial() ? ChatFormatting.BLUE : ChatFormatting.RED);
tooltip.add(effectString);
}
// add tooltip for unfermented
if (wrapName != null) {
tooltip.add(new TranslatableComponent(wrapName + ".tooltip").withStyle(ChatFormatting.GRAY, ChatFormatting.ITALIC));
}
}
}