Skip to content

Commit

Permalink
Redesign reacharound hud
Browse files Browse the repository at this point in the history
  • Loading branch information
Vazkii committed Jan 6, 2024
1 parent d1e66ad commit 53e0574
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
package org.violetmoon.quark.content.tweaks.module;

import java.util.List;

import org.apache.commons.lang3.tuple.Pair;
import org.violetmoon.quark.base.Quark;
import org.violetmoon.quark.base.config.Config;
import org.violetmoon.zeta.client.event.play.ZClientTick;
import org.violetmoon.zeta.client.event.play.ZRenderGuiOverlay;
import org.violetmoon.zeta.event.bus.LoadEvent;
import org.violetmoon.zeta.event.bus.PlayEvent;
import org.violetmoon.zeta.event.bus.ZPhase;
import org.violetmoon.zeta.event.load.ZCommonSetup;
import org.violetmoon.zeta.event.play.entity.player.ZRightClickItem;
import org.violetmoon.zeta.module.ZetaLoadModule;
import org.violetmoon.zeta.module.ZetaModule;

import com.google.common.collect.Lists;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.platform.Window;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;

import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -31,26 +48,12 @@
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;

import org.apache.commons.lang3.tuple.Pair;

import org.violetmoon.quark.base.Quark;
import org.violetmoon.quark.base.config.Config;
import org.violetmoon.quark.base.config.type.inputtable.RGBColorConfig;
import org.violetmoon.zeta.client.event.play.ZClientTick;
import org.violetmoon.zeta.client.event.play.ZRenderGuiOverlay;
import org.violetmoon.zeta.event.bus.LoadEvent;
import org.violetmoon.zeta.event.bus.PlayEvent;
import org.violetmoon.zeta.event.bus.ZPhase;
import org.violetmoon.zeta.event.load.ZCommonSetup;
import org.violetmoon.zeta.event.play.entity.player.ZRightClickItem;
import org.violetmoon.zeta.module.ZetaLoadModule;
import org.violetmoon.zeta.module.ZetaModule;

import java.util.List;

@ZetaLoadModule(category = "tweaks")
public class ReacharoundPlacingModule extends ZetaModule {

public static final ResourceLocation OVERLAY_HORIZONTAL = new ResourceLocation(Quark.MOD_ID, "textures/gui/reacharound_overlay_horizontal.png");
public static final ResourceLocation OVERLAY_VERTICAL = new ResourceLocation(Quark.MOD_ID, "textures/gui/reacharound_overlay_vertical.png");

@Config
@Config.Min(0)
@Config.Max(1)
Expand All @@ -60,12 +63,7 @@ public class ReacharoundPlacingModule extends ZetaModule {
public List<String> whitelist = Lists.newArrayList();
@Config
public List<String> blacklist = Lists.newArrayList();
@Config
public String display = "[ ]";
@Config
public String displayHorizontal = "< >";
@Config
public RGBColorConfig color = RGBColorConfig.forColor(1, 1, 1);


protected ReacharoundTarget currentTarget;
protected int ticksDisplayed;
Expand Down Expand Up @@ -199,31 +197,42 @@ protected record ReacharoundTarget(BlockPos pos, Direction dir, InteractionHand
public static class Client extends ReacharoundPlacingModule {

@PlayEvent
public void onRender(ZRenderGuiOverlay.Crosshair event) {
public void onRender(ZRenderGuiOverlay.Crosshair.Post event) {
GuiGraphics guiGraphics = event.getGuiGraphics();

Minecraft mc = Minecraft.getInstance();
Player player = mc.player;

if(mc.options.hideGui)
return;

HitResult result = mc.hitResult;
if(result instanceof BlockHitResult bhr) {
BlockPos hitPos = bhr.getBlockPos();
BlockState stateAt = player.level().getBlockState(hitPos);
if(!stateAt.isAir())
return;
}


if(player != null && currentTarget != null) {
Window res = event.getWindow();
PoseStack matrix = event.getGuiGraphics().pose();
String text = (currentTarget.dir.getAxis() == Axis.Y ? display : displayHorizontal);

matrix.pushPose();
matrix.translate(res.getGuiScaledWidth() / 2F, res.getGuiScaledHeight() / 2f - 4, 0);
boolean vertical = (currentTarget.dir.getAxis() == Axis.Y);
ResourceLocation texture = (vertical ? OVERLAY_VERTICAL : OVERLAY_HORIZONTAL);

RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.ONE_MINUS_DST_COLOR, GlStateManager.DestFactor.ONE_MINUS_SRC_COLOR, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);

float scale = Math.min(5, ticksDisplayed + event.getPartialTick()) / 5F;
scale *= scale;
int opacity = ((int) (255 * scale)) << 24;
matrix.pushPose();
int x = res.getGuiScaledWidth() / 2 - 7;
int y = res.getGuiScaledHeight() / 2 - 7;
guiGraphics.blit(texture, x, y, 0, 0, 16, 16, 16, 16);

matrix.scale(scale, 1F, 1F);
matrix.translate(-mc.font.width(text) / 2f, 0, 0);
guiGraphics.drawString(mc.font, text, 0, 0, color.getColor() | opacity, false);
matrix.popPose();

RenderSystem.defaultBlendFunc();

}
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 53e0574

Please sign in to comment.