diff --git a/src/main/java/ru/betterend/blocks/entities/PedestalBlockEntity.java b/src/main/java/ru/betterend/blocks/entities/PedestalBlockEntity.java index 37fff2c5..bc2bf595 100644 --- a/src/main/java/ru/betterend/blocks/entities/PedestalBlockEntity.java +++ b/src/main/java/ru/betterend/blocks/entities/PedestalBlockEntity.java @@ -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() { @@ -38,6 +39,10 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka public int getAge() { return this.age; } + + public int getMaxAge() { + return this.maxAge; + } @Override public void clear() { @@ -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; } } diff --git a/src/main/java/ru/betterend/blocks/entities/render/EndCrystalRenderer.java b/src/main/java/ru/betterend/blocks/entities/render/EndCrystalRenderer.java index 3ea68181..7179aa88 100644 --- a/src/main/java/ru/betterend/blocks/entities/render/EndCrystalRenderer.java +++ b/src/main/java/ru/betterend/blocks/entities/render/EndCrystalRenderer.java @@ -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); diff --git a/src/main/java/ru/betterend/blocks/entities/render/PedestalItemRenderer.java b/src/main/java/ru/betterend/blocks/entities/render/PedestalItemRenderer.java index c3c28f21..8b33b6b6 100644 --- a/src/main/java/ru/betterend/blocks/entities/render/PedestalItemRenderer.java +++ b/src/main/java/ru/betterend/blocks/entities/render/PedestalItemRenderer.java @@ -70,7 +70,7 @@ public class PedestalItemRenderer extends BlockEntityRenderer