Skip to content

Commit

Permalink
Blink Selected P2P + Unbound P2P Outline Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Dec 29, 2024
1 parent 5f27b9d commit 79dabcb
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 14 deletions.
19 changes: 19 additions & 0 deletions src/main/java/com/nomiceu/nomilabs/config/LabsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,25 @@ public static class ModIntegration {
@Config.Name("ae2 terminal options")
public final AE2TerminalOptions ae2TerminalOptions = new AE2TerminalOptions();

@Config.Comment("Better P2P Options")
@Config.LangKey("config.nomilabs.mod_integration.better_p2p")
@Config.Name("better p2p options")
public final BetterP2POptions betterP2POptions = new BetterP2POptions();

public static class BetterP2POptions {

@Config.Comment({ "Whether to highlight the Selected P2P by blinking, instead of with green.",
"Allows players to see whether the Selected P2P is Input or Output, but is less visible.",
"[default: true]" })
@Config.LangKey("config.nomilabs.mod_integration.better_p2p.blink")
public boolean blinkP2P = true;

@Config.Comment({ "Blink speed of Selected P2P in milliseconds.", "[default: 500]" })
@Config.LangKey("config.nomilabs.mod_integration.better_p2p.blink_speed")
@Config.RangeInt(min = 0)
public int blinkSpeed = 500;
}

public static class AE2TerminalOptions {

@Config.Comment({ "Whether to Auto-Focus the Fluid Terminal.", "[default: true]" })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ public class LabsClientCache {

public static final List<Pair<BlockPos, EnumFacing>> inputLoc = new ObjectArrayList<>();
public static final List<Pair<BlockPos, EnumFacing>> outputLoc = new ObjectArrayList<>();
public static boolean selectedIsOutput = false;
public static long lastSelectedRenderChange = 0;
public static boolean renderingSelected = true;
public static SortModes sortMode = SortModes.DEFAULT;
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,17 @@ private void properlyResetScrollbarFilterTyped(char typedChar, int keyCode, Call

@Inject(method = "refreshOverlay", at = @At("HEAD"))
private void fillLabsCache(CallbackInfo ci) {
LabsClientCache.selectedIsOutput = getSelectedInfo().getOutput();

// Reset time
LabsClientCache.lastSelectedRenderChange = System.currentTimeMillis();
LabsClientCache.renderingSelected = true;

LabsClientCache.inputLoc.clear();
LabsClientCache.outputLoc.clear();

var selected = getSelectedInfo();
if (selected == null) return;
if (selected == null || selected.getFrequency() == 0) return;

infos.getSorted().stream()
.filter(info -> info.getFrequency() == selected.getFrequency())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,81 @@
package com.nomiceu.nomilabs.mixin.betterp2p;

import java.util.Collection;
import java.util.List;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.client.event.RenderWorldLastEvent;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.google.common.collect.ImmutableList;
import com.nomiceu.nomilabs.config.LabsConfig;
import com.nomiceu.nomilabs.integration.betterp2p.LabsClientCache;
import com.projecturanus.betterp2p.client.ClientCache;
import com.projecturanus.betterp2p.client.render.OutlineRenderer;
import com.projecturanus.betterp2p.client.render.RenderHandler;
import com.projecturanus.betterp2p.item.ItemAdvancedMemoryCard;

import kotlin.Pair;

/**
* Adds different overlay colors for Output/Input.
* Adds different overlay colors for output/input, allows selected p2p to blink instead of be green.
*/
@Mixin(value = RenderHandler.class, remap = false)
public class RenderHandlerMixin {

/**
* Replace original outline handler.
*/
@Redirect(method = "renderOverlays",
at = @At(value = "INVOKE",
target = "Lcom/projecturanus/betterp2p/client/render/OutlineRenderer;renderOutlinesWithFacing(Lnet/minecraftforge/client/event/RenderWorldLastEvent;Lnet/minecraft/entity/player/EntityPlayer;Ljava/util/Collection;III)V",
ordinal = 1),
require = 1)
private static void replaceOriginalOutlineHandler(RenderWorldLastEvent evt, EntityPlayer p,
Collection<Pair<BlockPos, EnumFacing>> coordinates, int r, int g,
int b) {
OutlineRenderer.renderOutlinesWithFacing(evt, p, LabsClientCache.inputLoc, 0x6d, 0x9c, 0xf8);
OutlineRenderer.renderOutlinesWithFacing(evt, p, LabsClientCache.outputLoc, 0xec, 0xb3, 0x6c);
@Inject(method = "renderOverlays", at = @At(value = "HEAD"), cancellable = true)
private static void replaceOriginalOutlineHandler(RenderWorldLastEvent evt, CallbackInfo ci) {
ci.cancel();
EntityPlayer player = Minecraft.getMinecraft().player;
ClientCache cache = ClientCache.INSTANCE;

if (!(labs$heldIsMem(player, EnumHand.MAIN_HAND) || labs$heldIsMem(player, EnumHand.OFF_HAND))) return;

if (cache.getPositions().isEmpty() && cache.getSelectedPosition() == null) return;

boolean blinkSelected = LabsConfig.modIntegration.betterP2POptions.blinkP2P;
int blinkSpeed = LabsConfig.modIntegration.betterP2POptions.blinkSpeed;

if (cache.getSelectedPosition() != null) {
List<Pair<BlockPos, EnumFacing>> selectedList = ImmutableList
.of(new Pair<>(cache.getSelectedPosition(), cache.getSelectedFacing()));

if (!blinkSelected)
OutlineRenderer.renderOutlinesWithFacing(evt, player, selectedList, 0x45, 0xDA, 0x75);
else {
// Flip should render if needed
long time = System.currentTimeMillis();
if (time - LabsClientCache.lastSelectedRenderChange > blinkSpeed) {
LabsClientCache.lastSelectedRenderChange = time;
LabsClientCache.renderingSelected = !LabsClientCache.renderingSelected;
}

if (LabsClientCache.renderingSelected) {
if (LabsClientCache.selectedIsOutput)
OutlineRenderer.renderOutlinesWithFacing(evt, player, selectedList, 0xec, 0xb3, 0x6c);
else
OutlineRenderer.renderOutlinesWithFacing(evt, player, selectedList, 0x6d, 0x9c, 0xf8);
}
}
}

OutlineRenderer.renderOutlinesWithFacing(evt, player, LabsClientCache.inputLoc, 0x6d, 0x9c, 0xf8);
OutlineRenderer.renderOutlinesWithFacing(evt, player, LabsClientCache.outputLoc, 0xec, 0xb3, 0x6c);
}

@Unique
private static boolean labs$heldIsMem(EntityPlayer player, EnumHand hand) {
return player.getHeldItem(hand).getItem() instanceof ItemAdvancedMemoryCard;
}
}
4 changes: 4 additions & 0 deletions src/main/resources/assets/nomilabs/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ config.nomilabs.mod_integration.ae2_terminal.cfg_interface=Interface Configurati
config.nomilabs.mod_integration.ae2_terminal.cfg_fluid_interface=Fluid Interface Configuration Terminal Auto-Focusing
config.nomilabs.mod_integration.ae2_terminal.cfg_interface_save=Save Interface Configuration Terminal Searches

config.nomilabs.mod_integration.better_p2p=Better P2P Options
config.nomilabs.mod_integration.better_p2p.blink=Blink Selected P2P
config.nomilabs.mod_integration.better_p2p.blink_speed=Blink Selected P2P Speed

config.nomilabs.groovy=GroovyScript Extensions and Script Helper Settings
config.nomilabs.groovy.tooltip=GroovyScript Extensions and Script Helper Settings
config.nomilabs.groovy.hand=Enable GroovyScript Hand Command Additions
Expand Down

0 comments on commit 79dabcb

Please sign in to comment.