use of net.minecraft.client.renderer.culling.ICamera in project Charset by CharsetMC.
the class ProjectorRenderer method onRender.
@SubscribeEvent
public void onRender(RenderWorldLastEvent event) {
Minecraft.getMinecraft().mcProfiler.startSection("projectors");
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
GlStateManager.glBlendEquation(GL14.GL_FUNC_ADD);
GlStateManager.enableTexture2D();
GlStateManager.enableAlpha();
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder worldrenderer = tessellator.getBuffer();
worldrenderer.setTranslation(0, 0, 0);
Entity cameraEntity = Minecraft.getMinecraft().getRenderViewEntity();
Vec3d cameraPos = EntityUtils.interpolate(cameraEntity, event.getPartialTicks());
ICamera camera = new Frustum();
camera.setPosition(cameraPos.x, cameraPos.y, cameraPos.z);
GlStateManager.pushMatrix();
GlStateManager.translate(-cameraPos.x, -cameraPos.y, -cameraPos.z);
for (TileEntity tileEntity : Minecraft.getMinecraft().world.loadedTileEntityList) {
if (tileEntity instanceof TileProjector) {
LaserColor color = LaserColor.NONE;
Orientation orientation = ((TileProjector) tileEntity).getOrientation();
if (CharsetProjector.useLasers) {
for (int d = 0; d < 6; d++) {
LaserColor color2 = ((TileProjector) tileEntity).colors[d];
if (color2 != null && color2 != LaserColor.NONE) {
if (d == orientation.facing.getOpposite().ordinal()) {
// not rendering anything - laser in the way
color = LaserColor.NONE;
break;
} else {
color = color.union(color2);
}
}
}
} else {
color = ((TileProjector) tileEntity).redstoneLevel > 0 ? LaserColor.WHITE : LaserColor.NONE;
}
if (color != LaserColor.NONE) {
ItemStack stack = ((TileProjector) tileEntity).getStack();
IProjectorHandler<ItemStack> handler = CharsetProjector.getHandler(stack);
if (handler == null) {
continue;
}
Surface surface = getSurface(tileEntity.getWorld(), tileEntity.getPos(), orientation, 0.5f, handler.getAspectRatio(stack));
if (surface == null) {
continue;
}
if (!camera.isBoundingBoxInFrustum(new AxisAlignedBB(surface.cornerStart, surface.cornerEnd))) {
continue;
}
surface.r = color.red ? 1.0f : 0.0f;
surface.g = color.green ? 1.0f : 0.0f;
surface.b = color.blue ? 1.0f : 0.0f;
surface.a = 0.5f;
if (!CharsetProjector.useLasers) {
surface.a *= ((TileProjector) tileEntity).redstoneLevel / 15.0f;
}
EnumDyeColor dyeColor = null;
BlockPos inFrontPos = tileEntity.getPos().offset(((TileProjector) tileEntity).getOrientation().facing);
IBlockState state = tileEntity.getWorld().getBlockState(inFrontPos);
if (state.getBlock() instanceof BlockStainedGlass) {
dyeColor = state.getValue(BlockStainedGlass.COLOR);
}
if (dyeColor != null) {
float[] v = dyeColor.getColorComponentValues();
surface.r *= v[0];
surface.g *= v[1];
surface.b *= v[2];
}
surface.restoreGLColor();
handler.render(stack, (IProjector) tileEntity, surface);
}
}
}
GlStateManager.popMatrix();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.glBlendEquation(GL14.GL_FUNC_ADD);
GlStateManager.disableBlend();
Minecraft.getMinecraft().mcProfiler.endSection();
}
use of net.minecraft.client.renderer.culling.ICamera in project Charset by CharsetMC.
the class LaserRenderer method onRender.
@SubscribeEvent
public void onRender(RenderWorldLastEvent event) {
Minecraft mc = Minecraft.getMinecraft();
World world = mc.world;
Collection<LaserBeam> beams = CharsetLaser.laserStorage.getLaserBeams(world);
renderedLasers = 0;
totalLasers = beams.size();
if (totalLasers == 0)
return;
Minecraft.getMinecraft().mcProfiler.startSection("lasers");
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
GlStateManager.glBlendEquation(GL14.GL_FUNC_ADD);
GlStateManager.enableAlpha();
GlStateManager.disableLighting();
GlStateManager.disableTexture2D();
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder worldrenderer = tessellator.getBuffer();
Entity cameraEntity = Minecraft.getMinecraft().getRenderViewEntity();
Vec3d cameraPos = EntityUtils.interpolate(cameraEntity, event.getPartialTicks());
ICamera camera = new Frustum();
camera.setPosition(cameraPos.x, cameraPos.y, cameraPos.z);
int maxDist = Minecraft.getMinecraft().gameSettings.renderDistanceChunks * 16 + 1;
Collection<LaserBeam> beamsRender = beams;
worldrenderer.setTranslation(-cameraPos.x, -cameraPos.y, -cameraPos.z);
worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
for (LaserBeam beam : beamsRender) {
beam.vcstart = beam.calculateStartpoint();
beam.vcend = beam.calculateEndpoint();
beam.vcdist = MathUtils.linePointDistance(beam.vcstart, beam.vcend, cameraPos);
if (beam.vcdist > maxDist) {
continue;
}
Vec3d startVec = beam.vcstart;
Vec3d endVec = beam.vcend;
float t = THICKNESS;
if (beam.getColor().red)
t += 0.004f;
if (beam.getColor().green)
t += 0.002f;
if (beam.getColor().blue)
t += 0.001f;
if (beam.getStart().getX() == beam.getEnd().getX()) {
startVec = startVec.addVector(-t / 16.0, 0, 0);
endVec = endVec.addVector(t / 16.0, 0, 0);
}
if (beam.getStart().getY() == beam.getEnd().getY()) {
startVec = startVec.addVector(0, -t / 16.0, 0);
endVec = endVec.addVector(0, t / 16.0, 0);
}
if (beam.getStart().getZ() == beam.getEnd().getZ()) {
startVec = startVec.addVector(0, 0, -t / 16.0);
endVec = endVec.addVector(0, 0, t / 16.0);
}
if (!camera.isBoundingBoxInFrustum(new AxisAlignedBB(startVec, endVec))) {
continue;
}
renderedLasers++;
int color = CharsetLaser.LASER_COLORS[beam.getColor().ordinal()];
int r = (color >> 16) & 0xFF;
int g = (color >> 8) & 0xFF;
int b = color & 0xFF;
int a = (color >> 24) & 0xFF;
double[] data = new double[] { startVec.y, endVec.y, startVec.z, endVec.z, startVec.x, endVec.x };
for (EnumFacing facing : EnumFacing.VALUES) {
for (int i = 0; i < 4; i++) {
EnumFaceDirection.VertexInformation vi = EnumFaceDirection.getFacing(facing).getVertexInformation(i);
worldrenderer.pos(data[vi.xIndex], data[vi.yIndex], data[vi.zIndex]).color(r, g, b, a).endVertex();
}
}
}
if (Minecraft.getMinecraft().gameSettings.fancyGraphics) {
tessellator.getBuffer().sortVertexData((float) cameraPos.x, (float) cameraPos.y, (float) cameraPos.z);
}
tessellator.draw();
worldrenderer.setTranslation(0, 0, 0);
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.glBlendEquation(GL14.GL_FUNC_ADD);
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
Minecraft.getMinecraft().mcProfiler.endSection();
}
Aggregations