use of com.witchworks.api.item.BrewEffect in project Witchworks by Um-Mitternacht.
the class ItemBrew method addInformation.
@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) {
if (NBTHelper.hasTag(stack, BrewUtils.BREW_DESC)) {
tooltip.add(TextFormatting.ITALIC + I18n.format(NBTHelper.getString(stack, BrewUtils.BREW_DESC)));
}
if (GuiScreen.isShiftKeyDown()) {
tooltip.add(TextFormatting.DARK_GRAY + "" + TextFormatting.ITALIC + I18n.format("tooltip.brew.data"));
List<BrewEffect> brewsFromStack = BrewUtils.getBrewsFromStack(stack);
for (BrewEffect effect : brewsFromStack) {
if (effect == null)
break;
IBrew brew = effect.getBrew();
String info = " - " + TextFormatting.ITALIC + I18n.format(brew.getName()).replace(" Brew", "") + " ";
info += RomanNumber.getRoman(effect.getAmplifier() + 1) + " ";
info += "(" + StringUtils.ticksToElapsedTime(effect.getDuration()) + ")";
tooltip.add(TextFormatting.DARK_AQUA + info);
}
if (brewsFromStack.isEmpty()) {
tooltip.add("---");
} else
tooltip.add("");
BrewUtils.addPotionTooltip(stack, tooltip, 1.0F);
} else {
tooltip.add(TextFormatting.DARK_GRAY + "" + TextFormatting.ITALIC + I18n.format("tooltip.shift_for_info"));
}
}
use of com.witchworks.api.item.BrewEffect in project Witchworks by Um-Mitternacht.
the class BrewUtils method getBrewsFromStack.
public static List<BrewEffect> getBrewsFromStack(ItemStack stack) {
List<BrewEffect> effects = new ArrayList<>();
NBTTagList list = NBTHelper.getNBT(stack, BREW_DATA);
for (int i = 0, size = list.tagCount(); i < size; i++) {
NBTTagCompound tag = list.getCompoundTagAt(i);
IBrew brew = BrewRegistry.getBrewById(tag.getInteger(BREW_ID));
int duration = tag.getInteger(BREW_DURATION);
int amplifier = tag.getInteger(BREW_AMPLIFIER);
effects.add(new BrewEffect(brew, duration, amplifier));
}
return effects;
}
use of com.witchworks.api.item.BrewEffect in project Witchworks by Um-Mitternacht.
the class BrewUtils method mixBrews.
public static Collection<BrewEffect> mixBrews(Collection<BrewEffect> effects) {
List<BrewEffect> list = new ArrayList<>();
for (BrewEffect effect : effects) {
effects.stream().filter(added -> effect != added && effect.getBrew() == added.getBrew()).forEach(added -> {
effect.combine(added);
list.add(added);
});
}
effects.removeAll(list);
return effects;
}
use of com.witchworks.api.item.BrewEffect in project Witchworks by Um-Mitternacht.
the class BrewUtils method appendBrews.
public static void appendBrews(NBTTagCompound tag, Collection<BrewEffect> effects) {
NBTTagList list = new NBTTagList();
tag.setTag(BREW_DATA, list);
for (BrewEffect effect : effects) {
NBTTagCompound compound = new NBTTagCompound();
IBrew brew = effect.getBrew();
compound.setInteger(BREW_ID, BrewRegistry.getBrewId(brew));
compound.setInteger(BREW_AMPLIFIER, effect.getAmplifier());
compound.setInteger(BREW_DURATION, effect.getDuration());
list.appendTag(compound);
}
}
use of com.witchworks.api.item.BrewEffect in project Witchworks by Um-Mitternacht.
the class BrewEvents method onUpdate.
@SubscribeEvent
public void onUpdate(LivingEvent.LivingUpdateEvent event) {
final EntityLivingBase entity = event.getEntityLiving();
if (entity == null)
return;
Optional<IBrewStorage> optional = BrewStorageHandler.getBrewStorage(entity);
if (optional.isPresent()) {
IBrewStorage storage = optional.get();
Map<IBrew, BrewEffect> brews = storage.getBrews();
if (brews.isEmpty())
return;
Map<IBrew, BrewEffect> updated = new HashMap<>();
for (IBrew brew : brews.keySet()) {
BrewEffect effect = brews.get(brew);
if (effect.isInstant() || effect.getDuration() <= 0) {
effect.end(entity.world, entity.getPosition(), entity);
} else {
effect.update(entity.world, entity.getPosition(), entity);
updated.put(effect.getBrew(), effect);
}
}
storage.setBrews(updated);
if (entity instanceof EntityPlayer) {
PacketHandler.sendTo((EntityPlayerMP) entity, new PotionMessage(updated.keySet(), entity.getUniqueID()));
}
}
}
Aggregations