diff --git a/src/main/java/com/nomiceu/nomilabs/integration/betterp2p/LabsClientCache.java b/src/main/java/com/nomiceu/nomilabs/integration/betterp2p/LabsClientCache.java new file mode 100644 index 0000000..d44d2ec --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/integration/betterp2p/LabsClientCache.java @@ -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> inputLoc = new ObjectArrayList<>(); + public static final List> outputLoc = new ObjectArrayList<>(); +} diff --git a/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/GuiAdvancedMemoryCardMixin.java b/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/GuiAdvancedMemoryCardMixin.java index 0fd89b5..8651a69 100644 --- a/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/GuiAdvancedMemoryCardMixin.java +++ b/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/GuiAdvancedMemoryCardMixin.java @@ -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; @@ -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 { @@ -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() { @@ -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()))); + } } diff --git a/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/RenderHandlerMixin.java b/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/RenderHandlerMixin.java new file mode 100644 index 0000000..a8b69de --- /dev/null +++ b/src/main/java/com/nomiceu/nomilabs/mixin/betterp2p/RenderHandlerMixin.java @@ -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> 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); + } +} diff --git a/src/main/resources/mixins.nomilabs.betterp2p.json b/src/main/resources/mixins.nomilabs.betterp2p.json index b65db0f..70db9c5 100644 --- a/src/main/resources/mixins.nomilabs.betterp2p.json +++ b/src/main/resources/mixins.nomilabs.betterp2p.json @@ -14,6 +14,7 @@ "GuiAdvancedMemoryCardKtAccessor", "GuiAdvancedMemoryCardMixin", "ModeWidgetButtonMixin", + "RenderHandlerMixin", "WidgetP2PColumnMixin", "WidgetP2PDeviceMixin", "WidgetTypeSelectorMixin"