Add Redstone Emitter digital mode
This commit is contained in:
parent
e646e1e7c2
commit
1bbb193183
|
@ -3,6 +3,7 @@ package net.shadowfacts.phycon.block.redstone_emitter
|
||||||
import alexiil.mc.lib.attributes.item.GroupedItemInvView
|
import alexiil.mc.lib.attributes.item.GroupedItemInvView
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.nbt.CompoundTag
|
import net.minecraft.nbt.CompoundTag
|
||||||
|
import net.minecraft.text.TranslatableText
|
||||||
import net.shadowfacts.phycon.api.packet.Packet
|
import net.shadowfacts.phycon.api.packet.Packet
|
||||||
import net.shadowfacts.phycon.api.util.IPAddress
|
import net.shadowfacts.phycon.api.util.IPAddress
|
||||||
import net.shadowfacts.phycon.block.DeviceBlockEntity
|
import net.shadowfacts.phycon.block.DeviceBlockEntity
|
||||||
|
@ -26,6 +27,11 @@ class RedstoneEmitterBlockEntity: DeviceBlockEntity(PhyBlockEntities.REDSTONE_EM
|
||||||
|
|
||||||
var stackToMonitor: ItemStack = ItemStack.EMPTY
|
var stackToMonitor: ItemStack = ItemStack.EMPTY
|
||||||
var maxAmount = 64
|
var maxAmount = 64
|
||||||
|
var mode = Mode.ANALOG
|
||||||
|
set(value) {
|
||||||
|
field = value
|
||||||
|
recalculateRedstone()
|
||||||
|
}
|
||||||
|
|
||||||
override fun handle(packet: Packet) {
|
override fun handle(packet: Packet) {
|
||||||
when (packet) {
|
when (packet) {
|
||||||
|
@ -61,6 +67,8 @@ class RedstoneEmitterBlockEntity: DeviceBlockEntity(PhyBlockEntities.REDSTONE_EM
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun recalculateRedstone() {
|
private fun recalculateRedstone() {
|
||||||
|
if (world!!.isClient) return
|
||||||
|
|
||||||
if (stackToMonitor.isEmpty) {
|
if (stackToMonitor.isEmpty) {
|
||||||
cachedEmittedPower = 0
|
cachedEmittedPower = 0
|
||||||
updateWorld()
|
updateWorld()
|
||||||
|
@ -70,11 +78,15 @@ class RedstoneEmitterBlockEntity: DeviceBlockEntity(PhyBlockEntities.REDSTONE_EM
|
||||||
acc + inv.getAmount(stackToMonitor)
|
acc + inv.getAmount(stackToMonitor)
|
||||||
}
|
}
|
||||||
cachedEmittedPower =
|
cachedEmittedPower =
|
||||||
if (networkAmount == 0) {
|
when (mode) {
|
||||||
0
|
Mode.ANALOG -> if (networkAmount == 0) {
|
||||||
} else {
|
0
|
||||||
1 + round(networkAmount / maxAmount.toDouble() * 14).toInt()
|
} else {
|
||||||
|
1 + round(networkAmount / maxAmount.toDouble() * 14).toInt()
|
||||||
|
}
|
||||||
|
Mode.DIGITAL -> if (networkAmount >= maxAmount) 15 else 0
|
||||||
}
|
}
|
||||||
|
|
||||||
updateWorld()
|
updateWorld()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,9 +111,18 @@ class RedstoneEmitterBlockEntity: DeviceBlockEntity(PhyBlockEntities.REDSTONE_EM
|
||||||
|
|
||||||
override fun writeDeviceConfiguration(tag: CompoundTag) {
|
override fun writeDeviceConfiguration(tag: CompoundTag) {
|
||||||
tag.putInt("MaxAmount", maxAmount)
|
tag.putInt("MaxAmount", maxAmount)
|
||||||
|
tag.putString("Mode", mode.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun loadDeviceConfiguration(tag: CompoundTag) {
|
override fun loadDeviceConfiguration(tag: CompoundTag) {
|
||||||
maxAmount = tag.getInt("MaxAmount")
|
maxAmount = tag.getInt("MaxAmount")
|
||||||
|
mode = Mode.valueOf(tag.getString("Mode"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class Mode {
|
||||||
|
ANALOG, DIGITAL;
|
||||||
|
|
||||||
|
val friendlyName = TranslatableText("gui.phycon.redstone_emitter_mode.${name.toLowerCase()}")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
package net.shadowfacts.phycon.screen.console
|
||||||
|
|
||||||
|
import net.minecraft.client.MinecraftClient
|
||||||
|
import net.minecraft.text.TranslatableText
|
||||||
|
import net.shadowfacts.cacao.util.Color
|
||||||
|
import net.shadowfacts.cacao.view.Label
|
||||||
|
import net.shadowfacts.cacao.view.button.EnumButton
|
||||||
|
import net.shadowfacts.cacao.viewcontroller.ViewController
|
||||||
|
import net.shadowfacts.kiwidsl.dsl
|
||||||
|
import net.shadowfacts.phycon.block.redstone_emitter.RedstoneEmitterBlockEntity
|
||||||
|
import net.shadowfacts.phycon.networking.C2SConfigureDevice
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author shadowfacts
|
||||||
|
*/
|
||||||
|
class RedstoneEmitterViewController(
|
||||||
|
val device: RedstoneEmitterBlockEntity,
|
||||||
|
): ViewController() {
|
||||||
|
|
||||||
|
override fun viewDidLoad() {
|
||||||
|
super.viewDidLoad()
|
||||||
|
|
||||||
|
val label = Label(TranslatableText("gui.phycon.console.emitter.mode")).apply {
|
||||||
|
textColor = Color.TEXT
|
||||||
|
}
|
||||||
|
view.addSubview(label)
|
||||||
|
|
||||||
|
val mode = EnumButton(device.mode, RedstoneEmitterBlockEntity.Mode::friendlyName)
|
||||||
|
mode.handler = {
|
||||||
|
device.mode = it.value
|
||||||
|
MinecraftClient.getInstance().player!!.networkHandler.sendPacket(C2SConfigureDevice(device))
|
||||||
|
}
|
||||||
|
view.addSubview(mode)
|
||||||
|
|
||||||
|
view.solver.dsl {
|
||||||
|
mode.widthAnchor equalTo 100
|
||||||
|
mode.heightAnchor equalTo 20
|
||||||
|
mode.topAnchor equalTo view.topAnchor
|
||||||
|
mode.rightAnchor equalTo view.rightAnchor
|
||||||
|
|
||||||
|
label.centerYAnchor equalTo mode.centerYAnchor
|
||||||
|
label.rightAnchor equalTo (mode.leftAnchor - 4)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -32,6 +32,7 @@
|
||||||
"gui.phycon.console.receiver.priority": "Receiver Priority",
|
"gui.phycon.console.receiver.priority": "Receiver Priority",
|
||||||
"gui.phycon.console.receiver.priority_desc": "When a device puts items into the network, it starts with receiver (e.g., interfaces) with higher priorities. Priorities can be negative.",
|
"gui.phycon.console.receiver.priority_desc": "When a device puts items into the network, it starts with receiver (e.g., interfaces) with higher priorities. Priorities can be negative.",
|
||||||
"gui.phycon.console.receiver.sync": "Sync with Provider Priority",
|
"gui.phycon.console.receiver.sync": "Sync with Provider Priority",
|
||||||
|
"gui.phycon.console.emitter.mode": "Measurement Mode",
|
||||||
"gui.phycon.redstone_mode.high": "High",
|
"gui.phycon.redstone_mode.high": "High",
|
||||||
"gui.phycon.redstone_mode.low": "Low",
|
"gui.phycon.redstone_mode.low": "Low",
|
||||||
"gui.phycon.redstone_mode.toggle": "Toggle",
|
"gui.phycon.redstone_mode.toggle": "Toggle",
|
||||||
|
@ -42,6 +43,8 @@
|
||||||
"gui.phycon.emitter.count": "%d Item(s)",
|
"gui.phycon.emitter.count": "%d Item(s)",
|
||||||
"gui.phycon.miner_mode.automatic": "Automatic",
|
"gui.phycon.miner_mode.automatic": "Automatic",
|
||||||
"gui.phycon.miner_mode.on_demand": "On Demand",
|
"gui.phycon.miner_mode.on_demand": "On Demand",
|
||||||
|
"gui.phycon.redstone_emitter_mode.analog": "Analog",
|
||||||
|
"gui.phycon.redstone_emitter_mode.digital": "Digital",
|
||||||
|
|
||||||
"tooltip.phycon.device.configured": "Configured",
|
"tooltip.phycon.device.configured": "Configured",
|
||||||
"tooltip.phycon.device.ip": "IP: "
|
"tooltip.phycon.device.ip": "IP: "
|
||||||
|
|
Loading…
Reference in New Issue