Browse Source

tiny progress

master
Martmists 1 month ago
parent
commit
4ecbd5b80a
8 changed files with 36 additions and 18 deletions
  1. +2
    -4
      src/main/kotlin/com/martmists/ynet/block/CableBlock.kt
  2. +4
    -0
      src/main/kotlin/com/martmists/ynet/ext/Color.kt
  3. +7
    -2
      src/main/kotlin/com/martmists/ynet/screen/util/ColoredButtonWidget.kt
  4. +3
    -3
      src/main/kotlin/com/martmists/ynet/transfer/data/EnergyTransferData.kt
  5. +2
    -2
      src/main/kotlin/com/martmists/ynet/transfer/handler/EnergyTransferHandler.kt
  6. +1
    -0
      src/main/kotlin/com/martmists/ynet/transfer/handler/TransferHandler.kt
  7. +15
    -5
      src/main/kotlin/com/martmists/ynet/transfer/proxy/EnergyTransferProxy.kt
  8. +2
    -2
      src/main/kotlin/com/martmists/ynet/transfer/type/EnergyType.kt

+ 2
- 4
src/main/kotlin/com/martmists/ynet/block/CableBlock.kt View File

@@ -20,7 +20,7 @@ class CableBlock(settings: Settings) : ConnectingBlock(0.1875f, settings) {
builder.add(NORTH, EAST, SOUTH, WEST, UP, DOWN)
}

override fun getPlacementState(ctx: ItemPlacementContext): BlockState? {
override fun getPlacementState(ctx: ItemPlacementContext): BlockState {
return withConnectionProperties(ctx.world, ctx.blockPos)
}

@@ -46,10 +46,8 @@ class CableBlock(settings: Settings) : ConnectingBlock(0.1875f, settings) {
}

override fun onPlaced(world: World, pos: BlockPos, state: BlockState, placer: LivingEntity?, itemStack: ItemStack) {
val tStart = System.nanoTime()
super.onPlaced(world, pos, state, placer, itemStack)
Network.addCable(pos)
val tEnd = System.nanoTime()
println((tEnd - tStart).toString() + "ns")
}

fun withConnectionProperties(world: BlockView, pos: BlockPos): BlockState {


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

@@ -2,6 +2,10 @@ package com.martmists.ynet.ext

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

fun Color.eq(other: Color): Boolean {
return r == other.r && g == other.g && b == other.b && a == other.a
}

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


+ 7
- 2
src/main/kotlin/com/martmists/ynet/screen/util/ColoredButtonWidget.kt View File

@@ -11,6 +11,7 @@ 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.martmists.ynet.ext.eq
import com.martmists.ynet.ext.ofRGB
import net.minecraft.client.render.VertexConsumerProvider
import net.minecraft.client.sound.PositionedSoundInstance
@@ -18,6 +19,7 @@ import net.minecraft.client.util.math.MatrixStack
import net.minecraft.sound.SoundEvents
import net.minecraft.text.Text


class ColoredButtonWidget(private val clickAction: (ColoredButtonWidget) -> Unit, var color: Color) : AbstractWidget() {
var textureOn = PartitionedTexture(Blade.identifier("textures/widget/button_on.png"), 18F, 18F, 0.11111111111111111111F, 0.11111111111111111111F, 0.11111111111111111111F, 0.16666666666666666667F)
var textureOff = PartitionedTexture(Blade.identifier("textures/widget/button_off.png"), 18F, 18F, 0.11111111111111111111F, 0.11111111111111111111F, 0.11111111111111111111F, 0.11111111111111111111F)
@@ -26,7 +28,10 @@ class ColoredButtonWidget(private val clickAction: (ColoredButtonWidget) -> Unit
var disabled: Boolean = false

var label: Text? = null
init {

override fun onAdded(original: OriginalWidgetCollection, immediate: WidgetCollection) {
super.onAdded(original, immediate)
println("Marking Sync: MOUSE_CLICK")
synchronize.add(Networks.MOUSE_CLICK)
}

@@ -50,7 +55,7 @@ class ColoredButtonWidget(private val clickAction: (ColoredButtonWidget) -> Unit
val texture = if (disabled) textureOff else if (focused) textureOnFocus else textureOn

texture.draw(matrices, provider, position.x, position.y, size.width, size.height)
if (color == Color.ofRGB(0x000000)) {
if (!color.eq(Color.ofRGB(0x000000))) {
Drawings.drawQuad(matrices, provider, Layers.flat(), position.x, position.y, size.width, size.height, color)
}



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

@@ -3,7 +3,7 @@ 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")
}
var energy: Double = 0.0
override fun isEmpty(): Boolean = energy == 0.0
}

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

@@ -7,10 +7,10 @@ import com.martmists.ynet.transfer.type.EnergyType

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

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

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

@@ -13,6 +13,7 @@ interface TransferHandler<T: Type, D: TransferData<T>, O: TransferProxy<T, D>> {
val blocks = channel.connectedBlocks.map(::getProxy).toList()
val data = getData()

println("All blocks: ${blocks.map { "${it.be.type} ${it.mode}" }}")
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()


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

@@ -5,24 +5,34 @@ 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
import team.reborn.energy.EnergySide
import team.reborn.energy.EnergyStorage
import kotlin.math.min

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")
val max = (be as EnergyStorage).getMaxOutput(EnergySide.UNKNOWN)
val stored = be.getStored(EnergySide.UNKNOWN)
data.energy = min(max, stored)
return max != 0.0 && stored != 0.0
}

override fun canInsert(data: EnergyTransferData): Boolean {
TODO("Not yet implemented")
val max = (be as EnergyStorage).getMaxInput(EnergySide.UNKNOWN)
val stored = be.getStored(EnergySide.UNKNOWN)
val free = be.maxStoredPower - stored
data.energy = min(data.energy, min(max, free))
return max != 0.0 && free != 0.0
}

override fun extract(data: EnergyTransferData) {
TODO("Not yet implemented")
(be as EnergyStorage).setStored(be.getStored(EnergySide.UNKNOWN) - data.energy)
}

override fun insert(data: EnergyTransferData) {
TODO("Not yet implemented")
(be as EnergyStorage).setStored(be.getStored(EnergySide.UNKNOWN) + data.energy)
}
}
}

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

@@ -4,14 +4,14 @@ 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
import team.reborn.energy.EnergyStorage

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 appliesTo(world: World, pos: BlockPos) = world.getBlockState(pos).block is EnergyStorage

override fun canFilter(stack: ItemStack) = false
}

Loading…
Cancel
Save