Skip to content

Commit

Permalink
-Omega update to stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Cassunshine committed Feb 21, 2024
1 parent 5712caa commit 1982377
Show file tree
Hide file tree
Showing 45 changed files with 791 additions and 230 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ dependencies {
modRuntimeOnly "maven.modrinth:sodium:mc1.20.4-0.5.8"
modRuntimeOnly "maven.modrinth:lithium:mc1.20.4-0.12.1"
modRuntimeOnly "maven.modrinth:iris:1.6.17+1.20.4"
modRuntimeOnly "maven.modrinth:nbttooltip:1.8.0"

// Uncomment the following line to enable the deprecated Fabric API modules.
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cassunshine.thework.client.gui.ingame.notebook;

import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;

public class AlchemistNotebookNodeScreen extends AlchemistNotebookScreen {
public AlchemistNotebookNodeScreen() {
super(Text.translatable("ui.alchemist_notebook.page.node.title"), "nodes");


}


@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
super.render(context, mouseX, mouseY, delta);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package cassunshine.thework.client.gui.ingame.notebook;

import com.google.common.collect.ImmutableMap;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.text.Text;
import net.minecraft.util.Hand;

import java.util.function.Supplier;

public abstract class AlchemistNotebookScreen extends Screen {
private static final String DEFAULT_PAGE = "nodes";

private static final ImmutableMap<String, Supplier<AlchemistNotebookScreen>> SCREEN_GENERATORS = new ImmutableMap.Builder<String, Supplier<AlchemistNotebookScreen>>().put("node", AlchemistNotebookNodeScreen::new).build();

public NbtCompound itemNbt;
public NbtCompound pageNbt;

public AlchemistNotebookScreen(Text title, String pageName) {
super(title);

itemNbt = MinecraftClient.getInstance().player.getStackInHand(Hand.MAIN_HAND).getOrCreateNbt();
this.client = MinecraftClient.getInstance();

pageNbt = itemNbt.getCompound(pageName);
itemNbt.put(pageName, pageNbt);
}

public void openPage(String pageName) {
if (pageName.isEmpty())
pageName = DEFAULT_PAGE;

itemNbt.putString("opened_page", pageName);

String finalPageName = pageName;

this.client.execute(() -> {
client.setScreen(SCREEN_GENERATORS.get(finalPageName).get());
});
}

@Override
public boolean shouldPause() {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
package cassunshine.thework.client.networking;

import cassunshine.thework.client.events.TheWorkClientNetworkEvents;
import cassunshine.thework.client.gui.ingame.notebook.AlchemistNotebookNodeScreen;
import cassunshine.thework.items.TheWorkItems;
import cassunshine.thework.network.TheWorkNetworking;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.Hand;

public class TheWorkClientNetworking {

public static void initialize() {
TheWorkClientNetworkEvents.initialize();

ClientPlayNetworking.registerGlobalReceiver(TheWorkNetworking.OPEN_ALCHEMIST_BOOK, TheWorkClientNetworking::onOpenBook);
}

private static void onOpenBook(MinecraftClient minecraftClient, ClientPlayNetworkHandler clientPlayNetworkHandler, PacketByteBuf packetByteBuf, PacketSender packetSender) {
var stack = MinecraftClient.getInstance().player.getStackInHand(Hand.MAIN_HAND);

if (!stack.isOf(TheWorkItems.ALCHEMIST_NOTEBOOK_ITEM))
return;

minecraftClient.execute(() -> {
minecraftClient.setScreen(new AlchemistNotebookNodeScreen());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import cassunshine.thework.rendering.blockentities.alchemy_block.nodes.AlchemyNodeTypeRenderers;
import cassunshine.thework.rendering.util.RenderingUtilities;
import cassunshine.thework.utils.TheWorkUtils;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.render.LightmapTextureManager;
import net.minecraft.client.render.OverlayTexture;
import net.minecraft.client.render.RenderLayer;
Expand All @@ -20,6 +21,7 @@
import net.minecraft.client.render.block.entity.BlockEntityRendererFactory;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.BlockItem;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.MathHelper;
Expand Down Expand Up @@ -74,10 +76,11 @@ public void render(AlchemyCircleBlockEntity entity, float tickDelta, MatrixStack
RenderingUtilities.setupNormal(0, 1, 0);


if (!circle.isActive)
if (!circle.isActive) {
RenderingUtilities.setupColor(240, 240, 240, 255);
else
} else {
RenderingUtilities.setupColor(230, 240, 255, 255);
}

RenderingUtilities.setupWobble(circle.isActive ? 0.01f : 0);

Expand Down Expand Up @@ -129,7 +132,7 @@ private void drawRing(AlchemyRing ring, AlchemyRing next) {
if (nodeThis.nodeType != AlchemyNodeTypes.NONE)
specialRenders.add(nodeThis);
else
drawPip(ring.radius - 0.1f - LINE_THICKNESS, nodeThis.getAngle(), 0.2f + LINE_THICKNESS);
drawPip(ring.radius - 0.03f - LINE_THICKNESS, nodeThis.getAngle(), 0.06f + LINE_THICKNESS);

var pathThis = ring.paths[i];

Expand All @@ -151,7 +154,9 @@ private void drawNode(AlchemyNode node) {
//TODO - Check perf on this
RenderingUtilities.setupRenderLayer(getLayer(node.ring.circle));

drawFullCircle(0.5f, customRenderer == null ? 8 : customRenderer.circleSides);
RenderingUtilities.rotateMatrix(0, customRenderer.extraRotationAngle, 0);
drawFullCircle(0.5f, customRenderer.circleSides);
RenderingUtilities.rotateMatrix(0, -customRenderer.extraRotationAngle, 0);

//Render item
if (!node.heldStack.isEmpty()) {
Expand All @@ -175,8 +180,7 @@ private void drawNode(AlchemyNode node) {
}

//Run custom renderer
if (customRenderer != null)
customRenderer.render(node);
customRenderer.render(node);

} catch (Exception e) {
TheWorkMod.LOGGER.error(e.toString());
Expand All @@ -194,7 +198,7 @@ private void drawLink(AlchemyCircle circle, AlchemyLink link) {

var delta = destinationPosition.subtract(sourcePosition);

float angle = (float)MathHelper.atan2(-delta.z, delta.x);
float angle = (float) MathHelper.atan2(-delta.z, delta.x);
angle += MathHelper.PI * 0.5f;

float length = link.length;
Expand All @@ -203,7 +207,7 @@ private void drawLink(AlchemyCircle circle, AlchemyLink link) {
RenderingUtilities.translateMatrix(sourcePosition.x, 0, sourcePosition.z);
RenderingUtilities.rotateMatrix(0, angle, 0);

if(link.sourceNode.nodeType != AlchemyNodeTypes.NONE) {
if (link.sourceNode.nodeType != AlchemyNodeTypes.NONE) {
RenderingUtilities.translateMatrix(0, 0, 0.5f);
} else {
RenderingUtilities.translateMatrix(0, 0, LINE_THICKNESS * 2);
Expand All @@ -225,7 +229,7 @@ private void drawFullCircle(float radius, int segments) {
float circleMax = radius - LINE_THICKNESS;

//extra THICC for triangles bc my rendering code is bad
if(segments == 3)
if (segments == 3)
circleMax -= LINE_THICKNESS;

for (int i = 0; i < segments; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
public class AlchemyNodeTypeRenderer {

public int circleSides;
public float extraRotationAngle;

public void render(AlchemyNode node) {

Expand All @@ -15,4 +16,9 @@ public AlchemyNodeTypeRenderer withSides(int sides) {
this.circleSides = sides;
return this;
}

public AlchemyNodeTypeRenderer withRotation(float angle) {
this.extraRotationAngle = angle;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cassunshine.thework.alchemy.circle.node.type.AlchemyNodeType;
import cassunshine.thework.alchemy.circle.node.type.AlchemyNodeTypes;
import net.minecraft.util.math.MathHelper;

import java.util.HashMap;

Expand All @@ -16,13 +17,13 @@ private static void register(AlchemyNodeType type, AlchemyNodeTypeRenderer rende
renderers.put(type, renderer);
}

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

static {
register(AlchemyNodeTypes.DECONSTRUCT, new RuneAlchemyNodeTypeRenderer().withSides(4));
register(AlchemyNodeTypes.CONSTRUCT, new RuneAlchemyNodeTypeRenderer().withSides(6));
register(AlchemyNodeTypes.FILTER, new RuneAlchemyNodeTypeRenderer().withSides(3));
register(AlchemyNodeTypes.TRANSFER, new RuneAlchemyNodeTypeRenderer().withSides(4).withRotation(MathHelper.HALF_PI * 0.5f));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package cassunshine.thework.rendering.particles;

import cassunshine.thework.alchemy.circle.path.AlchemyPath;
import cassunshine.thework.particles.TheWorkParticles;
import net.minecraft.client.particle.ParticleTextureSheet;
import net.minecraft.client.particle.SpriteBillboardParticle;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.math.ColorHelper;
import net.minecraft.util.math.Vec3d;

public class PathParticle extends SpriteBillboardParticle {

private final Vec3d startPos;
private final Vec3d endPos;

private final double travelDistance;

private float progress = 0;

protected PathParticle(ClientWorld clientWorld, double x, double y, double z, double dstX, double dstY, double dstZ) {
super(clientWorld, x, y, z);
this.maxAge = Integer.MAX_VALUE;
this.setColor(ColorHelper.Argb.getRed(TheWorkParticles.particleColor) / 255.0f, ColorHelper.Argb.getGreen(TheWorkParticles.particleColor) / 255.0f, ColorHelper.Argb.getBlue(TheWorkParticles.particleColor) / 255.0f);
this.scale = 0.05f;

this.startPos = new Vec3d(x, y, z);
this.endPos = new Vec3d(dstX, dstY, dstZ);

this.travelDistance = startPos.distanceTo(endPos);

}

@Override
public ParticleTextureSheet getType() {
return ParticleTextureSheet.PARTICLE_SHEET_OPAQUE;
}

@Override
public void tick() {
super.tick();

if (progress >= travelDistance)
markDead();

//Move along path...
progress += AlchemyPath.TRAVEL_SPEED;

var progressFrac = progress / travelDistance;
Vec3d newPos = startPos.lerp(endPos, progressFrac);

x = newPos.x;
y = newPos.y;
z = newPos.z;
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package cassunshine.thework.rendering.particles;

import cassunshine.thework.alchemy.circle.path.AlchemyPath;
import cassunshine.thework.alchemy.circle.ring.AlchemyRing;
import cassunshine.thework.particles.TheWorkParticles;
import cassunshine.thework.utils.TheWorkUtils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.particle.*;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.particle.DefaultParticleType;
import net.minecraft.util.math.ColorHelper;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;


//TODO - Tidy :(
public class RadialParticle extends SpriteBillboardParticle {

private float radius;
Expand All @@ -31,19 +30,19 @@ protected RadialParticle(ClientWorld clientWorld, double x, double y, double z,
this.startAngle = (float) startAngle;
this.endAngle = (float) endAngle;

direction = startAngle < endAngle;

startPos = new Vec3d(x, y, z);
scale = 0.05f;

var angle = getAngle(progress);
prevPosX = x + MathHelper.sin(angle) * this.radius;
prevPosY = y;
prevPosZ = z + MathHelper.cos(angle) * this.radius;

this.maxAge = Integer.MAX_VALUE;
this.setColor(ColorHelper.Argb.getRed(TheWorkParticles.particleColor) / 255.0f, ColorHelper.Argb.getGreen(TheWorkParticles.particleColor) / 255.0f, ColorHelper.Argb.getBlue(TheWorkParticles.particleColor) / 255.0f);
this.scale = 0.05f;

this.setColor(ColorHelper.Argb.getRed(TheWorkParticles.radialColor) / 255.0f, ColorHelper.Argb.getGreen(TheWorkParticles.radialColor) / 255.0f, ColorHelper.Argb.getBlue(TheWorkParticles.radialColor) / 255.0f);

direction = startAngle < endAngle;
}

@Override
Expand All @@ -61,7 +60,6 @@ public void tick() {
super.tick();

float pathLength = (radius * MathHelper.TAU) * (TheWorkUtils.angleBetweenRadians(startAngle, endAngle) / MathHelper.TAU);

if (progress > pathLength)
markDead();

Expand All @@ -73,18 +71,4 @@ public void tick() {
x = startPos.x + MathHelper.sin(currentAngle) * radius;
z = startPos.z + MathHelper.cos(currentAngle) * radius;
}

public static class Factory implements ParticleFactory<DefaultParticleType> {
private final SpriteProvider spriteProvider;

public Factory(SpriteProvider spriteProvider) {
this.spriteProvider = spriteProvider;
}

public Particle createParticle(DefaultParticleType defaultParticleType, ClientWorld clientWorld, double x, double y, double z, double velX, double velY, double velZ) {
RadialParticle radialParticle = new RadialParticle(clientWorld, x, y, z, velX, velY, velZ);
radialParticle.setSprite(this.spriteProvider);
return radialParticle;
}
}
}
Loading

0 comments on commit 1982377

Please sign in to comment.