Skip to content

Commit

Permalink
1.1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
LasmGratel committed Oct 19, 2021
1 parent 1cc09b8 commit 62dc930
Show file tree
Hide file tree
Showing 35 changed files with 639 additions and 96 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Obtain a Better Memory Card.

![](img/showcase0.png)

Right click on a P2P device or any ME attached device to inspect all P2P devices in your ME Network.
Right-click on a P2P device or any ME attached device to inspect all P2P devices in your ME Network.

![](img/showcase1.png)

Expand All @@ -28,11 +28,28 @@ A wrong setup (usually P2P devices without input) will be in red color, and devi

![](img/showcase4.png)

Version 1.1 update:

P2P location is shown.

![](img/showcase5.png)

When you select one of the P2P device, outlines will render at other devices with same frequency.

You can Shift-click better memory card to clean this outline.

![](img/showcase6.png)

## TODOs

- [ ] Documentation
- [ ] Sort modes
- [ ] Better predicate to reduce crashes
- [ ] Backport to 1.7.10
- [ ] A green border show in the world to identify the selected P2P device
- [X] A border show in the world to identify the selected P2P device
- [ ] Optimize cache
- [ ] A minimap shows all P2P devices

## Credits

Cyclic for its block outline code
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ dependencies {
implementation "net.shadowfacts:Forgelin:1.8.4"
}

sourceJar {
duplicatesStrategy = DuplicatesStrategy.WARN
}

processResources
{
duplicatesStrategy = DuplicatesStrategy.WARN
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ org.gradle.jvmargs=-Xmx3G

# Mod Properties
mod_id = betterp2p
mod_version = 1.0.0
mod_version = 1.1.0
mod_group = com.projecturanus.betterp2p

# Minecraft & Forge
Expand Down
Binary file added img/showcase5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/showcase6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 1 addition & 4 deletions src/main/java/com/projecturanus/betterp2p/BetterP2P.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
package com.projecturanus.betterp2p

import com.projecturanus.betterp2p.client.ModGuiHandler
import com.projecturanus.betterp2p.network.ModNetwork
import net.minecraftforge.fml.common.Mod
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent
import net.minecraftforge.fml.common.network.NetworkRegistry
import org.apache.logging.log4j.Logger

const val MODID = "betterp2p"

@Mod(modid = MODID, modLanguageAdapter = "net.shadowfacts.forgelin.KotlinAdapter", dependencies = "required-after: appliedenergistics2")
@Mod(modid = MODID, modLanguageAdapter = "net.shadowfacts.forgelin.KotlinAdapter", dependencies = "required-after: appliedenergistics2; required-after: forgelin;")
object BetterP2P {
lateinit var logger: Logger

@Mod.EventHandler
fun preInit(event: FMLPreInitializationEvent) {
logger = event.modLog
NetworkRegistry.INSTANCE.registerGuiHandler(this, ModGuiHandler)
ModNetwork.registerNetwork()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.projecturanus.betterp2p.capability

import com.projecturanus.betterp2p.item.BetterMemoryCardModes

data class MemoryInfo(var selectedIndex: Int = -1, var mode: BetterMemoryCardModes = BetterMemoryCardModes.OUTPUT)
16 changes: 16 additions & 0 deletions src/main/java/com/projecturanus/betterp2p/client/ClientCache.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.projecturanus.betterp2p.client

import net.minecraft.util.EnumFacing
import net.minecraft.util.math.BlockPos

object ClientCache {
val positions = mutableListOf<Pair<BlockPos, EnumFacing>>()
var selectedPosition: BlockPos? = null
var selectedFacing: EnumFacing? = null

fun clear() {
positions.clear()
selectedPosition = null
selectedFacing = null
}
}
19 changes: 0 additions & 19 deletions src/main/java/com/projecturanus/betterp2p/client/ModGuiHandler.kt

This file was deleted.

16 changes: 0 additions & 16 deletions src/main/java/com/projecturanus/betterp2p/client/RenderHandler.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.projecturanus.betterp2p.client
package com.projecturanus.betterp2p.client.gui

import appeng.util.Platform
import com.projecturanus.betterp2p.MODID
import com.projecturanus.betterp2p.capability.MemoryInfo
import com.projecturanus.betterp2p.client.ClientCache
import com.projecturanus.betterp2p.client.TextureBound
import com.projecturanus.betterp2p.client.gui.widget.WidgetScrollBar
import com.projecturanus.betterp2p.item.BetterMemoryCardModes
import com.projecturanus.betterp2p.network.*
import net.minecraft.client.gui.GuiButton
import net.minecraft.client.gui.GuiScreen
Expand All @@ -28,7 +33,7 @@ class GuiBetterMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
private val rowWidth = 203
private val rowHeight = 22

private var selectedIndex = msg.targetIndex
private var selectedIndex = -1

private lateinit var scrollBar: WidgetScrollBar

Expand All @@ -43,11 +48,12 @@ class GuiBetterMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {

private var infoOnScreen: List<InfoWrapper>

private var mode = BetterMemoryCardModes.OUTPUT
private var mode = msg.memoryInfo.mode
private var modeString = getModeString()
private val modeButton by lazy { GuiButton(0, guiLeft + 8, guiTop + 140, 205, 20, modeString) }

init {
selectInfo(msg.memoryInfo.selectedIndex)
sortInfo()
infoOnScreen = sortedInfo.take(5)
}
Expand Down Expand Up @@ -100,6 +106,10 @@ class GuiBetterMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
.take(5)
}

fun syncMemoryInfo() {
ModNetwork.channel.sendToServer(C2SUpdateInfo(MemoryInfo(selectedIndex, mode)))
}

private fun drawButtons(info: InfoWrapper, x: Int, y: Int, mouseX: Int, mouseY: Int, partialTicks: Float) {
if (!info.bindButton.enabled && info.selectButton.enabled) {
info.bindButton.enabled = false
Expand Down Expand Up @@ -166,7 +176,8 @@ class GuiBetterMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
drawRect(x, y, x + rowWidth, y + rowHeight, outputColor)
}

fontRenderer.drawString(info.description, x + 32, y + 3, 0)
fontRenderer.drawString(info.description, x + 24, y + 3, 0)
fontRenderer.drawString(I18n.format("gui.better_memory_card.pos", info.pos.x, info.pos.y, info.pos.z), x + 24, y + 12, 0)

if (selectedIndex == -1) {
info.bindButton.enabled = false
Expand All @@ -185,6 +196,7 @@ class GuiBetterMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
}

override fun onGuiClosed() {
syncMemoryInfo()
ModNetwork.channel.sendToServer(C2SCloseGui())
}

Expand All @@ -206,6 +218,7 @@ class GuiBetterMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
mode = BetterMemoryCardModes.values()[mode.ordinal.plus(1) % BetterMemoryCardModes.values().size]
modeString = getModeString()
modeButton.displayString = modeString
syncMemoryInfo()
}

private fun getModeString(): String {
Expand All @@ -217,6 +230,12 @@ class GuiBetterMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {

fun selectInfo(index: Int) {
selectedIndex = index
syncMemoryInfo()

ClientCache.selectedPosition = selectedInfo?.pos
ClientCache.selectedFacing = selectedInfo?.facing
ClientCache.positions.clear()
ClientCache.positions.addAll(infos.filter { it.frequency == selectedInfo?.frequency && it != selectedInfo }.map { it.pos to it.facing })
}

private fun onSelectButtonClicked(info: InfoWrapper) {
Expand All @@ -228,16 +247,16 @@ class GuiBetterMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
when (mode) {
BetterMemoryCardModes.INPUT -> {
println("Bind ${info.index} as input")
ModNetwork.channel.sendToServer(C2SUpdateInfo(info.index, selectedIndex))
ModNetwork.channel.sendToServer(C2SLinkP2P(info.index, selectedIndex))
}
BetterMemoryCardModes.OUTPUT -> {
println("Bind ${info.index} as output")
ModNetwork.channel.sendToServer(C2SUpdateInfo(selectedIndex, info.index))
ModNetwork.channel.sendToServer(C2SLinkP2P(selectedIndex, info.index))
}
BetterMemoryCardModes.COPY -> {
val input = selectedInfo?.frequency?.let { findInput(it) }
if (input != null)
ModNetwork.channel.sendToServer(C2SUpdateInfo(input.index, info.index))
ModNetwork.channel.sendToServer(C2SLinkP2P(input.index, info.index))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.projecturanus.betterp2p.client
package com.projecturanus.betterp2p.client.gui

enum class InfoSortStrategy(val comparator: (InfoWrapper, InfoWrapper) -> Int) : Comparator<InfoWrapper> {
DEFAULT({ o1, o2 ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.projecturanus.betterp2p.client
package com.projecturanus.betterp2p.client.gui

import appeng.util.Platform
import com.projecturanus.betterp2p.network.P2PInfo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.projecturanus.betterp2p.client
package com.projecturanus.betterp2p.client.gui.widget

import com.projecturanus.betterp2p.client.TextureBound
import net.minecraft.client.gui.Gui
import net.minecraft.client.renderer.GlStateManager

Expand Down
Loading

0 comments on commit 62dc930

Please sign in to comment.