Compare commits

...

7 Commits

Author SHA1 Message Date
Shadowfacts 2035874baa
Add some advancements 2021-03-09 18:36:55 -05:00
Shadowfacts fab5dcdc35
Don't include extra copies of the Fabric API 2021-03-09 18:36:40 -05:00
Shadowfacts 7170c3482b
Fix Terminal screen not setting focused element
REI expects Screen.getFocused() to be non-null to skip its input
handling
2021-03-09 18:35:57 -05:00
Shadowfacts cd6299b876
Set Console and Screwdriver stack sizes to 1 2021-03-09 18:35:28 -05:00
Shadowfacts 1bbb193183
Add Redstone Emitter digital mode 2021-03-09 18:34:57 -05:00
Shadowfacts e646e1e7c2
Fix Redstone Controller not updating when mode is changed 2021-03-09 18:34:13 -05:00
Shadowfacts b78eb192de
Fix Miner not inserting things 2021-03-09 18:25:59 -05:00
17 changed files with 344 additions and 20 deletions

View File

@ -45,8 +45,12 @@ dependencies {
runtimeOnly project(":plugin:rei") runtimeOnly project(":plugin:rei")
include project(":plugin:rei") include project(":plugin:rei")
modRuntime "io.github.cottonmc:cotton-resources:${project.cotton_resources_version}" modRuntime("io.github.cottonmc:cotton-resources:${project.cotton_resources_version}") {
modRuntime "com.terraformersmc:modmenu:${project.modmenu_version}" exclude group: "net.fabricmc.fabric-api"
}
modRuntime("com.terraformersmc:modmenu:${project.modmenu_version}") {
exclude group: "net.fabricmc.fabric-api"
}
testImplementation "org.junit.jupiter:junit-jupiter:${project.junit_version}" testImplementation "org.junit.jupiter:junit-jupiter:${project.junit_version}"
} }

View File

@ -33,8 +33,12 @@ dependencies {
implementation project(":") implementation project(":")
modCompileOnly "me.shedaniel:RoughlyEnoughItems-api:${project.rei_version}" modCompileOnly("me.shedaniel:RoughlyEnoughItems-api:${project.rei_version}") {
modRuntime "me.shedaniel:RoughlyEnoughItems:${project.rei_version}" exclude group: "net.fabricmc.fabric-api"
}
modRuntime("me.shedaniel:RoughlyEnoughItems:${project.rei_version}") {
exclude group: "net.fabricmc.fabric-api"
}
} }
processResources { processResources {

View File

@ -17,10 +17,7 @@ import net.shadowfacts.phycon.api.packet.Packet
import net.shadowfacts.phycon.init.PhyBlockEntities import net.shadowfacts.phycon.init.PhyBlockEntities
import net.shadowfacts.phycon.block.DeviceBlockEntity import net.shadowfacts.phycon.block.DeviceBlockEntity
import net.shadowfacts.phycon.block.terminal.TerminalBlockEntity import net.shadowfacts.phycon.block.terminal.TerminalBlockEntity
import net.shadowfacts.phycon.component.ActivationController import net.shadowfacts.phycon.component.*
import net.shadowfacts.phycon.component.NetworkStackDispatcher
import net.shadowfacts.phycon.component.NetworkStackProvider
import net.shadowfacts.phycon.component.handleItemStack
import net.shadowfacts.phycon.packet.* import net.shadowfacts.phycon.packet.*
import net.shadowfacts.phycon.util.ActivationMode import net.shadowfacts.phycon.util.ActivationMode
import net.shadowfacts.phycon.util.ClientConfigurableDevice import net.shadowfacts.phycon.util.ClientConfigurableDevice
@ -55,6 +52,7 @@ class MinerBlockEntity: DeviceBlockEntity(PhyBlockEntities.MINER),
is ExtractStackPacket -> handleExtractStack(packet) is ExtractStackPacket -> handleExtractStack(packet)
is CapacityPacket -> handleCapacity(packet) is CapacityPacket -> handleCapacity(packet)
is ItemStackPacket -> handleItemStack(packet) is ItemStackPacket -> handleItemStack(packet)
is RemoteActivationPacket -> controller.handleRemoteActivation(packet)
} }
} }
@ -122,10 +120,12 @@ class MinerBlockEntity: DeviceBlockEntity(PhyBlockEntities.MINER),
override fun tick() { override fun tick() {
super.tick() super.tick()
if (!world!!.isClient && minerMode == MinerMode.AUTOMATIC) { if (!world!!.isClient) {
if (minerMode == MinerMode.AUTOMATIC) {
controller.tick() controller.tick()
} }
finishTimedOutPendingInsertions()
}
} }
override fun activate(): Boolean { override fun activate(): Boolean {

View File

@ -17,6 +17,10 @@ class RedstoneControllerBlockEntity: DeviceBlockEntity(PhyBlockEntities.REDSTONE
var managedDevices = Array<IPAddress?>(5) { null } var managedDevices = Array<IPAddress?>(5) { null }
var redstoneMode = RedstoneMode.HIGH var redstoneMode = RedstoneMode.HIGH
set(value) {
field = value
redstoneStateChanged()
}
private var redstonePowered = false private var redstonePowered = false
@ -24,6 +28,8 @@ class RedstoneControllerBlockEntity: DeviceBlockEntity(PhyBlockEntities.REDSTONE
} }
fun redstoneStateChanged() { fun redstoneStateChanged() {
if (world!!.isClient) return
val oldPowered = redstonePowered val oldPowered = redstonePowered
redstonePowered = cachedState[RedstoneControllerBlock.POWERED] redstonePowered = cachedState[RedstoneControllerBlock.POWERED]

View File

@ -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) {
Mode.ANALOG -> if (networkAmount == 0) {
0 0
} else { } else {
1 + round(networkAmount / maxAmount.toDouble() * 14).toInt() 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()}")
}
} }

View File

@ -62,6 +62,7 @@ class TerminalScreen(handler: TerminalScreenHandler, playerInv: PlayerInventory,
if (value && !oldValue) { if (value && !oldValue) {
amountBox.text = "1" amountBox.text = "1"
} }
updateFocusedElement()
} }
private var dialogChildren = mutableListOf<AbstractButtonWidget>() private var dialogChildren = mutableListOf<AbstractButtonWidget>()
@ -162,9 +163,20 @@ class TerminalScreen(handler: TerminalScreenHandler, playerInv: PlayerInventory,
} }
dialogChildren.add(request) dialogChildren.add(request)
updateFocusedElement()
requestUpdatedItems() requestUpdatedItems()
} }
private fun updateFocusedElement() {
focused = if (showingAmountDialog) {
amountBox
} else if (searchBox.isFocused) {
searchBox
} else {
null
}
}
private fun requestUpdatedItems() { private fun requestUpdatedItems() {
val player = MinecraftClient.getInstance().player!! val player = MinecraftClient.getInstance().player!!
player.networkHandler.sendPacket(C2STerminalUpdateDisplayedItems(handler.terminal, searchBox.text, sortButton.mode, scrollPosition)) player.networkHandler.sendPacket(C2STerminalUpdateDisplayedItems(handler.terminal, searchBox.text, sortButton.mode, scrollPosition))
@ -260,8 +272,7 @@ class TerminalScreen(handler: TerminalScreenHandler, playerInv: PlayerInventory,
override fun onMouseClick(slot: Slot?, invSlot: Int, clickData: Int, type: SlotActionType?) { override fun onMouseClick(slot: Slot?, invSlot: Int, clickData: Int, type: SlotActionType?) {
super.onMouseClick(slot, invSlot, clickData, type) super.onMouseClick(slot, invSlot, clickData, type)
// don't unfocus the search box on mouse click updateFocusedElement()
searchBox.setSelected(true)
if (slot != null && !slot.stack.isEmpty && handler.isNetworkSlot(slot.id)) { if (slot != null && !slot.stack.isEmpty && handler.isNetworkSlot(slot.id)) {
val stack = slot.stack val stack = slot.stack

View File

@ -13,7 +13,7 @@ import net.shadowfacts.phycon.screen.console.DeviceConsoleScreen
/** /**
* @author shadowfacts * @author shadowfacts
*/ */
class ConsoleItem: Item(Settings()) { class ConsoleItem: Item(Settings().maxCount(1)) {
companion object { companion object {
val ID = Identifier(PhysicalConnectivity.MODID, "console") val ID = Identifier(PhysicalConnectivity.MODID, "console")
} }

View File

@ -20,7 +20,7 @@ import net.shadowfacts.phycon.util.containsInclusive
/** /**
* @author shadowfacts * @author shadowfacts
*/ */
class ScrewdriverItem: Item(Settings()) { class ScrewdriverItem: Item(Settings().maxCount(1)) {
companion object { companion object {
val ID = Identifier(PhysicalConnectivity.MODID, "screwdriver") val ID = Identifier(PhysicalConnectivity.MODID, "screwdriver")
} }

View File

@ -15,6 +15,7 @@ import net.shadowfacts.kiwidsl.dsl
import net.shadowfacts.phycon.block.DeviceBlockEntity import net.shadowfacts.phycon.block.DeviceBlockEntity
import net.shadowfacts.phycon.block.miner.MinerBlockEntity import net.shadowfacts.phycon.block.miner.MinerBlockEntity
import net.shadowfacts.phycon.block.redstone_controller.RedstoneControllerBlockEntity import net.shadowfacts.phycon.block.redstone_controller.RedstoneControllerBlockEntity
import net.shadowfacts.phycon.block.redstone_emitter.RedstoneEmitterBlockEntity
import net.shadowfacts.phycon.component.ActivationController import net.shadowfacts.phycon.component.ActivationController
import net.shadowfacts.phycon.component.NetworkStackProvider import net.shadowfacts.phycon.component.NetworkStackProvider
import net.shadowfacts.phycon.component.NetworkStackReceiver import net.shadowfacts.phycon.component.NetworkStackReceiver
@ -80,6 +81,15 @@ class DeviceConsoleScreen(
ReceiverViewController(device), ReceiverViewController(device),
)) ))
} }
if (device is RedstoneEmitterBlockEntity) {
tabs.add(TabViewController.SimpleTab(
TextureView(Texture(Identifier("textures/item/redstone.png"), 0, 0, 16, 16)).apply {
intrinsicContentSize = Size(16.0, 16.0)
},
TranslatableText("block.phycon.redstone_emitter"),
RedstoneEmitterViewController(device)
))
}
tabController = TabViewController(tabs) tabController = TabViewController(tabs)

View File

@ -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)
}
}
}

View File

@ -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,7 +43,22 @@
"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: ",
"advancements.phycon.root.title": "Physical Connectivity",
"advancements.phycon.root.description": "Mass item storage and local networking",
"advancements.phycon.cable.title": "At a Distance",
"advancements.phycon.cable.description": "Place Cables to connect multiple devices",
"advancements.phycon.interface.title": "Attachment",
"advancements.phycon.interface.description": "Place a Network Interface on a Cable to connect to a Chest",
"advancements.phycon.terminal.title": "Spooky Action",
"advancements.phycon.terminal.description": "Use a Terminal to interact with a Chest",
"advancements.phycon.switch.title": "Interchange",
"advancements.phycon.switch.description": "Connect multiple devices with a Network Switch",
"advancements.phycon.console.title": "Console",
"advancements.phycon.console.description": "Configure a networked device"
} }

View File

@ -0,0 +1,34 @@
{
"parent": "phycon:root",
"display": {
"icon": {
"item": "phycon:cable"
},
"title": {
"translate": "advancements.phycon.cable.title"
},
"description": {
"translate": "advancements.phycon.cable.description"
},
"frame": "task",
"show_toast": true,
"announce_to_chat": true,
"hidden": false
},
"criteria": {
"cable": {
"trigger": "minecraft:placed_block",
"conditions": {
"block": "phycon:cable",
"item": {
"item": "phycon:cable"
}
}
}
},
"requirements": [
[
"cable"
]
]
}

View File

@ -0,0 +1,33 @@
{
"parent": "phycon:switch",
"display": {
"icon": {
"item": "phycon:console"
},
"title": {
"translate": "advancements.phycon.console.title"
},
"description": {
"translate": "advancements.phycon.console.description"
},
"frame": "task",
"show_toast": true,
"announce_to_chat": true,
"hidden": false
},
"criteria": {
"console": {
"trigger": "minecraft:item_used_on_block",
"conditions": {
"item": {
"item": "phycon:console"
}
}
}
},
"requirements": [
[
"console"
]
]
}

View File

@ -0,0 +1,35 @@
{
"parent": "phycon:cable",
"display": {
"icon": {
"item": "phycon:network_interface"
},
"title": {
"translate": "advancements.phycon.interface.title"
},
"description": {
"translate": "advancements.phycon.interface.description"
},
"frame": "task",
"show_toast": true,
"announce_to_chat": true,
"hidden": false
},
"criteria": {
"interface": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"item": "phycon:network_interface"
}
]
}
}
},
"requirements": [
[
"interface"
]
]
}

View File

@ -0,0 +1,35 @@
{
"display": {
"icon": {
"item": "phycon:terminal"
},
"title": {
"translate": "advancements.phycon.root.title"
},
"description": {
"translate": "advancements.phycon.root.description"
},
"frame": "task",
"show_toast": false,
"announce_to_chat": false,
"hidden": false,
"background": "phycon:textures/block/casing.png"
},
"criteria": {
"copper": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"tag": "c:copper_ingots"
}
]
}
}
},
"requirements": [
[
"copper"
]
]
}

View File

@ -0,0 +1,34 @@
{
"parent": "phycon:cable",
"display": {
"icon": {
"item": "phycon:switch"
},
"title": {
"translate": "advancements.phycon.switch.title"
},
"description": {
"translate": "advancements.phycon.switch.description"
},
"frame": "task",
"show_toast": true,
"announce_to_chat": true,
"hidden": false
},
"criteria": {
"switch": {
"trigger": "minecraft:placed_block",
"conditions": {
"block": "phycon:switch",
"item": {
"item": "phycon:switch"
}
}
}
},
"requirements": [
[
"switch"
]
]
}

View File

@ -0,0 +1,35 @@
{
"parent": "phycon:network_interface",
"display": {
"icon": {
"item": "phycon:terminal"
},
"title": {
"translate": "advancements.phycon.terminal.title"
},
"description": {
"translate": "advancements.phycon.terminal.description"
},
"frame": "task",
"show_toast": true,
"announce_to_chat": true,
"hidden": false
},
"criteria": {
"terminal": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"item": "phycon:terminal"
}
]
}
}
},
"requirements": [
[
"terminal"
]
]
}