use of com.witchworks.common.core.capability.potion.IBrewStorage in project Witchworks by Um-Mitternacht.
the class BrewEvents method onWorldJoin.
@SubscribeEvent
public void onWorldJoin(EntityJoinWorldEvent event) {
if (event.getEntity() instanceof EntityPlayerMP) {
EntityPlayerMP entity = (EntityPlayerMP) event.getEntity();
Optional<IBrewStorage> optional = BrewStorageHandler.getBrewStorage(entity);
if (optional.isPresent()) {
PacketHandler.sendTo(entity, new PotionMessage(optional.get().getBrews().keySet(), entity.getUniqueID()));
}
}
}
use of com.witchworks.common.core.capability.potion.IBrewStorage in project Witchworks by Um-Mitternacht.
the class BrewEvents method onPlayerClone.
@SuppressWarnings("ConstantConditions")
@SubscribeEvent
public void onPlayerClone(net.minecraftforge.event.entity.player.PlayerEvent.Clone event) {
final EntityPlayer oldPlayer = event.getOriginal();
final EntityPlayer newPlayer = event.getEntityPlayer();
if (event.isWasDeath() && oldPlayer.hasCapability(BrewStorageProvider.BREW_STORAGE_CAPABILITY, null) && newPlayer.hasCapability(BrewStorageProvider.BREW_STORAGE_CAPABILITY, null)) {
final IBrewStorage oldCap = oldPlayer.getCapability(BrewStorageProvider.BREW_STORAGE_CAPABILITY, null);
final IBrewStorage newCap = oldPlayer.getCapability(BrewStorageProvider.BREW_STORAGE_CAPABILITY, null);
newCap.setBrews(oldCap.getBrews());
}
}
use of com.witchworks.common.core.capability.potion.IBrewStorage 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.common.core.capability.potion.IBrewStorage in project Witchworks by Um-Mitternacht.
the class BrewHUD method renderOverlay.
@SubscribeEvent
public void renderOverlay(RenderGameOverlayEvent.Post event) {
if (!BREW_HUD.hide && event.getType() == RenderGameOverlayEvent.ElementType.ALL) {
Optional<IBrewStorage> optional = BrewStorageHandler.getBrewStorage(Minecraft.getMinecraft().player);
if (optional.isPresent()) {
ScaledResolution res = event.getResolution();
int x = res.getScaledWidth() - BREW_HUD.x;
int yOffset = BREW_HUD.y;
Minecraft mc = Minecraft.getMinecraft();
Set<IBrew> client = optional.get().getClient();
if (client == null)
return;
Iterator<IBrew> renders = client.iterator();
GlStateManager.pushMatrix();
while (renders.hasNext()) {
renders.next().renderHUD(x, yOffset, mc);
yOffset += 22;
}
GlStateManager.popMatrix();
}
}
}
Aggregations