Skip to content

Commit

Permalink
Different Outline Colors for Input/Output
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Aug 25, 2024
1 parent e4f6fc8 commit 4b5f341
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.nomiceu.nomilabs.integration.betterp2p;

import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import kotlin.Pair;

import java.util.List;

public class LabsClientCache {

public static final List<Pair<BlockPos, EnumFacing>> inputLoc = new ObjectArrayList<>();
public static final List<Pair<BlockPos, EnumFacing>> outputLoc = new ObjectArrayList<>();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.nomiceu.nomilabs.mixin.betterp2p;

import com.nomiceu.nomilabs.integration.betterp2p.LabsClientCache;
import com.projecturanus.betterp2p.client.gui.InfoList;
import com.projecturanus.betterp2p.client.gui.InfoWrapper;
import kotlin.Pair;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -9,9 +13,12 @@
import com.projecturanus.betterp2p.client.gui.GuiAdvancedMemoryCard;
import com.projecturanus.betterp2p.client.gui.widget.WidgetTypeSelector;
import com.projecturanus.betterp2p.item.BetterMemoryCardModes;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

/**
* Allows accessing needed functions and fields.
* Allows accessing needed functions and fields. Also fills up LabsClientCache.
*/
@Mixin(value = GuiAdvancedMemoryCard.class, remap = false)
public abstract class GuiAdvancedMemoryCardMixin implements AccessibleGuiAdvancedMemoryCard {
Expand All @@ -26,6 +33,13 @@ public abstract class GuiAdvancedMemoryCardMixin implements AccessibleGuiAdvance
@Final
private WidgetTypeSelector typeSelector;

@Shadow
protected abstract InfoWrapper getSelectedInfo();

@Shadow
@Final
private InfoList infos;

@Override
@Unique
public BetterMemoryCardModes labs$getMode() {
Expand All @@ -49,4 +63,22 @@ public abstract class GuiAdvancedMemoryCardMixin implements AccessibleGuiAdvance
public void labs$closeTypeSelector() {
typeSelector.setVisible(false);
}

@Inject(method = "refreshOverlay", at = @At("HEAD"))
private void fillLabsCache(CallbackInfo ci) {
LabsClientCache.inputLoc.clear();
LabsClientCache.outputLoc.clear();

var selected = getSelectedInfo();
if (selected == null) return;

infos.getSorted().stream()
.filter(info -> info.getFrequency() == selected.getFrequency())
.filter(info -> info.getType() == selected.getType())
.filter(info -> info.getLoc().getDim() == selected.getLoc().getDim())
.filter(info -> !info.equals(selected))
.map(info -> new Pair<>(info.getOutput() ? LabsClientCache.outputLoc : LabsClientCache.inputLoc,
info.getLoc()))
.forEach(pair -> pair.getFirst().add(new Pair<>(pair.getSecond().getPos(), pair.getSecond().getFacing())));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.nomiceu.nomilabs.mixin.betterp2p;

import com.nomiceu.nomilabs.integration.betterp2p.LabsClientCache;
import com.projecturanus.betterp2p.client.render.OutlineRenderer;
import com.projecturanus.betterp2p.client.render.RenderHandler;
import kotlin.Pair;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import java.util.Collection;

/**
* Adds different overlay colors for Output/Input.
*/
@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);
}
}
1 change: 1 addition & 0 deletions src/main/resources/mixins.nomilabs.betterp2p.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"GuiAdvancedMemoryCardKtAccessor",
"GuiAdvancedMemoryCardMixin",
"ModeWidgetButtonMixin",
"RenderHandlerMixin",
"WidgetP2PColumnMixin",
"WidgetP2PDeviceMixin",
"WidgetTypeSelectorMixin"
Expand Down

0 comments on commit 4b5f341

Please sign in to comment.