use of com.witchworks.api.item.IBrew in project Witchworks by Um-Mitternacht.
the class BrewUtils method addBrewEffect.
public static ItemStack addBrewEffect(ItemStack stack, BrewEffect effect) {
NBTTagList list = addBrewData(stack);
NBTTagCompound tag = new NBTTagCompound();
IBrew brew = effect.getBrew();
tag.setInteger(BREW_ID, BrewRegistry.getBrewId(brew));
tag.setInteger(BREW_AMPLIFIER, effect.getAmplifier());
tag.setInteger(BREW_DURATION, effect.getDuration());
list.appendTag(tag);
return stack;
}
use of com.witchworks.api.item.IBrew 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.IBrew 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()));
}
}
}
use of com.witchworks.api.item.IBrew in project Witchworks by Um-Mitternacht.
the class PotionMessage method toBytes.
@Override
public void toBytes(ByteBuf buf) {
buf.writeLong(target.getMostSignificantBits());
buf.writeLong(target.getLeastSignificantBits());
buf.writeInt(client.size());
for (IBrew brew : client) {
buf.writeInt(BrewRegistry.getBrewId(brew));
}
}
Aggregations