Skip to content

Commit

Permalink
Auto-cancel vanilla block outline of highlighted blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Feb 1, 2025
1 parent 02ae957 commit ab3f88d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void addBlocks(BlockPos from, BlockPos to, KubeColor color) {
}

public void addTargetBlock(KubeColor color) {
if (Minecraft.getInstance().hitResult instanceof BlockHitResult hit && hit.getType() == HitResult.Type.BLOCK) {
if (mc.hitResult instanceof BlockHitResult hit && hit.getType() == HitResult.Type.BLOCK) {
addBlock(hit.getBlockPos(), color);
}
}
Expand Down Expand Up @@ -121,10 +121,6 @@ public void addTargetEntity(KubeColor color) {
}
}

public void cancelBlockHighlight() {
renderer.cancelBlockHighlight = true;
}

public void addTarget(KubeColor color) {
if (mc.hitResult instanceof EntityHitResult hit) {
addEntity(hit.getEntity(), color);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
import dev.latvian.mods.kubejs.plugin.builtin.event.ClientEvents;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap;
import it.unimi.dsi.fastutil.longs.Long2IntLinkedOpenHashMap;
import it.unimi.dsi.fastutil.longs.Long2IntMap;
import it.unimi.dsi.fastutil.objects.Reference2IntLinkedOpenHashMap;
import it.unimi.dsi.fastutil.objects.Reference2IntMap;
import net.minecraft.CrashReport;
import net.minecraft.CrashReportCategory;
import net.minecraft.ReportedException;
Expand Down Expand Up @@ -62,15 +64,9 @@

public class HighlightRenderer {
public enum Mode {
NONE(false),
SCREEN(false),
WORLD(true);

public final boolean cancelBlockHighlight;

Mode(boolean cancelBlockHighlight) {
this.cancelBlockHighlight = cancelBlockHighlight;
}
NONE,
SCREEN,
WORLD
}

public record ShaderChain(PostChain postChain, RenderTarget renderInput, RenderTarget mcDepthInput, RenderTarget renderOutput, MutableBoolean renderAnything) {
Expand Down Expand Up @@ -218,8 +214,8 @@ public VertexConsumer setNormal(float f, float g, float h) {
public ShaderInstance highlightShader;

public final Set<Slot> hoveredSlots = new HashSet<>();
public final Reference2IntOpenHashMap<Entity> highlightedEntities = new Reference2IntOpenHashMap<>(0);
public final Long2IntOpenHashMap highlightedBlocks = new Long2IntOpenHashMap(0);
public final Reference2IntMap<Entity> highlightedEntities = new Reference2IntLinkedOpenHashMap<>(0);
public final Long2IntMap highlightedBlocks = new Long2IntLinkedOpenHashMap(0);
public final IntOpenHashSet uniqueColors = new IntOpenHashSet(0);
public boolean cancelBlockHighlight;

Expand Down Expand Up @@ -258,7 +254,7 @@ public void tickPre(Minecraft mc) {
highlightedEntities.clear();
highlightedBlocks.clear();
uniqueColors.clear();
cancelBlockHighlight = mode.cancelBlockHighlight;
cancelBlockHighlight = false;

if (mc.level != null && mc.player != null) {
var event = new HighlightKubeEvent(mc, this);
Expand All @@ -267,6 +263,10 @@ public void tickPre(Minecraft mc) {
if (mode == Mode.WORLD) {
event.addTarget(color);
}

if (mc.hitResult instanceof BlockHitResult hit && hit.getType() == HitResult.Type.BLOCK && highlightedBlocks.containsKey(hit.getBlockPos().asLong())) {
cancelBlockHighlight = true;
}
}
}

Expand Down Expand Up @@ -568,9 +568,5 @@ public void screen(Minecraft mc, GuiGraphics graphics, AbstractContainerScreen<?
}

public void hudPostDraw(Minecraft mc, GuiGraphics graphics, float delta) {
if (worldChain != null) {
graphics.flush();
// worldChain.draw(mc, delta);
}
}
}

0 comments on commit ab3f88d

Please sign in to comment.