use of com.bewitchment.api.capability.IBrewStorage in project Bewitchment by Um-Mitternacht.
the class BrewEvents method onPlayerClone.
@SubscribeEvent
public void onPlayerClone(Clone event) {
if (!event.isWasDeath()) {
final EntityPlayer oldPlayer = event.getOriginal();
final EntityPlayer newPlayer = event.getEntityPlayer();
Optional<IBrewStorage> optional = BrewStorageHandler.getBrewStorage(oldPlayer);
optional.ifPresent(oldStorage -> BrewStorageHandler.getBrewStorage(newPlayer).ifPresent(newStorage -> {
newStorage.setBrewMap(oldStorage.getBrewMap());
newStorage.syncToNear(newPlayer);
}));
}
}
use of com.bewitchment.api.capability.IBrewStorage 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.api.capability.IBrewStorage in project Bewitchment by Um-Mitternacht.
the class BrewEvents method onEntityStartTracking.
@SubscribeEvent
public void onEntityStartTracking(StartTracking event) {
Entity entity = event.getTarget();
EntityPlayer player = event.getEntityPlayer();
if (!entity.world.isRemote && entity != player && entity instanceof EntityLivingBase && player instanceof EntityPlayerMP) {
Optional<IBrewStorage> optional = BrewStorageHandler.getBrewStorage((EntityLivingBase) entity);
if (optional.isPresent()) {
IBrewStorage storage = optional.get();
storage.syncTo((EntityPlayerMP) event.getEntityPlayer());
}
}
}
use of com.bewitchment.api.capability.IBrewStorage 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);
}
}
}
}
use of com.bewitchment.api.capability.IBrewStorage in project Bewitchment by Um-Mitternacht.
the class BrewStorageHandler method addEntityBrewEffect.
/**
* Add a BrewEffect to the entity.
*
* @param entity The entity
* @param effect The effect
*/
public static void addEntityBrewEffect(EntityLivingBase entity, BrewEffect effect) {
Optional<IBrewStorage> optional = BrewStorageHandler.getBrewStorage(entity);
if (optional.isPresent()) {
IBrewStorage storage = optional.get();
BrewEffect active = storage.getBrew(effect.getBrew());
if (active == null || effect.getDuration() > active.getDuration()) {
storage.addBrew(entity, effect);
}
}
}
Aggregations