Black hole renderer
This commit is contained in:
parent
03afe7baad
commit
f9fb9124b7
@ -36,6 +36,10 @@ public class BlockEntityBlackHole extends BlockEntity {
|
||||
private double gravitation_strength = 1;
|
||||
private boolean suppress_updates = true;
|
||||
|
||||
public double getGravitationStrength() {
|
||||
return gravitation_strength;
|
||||
}
|
||||
|
||||
public void collapse() {
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
package ru.dbotthepony.mc.otm.client.render;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import ru.dbotthepony.mc.otm.block.entity.BlockEntityBlackHole;
|
||||
|
||||
import static org.lwjgl.opengl.GL33.*;
|
||||
|
||||
public class BlackHoleRenderer implements BlockEntityRenderer<BlockEntityBlackHole> {
|
||||
@Override
|
||||
public void render(BlockEntityBlackHole blockEntityBlackHole, float v, PoseStack poseStack, MultiBufferSource multiBufferSource, int i, int i1) {
|
||||
RenderHelper.setDrawColor(RGBAColor.BLACK);
|
||||
|
||||
RenderSystem.depthFunc(GL_LESS);
|
||||
RenderSystem.depthMask(true);
|
||||
|
||||
RenderSystem.enableDepthTest();
|
||||
RenderSystem.disableCull();
|
||||
|
||||
poseStack.pushPose();
|
||||
poseStack.translate(0.5, -0.25, blockEntityBlackHole.getGravitationStrength() * 0.5);
|
||||
|
||||
RenderHelper.colorSphere(poseStack, 1f);
|
||||
|
||||
poseStack.popPose();
|
||||
|
||||
RenderSystem.enableCull();
|
||||
RenderSystem.enableTexture();
|
||||
}
|
||||
|
||||
public BlackHoleRenderer(BlockEntityRendererProvider.Context context) {
|
||||
|
||||
}
|
||||
}
|
@ -93,6 +93,66 @@ public class RenderHelper {
|
||||
drawTexturedRectUV(matrix, x, y, width, height, uv.u0(), uv.v0(), uv.u1(), uv.v1());
|
||||
}
|
||||
|
||||
public static void colorSphere(Matrix4f matrix, float radius) {
|
||||
final int fragments = Math.round(radius * 16);
|
||||
|
||||
RenderSystem.setShader(GameRenderer::getPositionColorShader);
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
|
||||
var builder = Tesselator.getInstance().getBuilder();
|
||||
builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||
|
||||
final double turn_step = Math.PI * (1 / (double) fragments) * 2;
|
||||
final double stripe_step = Math.PI * (1 / (double) fragments);
|
||||
|
||||
for (int turn = 0; turn < fragments; turn++) {
|
||||
final double turn_pre = turn_step * turn;
|
||||
final double turn_post = turn_step * (turn + 1);
|
||||
|
||||
for (int sector = 0; sector < fragments; sector++) {
|
||||
final double tilt_pre = Math.PI / 2 - stripe_step * (sector);
|
||||
final double tilt_post = Math.PI / 2 - stripe_step * (sector + 1);
|
||||
|
||||
final float x_pre = (float) Math.sin(turn_pre) * radius;
|
||||
final float x_post = (float) Math.sin(turn_post) * radius;
|
||||
|
||||
final float z_pre = (float) Math.cos(turn_pre) * radius;
|
||||
final float z_post = (float) Math.cos(turn_post) * radius;
|
||||
|
||||
final float y_pre = (float) (Math.sin(tilt_pre) + 0.5) * radius;
|
||||
final float y_post = (float) (Math.sin(tilt_post) + 0.5) * radius;
|
||||
|
||||
//final float y_pre = (float) ((double) top_frag / (double) fragments) * 8;
|
||||
//final float y_post = (float) ((double) (top_frag + 1) / (double) fragments) * 8;
|
||||
|
||||
builder.vertex(matrix, x_pre * (float) Math.cos(tilt_post), y_post, z_pre * (float) Math.cos(tilt_post))
|
||||
.color(draw_color.r(), draw_color.g(), draw_color.b(), draw_color.a())
|
||||
.endVertex();
|
||||
|
||||
builder.vertex(matrix, x_post * (float) Math.cos(tilt_post), y_post, z_post * (float) Math.cos(tilt_post))
|
||||
.color(draw_color.r(), draw_color.g(), draw_color.b(), draw_color.a())
|
||||
.endVertex();
|
||||
|
||||
builder.vertex(matrix, x_post * (float) Math.cos(tilt_pre), y_pre, z_post * (float) Math.cos(tilt_pre))
|
||||
.color(draw_color.r(), draw_color.g(), draw_color.b(), draw_color.a())
|
||||
.endVertex();
|
||||
|
||||
builder.vertex(matrix, x_pre * (float) Math.cos(tilt_pre), y_pre, z_pre * (float) Math.cos(tilt_pre))
|
||||
.color(draw_color.r(), draw_color.g(), draw_color.b(), draw_color.a())
|
||||
.endVertex();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
builder.end();
|
||||
BufferUploader.end(builder);
|
||||
}
|
||||
|
||||
public static void colorSphere(PoseStack stack, float radius) {
|
||||
colorSphere(stack.last().pose(), radius);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a textured rectangle on screen
|
||||
*
|
||||
@ -488,18 +548,18 @@ public class RenderHelper {
|
||||
}
|
||||
|
||||
public static RGBAColor getDrawColor() {
|
||||
return rect_color;
|
||||
return draw_color;
|
||||
}
|
||||
|
||||
public static void setDrawColor(RGBAColor rect_color) {
|
||||
RenderHelper.rect_color = rect_color;
|
||||
RenderHelper.draw_color = rect_color;
|
||||
}
|
||||
|
||||
public static void setShaderColor(RGBAColor rect_color) {
|
||||
RenderSystem.setShaderColor(rect_color.r(), rect_color.g(), rect_color.b(), rect_color.a());
|
||||
}
|
||||
|
||||
private static RGBAColor rect_color = new RGBAColor(255, 255, 255, 255);
|
||||
private static RGBAColor draw_color = new RGBAColor(255, 255, 255, 255);
|
||||
|
||||
/**
|
||||
* Draws a solid color rectangle on screen, defined by last setDrawColor(RGBColor rect_color) call
|
||||
@ -529,10 +589,10 @@ public class RenderHelper {
|
||||
|
||||
builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||
|
||||
builder.vertex(matrix, x, y + height, depth_z).color(rect_color.r(), rect_color.g(), rect_color.b(), rect_color.a()).endVertex();
|
||||
builder.vertex(matrix, x + width, y + height, depth_z).color(rect_color.r(), rect_color.g(), rect_color.b(), rect_color.a()).endVertex();
|
||||
builder.vertex(matrix, x + width, y, depth_z).color(rect_color.r(), rect_color.g(), rect_color.b(), rect_color.a()).endVertex();
|
||||
builder.vertex(matrix, x, y, depth_z).color(rect_color.r(), rect_color.g(), rect_color.b(), rect_color.a()).endVertex();
|
||||
builder.vertex(matrix, x, y + height, depth_z).color(draw_color.r(), draw_color.g(), draw_color.b(), draw_color.a()).endVertex();
|
||||
builder.vertex(matrix, x + width, y + height, depth_z).color(draw_color.r(), draw_color.g(), draw_color.b(), draw_color.a()).endVertex();
|
||||
builder.vertex(matrix, x + width, y, depth_z).color(draw_color.r(), draw_color.g(), draw_color.b(), draw_color.a()).endVertex();
|
||||
builder.vertex(matrix, x, y, depth_z).color(draw_color.r(), draw_color.g(), draw_color.b(), draw_color.a()).endVertex();
|
||||
|
||||
tess.end();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user