Browse Source

help

master
Martmists 1 month ago
parent
commit
d7791774b2
20 changed files with 242 additions and 81 deletions
  1. +8
    -0
      build.gradle
  2. +2
    -1
      gradle.properties
  3. +9
    -5
      src/main/kotlin/com/martmists/ynet/YNetMod.kt
  4. +5
    -3
      src/main/kotlin/com/martmists/ynet/blockentity/ControllerBlockEntity.kt
  5. +10
    -0
      src/main/kotlin/com/martmists/ynet/ext/Color.kt
  6. +7
    -9
      src/main/kotlin/com/martmists/ynet/network/Network.kt
  7. +65
    -47
      src/main/kotlin/com/martmists/ynet/screen/ControllerConfigScreenHandler.kt
  8. +1
    -2
      src/main/kotlin/com/martmists/ynet/screen/util/ColoredButtonWidget.kt
  9. +22
    -0
      src/main/kotlin/com/martmists/ynet/screen/util/CustomTooltipItemWidget.kt
  10. +6
    -12
      src/main/kotlin/com/martmists/ynet/screen/util/WidgetBuilder.kt
  11. +11
    -0
      src/main/kotlin/com/martmists/ynet/support/RebornEnergySupport.kt
  12. +11
    -0
      src/main/kotlin/com/martmists/ynet/support/VanillaSupport.kt
  13. +9
    -0
      src/main/kotlin/com/martmists/ynet/transfer/data/EnergyTransferData.kt
  14. +16
    -0
      src/main/kotlin/com/martmists/ynet/transfer/handler/EnergyTransferHandler.kt
  15. +2
    -0
      src/main/kotlin/com/martmists/ynet/transfer/handler/TransferHandler.kt
  16. +28
    -0
      src/main/kotlin/com/martmists/ynet/transfer/proxy/EnergyTransferProxy.kt
  17. +1
    -1
      src/main/kotlin/com/martmists/ynet/transfer/type/DisabledType.kt
  18. +17
    -0
      src/main/kotlin/com/martmists/ynet/transfer/type/EnergyType.kt
  19. +0
    -1
      src/main/kotlin/com/martmists/ynet/transfer/type/ItemType.kt
  20. +12
    -0
      src/main/resources/fabric.mod.json

+ 8
- 0
build.gradle View File

@@ -16,6 +16,13 @@ plugins {

sourceCompatibility = 1.8
targetCompatibility = 1.8
compileKotlin {
kotlinOptions {
jvmTarget = '1.8'
}
}


archivesBaseName = "${project.mod_name}-${project.mod_version}+${project.minecraft_version}"

dependencies {
@@ -29,6 +36,7 @@ dependencies {
modApi ("alexiil.mc.lib:libblockattributes-fatjar_devonly:0.7.0") {
transitive = false
}
modApi ("teamreborn:energy:${project.tr_energy_version}")
modImplementation ("com.github.vini2003:blade:${project.blade_version}")

include "alexiil.mc.lib:libblockattributes-all:0.7.0"


+ 2
- 1
gradle.properties View File

@@ -8,4 +8,5 @@ yarn_mappings=1.16.2+build.42
loader_version=0.9.2+build.206
fabric_version=0.19.0+build.398-1.16
fabric_language_kotlin=1.4.0+build.1
blade_version=d3dce1f
blade_version=d3dce1f
tr_energy_version=0.1.0

+ 9
- 5
src/main/kotlin/com/martmists/ynet/YNetMod.kt View File

@@ -20,14 +20,12 @@ import net.minecraft.util.registry.Registry
import com.martmists.ynet.blockentity.ControllerBlockEntity
import com.martmists.ynet.screen.ControllerConfigScreenHandler
import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry
import net.fabricmc.loader.api.FabricLoader
import net.minecraft.util.math.BlockPos
import net.minecraft.world.World
import java.util.function.Supplier

object YNetMod : ModInitializer {
// === YNET TYPES ===
val ITEM_TYPE = YNetRegistry.register(ItemType, ItemTransferHandler)

// === BLOCKS ===
val YNET_GROUP = FabricItemGroupBuilder.build(Identifier("ynet:items")) { ItemStack(Registry.ITEM[Identifier("ynet:controller")]) }
val CABLE = register("cable", CableBlock(AbstractBlock.Settings.of(Material.METAL)))
@@ -54,7 +52,6 @@ object YNetMod : ModInitializer {

internal fun shouldConnect(world: World, pos: BlockPos): Boolean {
return world.getBlockState(pos).block === CONTROLLER || YNetRegistry.getTypes().any {
println("Type: $it")
it.appliesTo(world, pos)
}
}
@@ -65,6 +62,13 @@ object YNetMod : ModInitializer {
}

override fun onInitialize() {

FabricLoader.getInstance().getEntrypoints("ynet:support", Runnable::class.java).forEach {
try {
it.run()
} catch (e: Exception) {
println("An error occurred during ynet:support entrypoint $it")
e.printStackTrace()
}
}
}
}

+ 5
- 3
src/main/kotlin/com/martmists/ynet/blockentity/ControllerBlockEntity.kt View File

@@ -1,12 +1,12 @@
package com.martmists.ynet.blockentity

import com.martmists.ynet.YNetMod
import com.martmists.ynet.util.YNetRegistry
import com.martmists.ynet.network.Channel
import com.martmists.ynet.network.ConfiguredBlockEntity
import com.martmists.ynet.network.InteractionMode
import com.martmists.ynet.network.Network
import com.martmists.ynet.transfer.type.DisabledType
import com.martmists.ynet.util.YNetRegistry
import net.fabricmc.fabric.api.util.NbtType
import net.minecraft.block.BlockState
import net.minecraft.block.entity.BlockEntity
@@ -28,6 +28,7 @@ class ControllerBlockEntity : BlockEntity(YNetMod.CONTROLLER_BE), Tickable {

override fun fromTag(state: BlockState, tag: CompoundTag) {
super.fromTag(state, tag)
println("fromTag: $tag")
val data = tag.getCompound("controllerData")
val channels = data.getList("channels", NbtType.COMPOUND)
channels.forEachIndexed { index, tag ->
@@ -38,7 +39,7 @@ class ControllerBlockEntity : BlockEntity(YNetMod.CONTROLLER_BE), Tickable {

val channel = Channel(this.network, mutableListOf(), type ?: DisabledType)

if (channel.type == DisabledType) return@forEachIndexed;
if (channel.type == DisabledType) return@forEachIndexed

for (block in blocks) {
block as CompoundTag
@@ -52,7 +53,7 @@ class ControllerBlockEntity : BlockEntity(YNetMod.CONTROLLER_BE), Tickable {
channel.connectedBlocks.add(cbe)
}

network.channels[index] = channel;
network.channels[index] = channel
}
}

@@ -83,6 +84,7 @@ class ControllerBlockEntity : BlockEntity(YNetMod.CONTROLLER_BE), Tickable {
}
data.put("channels", channels)
tag.put("controllerData", data)
println("toTag: $tag")
return tag
}
}

+ 10
- 0
src/main/kotlin/com/martmists/ynet/ext/Color.kt View File

@@ -0,0 +1,10 @@
package com.martmists.ynet.ext

import com.github.vini2003.blade.common.data.Color

fun Color.Companion.ofRGB(v: Int): Color {
return Color(((v shr 16) and 0xFF) / 255.0f,
((v shr 8) and 0xFF) / 255.0f,
((v shr 0) and 0xFF) / 255.0f,
0f)
}

+ 7
- 9
src/main/kotlin/com/martmists/ynet/network/Network.kt View File

@@ -47,6 +47,7 @@ class Network(val be: ControllerBlockEntity) {
})
channels[index] = new
}
be.markDirty()
}

private fun getNeighbors(pos: BlockPos) = listOf(pos.up(), pos.down(), pos.north(), pos.east(), pos.south(), pos.west()).map { it.asLong() }
@@ -58,12 +59,9 @@ class Network(val be: ControllerBlockEntity) {
val next = toScan.elementAt(0)
toScan.remove(next)

println("Removed $next")

for (side in getNeighbors(BlockPos.fromLong(next))) {
if (side !in scanned) {
scanned.add(side)
println("Marking $side")

val b = world.getBlockState(BlockPos.fromLong(side)).block
if (b === YNetMod.CABLE) {
@@ -84,8 +82,12 @@ class Network(val be: ControllerBlockEntity) {
rescan()
didInit = true
}

if (world.isClient) return

channels.forEach {
if (it.type != DisabledType) {
println("ticking channel $it of type ${it.type}")
YNetRegistry.getHandler(it.type)?.tick(it as Channel<Type>)
}
}
@@ -105,12 +107,8 @@ class Network(val be: ControllerBlockEntity) {
}
}

println(allBlocks)

return allBlocks.map {
println(BlockPos.fromLong(it))
println(world.getBlockState(BlockPos.fromLong(it)))
world.getBlockEntity(BlockPos.fromLong(it))!!
return allBlocks.mapNotNull {
world.getBlockEntity(BlockPos.fromLong(it))
}.toList()
}



+ 65
- 47
src/main/kotlin/com/martmists/ynet/screen/ControllerConfigScreenHandler.kt View File

@@ -5,23 +5,21 @@ import com.github.vini2003.blade.common.data.Position
import com.github.vini2003.blade.common.data.Size
import com.github.vini2003.blade.common.data.Slots
import com.github.vini2003.blade.common.handler.BaseScreenHandler
import com.github.vini2003.blade.common.widget.base.ButtonWidget
import com.github.vini2003.blade.common.widget.base.SlotListWidget
import com.github.vini2003.blade.common.widget.base.SlotWidget
import com.github.vini2003.blade.common.widget.base.TextWidget
import com.github.vini2003.blade.common.widget.base.*
import com.martmists.ynet.YNetMod
import com.martmists.ynet.blockentity.ControllerBlockEntity
import com.martmists.ynet.ext.next
import com.martmists.ynet.ext.ofRGB
import com.martmists.ynet.network.Channel
import com.martmists.ynet.network.ConfiguredBlockEntity
import com.martmists.ynet.network.InteractionMode
import com.martmists.ynet.transfer.type.DisabledType
import com.martmists.ynet.util.WidgetBuilder
import com.martmists.ynet.screen.util.ColoredButtonWidget
import com.martmists.ynet.screen.util.WidgetBuilder
import com.martmists.ynet.util.YNetRegistry
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.inventory.SimpleInventory
import net.minecraft.item.ItemStack
import net.minecraft.network.PacketByteBuf
import net.minecraft.screen.slot.SlotActionType
import net.minecraft.text.LiteralText
import net.minecraft.text.TranslatableText
@@ -29,9 +27,17 @@ import net.minecraft.util.math.BlockPos

class ControllerConfigScreenHandler(syncId: Int, player: PlayerEntity, pos: BlockPos) : BaseScreenHandler(YNetMod.CONTROLLER_SCREEN_HANDLER, syncId, player) {
val be = player.world.getBlockEntity(pos) as ControllerBlockEntity
var currentChannel: Channel<*>? = null
var currentBlock: ConfiguredBlockEntity? = null
var selectedButton: ButtonWidget? = null
var currentBlockSet = false

lateinit var currentChannel: Channel<*>
lateinit var currentBlock: ConfiguredBlockEntity
lateinit var selectedButton: AbstractWidget

lateinit var rpcText: TextWidget
lateinit var rpcButton: ButtonWidget
lateinit var rpbButton: ButtonWidget
lateinit var rpbSlots: MutableCollection<SlotWidget>

val filterInventory = SimpleInventory(
ItemStack.EMPTY,
ItemStack.EMPTY,
@@ -92,19 +98,17 @@ class ControllerConfigScreenHandler(syncId: Int, player: PlayerEntity, pos: Bloc
// +------------------+ +-------------------+

val main = WidgetBuilder.build(this) {
size(Size.of(370, 192))
size(Size.of(390, 192))
position(Position.of(width/2 - root.size.width/2, height/2 - root.size.height/2))

// EMPTY
val rightPanelEmpty = panel {
size(Size.of(165, 95))
relativePosition(200, 5)
hidden(true)
relativePosition(220, 5)
hidden(false)
}

// CHANNEL
var rpcText: TextWidget? = null
var rpcButton: ButtonWidget? = null
val rightPanelChannel = panel {
size(rightPanelEmpty.size)
position(rightPanelEmpty.position)
@@ -117,11 +121,12 @@ class ControllerConfigScreenHandler(syncId: Int, player: PlayerEntity, pos: Bloc
}
rpcButton = button ({ channelTypeButton ->
val types = YNetRegistry.getTypes().toMutableList().also { it.add(0, DisabledType) }
println(currentChannel)
val newChannel = Channel(currentChannel!!.network, currentChannel!!.connectedBlocks.map { ConfiguredBlockEntity(it.controller, it.be, 0, InteractionMode.DISABLED, mutableListOf()) }.toMutableList(), types.next(currentChannel!!.type))
currentChannel!!.network.channels[currentChannel!!.network.channels.indexOf(currentChannel)] = newChannel
val newChannel = Channel(currentChannel.network, currentChannel.connectedBlocks.map { ConfiguredBlockEntity(it.controller, it.be, 0, InteractionMode.DISABLED, mutableListOf()) }.toMutableList(), types.next(currentChannel.type))
be.network.channels[be.network.channels.indexOf(currentChannel)] = newChannel
currentChannel = newChannel
channelTypeButton.label = TranslatableText(newChannel.type.identifier.toString().replace("ynet:", "ynet.ui."))
(selectedButton as ColoredButtonWidget).color = Color.ofRGB(newChannel.type.color)
be.markDirty()
}) {
size(Size.of(90, 20))
relativePosition(55, 20)
@@ -129,12 +134,10 @@ class ControllerConfigScreenHandler(syncId: Int, player: PlayerEntity, pos: Bloc
}

// BLOCK
var rpbButton: ButtonWidget? = null
var rpbSlots: MutableCollection<SlotWidget>? = null
val rightPanelBlock = panel {
size(rightPanelEmpty.size)
position(rightPanelEmpty.position)
hidden(false)
hidden(true)
text(TranslatableText("ynet.ui.block")) {
relativePosition(40, 5)
}
@@ -143,17 +146,18 @@ class ControllerConfigScreenHandler(syncId: Int, player: PlayerEntity, pos: Bloc
}
rpbButton = button ({
val modes = InteractionMode.values().toList()
currentBlock!!.mode = modes.next(currentBlock!!.mode)
it.label = TranslatableText("ynet.ui.mode." + currentBlock!!.mode.name.toLowerCase())
when (currentBlock!!.mode) {
currentBlock.mode = modes.next(currentBlock.mode)
it.label = TranslatableText("ynet.ui.mode." + currentBlock.mode.name.toLowerCase())
when (currentBlock.mode) {
InteractionMode.INSERT -> {
selectedButton!!.label = LiteralText("I")
(selectedButton as ButtonWidget).label = LiteralText("I")
}
InteractionMode.EXTRACT -> {
selectedButton!!.label = LiteralText("E")
(selectedButton as ButtonWidget).label = LiteralText("E")
}
else -> {}
}
be.markDirty()
}) {
size(Size.of(90, 20))
relativePosition(55, 20)
@@ -167,62 +171,76 @@ class ControllerConfigScreenHandler(syncId: Int, player: PlayerEntity, pos: Bloc

// LEFT PANEL
panel {
size(Size.of(193, 182))
size(Size.of(213, 182))
relativePosition(5, 5)


for (x in 0 until 10) {
button(Color.of(DisabledType.color), {
button(Color.ofRGB(be.network.channels[x].type.color), {
currentChannel = be.network.channels[x]
rpcButton!!.label = TranslatableText(currentChannel!!.type.identifier.toString().replace("ynet:", "ynet.ui."))
rpcText!!.text = TranslatableText("ynet.ui.channel.index", x)
rpcButton.label = TranslatableText(currentChannel.type.identifier.toString().replace("ynet:", "ynet.ui."))
rpcText.text = TranslatableText("ynet.ui.channel.index", x)
rightPanelEmpty.hidden = true
rightPanelChannel.hidden = false
rightPanelBlock.hidden = true
selectedButton = it
}) {
size(Size.of(14, 14))
relativePosition(40 + 15*x, 6)
relativePosition(26 + 15*x, 6)
root.label = LiteralText(x.toString())
}
}

list {
size(Size.of(180, 140))
relativePosition(3, 20)
size(Size.of(202, 140))
relativePosition(3, 25)

be.network.getConnectedBlocks().forEachIndexed { index, block ->
panel {
size(Size.of(180, 30))
size(Size.of(175, 25))
relativePosition(3, 32 * index)

icon(be.world!!.getBlockState(block.pos).block) {
icon(be.world!!.getBlockState(block.pos).block, LiteralText(block.pos.toShortString())) {
size(Size.of(20, 20))
relativePosition(4, 4)
relativePosition(4, 5)

}

for (x in 0 until 10) {
button ({
if (be.network.channels[x].type == DisabledType) return@button
selectedButton = it
currentBlock = be.network.channels[x].connectedBlocks.first { b -> b.be == block }
currentBlock = be.network.channels[x].connectedBlocks.first { b -> b.be === block }
currentBlockSet = true

rpbButton!!.label = TranslatableText("ynet.ui.mode." + currentBlock!!.mode.name.toLowerCase())
rpbButton.label = TranslatableText("ynet.ui.mode." + currentBlock.mode.name.toLowerCase())
// TODO: Priority
for (i in 0 until filterInventory.size()) {
filterInventory.setStack(i, ItemStack.EMPTY)
}
currentBlock!!.filter.forEachIndexed { index, itemStack ->
currentBlock.filter.forEachIndexed { index, itemStack ->
filterInventory.setStack(index, itemStack)
}

rightPanelEmpty.hidden = true
rightPanelChannel.hidden = true
rightPanelBlock.hidden = false
rpbSlots?.forEach { s -> s.hidden = be.network.channels[x].type.canFilter }
rpbSlots.forEach { s -> s.hidden = be.network.channels[x].type.canFilter }
}) {
size(Size.of(14, 14))
relativePosition(20 + 15*x, 6)
root.label = LiteralText(" ")
val cbe = be.network.channels[x].connectedBlocks.first { b -> b.be == block }
when (cbe.mode) {
InteractionMode.INSERT -> {
root.label = LiteralText("I")
}
InteractionMode.EXTRACT -> {
root.label = LiteralText("E")
}
else -> {
root.label = LiteralText(" ")
}
}
}
}
}
@@ -231,18 +249,18 @@ class ControllerConfigScreenHandler(syncId: Int, player: PlayerEntity, pos: Bloc
}

text(TranslatableText("container.inventory")) {
relativePosition(202, 101)
relativePosition(222, 101)
}
}

Slots.addPlayerInventory(Position.of(main, 202, 110), Size.of(18, 18), main, getPlayer().inventory)
Slots.addPlayerInventory(Position.of(main, 222, 110), Size.of(18, 18), main, getPlayer().inventory)

addWidget(main)
}

override fun onSlotClick(slotNumber: Int, button: Int, actionType: SlotActionType?, playerEntity: PlayerEntity?): ItemStack {
val cursor = playerEntity!!.inventory.cursorStack
if (slotNumber < 0 || currentBlock == null) return cursor
if (slotNumber < 0 || !currentBlockSet) return cursor
val copy = cursor.copy()
when {
(slots[slotNumber] ?: return cursor).inventory == filterInventory -> {
@@ -252,15 +270,15 @@ class ControllerConfigScreenHandler(syncId: Int, player: PlayerEntity, pos: Bloc
copy.count = 1
val old = filterInventory.getStack(slotNumber)
if (!old.isEmpty) {
currentBlock!!.filter.remove(old)
currentBlock.filter.remove(old)
}
filterInventory.setStack(slotNumber, copy)
currentBlock!!.filter.add(copy)
currentBlock.filter.add(copy)
}
} else if (button == 1) { // Take
val old = filterInventory.getStack(slotNumber)
if (!old.isEmpty) {
currentBlock!!.filter.remove(old)
currentBlock.filter.remove(old)
}
filterInventory.setStack(slotNumber, ItemStack.EMPTY)
}
@@ -279,7 +297,7 @@ class ControllerConfigScreenHandler(syncId: Int, player: PlayerEntity, pos: Bloc
}
copy.count = 1
filterInventory.setStack(index, copy)
currentBlock!!.filter.add(copy)
currentBlock.filter.add(copy)
return cursor
}
else -> {


src/main/kotlin/com/martmists/ynet/util/ColoredButtonWidget.kt → src/main/kotlin/com/martmists/ynet/screen/util/ColoredButtonWidget.kt View File

@@ -1,4 +1,4 @@
package com.martmists.ynet.util
package com.martmists.ynet.screen.util

import com.github.vini2003.blade.Blade
import com.github.vini2003.blade.client.data.PartitionedTexture
@@ -11,7 +11,6 @@ import com.github.vini2003.blade.common.utilities.Networks
import com.github.vini2003.blade.common.widget.OriginalWidgetCollection
import com.github.vini2003.blade.common.widget.WidgetCollection
import com.github.vini2003.blade.common.widget.base.AbstractWidget
import com.github.vini2003.blade.common.widget.base.ButtonWidget
import net.minecraft.client.render.VertexConsumerProvider
import net.minecraft.client.sound.PositionedSoundInstance
import net.minecraft.client.util.math.MatrixStack

+ 22
- 0
src/main/kotlin/com/martmists/ynet/screen/util/CustomTooltipItemWidget.kt View File

@@ -0,0 +1,22 @@
package com.martmists.ynet.screen.util

import com.github.vini2003.blade.client.utilities.Drawings
import com.github.vini2003.blade.client.utilities.Instances
import com.github.vini2003.blade.common.widget.base.AbstractWidget
import com.github.vini2003.blade.common.widget.base.ItemWidget
import net.minecraft.client.render.VertexConsumerProvider
import net.minecraft.client.util.math.MatrixStack
import net.minecraft.item.ItemStack
import net.minecraft.text.Text

class CustomTooltipItemWidget(val stack: ItemStack = ItemStack.EMPTY, val tooltip: Text) : AbstractWidget() {
override fun getTooltip(): List<Text> {
return if (stack.isEmpty) emptyList() else listOf(tooltip)
}

override fun drawWidget(matrices: MatrixStack, provider: VertexConsumerProvider) {
if (hidden) return

Drawings.getItemRenderer()?.renderInGui(stack, position.x.toInt(), position.y.toInt())
}
}

src/main/kotlin/com/martmists/ynet/util/WidgetBuilder.kt → src/main/kotlin/com/martmists/ynet/screen/util/WidgetBuilder.kt View File

@@ -1,4 +1,4 @@
package com.martmists.ynet.util
package com.martmists.ynet.screen.util

import com.github.vini2003.blade.common.data.Color
import com.github.vini2003.blade.common.data.Position
@@ -7,9 +7,7 @@ import com.github.vini2003.blade.common.handler.BaseScreenHandler
import com.github.vini2003.blade.common.widget.WidgetCollection
import com.github.vini2003.blade.common.widget.base.*
import net.minecraft.block.Block
import net.minecraft.client.gui.widget.TextFieldWidget
import net.minecraft.item.ItemStack
import net.minecraft.screen.ScreenHandler
import net.minecraft.text.Text

object WidgetBuilder {
@@ -47,13 +45,11 @@ object WidgetBuilder {
return p
}

fun button(onClick: (ButtonWidget) -> Unit) = button(onClick) { }
fun button(onClick: (ButtonWidget) -> Unit, callback: SingleBuilder<ButtonWidget>.() -> Unit): ButtonWidget {
val b = ButtonWidget(onClick)
buildInner(callback, b)
return b
}
fun button(color: Color, onClick: (ColoredButtonWidget) -> Unit) = button(color, onClick) { }
fun button(color: Color, onClick: (ColoredButtonWidget) -> Unit, callback: SingleBuilder<ColoredButtonWidget>.() -> Unit): ColoredButtonWidget {
val b = ColoredButtonWidget(onClick, color)
buildInner(callback, b)
@@ -66,7 +62,6 @@ object WidgetBuilder {
return l
}

fun text(txt: Text) = text(txt) { }
fun text(txt: Text, callback: SingleBuilder<TextWidget>.() -> Unit): TextWidget {
val t = TextWidget()
t.text = txt
@@ -74,22 +69,21 @@ object WidgetBuilder {
return t
}

fun icon(b: Block) = icon(b) { }
fun icon(b: Block, callback: SingleBuilder<ItemWidget>.() -> Unit): ItemWidget {
val i = ItemWidget()
i.stack = ItemStack(b)
fun icon(b: Block, text: Text, callback: SingleBuilder<CustomTooltipItemWidget>.() -> Unit): CustomTooltipItemWidget {
val i = CustomTooltipItemWidget(ItemStack(b), text)
buildInner(callback, i)
return i
}
}

open class SingleBuilder<T : AbstractWidget>(open val root: T) {
fun relativePosition(x: Number, y: Number) = position(Position.of(root.parent!!, x, y))
fun position(x: Number, y: Number) = position(Position.of(x, y))
fun position(pos: Position) {
root.position = pos
}

fun relativePosition(x: Number, y: Number) = position(Position.of(root.parent!!, x, y))

fun size(width: Number, height: Number) = size(Size.of(width, height))
fun size(size: Size) {
root.size = size
}

+ 11
- 0
src/main/kotlin/com/martmists/ynet/support/RebornEnergySupport.kt View File

@@ -0,0 +1,11 @@
package com.martmists.ynet.support

import com.martmists.ynet.transfer.handler.EnergyTransferHandler
import com.martmists.ynet.transfer.type.EnergyType
import com.martmists.ynet.util.YNetRegistry

object RebornEnergySupport : Runnable {
override fun run() {
YNetRegistry.register(EnergyType, EnergyTransferHandler)
}
}

+ 11
- 0
src/main/kotlin/com/martmists/ynet/support/VanillaSupport.kt View File

@@ -0,0 +1,11 @@
package com.martmists.ynet.support

import com.martmists.ynet.transfer.handler.ItemTransferHandler
import com.martmists.ynet.transfer.type.ItemType
import com.martmists.ynet.util.YNetRegistry

object VanillaSupport : Runnable {
override fun run() {
YNetRegistry.register(ItemType, ItemTransferHandler)
}
}

+ 9
- 0
src/main/kotlin/com/martmists/ynet/transfer/data/EnergyTransferData.kt View File

@@ -0,0 +1,9 @@
package com.martmists.ynet.transfer.data

import com.martmists.ynet.transfer.type.EnergyType

class EnergyTransferData : TransferData<EnergyType> {
override fun isEmpty(): Boolean {
TODO("Not yet implemented")
}
}

+ 16
- 0
src/main/kotlin/com/martmists/ynet/transfer/handler/EnergyTransferHandler.kt View File

@@ -0,0 +1,16 @@
package com.martmists.ynet.transfer.handler

import com.martmists.ynet.network.ConfiguredBlockEntity
import com.martmists.ynet.transfer.data.EnergyTransferData
import com.martmists.ynet.transfer.proxy.EnergyTransferProxy
import com.martmists.ynet.transfer.type.EnergyType

object EnergyTransferHandler : TransferHandler<EnergyType, EnergyTransferData, EnergyTransferProxy> {
override fun getProxy(cbe: ConfiguredBlockEntity): EnergyTransferProxy {
TODO("Not yet implemented")
}

override fun getData(): EnergyTransferData {
TODO("Not yet implemented")
}
}

+ 2
- 0
src/main/kotlin/com/martmists/ynet/transfer/handler/TransferHandler.kt View File

@@ -14,7 +14,9 @@ interface TransferHandler<T: Type, D: TransferData<T>, O: TransferProxy<T, D>> {
val data = getData()

val extract = blocks.filter { it.mode == InteractionMode.EXTRACT }.sortedByDescending { it.priority }.toMutableList()
println("Extracting from: $extract")
val insert = blocks.filter { it.mode == InteractionMode.INSERT }.toMutableList()
println("Inserting into: $insert")

for (ex in extract) {
if (!ex.canExtract(data)) {


+ 28
- 0
src/main/kotlin/com/martmists/ynet/transfer/proxy/EnergyTransferProxy.kt View File

@@ -0,0 +1,28 @@
package com.martmists.ynet.transfer.proxy

import com.martmists.ynet.network.InteractionMode
import com.martmists.ynet.transfer.data.EnergyTransferData
import com.martmists.ynet.transfer.type.EnergyType
import net.minecraft.block.entity.BlockEntity
import net.minecraft.item.ItemStack

class EnergyTransferProxy(override val be: BlockEntity,
override val mode: InteractionMode,
override val priority: Int,
override val filter: List<ItemStack>) : TransferProxy<EnergyType, EnergyTransferData> {
override fun canExtract(data: EnergyTransferData): Boolean {
TODO("Not yet implemented")
}

override fun canInsert(data: EnergyTransferData): Boolean {
TODO("Not yet implemented")
}

override fun extract(data: EnergyTransferData) {
TODO("Not yet implemented")
}

override fun insert(data: EnergyTransferData) {
TODO("Not yet implemented")
}
}

+ 1
- 1
src/main/kotlin/com/martmists/ynet/transfer/type/DisabledType.kt View File

@@ -7,7 +7,7 @@ import net.minecraft.world.World

object DisabledType : Type {
override val identifier = Identifier("ynet:disabled")
override val color = 0x00_00_00_00
override val color = 0x000000
override val canFilter = false

override fun appliesTo(world: World, pos: BlockPos) = false


+ 17
- 0
src/main/kotlin/com/martmists/ynet/transfer/type/EnergyType.kt View File

@@ -0,0 +1,17 @@
package com.martmists.ynet.transfer.type

import net.minecraft.item.ItemStack
import net.minecraft.util.Identifier
import net.minecraft.util.math.BlockPos
import net.minecraft.world.World
import team.reborn.energy.EnergyHolder

object EnergyType : Type {
override val identifier = Identifier("ynet:energy")
override val color = 0xFFFF00
override val canFilter = false

override fun appliesTo(world: World, pos: BlockPos) = world.getBlockState(pos).block is EnergyHolder

override fun canFilter(stack: ItemStack) = false
}

+ 0
- 1
src/main/kotlin/com/martmists/ynet/transfer/type/ItemType.kt View File

@@ -14,7 +14,6 @@ object ItemType : Type {
override fun appliesTo(world: World, pos: BlockPos): Boolean {
val canInsert = ItemAttributes.INSERTABLE.getFirstOrNull(world, pos) != null
val canExtract = ItemAttributes.EXTRACTABLE.getFirstOrNull(world, pos) != null
println("canInsert: $canInsert | canExtract: $canExtract")
return canInsert || canExtract
}



+ 12
- 0
src/main/resources/fabric.mod.json View File

@@ -21,11 +21,23 @@
"value": "com.martmists.ynet.YNetModClient",
"adapter": "kotlin"
}
],
"ynet:support": [
{
"value": "com.martmists.ynet.support.VanillaSupport",
"adapter": "kotlin"
},
{
"value": "com.martmists.ynet.support.RebornEnergySupport",
"adapter": "kotlin"
}
]
},
"mixins": [
],
"depends": {
"libblockattributes": "*",
"blade": "*",
"fabricloader": ">=0.4.0"
},
"suggests": {


Loading…
Cancel
Save