Skip to content

Commit

Permalink
Refactor fusion reactor renderer (#2855)
Browse files Browse the repository at this point in the history
  • Loading branch information
omergunr100 authored Feb 12, 2025
1 parent 2d3a389 commit 71a64b6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/generated/resources/assets/gtceu/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,7 @@
"config.gtceu.option.machines": "sǝuıɥɔɐɯ",
"config.gtceu.option.machinesEmissiveTextures": "sǝɹnʇxǝ⟘ǝʌıssıɯƎsǝuıɥɔɐɯ",
"config.gtceu.option.meHatchEnergyUsage": "ǝbɐs∩ʎbɹǝuƎɥɔʇɐHǝɯ",
"config.gtceu.option.minerSpeed": "pǝǝdSɹǝuıɯ",
"config.gtceu.option.minimap": "dɐɯıuıɯ",
"config.gtceu.option.nanoSaber": "ɹǝqɐSouɐu",
"config.gtceu.option.nanoSaberBaseDamage": "ǝbɐɯɐᗡǝsɐᗺɹǝqɐSouɐu",
Expand Down
1 change: 1 addition & 0 deletions src/generated/resources/assets/gtceu/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,7 @@
"config.gtceu.option.machines": "machines",
"config.gtceu.option.machinesEmissiveTextures": "machinesEmissiveTextures",
"config.gtceu.option.meHatchEnergyUsage": "meHatchEnergyUsage",
"config.gtceu.option.minerSpeed": "minerSpeed",
"config.gtceu.option.minimap": "minimap",
"config.gtceu.option.nanoSaber": "nanoSaber",
"config.gtceu.option.nanoSaberBaseDamage": "nanoSaberBaseDamage",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class GTRenderTypes extends RenderType {
RenderType.CompositeState.builder()
.setCullState(NO_CULL)
.setShaderState(RenderStateShard.POSITION_COLOR_SHADER)
.setTransparencyState(RenderStateShard.TRANSLUCENT_TRANSPARENCY)
.createCompositeState(false));

private GTRenderTypes(String name, VertexFormat format, VertexFormat.Mode mode, int bufferSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,27 @@
import com.gregtechceu.gtceu.client.util.RenderBufferHelper;
import com.gregtechceu.gtceu.common.machine.multiblock.electric.FusionReactorMachine;

import com.lowdragmc.lowdraglib.utils.ColorUtils;
import com.lowdragmc.lowdraglib.utils.interpolate.Eases;
import com.lowdragmc.shimmer.client.shader.RenderUtils;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import com.mojang.blaze3d.vertex.PoseStack;

import static net.minecraft.util.FastColor.ARGB32.*;

public class FusionReactorRenderer extends WorkableCasingMachineRenderer {

public static final float FADEOUT = 60;

protected float delta = 0;
protected int lastColor = -1;

public FusionReactorRenderer(ResourceLocation baseCasing, ResourceLocation workableModel) {
super(baseCasing, workableModel);
}
Expand All @@ -33,6 +39,9 @@ public void render(BlockEntity blockEntity, float partialTicks, PoseStack stack,
int combinedLight, int combinedOverlay) {
if (blockEntity instanceof IMachineBlockEntity machineBlockEntity &&
machineBlockEntity.getMetaMachine() instanceof FusionReactorMachine machine) {
if (machine.getColor() == -1 && delta < 0) {
return;
}
if (GTCEu.Mods.isShimmerLoaded()) {
PoseStack finalStack = RenderUtils.copyPoseStack(stack);
BloomUtils.entityBloom(source -> renderLightRing(machine, partialTicks, finalStack, source));
Expand All @@ -46,24 +55,31 @@ public void render(BlockEntity blockEntity, float partialTicks, PoseStack stack,
private void renderLightRing(FusionReactorMachine machine, float partialTicks, PoseStack stack,
MultiBufferSource buffer) {
var color = machine.getColor();
if (color == -1) return;
int ringColor = ColorUtils.blendColor(color, -1, Eases.EaseQuadIn.getInterpolation(
Math.abs((Math.abs(machine.getOffsetTimer() % 50) + partialTicks) - 25) / 25));
var alpha = 1f;
if (color != -1) {
lastColor = color;
delta = FADEOUT;
} else {
alpha = delta / FADEOUT;
lastColor = color(Mth.floor(alpha * 255), red(lastColor), green(lastColor), blue(lastColor));
delta -= Minecraft.getInstance().getDeltaFrameTime();
}

final var lerpFactor = Math.abs((Math.abs(machine.getOffsetTimer() % 50) + partialTicks) - 25) / 25;
var front = machine.getFrontFacing();
var upwards = machine.getUpwardsFacing();
var flipped = machine.isFlipped();
Direction relativeBack = RelativeDirection.BACK.getRelativeFacing(front, upwards, flipped);
Direction.Axis axis = RelativeDirection.UP.getRelativeFacing(front, upwards, flipped).getAxis();
float a = ColorUtils.alpha(ringColor);
float r = ColorUtils.red(ringColor);
float g = ColorUtils.green(ringColor);
float b = ColorUtils.blue(ringColor);
var back = RelativeDirection.BACK.getRelativeFacing(front, upwards, flipped);
var axis = RelativeDirection.UP.getRelativeFacing(front, upwards, flipped).getAxis();
var r = Mth.lerp(lerpFactor, red(lastColor), 255) / 255f;
var g = Mth.lerp(lerpFactor, green(lastColor), 255) / 255f;
var b = Mth.lerp(lerpFactor, blue(lastColor), 255) / 255f;
RenderBufferHelper.renderRing(stack, buffer.getBuffer(GTRenderTypes.getLightRing()),
relativeBack.getStepX() * 7 + 0.5F,
relativeBack.getStepY() * 7 + 0.5F,
relativeBack.getStepZ() * 7 + 0.5F,
back.getStepX() * 7 + 0.5F,
back.getStepY() * 7 + 0.5F,
back.getStepZ() * 7 + 0.5F,
6, 0.2F, 10, 20,
r, g, b, a, axis);
r, g, b, alpha, axis);
}

@Override
Expand Down

0 comments on commit 71a64b6

Please sign in to comment.