Skip to content

Commit

Permalink
-Actual transmutation!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
Cassunshine committed Feb 7, 2024
1 parent 0e3a59f commit e8786c1
Show file tree
Hide file tree
Showing 43 changed files with 1,265 additions and 509 deletions.
6 changes: 4 additions & 2 deletions src/client/java/cassunshine/thework/TheWorkClient.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cassunshine.thework;

import cassunshine.thework.blocks.TheWorkBlocks;
import cassunshine.thework.client.networking.TheWorkClientNetworking;
import cassunshine.thework.rendering.blockentities.TheWorkBlockEntityRenderers;
import cassunshine.thework.rendering.blockentities.alchemy_block.nodes.NodeTypeRenderers;
import cassunshine.thework.rendering.blockentities.alchemy_block.nodes.AlchemyNodeTypeRenderers;
import cassunshine.thework.rendering.entities.TheWorkEntityRenderers;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
Expand All @@ -17,8 +18,9 @@ public class TheWorkClient implements ClientModInitializer {
public void onInitializeClient() {
TheWorkBlockEntityRenderers.initialize();
TheWorkEntityRenderers.initialize();
TheWorkClientNetworking.initialize();

NodeTypeRenderers.initialize();
AlchemyNodeTypeRenderers.initialize();

BlockRenderLayerMap.INSTANCE.putBlock(TheWorkBlocks.ALCHEMY_JAR_BLOCK, RenderLayer.getTranslucent());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
import cassunshine.thework.TheWorkMod;
import cassunshine.thework.blockentities.alchemy_circle.AlchemyCircleBlockEntity;
import cassunshine.thework.blockentities.alchemy_circle.nodes.AlchemyNode;
import cassunshine.thework.blockentities.alchemy_circle.nodes.NodeTypes;
import cassunshine.thework.blockentities.alchemy_circle.nodes.types.AlchemyNodeTypes;
import cassunshine.thework.blockentities.alchemy_circle.rings.AlchemyRing;
import cassunshine.thework.rendering.blockentities.alchemy_block.nodes.NodeTypeRenderers;
import cassunshine.thework.rendering.blockentities.alchemy_block.nodes.AlchemyNodeTypeRenderers;
import cassunshine.thework.rendering.util.RenderingUtilities;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.LightmapTextureManager;
import net.minecraft.client.render.OverlayTexture;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactory;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.LightType;

import java.util.ArrayList;
import java.util.Comparator;
Expand All @@ -35,14 +40,31 @@ public void render(AlchemyCircleBlockEntity entity, float tickDelta, MatrixStack

RenderingUtilities.pushMat();
RenderingUtilities.setupConsumers(vertexConsumers);
RenderingUtilities.setupRenderLayer(getLayer());
RenderingUtilities.setupRenderLayer(getLayer(entity));

float time = entity.getWorld().getTime() + MinecraftClient.getInstance().getTickDelta();

try {
RenderingUtilities.translateMatrix(0.5f, 1 / 32.0f, 0.5f);

/*if (entity.isActive) {
entity.animationRotation += MinecraftClient.getInstance().getLastFrameDuration() * 0.1f;
entity.animationRotation %= MathHelper.TAU;
} else {
entity.animationRotation = MathHelper.lerpAngleDegrees(0.1f, (entity.animationRotation / MathHelper.TAU) * 360, 0);
}
RenderingUtilities.rotateMatrix(0, entity.animationRotation, 0);*/


ArrayList<AlchemyRing> rings = entity.rings;
for (int i = 0; i < rings.size(); i++)
drawRing(rings.get(i), i + 1 >= rings.size() ? null : rings.get(i + 1));

for (int i = 0; i < rings.size(); i++) {
AlchemyRing nextRing = entity.isOutward ? (i + 1 >= rings.size() ? null : rings.get(i + 1)) : (i - 1 < 0 ? null : rings.get(i - 1));

drawRing(rings.get(i), nextRing, entity.isOutward);
}


nodesToDraw.sort(Comparator.comparing(a -> a.type.id));
for (AlchemyNode node : nodesToDraw) {
Expand All @@ -62,16 +84,16 @@ public int getRenderDistance() {
return 999;
}

public RenderLayer getLayer() {
return RenderLayer.getEntityCutoutNoCull(ALCHEMY_CIRCLE_TEXTURE);
public RenderLayer getLayer(AlchemyCircleBlockEntity entity) {
return entity.isActive ? RenderLayer.getEntityTranslucentEmissive(ALCHEMY_CIRCLE_TEXTURE) : RenderLayer.getEntityCutoutNoCull(ALCHEMY_CIRCLE_TEXTURE);
}

@Override
public boolean rendersOutsideBoundingBox(AlchemyCircleBlockEntity blockEntity) {
return true;
}

private void drawRing(AlchemyRing ring, AlchemyRing nextRing) {
private void drawRing(AlchemyRing ring, AlchemyRing nextRing, boolean outward) {

//Small circles just draw as-is.
if (ring.nodes.length == 0) {
Expand All @@ -93,44 +115,52 @@ private void drawRing(AlchemyRing ring, AlchemyRing nextRing) {
var nextNode = ring.getNode(i + 1);

//Angles of the line segment being drawn out of this node.
float segmentStartAngle = currentNode.type == NodeTypes.NONE ? lastAngle : lastAngle + nodeSizeAngle;
float segmentEndAngle = nextNode.type == NodeTypes.NONE ? lastAngle + anglePerNode : lastAngle + anglePerNode - nodeSizeAngle;
float segmentStartAngle = currentNode.type == AlchemyNodeTypes.NONE ? lastAngle : lastAngle + nodeSizeAngle;
float segmentEndAngle = nextNode.type == AlchemyNodeTypes.NONE ? lastAngle + anglePerNode : lastAngle + anglePerNode - nodeSizeAngle;

float nextRadius = nextRing == null ? ring.radius + 0.1f : nextRing.radius;
nextRadius = nextRing == null ? nextRadius : nextRadius + (nextRadius - (nextRing.getClosestRadius(lastAngle))) * (outward ? -1 : 1);

float pipOffset = 0;
float nextRadius = nextRing == null ? ring.radius + 0.1f : nextRing.getClosestRadius(lastAngle);
float pipHeight = (nextRadius - ring.radius);

//If the current node is special
if (currentNode.type != NodeTypes.NONE) {
if (currentNode.type != AlchemyNodeTypes.NONE) {
//Draw circle.
RenderingUtilities.pushMat();

var pos = currentNode.position.subtract(currentNode.ring.position);
RenderingUtilities.translateMatrix((float)pos.x, 0, (float)pos.z);
//Move rendering to where the alchemy node is in the world.
var pos = currentNode.position.subtract(ring.circle.fullPosition);
RenderingUtilities.translateMatrix((float) pos.x, 0, (float) pos.z);

var customDraw = AlchemyNodeTypeRenderers.get(currentNode.type);
int segments = customDraw == null ? 8 : customDraw.circleSides;

drawCircleSegment(0.5f, 0, MathHelper.TAU);
RenderingUtilities.rotateMatrix(0, lastAngle, 0);
//Draw a circle where the node is.
drawCircleSegment(0.5f, 0, MathHelper.TAU, segments);
RenderingUtilities.popMat();

//Calculate offset for pip
pipOffset += 0.5f;
pipHeight -= 0.5f;
pipOffset += outward ? 0.5f : -0.5f;
if (nextRing == null)
pipHeight = 0;
else
pipHeight += outward ? -0.5f : 0.5f;

//Queue up special renderer for later.
nodesToDraw.add(currentNode);

if(nextRing == null)
pipHeight = 0;
} else {
pipHeight = 0.1f;
pipHeight = outward ? 0.1f : -0.1f;
}

if(pipHeight > 0.0001)
if (Math.abs(pipHeight) > 0.0001)
drawPip(ring.radius + pipOffset, lastAngle, 1 / 32.0f, pipHeight);

//Draw segment.
drawCircleSegment(ring.radius, segmentStartAngle, segmentEndAngle);

float innerSign = ring.isClockwise ? 1/16.0f : -(1/16.0f);
float innerSign = ring.isClockwise ? 1 / 16.0f : -(1 / 16.0f);
drawSegmentPips(ring.radius, segmentStartAngle, segmentEndAngle, innerSign, innerSign);

//Increase angle by 1 node.
Expand All @@ -139,18 +169,33 @@ private void drawRing(AlchemyRing ring, AlchemyRing nextRing) {
}

private void drawNode(AlchemyNode node) {
var customDraw = NodeTypeRenderers.get(node.type.getClass());
RenderingUtilities.pushMat();

if(customDraw != null){
RenderingUtilities.pushMat();
var pos = node.position.subtract(node.ring.position);
RenderingUtilities.translateMatrix((float)pos.x, 0, (float)pos.z);
RenderingUtilities.rotateMatrix(0, -node.rotation, 0);
//Move and rotate drawing to match node.
var pos = node.position.subtract(node.ring.circle.fullPosition);
RenderingUtilities.translateMatrix((float) pos.x, 0, (float) pos.z);
RenderingUtilities.rotateMatrix(0, node.rotation - MathHelper.PI, 0);

var customDraw = AlchemyNodeTypeRenderers.get(node.type);
if (customDraw != null)
customDraw.render(node);

RenderingUtilities.popMat();
{


var world = node.ring.circle.getWorld();
var blockPos = BlockPos.ofFloored(node.position);
var light = LightmapTextureManager.pack(world.getLightLevel(LightType.BLOCK, blockPos), world.getLightLevel(LightType.SKY, blockPos));

float random = (node.position.hashCode() % 1000) / 100.0f;
float time = world.getTime() + MinecraftClient.getInstance().getTickDelta();
RenderingUtilities.rotateMatrix(0, (time + random) / 10.0f, 0);
RenderingUtilities.translateMatrix(0, (MathHelper.sin(((time * 0.05f) + random) % MathHelper.TAU) + 1) * 0.1f, 0);

RenderingUtilities.renderItem(node.item, node.ring.circle.getWorld(), light, OverlayTexture.DEFAULT_UV);
}

RenderingUtilities.popMat();
}

private void drawCircleSegment(float radius, float startAngle, float endAngle) {
Expand Down Expand Up @@ -192,6 +237,37 @@ private void drawCircleSegment(float radius, float startAngle, float endAngle) {
}
}

private void drawCircleSegment(float radius, float startAngle, float endAngle, int drawSegments) {

float circleHalfThickness = 1 / 32.0f;
float circleMin = radius - circleHalfThickness;
float circleMax = radius + circleHalfThickness;

//Total circumference of the circle.
float totalCircumference = 2 * MathHelper.PI * radius;

float startCircumference = totalCircumference * (startAngle / MathHelper.TAU);

for (int i = 0; i < drawSegments; i++) {
float angleThis = MathHelper.lerp(i / (float) drawSegments, startAngle, endAngle);
float angleNext = MathHelper.lerp((i + 1) / (float) drawSegments, startAngle, endAngle);

float startSin = MathHelper.sin(angleThis);
float startCos = MathHelper.cos(angleThis);

float nextSin = MathHelper.sin(angleNext);
float nextCos = MathHelper.cos(angleNext);

RenderingUtilities.saneVertex(startSin * circleMin, 0, startCos * circleMin, 255, 255, 255, startCircumference, 0, 0, 1, 0);
RenderingUtilities.saneVertex(startSin * circleMax, 0, startCos * circleMax, 255, 255, 255, startCircumference, 0.125f, 0, 1, 0);

startCircumference += 1;

RenderingUtilities.saneVertex(nextSin * circleMax, 0, nextCos * circleMax, 255, 255, 255, startCircumference, 0.125f, 0, 1, 0);
RenderingUtilities.saneVertex(nextSin * circleMin, 0, nextCos * circleMin, 255, 255, 255, startCircumference, 0, 0, 1, 0);
}
}

private void drawSegmentPips(float radius, float startAngle, float endAngle, float size, float offset) {

//Total circumference of the circle.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

import cassunshine.thework.blockentities.alchemy_circle.nodes.AlchemyNode;

public class NodeRenderer {
public class AlchemyNodeTypeRenderer {

public int circleSides;

public void render(AlchemyNode node) {

}

public AlchemyNodeTypeRenderer withSides(int sides) {
this.circleSides = sides;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package cassunshine.thework.rendering.blockentities.alchemy_block.nodes;

import cassunshine.thework.blockentities.alchemy_circle.nodes.types.AlchemyNodeType;
import cassunshine.thework.blockentities.alchemy_circle.nodes.types.AlchemyNodeTypes;

import java.util.HashMap;

public class AlchemyNodeTypeRenderers {
private static final HashMap<AlchemyNodeType, AlchemyNodeTypeRenderer> renderers = new HashMap<>();

public static void initialize() {

}

private static void register(AlchemyNodeType type, AlchemyNodeTypeRenderer renderer) {
renderers.put(type, renderer);
}

public static <T extends AlchemyNodeType> AlchemyNodeTypeRenderer get(AlchemyNodeType type) {
return renderers.get(type);
}

static {
register(AlchemyNodeTypes.DECONSTRUCT, new RuneAlchemyNodeTypeRenderer().withSides(4));
register(AlchemyNodeTypes.CONSTRUCT, new RuneAlchemyNodeTypeRenderer().withSides(6));
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit e8786c1

Please sign in to comment.