use of de.teamlapen.vampirism.api.entity.IExtendedCreatureVampirism in project Vampirism by TeamLapen.
the class RenderHandler method onRenderLivingPost.
@SubscribeEvent
public void onRenderLivingPost(RenderLivingEvent.Post event) {
if (!isInsideBloodVisionRendering && shouldRenderBloodVision() && !reducedBloodVision) {
Entity entity = event.getEntity();
boolean flag = !(entity instanceof PlayerEntity) || VampirismPlayerAttributes.get((PlayerEntity) entity).getHuntSpecial().fullHunterCoat == null;
double dist = mc.player.distanceToSqr(entity);
if (dist > VampirismConfig.BALANCE.vsBloodVisionDistanceSq.get()) {
flag = false;
}
if (flag) {
int color;
LazyOptional<IExtendedCreatureVampirism> opt = entity instanceof CreatureEntity && entity.isAlive() ? ExtendedCreature.getSafe(entity) : LazyOptional.empty();
if (opt.map(creature -> creature.getBlood() > 0 && !creature.hasPoisonousBlood()).orElse(false)) {
color = 0xFF0000;
} else if (VampirismPlayerAttributes.get(mc.player).getVampSpecial().blood_vision_garlic && ((opt.map(IExtendedCreatureVampirism::hasPoisonousBlood).orElse(false)) || entity instanceof IHunterMob)) {
color = 0x07FF07;
} else {
color = 0xA0A0A0;
}
EntityRendererManager renderManager = mc.getEntityRenderDispatcher();
if (bloodVisionBuffer == null) {
bloodVisionBuffer = new OutlineLayerBuffer(mc.renderBuffers().bufferSource());
}
int r = color >> 16 & 255;
int g = color >> 8 & 255;
int b = color & 255;
int alpha = (int) ((dist > ENTITY_NEAR_SQ_DISTANCE ? 50 : (dist / (double) ENTITY_NEAR_SQ_DISTANCE * 50d)) * getBloodVisionProgress(event.getPartialRenderTick()));
bloodVisionBuffer.setColor(r, g, b, alpha);
float f = MathHelper.lerp(event.getPartialRenderTick(), entity.yRotO, entity.yRot);
isInsideBloodVisionRendering = true;
EntityRenderer<? super Entity> entityrenderer = renderManager.getRenderer(entity);
entityrenderer.render(entity, f, event.getPartialRenderTick(), event.getMatrixStack(), bloodVisionBuffer, renderManager.getPackedLightCoords(entity, event.getPartialRenderTick()));
mc.getMainRenderTarget().bindWrite(false);
isInsideBloodVisionRendering = false;
}
}
}
use of de.teamlapen.vampirism.api.entity.IExtendedCreatureVampirism in project Vampirism by TeamLapen.
the class VampirismHUDOverlay method onRenderCrosshair.
@SubscribeEvent
public void onRenderCrosshair(RenderGameOverlayEvent.Pre event) {
if (event.getType() != RenderGameOverlayEvent.ElementType.CROSSHAIRS || mc.player == null || !mc.player.isAlive()) {
return;
}
RayTraceResult p = Minecraft.getInstance().hitResult;
if (p != null && p.getType() == RayTraceResult.Type.ENTITY) {
Entity entity = ((EntityRayTraceResult) p).getEntity();
if (!entity.isInvisible()) {
VampirismPlayerAttributes atts = VampirismPlayerAttributes.get(mc.player);
if (atts.vampireLevel > 0 && !mc.player.isSpectator() && !atts.getVampSpecial().bat) {
VampirePlayer.getOpt(mc.player).ifPresent(player -> {
LazyOptional<? extends IBiteableEntity> biteableOpt = LazyOptional.empty();
if (entity instanceof IBiteableEntity) {
biteableOpt = LazyOptional.of(() -> (IBiteableEntity) entity);
} else if (entity instanceof CreatureEntity && entity.isAlive()) {
biteableOpt = ExtendedCreature.getSafe(entity);
} else if (entity instanceof PlayerEntity) {
biteableOpt = VampirePlayer.getOpt((PlayerEntity) entity);
}
biteableOpt.filter(iBiteableEntity -> iBiteableEntity.canBeBitten(player)).ifPresent(biteable -> {
int color = 0xFF0000;
if (entity instanceof IHunterMob || ExtendedCreature.getSafe(entity).map(IExtendedCreatureVampirism::hasPoisonousBlood).orElse(false))
color = 0x099022;
renderBloodFangs(event.getMatrixStack(), this.mc.getWindow().getGuiScaledWidth(), this.mc.getWindow().getGuiScaledHeight(), MathHelper.clamp(biteable.getBloodLevelRelative(), 0.2F, 1F), color);
event.setCanceled(true);
});
});
}
if (atts.hunterLevel > 0 && !mc.player.isSpectator() && mc.player.getMainHandItem().getItem() == ModItems.stake) {
if (entity instanceof LivingEntity && entity instanceof IVampireMob) {
if (StakeItem.canKillInstant((LivingEntity) entity, mc.player)) {
if (((LivingEntity) entity).getHealth() > 0) {
this.renderStakeInstantKill(event.getMatrixStack(), this.mc.getWindow().getGuiScaledWidth(), this.mc.getWindow().getGuiScaledHeight());
event.setCanceled(true);
}
}
}
}
}
} else if (p != null && p.getType() == RayTraceResult.Type.BLOCK) {
BlockState block = Minecraft.getInstance().level.getBlockState(((BlockRayTraceResult) p).getBlockPos());
if (ModBlocks.blood_container.equals(block.getBlock())) {
if (VampirePlayer.getOpt(mc.player).map(VampirePlayer::wantsBlood).orElse(false)) {
TileEntity tile = Minecraft.getInstance().level.getBlockEntity(((BlockRayTraceResult) p).getBlockPos());
if (tile != null) {
tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY).ifPresent(handler -> {
if (FluidLib.getFluidAmount(handler, ModFluids.blood) > 0) {
renderBloodFangs(event.getMatrixStack(), this.mc.getWindow().getGuiScaledWidth(), this.mc.getWindow().getGuiScaledHeight(), 1, 0xFF0000);
event.setCanceled(true);
}
});
}
}
}
}
// Render blood feed progress
GameSettings gamesettings = this.mc.options;
if (gamesettings.getCameraType().isFirstPerson() && this.mc.gameMode.getPlayerMode() != GameType.SPECTATOR) {
float progress = VampirePlayer.getOpt(mc.player).map(VampirePlayer::getFeedProgress).orElse(0f);
if (progress > 0) {
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.ONE_MINUS_DST_COLOR, GlStateManager.DestFactor.ONE_MINUS_SRC_COLOR, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
if (progress <= 1.0F) {
int x = this.mc.getWindow().getGuiScaledWidth() / 2 - 8;
int y = this.mc.getWindow().getGuiScaledHeight() / 2 - 7 + 16;
this.mc.getTextureManager().bind(icons);
int l = (int) (progress * 14.0F) + 2;
this.blit(event.getMatrixStack(), x, y, 0, 19, 16, 2);
this.blit(event.getMatrixStack(), x, y, 16, 19, l, 2);
}
}
}
}
use of de.teamlapen.vampirism.api.entity.IExtendedCreatureVampirism in project Vampirism by TeamLapen.
the class VampirePlayer method biteFeed.
/**
* Bite the given entity.
* Does NOT check reach distance
*
* @param entity the entity to feed on
* @return If feeding can continue
*/
private boolean biteFeed(LivingEntity entity) {
if (isRemote())
return true;
if (getLevel() == 0)
return false;
int blood = 0;
float saturationMod = IBloodStats.HIGH_SATURATION;
boolean continue_feeding = true;
if (feed_victim_bite_type == BITE_TYPE.SUCK_BLOOD_CREATURE && entity.isAlive()) {
LazyOptional<IExtendedCreatureVampirism> opt = ExtendedCreature.getSafe(entity);
blood = opt.map(creature -> creature.onBite(this)).orElse(0);
saturationMod = opt.map(IBiteableEntity::getBloodSaturation).orElse(0f);
if (isAdvancedBiter() && opt.map(IExtendedCreatureVampirism::getBlood).orElse(0) == 1) {
continue_feeding = false;
}
} else if (feed_victim_bite_type == BITE_TYPE.SUCK_BLOOD_PLAYER) {
blood = VampirePlayer.getOpt((PlayerEntity) entity).map(v -> v.onBite(this)).orElse(0);
saturationMod = VampirePlayer.getOpt((PlayerEntity) entity).map(VampirePlayer::getBloodSaturation).orElse(0f);
} else if (feed_victim_bite_type == BITE_TYPE.SUCK_BLOOD) {
blood = ((IBiteableEntity) entity).onBite(this);
saturationMod = ((IBiteableEntity) entity).getBloodSaturation();
}
if (blood > 0) {
drinkBlood(blood, saturationMod);
CompoundNBT updatePacket = bloodStats.writeUpdate(new CompoundNBT());
updatePacket.putInt(KEY_SPAWN_BITE_PARTICLE, entity.getId());
sync(updatePacket, true);
if (player instanceof ServerPlayerEntity) {
ModAdvancements.TRIGGER_VAMPIRE_ACTION.trigger((ServerPlayerEntity) player, VampireActionTrigger.Action.SUCK_BLOOD);
}
return continue_feeding;
}
return false;
}
Aggregations