use of com.bewitchment.common.brew.BrewEffect in project Bewitchment by Um-Mitternacht.
the class BrewMessage method toBytes.
@Override
public void toBytes(ByteBuf buf) {
buf.writeLong(target.getMostSignificantBits());
buf.writeLong(target.getLeastSignificantBits());
buf.writeInt(effects.size());
for (BrewEffect effect : effects.values()) {
buf.writeInt(BrewRegistry.getBrewId(effect.getBrew()));
buf.writeInt(effect.getDuration());
buf.writeInt(effect.getAmplifier());
}
}
use of com.bewitchment.common.brew.BrewEffect in project Bewitchment by Um-Mitternacht.
the class EntityBrew method doSplash.
private void doSplash() {
AxisAlignedBB axisalignedbb = this.getEntityBoundingBox().expand(4.0D, 2.0D, 4.0D);
List<EntityLivingBase> list = this.world.getEntitiesWithinAABB(EntityLivingBase.class, axisalignedbb);
if (!list.isEmpty()) {
Tuple<List<BrewEffect>, List<PotionEffect>> tuple = BrewUtils.deSerialize(NBTHelper.fixNBT(getBrew()));
for (EntityLivingBase entity : list) {
double distance = this.getDistanceSq(entity);
if (distance < 16.0D) {
for (BrewEffect effect : tuple.getFirst()) {
BrewStorageHandler.addEntityBrewEffect(entity, effect.copy());
}
for (PotionEffect potioneffect : tuple.getSecond()) {
entity.addPotionEffect(new PotionEffect(potioneffect));
}
}
}
}
}
use of com.bewitchment.common.brew.BrewEffect in project Bewitchment 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;
}
use of com.bewitchment.common.brew.BrewEffect in project Bewitchment by Um-Mitternacht.
the class BrewHUD method renderOverlay.
@SubscribeEvent
public void renderOverlay(RenderGameOverlayEvent.Post event) {
if (!ConfigHandler.CLIENT.BREW_HUD.hide && event.getType() == RenderGameOverlayEvent.ElementType.ALL) {
Optional<IBrewStorage> optional = BrewStorageHandler.getBrewStorage(Minecraft.getMinecraft().player);
if (optional.isPresent()) {
ScaledResolution res = event.getResolution();
int xOffset = res.getScaledWidth() - ConfigHandler.CLIENT.BREW_HUD.x;
int yOffset = ConfigHandler.CLIENT.BREW_HUD.y;
Minecraft mc = Minecraft.getMinecraft();
Collection<BrewEffect> effects = optional.get().getBrewEffects();
if (effects.isEmpty())
return;
for (BrewEffect effect : effects) {
IBrew brew = effect.getBrew();
if (brew.shouldRender()) {
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
brew.renderHUD(xOffset, yOffset, mc, effect.getAmplifier());
if (ConfigHandler.CLIENT.BREW_HUD.orientation) {
yOffset += 22;
} else {
xOffset += 22;
}
GlStateManager.disableBlend();
GlStateManager.popMatrix();
}
}
}
}
}
use of com.bewitchment.common.brew.BrewEffect in project Bewitchment by Um-Mitternacht.
the class BrewEvents method onUpdate.
@SubscribeEvent
public void onUpdate(LivingEvent.LivingUpdateEvent event) {
EntityLivingBase entity = event.getEntityLiving();
Optional<IBrewStorage> optional = BrewStorageHandler.getBrewStorage(entity);
if (optional.isPresent()) {
IBrewStorage storage = optional.get();
Map<IBrew, BrewEffect> brews = storage.getBrewMap();
if (brews.isEmpty())
return;
boolean update = false;
if (!entity.world.isRemote && BrewStorageHandler.BREW_REMOVAL.containsKey(entity)) {
for (IBrew brew : BrewStorageHandler.BREW_REMOVAL.get(entity)) {
brews.get(brew).end(entity.world, entity.getPosition(), entity);
brews.remove(brew);
}
BrewStorageHandler.BREW_REMOVAL.remove(entity);
update = true;
}
Map<IBrew, BrewEffect> updated = new HashMap<>();
for (BrewEffect effect : brews.values()) {
if (effect.getDuration() <= 0) {
effect.end(entity.world, entity.getPosition(), entity);
update = true;
} else {
effect.update(entity.world, entity.getPosition(), entity);
updated.put(effect.getBrew(), effect);
}
}
if (!entity.world.isRemote) {
storage.setBrewMap(updated);
if (update) {
storage.syncToNear(entity);
}
}
}
}
Aggregations