use of net.minecraft.potion.PotionEffect in project MinecraftForge by MinecraftForge.
the class PotionCurativeItemDebug method preInit.
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent evt) {
Item medicine = new Medicine().setRegistryName(MOD_ID, "medicine");
GameRegistry.register(medicine);
Potion incurablePotion = new IncurablePotion().setRegistryName(MOD_ID, "incurable_potion");
GameRegistry.register(incurablePotion);
// Register PotionType that can be cured with medicine
PotionEffect curable = new PotionEffect(incurablePotion, 1200);
curable.setCurativeItems(Collections.singletonList(new ItemStack(medicine)));
GameRegistry.register(new PotionType(curable).setRegistryName(MOD_ID, "curable_potion_type"));
// Register PotionType that can't be cured
GameRegistry.register(new PotionType(new PotionEffect(incurablePotion, 1200)).setRegistryName(MOD_ID, "incurable_potion_type"));
}
use of net.minecraft.potion.PotionEffect in project Witchworks by Um-Mitternacht.
the class BrewUtils method serialize.
public static NBTTagCompound serialize(Collection<Object> collection) {
List<BrewEffect> brewEffects = new ArrayList<>();
List<PotionEffect> potionEffects = new ArrayList<>();
for (Object brew : collection) {
if (brew instanceof BrewEffect) {
brewEffects.add((BrewEffect) brew);
} else if (brew instanceof PotionEffect) {
potionEffects.add((PotionEffect) brew);
}
}
NBTTagCompound compound = new NBTTagCompound();
appendPotions(compound, mixPotions(potionEffects));
appendBrews(compound, mixBrews(brewEffects));
return compound;
}
use of net.minecraft.potion.PotionEffect in project Witchworks by Um-Mitternacht.
the class BrewUtils method appendPotions.
public static void appendPotions(NBTTagCompound tag, Collection<PotionEffect> effects) {
NBTTagList tagList = tag.getTagList("CustomPotionEffects", 9);
for (PotionEffect potioneffect : effects) {
tagList.appendTag(potioneffect.writeCustomPotionEffectToNBT(new NBTTagCompound()));
}
tag.setTag("CustomPotionEffects", tagList);
}
use of net.minecraft.potion.PotionEffect in project Witchworks by Um-Mitternacht.
the class BrewUtils method addPotionTooltip.
@SideOnly(Side.CLIENT)
public static void addPotionTooltip(ItemStack itemIn, List<String> tooltip, float durationFactor) {
List<PotionEffect> list = PotionUtils.getEffectsFromStack(itemIn);
List<Tuple<String, AttributeModifier>> attributes = Lists.newArrayList();
if (list.isEmpty()) {
String empty = I18n.format("effect.none").trim();
tooltip.add(TextFormatting.GRAY + empty);
} else {
for (PotionEffect effect : list) {
StringBuilder string = new StringBuilder();
string.append(I18n.format(effect.getEffectName()).trim());
Potion potion = effect.getPotion();
Map<IAttribute, AttributeModifier> map = potion.getAttributeModifierMap();
if (!map.isEmpty()) {
for (Map.Entry<IAttribute, AttributeModifier> entry : map.entrySet()) {
AttributeModifier attribute = entry.getValue();
attribute = new AttributeModifier(attribute.getName(), potion.getAttributeModifierAmount(effect.getAmplifier(), attribute), attribute.getOperation());
attributes.add(new Tuple<>(entry.getKey().getName(), attribute));
}
}
if (effect.getAmplifier() > 0) {
string.append(" ").append(RomanNumber.getRoman(effect.getAmplifier()));
}
if (effect.getDuration() > 20) {
string.append(" (").append(Potion.getPotionDurationString(effect, durationFactor)).append(")");
}
if (potion.isBadEffect()) {
tooltip.add(TextFormatting.DARK_RED + string.toString());
} else {
tooltip.add(TextFormatting.DARK_BLUE + string.toString());
}
}
}
if (!attributes.isEmpty()) {
tooltip.add("");
tooltip.add(TextFormatting.DARK_PURPLE + I18n.format("potion.whenDrank"));
for (Tuple<String, AttributeModifier> tuple : attributes) {
AttributeModifier modifier = tuple.getSecond();
double amount = modifier.getAmount();
double newAmount;
if (modifier.getOperation() != 1 && modifier.getOperation() != 2) {
newAmount = modifier.getAmount();
} else {
newAmount = modifier.getAmount() * 100.0D;
}
if (amount > 0.0D) {
tooltip.add(TextFormatting.BLUE + I18n.format("attribute.modifier.plus." + modifier.getOperation(), ItemStack.DECIMALFORMAT.format(newAmount), I18n.format("attribute.name." + (String) tuple.getFirst())));
} else if (amount < 0.0D) {
newAmount = newAmount * -1.0D;
tooltip.add(TextFormatting.RED + I18n.format("attribute.modifier.take." + modifier.getOperation(), ItemStack.DECIMALFORMAT.format(newAmount), I18n.format("attribute.name." + (String) tuple.getFirst())));
}
}
}
}
use of net.minecraft.potion.PotionEffect in project Witchworks by Um-Mitternacht.
the class BrewSimpleModifier method apply.
@Override
public boolean apply(List<Object> brews, Object current) {
if (current instanceof PotionEffect) {
PotionEffect effect = (PotionEffect) current;
if (effect.getDuration() < 9600) {
int hue = MathHelper.clamp(effect.getDuration() + duration, 0, 9600);
effect.combine(new PotionEffect(effect.getPotion(), hue, effect.getAmplifier()));
}
if (effect.getAmplifier() < 3) {
int hue = MathHelper.clamp(effect.getAmplifier() + amplifier, 0, 3);
effect.combine(new PotionEffect(effect.getPotion(), effect.getDuration(), hue));
}
} else if (current instanceof BrewEffect) {
BrewEffect effect = (BrewEffect) current;
if (effect.getDuration() < 9600) {
int hue = MathHelper.clamp(effect.getDuration() + duration, 0, 9600);
effect.setDuration(hue);
}
if (effect.getAmplifier() < 3) {
int hue = MathHelper.clamp(effect.getAmplifier() + amplifier, 0, 3);
effect.setAmplifier(hue);
}
}
return true;
}
Aggregations