Skip to content

Commit

Permalink
Small adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Edivad99 committed Feb 25, 2024
1 parent c7d4cad commit 1b47c3b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import java.util.Collection;
import com.mojang.blaze3d.vertex.PoseStack;
import mods.railcraft.client.util.LineRenderer;
import mods.railcraft.client.util.SimpleLineRenderer;
import mods.railcraft.network.play.LinkedCartsMessage;
import mods.railcraft.world.item.GogglesItem;
import mods.railcraft.world.item.RailcraftItems;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.vehicle.AbstractMinecart;
import net.minecraft.world.level.Level;
Expand Down Expand Up @@ -47,15 +49,15 @@ public void render(PoseStack poseStack, Camera mainCamera, float partialTick) {
continue;
}

var renderer = LineRenderer.create(bufferSource);
var renderer = new SimpleLineRenderer(bufferSource);
final int color = linkedCart.trainId().hashCode();
final var cartPosition = cart.getPosition(partialTick);

renderer.renderLine(poseStack, color, cartPosition, cartPosition.add(0, 2, 0));
this.renderLink(level, cartPosition, linkedCart.linkAId(), color, partialTick, renderer, poseStack);
this.renderLink(level, cartPosition, linkedCart.linkBId(), color, partialTick, renderer, poseStack);

bufferSource.endBatch();
bufferSource.endBatch(RenderType.lines());
}
poseStack.popPose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import mods.railcraft.api.signal.BlockSignalEntity;
import mods.railcraft.api.signal.TokenSignalEntity;
import mods.railcraft.api.signal.entity.SignalControllerEntity;
import mods.railcraft.client.util.LineRenderer;
import mods.railcraft.client.util.RenderUtil;
import mods.railcraft.client.util.SimpleLineRenderer;
import mods.railcraft.world.item.GogglesItem;
Expand Down Expand Up @@ -59,7 +60,7 @@ private static void renderSignalAuraf(
}

var renderer = new SimpleLineRenderer(bufferSource);
for (Vec3 target : endPoints) {
for (var target : endPoints) {
int color = colorProfile.getColor(blockEntity, blockEntity.getBlockPos(), BlockPos.containing(target));
float red = RenderUtil.getRed(color);
float green = RenderUtil.getGreen(color);
Expand All @@ -84,8 +85,8 @@ private static void renderSignalAura(
return;
}

var renderer = new SimpleLineRenderer(bufferSource);
for (BlockPos target : endPoints) {
var renderer = LineRenderer.create(bufferSource);
for (var target : endPoints) {
int color = colorProfile.getColor(blockEntity, blockEntity.getBlockPos(), target);
float red = RenderUtil.getRed(color);
float green = RenderUtil.getGreen(color);
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/mods/railcraft/client/util/LineRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

import org.joml.Vector3f;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.world.phys.Vec3;

public interface LineRenderer {
static LineRenderer create(MultiBufferSource bufferSource) {
return new SimpleLineRenderer(bufferSource);
}

default void renderLine(PoseStack poseStack, int color, Vec3 from, Vec3 to) {
renderLine(poseStack,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class SimpleLineRenderer implements LineRenderer {
private final VertexConsumer consumer;

public SimpleLineRenderer(MultiBufferSource bufferSource) {
consumer = bufferSource.getBuffer(RenderType.lines());
this.consumer = bufferSource.getBuffer(RenderType.lines());
}

public void renderLine(PoseStack poseStack, float r, float g, float b, float x0, float y0, float z0, float x1, float y1, float z1) {
Expand All @@ -22,12 +22,12 @@ public void renderLine(PoseStack poseStack, float r, float g, float b, float x0,
int nx = i == 0 ? 1 : 0;
int ny = i == 1 ? 1 : 0;
int nz = i == 2 ? 1 : 0;
consumer
this.consumer
.vertex(matrix, x0, y0, z0)
.color(r, g, b, 1)
.normal(normal, nx, ny, nz)
.endVertex();
consumer
this.consumer
.vertex(matrix, x1, y1, z1)
.color(r, g, b, 1)
.normal(normal, nx, ny, nz)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,17 @@ public void load(CompoundTag tag) {
public void writeToBuf(FriendlyByteBuf data) {
super.writeToBuf(data);
this.signalController.writeToBuf(data);
data.writeFloat((float) this.ringCentroidPos.x());
data.writeFloat((float) this.ringCentroidPos.y());
data.writeFloat((float) this.ringCentroidPos.z());
data.writeDouble(this.ringCentroidPos.x());
data.writeDouble(this.ringCentroidPos.y());
data.writeDouble(this.ringCentroidPos.z());
data.writeUUID(this.ringId);
}

@Override
public void readFromBuf(FriendlyByteBuf data) {
super.readFromBuf(data);
this.signalController.readFromBuf(data);
this.ringCentroidPos = new Vec3(data.readFloat(), data.readFloat(), data.readFloat());
this.ringCentroidPos = new Vec3(data.readDouble(), data.readDouble(), data.readDouble());
this.ringId = data.readUUID();
}

Expand Down

0 comments on commit 1b47c3b

Please sign in to comment.