WIP: End Crystal render
This commit is contained in:
parent
05f189eadc
commit
cf2bdf541b
3 changed files with 61 additions and 12 deletions
|
@ -17,6 +17,7 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka
|
|||
private ItemStack activeItem = ItemStack.EMPTY;
|
||||
|
||||
private EternalRitual linkedRitual;
|
||||
private final int maxAge = 314;
|
||||
private int age;
|
||||
|
||||
public PedestalBlockEntity() {
|
||||
|
@ -39,6 +40,10 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka
|
|||
return this.age;
|
||||
}
|
||||
|
||||
public int getMaxAge() {
|
||||
return this.maxAge;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
this.activeItem = ItemStack.EMPTY;
|
||||
|
@ -123,7 +128,7 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka
|
|||
public void tick() {
|
||||
if (!isEmpty()) {
|
||||
this.age++;
|
||||
if (age > 314) {
|
||||
if (age > maxAge) {
|
||||
this.age = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,40 +8,84 @@ import net.minecraft.client.render.VertexConsumerProvider;
|
|||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.client.util.math.Vector3f;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Matrix3f;
|
||||
import net.minecraft.util.math.Matrix4f;
|
||||
import net.minecraft.util.math.Quaternion;
|
||||
|
||||
public class EndCrystalRenderer {
|
||||
private static final Identifier TEXTURE = new Identifier("textures/entity/end_crystal/end_crystal.png");
|
||||
private static final Identifier CRYSTAL_TEXTURE = new Identifier("textures/entity/end_crystal/end_crystal.png");
|
||||
private static final Identifier CRYSTAL_BEAM_TEXTURE = new Identifier("textures/entity/end_crystal/end_crystal_beam.png");
|
||||
private static final RenderLayer CRYSTAL_BEAM_LAYER;
|
||||
private static final RenderLayer END_CRYSTAL;
|
||||
private static final float SINE_45_DEGREES;
|
||||
private static final ModelPart CORE;
|
||||
private static final ModelPart FRAME;
|
||||
private static final int AGE_CYCLE = 240;
|
||||
private static final float SINE_45_DEGREES;
|
||||
|
||||
public static void render(int age, float tickDelta, float rotation, MatrixStack matrices, VertexConsumerProvider vertexConsumerProvider, int light) {
|
||||
float k = 240F / 314F;
|
||||
float rotation2 = (age * k + tickDelta) * 3.0F;
|
||||
public static void render(int age, int maxAge, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumerProvider, int light) {
|
||||
float k = (float) AGE_CYCLE / maxAge;
|
||||
float rotation = (age * k + tickDelta) * 3.0F;
|
||||
VertexConsumer vertexConsumer = vertexConsumerProvider.getBuffer(END_CRYSTAL);
|
||||
matrices.push();
|
||||
matrices.scale(0.8F, 0.8F, 0.8F);
|
||||
matrices.translate(0.0D, -0.5D, 0.0D);
|
||||
matrices.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(rotation2));
|
||||
matrices.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(rotation));
|
||||
matrices.translate(0.0D, 0.8F, 0.0D);
|
||||
matrices.multiply(new Quaternion(new Vector3f(SINE_45_DEGREES, 0.0F, SINE_45_DEGREES), 60.0F, true));
|
||||
FRAME.render(matrices, vertexConsumer, light, OverlayTexture.DEFAULT_UV);
|
||||
matrices.scale(0.875F, 0.875F, 0.875F);
|
||||
matrices.multiply(new Quaternion(new Vector3f(SINE_45_DEGREES, 0.0F, SINE_45_DEGREES), 60.0F, true));
|
||||
matrices.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(rotation2));
|
||||
matrices.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(rotation));
|
||||
FRAME.render(matrices, vertexConsumer, light, OverlayTexture.DEFAULT_UV);
|
||||
matrices.scale(0.875F, 0.875F, 0.875F);
|
||||
matrices.multiply(new Quaternion(new Vector3f(SINE_45_DEGREES, 0.0F, SINE_45_DEGREES), 60.0F, true));
|
||||
matrices.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(rotation2));
|
||||
matrices.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(rotation));
|
||||
CORE.render(matrices, vertexConsumer, light, OverlayTexture.DEFAULT_UV);
|
||||
matrices.pop();
|
||||
}
|
||||
|
||||
public static void renderBeam(BlockPos start, BlockPos end, float tickDelta, int age, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light) {
|
||||
float dx = start.getX() - end.getX() + 1.0F;
|
||||
float dy = start.getY() - end.getY() + 1.0F;
|
||||
float dz = start.getZ() - end.getZ() + 1.0F;
|
||||
float f = MathHelper.sqrt(dx * dx + dz * dz);
|
||||
float g = MathHelper.sqrt(dx * dx + dy * dy + dz * dz);
|
||||
matrices.push();
|
||||
matrices.translate(0.0D, 2.0D, 0.0D);
|
||||
matrices.multiply(Vector3f.POSITIVE_Y.getRadialQuaternion((float)(-Math.atan2((double)dz, (double)dx)) - 1.5707964F));
|
||||
matrices.multiply(Vector3f.POSITIVE_X.getRadialQuaternion((float)(-Math.atan2((double)f, (double)dy)) - 1.5707964F));
|
||||
VertexConsumer vertexConsumer = vertexConsumers.getBuffer(CRYSTAL_BEAM_LAYER);
|
||||
float h = 0.0F - ((float)age + tickDelta) * 0.01F;
|
||||
float i = MathHelper.sqrt(dx * dx + dy * dy + dz * dz) / 32.0F - ((float)age + tickDelta) * 0.01F;
|
||||
float k = 0.0F;
|
||||
float l = 0.75F;
|
||||
float m = 0.0F;
|
||||
MatrixStack.Entry entry = matrices.peek();
|
||||
Matrix4f matrix4f = entry.getModel();
|
||||
Matrix3f matrix3f = entry.getNormal();
|
||||
|
||||
for(int n = 1; n <= 8; ++n) {
|
||||
float o = MathHelper.sin((float)n * 6.2831855F / 8.0F) * 0.75F;
|
||||
float p = MathHelper.cos((float)n * 6.2831855F / 8.0F) * 0.75F;
|
||||
float q = (float)n / 8.0F;
|
||||
vertexConsumer.vertex(matrix4f, k * 0.2F, l * 0.2F, 0.0F).color(0, 0, 0, 255).texture(m, h).overlay(OverlayTexture.DEFAULT_UV).light(light).normal(matrix3f, 0.0F, -1.0F, 0.0F).next();
|
||||
vertexConsumer.vertex(matrix4f, k, l, g).color(255, 255, 255, 255).texture(m, i).overlay(OverlayTexture.DEFAULT_UV).light(light).normal(matrix3f, 0.0F, -1.0F, 0.0F).next();
|
||||
vertexConsumer.vertex(matrix4f, o, p, g).color(255, 255, 255, 255).texture(q, i).overlay(OverlayTexture.DEFAULT_UV).light(light).normal(matrix3f, 0.0F, -1.0F, 0.0F).next();
|
||||
vertexConsumer.vertex(matrix4f, o * 0.2F, p * 0.2F, 0.0F).color(0, 0, 0, 255).texture(q, h).overlay(OverlayTexture.DEFAULT_UV).light(light).normal(matrix3f, 0.0F, -1.0F, 0.0F).next();
|
||||
k = o;
|
||||
l = p;
|
||||
m = q;
|
||||
}
|
||||
|
||||
matrices.pop();
|
||||
}
|
||||
|
||||
static {
|
||||
END_CRYSTAL = RenderLayer.getEntityCutoutNoCull(TEXTURE);
|
||||
SINE_45_DEGREES = (float)Math.sin(0.7853981633974483D);
|
||||
END_CRYSTAL = RenderLayer.getEntityCutoutNoCull(CRYSTAL_TEXTURE);
|
||||
CRYSTAL_BEAM_LAYER = RenderLayer.getEntitySmoothCutout(CRYSTAL_BEAM_TEXTURE);
|
||||
SINE_45_DEGREES = (float) Math.sin(0.7853981633974483D);
|
||||
FRAME = new ModelPart(64, 32, 0, 0);
|
||||
FRAME.addCuboid(-4.0F, -4.0F, -4.0F, 8.0F, 8.0F, 8.0F);
|
||||
CORE = new ModelPart(64, 32, 32, 0);
|
||||
|
|
|
@ -70,7 +70,7 @@ public class PedestalItemRenderer extends BlockEntityRenderer<PedestalBlockEntit
|
|||
}
|
||||
|
||||
if (activeItem.getItem() == Items.END_CRYSTAL) {
|
||||
EndCrystalRenderer.render(blockEntity.getAge(), tickDelta, rotation, matrices, vertexConsumers, light);
|
||||
EndCrystalRenderer.render(blockEntity.getAge(), blockEntity.getMaxAge(), tickDelta, matrices, vertexConsumers, light);
|
||||
} else {
|
||||
minecraft.getItemRenderer().renderItem(activeItem, ModelTransformation.Mode.GROUND, false, matrices, vertexConsumers, light, overlay, model);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue