Compare commits
No commits in common. "e88ecd3215a2d16e796800c1bb94c86b79cef645" and "172536cdb83ec2d5493971831c5a1d969759dc5d" have entirely different histories.
e88ecd3215
...
172536cdb8
85
build.gradle
85
build.gradle
|
@ -1,7 +1,7 @@
|
||||||
plugins {
|
plugins {
|
||||||
id "fabric-loom" version "0.10-SNAPSHOT"
|
id "fabric-loom" version "0.6.49"
|
||||||
id "maven-publish"
|
id "maven-publish"
|
||||||
id "org.jetbrains.kotlin.jvm" version "1.6.10"
|
id "org.jetbrains.kotlin.jvm" version "1.4.30"
|
||||||
}
|
}
|
||||||
|
|
||||||
archivesBaseName = project.archives_base_name
|
archivesBaseName = project.archives_base_name
|
||||||
|
@ -10,8 +10,8 @@ group = project.maven_group
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
pluginManager.withPlugin("java") {
|
pluginManager.withPlugin("java") {
|
||||||
sourceCompatibility = JavaVersion.VERSION_17
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
targetCompatibility = JavaVersion.VERSION_17
|
targetCompatibility = JavaVersion.VERSION_1_8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,8 +43,6 @@ configure(allprojects.findAll { it.name != "kiwi-java" }) {
|
||||||
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
|
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
|
||||||
tasks.withType(JavaCompile) {
|
tasks.withType(JavaCompile) {
|
||||||
options.encoding = "UTF-8"
|
options.encoding = "UTF-8"
|
||||||
// Minecraft 1.18 (1.18-pre2) upwards uses Java 17.
|
|
||||||
options.release = 17
|
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
|
@ -57,54 +55,43 @@ configure(allprojects.findAll { it.name != "kiwi-java" }) {
|
||||||
|
|
||||||
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
|
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
|
||||||
compileKotlin {
|
compileKotlin {
|
||||||
kotlinOptions.jvmTarget = JavaVersion.VERSION_17
|
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loom {
|
minecraft {
|
||||||
log4jConfigs.from "PhyConDebugLogging.xml"
|
log4jConfigs.from "PhyConDebugLogging.xml"
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven { url "https://mod-buildcraft.com/maven" }
|
maven { url "https://mod-buildcraft.com/maven" }
|
||||||
// maven { url "https://server.bbkr.space:8081/artifactory/libs-release/" }
|
maven { url "http://server.bbkr.space:8081/artifactory/libs-release/" }
|
||||||
maven { url "https://maven.terraformersmc.com/releases" }
|
maven { url "https://maven.terraformersmc.com/releases" }
|
||||||
maven { url "https://maven.shedaniel.me/" }
|
jcenter()
|
||||||
maven { url "https://maven.siphalor.de/" }
|
|
||||||
maven { url "https://jitpack.io" }
|
|
||||||
mavenCentral()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
|
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
|
||||||
// You may need to force-disable transitiveness on them.
|
// You may need to force-disable transitiveness on them.
|
||||||
modImplementation "alexiil.mc.lib:libblockattributes-all:${project.libblockattributes_version}"
|
modCompile "alexiil.mc.lib:libblockattributes-all:${project.libblockattributes_version}"
|
||||||
include "alexiil.mc.lib:libblockattributes-core:${project.libblockattributes_version}"
|
include "alexiil.mc.lib:libblockattributes-core:${project.libblockattributes_version}"
|
||||||
include "alexiil.mc.lib:libblockattributes-items:${project.libblockattributes_version}"
|
include "alexiil.mc.lib:libblockattributes-items:${project.libblockattributes_version}"
|
||||||
|
|
||||||
implementation project(":kiwi-java")
|
compile project(":kiwi-java")
|
||||||
include project(":kiwi-java")
|
include project(":kiwi-java")
|
||||||
|
|
||||||
modRuntimeOnly "de.siphalor:mousewheelie-1.18:${project.mousewheelie_version}"
|
runtimeOnly project(":plugin:mousewheelie")
|
||||||
runtimeOnly(project(":plugin:mousewheelie")) {
|
|
||||||
transitive = false
|
|
||||||
}
|
|
||||||
include project(":plugin:mousewheelie")
|
include project(":plugin:mousewheelie")
|
||||||
|
runtimeOnly project(":plugin:rei")
|
||||||
modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}"
|
|
||||||
runtimeOnly(project(":plugin:rei")) {
|
|
||||||
transitive = false
|
|
||||||
}
|
|
||||||
include project(":plugin:rei")
|
include project(":plugin:rei")
|
||||||
|
runtimeOnly project(":plugin:techreborn")
|
||||||
|
include project(":plugin:techreborn")
|
||||||
|
|
||||||
// runtimeOnly project(":plugin:techreborn")
|
modRuntime("io.github.cottonmc:cotton-resources:${project.cotton_resources_version}") {
|
||||||
// include project(":plugin:techreborn")
|
exclude group: "net.fabricmc.fabric-api"
|
||||||
|
}
|
||||||
// modRuntime("io.github.cottonmc:cotton-resources:${project.cotton_resources_version}") {
|
modRuntime("com.terraformersmc:modmenu:${project.modmenu_version}") {
|
||||||
// exclude group: "net.fabricmc.fabric-api"
|
|
||||||
// }
|
|
||||||
modRuntimeOnly("com.terraformersmc:modmenu:${project.modmenu_version}") {
|
|
||||||
exclude group: "net.fabricmc.fabric-api"
|
exclude group: "net.fabricmc.fabric-api"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,22 +105,22 @@ jar {
|
||||||
}
|
}
|
||||||
|
|
||||||
// configure the maven publication
|
// configure the maven publication
|
||||||
// publishing {
|
publishing {
|
||||||
// publications {
|
publications {
|
||||||
// mavenJava(MavenPublication) {
|
mavenJava(MavenPublication) {
|
||||||
// // add all the jars that should be included when publishing to maven
|
// add all the jars that should be included when publishing to maven
|
||||||
// artifact(remapJar) {
|
artifact(remapJar) {
|
||||||
// builtBy remapJar
|
builtBy remapJar
|
||||||
// }
|
}
|
||||||
// artifact(sourcesJar) {
|
artifact(sourcesJar) {
|
||||||
// builtBy remapSourcesJar
|
builtBy remapSourcesJar
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // select the repositories you want to publish to
|
// select the repositories you want to publish to
|
||||||
// repositories {
|
repositories {
|
||||||
// // uncomment to publish to the local maven
|
// uncomment to publish to the local maven
|
||||||
// // mavenLocal()
|
// mavenLocal()
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
|
@ -1,21 +1,19 @@
|
||||||
org.gradle.jvmargs=-Xmx1G
|
org.gradle.jvmargs=-Xmx1G
|
||||||
org.gradle.daemon=false
|
org.gradle.daemon=false
|
||||||
|
|
||||||
minecraft_version=1.18.1
|
minecraft_version=1.16.5
|
||||||
yarn_mappings=1.18.1+build.7
|
yarn_mappings=1.16.5+build.4
|
||||||
loader_version=0.12.12
|
loader_version=0.11.1
|
||||||
|
|
||||||
mod_version=0.2.0
|
mod_version=0.2.0
|
||||||
maven_group=net.shadowfacts
|
maven_group=net.shadowfacts
|
||||||
archives_base_name=PhysicalConnectivity
|
archives_base_name=PhysicalConnectivity
|
||||||
|
|
||||||
fabric_version=0.44.0+1.18
|
fabric_version=0.30.0+1.16
|
||||||
fabric_kotlin_version=1.7.1+kotlin.1.6.10
|
fabric_kotlin_version=1.4.30+build.2
|
||||||
|
|
||||||
libblockattributes_version=0.10.0
|
libblockattributes_version=0.8.5
|
||||||
# cotton_resources_version=1.7.4
|
cotton_resources_version=1.7.4
|
||||||
modmenu_version=3.0.1
|
modmenu_version=1.16.8
|
||||||
rei_version=7.1.356
|
|
||||||
mousewheelie_version=1.8.0+mc1.18-pre5
|
|
||||||
|
|
||||||
junit_version = 5.4.0
|
junit_version = 5.4.0
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit abe783ae7ce45ccf296ed7b7e5c1b194e7c560fa
|
Subproject commit 1cbaea53d207f1e16c6e5ee2e6bf6e3c1440ac44
|
|
@ -3,7 +3,7 @@ plugins {
|
||||||
id "org.jetbrains.kotlin.jvm"
|
id "org.jetbrains.kotlin.jvm"
|
||||||
}
|
}
|
||||||
|
|
||||||
archivesBaseName = "PhyCon-Plugin-MouseWheelie"
|
archivesBaseName = project.archives_base_name
|
||||||
version = project.mod_version
|
version = project.mod_version
|
||||||
group = project.maven_group
|
group = project.maven_group
|
||||||
|
|
||||||
|
@ -11,18 +11,13 @@ repositories {
|
||||||
maven {
|
maven {
|
||||||
url = "https://maven.siphalor.de/"
|
url = "https://maven.siphalor.de/"
|
||||||
}
|
}
|
||||||
maven {
|
jcenter()
|
||||||
url = "https://jitpack.io"
|
|
||||||
}
|
|
||||||
mavenCentral()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(":")) {
|
implementation project(":")
|
||||||
transitive = false
|
|
||||||
}
|
|
||||||
|
|
||||||
modImplementation("de.siphalor:mousewheelie-1.18:${project.mousewheelie_version}") {
|
modImplementation("de.siphalor:mousewheelie-1.16:${project.mousewheelie_version}") {
|
||||||
exclude group: "net.fabricmc"
|
exclude group: "net.fabricmc"
|
||||||
exclude group: "net.fabricmc.fabric-api"
|
exclude group: "net.fabricmc.fabric-api"
|
||||||
exclude module: "modmenu"
|
exclude module: "modmenu"
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
archives_base_name=PhyCon-Plugin-MouseWheelie
|
||||||
|
|
||||||
|
mousewheelie_version=1.6.4+mc1.16.4
|
||||||
|
|
|
@ -3,7 +3,7 @@ plugins {
|
||||||
id "org.jetbrains.kotlin.jvm"
|
id "org.jetbrains.kotlin.jvm"
|
||||||
}
|
}
|
||||||
|
|
||||||
archivesBaseName = "PhyCon-Plugin-REI"
|
archivesBaseName = project.archives_base_name
|
||||||
version = project.mod_version
|
version = project.mod_version
|
||||||
group = project.maven_group
|
group = project.maven_group
|
||||||
|
|
||||||
|
@ -11,15 +11,16 @@ repositories {
|
||||||
maven {
|
maven {
|
||||||
url = "https://maven.shedaniel.me/"
|
url = "https://maven.shedaniel.me/"
|
||||||
}
|
}
|
||||||
mavenCentral()
|
jcenter()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(":")) {
|
implementation project(":")
|
||||||
transitive = false
|
|
||||||
}
|
|
||||||
|
|
||||||
modCompileOnly("me.shedaniel:RoughlyEnoughItems-api-fabric:${project.rei_version}") {
|
modCompileOnly("me.shedaniel:RoughlyEnoughItems-api:${project.rei_version}") {
|
||||||
|
exclude group: "net.fabricmc.fabric-api"
|
||||||
|
}
|
||||||
|
modRuntime("me.shedaniel:RoughlyEnoughItems:${project.rei_version}") {
|
||||||
exclude group: "net.fabricmc.fabric-api"
|
exclude group: "net.fabricmc.fabric-api"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
archives_base_name=PhyCon-Plugin-REI
|
||||||
|
|
||||||
|
rei_version=5.10.184
|
|
@ -0,0 +1,45 @@
|
||||||
|
package net.shadowfacts.phycon.plugin.rei
|
||||||
|
|
||||||
|
import me.shedaniel.math.Rectangle
|
||||||
|
import me.shedaniel.rei.api.BaseBoundsHandler
|
||||||
|
import me.shedaniel.rei.api.DisplayHelper
|
||||||
|
import me.shedaniel.rei.api.REIHelper
|
||||||
|
import me.shedaniel.rei.api.plugins.REIPluginV0
|
||||||
|
import net.fabricmc.api.ClientModInitializer
|
||||||
|
import net.minecraft.client.MinecraftClient
|
||||||
|
import net.minecraft.util.Identifier
|
||||||
|
import net.shadowfacts.phycon.block.terminal.AbstractTerminalScreen
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author shadowfacts
|
||||||
|
*/
|
||||||
|
object PhyConPlugin: ClientModInitializer, REIPluginV0 {
|
||||||
|
const val MODID = "phycon_rei"
|
||||||
|
|
||||||
|
override fun onInitializeClient() {
|
||||||
|
AbstractTerminalScreen.registerClickHandler { mouseX, mouseY, button ->
|
||||||
|
REIHelper.getInstance().searchTextField?.also {
|
||||||
|
if (it.bounds.contains(mouseX, mouseY)) {
|
||||||
|
this.terminalVC.searchField.resignFirstResponder()
|
||||||
|
} else {
|
||||||
|
this.terminalVC.searchField.becomeFirstResponder()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getPluginIdentifier() = Identifier(MODID, "rei_plugin")
|
||||||
|
|
||||||
|
override fun registerBounds(helper: DisplayHelper) {
|
||||||
|
BaseBoundsHandler.getInstance().registerExclusionZones(AbstractTerminalScreen::class.java) {
|
||||||
|
val screen = MinecraftClient.getInstance().currentScreen as AbstractTerminalScreen<*, *>
|
||||||
|
val view = screen.terminalVC.settingsView
|
||||||
|
val rect = view.convert(view.bounds, to = null)
|
||||||
|
listOf(
|
||||||
|
Rectangle(rect.left.toInt(), rect.top.toInt(), 20, 20)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,87 +0,0 @@
|
||||||
package net.shadowfacts.phycon.plugin.rei
|
|
||||||
|
|
||||||
import dev.architectury.event.EventResult
|
|
||||||
import dev.architectury.event.events.client.ClientScreenInputEvent
|
|
||||||
import me.shedaniel.math.Rectangle
|
|
||||||
import me.shedaniel.rei.api.client.REIRuntime
|
|
||||||
import me.shedaniel.rei.api.client.plugins.REIClientPlugin
|
|
||||||
import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry
|
|
||||||
import net.fabricmc.api.ClientModInitializer
|
|
||||||
import net.minecraft.client.MinecraftClient
|
|
||||||
import net.shadowfacts.phycon.PhysicalConnectivityClient
|
|
||||||
import net.shadowfacts.phycon.block.terminal.AbstractTerminalScreen
|
|
||||||
import org.apache.logging.log4j.LogManager
|
|
||||||
import java.lang.invoke.MethodHandle
|
|
||||||
import java.lang.invoke.MethodHandles
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author shadowfacts
|
|
||||||
*/
|
|
||||||
object PhyConPluginClient: ClientModInitializer, REIClientPlugin, AbstractTerminalScreen.SearchQueryListener {
|
|
||||||
|
|
||||||
private val logger = LogManager.getLogger()
|
|
||||||
private var isHighlightingHandle: MethodHandle? = null
|
|
||||||
|
|
||||||
override fun onInitializeClient() {
|
|
||||||
ClientScreenInputEvent.MOUSE_RELEASED_PRE.register { client, screen, mouseX, mouseY, button ->
|
|
||||||
if (screen is AbstractTerminalScreen<*, *>) {
|
|
||||||
REIRuntime.getInstance().searchTextField?.also {
|
|
||||||
if (it.isFocused) {
|
|
||||||
screen.terminalVC.searchField.resignFirstResponder()
|
|
||||||
} else {
|
|
||||||
screen.terminalVC.searchField.becomeFirstResponder()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EventResult.pass()
|
|
||||||
}
|
|
||||||
|
|
||||||
AbstractTerminalScreen.searchQueryListener = this
|
|
||||||
try {
|
|
||||||
val clazz = Class.forName("me.shedaniel.rei.impl.client.gui.widget.search.OverlaySearchField")
|
|
||||||
isHighlightingHandle = MethodHandles.publicLookup().findStaticGetter(clazz, "isHighlighting", Boolean::class.java)
|
|
||||||
} catch (e: ReflectiveOperationException) {
|
|
||||||
logger.warn("Unable to find OverlaySearchField.isHighlighting, highlight sync will be disabled", e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun registerScreens(registry: ScreenRegistry) {
|
|
||||||
registry.exclusionZones().register(AbstractTerminalScreen::class.java) {
|
|
||||||
val screen = MinecraftClient.getInstance().currentScreen as AbstractTerminalScreen<*, *>
|
|
||||||
val view = screen.terminalVC.settingsView
|
|
||||||
val rect = view.convert(view.bounds, to = null)
|
|
||||||
listOf(
|
|
||||||
Rectangle(rect.left.toInt(), rect.top.toInt(), view.bounds.width.toInt(), view.bounds.height.toInt())
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun terminalSearchQueryChanged(newValue: String) {
|
|
||||||
if (shouldSync()) {
|
|
||||||
REIRuntime.getInstance().searchTextField?.text = newValue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun requestTerminalSearchFieldUpdate(): String? {
|
|
||||||
return if (shouldSync()) {
|
|
||||||
REIRuntime.getInstance().searchTextField?.text
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun shouldSync(): Boolean {
|
|
||||||
return when (PhysicalConnectivityClient.terminalSettings[PhyConPluginCommon.REI_SYNC_KEY]) {
|
|
||||||
REISyncMode.OFF -> false
|
|
||||||
REISyncMode.ON -> true
|
|
||||||
REISyncMode.HIGHLIGHT_ONLY -> {
|
|
||||||
if (isHighlightingHandle != null) {
|
|
||||||
isHighlightingHandle!!.invoke() as Boolean
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,67 +1,46 @@
|
||||||
package net.shadowfacts.phycon.plugin.rei
|
package net.shadowfacts.phycon.plugin.rei
|
||||||
|
|
||||||
import me.shedaniel.rei.api.common.category.CategoryIdentifier
|
import me.shedaniel.rei.server.ContainerContext
|
||||||
import me.shedaniel.rei.api.common.display.SimpleGridMenuDisplay
|
import me.shedaniel.rei.server.ContainerInfo
|
||||||
import me.shedaniel.rei.api.common.plugins.REIServerPlugin
|
import me.shedaniel.rei.server.ContainerInfoHandler
|
||||||
import me.shedaniel.rei.api.common.transfer.info.MenuInfoContext
|
import me.shedaniel.rei.server.StackAccessor
|
||||||
import me.shedaniel.rei.api.common.transfer.info.MenuInfoRegistry
|
import net.fabricmc.api.ModInitializer
|
||||||
import me.shedaniel.rei.api.common.transfer.info.simple.SimpleGridMenuInfo
|
|
||||||
import me.shedaniel.rei.api.common.transfer.info.simple.SimpleMenuInfoProvider
|
|
||||||
import me.shedaniel.rei.api.common.transfer.info.stack.SlotAccessor
|
|
||||||
import net.minecraft.util.Identifier
|
import net.minecraft.util.Identifier
|
||||||
import net.shadowfacts.phycon.api.PhyConAPI
|
|
||||||
import net.shadowfacts.phycon.api.PhyConPlugin
|
|
||||||
import net.shadowfacts.phycon.api.TerminalSettingKey
|
|
||||||
import net.shadowfacts.phycon.block.terminal.CraftingTerminalScreenHandler
|
import net.shadowfacts.phycon.block.terminal.CraftingTerminalScreenHandler
|
||||||
import java.util.stream.IntStream
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
object PhyConPluginCommon: REIServerPlugin, PhyConPlugin {
|
object PhyConPluginCommon: ModInitializer {
|
||||||
const val MODID = "phycon_rei"
|
|
||||||
|
|
||||||
lateinit var REI_SYNC_KEY: TerminalSettingKey<REISyncMode>
|
override fun onInitialize() {
|
||||||
private set
|
ContainerInfoHandler.registerContainerInfo(Identifier("minecraft", "plugins/crafting"), TerminalInfo)
|
||||||
|
|
||||||
override fun registerMenuInfo(registry: MenuInfoRegistry) {
|
|
||||||
registry.register(CategoryIdentifier.of("minecraft", "plugins/crafting"), CraftingTerminalScreenHandler::class.java, SimpleMenuInfoProvider.of(::TerminalInfo))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun initializePhyCon(api: PhyConAPI) {
|
object TerminalInfo: ContainerInfo<CraftingTerminalScreenHandler> {
|
||||||
REI_SYNC_KEY = api.registerTerminalSetting(Identifier(MODID, "rei_sync"), REISyncMode.OFF)
|
override fun getContainerClass() = CraftingTerminalScreenHandler::class.java
|
||||||
}
|
|
||||||
|
|
||||||
class TerminalInfo<D: SimpleGridMenuDisplay>(
|
override fun getCraftingResultSlotIndex(container: CraftingTerminalScreenHandler): Int {
|
||||||
private val display: D,
|
return container.resultSlot.id
|
||||||
): SimpleGridMenuInfo<CraftingTerminalScreenHandler, D> {
|
|
||||||
|
|
||||||
override fun getCraftingResultSlotIndex(menu: CraftingTerminalScreenHandler): Int {
|
|
||||||
return menu.resultSlot.id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getInputStackSlotIds(context: MenuInfoContext<CraftingTerminalScreenHandler, *, D>): IntStream {
|
override fun getCraftingWidth(container: CraftingTerminalScreenHandler): Int {
|
||||||
return IntStream.range(context.menu.craftingSlotsStart, context.menu.craftingSlotsEnd)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getInventorySlots(context: MenuInfoContext<CraftingTerminalScreenHandler, *, D>): Iterable<SlotAccessor> {
|
|
||||||
val slots = super.getInventorySlots(context).toMutableList()
|
|
||||||
for (i in (context.menu.bufferSlotsStart until context.menu.bufferSlotsEnd)) {
|
|
||||||
slots.add(SlotAccessor.fromSlot(context.menu.getSlot(i)))
|
|
||||||
}
|
|
||||||
return slots
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getCraftingWidth(menu: CraftingTerminalScreenHandler): Int {
|
|
||||||
return 3
|
return 3
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getCraftingHeight(menu: CraftingTerminalScreenHandler): Int {
|
override fun getCraftingHeight(container: CraftingTerminalScreenHandler): Int {
|
||||||
return 3
|
return 3
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getDisplay(): D {
|
override fun getGridStacks(context: ContainerContext<CraftingTerminalScreenHandler>): List<StackAccessor> {
|
||||||
return display
|
val handler = context.container
|
||||||
|
return (handler.craftingSlotsStart until handler.craftingSlotsEnd).map(context::getStack)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getInventoryStacks(context: ContainerContext<CraftingTerminalScreenHandler>): List<StackAccessor> {
|
||||||
|
val handler = context.container
|
||||||
|
val slots = (handler.playerSlotsStart until handler.playerSlotsEnd) + (handler.bufferSlotsStart until handler.bufferSlotsEnd)
|
||||||
|
return slots.map(context::getStack)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
package net.shadowfacts.phycon.plugin.rei
|
|
||||||
|
|
||||||
import net.minecraft.text.LiteralText
|
|
||||||
import net.minecraft.util.Identifier
|
|
||||||
import net.shadowfacts.phycon.PhysicalConnectivity
|
|
||||||
import net.shadowfacts.phycon.api.TerminalSetting
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author shadowfacts
|
|
||||||
*/
|
|
||||||
enum class REISyncMode: TerminalSetting {
|
|
||||||
OFF,
|
|
||||||
ON,
|
|
||||||
HIGHLIGHT_ONLY;
|
|
||||||
|
|
||||||
override fun getIconTexture() = Identifier(PhysicalConnectivity.MODID, "textures/gui/terminal.png")
|
|
||||||
|
|
||||||
override fun getUV() = when (this) {
|
|
||||||
OFF -> intArrayOf(0, 240)
|
|
||||||
ON -> intArrayOf(16, 240)
|
|
||||||
HIGHLIGHT_ONLY -> intArrayOf(32, 240)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getTooltip() = when (this) {
|
|
||||||
OFF -> LiteralText("Don't sync with REI")
|
|
||||||
ON -> LiteralText("Sync with REI")
|
|
||||||
HIGHLIGHT_ONLY -> LiteralText("Sync in highlight mode")
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -13,26 +13,22 @@
|
||||||
},
|
},
|
||||||
"license": "LGPL-3.0",
|
"license": "LGPL-3.0",
|
||||||
"entrypoints": {
|
"entrypoints": {
|
||||||
|
"main": [
|
||||||
|
{
|
||||||
|
"adapter": "kotlin",
|
||||||
|
"value": "net.shadowfacts.phycon.plugin.rei.PhyConPluginCommon"
|
||||||
|
}
|
||||||
|
],
|
||||||
"client": [
|
"client": [
|
||||||
{
|
{
|
||||||
"adapter": "kotlin",
|
"adapter": "kotlin",
|
||||||
"value": "net.shadowfacts.phycon.plugin.rei.PhyConPluginClient"
|
"value": "net.shadowfacts.phycon.plugin.rei.PhyConPlugin"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"rei": [
|
"rei_plugins": [
|
||||||
{
|
{
|
||||||
"adapter": "kotlin",
|
"adapter": "kotlin",
|
||||||
"value": "net.shadowfacts.phycon.plugin.rei.PhyConPluginClient"
|
"value": "net.shadowfacts.phycon.plugin.rei.PhyConPlugin"
|
||||||
},
|
|
||||||
{
|
|
||||||
"adapter": "kotlin",
|
|
||||||
"value": "net.shadowfacts.phycon.plugin.rei.PhyConPluginCommon"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"phycon": [
|
|
||||||
{
|
|
||||||
"adapter": "kotlin",
|
|
||||||
"value": "net.shadowfacts.phycon.plugin.rei.PhyConPluginCommon"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -43,7 +39,7 @@
|
||||||
"fabric": "*",
|
"fabric": "*",
|
||||||
"fabric-language-kotlin": ">=1.3.50",
|
"fabric-language-kotlin": ">=1.3.50",
|
||||||
"phycon": "*",
|
"phycon": "*",
|
||||||
"roughlyenoughitems": "^7.0.0"
|
"roughlyenoughitems": "^5.0.0"
|
||||||
},
|
},
|
||||||
|
|
||||||
"custom": {
|
"custom": {
|
||||||
|
|
|
@ -11,13 +11,11 @@ repositories {
|
||||||
maven {
|
maven {
|
||||||
url = "https://maven.modmuss50.me/"
|
url = "https://maven.modmuss50.me/"
|
||||||
}
|
}
|
||||||
mavenCentral()
|
jcenter()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(":")) {
|
implementation project(":")
|
||||||
transitive = false
|
|
||||||
}
|
|
||||||
|
|
||||||
modImplementation("TechReborn:TechReborn-1.16:${project.techreborn_version}") {
|
modImplementation("TechReborn:TechReborn-1.16:${project.techreborn_version}") {
|
||||||
exclude group: "net.fabricmc.fabric-api"
|
exclude group: "net.fabricmc.fabric-api"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
pluginManagement {
|
pluginManagement {
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
jcenter()
|
||||||
maven {
|
maven {
|
||||||
name = 'Fabric'
|
name = 'Fabric'
|
||||||
url = 'https://maven.fabricmc.net/'
|
url = 'https://maven.fabricmc.net/'
|
||||||
|
@ -12,4 +12,4 @@ pluginManagement {
|
||||||
include("kiwi-java")
|
include("kiwi-java")
|
||||||
include("plugin:mousewheelie")
|
include("plugin:mousewheelie")
|
||||||
include("plugin:rei")
|
include("plugin:rei")
|
||||||
// include("plugin:techreborn")
|
include("plugin:techreborn")
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
package net.shadowfacts.phycon.api;
|
package net.shadowfacts.phycon.api;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
public interface PhyConPlugin {
|
public interface PhyConPlugin {
|
||||||
|
|
||||||
void initializePhyCon(@NotNull PhyConAPI api);
|
void initializePhyCon(PhyConAPI api);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,4 @@ public interface TerminalSettingKey<E extends Enum<E> & TerminalSetting> {
|
||||||
|
|
||||||
E getValue();
|
E getValue();
|
||||||
|
|
||||||
void setPriority(int priority);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,8 @@ public class MixinHandledScreen {
|
||||||
at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;enableDepthTest()V")
|
at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;enableDepthTest()V")
|
||||||
)
|
)
|
||||||
private void drawSlotUnderlay(MatrixStack matrixStack, Slot slot, CallbackInfo ci) {
|
private void drawSlotUnderlay(MatrixStack matrixStack, Slot slot, CallbackInfo ci) {
|
||||||
if ((Object)this instanceof AbstractTerminalScreen<?, ?> self) {
|
if ((Object)this instanceof AbstractTerminalScreen) {
|
||||||
|
AbstractTerminalScreen<?, ?> self = (AbstractTerminalScreen<?, ?>)(Object)this;
|
||||||
self.drawSlotUnderlay(matrixStack, slot);
|
self.drawSlotUnderlay(matrixStack, slot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,10 +37,11 @@ public class MixinHandledScreen {
|
||||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/ItemRenderer;renderGuiItemOverlay(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V")
|
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/ItemRenderer;renderGuiItemOverlay(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V")
|
||||||
)
|
)
|
||||||
private void drawSlotAmount(ItemRenderer itemRenderer, TextRenderer textRenderer, ItemStack stack, int x, int y, @Nullable String countLabel, MatrixStack matrixStack, Slot slot) {
|
private void drawSlotAmount(ItemRenderer itemRenderer, TextRenderer textRenderer, ItemStack stack, int x, int y, @Nullable String countLabel, MatrixStack matrixStack, Slot slot) {
|
||||||
if ((Object)this instanceof AbstractTerminalScreen<?, ?> self) {
|
if ((Object)this instanceof AbstractTerminalScreen) {
|
||||||
|
AbstractTerminalScreen<?, ?> self = (AbstractTerminalScreen<?, ?>)(Object)this;
|
||||||
AbstractTerminalScreenHandler<?> handler = self.getScreenHandler();
|
AbstractTerminalScreenHandler<?> handler = self.getScreenHandler();
|
||||||
if (slot.id < handler.getNetworkSlotsEnd() && stack.getCount() > 1) {
|
if (slot.id < handler.getNetworkSlotsEnd() && stack.getCount() > 1) {
|
||||||
self.drawNetworkSlotAmount(stack, x, y);
|
self.drawNetworkSlotAmount(stack, x, y, slot, matrixStack);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
package net.shadowfacts.phycon.mixin.client;
|
|
||||||
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
|
||||||
import net.shadowfacts.cacao.AbstractCacaoScreen;
|
|
||||||
import org.objectweb.asm.Opcodes;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author shadowfacts
|
|
||||||
*/
|
|
||||||
@Mixin(MinecraftClient.class)
|
|
||||||
public class MixinMinecraftClient {
|
|
||||||
|
|
||||||
@Inject(
|
|
||||||
method = "setScreen(Lnet/minecraft/client/gui/screen/Screen;)V",
|
|
||||||
at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;currentScreen:Lnet/minecraft/client/gui/screen/Screen;", opcode = Opcodes.PUTFIELD, shift = At.Shift.AFTER)
|
|
||||||
)
|
|
||||||
private void setScreen(Screen screen, CallbackInfo ci) {
|
|
||||||
if (screen instanceof AbstractCacaoScreen cacaoScreen) {
|
|
||||||
cacaoScreen.screenWillAppear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -14,6 +14,4 @@ interface AbstractCacaoScreen {
|
||||||
|
|
||||||
fun removeWindow(window: Window)
|
fun removeWindow(window: Window)
|
||||||
|
|
||||||
fun screenWillAppear()
|
}
|
||||||
|
|
||||||
}
|
|
|
@ -1,6 +1,6 @@
|
||||||
package net.shadowfacts.cacao
|
package net.shadowfacts.cacao
|
||||||
|
|
||||||
import net.minecraft.client.MinecraftClient
|
import com.mojang.blaze3d.systems.RenderSystem
|
||||||
import net.minecraft.client.gui.screen.ingame.HandledScreen
|
import net.minecraft.client.gui.screen.ingame.HandledScreen
|
||||||
import net.minecraft.client.util.math.MatrixStack
|
import net.minecraft.client.util.math.MatrixStack
|
||||||
import net.minecraft.entity.player.PlayerInventory
|
import net.minecraft.entity.player.PlayerInventory
|
||||||
|
@ -14,7 +14,6 @@ import net.shadowfacts.cacao.util.RenderHelper
|
||||||
import net.shadowfacts.cacao.window.ScreenHandlerWindow
|
import net.shadowfacts.cacao.window.ScreenHandlerWindow
|
||||||
import net.shadowfacts.cacao.window.Window
|
import net.shadowfacts.cacao.window.Window
|
||||||
import org.lwjgl.glfw.GLFW
|
import org.lwjgl.glfw.GLFW
|
||||||
import org.lwjgl.opengl.GL11
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,16 +29,10 @@ open class CacaoHandledScreen<Handler: ScreenHandler>(
|
||||||
|
|
||||||
override val windows: List<Window> = _windows
|
override val windows: List<Window> = _windows
|
||||||
|
|
||||||
private var hasAppeared = false
|
|
||||||
|
|
||||||
|
|
||||||
override fun <T: Window> addWindow(window: T, index: Int): T {
|
override fun <T: Window> addWindow(window: T, index: Int): T {
|
||||||
if (window is ScreenHandlerWindow && window.screenHandler != handler) {
|
if (window is ScreenHandlerWindow && window.screenHandler != handler) {
|
||||||
throw RuntimeException("Adding ScreenHandlerWindow to CacaoHandledScreen with different screen handler is not supported")
|
throw RuntimeException("Adding ScreenHandlerWindow to CacaoHandledScreen with different screen handler is not supported")
|
||||||
}
|
}
|
||||||
if (hasAppeared) {
|
|
||||||
window.viewController.viewWillAppear()
|
|
||||||
}
|
|
||||||
|
|
||||||
_windows.add(index, window)
|
_windows.add(index, window)
|
||||||
|
|
||||||
|
@ -61,12 +54,6 @@ open class CacaoHandledScreen<Handler: ScreenHandler>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun screenWillAppear() {
|
|
||||||
windows.forEach {
|
|
||||||
it.viewController.viewWillAppear()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun init() {
|
override fun init() {
|
||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
|
@ -79,8 +66,7 @@ open class CacaoHandledScreen<Handler: ScreenHandler>(
|
||||||
super.onClose()
|
super.onClose()
|
||||||
|
|
||||||
windows.forEach {
|
windows.forEach {
|
||||||
it.viewController.viewWillDisappear()
|
// todo: VC callbacks
|
||||||
it.viewController.viewDidDisappear()
|
|
||||||
|
|
||||||
it.firstResponder = null
|
it.firstResponder = null
|
||||||
}
|
}
|
||||||
|
@ -96,8 +82,8 @@ open class CacaoHandledScreen<Handler: ScreenHandler>(
|
||||||
override fun render(matrixStack: MatrixStack, mouseX: Int, mouseY: Int, delta: Float) {
|
override fun render(matrixStack: MatrixStack, mouseX: Int, mouseY: Int, delta: Float) {
|
||||||
val mouse = Point(mouseX, mouseY)
|
val mouse = Point(mouseX, mouseY)
|
||||||
|
|
||||||
matrixStack.push()
|
RenderSystem.pushMatrix()
|
||||||
matrixStack.translate(0.0, 0.0, -350.0)
|
RenderSystem.translatef(0f, 0f, -350f)
|
||||||
|
|
||||||
for (i in windows.indices) {
|
for (i in windows.indices) {
|
||||||
val it = windows[i]
|
val it = windows[i]
|
||||||
|
@ -114,7 +100,7 @@ open class CacaoHandledScreen<Handler: ScreenHandler>(
|
||||||
super.render(matrixStack, -1, -1, delta)
|
super.render(matrixStack, -1, -1, delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
matrixStack.pop()
|
RenderSystem.popMatrix()
|
||||||
}
|
}
|
||||||
|
|
||||||
it.draw(matrixStack, mouse, delta)
|
it.draw(matrixStack, mouse, delta)
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package net.shadowfacts.cacao
|
package net.shadowfacts.cacao
|
||||||
|
|
||||||
import net.minecraft.client.MinecraftClient
|
|
||||||
import net.minecraft.client.gui.screen.Screen
|
import net.minecraft.client.gui.screen.Screen
|
||||||
import net.minecraft.client.util.math.MatrixStack
|
import net.minecraft.client.util.math.MatrixStack
|
||||||
import net.minecraft.sound.SoundEvents
|
import net.minecraft.sound.SoundEvents
|
||||||
|
@ -33,8 +32,6 @@ open class CacaoScreen(title: Text = LiteralText("CacaoScreen")): Screen(title),
|
||||||
*/
|
*/
|
||||||
override val windows: List<Window> = _windows
|
override val windows: List<Window> = _windows
|
||||||
|
|
||||||
private var hasAppeared = false
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the given window to this screen's window list at the given position.
|
* Adds the given window to this screen's window list at the given position.
|
||||||
*
|
*
|
||||||
|
@ -43,10 +40,6 @@ open class CacaoScreen(title: Text = LiteralText("CacaoScreen")): Screen(title),
|
||||||
* @return The window that was added, as a convenience.
|
* @return The window that was added, as a convenience.
|
||||||
*/
|
*/
|
||||||
override fun <T: Window> addWindow(window: T, index: Int): T {
|
override fun <T: Window> addWindow(window: T, index: Int): T {
|
||||||
if (hasAppeared) {
|
|
||||||
window.viewController.viewWillAppear()
|
|
||||||
}
|
|
||||||
|
|
||||||
_windows.add(index, window)
|
_windows.add(index, window)
|
||||||
|
|
||||||
window.screen = this
|
window.screen = this
|
||||||
|
@ -73,12 +66,6 @@ open class CacaoScreen(title: Text = LiteralText("CacaoScreen")): Screen(title),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun screenWillAppear() {
|
|
||||||
windows.forEach {
|
|
||||||
it.viewController.viewWillAppear()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun init() {
|
override fun init() {
|
||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
|
@ -91,8 +78,7 @@ open class CacaoScreen(title: Text = LiteralText("CacaoScreen")): Screen(title),
|
||||||
super.onClose()
|
super.onClose()
|
||||||
|
|
||||||
windows.forEach {
|
windows.forEach {
|
||||||
it.viewController.viewWillDisappear()
|
// todo: VC callbacks
|
||||||
it.viewController.viewDidDisappear()
|
|
||||||
|
|
||||||
// resign the current first responder (if any)
|
// resign the current first responder (if any)
|
||||||
it.firstResponder = null
|
it.firstResponder = null
|
||||||
|
|
|
@ -1,21 +1,20 @@
|
||||||
package net.shadowfacts.cacao.util
|
package net.shadowfacts.cacao.util
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.GlStateManager
|
||||||
import com.mojang.blaze3d.systems.RenderSystem
|
import com.mojang.blaze3d.systems.RenderSystem
|
||||||
import net.minecraft.client.MinecraftClient
|
import net.minecraft.client.MinecraftClient
|
||||||
import net.minecraft.client.gui.DrawableHelper
|
import net.minecraft.client.gui.DrawableHelper
|
||||||
import net.minecraft.client.gui.screen.Screen
|
|
||||||
import net.minecraft.client.render.*
|
import net.minecraft.client.render.*
|
||||||
import net.minecraft.client.sound.PositionedSoundInstance
|
import net.minecraft.client.sound.PositionedSoundInstance
|
||||||
import net.minecraft.client.util.math.MatrixStack
|
import net.minecraft.client.util.math.MatrixStack
|
||||||
import net.minecraft.sound.SoundEvent
|
import net.minecraft.sound.SoundEvent
|
||||||
import net.minecraft.text.LiteralText
|
|
||||||
import net.minecraft.text.OrderedText
|
import net.minecraft.text.OrderedText
|
||||||
import net.minecraft.text.Text
|
import net.minecraft.text.Text
|
||||||
import net.minecraft.util.math.Matrix4f
|
import net.minecraft.util.math.Matrix4f
|
||||||
import net.shadowfacts.cacao.geometry.Point
|
import net.shadowfacts.cacao.geometry.Point
|
||||||
import net.shadowfacts.cacao.geometry.Rect
|
import net.shadowfacts.cacao.geometry.Rect
|
||||||
import net.shadowfacts.cacao.util.texture.Texture
|
import net.shadowfacts.cacao.util.texture.Texture
|
||||||
import kotlin.math.roundToInt
|
import org.lwjgl.opengl.GL11
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper methods for rendering using Minecraft's utilities from Cacao views.
|
* Helper methods for rendering using Minecraft's utilities from Cacao views.
|
||||||
|
@ -46,18 +45,18 @@ object RenderHelper: DrawableHelper() {
|
||||||
*/
|
*/
|
||||||
fun draw(matrixStack: MatrixStack, rect: Rect, texture: Texture) {
|
fun draw(matrixStack: MatrixStack, rect: Rect, texture: Texture) {
|
||||||
if (disabled) return
|
if (disabled) return
|
||||||
RenderSystem.setShader(GameRenderer::getPositionTexShader)
|
color(1f, 1f, 1f, 1f)
|
||||||
RenderSystem.setShaderTexture(0, texture.location)
|
MinecraftClient.getInstance().textureManager.bindTexture(texture.location)
|
||||||
draw(matrixStack, rect.left, rect.top, texture.u, texture.v, rect.width, rect.height, texture.width, texture.height)
|
draw(matrixStack, rect.left, rect.top, texture.u, texture.v, rect.width, rect.height, texture.width, texture.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun drawLine(start: Point, end: Point, z: Double, width: Float, color: Color) {
|
fun drawLine(start: Point, end: Point, z: Double, width: Float, color: Color) {
|
||||||
if (disabled) return
|
if (disabled) return
|
||||||
|
|
||||||
RenderSystem.lineWidth(width)
|
GlStateManager.lineWidth(width)
|
||||||
val tessellator = Tessellator.getInstance()
|
val tessellator = Tessellator.getInstance()
|
||||||
val buffer = tessellator.buffer
|
val buffer = tessellator.buffer
|
||||||
buffer.begin(VertexFormat.DrawMode.LINES, VertexFormats.POSITION_COLOR)
|
buffer.begin(GL11.GL_LINES, VertexFormats.POSITION_COLOR)
|
||||||
buffer.vertex(start.x, start.y, z).color(color).next()
|
buffer.vertex(start.x, start.y, z).color(color).next()
|
||||||
buffer.vertex(end.x, end.y, z).color(color).next()
|
buffer.vertex(end.x, end.y, z).color(color).next()
|
||||||
tessellator.draw()
|
tessellator.draw()
|
||||||
|
@ -72,19 +71,19 @@ object RenderHelper: DrawableHelper() {
|
||||||
val uEnd = (u + width).toFloat() / textureWidth
|
val uEnd = (u + width).toFloat() / textureWidth
|
||||||
val vStart = v.toFloat() / textureHeight
|
val vStart = v.toFloat() / textureHeight
|
||||||
val vEnd = (v + height).toFloat() / textureHeight
|
val vEnd = (v + height).toFloat() / textureHeight
|
||||||
drawTexturedQuad(matrixStack.peek().positionMatrix, x, x + width, y, y + height, 0.0, uStart, uEnd, vStart, vEnd)
|
drawTexturedQuad(matrixStack.peek().model, x, x + width, y, y + height, 0.0, uStart, uEnd, vStart, vEnd)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copied from net.minecraft.client.gui.DrawableHelper
|
// Copied from net.minecraft.client.gui.DrawableHelper
|
||||||
// TODO: use an access transformer to just call minecraft's impl
|
|
||||||
private fun drawTexturedQuad(matrix: Matrix4f, x0: Double, x1: Double, y0: Double, y1: Double, z: Double, u0: Float, u1: Float, v0: Float, v1: Float) {
|
private fun drawTexturedQuad(matrix: Matrix4f, x0: Double, x1: Double, y0: Double, y1: Double, z: Double, u0: Float, u1: Float, v0: Float, v1: Float) {
|
||||||
val bufferBuilder = Tessellator.getInstance().buffer
|
val bufferBuilder = Tessellator.getInstance().buffer
|
||||||
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE)
|
bufferBuilder.begin(GL11.GL_QUADS, VertexFormats.POSITION_TEXTURE)
|
||||||
bufferBuilder.vertex(matrix, x0.toFloat(), y1.toFloat(), z.toFloat()).texture(u0, v1).next()
|
bufferBuilder.vertex(matrix, x0.toFloat(), y1.toFloat(), z.toFloat()).texture(u0, v1).next()
|
||||||
bufferBuilder.vertex(matrix, x1.toFloat(), y1.toFloat(), z.toFloat()).texture(u1, v1).next()
|
bufferBuilder.vertex(matrix, x1.toFloat(), y1.toFloat(), z.toFloat()).texture(u1, v1).next()
|
||||||
bufferBuilder.vertex(matrix, x1.toFloat(), y0.toFloat(), z.toFloat()).texture(u1, v0).next()
|
bufferBuilder.vertex(matrix, x1.toFloat(), y0.toFloat(), z.toFloat()).texture(u1, v0).next()
|
||||||
bufferBuilder.vertex(matrix, x0.toFloat(), y0.toFloat(), z.toFloat()).texture(u0, v0).next()
|
bufferBuilder.vertex(matrix, x0.toFloat(), y0.toFloat(), z.toFloat()).texture(u0, v0).next()
|
||||||
bufferBuilder.end()
|
bufferBuilder.end()
|
||||||
|
RenderSystem.enableAlphaTest()
|
||||||
BufferRenderer.draw(bufferBuilder)
|
BufferRenderer.draw(bufferBuilder)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,22 +95,110 @@ object RenderHelper: DrawableHelper() {
|
||||||
drawTooltip(matrixStack, texts.map(Text::asOrderedText), mouse)
|
drawTooltip(matrixStack, texts.map(Text::asOrderedText), mouse)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val dummyScreen = object: Screen(LiteralText("")) {
|
// Based on Screen.renderOrderedTooltip
|
||||||
init {
|
|
||||||
textRenderer = MinecraftClient.getInstance().textRenderer
|
|
||||||
itemRenderer = MinecraftClient.getInstance().itemRenderer
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@JvmName("drawOrderedTooltip")
|
@JvmName("drawOrderedTooltip")
|
||||||
fun drawTooltip(matrixStack: MatrixStack, texts: List<OrderedText>, mouse: Point) {
|
fun drawTooltip(matrixStack: MatrixStack, texts: List<OrderedText>, mouse: Point) {
|
||||||
if (disabled) return
|
if (disabled) return
|
||||||
if (texts.isEmpty()) return
|
if (texts.isEmpty()) return
|
||||||
|
|
||||||
val client = MinecraftClient.getInstance()
|
val client = MinecraftClient.getInstance()
|
||||||
dummyScreen.width = client.window.scaledWidth
|
val textRenderer = client.textRenderer
|
||||||
dummyScreen.height = client.window.scaledHeight
|
|
||||||
dummyScreen.renderOrderedTooltip(matrixStack, texts, mouse.x.roundToInt(), mouse.y.roundToInt())
|
val maxWidth = texts.maxOf(textRenderer::getWidth)
|
||||||
|
|
||||||
|
var x = mouse.x.toInt() + 12
|
||||||
|
var y = mouse.y.toInt() - 12
|
||||||
|
var p = 8
|
||||||
|
if (texts.size > 1) {
|
||||||
|
p += 2 + (texts.size - 1) * 8
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x + maxWidth > client.window.scaledWidth) {
|
||||||
|
x -= 28 + maxWidth
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y + p + 6 > client.window.scaledHeight) {
|
||||||
|
y = client.window.scaledHeight - p - 6
|
||||||
|
}
|
||||||
|
|
||||||
|
matrixStack.push()
|
||||||
|
val q = -267386864
|
||||||
|
val r = 1347420415
|
||||||
|
val s = 1344798847
|
||||||
|
val t = 1
|
||||||
|
val tessellator = Tessellator.getInstance()
|
||||||
|
val buffer = tessellator.buffer
|
||||||
|
buffer.begin(GL11.GL_QUADS, VertexFormats.POSITION_COLOR)
|
||||||
|
val matrix = matrixStack.peek().model
|
||||||
|
val z = 400
|
||||||
|
fillGradient(matrix, buffer, x - 3, y - 4, x + maxWidth + 3, y - 3, z, q, q)
|
||||||
|
fillGradient(matrix, buffer, x - 3, y + p + 3, x + maxWidth + 3, y + p + 4, z, q, q)
|
||||||
|
fillGradient(matrix, buffer, x - 3, y - 3, x + maxWidth + 3, y + p + 3, z, q, q)
|
||||||
|
fillGradient(matrix, buffer, x - 4, y - 3, x - 3, y + p + 3, z, q, q)
|
||||||
|
fillGradient(matrix, buffer, x + maxWidth + 3, y - 3, x + maxWidth + 4, y + p + 3, z, q, q)
|
||||||
|
fillGradient(matrix, buffer, x - 3, y - 3 + 1, x - 3 + 1, y + p + 3 - 1, z, r, s)
|
||||||
|
fillGradient(matrix, buffer, x + maxWidth + 2, y - 3 + 1, x + maxWidth + 3, y + p + 3 - 1, z, r, s)
|
||||||
|
fillGradient(matrix, buffer, x - 3, y - 3, x + maxWidth + 3, y - 3 + 1, z, r, r)
|
||||||
|
fillGradient(matrix, buffer, x - 3, y + p + 2, x + maxWidth + 3, y + p + 3, z, s, s)
|
||||||
|
RenderSystem.enableDepthTest()
|
||||||
|
RenderSystem.disableTexture()
|
||||||
|
RenderSystem.enableBlend()
|
||||||
|
RenderSystem.defaultBlendFunc()
|
||||||
|
RenderSystem.shadeModel(7425)
|
||||||
|
buffer.end()
|
||||||
|
BufferRenderer.draw(buffer)
|
||||||
|
RenderSystem.shadeModel(7424)
|
||||||
|
RenderSystem.disableBlend()
|
||||||
|
RenderSystem.enableTexture()
|
||||||
|
val immediate = VertexConsumerProvider.immediate(buffer)
|
||||||
|
|
||||||
|
matrixStack.translate(0.0, 0.0, 400.0)
|
||||||
|
|
||||||
|
for (i in texts.indices) {
|
||||||
|
val text = texts[i]
|
||||||
|
textRenderer.draw(text, x.toFloat(), y.toFloat(), -1, true, matrix, immediate, false, 0, 15728880)
|
||||||
|
|
||||||
|
if (i == 0) {
|
||||||
|
y += 2
|
||||||
|
}
|
||||||
|
|
||||||
|
y += 10
|
||||||
|
}
|
||||||
|
|
||||||
|
immediate.draw()
|
||||||
|
matrixStack.pop()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.lwjgl.opengl.GL11.glPushMatrix
|
||||||
|
*/
|
||||||
|
fun pushMatrix() {
|
||||||
|
if (disabled) return
|
||||||
|
RenderSystem.pushMatrix()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.lwjgl.opengl.GL11.glPopMatrix
|
||||||
|
*/
|
||||||
|
fun popMatrix() {
|
||||||
|
if (disabled) return
|
||||||
|
RenderSystem.popMatrix()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.lwjgl.opengl.GL11.glTranslated
|
||||||
|
*/
|
||||||
|
fun translate(x: Double, y: Double, z: Double = 0.0) {
|
||||||
|
if (disabled) return
|
||||||
|
RenderSystem.translated(x, y, z)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.lwjgl.opengl.GL11.glScaled
|
||||||
|
*/
|
||||||
|
fun scale(x: Double, y: Double, z: Double = 1.0) {
|
||||||
|
if (disabled) return
|
||||||
|
RenderSystem.scaled(x, y, z)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -119,7 +206,7 @@ object RenderHelper: DrawableHelper() {
|
||||||
*/
|
*/
|
||||||
fun color(r: Float, g: Float, b: Float, alpha: Float) {
|
fun color(r: Float, g: Float, b: Float, alpha: Float) {
|
||||||
if (disabled) return
|
if (disabled) return
|
||||||
RenderSystem.setShaderColor(r, g, b, alpha)
|
RenderSystem.color4f(r, g, b, alpha)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun VertexConsumer.color(color: Color): VertexConsumer {
|
private fun VertexConsumer.color(color: Color): VertexConsumer {
|
||||||
|
|
|
@ -26,13 +26,11 @@ class BezierCurveView(val curve: BezierCurve): View() {
|
||||||
var lineColor = Color.BLACK
|
var lineColor = Color.BLACK
|
||||||
|
|
||||||
override fun drawContent(matrixStack: MatrixStack, mouse: Point, delta: Float) {
|
override fun drawContent(matrixStack: MatrixStack, mouse: Point, delta: Float) {
|
||||||
matrixStack.push()
|
RenderHelper.scale(bounds.width, bounds.height)
|
||||||
matrixStack.scale(bounds.width.toFloat(), bounds.height.toFloat(), 1f)
|
|
||||||
for ((index, point) in points.withIndex()) {
|
for ((index, point) in points.withIndex()) {
|
||||||
val next = points.getOrNull(index + 1) ?: break
|
val next = points.getOrNull(index + 1) ?: break
|
||||||
RenderHelper.drawLine(point, next, zIndex, lineWidth, lineColor)
|
RenderHelper.drawLine(point, next, zIndex, lineWidth, lineColor)
|
||||||
}
|
}
|
||||||
matrixStack.pop()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -29,7 +29,7 @@ class DialogView(
|
||||||
CANCEL, CONFIRM, OK, CLOSE;
|
CANCEL, CONFIRM, OK, CLOSE;
|
||||||
|
|
||||||
override val localizedName: Text
|
override val localizedName: Text
|
||||||
get() = LiteralText(name.lowercase().replaceFirstChar(Char::titlecase)) // todo: actually localize me
|
get() = LiteralText(name.toLowerCase().capitalize()) // todo: actually localize me
|
||||||
}
|
}
|
||||||
|
|
||||||
private lateinit var background: NinePatchView
|
private lateinit var background: NinePatchView
|
||||||
|
|
|
@ -12,6 +12,7 @@ import no.birkett.kiwi.Constraint
|
||||||
import no.birkett.kiwi.Solver
|
import no.birkett.kiwi.Solver
|
||||||
import java.lang.RuntimeException
|
import java.lang.RuntimeException
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import kotlin.collections.HashSet
|
||||||
import kotlin.math.floor
|
import kotlin.math.floor
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -367,8 +368,8 @@ open class View(): Responder {
|
||||||
* @param delta The time since the last frame.
|
* @param delta The time since the last frame.
|
||||||
*/
|
*/
|
||||||
open fun draw(matrixStack: MatrixStack, mouse: Point, delta: Float) {
|
open fun draw(matrixStack: MatrixStack, mouse: Point, delta: Float) {
|
||||||
matrixStack.push()
|
RenderHelper.pushMatrix()
|
||||||
matrixStack.translate(frame.left, frame.top, 0.0)
|
RenderHelper.translate(floor(frame.left), floor(frame.top))
|
||||||
|
|
||||||
RenderHelper.fill(matrixStack, bounds, backgroundColor)
|
RenderHelper.fill(matrixStack, bounds, backgroundColor)
|
||||||
|
|
||||||
|
@ -379,7 +380,7 @@ open class View(): Responder {
|
||||||
it.draw(matrixStack, mouseInView, delta)
|
it.draw(matrixStack, mouseInView, delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
matrixStack.pop()
|
RenderHelper.popMatrix()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -109,8 +109,8 @@ abstract class AbstractButton<Impl: AbstractButton<Impl>>(val content: View, val
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun draw(matrixStack: MatrixStack, mouse: Point, delta: Float) {
|
override fun draw(matrixStack: MatrixStack, mouse: Point, delta: Float) {
|
||||||
matrixStack.push()
|
RenderHelper.pushMatrix()
|
||||||
matrixStack.translate(frame.left, frame.top, 0.0)
|
RenderHelper.translate(floor(frame.left), floor(frame.top))
|
||||||
|
|
||||||
RenderHelper.fill(matrixStack, bounds, backgroundColor)
|
RenderHelper.fill(matrixStack, bounds, backgroundColor)
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ abstract class AbstractButton<Impl: AbstractButton<Impl>>(val content: View, val
|
||||||
|
|
||||||
// don't draw subviews, otherwise all background views + content will get drawn
|
// don't draw subviews, otherwise all background views + content will get drawn
|
||||||
|
|
||||||
matrixStack.pop()
|
RenderHelper.popMatrix()
|
||||||
|
|
||||||
if (tooltip != null && mouse in bounds) {
|
if (tooltip != null && mouse in bounds) {
|
||||||
window!!.drawTooltip(listOf(tooltip!!))
|
window!!.drawTooltip(listOf(tooltip!!))
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
package net.shadowfacts.cacao.view.textfield
|
package net.shadowfacts.cacao.view.textfield
|
||||||
|
|
||||||
import net.minecraft.client.MinecraftClient
|
import net.minecraft.client.MinecraftClient
|
||||||
|
import net.minecraft.client.gui.screen.TickableElement
|
||||||
import net.minecraft.client.gui.widget.TextFieldWidget
|
import net.minecraft.client.gui.widget.TextFieldWidget
|
||||||
import net.minecraft.client.util.math.MatrixStack
|
import net.minecraft.client.util.math.MatrixStack
|
||||||
import net.minecraft.text.LiteralText
|
import net.minecraft.text.LiteralText
|
||||||
import net.shadowfacts.cacao.geometry.Point
|
import net.shadowfacts.cacao.geometry.Point
|
||||||
|
import net.shadowfacts.cacao.util.Color
|
||||||
import net.shadowfacts.cacao.util.KeyModifiers
|
import net.shadowfacts.cacao.util.KeyModifiers
|
||||||
import net.shadowfacts.cacao.util.MouseButton
|
import net.shadowfacts.cacao.util.MouseButton
|
||||||
|
import net.shadowfacts.cacao.util.RenderHelper
|
||||||
import net.shadowfacts.cacao.view.View
|
import net.shadowfacts.cacao.view.View
|
||||||
import net.shadowfacts.phycon.mixin.client.TextFieldWidgetAccessor
|
import net.shadowfacts.phycon.mixin.client.TextFieldWidgetAccessor
|
||||||
import org.lwjgl.glfw.GLFW
|
import org.lwjgl.glfw.GLFW
|
||||||
|
@ -22,7 +25,7 @@ import org.lwjgl.glfw.GLFW
|
||||||
*/
|
*/
|
||||||
abstract class AbstractTextField<Impl: AbstractTextField<Impl>>(
|
abstract class AbstractTextField<Impl: AbstractTextField<Impl>>(
|
||||||
initialText: String
|
initialText: String
|
||||||
): View() {
|
): View(), TickableElement {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function that is invoked when the text in this text field changes.
|
* A function that is invoked when the text in this text field changes.
|
||||||
|
@ -67,7 +70,7 @@ abstract class AbstractTextField<Impl: AbstractTextField<Impl>>(
|
||||||
var drawBackground = true
|
var drawBackground = true
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
minecraftWidget.setDrawsBackground(value)
|
minecraftWidget.setHasBorder(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
private lateinit var originInWindow: Point
|
private lateinit var originInWindow: Point
|
||||||
|
@ -76,7 +79,7 @@ abstract class AbstractTextField<Impl: AbstractTextField<Impl>>(
|
||||||
init {
|
init {
|
||||||
minecraftWidget.text = initialText
|
minecraftWidget.text = initialText
|
||||||
minecraftWidget.setTextPredicate { this.validate(it) }
|
minecraftWidget.setTextPredicate { this.validate(it) }
|
||||||
minecraftWidget.setDrawsBackground(drawBackground)
|
minecraftWidget.setHasBorder(drawBackground)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -100,14 +103,14 @@ abstract class AbstractTextField<Impl: AbstractTextField<Impl>>(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun drawContent(matrixStack: MatrixStack, mouse: Point, delta: Float) {
|
override fun drawContent(matrixStack: MatrixStack, mouse: Point, delta: Float) {
|
||||||
matrixStack.push()
|
RenderHelper.pushMatrix()
|
||||||
matrixStack.translate(-originInWindow.x, -originInWindow.y, 0.0)
|
RenderHelper.translate(-originInWindow.x, -originInWindow.y)
|
||||||
|
|
||||||
val mouseXInWindow = (mouse.x + originInWindow.x).toInt()
|
val mouseXInWindow = (mouse.x + originInWindow.x).toInt()
|
||||||
val mouseYInWindow = (mouse.y + originInWindow.y).toInt()
|
val mouseYInWindow = (mouse.y + originInWindow.y).toInt()
|
||||||
minecraftWidget.render(matrixStack, mouseXInWindow, mouseYInWindow, delta)
|
minecraftWidget.render(matrixStack, mouseXInWindow, mouseYInWindow, delta)
|
||||||
|
|
||||||
matrixStack.pop()
|
RenderHelper.popMatrix()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun mouseClicked(point: Point, mouseButton: MouseButton): Boolean {
|
override fun mouseClicked(point: Point, mouseButton: MouseButton): Boolean {
|
||||||
|
@ -132,12 +135,12 @@ abstract class AbstractTextField<Impl: AbstractTextField<Impl>>(
|
||||||
|
|
||||||
override fun didBecomeFirstResponder() {
|
override fun didBecomeFirstResponder() {
|
||||||
super.didBecomeFirstResponder()
|
super.didBecomeFirstResponder()
|
||||||
minecraftWidget.setTextFieldFocused(true)
|
minecraftWidget.setSelected(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun didResignFirstResponder() {
|
override fun didResignFirstResponder() {
|
||||||
super.didResignFirstResponder()
|
super.didResignFirstResponder()
|
||||||
minecraftWidget.setTextFieldFocused(false)
|
minecraftWidget.setSelected(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun charTyped(char: Char, modifiers: KeyModifiers): Boolean {
|
override fun charTyped(char: Char, modifiers: KeyModifiers): Boolean {
|
||||||
|
@ -161,7 +164,7 @@ abstract class AbstractTextField<Impl: AbstractTextField<Impl>>(
|
||||||
return result || (isFirstResponder && keyCode != GLFW.GLFW_KEY_ESCAPE)
|
return result || (isFirstResponder && keyCode != GLFW.GLFW_KEY_ESCAPE)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun tick() {
|
override fun tick() {
|
||||||
minecraftWidget.tick()
|
minecraftWidget.tick()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -147,6 +147,11 @@ class TabViewController<T: TabViewController.Tab>(
|
||||||
currentTabController.viewWillAppear()
|
currentTabController.viewWillAppear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun viewDidAppear() {
|
||||||
|
super.viewDidAppear()
|
||||||
|
currentTabController.viewDidAppear()
|
||||||
|
}
|
||||||
|
|
||||||
override fun viewWillDisappear() {
|
override fun viewWillDisappear() {
|
||||||
super.viewWillDisappear()
|
super.viewWillDisappear()
|
||||||
currentTabController.viewWillDisappear()
|
currentTabController.viewWillDisappear()
|
||||||
|
@ -220,6 +225,7 @@ class TabViewController<T: TabViewController.Tab>(
|
||||||
embedChild(currentTabController, tabVCContainer)
|
embedChild(currentTabController, tabVCContainer)
|
||||||
currentTabController.didMoveTo(this)
|
currentTabController.didMoveTo(this)
|
||||||
currentTabController.viewWillAppear()
|
currentTabController.viewWillAppear()
|
||||||
|
currentTabController.viewDidAppear()
|
||||||
|
|
||||||
onTabChange?.invoke(currentTab)
|
onTabChange?.invoke(currentTab)
|
||||||
|
|
||||||
|
|
|
@ -122,12 +122,12 @@ abstract class ViewController {
|
||||||
children.forEach(ViewController::viewWillAppear)
|
children.forEach(ViewController::viewWillAppear)
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Called immediately after the VC's view has first been displayed on screen.
|
* Called immediately after the VC's view has first been displayed on screen.
|
||||||
// */
|
*/
|
||||||
// open fun viewDidAppear() {
|
open fun viewDidAppear() {
|
||||||
// children.forEach(ViewController::viewDidAppear)
|
children.forEach(ViewController::viewDidAppear)
|
||||||
// }
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called before the view will disappear from the screen, either because the VC has been removed from it's parent/screen
|
* Called before the view will disappear from the screen, either because the VC has been removed from it's parent/screen
|
||||||
|
|
|
@ -100,4 +100,4 @@ class KiwiContext(val solver: Solver) {
|
||||||
fun Solver.dsl(init: KiwiContext.() -> Unit): Solver {
|
fun Solver.dsl(init: KiwiContext.() -> Unit): Solver {
|
||||||
KiwiContext(this).init()
|
KiwiContext(this).init()
|
||||||
return this
|
return this
|
||||||
}
|
}
|
|
@ -16,7 +16,6 @@ object DefaultPlugin: PhyConPlugin {
|
||||||
|
|
||||||
override fun initializePhyCon(api: PhyConAPI) {
|
override fun initializePhyCon(api: PhyConAPI) {
|
||||||
SORT_MODE = api.registerTerminalSetting(Identifier(PhysicalConnectivity.MODID, "sort"), SortMode.COUNT_HIGH_FIRST)
|
SORT_MODE = api.registerTerminalSetting(Identifier(PhysicalConnectivity.MODID, "sort"), SortMode.COUNT_HIGH_FIRST)
|
||||||
SORT_MODE.setPriority(Int.MAX_VALUE)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,8 @@ package net.shadowfacts.phycon
|
||||||
|
|
||||||
import net.fabricmc.api.ModInitializer
|
import net.fabricmc.api.ModInitializer
|
||||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking
|
||||||
import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage
|
|
||||||
import net.fabricmc.loader.api.FabricLoader
|
import net.fabricmc.loader.api.FabricLoader
|
||||||
import net.shadowfacts.phycon.api.PhyConPlugin
|
import net.shadowfacts.phycon.api.PhyConPlugin
|
||||||
import net.shadowfacts.phycon.block.p2p.P2PReceiverBlockEntity
|
|
||||||
import net.shadowfacts.phycon.init.PhyBlockEntities
|
import net.shadowfacts.phycon.init.PhyBlockEntities
|
||||||
import net.shadowfacts.phycon.init.PhyBlocks
|
import net.shadowfacts.phycon.init.PhyBlocks
|
||||||
import net.shadowfacts.phycon.init.PhyItems
|
import net.shadowfacts.phycon.init.PhyItems
|
||||||
|
@ -33,8 +31,6 @@ object PhysicalConnectivity: ModInitializer {
|
||||||
registerGlobalReceiver(C2STerminalRequestItem)
|
registerGlobalReceiver(C2STerminalRequestItem)
|
||||||
registerGlobalReceiver(C2STerminalUpdateDisplayedItems)
|
registerGlobalReceiver(C2STerminalUpdateDisplayedItems)
|
||||||
|
|
||||||
ItemStorage.SIDED.registerForBlockEntity(P2PReceiverBlockEntity::provideItemStorage, PhyBlockEntities.P2P_RECEIVER)
|
|
||||||
|
|
||||||
for (it in FabricLoader.getInstance().getEntrypoints("phycon", PhyConPlugin::class.java)) {
|
for (it in FabricLoader.getInstance().getEntrypoints("phycon", PhyConPlugin::class.java)) {
|
||||||
it.initializePhyCon(PhyConAPIImpl)
|
it.initializePhyCon(PhyConAPIImpl)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,20 +2,15 @@ package net.shadowfacts.phycon.block
|
||||||
|
|
||||||
import net.minecraft.block.Block
|
import net.minecraft.block.Block
|
||||||
import net.minecraft.block.BlockEntityProvider
|
import net.minecraft.block.BlockEntityProvider
|
||||||
import net.minecraft.block.BlockState
|
|
||||||
import net.minecraft.block.entity.BlockEntity
|
import net.minecraft.block.entity.BlockEntity
|
||||||
import net.minecraft.block.entity.BlockEntityTicker
|
|
||||||
import net.minecraft.block.entity.BlockEntityType
|
|
||||||
import net.minecraft.util.math.BlockPos
|
import net.minecraft.util.math.BlockPos
|
||||||
import net.minecraft.world.BlockView
|
import net.minecraft.world.BlockView
|
||||||
import net.minecraft.world.World
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
abstract class BlockWithEntity<T: BlockEntity>(settings: Settings): Block(settings), BlockEntityProvider {
|
abstract class BlockWithEntity<T: BlockEntity>(settings: Settings): Block(settings), BlockEntityProvider {
|
||||||
abstract override fun createBlockEntity(pos: BlockPos, state: BlockState): T?
|
abstract override fun createBlockEntity(world: BlockView): T?
|
||||||
|
|
||||||
fun getBlockEntity(world: BlockView, pos: BlockPos): T? {
|
fun getBlockEntity(world: BlockView, pos: BlockPos): T? {
|
||||||
val entity = world.getBlockEntity(pos)
|
val entity = world.getBlockEntity(pos)
|
||||||
return if (entity != null) {
|
return if (entity != null) {
|
||||||
|
@ -24,4 +19,4 @@ abstract class BlockWithEntity<T: BlockEntity>(settings: Settings): Block(settin
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,9 +1,6 @@
|
||||||
package net.shadowfacts.phycon.block
|
package net.shadowfacts.phycon.block
|
||||||
|
|
||||||
import net.minecraft.block.BlockState
|
import net.minecraft.block.BlockState
|
||||||
import net.minecraft.block.entity.BlockEntity
|
|
||||||
import net.minecraft.block.entity.BlockEntityTicker
|
|
||||||
import net.minecraft.block.entity.BlockEntityType
|
|
||||||
import net.minecraft.entity.player.PlayerEntity
|
import net.minecraft.entity.player.PlayerEntity
|
||||||
import net.minecraft.util.math.BlockPos
|
import net.minecraft.util.math.BlockPos
|
||||||
import net.minecraft.util.math.Direction
|
import net.minecraft.util.math.Direction
|
||||||
|
@ -28,14 +25,4 @@ abstract class DeviceBlock<T: DeviceBlockEntity>(settings: Settings): BlockWithE
|
||||||
getBlockEntity(world, pos)!!.onBreak()
|
getBlockEntity(world, pos)!!.onBreak()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun <T: BlockEntity> getTicker(world: World, state: BlockState, type: BlockEntityType<T>): BlockEntityTicker<T>? {
|
|
||||||
return if (world.isClient) {
|
|
||||||
null
|
|
||||||
} else {
|
|
||||||
BlockEntityTicker { world, blockPos, blockState, blockEntity ->
|
|
||||||
(blockEntity as DeviceBlockEntity).tick()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,32 +1,34 @@
|
||||||
package net.shadowfacts.phycon.block
|
package net.shadowfacts.phycon.block
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable
|
||||||
import net.minecraft.block.BlockState
|
import net.minecraft.block.BlockState
|
||||||
import net.minecraft.block.entity.BlockEntity
|
import net.minecraft.block.entity.BlockEntity
|
||||||
import net.minecraft.block.entity.BlockEntityType
|
import net.minecraft.block.entity.BlockEntityType
|
||||||
import net.minecraft.nbt.NbtCompound
|
import net.minecraft.nbt.CompoundTag
|
||||||
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket
|
import net.minecraft.util.Tickable
|
||||||
import net.minecraft.util.math.BlockPos
|
|
||||||
import net.shadowfacts.phycon.PhysicalConnectivity
|
import net.shadowfacts.phycon.PhysicalConnectivity
|
||||||
import net.shadowfacts.phycon.api.Interface
|
|
||||||
import net.shadowfacts.phycon.api.NetworkComponentBlock
|
|
||||||
import net.shadowfacts.phycon.api.PacketSink
|
import net.shadowfacts.phycon.api.PacketSink
|
||||||
import net.shadowfacts.phycon.api.PacketSource
|
import net.shadowfacts.phycon.api.PacketSource
|
||||||
|
import net.shadowfacts.phycon.api.Interface
|
||||||
|
import net.shadowfacts.phycon.api.NetworkComponentBlock
|
||||||
import net.shadowfacts.phycon.api.frame.EthernetFrame
|
import net.shadowfacts.phycon.api.frame.EthernetFrame
|
||||||
import net.shadowfacts.phycon.api.frame.PacketFrame
|
import net.shadowfacts.phycon.api.frame.PacketFrame
|
||||||
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.api.util.MACAddress
|
import net.shadowfacts.phycon.api.util.MACAddress
|
||||||
|
import net.shadowfacts.phycon.util.NetworkUtil
|
||||||
import net.shadowfacts.phycon.frame.ARPQueryFrame
|
import net.shadowfacts.phycon.frame.ARPQueryFrame
|
||||||
import net.shadowfacts.phycon.frame.ARPResponseFrame
|
import net.shadowfacts.phycon.frame.ARPResponseFrame
|
||||||
import net.shadowfacts.phycon.frame.BasePacketFrame
|
import net.shadowfacts.phycon.frame.BasePacketFrame
|
||||||
import net.shadowfacts.phycon.packet.*
|
import net.shadowfacts.phycon.packet.*
|
||||||
import net.shadowfacts.phycon.util.NetworkUtil
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
abstract class DeviceBlockEntity(type: BlockEntityType<*>, pos: BlockPos, state: BlockState): BlockEntity(type, pos, state),
|
abstract class DeviceBlockEntity(type: BlockEntityType<*>): BlockEntity(type),
|
||||||
|
BlockEntityClientSerializable,
|
||||||
|
Tickable,
|
||||||
PacketSink,
|
PacketSink,
|
||||||
PacketSource,
|
PacketSource,
|
||||||
Interface {
|
Interface {
|
||||||
|
@ -57,9 +59,6 @@ abstract class DeviceBlockEntity(type: BlockEntityType<*>, pos: BlockPos, state:
|
||||||
is DeviceRemovedPacket -> {
|
is DeviceRemovedPacket -> {
|
||||||
arpTable.remove(packet.source)
|
arpTable.remove(packet.source)
|
||||||
}
|
}
|
||||||
is PingPacket -> {
|
|
||||||
sendPacket(PongPacket(ipAddress, packet.source))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
handle(packet)
|
handle(packet)
|
||||||
}
|
}
|
||||||
|
@ -127,7 +126,7 @@ abstract class DeviceBlockEntity(type: BlockEntityType<*>, pos: BlockPos, state:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun tick() {
|
override fun tick() {
|
||||||
counter++
|
counter++
|
||||||
|
|
||||||
if (!world!!.isClient) {
|
if (!world!!.isClient) {
|
||||||
|
@ -149,50 +148,33 @@ abstract class DeviceBlockEntity(type: BlockEntityType<*>, pos: BlockPos, state:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun toCommonTag(tag: NbtCompound) {
|
protected open fun toCommonTag(tag: CompoundTag) {
|
||||||
tag.putInt("IPAddress", ipAddress.address)
|
tag.putInt("IPAddress", ipAddress.address)
|
||||||
tag.putLong("MACAddress", macAddress.address)
|
tag.putLong("MACAddress", macAddress.address)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected open fun fromCommonTag(tag: NbtCompound) {
|
protected open fun fromCommonTag(tag: CompoundTag) {
|
||||||
ipAddress = IPAddress(tag.getInt("IPAddress"))
|
ipAddress = IPAddress(tag.getInt("IPAddress"))
|
||||||
macAddress = MACAddress(tag.getLong("MACAddress"))
|
macAddress = MACAddress(tag.getLong("MACAddress"))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun writeNbt(tag: NbtCompound) {
|
override fun toTag(tag: CompoundTag): CompoundTag {
|
||||||
super.writeNbt(tag)
|
|
||||||
toCommonTag(tag)
|
toCommonTag(tag)
|
||||||
|
return super.toTag(tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun readNbt(tag: NbtCompound) {
|
override fun fromTag(state: BlockState, tag: CompoundTag) {
|
||||||
super.readNbt(tag)
|
super.fromTag(state, tag)
|
||||||
fromCommonTag(tag)
|
fromCommonTag(tag)
|
||||||
if (tag.getBoolean("_SyncPacket")) {
|
|
||||||
fromClientTag(tag)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toUpdatePacket(): BlockEntityUpdateS2CPacket {
|
override fun toClientTag(tag: CompoundTag): CompoundTag {
|
||||||
return BlockEntityUpdateS2CPacket.create(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toInitialChunkDataNbt(): NbtCompound {
|
|
||||||
val tag = NbtCompound()
|
|
||||||
tag.putBoolean("_SyncPacket", true)
|
|
||||||
return toClientTag(tag)
|
|
||||||
}
|
|
||||||
|
|
||||||
open fun toClientTag(tag: NbtCompound): NbtCompound {
|
|
||||||
toCommonTag(tag)
|
toCommonTag(tag)
|
||||||
return tag
|
return tag
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun fromClientTag(tag: NbtCompound) {
|
override fun fromClientTag(tag: CompoundTag) {
|
||||||
}
|
fromCommonTag(tag)
|
||||||
|
|
||||||
fun markUpdate() {
|
|
||||||
markDirty()
|
|
||||||
world!!.updateListeners(pos, cachedState, cachedState, 3)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onBreak() {
|
fun onBreak() {
|
||||||
|
|
|
@ -42,7 +42,7 @@ class CableBlock(
|
||||||
), NetworkCableBlock {
|
), NetworkCableBlock {
|
||||||
companion object {
|
companion object {
|
||||||
val ID = Identifier(PhysicalConnectivity.MODID, "cable")
|
val ID = Identifier(PhysicalConnectivity.MODID, "cable")
|
||||||
val CABLE_MATERIAL = Material.Builder(MapColor.BLUE).build()
|
val CABLE_MATERIAL = Material.Builder(MaterialColor.BLUE).build()
|
||||||
val CENTER_SHAPE = createCuboidShape(6.0, 6.0, 6.0, 10.0, 10.0, 10.0)
|
val CENTER_SHAPE = createCuboidShape(6.0, 6.0, 6.0, 10.0, 10.0, 10.0)
|
||||||
val SIDE_SHAPES = mapOf<Direction, VoxelShape>(
|
val SIDE_SHAPES = mapOf<Direction, VoxelShape>(
|
||||||
Direction.DOWN to createCuboidShape(6.0, 0.0, 6.0, 10.0, 6.0, 10.0),
|
Direction.DOWN to createCuboidShape(6.0, 0.0, 6.0, 10.0, 6.0, 10.0),
|
||||||
|
|
|
@ -15,8 +15,6 @@ import net.minecraft.world.BlockView
|
||||||
import net.minecraft.world.World
|
import net.minecraft.world.World
|
||||||
import net.shadowfacts.phycon.PhysicalConnectivity
|
import net.shadowfacts.phycon.PhysicalConnectivity
|
||||||
import net.shadowfacts.phycon.block.FaceDeviceBlock
|
import net.shadowfacts.phycon.block.FaceDeviceBlock
|
||||||
import kotlin.math.max
|
|
||||||
import kotlin.math.min
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
|
@ -59,7 +57,7 @@ class ExtractorBlock: FaceDeviceBlock<ExtractorBlockEntity>(
|
||||||
arr[i] = 16.0 - arr[i]
|
arr[i] = 16.0 - arr[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
createCuboidShape(min(arr[0], arr[3]), min(arr[1], arr[4]), min(arr[2], arr[5]), max(arr[0], arr[3]), max(arr[1], arr[4]), max(arr[2], arr[5]))
|
createCuboidShape(arr[0], arr[1], arr[2], arr[3], arr[4], arr[5])
|
||||||
}
|
}
|
||||||
EXTRACTOR_SHAPES[dir] = shapes.reduce { a, b -> VoxelShapes.union(a, b) }
|
EXTRACTOR_SHAPES[dir] = shapes.reduce { a, b -> VoxelShapes.union(a, b) }
|
||||||
}
|
}
|
||||||
|
@ -69,7 +67,7 @@ class ExtractorBlock: FaceDeviceBlock<ExtractorBlockEntity>(
|
||||||
override val faceThickness = 6.0
|
override val faceThickness = 6.0
|
||||||
override val faceShapes: Map<Direction, VoxelShape> = EXTRACTOR_SHAPES
|
override val faceShapes: Map<Direction, VoxelShape> = EXTRACTOR_SHAPES
|
||||||
|
|
||||||
override fun createBlockEntity(pos: BlockPos, state: BlockState) = ExtractorBlockEntity(pos, state)
|
override fun createBlockEntity(world: BlockView) = ExtractorBlockEntity()
|
||||||
|
|
||||||
override fun onPlaced(world: World, pos: BlockPos, state: BlockState, entity: LivingEntity?, stack: ItemStack) {
|
override fun onPlaced(world: World, pos: BlockPos, state: BlockState, entity: LivingEntity?, stack: ItemStack) {
|
||||||
if (!world.isClient) {
|
if (!world.isClient) {
|
||||||
|
|
|
@ -5,10 +5,8 @@ import alexiil.mc.lib.attributes.Simulation
|
||||||
import alexiil.mc.lib.attributes.item.FixedItemInv
|
import alexiil.mc.lib.attributes.item.FixedItemInv
|
||||||
import alexiil.mc.lib.attributes.item.ItemAttributes
|
import alexiil.mc.lib.attributes.item.ItemAttributes
|
||||||
import alexiil.mc.lib.attributes.item.filter.ExactItemStackFilter
|
import alexiil.mc.lib.attributes.item.filter.ExactItemStackFilter
|
||||||
import net.minecraft.block.BlockState
|
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.nbt.NbtCompound
|
import net.minecraft.nbt.CompoundTag
|
||||||
import net.minecraft.util.math.BlockPos
|
|
||||||
import net.minecraft.util.math.Direction
|
import net.minecraft.util.math.Direction
|
||||||
import net.shadowfacts.phycon.api.packet.Packet
|
import net.shadowfacts.phycon.api.packet.Packet
|
||||||
import net.shadowfacts.phycon.init.PhyBlockEntities
|
import net.shadowfacts.phycon.init.PhyBlockEntities
|
||||||
|
@ -28,7 +26,7 @@ import kotlin.properties.Delegates
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
class ExtractorBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockEntity(PhyBlockEntities.EXTRACTOR, pos, state),
|
class ExtractorBlockEntity: DeviceBlockEntity(PhyBlockEntities.EXTRACTOR),
|
||||||
NetworkStackDispatcher<ExtractorBlockEntity.PendingInsertion>,
|
NetworkStackDispatcher<ExtractorBlockEntity.PendingInsertion>,
|
||||||
ActivationController.ActivatableDevice,
|
ActivationController.ActivatableDevice,
|
||||||
ClientConfigurableDevice {
|
ClientConfigurableDevice {
|
||||||
|
@ -108,21 +106,21 @@ class ExtractorBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockEntity(
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toCommonTag(tag: NbtCompound) {
|
override fun toCommonTag(tag: CompoundTag) {
|
||||||
super.toCommonTag(tag)
|
super.toCommonTag(tag)
|
||||||
writeDeviceConfiguration(tag)
|
writeDeviceConfiguration(tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fromCommonTag(tag: NbtCompound) {
|
override fun fromCommonTag(tag: CompoundTag) {
|
||||||
super.fromCommonTag(tag)
|
super.fromCommonTag(tag)
|
||||||
loadDeviceConfiguration(tag)
|
loadDeviceConfiguration(tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun writeDeviceConfiguration(tag: NbtCompound) {
|
override fun writeDeviceConfiguration(tag: CompoundTag) {
|
||||||
tag.putString("ActivationMode", controller.activationMode.name)
|
tag.putString("ActivationMode", controller.activationMode.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun loadDeviceConfiguration(tag: NbtCompound) {
|
override fun loadDeviceConfiguration(tag: CompoundTag) {
|
||||||
controller.activationMode = ActivationMode.valueOf(tag.getString("ActivationMode"))
|
controller.activationMode = ActivationMode.valueOf(tag.getString("ActivationMode"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,6 @@ import net.minecraft.world.World
|
||||||
import net.shadowfacts.phycon.PhysicalConnectivity
|
import net.shadowfacts.phycon.PhysicalConnectivity
|
||||||
import net.shadowfacts.phycon.block.FaceDeviceBlock
|
import net.shadowfacts.phycon.block.FaceDeviceBlock
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.math.max
|
|
||||||
import kotlin.math.min
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
|
@ -68,7 +66,7 @@ class InserterBlock: FaceDeviceBlock<InserterBlockEntity>(
|
||||||
arr[i] = 16.0 - arr[i]
|
arr[i] = 16.0 - arr[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
createCuboidShape(min(arr[0], arr[3]), min(arr[1], arr[4]), min(arr[2], arr[5]), max(arr[0], arr[3]), max(arr[1], arr[4]), max(arr[2], arr[5]))
|
createCuboidShape(arr[0], arr[1], arr[2], arr[3], arr[4], arr[5])
|
||||||
}
|
}
|
||||||
INSERTER_SHAPES[dir] = shapes.reduce { a, b -> VoxelShapes.union(a, b) }
|
INSERTER_SHAPES[dir] = shapes.reduce { a, b -> VoxelShapes.union(a, b) }
|
||||||
}
|
}
|
||||||
|
@ -78,7 +76,7 @@ class InserterBlock: FaceDeviceBlock<InserterBlockEntity>(
|
||||||
override val faceThickness = 6.0
|
override val faceThickness = 6.0
|
||||||
override val faceShapes: Map<Direction, VoxelShape> = INSERTER_SHAPES
|
override val faceShapes: Map<Direction, VoxelShape> = INSERTER_SHAPES
|
||||||
|
|
||||||
override fun createBlockEntity(pos: BlockPos, state: BlockState) = InserterBlockEntity(pos, state)
|
override fun createBlockEntity(world: BlockView) = InserterBlockEntity()
|
||||||
|
|
||||||
override fun onPlaced(world: World, pos: BlockPos, state: BlockState, entity: LivingEntity?, stack: ItemStack) {
|
override fun onPlaced(world: World, pos: BlockPos, state: BlockState, entity: LivingEntity?, stack: ItemStack) {
|
||||||
if (!world.isClient) {
|
if (!world.isClient) {
|
||||||
|
@ -96,7 +94,7 @@ class InserterBlock: FaceDeviceBlock<InserterBlockEntity>(
|
||||||
if (!world.isClient) {
|
if (!world.isClient) {
|
||||||
val be = getBlockEntity(world, pos)!!
|
val be = getBlockEntity(world, pos)!!
|
||||||
|
|
||||||
be.markUpdate()
|
be.sync()
|
||||||
|
|
||||||
val factory = object: ExtendedScreenHandlerFactory {
|
val factory = object: ExtendedScreenHandlerFactory {
|
||||||
override fun createMenu(syncId: Int, playerInv: PlayerInventory, player: PlayerEntity): ScreenHandler {
|
override fun createMenu(syncId: Int, playerInv: PlayerInventory, player: PlayerEntity): ScreenHandler {
|
||||||
|
|
|
@ -5,10 +5,8 @@ import alexiil.mc.lib.attributes.Simulation
|
||||||
import alexiil.mc.lib.attributes.item.ItemAttributes
|
import alexiil.mc.lib.attributes.item.ItemAttributes
|
||||||
import alexiil.mc.lib.attributes.item.ItemInsertable
|
import alexiil.mc.lib.attributes.item.ItemInsertable
|
||||||
import alexiil.mc.lib.attributes.item.ItemStackUtil
|
import alexiil.mc.lib.attributes.item.ItemStackUtil
|
||||||
import net.minecraft.block.BlockState
|
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.nbt.NbtCompound
|
import net.minecraft.nbt.CompoundTag
|
||||||
import net.minecraft.util.math.BlockPos
|
|
||||||
import net.minecraft.util.math.Direction
|
import net.minecraft.util.math.Direction
|
||||||
import net.shadowfacts.phycon.api.packet.Packet
|
import net.shadowfacts.phycon.api.packet.Packet
|
||||||
import net.shadowfacts.phycon.block.DeviceBlockEntity
|
import net.shadowfacts.phycon.block.DeviceBlockEntity
|
||||||
|
@ -27,7 +25,7 @@ import kotlin.math.min
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
class InserterBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockEntity(PhyBlockEntities.INSERTER, pos, state),
|
class InserterBlockEntity: DeviceBlockEntity(PhyBlockEntities.INSERTER),
|
||||||
ItemStackPacketHandler,
|
ItemStackPacketHandler,
|
||||||
ActivationController.ActivatableDevice,
|
ActivationController.ActivatableDevice,
|
||||||
ClientConfigurableDevice,
|
ClientConfigurableDevice,
|
||||||
|
@ -134,24 +132,24 @@ class InserterBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockEntity(P
|
||||||
currentRequest = null
|
currentRequest = null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toCommonTag(tag: NbtCompound) {
|
override fun toCommonTag(tag: CompoundTag) {
|
||||||
super.toCommonTag(tag)
|
super.toCommonTag(tag)
|
||||||
writeDeviceConfiguration(tag)
|
writeDeviceConfiguration(tag)
|
||||||
tag.put("StackToExtract", stackToExtract.writeNbt(NbtCompound()))
|
tag.put("StackToExtract", stackToExtract.toTag(CompoundTag()))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fromCommonTag(tag: NbtCompound) {
|
override fun fromCommonTag(tag: CompoundTag) {
|
||||||
super.fromCommonTag(tag)
|
super.fromCommonTag(tag)
|
||||||
loadDeviceConfiguration(tag)
|
loadDeviceConfiguration(tag)
|
||||||
stackToExtract = ItemStack.fromNbt(tag.getCompound("StackToExtract"))
|
stackToExtract = ItemStack.fromTag(tag.getCompound("StackToExtract"))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun writeDeviceConfiguration(tag: NbtCompound) {
|
override fun writeDeviceConfiguration(tag: CompoundTag) {
|
||||||
tag.putString("ActivationMode", controller.activationMode.name)
|
tag.putString("ActivationMode", controller.activationMode.name)
|
||||||
tag.putInt("AmountToExtract", amountToExtract)
|
tag.putInt("AmountToExtract", amountToExtract)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun loadDeviceConfiguration(tag: NbtCompound) {
|
override fun loadDeviceConfiguration(tag: CompoundTag) {
|
||||||
controller.activationMode = ActivationMode.valueOf(tag.getString("ActivationMode"))
|
controller.activationMode = ActivationMode.valueOf(tag.getString("ActivationMode"))
|
||||||
amountToExtract = tag.getInt("AmountToExtract")
|
amountToExtract = tag.getInt("AmountToExtract")
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package net.shadowfacts.phycon.block.inserter
|
||||||
import com.mojang.blaze3d.systems.RenderSystem
|
import com.mojang.blaze3d.systems.RenderSystem
|
||||||
import net.minecraft.client.gui.screen.ingame.HandledScreen
|
import net.minecraft.client.gui.screen.ingame.HandledScreen
|
||||||
import net.minecraft.client.gui.widget.TextFieldWidget
|
import net.minecraft.client.gui.widget.TextFieldWidget
|
||||||
import net.minecraft.client.render.GameRenderer
|
|
||||||
import net.minecraft.client.util.math.MatrixStack
|
import net.minecraft.client.util.math.MatrixStack
|
||||||
import net.minecraft.entity.player.PlayerInventory
|
import net.minecraft.entity.player.PlayerInventory
|
||||||
import net.minecraft.screen.slot.Slot
|
import net.minecraft.screen.slot.Slot
|
||||||
|
@ -45,9 +44,9 @@ class InserterScreen(
|
||||||
|
|
||||||
amountField = TextFieldWidget(textRenderer, x + 57, y + 24, 80, 9, LiteralText("Amount"))
|
amountField = TextFieldWidget(textRenderer, x + 57, y + 24, 80, 9, LiteralText("Amount"))
|
||||||
amountField.text = handler.inserter.amountToExtract.toString()
|
amountField.text = handler.inserter.amountToExtract.toString()
|
||||||
amountField.setDrawsBackground(false)
|
amountField.setHasBorder(false)
|
||||||
amountField.isVisible = true
|
amountField.isVisible = true
|
||||||
amountField.setTextFieldFocused(true)
|
amountField.setSelected(true)
|
||||||
amountField.setEditableColor(0xffffff)
|
amountField.setEditableColor(0xffffff)
|
||||||
amountField.setTextPredicate {
|
amountField.setTextPredicate {
|
||||||
if (it.isEmpty()) {
|
if (it.isEmpty()) {
|
||||||
|
@ -61,7 +60,7 @@ class InserterScreen(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
addDrawableChild(amountField)
|
addChild(amountField)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun amountUpdated() {
|
fun amountUpdated() {
|
||||||
|
@ -71,16 +70,16 @@ class InserterScreen(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handledScreenTick() {
|
override fun tick() {
|
||||||
super.handledScreenTick()
|
super.tick()
|
||||||
amountField.tick()
|
amountField.tick()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun drawBackground(matrixStack: MatrixStack, delta: Float, mouseX: Int, mouseY: Int) {
|
override fun drawBackground(matrixStack: MatrixStack, delta: Float, mouseX: Int, mouseY: Int) {
|
||||||
renderBackground(matrixStack)
|
renderBackground(matrixStack)
|
||||||
|
|
||||||
RenderSystem.setShader(GameRenderer::getPositionTexShader)
|
RenderSystem.color4f(1f, 1f, 1f, 1f)
|
||||||
RenderSystem.setShaderTexture(0, BACKGROUND)
|
client!!.textureManager.bindTexture(BACKGROUND)
|
||||||
val x = (width - backgroundWidth) / 2
|
val x = (width - backgroundWidth) / 2
|
||||||
val y = (height - backgroundHeight) / 2
|
val y = (height - backgroundHeight) / 2
|
||||||
drawTexture(matrixStack, x, y, 0, 0, backgroundWidth, backgroundHeight)
|
drawTexture(matrixStack, x, y, 0, 0, backgroundWidth, backgroundHeight)
|
||||||
|
@ -97,7 +96,7 @@ class InserterScreen(
|
||||||
override fun onMouseClick(slot: Slot?, invSlot: Int, clickData: Int, slotActionType: SlotActionType?) {
|
override fun onMouseClick(slot: Slot?, invSlot: Int, clickData: Int, slotActionType: SlotActionType?) {
|
||||||
super.onMouseClick(slot, invSlot, clickData, slotActionType)
|
super.onMouseClick(slot, invSlot, clickData, slotActionType)
|
||||||
|
|
||||||
amountField.setTextFieldFocused(true)
|
amountField.setSelected(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun charTyped(c: Char, i: Int): Boolean {
|
override fun charTyped(c: Char, i: Int): Boolean {
|
||||||
|
|
|
@ -60,17 +60,17 @@ class InserterScreenHandler(
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSlotClick(slotId: Int, clickData: Int, actionType: SlotActionType, player: PlayerEntity) {
|
override fun onSlotClick(slotId: Int, clickData: Int, actionType: SlotActionType, player: PlayerEntity): ItemStack {
|
||||||
// fake slot
|
// fake slot
|
||||||
if (slotId == 0) {
|
if (slotId == 0) {
|
||||||
if (cursorStack.isEmpty) {
|
if (player.inventory.cursorStack.isEmpty) {
|
||||||
inserter.stackToExtract = ItemStack.EMPTY
|
inserter.stackToExtract = ItemStack.EMPTY
|
||||||
} else {
|
} else {
|
||||||
inserter.stackToExtract = cursorStack.copyWithCount(1)
|
inserter.stackToExtract = player.inventory.cursorStack.copyWithCount(1)
|
||||||
}
|
}
|
||||||
stackToExtractChanged()
|
stackToExtractChanged()
|
||||||
}
|
}
|
||||||
super.onSlotClick(slotId, clickData, actionType, player)
|
return super.onSlotClick(slotId, clickData, actionType, player)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun transferSlot(player: PlayerEntity, slotId: Int): ItemStack {
|
override fun transferSlot(player: PlayerEntity, slotId: Int): ItemStack {
|
||||||
|
|
|
@ -51,7 +51,7 @@ class MinerBlock: DeviceBlock<MinerBlockEntity>(
|
||||||
builder.add(FACING)
|
builder.add(FACING)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createBlockEntity(pos: BlockPos, state: BlockState) = MinerBlockEntity(pos, state)
|
override fun createBlockEntity(world: BlockView) = MinerBlockEntity()
|
||||||
|
|
||||||
override fun getPlacementState(context: ItemPlacementContext): BlockState? {
|
override fun getPlacementState(context: ItemPlacementContext): BlockState? {
|
||||||
val facing = if (context.player?.isSneaking == true) context.side.opposite else context.playerFacing.opposite
|
val facing = if (context.player?.isSneaking == true) context.side.opposite else context.playerFacing.opposite
|
||||||
|
|
|
@ -7,7 +7,7 @@ import net.minecraft.block.Block
|
||||||
import net.minecraft.block.BlockState
|
import net.minecraft.block.BlockState
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.item.Items
|
import net.minecraft.item.Items
|
||||||
import net.minecraft.nbt.NbtCompound
|
import net.minecraft.nbt.CompoundTag
|
||||||
import net.minecraft.server.world.ServerWorld
|
import net.minecraft.server.world.ServerWorld
|
||||||
import net.minecraft.text.TranslatableText
|
import net.minecraft.text.TranslatableText
|
||||||
import net.minecraft.util.math.BlockPos
|
import net.minecraft.util.math.BlockPos
|
||||||
|
@ -27,7 +27,7 @@ import kotlin.math.min
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
class MinerBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockEntity(PhyBlockEntities.MINER, pos, state),
|
class MinerBlockEntity: DeviceBlockEntity(PhyBlockEntities.MINER),
|
||||||
NetworkStackProvider,
|
NetworkStackProvider,
|
||||||
NetworkStackDispatcher<MinerBlockEntity.PendingInsertion>,
|
NetworkStackDispatcher<MinerBlockEntity.PendingInsertion>,
|
||||||
ActivationController.ActivatableDevice,
|
ActivationController.ActivatableDevice,
|
||||||
|
@ -57,10 +57,10 @@ class MinerBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockEntity(PhyB
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleRequestInventory(packet: RequestInventoryPacket) {
|
private fun handleRequestInventory(packet: RequestInventoryPacket) {
|
||||||
if (minerMode != MinerMode.ON_DEMAND || packet.kind != RequestInventoryPacket.Kind.GROUPED) {
|
if (minerMode != MinerMode.ON_DEMAND) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sendPacket(ReadGroupedInventoryPacket(invProxy, ipAddress, packet.source))
|
sendPacket(ReadInventoryPacket(invProxy, ipAddress, packet.source))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleLocateStack(packet: LocateStackPacket) {
|
private fun handleLocateStack(packet: LocateStackPacket) {
|
||||||
|
@ -156,23 +156,23 @@ class MinerBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockEntity(PhyB
|
||||||
return minerMode == MinerMode.ON_DEMAND
|
return minerMode == MinerMode.ON_DEMAND
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toCommonTag(tag: NbtCompound) {
|
override fun toCommonTag(tag: CompoundTag) {
|
||||||
super.toCommonTag(tag)
|
super.toCommonTag(tag)
|
||||||
writeDeviceConfiguration(tag)
|
writeDeviceConfiguration(tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fromCommonTag(tag: NbtCompound) {
|
override fun fromCommonTag(tag: CompoundTag) {
|
||||||
super.fromCommonTag(tag)
|
super.fromCommonTag(tag)
|
||||||
loadDeviceConfiguration(tag)
|
loadDeviceConfiguration(tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun writeDeviceConfiguration(tag: NbtCompound) {
|
override fun writeDeviceConfiguration(tag: CompoundTag) {
|
||||||
tag.putString("MinerMode", minerMode.name)
|
tag.putString("MinerMode", minerMode.name)
|
||||||
tag.putString("ActivationMode", controller.activationMode.name)
|
tag.putString("ActivationMode", controller.activationMode.name)
|
||||||
tag.putInt("ProviderPriority", providerPriority)
|
tag.putInt("ProviderPriority", providerPriority)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun loadDeviceConfiguration(tag: NbtCompound) {
|
override fun loadDeviceConfiguration(tag: CompoundTag) {
|
||||||
minerMode = MinerMode.valueOf(tag.getString("MinerMode"))
|
minerMode = MinerMode.valueOf(tag.getString("MinerMode"))
|
||||||
controller.activationMode = ActivationMode.valueOf(tag.getString("ActivationMode"))
|
controller.activationMode = ActivationMode.valueOf(tag.getString("ActivationMode"))
|
||||||
providerPriority = tag.getInt("ProviderPriority")
|
providerPriority = tag.getInt("ProviderPriority")
|
||||||
|
@ -181,7 +181,7 @@ class MinerBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockEntity(PhyB
|
||||||
enum class MinerMode {
|
enum class MinerMode {
|
||||||
ON_DEMAND, AUTOMATIC;
|
ON_DEMAND, AUTOMATIC;
|
||||||
|
|
||||||
val friendlyName = TranslatableText("gui.phycon.miner_mode.${name.lowercase()}")
|
val friendlyName = TranslatableText("gui.phycon.miner_mode.${name.toLowerCase()}")
|
||||||
}
|
}
|
||||||
|
|
||||||
class MinerInvProxy(val miner: MinerBlockEntity): GroupedItemInvView {
|
class MinerInvProxy(val miner: MinerBlockEntity): GroupedItemInvView {
|
||||||
|
@ -205,8 +205,7 @@ class MinerBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockEntity(PhyB
|
||||||
// todo: does BlockState.equals actually work or is reference equality fine for BlockStates?
|
// todo: does BlockState.equals actually work or is reference equality fine for BlockStates?
|
||||||
if (cachedDrops == null || realState != cachedState || recalculate) {
|
if (cachedDrops == null || realState != cachedState || recalculate) {
|
||||||
cachedState = realState
|
cachedState = realState
|
||||||
|
val be = if (realState.block.hasBlockEntity()) world.getBlockEntity(targetPos) else null
|
||||||
val be = if (realState.hasBlockEntity()) world.getBlockEntity(targetPos) else null
|
|
||||||
cachedDrops = Block.getDroppedStacks(realState, world as ServerWorld, targetPos, be, null, TOOL)
|
cachedDrops = Block.getDroppedStacks(realState, world as ServerWorld, targetPos, be, null, TOOL)
|
||||||
}
|
}
|
||||||
return cachedDrops!!
|
return cachedDrops!!
|
||||||
|
|
|
@ -40,7 +40,7 @@ class InterfaceBlock: FaceDeviceBlock<InterfaceBlockEntity>(
|
||||||
Direction.EAST to createCuboidShape(14.0, 2.0, 2.0, 16.0, 14.0, 14.0)
|
Direction.EAST to createCuboidShape(14.0, 2.0, 2.0, 16.0, 14.0, 14.0)
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun createBlockEntity(pos: BlockPos, state: BlockState) = InterfaceBlockEntity(pos, state)
|
override fun createBlockEntity(world: BlockView) = InterfaceBlockEntity()
|
||||||
|
|
||||||
override fun onPlaced(world: World, pos: BlockPos, state: BlockState, placer: LivingEntity?, stack: ItemStack) {
|
override fun onPlaced(world: World, pos: BlockPos, state: BlockState, placer: LivingEntity?, stack: ItemStack) {
|
||||||
if (!world.isClient) {
|
if (!world.isClient) {
|
||||||
|
|
|
@ -6,8 +6,7 @@ import alexiil.mc.lib.attributes.item.GroupedItemInv
|
||||||
import alexiil.mc.lib.attributes.item.ItemAttributes
|
import alexiil.mc.lib.attributes.item.ItemAttributes
|
||||||
import net.minecraft.block.BlockState
|
import net.minecraft.block.BlockState
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.nbt.NbtCompound
|
import net.minecraft.nbt.CompoundTag
|
||||||
import net.minecraft.util.math.BlockPos
|
|
||||||
import net.minecraft.util.math.Direction
|
import net.minecraft.util.math.Direction
|
||||||
import net.shadowfacts.phycon.api.packet.Packet
|
import net.shadowfacts.phycon.api.packet.Packet
|
||||||
import net.shadowfacts.phycon.init.PhyBlockEntities
|
import net.shadowfacts.phycon.init.PhyBlockEntities
|
||||||
|
@ -24,7 +23,7 @@ import kotlin.math.min
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
class InterfaceBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockEntity(PhyBlockEntities.INTERFACE, pos, state),
|
class InterfaceBlockEntity: DeviceBlockEntity(PhyBlockEntities.INTERFACE),
|
||||||
ItemStackPacketHandler,
|
ItemStackPacketHandler,
|
||||||
NetworkStackProvider,
|
NetworkStackProvider,
|
||||||
NetworkStackReceiver,
|
NetworkStackReceiver,
|
||||||
|
@ -64,11 +63,8 @@ class InterfaceBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockEntity(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleRequestInventory(packet: RequestInventoryPacket) {
|
private fun handleRequestInventory(packet: RequestInventoryPacket) {
|
||||||
if (packet.kind != RequestInventoryPacket.Kind.GROUPED) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
getInventory()?.also { inv ->
|
getInventory()?.also { inv ->
|
||||||
sendPacket(ReadGroupedInventoryPacket(inv, ipAddress, packet.source))
|
sendPacket(ReadInventoryPacket(inv, ipAddress, packet.source))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,23 +109,23 @@ class InterfaceBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockEntity(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toCommonTag(tag: NbtCompound) {
|
override fun toCommonTag(tag: CompoundTag) {
|
||||||
super.toCommonTag(tag)
|
super.toCommonTag(tag)
|
||||||
writeDeviceConfiguration(tag)
|
writeDeviceConfiguration(tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fromCommonTag(tag: NbtCompound) {
|
override fun fromCommonTag(tag: CompoundTag) {
|
||||||
super.fromCommonTag(tag)
|
super.fromCommonTag(tag)
|
||||||
loadDeviceConfiguration(tag)
|
loadDeviceConfiguration(tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun writeDeviceConfiguration(tag: NbtCompound) {
|
override fun writeDeviceConfiguration(tag: CompoundTag) {
|
||||||
tag.putInt("ProviderPriority", providerPriority)
|
tag.putInt("ProviderPriority", providerPriority)
|
||||||
tag.putInt("ReceiverPriority", receiverPriority)
|
tag.putInt("ReceiverPriority", receiverPriority)
|
||||||
tag.putBoolean("SyncPriorities", syncPriorities)
|
tag.putBoolean("SyncPriorities", syncPriorities)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun loadDeviceConfiguration(tag: NbtCompound) {
|
override fun loadDeviceConfiguration(tag: CompoundTag) {
|
||||||
providerPriority = tag.getInt("ProviderPriority")
|
providerPriority = tag.getInt("ProviderPriority")
|
||||||
receiverPriority = tag.getInt("ReceiverPriority")
|
receiverPriority = tag.getInt("ReceiverPriority")
|
||||||
syncPriorities = tag.getBoolean("SyncPriorities")
|
syncPriorities = tag.getBoolean("SyncPriorities")
|
||||||
|
|
|
@ -4,9 +4,6 @@ import alexiil.mc.lib.attributes.AttributeList
|
||||||
import alexiil.mc.lib.attributes.AttributeProvider
|
import alexiil.mc.lib.attributes.AttributeProvider
|
||||||
import net.minecraft.block.BlockState
|
import net.minecraft.block.BlockState
|
||||||
import net.minecraft.block.Material
|
import net.minecraft.block.Material
|
||||||
import net.minecraft.block.entity.BlockEntity
|
|
||||||
import net.minecraft.block.entity.BlockEntityTicker
|
|
||||||
import net.minecraft.block.entity.BlockEntityType
|
|
||||||
import net.minecraft.sound.BlockSoundGroup
|
import net.minecraft.sound.BlockSoundGroup
|
||||||
import net.minecraft.util.Identifier
|
import net.minecraft.util.Identifier
|
||||||
import net.minecraft.util.math.BlockPos
|
import net.minecraft.util.math.BlockPos
|
||||||
|
@ -43,17 +40,7 @@ class SwitchBlock: BlockWithEntity<SwitchBlockEntity>(
|
||||||
return getBlockEntity(world, pos)?.interfaces?.find { it.side == side }
|
return getBlockEntity(world, pos)?.interfaces?.find { it.side == side }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createBlockEntity(pos: BlockPos, state: BlockState) = SwitchBlockEntity(pos, state)
|
override fun createBlockEntity(world: BlockView) = SwitchBlockEntity()
|
||||||
|
|
||||||
override fun <T: BlockEntity> getTicker(world: World, state: BlockState, type: BlockEntityType<T>): BlockEntityTicker<T>? {
|
|
||||||
return if (world.isClient) {
|
|
||||||
null
|
|
||||||
} else {
|
|
||||||
BlockEntityTicker { world, blockPos, blockState, blockEntity ->
|
|
||||||
(blockEntity as SwitchBlockEntity).tick()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun addAllAttributes(world: World, pos: BlockPos, state: BlockState, to: AttributeList<*>) {
|
override fun addAllAttributes(world: World, pos: BlockPos, state: BlockState, to: AttributeList<*>) {
|
||||||
to.offer(getBlockEntity(world, pos))
|
to.offer(getBlockEntity(world, pos))
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
package net.shadowfacts.phycon.block.netswitch
|
package net.shadowfacts.phycon.block.netswitch
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable
|
||||||
import net.minecraft.block.BlockState
|
import net.minecraft.block.BlockState
|
||||||
import net.minecraft.block.entity.BlockEntity
|
import net.minecraft.block.entity.BlockEntity
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.nbt.NbtCompound
|
import net.minecraft.nbt.CompoundTag
|
||||||
import net.minecraft.nbt.NbtList
|
import net.minecraft.nbt.ListTag
|
||||||
import net.minecraft.network.Packet
|
import net.minecraft.util.Tickable
|
||||||
import net.minecraft.network.listener.ClientPlayPacketListener
|
|
||||||
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket
|
|
||||||
import net.minecraft.util.math.BlockPos
|
|
||||||
import net.minecraft.util.math.Direction
|
import net.minecraft.util.math.Direction
|
||||||
import net.shadowfacts.phycon.PhysicalConnectivity
|
import net.shadowfacts.phycon.PhysicalConnectivity
|
||||||
import net.shadowfacts.phycon.api.Interface
|
import net.shadowfacts.phycon.api.Interface
|
||||||
|
@ -27,7 +25,9 @@ import java.util.LinkedList
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
class SwitchBlockEntity(pos: BlockPos, state: BlockState): BlockEntity(PhyBlockEntities.SWITCH, pos, state) {
|
class SwitchBlockEntity: BlockEntity(PhyBlockEntities.SWITCH),
|
||||||
|
BlockEntityClientSerializable,
|
||||||
|
Tickable {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
var SWITCHING_CAPACITY = 256 // 256 packets/tick
|
var SWITCHING_CAPACITY = 256 // 256 packets/tick
|
||||||
|
@ -82,7 +82,7 @@ class SwitchBlockEntity(pos: BlockPos, state: BlockState): BlockEntity(PhyBlockE
|
||||||
return NetworkUtil.findConnectedInterface(world!!, pos, side)
|
return NetworkUtil.findConnectedInterface(world!!, pos, side)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun tick() {
|
override fun tick() {
|
||||||
packetsHandledThisTick = 0
|
packetsHandledThisTick = 0
|
||||||
|
|
||||||
while (delayedPackets.isNotEmpty() && packetsHandledThisTick <= SWITCHING_CAPACITY) {
|
while (delayedPackets.isNotEmpty() && packetsHandledThisTick <= SWITCHING_CAPACITY) {
|
||||||
|
@ -91,41 +91,39 @@ class SwitchBlockEntity(pos: BlockPos, state: BlockState): BlockEntity(PhyBlockE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun writeNbt(tag: NbtCompound) {
|
override fun toTag(tag: CompoundTag): CompoundTag {
|
||||||
super.writeNbt(tag)
|
|
||||||
|
|
||||||
tag.putLongArray("InterfaceAddresses", interfaces.map { it.macAddress.address })
|
tag.putLongArray("InterfaceAddresses", interfaces.map { it.macAddress.address })
|
||||||
val list = NbtList()
|
val list = ListTag()
|
||||||
for ((frame, fromItf) in delayedPackets) {
|
for ((frame, fromItf) in delayedPackets) {
|
||||||
val packet = frame.packet
|
val packet = frame.packet
|
||||||
if (packet !is ItemStackPacket) continue
|
if (packet !is ItemStackPacket) continue
|
||||||
val compound = NbtCompound()
|
val compound = CompoundTag()
|
||||||
compound.putInt("FromItfSide", fromItf.side.ordinal)
|
compound.putInt("FromItfSide", fromItf.side.ordinal)
|
||||||
compound.putInt("SourceIP", packet.source.address)
|
compound.putInt("SourceIP", packet.source.address)
|
||||||
compound.putInt("DestinationIP", packet.destination.address)
|
compound.putInt("DestinationIP", packet.destination.address)
|
||||||
compound.putLong("SourceMAC", frame.source.address)
|
compound.putLong("SourceMAC", frame.source.address)
|
||||||
compound.putLong("DestinationMAC", frame.destination.address)
|
compound.putLong("DestinationMAC", frame.destination.address)
|
||||||
compound.put("Stack", packet.stack.writeNbt(NbtCompound()))
|
compound.put("Stack", packet.stack.toTag(CompoundTag()))
|
||||||
list.add(compound)
|
list.add(compound)
|
||||||
}
|
}
|
||||||
tag.put("DelayedStackPackets", list)
|
tag.put("DelayedStackPackets", list)
|
||||||
|
return super.toTag(tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun readNbt(tag: NbtCompound) {
|
override fun fromTag(state: BlockState, tag: CompoundTag) {
|
||||||
super.readNbt(tag)
|
super.fromTag(state, tag)
|
||||||
|
|
||||||
tag.getLongArray("InterfaceAddresses")?.forEachIndexed { i, l ->
|
tag.getLongArray("InterfaceAddresses")?.forEachIndexed { i, l ->
|
||||||
interfaces[i].macAddress = MACAddress(l)
|
interfaces[i].macAddress = MACAddress(l)
|
||||||
}
|
}
|
||||||
tag.getList("DelayedStackPackets", 10).forEach { it ->
|
tag.getList("DelayedStackPackets", 10).forEach { it ->
|
||||||
val compound = it as NbtCompound
|
val compound = it as CompoundTag
|
||||||
val fromItfSide = Direction.values()[compound.getInt("FromItfSide")]
|
val fromItfSide = Direction.values()[compound.getInt("FromItfSide")]
|
||||||
val fromItf = interfaces.find { it.side == fromItfSide }!!
|
val fromItf = interfaces.find { it.side == fromItfSide }!!
|
||||||
val sourceIP = IPAddress(compound.getInt("SourceIP"))
|
val sourceIP = IPAddress(compound.getInt("SourceIP"))
|
||||||
val destinationIP = IPAddress(compound.getInt("DestinationIP"))
|
val destinationIP = IPAddress(compound.getInt("DestinationIP"))
|
||||||
val sourceMAC = MACAddress(compound.getLong("SourceMAC"))
|
val sourceMAC = MACAddress(compound.getLong("SourceMAC"))
|
||||||
val destinationMAC = MACAddress(compound.getLong("DestinationMAC"))
|
val destinationMAC = MACAddress(compound.getLong("DestinationMAC"))
|
||||||
val stack = ItemStack.fromNbt(compound.getCompound("Stack"))
|
val stack = ItemStack.fromTag(compound.getCompound("Stack"))
|
||||||
if (!stack.isEmpty) {
|
if (!stack.isEmpty) {
|
||||||
val packet = ItemStackPacket(stack, sourceIP, destinationIP)
|
val packet = ItemStackPacket(stack, sourceIP, destinationIP)
|
||||||
val frame = BasePacketFrame(packet, sourceMAC, destinationMAC)
|
val frame = BasePacketFrame(packet, sourceMAC, destinationMAC)
|
||||||
|
@ -134,16 +132,17 @@ class SwitchBlockEntity(pos: BlockPos, state: BlockState): BlockEntity(PhyBlockE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toUpdatePacket(): Packet<ClientPlayPacketListener>? {
|
override fun toClientTag(tag: CompoundTag): CompoundTag {
|
||||||
return BlockEntityUpdateS2CPacket.create(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toInitialChunkDataNbt(): NbtCompound {
|
|
||||||
val tag = NbtCompound()
|
|
||||||
tag.putLongArray("InterfaceAddresses", interfaces.map { it.macAddress.address })
|
tag.putLongArray("InterfaceAddresses", interfaces.map { it.macAddress.address })
|
||||||
return tag
|
return tag
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun fromClientTag(tag: CompoundTag) {
|
||||||
|
tag.getLongArray("InterfaceAddresses")?.forEachIndexed { i, l ->
|
||||||
|
interfaces[i].macAddress = MACAddress(l)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class SwitchInterface(
|
class SwitchInterface(
|
||||||
val side: Direction,
|
val side: Direction,
|
||||||
val switch: WeakReference<SwitchBlockEntity>,
|
val switch: WeakReference<SwitchBlockEntity>,
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
package net.shadowfacts.phycon.block.p2p
|
|
||||||
|
|
||||||
import net.minecraft.block.BlockState
|
|
||||||
import net.minecraft.block.Material
|
|
||||||
import net.minecraft.sound.BlockSoundGroup
|
|
||||||
import net.minecraft.util.Identifier
|
|
||||||
import net.minecraft.util.math.BlockPos
|
|
||||||
import net.minecraft.util.math.Direction
|
|
||||||
import net.shadowfacts.phycon.PhysicalConnectivity
|
|
||||||
import net.shadowfacts.phycon.block.FaceDeviceBlock
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author shadowfacts
|
|
||||||
*/
|
|
||||||
class P2PInterfaceBlock: FaceDeviceBlock<P2PInterfaceBlockEntity>(
|
|
||||||
Settings.of(Material.METAL)
|
|
||||||
.strength(1.5f)
|
|
||||||
.sounds(BlockSoundGroup.METAL)
|
|
||||||
) {
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
val ID = Identifier(PhysicalConnectivity.MODID, "p2p_interface")
|
|
||||||
}
|
|
||||||
|
|
||||||
override val faceThickness = 4.0
|
|
||||||
override val faceShapes = mapOf(
|
|
||||||
Direction.DOWN to createCuboidShape(0.0, 0.0, 0.0, 16.0, 4.0, 16.0),
|
|
||||||
Direction.UP to createCuboidShape(0.0, 12.0, 0.0, 16.0, 16.0, 16.0),
|
|
||||||
Direction.NORTH to createCuboidShape(0.0, 0.0, 0.0, 16.0, 16.0, 4.0),
|
|
||||||
Direction.SOUTH to createCuboidShape(0.0, 0.0, 12.0, 16.0, 16.0, 16.0),
|
|
||||||
Direction.WEST to createCuboidShape(0.0, 0.0, 0.0, 4.0, 16.0, 16.0),
|
|
||||||
Direction.EAST to createCuboidShape(12.0, 0.0, 0.0, 16.0, 16.0, 16.0)
|
|
||||||
)
|
|
||||||
|
|
||||||
override fun createBlockEntity(pos: BlockPos, state: BlockState) = P2PInterfaceBlockEntity(pos, state)
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,47 +0,0 @@
|
||||||
package net.shadowfacts.phycon.block.p2p
|
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage
|
|
||||||
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant
|
|
||||||
import net.fabricmc.fabric.api.transfer.v1.storage.Storage
|
|
||||||
import net.minecraft.block.BlockState
|
|
||||||
import net.minecraft.util.math.BlockPos
|
|
||||||
import net.shadowfacts.phycon.api.packet.Packet
|
|
||||||
import net.shadowfacts.phycon.block.DeviceBlockEntity
|
|
||||||
import net.shadowfacts.phycon.block.FaceDeviceBlock
|
|
||||||
import net.shadowfacts.phycon.init.PhyBlockEntities
|
|
||||||
import net.shadowfacts.phycon.packet.ReadItemStoragePacket
|
|
||||||
import net.shadowfacts.phycon.packet.RequestInventoryPacket
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author shadowfacts
|
|
||||||
*/
|
|
||||||
class P2PInterfaceBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockEntity(PhyBlockEntities.P2P_INTERFACE, pos, state) {
|
|
||||||
|
|
||||||
private var inventory: Storage<ItemVariant>? = null
|
|
||||||
|
|
||||||
private fun updateInventory() {
|
|
||||||
val facing = cachedState[FaceDeviceBlock.FACING]
|
|
||||||
inventory = ItemStorage.SIDED.find(world!!, pos.offset(facing), facing.opposite)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getInventory(): Storage<ItemVariant>? {
|
|
||||||
if (inventory == null) updateInventory()
|
|
||||||
return inventory
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun handle(packet: Packet) {
|
|
||||||
when (packet) {
|
|
||||||
is RequestInventoryPacket -> handleRequestInventory(packet)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun handleRequestInventory(packet: RequestInventoryPacket) {
|
|
||||||
if (packet.kind != RequestInventoryPacket.Kind.SIDED) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
getInventory()?.also {
|
|
||||||
sendPacket(ReadItemStoragePacket(it, ipAddress, packet.source))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
package net.shadowfacts.phycon.block.p2p
|
|
||||||
|
|
||||||
import net.minecraft.block.BlockState
|
|
||||||
import net.minecraft.block.InventoryProvider
|
|
||||||
import net.minecraft.block.Material
|
|
||||||
import net.minecraft.inventory.SidedInventory
|
|
||||||
import net.minecraft.sound.BlockSoundGroup
|
|
||||||
import net.minecraft.util.Identifier
|
|
||||||
import net.minecraft.util.math.BlockPos
|
|
||||||
import net.minecraft.util.math.Direction
|
|
||||||
import net.minecraft.util.shape.VoxelShape
|
|
||||||
import net.minecraft.world.WorldAccess
|
|
||||||
import net.shadowfacts.phycon.PhysicalConnectivity
|
|
||||||
import net.shadowfacts.phycon.block.FaceDeviceBlock
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author shadowfacts
|
|
||||||
*/
|
|
||||||
class P2PReceiverBlock: FaceDeviceBlock<P2PReceiverBlockEntity>(
|
|
||||||
Settings.of(Material.METAL)
|
|
||||||
.strength(1.5f)
|
|
||||||
.sounds(BlockSoundGroup.METAL)
|
|
||||||
) {
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
val ID = Identifier(PhysicalConnectivity.MODID, "p2p_receiver")
|
|
||||||
}
|
|
||||||
|
|
||||||
override val faceThickness = 4.0
|
|
||||||
override val faceShapes = mapOf(
|
|
||||||
Direction.DOWN to createCuboidShape(0.0, 0.0, 0.0, 16.0, 4.0, 16.0),
|
|
||||||
Direction.UP to createCuboidShape(0.0, 12.0, 0.0, 16.0, 16.0, 16.0),
|
|
||||||
Direction.NORTH to createCuboidShape(0.0, 0.0, 0.0, 16.0, 16.0, 4.0),
|
|
||||||
Direction.SOUTH to createCuboidShape(0.0, 0.0, 12.0, 16.0, 16.0, 16.0),
|
|
||||||
Direction.WEST to createCuboidShape(0.0, 0.0, 0.0, 4.0, 16.0, 16.0),
|
|
||||||
Direction.EAST to createCuboidShape(12.0, 0.0, 0.0, 16.0, 16.0, 16.0)
|
|
||||||
)
|
|
||||||
|
|
||||||
override fun createBlockEntity(pos: BlockPos, state: BlockState) = P2PReceiverBlockEntity(pos, state)
|
|
||||||
}
|
|
|
@ -1,133 +0,0 @@
|
||||||
package net.shadowfacts.phycon.block.p2p
|
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant
|
|
||||||
import net.fabricmc.fabric.api.transfer.v1.storage.Storage
|
|
||||||
import net.minecraft.block.BlockState
|
|
||||||
import net.minecraft.nbt.NbtCompound
|
|
||||||
import net.minecraft.text.Text
|
|
||||||
import net.minecraft.text.TranslatableText
|
|
||||||
import net.minecraft.util.math.BlockPos
|
|
||||||
import net.minecraft.util.math.Direction
|
|
||||||
import net.shadowfacts.phycon.api.packet.Packet
|
|
||||||
import net.shadowfacts.phycon.api.util.IPAddress
|
|
||||||
import net.shadowfacts.phycon.block.DeviceBlockEntity
|
|
||||||
import net.shadowfacts.phycon.block.FaceDeviceBlock
|
|
||||||
import net.shadowfacts.phycon.init.PhyBlockEntities
|
|
||||||
import net.shadowfacts.phycon.packet.*
|
|
||||||
import net.shadowfacts.phycon.util.ClientConfigurableDevice
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author shadowfacts
|
|
||||||
*/
|
|
||||||
class P2PReceiverBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockEntity(PhyBlockEntities.P2P_RECEIVER, pos, state),
|
|
||||||
ClientConfigurableDevice {
|
|
||||||
|
|
||||||
enum class Status {
|
|
||||||
OK,
|
|
||||||
NO_TARGET,
|
|
||||||
WAITING_FOR_RESPONSE;
|
|
||||||
|
|
||||||
val displayName: Text
|
|
||||||
get() = when (this) {
|
|
||||||
OK -> TranslatableText("gui.phycon.p2p_receiver.status.ok")
|
|
||||||
NO_TARGET -> TranslatableText("gui.phycon.p2p_receiver.status.no_target")
|
|
||||||
WAITING_FOR_RESPONSE -> TranslatableText("gui.phycon.p2p_receiver.status.waiting_for_response")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun provideItemStorage(be: P2PReceiverBlockEntity, side: Direction): Storage<ItemVariant>? {
|
|
||||||
if (side == be.cachedState[FaceDeviceBlock.FACING]) {
|
|
||||||
return be.getTargetInventory()
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var target: IPAddress? = null
|
|
||||||
var status = Status.NO_TARGET
|
|
||||||
|
|
||||||
var clientObserver: (() -> Unit)? = null
|
|
||||||
|
|
||||||
private var isFirstTick = true
|
|
||||||
// todo: need some way of removing this when there's no network path to the p2p interface
|
|
||||||
private var targetInventory: Storage<ItemVariant>? = null
|
|
||||||
|
|
||||||
override fun handle(packet: Packet) {
|
|
||||||
when (packet) {
|
|
||||||
is PongPacket -> if (packet.source == target) status = Status.OK
|
|
||||||
is ReadItemStoragePacket -> targetInventory = packet.inventory
|
|
||||||
is DeviceRemovedPacket -> if (packet.source == target) targetInventory = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun tick() {
|
|
||||||
super.tick()
|
|
||||||
|
|
||||||
if (isFirstTick) {
|
|
||||||
isFirstTick = false
|
|
||||||
updateStatus()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getTargetInventory(): Storage<ItemVariant>? {
|
|
||||||
if (target == null) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
if (targetInventory == null) {
|
|
||||||
sendPacket(RequestInventoryPacket(RequestInventoryPacket.Kind.SIDED, ipAddress, target!!))
|
|
||||||
}
|
|
||||||
return targetInventory
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateStatus() {
|
|
||||||
if (world?.isClient != false) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
assert(!world!!.isClient)
|
|
||||||
if (target == null) {
|
|
||||||
status = Status.NO_TARGET
|
|
||||||
} else {
|
|
||||||
status = Status.WAITING_FOR_RESPONSE
|
|
||||||
sendPacket(PingPacket(ipAddress, target!!))
|
|
||||||
}
|
|
||||||
|
|
||||||
markUpdate()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toCommonTag(tag: NbtCompound) {
|
|
||||||
super.toCommonTag(tag)
|
|
||||||
writeDeviceConfiguration(tag)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun fromCommonTag(tag: NbtCompound) {
|
|
||||||
super.fromCommonTag(tag)
|
|
||||||
loadDeviceConfiguration(tag)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toClientTag(tag: NbtCompound): NbtCompound {
|
|
||||||
tag.putInt("Status", status.ordinal)
|
|
||||||
return super.toClientTag(tag)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun fromClientTag(tag: NbtCompound) {
|
|
||||||
super.fromClientTag(tag)
|
|
||||||
status = Status.values()[tag.getInt("Status")]
|
|
||||||
clientObserver?.invoke()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun writeDeviceConfiguration(tag: NbtCompound) {
|
|
||||||
target?.address?.let { tag.putInt("Target", it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun loadDeviceConfiguration(tag: NbtCompound) {
|
|
||||||
target = if (tag.contains("Target")) {
|
|
||||||
IPAddress(tag.getInt("Target"))
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
|
|
||||||
updateStatus()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -44,7 +44,7 @@ class RedstoneControllerBlock: FaceDeviceBlock<RedstoneControllerBlockEntity>(
|
||||||
builder.add(POWERED)
|
builder.add(POWERED)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createBlockEntity(pos: BlockPos, state: BlockState) = RedstoneControllerBlockEntity(pos, state)
|
override fun createBlockEntity(world: BlockView) = RedstoneControllerBlockEntity()
|
||||||
|
|
||||||
override fun getPlacementState(context: ItemPlacementContext): BlockState {
|
override fun getPlacementState(context: ItemPlacementContext): BlockState {
|
||||||
val state = super.getPlacementState(context)
|
val state = super.getPlacementState(context)
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package net.shadowfacts.phycon.block.redstone_controller
|
package net.shadowfacts.phycon.block.redstone_controller
|
||||||
|
|
||||||
import net.minecraft.block.BlockState
|
import net.minecraft.nbt.CompoundTag
|
||||||
import net.minecraft.nbt.NbtCompound
|
|
||||||
import net.minecraft.util.math.BlockPos
|
|
||||||
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.init.PhyBlockEntities
|
import net.shadowfacts.phycon.init.PhyBlockEntities
|
||||||
|
@ -14,7 +12,7 @@ import net.shadowfacts.phycon.util.RedstoneMode
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
class RedstoneControllerBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockEntity(PhyBlockEntities.REDSTONE_CONTROLLER, pos, state),
|
class RedstoneControllerBlockEntity: DeviceBlockEntity(PhyBlockEntities.REDSTONE_CONTROLLER),
|
||||||
ClientConfigurableDevice {
|
ClientConfigurableDevice {
|
||||||
|
|
||||||
var managedDevices = Array<IPAddress?>(5) { null }
|
var managedDevices = Array<IPAddress?>(5) { null }
|
||||||
|
@ -55,22 +53,22 @@ class RedstoneControllerBlockEntity(pos: BlockPos, state: BlockState): DeviceBlo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toCommonTag(tag: NbtCompound) {
|
override fun toCommonTag(tag: CompoundTag) {
|
||||||
super.toCommonTag(tag)
|
super.toCommonTag(tag)
|
||||||
writeDeviceConfiguration(tag)
|
writeDeviceConfiguration(tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fromCommonTag(tag: NbtCompound) {
|
override fun fromCommonTag(tag: CompoundTag) {
|
||||||
super.fromCommonTag(tag)
|
super.fromCommonTag(tag)
|
||||||
loadDeviceConfiguration(tag)
|
loadDeviceConfiguration(tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun writeDeviceConfiguration(tag: NbtCompound) {
|
override fun writeDeviceConfiguration(tag: CompoundTag) {
|
||||||
tag.putIntArray("ManagedDevices", managedDevices.mapNotNull { it?.address })
|
tag.putIntArray("ManagedDevices", managedDevices.mapNotNull { it?.address })
|
||||||
tag.putString("RedstoneMode", redstoneMode.name)
|
tag.putString("RedstoneMode", redstoneMode.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun loadDeviceConfiguration(tag: NbtCompound) {
|
override fun loadDeviceConfiguration(tag: CompoundTag) {
|
||||||
val addresses = tag.getIntArray("ManagedDevices")
|
val addresses = tag.getIntArray("ManagedDevices")
|
||||||
managedDevices = (0..4).map { if (it >= addresses.size) null else IPAddress(addresses[it]) }.toTypedArray()
|
managedDevices = (0..4).map { if (it >= addresses.size) null else IPAddress(addresses[it]) }.toTypedArray()
|
||||||
redstoneMode = RedstoneMode.valueOf(tag.getString("RedstoneMode"))
|
redstoneMode = RedstoneMode.valueOf(tag.getString("RedstoneMode"))
|
||||||
|
|
|
@ -45,7 +45,7 @@ class RedstoneEmitterBlock: FaceDeviceBlock<RedstoneEmitterBlockEntity>(
|
||||||
Direction.EAST to createCuboidShape(13.0, 0.0, 0.0, 16.0, 16.0, 16.0)
|
Direction.EAST to createCuboidShape(13.0, 0.0, 0.0, 16.0, 16.0, 16.0)
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun createBlockEntity(pos: BlockPos, state: BlockState) = RedstoneEmitterBlockEntity(pos, state)
|
override fun createBlockEntity(world: BlockView) = RedstoneEmitterBlockEntity()
|
||||||
|
|
||||||
override fun emitsRedstonePower(state: BlockState): Boolean {
|
override fun emitsRedstonePower(state: BlockState): Boolean {
|
||||||
return true
|
return true
|
||||||
|
@ -67,7 +67,7 @@ class RedstoneEmitterBlock: FaceDeviceBlock<RedstoneEmitterBlockEntity>(
|
||||||
if (!world.isClient) {
|
if (!world.isClient) {
|
||||||
val be = getBlockEntity(world, pos)!!
|
val be = getBlockEntity(world, pos)!!
|
||||||
|
|
||||||
be.markUpdate()
|
be.sync()
|
||||||
|
|
||||||
val factory = object: ExtendedScreenHandlerFactory {
|
val factory = object: ExtendedScreenHandlerFactory {
|
||||||
override fun createMenu(syncId: Int, playerInv: PlayerInventory, player: PlayerEntity): ScreenHandler {
|
override fun createMenu(syncId: Int, playerInv: PlayerInventory, player: PlayerEntity): ScreenHandler {
|
||||||
|
|
|
@ -1,18 +1,16 @@
|
||||||
package net.shadowfacts.phycon.block.redstone_emitter
|
package net.shadowfacts.phycon.block.redstone_emitter
|
||||||
|
|
||||||
import alexiil.mc.lib.attributes.item.GroupedItemInvView
|
import alexiil.mc.lib.attributes.item.GroupedItemInvView
|
||||||
import net.minecraft.block.BlockState
|
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.nbt.NbtCompound
|
import net.minecraft.nbt.CompoundTag
|
||||||
import net.minecraft.text.TranslatableText
|
import net.minecraft.text.TranslatableText
|
||||||
import net.minecraft.util.math.BlockPos
|
|
||||||
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
|
||||||
import net.shadowfacts.phycon.block.FaceDeviceBlock
|
import net.shadowfacts.phycon.block.FaceDeviceBlock
|
||||||
import net.shadowfacts.phycon.init.PhyBlockEntities
|
import net.shadowfacts.phycon.init.PhyBlockEntities
|
||||||
import net.shadowfacts.phycon.packet.DeviceRemovedPacket
|
import net.shadowfacts.phycon.packet.DeviceRemovedPacket
|
||||||
import net.shadowfacts.phycon.packet.ReadGroupedInventoryPacket
|
import net.shadowfacts.phycon.packet.ReadInventoryPacket
|
||||||
import net.shadowfacts.phycon.packet.RequestInventoryPacket
|
import net.shadowfacts.phycon.packet.RequestInventoryPacket
|
||||||
import net.shadowfacts.phycon.util.ClientConfigurableDevice
|
import net.shadowfacts.phycon.util.ClientConfigurableDevice
|
||||||
import net.shadowfacts.phycon.util.GhostInv
|
import net.shadowfacts.phycon.util.GhostInv
|
||||||
|
@ -21,7 +19,7 @@ import kotlin.math.round
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
class RedstoneEmitterBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockEntity(PhyBlockEntities.REDSTONE_EMITTER, pos, state),
|
class RedstoneEmitterBlockEntity: DeviceBlockEntity(PhyBlockEntities.REDSTONE_EMITTER),
|
||||||
ClientConfigurableDevice,
|
ClientConfigurableDevice,
|
||||||
GhostInv {
|
GhostInv {
|
||||||
|
|
||||||
|
@ -42,12 +40,12 @@ class RedstoneEmitterBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockE
|
||||||
|
|
||||||
override fun handle(packet: Packet) {
|
override fun handle(packet: Packet) {
|
||||||
when (packet) {
|
when (packet) {
|
||||||
is ReadGroupedInventoryPacket -> handleReadInventory(packet)
|
is ReadInventoryPacket -> handleReadInventory(packet)
|
||||||
is DeviceRemovedPacket -> handleDeviceRemoved(packet)
|
is DeviceRemovedPacket -> handleDeviceRemoved(packet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleReadInventory(packet: ReadGroupedInventoryPacket) {
|
private fun handleReadInventory(packet: ReadInventoryPacket) {
|
||||||
inventoryCache[packet.source] = packet.inventory
|
inventoryCache[packet.source] = packet.inventory
|
||||||
recalculateRedstone()
|
recalculateRedstone()
|
||||||
}
|
}
|
||||||
|
@ -70,7 +68,7 @@ class RedstoneEmitterBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockE
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateInventories() {
|
private fun updateInventories() {
|
||||||
sendPacket(RequestInventoryPacket(RequestInventoryPacket.Kind.GROUPED, ipAddress))
|
sendPacket(RequestInventoryPacket(ipAddress))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun recalculateRedstone() {
|
private fun recalculateRedstone() {
|
||||||
|
@ -102,26 +100,26 @@ class RedstoneEmitterBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockE
|
||||||
world!!.updateNeighborsAlways(pos.offset(cachedState[FaceDeviceBlock.FACING]), cachedState.block)
|
world!!.updateNeighborsAlways(pos.offset(cachedState[FaceDeviceBlock.FACING]), cachedState.block)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toCommonTag(tag: NbtCompound) {
|
override fun toCommonTag(tag: CompoundTag) {
|
||||||
super.toCommonTag(tag)
|
super.toCommonTag(tag)
|
||||||
tag.putInt("CachedEmittedPower", cachedEmittedPower)
|
tag.putInt("CachedEmittedPower", cachedEmittedPower)
|
||||||
tag.put("StackToMonitor", stackToMonitor.writeNbt(NbtCompound()))
|
tag.put("StackToMonitor", stackToMonitor.toTag(CompoundTag()))
|
||||||
writeDeviceConfiguration(tag)
|
writeDeviceConfiguration(tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fromCommonTag(tag: NbtCompound) {
|
override fun fromCommonTag(tag: CompoundTag) {
|
||||||
super.fromCommonTag(tag)
|
super.fromCommonTag(tag)
|
||||||
cachedEmittedPower = tag.getInt("CachedEmittedPower")
|
cachedEmittedPower = tag.getInt("CachedEmittedPower")
|
||||||
stackToMonitor = ItemStack.fromNbt(tag.getCompound("StackToMonitor"))
|
stackToMonitor = ItemStack.fromTag(tag.getCompound("StackToMonitor"))
|
||||||
loadDeviceConfiguration(tag)
|
loadDeviceConfiguration(tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun writeDeviceConfiguration(tag: NbtCompound) {
|
override fun writeDeviceConfiguration(tag: CompoundTag) {
|
||||||
tag.putInt("MaxAmount", maxAmount)
|
tag.putInt("MaxAmount", maxAmount)
|
||||||
tag.putString("Mode", mode.name)
|
tag.putString("Mode", mode.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun loadDeviceConfiguration(tag: NbtCompound) {
|
override fun loadDeviceConfiguration(tag: CompoundTag) {
|
||||||
maxAmount = tag.getInt("MaxAmount")
|
maxAmount = tag.getInt("MaxAmount")
|
||||||
mode = Mode.valueOf(tag.getString("Mode"))
|
mode = Mode.valueOf(tag.getString("Mode"))
|
||||||
}
|
}
|
||||||
|
@ -129,7 +127,7 @@ class RedstoneEmitterBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockE
|
||||||
enum class Mode {
|
enum class Mode {
|
||||||
ANALOG, DIGITAL;
|
ANALOG, DIGITAL;
|
||||||
|
|
||||||
val friendlyName = TranslatableText("gui.phycon.redstone_emitter_mode.${name.lowercase()}")
|
val friendlyName = TranslatableText("gui.phycon.redstone_emitter_mode.${name.toLowerCase()}")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package net.shadowfacts.phycon.block.redstone_emitter
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem
|
import com.mojang.blaze3d.systems.RenderSystem
|
||||||
import net.minecraft.client.MinecraftClient
|
import net.minecraft.client.MinecraftClient
|
||||||
import net.minecraft.client.render.GameRenderer
|
|
||||||
import net.minecraft.client.util.math.MatrixStack
|
import net.minecraft.client.util.math.MatrixStack
|
||||||
import net.minecraft.entity.player.PlayerInventory
|
import net.minecraft.entity.player.PlayerInventory
|
||||||
import net.minecraft.text.Text
|
import net.minecraft.text.Text
|
||||||
|
@ -50,8 +49,8 @@ class RedstoneEmitterScreen(
|
||||||
override fun drawBackground(matrixStack: MatrixStack, delta: Float, mouseX: Int, mouseY: Int) {
|
override fun drawBackground(matrixStack: MatrixStack, delta: Float, mouseX: Int, mouseY: Int) {
|
||||||
super.drawBackground(matrixStack, delta, mouseX, mouseY)
|
super.drawBackground(matrixStack, delta, mouseX, mouseY)
|
||||||
|
|
||||||
RenderSystem.setShader(GameRenderer::getPositionTexShader)
|
RenderSystem.color4f(1f, 1f, 1f, 1f)
|
||||||
RenderSystem.setShaderTexture(0, BACKGROUND)
|
client!!.textureManager.bindTexture(BACKGROUND)
|
||||||
val x = (width - backgroundWidth) / 2
|
val x = (width - backgroundWidth) / 2
|
||||||
val y = (height - backgroundHeight) / 2
|
val y = (height - backgroundHeight) / 2
|
||||||
drawTexture(matrixStack, x, y, 0, 0, backgroundWidth, backgroundHeight)
|
drawTexture(matrixStack, x, y, 0, 0, backgroundWidth, backgroundHeight)
|
||||||
|
|
|
@ -55,16 +55,16 @@ class RedstoneEmitterScreenHandler(
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSlotClick(slotId: Int, clickData: Int, slotActionType: SlotActionType, player: PlayerEntity) {
|
override fun onSlotClick(slotId: Int, clickData: Int, slotActionType: SlotActionType, player: PlayerEntity): ItemStack {
|
||||||
// fake slot
|
// fake slot
|
||||||
if (slotId == 0) {
|
if (slotId == 0) {
|
||||||
if (cursorStack.isEmpty) {
|
if (player.inventory.cursorStack.isEmpty) {
|
||||||
emitter.stackToMonitor = ItemStack.EMPTY
|
emitter.stackToMonitor = ItemStack.EMPTY
|
||||||
} else {
|
} else {
|
||||||
emitter.stackToMonitor = cursorStack.copyWithCount(1)
|
emitter.stackToMonitor = player.inventory.cursorStack.copyWithCount(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
super.onSlotClick(slotId, clickData, slotActionType, player)
|
return super.onSlotClick(slotId, clickData, slotActionType, player)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun transferSlot(player: PlayerEntity, slotId: Int): ItemStack {
|
override fun transferSlot(player: PlayerEntity, slotId: Int): ItemStack {
|
||||||
|
|
|
@ -3,34 +3,42 @@ package net.shadowfacts.phycon.block.terminal
|
||||||
import alexiil.mc.lib.attributes.item.GroupedItemInvView
|
import alexiil.mc.lib.attributes.item.GroupedItemInvView
|
||||||
import alexiil.mc.lib.attributes.item.ItemStackCollections
|
import alexiil.mc.lib.attributes.item.ItemStackCollections
|
||||||
import alexiil.mc.lib.attributes.item.ItemStackUtil
|
import alexiil.mc.lib.attributes.item.ItemStackUtil
|
||||||
import net.minecraft.block.BlockState
|
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable
|
||||||
|
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory
|
||||||
import net.minecraft.block.entity.BlockEntityType
|
import net.minecraft.block.entity.BlockEntityType
|
||||||
import net.minecraft.entity.player.PlayerEntity
|
import net.minecraft.entity.player.PlayerEntity
|
||||||
|
import net.minecraft.entity.player.PlayerInventory
|
||||||
import net.minecraft.inventory.Inventory
|
import net.minecraft.inventory.Inventory
|
||||||
import net.minecraft.inventory.InventoryChangedListener
|
import net.minecraft.inventory.InventoryChangedListener
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.nbt.NbtCompound
|
import net.minecraft.nbt.CompoundTag
|
||||||
|
import net.minecraft.network.PacketByteBuf
|
||||||
|
import net.minecraft.screen.ScreenHandler
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity
|
||||||
|
import net.minecraft.text.TranslatableText
|
||||||
import net.minecraft.util.ItemScatterer
|
import net.minecraft.util.ItemScatterer
|
||||||
import net.minecraft.util.math.BlockPos
|
import net.minecraft.util.Tickable
|
||||||
import net.minecraft.util.math.Direction
|
import net.minecraft.util.math.Direction
|
||||||
import net.shadowfacts.phycon.api.Interface
|
import net.shadowfacts.phycon.api.Interface
|
||||||
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.init.PhyBlockEntities
|
||||||
import net.shadowfacts.phycon.block.DeviceBlockEntity
|
import net.shadowfacts.phycon.block.DeviceBlockEntity
|
||||||
|
import net.shadowfacts.phycon.util.NetworkUtil
|
||||||
import net.shadowfacts.phycon.component.*
|
import net.shadowfacts.phycon.component.*
|
||||||
import net.shadowfacts.phycon.packet.*
|
import net.shadowfacts.phycon.packet.*
|
||||||
import net.shadowfacts.phycon.util.NetworkUtil
|
|
||||||
import java.lang.ref.WeakReference
|
import java.lang.ref.WeakReference
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.function.IntBinaryOperator
|
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
import kotlin.properties.Delegates
|
import kotlin.properties.Delegates
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
abstract class AbstractTerminalBlockEntity(type: BlockEntityType<*>, pos: BlockPos, state: BlockState): DeviceBlockEntity(type, pos, state),
|
abstract class AbstractTerminalBlockEntity(type: BlockEntityType<*>): DeviceBlockEntity(type),
|
||||||
InventoryChangedListener,
|
InventoryChangedListener,
|
||||||
|
BlockEntityClientSerializable,
|
||||||
|
Tickable,
|
||||||
ItemStackPacketHandler,
|
ItemStackPacketHandler,
|
||||||
NetworkStackDispatcher<AbstractTerminalBlockEntity.PendingInsertion> {
|
NetworkStackDispatcher<AbstractTerminalBlockEntity.PendingInsertion> {
|
||||||
|
|
||||||
|
@ -70,7 +78,7 @@ abstract class AbstractTerminalBlockEntity(type: BlockEntityType<*>, pos: BlockP
|
||||||
|
|
||||||
override fun handle(packet: Packet) {
|
override fun handle(packet: Packet) {
|
||||||
when (packet) {
|
when (packet) {
|
||||||
is ReadGroupedInventoryPacket -> handleReadInventory(packet)
|
is ReadInventoryPacket -> handleReadInventory(packet)
|
||||||
is DeviceRemovedPacket -> handleDeviceRemoved(packet)
|
is DeviceRemovedPacket -> handleDeviceRemoved(packet)
|
||||||
is StackLocationPacket -> handleStackLocation(packet)
|
is StackLocationPacket -> handleStackLocation(packet)
|
||||||
is ItemStackPacket -> handleItemStack(packet)
|
is ItemStackPacket -> handleItemStack(packet)
|
||||||
|
@ -78,7 +86,7 @@ abstract class AbstractTerminalBlockEntity(type: BlockEntityType<*>, pos: BlockP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleReadInventory(packet: ReadGroupedInventoryPacket) {
|
private fun handleReadInventory(packet: ReadInventoryPacket) {
|
||||||
inventoryCache[packet.source] = packet.inventory
|
inventoryCache[packet.source] = packet.inventory
|
||||||
updateAndSync()
|
updateAndSync()
|
||||||
}
|
}
|
||||||
|
@ -121,7 +129,7 @@ abstract class AbstractTerminalBlockEntity(type: BlockEntityType<*>, pos: BlockP
|
||||||
protected fun updateAndSync() {
|
protected fun updateAndSync() {
|
||||||
updateNetItems()
|
updateNetItems()
|
||||||
// syncs the internal buffer to the client
|
// syncs the internal buffer to the client
|
||||||
markUpdate()
|
sync()
|
||||||
// syncs the open container (if any) to the client
|
// syncs the open container (if any) to the client
|
||||||
netItemObserver?.get()?.netItemsChanged()
|
netItemObserver?.get()?.netItemsChanged()
|
||||||
}
|
}
|
||||||
|
@ -131,7 +139,7 @@ abstract class AbstractTerminalBlockEntity(type: BlockEntityType<*>, pos: BlockP
|
||||||
for (inventory in inventoryCache.values) {
|
for (inventory in inventoryCache.values) {
|
||||||
for (stack in inventory.storedStacks) {
|
for (stack in inventory.storedStacks) {
|
||||||
val amount = inventory.getAmount(stack)
|
val amount = inventory.getAmount(stack)
|
||||||
cachedNetItems.mergeInt(stack, amount, IntBinaryOperator { a, b -> a + b })
|
cachedNetItems.mergeInt(stack, amount) { a, b -> a + b }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -217,7 +225,8 @@ abstract class AbstractTerminalBlockEntity(type: BlockEntityType<*>, pos: BlockP
|
||||||
|
|
||||||
override fun onInventoryChanged(inv: Inventory) {
|
override fun onInventoryChanged(inv: Inventory) {
|
||||||
if (inv == internalBuffer && world != null && !world!!.isClient) {
|
if (inv == internalBuffer && world != null && !world!!.isClient) {
|
||||||
markUpdate()
|
markDirty()
|
||||||
|
sync()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,12 +234,12 @@ abstract class AbstractTerminalBlockEntity(type: BlockEntityType<*>, pos: BlockP
|
||||||
ItemScatterer.spawn(world, pos, internalBuffer)
|
ItemScatterer.spawn(world, pos, internalBuffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toCommonTag(tag: NbtCompound) {
|
override fun toCommonTag(tag: CompoundTag) {
|
||||||
super.toCommonTag(tag)
|
super.toCommonTag(tag)
|
||||||
tag.put("InternalBuffer", internalBuffer.toTag())
|
tag.put("InternalBuffer", internalBuffer.toTag())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fromCommonTag(tag: NbtCompound) {
|
override fun fromCommonTag(tag: CompoundTag) {
|
||||||
super.fromCommonTag(tag)
|
super.fromCommonTag(tag)
|
||||||
internalBuffer.fromTag(tag.getCompound("InternalBuffer"))
|
internalBuffer.fromTag(tag.getCompound("InternalBuffer"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import com.mojang.blaze3d.systems.RenderSystem
|
||||||
import net.minecraft.client.MinecraftClient
|
import net.minecraft.client.MinecraftClient
|
||||||
import net.minecraft.client.gui.DrawableHelper
|
import net.minecraft.client.gui.DrawableHelper
|
||||||
import net.minecraft.client.gui.Element
|
import net.minecraft.client.gui.Element
|
||||||
import net.minecraft.client.render.GameRenderer
|
import net.minecraft.client.gui.widget.TextFieldWidget
|
||||||
import net.minecraft.client.render.Tessellator
|
import net.minecraft.client.render.Tessellator
|
||||||
import net.minecraft.client.render.VertexConsumerProvider
|
import net.minecraft.client.render.VertexConsumerProvider
|
||||||
import net.minecraft.client.util.math.MatrixStack
|
import net.minecraft.client.util.math.MatrixStack
|
||||||
|
@ -12,6 +12,7 @@ import net.minecraft.entity.player.PlayerInventory
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.screen.slot.Slot
|
import net.minecraft.screen.slot.Slot
|
||||||
import net.minecraft.screen.slot.SlotActionType
|
import net.minecraft.screen.slot.SlotActionType
|
||||||
|
import net.minecraft.text.LiteralText
|
||||||
import net.minecraft.text.Text
|
import net.minecraft.text.Text
|
||||||
import net.minecraft.util.Identifier
|
import net.minecraft.util.Identifier
|
||||||
import net.shadowfacts.cacao.CacaoHandledScreen
|
import net.shadowfacts.cacao.CacaoHandledScreen
|
||||||
|
@ -21,6 +22,7 @@ import net.shadowfacts.phycon.networking.C2STerminalRequestItem
|
||||||
import net.shadowfacts.phycon.networking.C2STerminalUpdateDisplayedItems
|
import net.shadowfacts.phycon.networking.C2STerminalUpdateDisplayedItems
|
||||||
import java.math.RoundingMode
|
import java.math.RoundingMode
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
|
import java.util.LinkedList
|
||||||
import kotlin.math.ceil
|
import kotlin.math.ceil
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
|
@ -35,13 +37,12 @@ abstract class AbstractTerminalScreen<BE: AbstractTerminalBlockEntity, T: Abstra
|
||||||
val terminalBackgroundHeight: Int,
|
val terminalBackgroundHeight: Int,
|
||||||
): CacaoHandledScreen<T>(handler, playerInv, title) {
|
): CacaoHandledScreen<T>(handler, playerInv, title) {
|
||||||
|
|
||||||
interface SearchQueryListener {
|
|
||||||
fun terminalSearchQueryChanged(newValue: String)
|
|
||||||
fun requestTerminalSearchFieldUpdate(): String?
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
var searchQueryListener: SearchQueryListener? = null
|
private val clickHandlers = LinkedList<AbstractTerminalScreen<*, *>.(Double, Double, Int) -> Boolean?>()
|
||||||
|
|
||||||
|
fun registerClickHandler(handler: AbstractTerminalScreen<*, *>.(Double, Double, Int) -> Boolean?) {
|
||||||
|
clickHandlers.add(handler)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract val backgroundTexture: Identifier
|
abstract val backgroundTexture: Identifier
|
||||||
|
@ -49,15 +50,7 @@ abstract class AbstractTerminalScreen<BE: AbstractTerminalBlockEntity, T: Abstra
|
||||||
val terminalVC: AbstractTerminalViewController<*, *, *>
|
val terminalVC: AbstractTerminalViewController<*, *, *>
|
||||||
var amountVC: TerminalRequestAmountViewController? = null
|
var amountVC: TerminalRequestAmountViewController? = null
|
||||||
|
|
||||||
private var prevSearchQuery = ""
|
|
||||||
var searchQuery = ""
|
var searchQuery = ""
|
||||||
set(value) {
|
|
||||||
field = value
|
|
||||||
if (prevSearchQuery != value) {
|
|
||||||
searchQueryListener?.terminalSearchQueryChanged(value)
|
|
||||||
}
|
|
||||||
prevSearchQuery = value
|
|
||||||
}
|
|
||||||
var scrollPosition = 0.0
|
var scrollPosition = 0.0
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
@ -107,7 +100,7 @@ abstract class AbstractTerminalScreen<BE: AbstractTerminalBlockEntity, T: Abstra
|
||||||
private val DECIMAL_FORMAT = DecimalFormat("#.#").apply { roundingMode = RoundingMode.HALF_UP }
|
private val DECIMAL_FORMAT = DecimalFormat("#.#").apply { roundingMode = RoundingMode.HALF_UP }
|
||||||
private val FORMAT = DecimalFormat("##").apply { roundingMode = RoundingMode.HALF_UP }
|
private val FORMAT = DecimalFormat("##").apply { roundingMode = RoundingMode.HALF_UP }
|
||||||
|
|
||||||
fun drawNetworkSlotAmount(stack: ItemStack, x: Int, y: Int) {
|
fun drawNetworkSlotAmount(stack: ItemStack, x: Int, y: Int, slot: Slot, matrixStack: MatrixStack) {
|
||||||
val amount = stack.count
|
val amount = stack.count
|
||||||
val s = when {
|
val s = when {
|
||||||
amount < 1_000 -> amount.toString()
|
amount < 1_000 -> amount.toString()
|
||||||
|
@ -128,17 +121,16 @@ abstract class AbstractTerminalScreen<BE: AbstractTerminalBlockEntity, T: Abstra
|
||||||
// empty string for label because vanilla renders the count behind the damage bar
|
// empty string for label because vanilla renders the count behind the damage bar
|
||||||
itemRenderer.renderGuiItemOverlay(textRenderer, stack, x, y, "")
|
itemRenderer.renderGuiItemOverlay(textRenderer, stack, x, y, "")
|
||||||
|
|
||||||
// ItemRenderer.renderGuiItemOverlay creates a new MatrixStack specifically for drawing the overlay
|
matrixStack.push()
|
||||||
val matrixStack = MatrixStack()
|
|
||||||
matrixStack.translate(x.toDouble(), y.toDouble(), itemRenderer.zOffset + 200.0)
|
matrixStack.translate(x.toDouble(), y.toDouble(), itemRenderer.zOffset + 200.0)
|
||||||
val scale = 2 / 3f
|
val scale = 2 / 3f
|
||||||
matrixStack.scale(scale, scale, 1.0f)
|
matrixStack.scale(scale, scale, 1.0f)
|
||||||
val immediate = VertexConsumerProvider.immediate(Tessellator.getInstance().buffer)
|
val immediate = VertexConsumerProvider.immediate(Tessellator.getInstance().buffer)
|
||||||
val textX = (1 / scale * 18) - textRenderer.getWidth(s).toFloat() - 3
|
val textX = (1 / scale * 18) - textRenderer.getWidth(s).toFloat() - 3
|
||||||
val textY = (1 / scale * 18) - 11
|
val textY = (1 / scale * 18) - 11
|
||||||
textRenderer.draw(s, textX, textY, 0xffffff, true, matrixStack.peek().positionMatrix, immediate, false, 0, 0xF000F0)
|
textRenderer.draw(s, textX, textY, 0xffffff, true, matrixStack.peek().model, immediate, false, 0, 0xF000F0)
|
||||||
RenderSystem.enableDepthTest()
|
|
||||||
immediate.draw()
|
immediate.draw()
|
||||||
|
matrixStack.pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun drawBackground(matrixStack: MatrixStack, delta: Float, mouseX: Int, mouseY: Int) {
|
override fun drawBackground(matrixStack: MatrixStack, delta: Float, mouseX: Int, mouseY: Int) {
|
||||||
|
@ -148,35 +140,38 @@ abstract class AbstractTerminalScreen<BE: AbstractTerminalBlockEntity, T: Abstra
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun drawBackgroundTexture(matrixStack: MatrixStack) {
|
open fun drawBackgroundTexture(matrixStack: MatrixStack) {
|
||||||
RenderSystem.setShader(GameRenderer::getPositionTexColorShader)
|
RenderSystem.color4f(1f, 1f, 1f, 1f)
|
||||||
RenderSystem.setShaderTexture(0, backgroundTexture)
|
client!!.textureManager.bindTexture(backgroundTexture)
|
||||||
RenderSystem.setShaderColor(1f, 1f, 1f, 1f)
|
|
||||||
val x = (width - backgroundWidth) / 2
|
val x = (width - backgroundWidth) / 2
|
||||||
val y = (height - backgroundHeight) / 2
|
val y = (height - backgroundHeight) / 2
|
||||||
drawTexture(matrixStack, x, y, 0, 0, backgroundWidth, backgroundHeight)
|
drawTexture(matrixStack, x, y, 0, 0, backgroundWidth, backgroundHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handledScreenTick() {
|
override fun tick() {
|
||||||
super.handledScreenTick()
|
super.tick()
|
||||||
|
|
||||||
if (amountVC != null) {
|
if (amountVC != null) {
|
||||||
amountVC!!.field.tick()
|
amountVC!!.field.tick()
|
||||||
} else {
|
} else {
|
||||||
terminalVC.searchField.tick()
|
terminalVC.searchField.tick()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val newSearchQuery = searchQueryListener?.requestTerminalSearchFieldUpdate()
|
override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {
|
||||||
if (newSearchQuery != null && searchQuery != newSearchQuery) {
|
for (handler in clickHandlers) {
|
||||||
searchQuery = newSearchQuery
|
val res = handler(mouseX, mouseY, button)
|
||||||
terminalVC.searchField.text = newSearchQuery
|
if (res != null) {
|
||||||
requestUpdatedItems()
|
return res
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return super.mouseClicked(mouseX, mouseY, button)
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
if (slot != null && !slot.stack.isEmpty && handler.isNetworkSlot(slot.id) && handler.cursorStack.isEmpty) {
|
if (slot != null && !slot.stack.isEmpty && handler.isNetworkSlot(slot.id) && playerInventory.cursorStack.isEmpty) {
|
||||||
val stack = slot.stack
|
val stack = slot.stack
|
||||||
|
|
||||||
if (type == SlotActionType.QUICK_MOVE) {
|
if (type == SlotActionType.QUICK_MOVE) {
|
||||||
|
@ -193,11 +188,12 @@ abstract class AbstractTerminalScreen<BE: AbstractTerminalBlockEntity, T: Abstra
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setFocused(element: Element?) {
|
private val fakeFocusedElement = TextFieldWidget(textRenderer, 0, 0, 0, 0, LiteralText(""))
|
||||||
super.setFocused(element)
|
override fun getFocused(): Element? {
|
||||||
// so that when something else (e.g., REI) steals focus and calls setFocused(null) on us, any first responder resigns
|
return if (windows.last().firstResponder != null) {
|
||||||
if (element == null) {
|
fakeFocusedElement
|
||||||
windows.last().firstResponder?.resignFirstResponder()
|
} else {
|
||||||
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -170,16 +170,16 @@ abstract class AbstractTerminalScreenHandler<T: AbstractTerminalBlockEntity>(
|
||||||
terminal.netItemObserver = null
|
terminal.netItemObserver = null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSlotClick(slotId: Int, clickData: Int, actionType: SlotActionType, player: PlayerEntity) {
|
override fun onSlotClick(slotId: Int, clickData: Int, actionType: SlotActionType, player: PlayerEntity): ItemStack {
|
||||||
if (isBufferSlot(slotId)) {
|
if (isBufferSlot(slotId)) {
|
||||||
// todo: why does this think it's quick_craft sometimes?
|
// todo: why does this think it's quick_craft sometimes?
|
||||||
if ((actionType == SlotActionType.PICKUP || actionType == SlotActionType.QUICK_CRAFT) && !cursorStack.isEmpty) {
|
if ((actionType == SlotActionType.PICKUP || actionType == SlotActionType.QUICK_CRAFT) && !player.inventory.cursorStack.isEmpty) {
|
||||||
// placing cursor stack into buffer
|
// placing cursor stack into buffer
|
||||||
val bufferSlot = slotId - bufferSlotsStart // subtract 54 to convert the handler slot ID to a valid buffer index
|
val bufferSlot = slotId - bufferSlotsStart // subtract 54 to convert the handler slot ID to a valid buffer index
|
||||||
terminal.internalBuffer.markSlot(bufferSlot, TerminalBufferInventory.Mode.TO_NETWORK)
|
terminal.internalBuffer.markSlot(bufferSlot, TerminalBufferInventory.Mode.TO_NETWORK)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
super.onSlotClick(slotId, clickData, actionType, player)
|
return super.onSlotClick(slotId, clickData, actionType, player)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun transferSlot(player: PlayerEntity, slotId: Int): ItemStack {
|
override fun transferSlot(player: PlayerEntity, slotId: Int): ItemStack {
|
||||||
|
@ -227,7 +227,7 @@ abstract class AbstractTerminalScreenHandler<T: AbstractTerminalBlockEntity>(
|
||||||
|
|
||||||
slot.markDirty()
|
slot.markDirty()
|
||||||
slotsInsertedInto.add(index)
|
slotsInsertedInto.add(index)
|
||||||
} else if (ItemStack.canCombine(slotStack, stack) && slotStack.count < slotStack.maxCount) {
|
} else if (canStacksCombine(slotStack, stack) && slotStack.count < slotStack.maxCount) {
|
||||||
val maxToMove = slotStack.maxCount - slotStack.count
|
val maxToMove = slotStack.maxCount - slotStack.count
|
||||||
val toMove = min(maxToMove, stack.count)
|
val toMove = min(maxToMove, stack.count)
|
||||||
slotStack.increment(toMove)
|
slotStack.increment(toMove)
|
||||||
|
|
|
@ -100,12 +100,13 @@ abstract class AbstractTerminalViewController<BE: AbstractTerminalBlockEntity, S
|
||||||
handler = ::searchFieldChanged
|
handler = ::searchFieldChanged
|
||||||
drawBackground = false
|
drawBackground = false
|
||||||
}
|
}
|
||||||
|
searchField.becomeFirstResponder()
|
||||||
|
|
||||||
scrollTrack = view.addSubview(ScrollTrackView(::scrollPositionChanged))
|
scrollTrack = view.addSubview(ScrollTrackView(::scrollPositionChanged))
|
||||||
|
|
||||||
val settingsStack = view.addSubview(StackView(Axis.VERTICAL, spacing = 2.0))
|
val settingsStack = view.addSubview(StackView(Axis.VERTICAL, spacing = 2.0))
|
||||||
settingsView = settingsStack
|
settingsView = settingsStack
|
||||||
TerminalSettings.allKeys.sortedByDescending { it.priority }.forEach { key ->
|
TerminalSettings.allKeys.forEach { key ->
|
||||||
val button = SettingButton(key)
|
val button = SettingButton(key)
|
||||||
button.handler = { settingsChanged() }
|
button.handler = { settingsChanged() }
|
||||||
settingsStack.addArrangedSubview(button)
|
settingsStack.addArrangedSubview(button)
|
||||||
|
@ -136,12 +137,6 @@ abstract class AbstractTerminalViewController<BE: AbstractTerminalBlockEntity, S
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun viewWillAppear() {
|
|
||||||
super.viewWillAppear()
|
|
||||||
|
|
||||||
searchField.becomeFirstResponder()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun searchFieldChanged(field: TextField) {
|
private fun searchFieldChanged(field: TextField) {
|
||||||
screen.searchQuery = field.text
|
screen.searchQuery = field.text
|
||||||
screen.requestUpdatedItems()
|
screen.requestUpdatedItems()
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package net.shadowfacts.phycon.block.terminal
|
package net.shadowfacts.phycon.block.terminal
|
||||||
|
|
||||||
import net.minecraft.block.BlockState
|
|
||||||
import net.minecraft.util.Identifier
|
import net.minecraft.util.Identifier
|
||||||
import net.minecraft.util.math.BlockPos
|
|
||||||
import net.minecraft.world.BlockView
|
import net.minecraft.world.BlockView
|
||||||
import net.shadowfacts.phycon.PhysicalConnectivity
|
import net.shadowfacts.phycon.PhysicalConnectivity
|
||||||
|
|
||||||
|
@ -15,6 +13,6 @@ class CraftingTerminalBlock: AbstractTerminalBlock<CraftingTerminalBlockEntity>(
|
||||||
val ID = Identifier(PhysicalConnectivity.MODID, "crafting_terminal")
|
val ID = Identifier(PhysicalConnectivity.MODID, "crafting_terminal")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createBlockEntity(pos: BlockPos, state: BlockState) = CraftingTerminalBlockEntity(pos, state)
|
override fun createBlockEntity(world: BlockView) = CraftingTerminalBlockEntity()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,18 +2,19 @@ package net.shadowfacts.phycon.block.terminal
|
||||||
|
|
||||||
import alexiil.mc.lib.attributes.item.ItemStackCollections
|
import alexiil.mc.lib.attributes.item.ItemStackCollections
|
||||||
import alexiil.mc.lib.attributes.item.ItemStackUtil
|
import alexiil.mc.lib.attributes.item.ItemStackUtil
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2IntMap
|
||||||
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory
|
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory
|
||||||
import net.minecraft.block.BlockState
|
|
||||||
import net.minecraft.entity.player.PlayerEntity
|
import net.minecraft.entity.player.PlayerEntity
|
||||||
import net.minecraft.entity.player.PlayerInventory
|
import net.minecraft.entity.player.PlayerInventory
|
||||||
|
import net.minecraft.inventory.CraftingInventory
|
||||||
import net.minecraft.inventory.SimpleInventory
|
import net.minecraft.inventory.SimpleInventory
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.nbt.NbtCompound
|
import net.minecraft.nbt.CompoundTag
|
||||||
import net.minecraft.network.PacketByteBuf
|
import net.minecraft.network.PacketByteBuf
|
||||||
import net.minecraft.screen.ScreenHandler
|
import net.minecraft.screen.ScreenHandler
|
||||||
import net.minecraft.server.network.ServerPlayerEntity
|
import net.minecraft.server.network.ServerPlayerEntity
|
||||||
|
import net.minecraft.text.Text
|
||||||
import net.minecraft.text.TranslatableText
|
import net.minecraft.text.TranslatableText
|
||||||
import net.minecraft.util.math.BlockPos
|
|
||||||
import net.shadowfacts.phycon.init.PhyBlockEntities
|
import net.shadowfacts.phycon.init.PhyBlockEntities
|
||||||
import net.shadowfacts.phycon.packet.ItemStackPacket
|
import net.shadowfacts.phycon.packet.ItemStackPacket
|
||||||
import net.shadowfacts.phycon.packet.LocateStackPacket
|
import net.shadowfacts.phycon.packet.LocateStackPacket
|
||||||
|
@ -26,7 +27,7 @@ import kotlin.math.min
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
class CraftingTerminalBlockEntity(pos: BlockPos, state: BlockState): AbstractTerminalBlockEntity(PhyBlockEntities.CRAFTING_TERMINAL, pos, state) {
|
class CraftingTerminalBlockEntity: AbstractTerminalBlockEntity(PhyBlockEntities.CRAFTING_TERMINAL) {
|
||||||
|
|
||||||
val craftingInv = SimpleInventory(9)
|
val craftingInv = SimpleInventory(9)
|
||||||
|
|
||||||
|
@ -37,7 +38,7 @@ class CraftingTerminalBlockEntity(pos: BlockPos, state: BlockState): AbstractTer
|
||||||
updateAndSync()
|
updateAndSync()
|
||||||
|
|
||||||
inventoryCache.clear()
|
inventoryCache.clear()
|
||||||
sendPacket(RequestInventoryPacket(RequestInventoryPacket.Kind.GROUPED, ipAddress))
|
sendPacket(RequestInventoryPacket(ipAddress))
|
||||||
val factory = object: ExtendedScreenHandlerFactory {
|
val factory = object: ExtendedScreenHandlerFactory {
|
||||||
override fun createMenu(syncId: Int, playerInv: PlayerInventory, player: PlayerEntity): ScreenHandler? {
|
override fun createMenu(syncId: Int, playerInv: PlayerInventory, player: PlayerEntity): ScreenHandler? {
|
||||||
return CraftingTerminalScreenHandler(syncId, playerInv, this@CraftingTerminalBlockEntity)
|
return CraftingTerminalScreenHandler(syncId, playerInv, this@CraftingTerminalBlockEntity)
|
||||||
|
@ -118,12 +119,12 @@ class CraftingTerminalBlockEntity(pos: BlockPos, state: BlockState): AbstractTer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toCommonTag(tag: NbtCompound) {
|
override fun toCommonTag(tag: CompoundTag) {
|
||||||
super.toCommonTag(tag)
|
super.toCommonTag(tag)
|
||||||
tag.put("CraftingInv", craftingInv.toTag())
|
tag.put("CraftingInv", craftingInv.toTag())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fromCommonTag(tag: NbtCompound) {
|
override fun fromCommonTag(tag: CompoundTag) {
|
||||||
super.fromCommonTag(tag)
|
super.fromCommonTag(tag)
|
||||||
craftingInv.fromTag(tag.getList("CraftingInv", 10))
|
craftingInv.fromTag(tag.getList("CraftingInv", 10))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package net.shadowfacts.phycon.block.terminal
|
package net.shadowfacts.phycon.block.terminal
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem
|
import com.mojang.blaze3d.systems.RenderSystem
|
||||||
import net.minecraft.client.render.GameRenderer
|
|
||||||
import net.minecraft.client.util.math.MatrixStack
|
import net.minecraft.client.util.math.MatrixStack
|
||||||
import net.minecraft.entity.player.PlayerInventory
|
import net.minecraft.entity.player.PlayerInventory
|
||||||
import net.minecraft.text.Text
|
import net.minecraft.text.Text
|
||||||
|
@ -35,13 +34,13 @@ class CraftingTerminalScreen(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun drawBackgroundTexture(matrixStack: MatrixStack) {
|
override fun drawBackgroundTexture(matrixStack: MatrixStack) {
|
||||||
RenderSystem.setShader(GameRenderer::getPositionTexShader)
|
RenderSystem.color4f(1f, 1f, 1f, 1f)
|
||||||
RenderSystem.setShaderTexture(0, BACKGROUND_1)
|
client!!.textureManager.bindTexture(BACKGROUND_1)
|
||||||
val x = (width - backgroundWidth) / 2
|
val x = (width - backgroundWidth) / 2
|
||||||
val y = (height - backgroundHeight) / 2
|
val y = (height - backgroundHeight) / 2
|
||||||
drawTexture(matrixStack, x, y, 0, 0, 256, 252)
|
drawTexture(matrixStack, x, y, 0, 0, 256, 252)
|
||||||
|
|
||||||
RenderSystem.setShaderTexture(0, BACKGROUND_2)
|
client!!.textureManager.bindTexture(BACKGROUND_2)
|
||||||
drawTexture(matrixStack, x + 256, y, 0, 0, 3, 252)
|
drawTexture(matrixStack, x + 256, y, 0, 0, 3, 252)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import net.minecraft.inventory.Inventory
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.network.PacketByteBuf
|
import net.minecraft.network.PacketByteBuf
|
||||||
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket
|
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket
|
||||||
import net.minecraft.recipe.RecipeMatcher
|
import net.minecraft.recipe.RecipeFinder
|
||||||
import net.minecraft.recipe.RecipeType
|
import net.minecraft.recipe.RecipeType
|
||||||
import net.minecraft.screen.slot.CraftingResultSlot
|
import net.minecraft.screen.slot.CraftingResultSlot
|
||||||
import net.minecraft.screen.slot.Slot
|
import net.minecraft.screen.slot.Slot
|
||||||
|
@ -73,7 +73,7 @@ class CraftingTerminalScreenHandler(
|
||||||
ItemStack.EMPTY
|
ItemStack.EMPTY
|
||||||
}
|
}
|
||||||
result.setStack(0, resultStack)
|
result.setStack(0, resultStack)
|
||||||
player.networkHandler.sendPacket(ScreenHandlerSlotUpdateS2CPacket(syncId, nextRevision(), resultSlot.id, resultStack))
|
player.networkHandler.sendPacket(ScreenHandlerSlotUpdateS2CPacket(syncId, resultSlot.id, resultStack))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ class CraftingTerminalScreenHandler(
|
||||||
if (!insertItem(craftingResult, playerSlotsStart, playerSlotsEnd, true)) {
|
if (!insertItem(craftingResult, playerSlotsStart, playerSlotsEnd, true)) {
|
||||||
return ItemStack.EMPTY
|
return ItemStack.EMPTY
|
||||||
}
|
}
|
||||||
resultSlot.onQuickTransfer(craftingResult, originalResult)
|
resultSlot.onStackChanged(craftingResult, originalResult)
|
||||||
|
|
||||||
if (craftingResult.isEmpty) {
|
if (craftingResult.isEmpty) {
|
||||||
resultSlot.stack = ItemStack.EMPTY
|
resultSlot.stack = ItemStack.EMPTY
|
||||||
|
@ -115,8 +115,8 @@ class CraftingTerminalScreenHandler(
|
||||||
return ItemStack.EMPTY
|
return ItemStack.EMPTY
|
||||||
}
|
}
|
||||||
|
|
||||||
resultSlot.onTakeItem(player, craftingResult)
|
val taken = resultSlot.onTakeItem(player, craftingResult)
|
||||||
player.dropItem(craftingResult, false)
|
player.dropItem(taken, false)
|
||||||
|
|
||||||
return originalResult
|
return originalResult
|
||||||
} else {
|
} else {
|
||||||
|
@ -157,7 +157,7 @@ class CraftingTerminalScreenHandler(
|
||||||
backing.clear()
|
backing.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun provideRecipeInputs(finder: RecipeMatcher) {
|
override fun provideRecipeInputs(finder: RecipeFinder) {
|
||||||
TODO()
|
TODO()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
package net.shadowfacts.phycon.block.terminal
|
package net.shadowfacts.phycon.block.terminal
|
||||||
|
|
||||||
import net.minecraft.block.BlockState
|
|
||||||
import net.minecraft.util.Identifier
|
import net.minecraft.util.Identifier
|
||||||
import net.minecraft.util.math.BlockPos
|
import net.minecraft.world.BlockView
|
||||||
import net.shadowfacts.phycon.PhysicalConnectivity
|
import net.shadowfacts.phycon.PhysicalConnectivity
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,6 +13,6 @@ class TerminalBlock: AbstractTerminalBlock<TerminalBlockEntity>() {
|
||||||
val ID = Identifier(PhysicalConnectivity.MODID, "terminal")
|
val ID = Identifier(PhysicalConnectivity.MODID, "terminal")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createBlockEntity(pos: BlockPos, state: BlockState) = TerminalBlockEntity(pos, state)
|
override fun createBlockEntity(world: BlockView) = TerminalBlockEntity()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +1,26 @@
|
||||||
package net.shadowfacts.phycon.block.terminal
|
package net.shadowfacts.phycon.block.terminal
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory
|
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory
|
||||||
import net.minecraft.block.BlockState
|
|
||||||
import net.minecraft.entity.player.PlayerEntity
|
import net.minecraft.entity.player.PlayerEntity
|
||||||
import net.minecraft.entity.player.PlayerInventory
|
import net.minecraft.entity.player.PlayerInventory
|
||||||
import net.minecraft.network.PacketByteBuf
|
import net.minecraft.network.PacketByteBuf
|
||||||
import net.minecraft.screen.ScreenHandler
|
import net.minecraft.screen.ScreenHandler
|
||||||
import net.minecraft.server.network.ServerPlayerEntity
|
import net.minecraft.server.network.ServerPlayerEntity
|
||||||
import net.minecraft.text.TranslatableText
|
import net.minecraft.text.TranslatableText
|
||||||
import net.minecraft.util.math.BlockPos
|
|
||||||
import net.shadowfacts.phycon.init.PhyBlockEntities
|
import net.shadowfacts.phycon.init.PhyBlockEntities
|
||||||
import net.shadowfacts.phycon.packet.RequestInventoryPacket
|
import net.shadowfacts.phycon.packet.RequestInventoryPacket
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
class TerminalBlockEntity(pos: BlockPos, state: BlockState): AbstractTerminalBlockEntity(PhyBlockEntities.TERMINAL, pos, state) {
|
class TerminalBlockEntity: AbstractTerminalBlockEntity(PhyBlockEntities.TERMINAL) {
|
||||||
|
|
||||||
override fun onActivate(player: PlayerEntity) {
|
override fun onActivate(player: PlayerEntity) {
|
||||||
if (!world!!.isClient) {
|
if (!world!!.isClient) {
|
||||||
updateAndSync()
|
updateAndSync()
|
||||||
|
|
||||||
inventoryCache.clear()
|
inventoryCache.clear()
|
||||||
sendPacket(RequestInventoryPacket(RequestInventoryPacket.Kind.GROUPED, ipAddress))
|
sendPacket(RequestInventoryPacket(ipAddress))
|
||||||
val factory = object: ExtendedScreenHandlerFactory {
|
val factory = object: ExtendedScreenHandlerFactory {
|
||||||
override fun createMenu(syncId: Int, playerInv: PlayerInventory, player: PlayerEntity): ScreenHandler {
|
override fun createMenu(syncId: Int, playerInv: PlayerInventory, player: PlayerEntity): ScreenHandler {
|
||||||
return TerminalScreenHandler(syncId, playerInv, this@TerminalBlockEntity)
|
return TerminalScreenHandler(syncId, playerInv, this@TerminalBlockEntity)
|
||||||
|
|
|
@ -3,8 +3,8 @@ package net.shadowfacts.phycon.block.terminal
|
||||||
import alexiil.mc.lib.attributes.item.ItemStackUtil
|
import alexiil.mc.lib.attributes.item.ItemStackUtil
|
||||||
import net.minecraft.inventory.SimpleInventory
|
import net.minecraft.inventory.SimpleInventory
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.nbt.NbtCompound
|
import net.minecraft.nbt.CompoundTag
|
||||||
import net.minecraft.nbt.NbtIntArray
|
import net.minecraft.nbt.IntArrayTag
|
||||||
import net.shadowfacts.phycon.util.fromTag
|
import net.shadowfacts.phycon.util.fromTag
|
||||||
import net.shadowfacts.phycon.util.toTag
|
import net.shadowfacts.phycon.util.toTag
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
@ -21,14 +21,14 @@ class TerminalBufferInventory(size: Int): SimpleInventory(size) {
|
||||||
var modes = Array(size) { Mode.UNASSIGNED }
|
var modes = Array(size) { Mode.UNASSIGNED }
|
||||||
private set
|
private set
|
||||||
|
|
||||||
fun toTag(): NbtCompound {
|
fun toTag(): CompoundTag {
|
||||||
val compound = NbtCompound()
|
val compound = CompoundTag()
|
||||||
compound.put("Inventory", (this as SimpleInventory).toTag())
|
compound.put("Inventory", (this as SimpleInventory).toTag())
|
||||||
compound.put("Modes", NbtIntArray(modes.map(Mode::ordinal)))
|
compound.put("Modes", IntArrayTag(modes.map(Mode::ordinal)))
|
||||||
return compound
|
return compound
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fromTag(tag: NbtCompound) {
|
fun fromTag(tag: CompoundTag) {
|
||||||
val inventory = tag.getList("Inventory", 10)
|
val inventory = tag.getList("Inventory", 10)
|
||||||
(this as SimpleInventory).fromTag(inventory)
|
(this as SimpleInventory).fromTag(inventory)
|
||||||
tag.getIntArray("Modes").forEachIndexed { i, it -> modes[i] = Mode.values()[it] }
|
tag.getIntArray("Modes").forEachIndexed { i, it -> modes[i] = Mode.values()[it] }
|
||||||
|
|
|
@ -25,10 +25,6 @@ class PhyModelProvider(resourceManager: ResourceManager) : ModelResourceProvider
|
||||||
val EXTRACTOR_SIDE = Identifier(PhysicalConnectivity.MODID, "block/extractor_side")
|
val EXTRACTOR_SIDE = Identifier(PhysicalConnectivity.MODID, "block/extractor_side")
|
||||||
val INSERTER = Identifier(PhysicalConnectivity.MODID, "block/inserter")
|
val INSERTER = Identifier(PhysicalConnectivity.MODID, "block/inserter")
|
||||||
val INSERTER_SIDE = Identifier(PhysicalConnectivity.MODID, "block/inserter_side")
|
val INSERTER_SIDE = Identifier(PhysicalConnectivity.MODID, "block/inserter_side")
|
||||||
val P2P_INTERFACE = Identifier(PhysicalConnectivity.MODID, "block/p2p_interface")
|
|
||||||
val P2P_INTERFACE_SIDE = Identifier(PhysicalConnectivity.MODID, "block/p2p_interface_side")
|
|
||||||
val P2P_RECEIVER = Identifier(PhysicalConnectivity.MODID, "block/p2p_receiver")
|
|
||||||
val P2P_RECEIVER_SIDE = Identifier(PhysicalConnectivity.MODID, "block/p2p_receiver_side")
|
|
||||||
|
|
||||||
val CABLES = DyeColor.values().map {
|
val CABLES = DyeColor.values().map {
|
||||||
Identifier(PhysicalConnectivity.MODID, "block/cable/${it.getName()}") to it
|
Identifier(PhysicalConnectivity.MODID, "block/cable/${it.getName()}") to it
|
||||||
|
@ -42,8 +38,6 @@ class PhyModelProvider(resourceManager: ResourceManager) : ModelResourceProvider
|
||||||
REDSTONE_EMITTER -> SimpleFaceDeviceModel(REDSTONE_EMITTER_SIDE)
|
REDSTONE_EMITTER -> SimpleFaceDeviceModel(REDSTONE_EMITTER_SIDE)
|
||||||
EXTRACTOR -> SimpleFaceDeviceModel(EXTRACTOR_SIDE)
|
EXTRACTOR -> SimpleFaceDeviceModel(EXTRACTOR_SIDE)
|
||||||
INSERTER -> SimpleFaceDeviceModel(INSERTER_SIDE)
|
INSERTER -> SimpleFaceDeviceModel(INSERTER_SIDE)
|
||||||
P2P_INTERFACE -> SimpleFaceDeviceModel(P2P_INTERFACE_SIDE)
|
|
||||||
P2P_RECEIVER -> SimpleFaceDeviceModel(P2P_RECEIVER_SIDE)
|
|
||||||
in CABLES -> ColoredCableModel(CABLES[resourceId]!!)
|
in CABLES -> ColoredCableModel(CABLES[resourceId]!!)
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import net.minecraft.client.render.model.*
|
||||||
import net.minecraft.client.texture.Sprite
|
import net.minecraft.client.texture.Sprite
|
||||||
import net.minecraft.client.texture.SpriteAtlasTexture
|
import net.minecraft.client.texture.SpriteAtlasTexture
|
||||||
import net.minecraft.client.util.SpriteIdentifier
|
import net.minecraft.client.util.SpriteIdentifier
|
||||||
import net.minecraft.screen.PlayerScreenHandler
|
|
||||||
import net.minecraft.util.DyeColor
|
import net.minecraft.util.DyeColor
|
||||||
import net.minecraft.util.Identifier
|
import net.minecraft.util.Identifier
|
||||||
import net.minecraft.util.math.Direction
|
import net.minecraft.util.math.Direction
|
||||||
|
@ -86,7 +85,7 @@ class ColoredCableModel(
|
||||||
rotationContainer: ModelBakeSettings,
|
rotationContainer: ModelBakeSettings,
|
||||||
modelId: Identifier
|
modelId: Identifier
|
||||||
): BakedModel {
|
): BakedModel {
|
||||||
centerSprite = textureGetter.apply(SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, Identifier(PhysicalConnectivity.MODID, "block/cable/${color.getName()}/straight")))
|
centerSprite = textureGetter.apply(SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, Identifier(PhysicalConnectivity.MODID, "block/cable/${color.getName()}/straight")))
|
||||||
|
|
||||||
sideRotations.forEach { (side, rot) ->
|
sideRotations.forEach { (side, rot) ->
|
||||||
this.side[side.ordinal] = loader.bakeRecoloredCable(SIDE, rot, textureGetter, color)
|
this.side[side.ordinal] = loader.bakeRecoloredCable(SIDE, rot, textureGetter, color)
|
||||||
|
@ -261,7 +260,7 @@ class ColoredCableModel(
|
||||||
|
|
||||||
override fun isBuiltin() = false
|
override fun isBuiltin() = false
|
||||||
|
|
||||||
override fun getParticleSprite() = centerSprite
|
override fun getSprite() = centerSprite
|
||||||
|
|
||||||
override fun getTransformation() = null
|
override fun getTransformation() = null
|
||||||
|
|
||||||
|
|
|
@ -120,9 +120,9 @@ abstract class FaceDeviceModel: UnbakedModel, BakedModel {
|
||||||
|
|
||||||
val sideQuads = getSideModel(state)?.getQuads(state, face, random) ?: listOf()
|
val sideQuads = getSideModel(state)?.getQuads(state, face, random) ?: listOf()
|
||||||
val cableQuads = if (connection.direction == facing.opposite) {
|
val cableQuads = if (connection.direction == facing.opposite) {
|
||||||
interfaceCableStraight[color]!![facing.ordinal].getQuads(state, face, random) ?: listOf()
|
interfaceCableStraight[color]!![facing.ordinal]?.getQuads(state, face, random) ?: listOf()
|
||||||
} else if (connection == FaceCableConnection.NONE) {
|
} else if (connection == FaceCableConnection.NONE) {
|
||||||
interfaceCableCap[color]!![facing.ordinal].getQuads(state, face, random) ?: listOf()
|
interfaceCableCap[color]!![facing.ordinal]?.getQuads(state, face, random) ?: listOf()
|
||||||
} else {
|
} else {
|
||||||
val model = when (facing) {
|
val model = when (facing) {
|
||||||
Direction.DOWN -> when (connection) {
|
Direction.DOWN -> when (connection) {
|
||||||
|
@ -183,7 +183,7 @@ abstract class FaceDeviceModel: UnbakedModel, BakedModel {
|
||||||
|
|
||||||
override fun isBuiltin() = false
|
override fun isBuiltin() = false
|
||||||
|
|
||||||
abstract override fun getParticleSprite(): Sprite
|
abstract override fun getSprite(): Sprite
|
||||||
|
|
||||||
override fun getTransformation() = null
|
override fun getTransformation() = null
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,8 @@ object RedstoneControllerModel: FaceDeviceModel() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getParticleSprite(): Sprite {
|
override fun getSprite(): Sprite {
|
||||||
return offModels.first()!!.particleSprite
|
return offModels.first()!!.sprite
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ import net.minecraft.client.texture.Sprite
|
||||||
import net.minecraft.client.texture.SpriteAtlasTexture
|
import net.minecraft.client.texture.SpriteAtlasTexture
|
||||||
import net.minecraft.client.util.SpriteIdentifier
|
import net.minecraft.client.util.SpriteIdentifier
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.screen.PlayerScreenHandler
|
|
||||||
import net.minecraft.util.Identifier
|
import net.minecraft.util.Identifier
|
||||||
import net.minecraft.util.math.BlockPos
|
import net.minecraft.util.math.BlockPos
|
||||||
import net.minecraft.util.math.Direction
|
import net.minecraft.util.math.Direction
|
||||||
|
@ -33,10 +32,10 @@ class ScreenDeviceModel(
|
||||||
): UnbakedModel, BakedModel, FabricBakedModel {
|
): UnbakedModel, BakedModel, FabricBakedModel {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val CASING = SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, Identifier(PhysicalConnectivity.MODID, "block/casing"))
|
private val CASING = SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, Identifier(PhysicalConnectivity.MODID, "block/casing"))
|
||||||
}
|
}
|
||||||
|
|
||||||
private val screenTexture = SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, screenTexture)
|
private val screenTexture = SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, screenTexture)
|
||||||
|
|
||||||
private lateinit var meshes: Array<Mesh>
|
private lateinit var meshes: Array<Mesh>
|
||||||
private lateinit var screenSprite: Sprite
|
private lateinit var screenSprite: Sprite
|
||||||
|
@ -172,7 +171,7 @@ class ScreenDeviceModel(
|
||||||
|
|
||||||
override fun isBuiltin() = false
|
override fun isBuiltin() = false
|
||||||
|
|
||||||
override fun getParticleSprite() = screenSprite
|
override fun getSprite() = screenSprite
|
||||||
|
|
||||||
override fun getTransformation() = null
|
override fun getTransformation() = null
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ class SimpleFaceDeviceModel(
|
||||||
return sideModels[state[FaceDeviceBlock.COLOR]]!![state[FaceDeviceBlock.FACING].ordinal]
|
return sideModels[state[FaceDeviceBlock.COLOR]]!![state[FaceDeviceBlock.FACING].ordinal]
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getParticleSprite(): Sprite {
|
override fun getSprite(): Sprite {
|
||||||
return sideModels[DyeColor.BLACK]!!.first().particleSprite
|
return sideModels[DyeColor.BLACK]!!.first().sprite
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package net.shadowfacts.phycon.client.screen
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.widget.AbstractPressableButtonWidget
|
||||||
|
import net.shadowfacts.phycon.util.FriendlyNameable
|
||||||
|
import net.shadowfacts.phycon.util.RotatableEnum
|
||||||
|
import net.shadowfacts.phycon.util.next
|
||||||
|
import net.shadowfacts.phycon.util.prev
|
||||||
|
import kotlin.reflect.KMutableProperty
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author shadowfacts
|
||||||
|
*/
|
||||||
|
class EnumButton<E>(
|
||||||
|
val prop: KMutableProperty<E>,
|
||||||
|
x: Int,
|
||||||
|
y: Int,
|
||||||
|
width: Int,
|
||||||
|
height: Int,
|
||||||
|
val onChange: () -> Unit
|
||||||
|
): AbstractPressableButtonWidget(
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
prop.getter.call().friendlyName
|
||||||
|
) where E: Enum<E>, E: RotatableEnum, E: FriendlyNameable {
|
||||||
|
|
||||||
|
private var currentButton: Int? = null
|
||||||
|
|
||||||
|
override fun mouseClicked(d: Double, e: Double, button: Int): Boolean {
|
||||||
|
currentButton = button
|
||||||
|
val res = super.mouseClicked(d, e, button)
|
||||||
|
currentButton = null
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isValidClickButton(i: Int): Boolean {
|
||||||
|
return i == 0 || i == 1
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPress() {
|
||||||
|
val newVal = if ((currentButton ?: 0) == 0) prop.getter.call().next else prop.getter.call().prev
|
||||||
|
prop.setter.call(newVal)
|
||||||
|
message = newVal.friendlyName
|
||||||
|
onChange()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -18,7 +18,7 @@ class ScrollTrackView(
|
||||||
): View() {
|
): View() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val THUMB = Texture(Identifier(PhysicalConnectivity.MODID, "textures/gui/terminal.png"), 52, 224)
|
private val THUMB = Texture(Identifier(PhysicalConnectivity.MODID, "textures/gui/terminal.png"), 52, 230)
|
||||||
private const val THUMB_WIDTH = 12.0
|
private const val THUMB_WIDTH = 12.0
|
||||||
private const val THUMB_HEIGHT = 15.0
|
private const val THUMB_HEIGHT = 15.0
|
||||||
}
|
}
|
||||||
|
@ -50,16 +50,16 @@ class ScrollTrackView(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun mouseDragged(startPoint: Point, delta: Point, mouseButton: MouseButton): Boolean {
|
override fun mouseDragged(point: Point, delta: Point, mouseButton: MouseButton): Boolean {
|
||||||
if (grabbedY == null && startPoint !in thumbView.frame) {
|
if (grabbedY == null && point !in thumbView.frame) {
|
||||||
val newCenter = MathHelper.clamp(startPoint.y, THUMB_HEIGHT / 2, frame.height - THUMB_HEIGHT / 2)
|
val newCenter = MathHelper.clamp(point.y, THUMB_HEIGHT / 2, frame.height - THUMB_HEIGHT / 2)
|
||||||
thumbView.frame = Rect(0.0, newCenter - THUMB_HEIGHT / 2, THUMB_WIDTH, THUMB_HEIGHT)
|
thumbView.frame = Rect(0.0, newCenter - THUMB_HEIGHT / 2, THUMB_WIDTH, THUMB_HEIGHT)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (grabbedY == null) {
|
if (grabbedY == null) {
|
||||||
grabbedY = startPoint.y - thumbView.frame.top
|
grabbedY = point.y - thumbView.frame.top
|
||||||
}
|
}
|
||||||
val newTop = MathHelper.clamp(startPoint.y - grabbedY!!, 0.0, frame.height - THUMB_HEIGHT)
|
val newTop = MathHelper.clamp(point.y - grabbedY!!, 0.0, frame.height - THUMB_HEIGHT)
|
||||||
thumbView.frame = Rect(0.0, newTop, THUMB_WIDTH, THUMB_HEIGHT)
|
thumbView.frame = Rect(0.0, newTop, THUMB_WIDTH, THUMB_HEIGHT)
|
||||||
|
|
||||||
scrollPositionChanged(this)
|
scrollPositionChanged(this)
|
||||||
|
|
|
@ -14,7 +14,6 @@ import net.shadowfacts.cacao.window.Window
|
||||||
import net.shadowfacts.kiwidsl.dsl
|
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.p2p.P2PReceiverBlockEntity
|
|
||||||
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.block.redstone_emitter.RedstoneEmitterBlockEntity
|
||||||
import net.shadowfacts.phycon.component.ActivationController
|
import net.shadowfacts.phycon.component.ActivationController
|
||||||
|
@ -91,15 +90,6 @@ class DeviceConsoleScreen(
|
||||||
RedstoneEmitterViewController(device)
|
RedstoneEmitterViewController(device)
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
if (device is P2PReceiverBlockEntity) {
|
|
||||||
tabs.add(TabViewController.SimpleTab(
|
|
||||||
TextureView(Texture(Identifier("textures/item/ender_pearl.png"), 0, 0, 16, 16)).apply {
|
|
||||||
intrinsicContentSize = Size(16.0, 16.0)
|
|
||||||
},
|
|
||||||
TranslatableText("block.phycon.p2p_receiver"),
|
|
||||||
P2PReceiverViewController(device)
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
tabController = TabViewController(tabs)
|
tabController = TabViewController(tabs)
|
||||||
|
|
||||||
|
|
|
@ -1,58 +0,0 @@
|
||||||
package net.shadowfacts.phycon.client.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.textfield.TextField
|
|
||||||
import net.shadowfacts.cacao.viewcontroller.ViewController
|
|
||||||
import net.shadowfacts.kiwidsl.dsl
|
|
||||||
import net.shadowfacts.phycon.api.util.IPAddress
|
|
||||||
import net.shadowfacts.phycon.block.p2p.P2PReceiverBlockEntity
|
|
||||||
import net.shadowfacts.phycon.networking.C2SConfigureDevice
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author shadowfacts
|
|
||||||
*/
|
|
||||||
class P2PReceiverViewController(
|
|
||||||
val device: P2PReceiverBlockEntity,
|
|
||||||
): ViewController() {
|
|
||||||
|
|
||||||
override fun viewDidLoad() {
|
|
||||||
super.viewDidLoad()
|
|
||||||
|
|
||||||
val label = Label(TranslatableText("gui.phycon.console.p2p_receiver.target")).apply {
|
|
||||||
textColor = Color.TEXT
|
|
||||||
}
|
|
||||||
view.addSubview(label)
|
|
||||||
|
|
||||||
val textField =
|
|
||||||
TextField(device.target?.toString() ?: "") {
|
|
||||||
device.target = IPAddress.parse(it.text)
|
|
||||||
MinecraftClient.getInstance().player!!.networkHandler.sendPacket(C2SConfigureDevice(device))
|
|
||||||
}
|
|
||||||
view.addSubview(textField)
|
|
||||||
|
|
||||||
val status = Label(device.status.displayName).apply {
|
|
||||||
textColor = Color.TEXT
|
|
||||||
}
|
|
||||||
view.addSubview(status)
|
|
||||||
device.clientObserver = {
|
|
||||||
status.text = device.status.displayName
|
|
||||||
}
|
|
||||||
|
|
||||||
view.solver.dsl {
|
|
||||||
textField.widthAnchor equalTo 100
|
|
||||||
textField.heightAnchor equalTo 20
|
|
||||||
textField.topAnchor equalTo view.topAnchor
|
|
||||||
textField.rightAnchor equalTo view.rightAnchor
|
|
||||||
|
|
||||||
label.centerYAnchor equalTo textField.centerYAnchor
|
|
||||||
label.rightAnchor equalTo (textField.leftAnchor - 4)
|
|
||||||
|
|
||||||
status.centerXAnchor equalTo view.centerXAnchor
|
|
||||||
status.centerYAnchor equalTo (view.centerYAnchor - 10)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -7,8 +7,8 @@ import net.shadowfacts.phycon.api.util.MACAddress
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
open class BaseFrame(
|
open class BaseFrame(
|
||||||
private val source: MACAddress,
|
@JvmField private val source: MACAddress,
|
||||||
private val destination: MACAddress
|
@JvmField private val destination: MACAddress
|
||||||
): EthernetFrame {
|
): EthernetFrame {
|
||||||
override fun getSource() = source
|
override fun getSource() = source
|
||||||
override fun getDestination() = destination
|
override fun getDestination() = destination
|
||||||
|
|
|
@ -8,7 +8,7 @@ import net.shadowfacts.phycon.api.util.MACAddress
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
class BasePacketFrame(
|
class BasePacketFrame(
|
||||||
private val packet: Packet,
|
@JvmField private val packet: Packet,
|
||||||
source: MACAddress,
|
source: MACAddress,
|
||||||
destination: MACAddress,
|
destination: MACAddress,
|
||||||
): BaseFrame(source, destination), PacketFrame {
|
): BaseFrame(source, destination), PacketFrame {
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
package net.shadowfacts.phycon.init
|
package net.shadowfacts.phycon.init
|
||||||
|
|
||||||
import net.minecraft.block.Block
|
import net.minecraft.block.Block
|
||||||
import net.minecraft.block.BlockState
|
|
||||||
import net.minecraft.block.entity.BlockEntity
|
import net.minecraft.block.entity.BlockEntity
|
||||||
import net.minecraft.block.entity.BlockEntityType
|
import net.minecraft.block.entity.BlockEntityType
|
||||||
import net.minecraft.util.Identifier
|
import net.minecraft.util.Identifier
|
||||||
import net.minecraft.util.math.BlockPos
|
|
||||||
import net.minecraft.util.registry.Registry
|
import net.minecraft.util.registry.Registry
|
||||||
import net.shadowfacts.phycon.block.extractor.ExtractorBlock
|
import net.shadowfacts.phycon.block.extractor.ExtractorBlock
|
||||||
import net.shadowfacts.phycon.block.extractor.ExtractorBlockEntity
|
import net.shadowfacts.phycon.block.extractor.ExtractorBlockEntity
|
||||||
|
@ -17,10 +15,6 @@ import net.shadowfacts.phycon.block.netinterface.InterfaceBlock
|
||||||
import net.shadowfacts.phycon.block.netinterface.InterfaceBlockEntity
|
import net.shadowfacts.phycon.block.netinterface.InterfaceBlockEntity
|
||||||
import net.shadowfacts.phycon.block.netswitch.SwitchBlock
|
import net.shadowfacts.phycon.block.netswitch.SwitchBlock
|
||||||
import net.shadowfacts.phycon.block.netswitch.SwitchBlockEntity
|
import net.shadowfacts.phycon.block.netswitch.SwitchBlockEntity
|
||||||
import net.shadowfacts.phycon.block.p2p.P2PInterfaceBlock
|
|
||||||
import net.shadowfacts.phycon.block.p2p.P2PInterfaceBlockEntity
|
|
||||||
import net.shadowfacts.phycon.block.p2p.P2PReceiverBlock
|
|
||||||
import net.shadowfacts.phycon.block.p2p.P2PReceiverBlockEntity
|
|
||||||
import net.shadowfacts.phycon.block.redstone_controller.RedstoneControllerBlock
|
import net.shadowfacts.phycon.block.redstone_controller.RedstoneControllerBlock
|
||||||
import net.shadowfacts.phycon.block.redstone_controller.RedstoneControllerBlockEntity
|
import net.shadowfacts.phycon.block.redstone_controller.RedstoneControllerBlockEntity
|
||||||
import net.shadowfacts.phycon.block.redstone_emitter.RedstoneEmitterBlock
|
import net.shadowfacts.phycon.block.redstone_emitter.RedstoneEmitterBlock
|
||||||
|
@ -44,10 +38,8 @@ object PhyBlockEntities {
|
||||||
val MINER = create(::MinerBlockEntity, PhyBlocks.MINER)
|
val MINER = create(::MinerBlockEntity, PhyBlocks.MINER)
|
||||||
val REDSTONE_CONTROLLER = create(::RedstoneControllerBlockEntity, PhyBlocks.REDSTONE_CONTROLLER)
|
val REDSTONE_CONTROLLER = create(::RedstoneControllerBlockEntity, PhyBlocks.REDSTONE_CONTROLLER)
|
||||||
val REDSTONE_EMITTER = create(::RedstoneEmitterBlockEntity, PhyBlocks.REDSTONE_EMITTER)
|
val REDSTONE_EMITTER = create(::RedstoneEmitterBlockEntity, PhyBlocks.REDSTONE_EMITTER)
|
||||||
val P2P_INTERFACE = create(::P2PInterfaceBlockEntity, PhyBlocks.P2P_INTERFACE)
|
|
||||||
val P2P_RECEIVER = create(::P2PReceiverBlockEntity, PhyBlocks.P2P_RECEIVER)
|
|
||||||
|
|
||||||
private fun <T: BlockEntity> create(builder: (BlockPos, BlockState) -> T, block: Block): BlockEntityType<T> {
|
private fun <T: BlockEntity> create(builder: () -> T, block: Block): BlockEntityType<T> {
|
||||||
return BlockEntityType.Builder.create(builder, block).build(null)
|
return BlockEntityType.Builder.create(builder, block).build(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,8 +53,6 @@ object PhyBlockEntities {
|
||||||
register(MinerBlock.ID, MINER)
|
register(MinerBlock.ID, MINER)
|
||||||
register(RedstoneControllerBlock.ID, REDSTONE_CONTROLLER)
|
register(RedstoneControllerBlock.ID, REDSTONE_CONTROLLER)
|
||||||
register(RedstoneEmitterBlock.ID, REDSTONE_EMITTER)
|
register(RedstoneEmitterBlock.ID, REDSTONE_EMITTER)
|
||||||
register(P2PInterfaceBlock.ID, P2P_INTERFACE)
|
|
||||||
register(P2PReceiverBlock.ID, P2P_RECEIVER)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun register(id: Identifier, type: BlockEntityType<*>) {
|
private fun register(id: Identifier, type: BlockEntityType<*>) {
|
||||||
|
|
|
@ -11,8 +11,6 @@ import net.shadowfacts.phycon.block.inserter.InserterBlock
|
||||||
import net.shadowfacts.phycon.block.miner.MinerBlock
|
import net.shadowfacts.phycon.block.miner.MinerBlock
|
||||||
import net.shadowfacts.phycon.block.netinterface.InterfaceBlock
|
import net.shadowfacts.phycon.block.netinterface.InterfaceBlock
|
||||||
import net.shadowfacts.phycon.block.netswitch.SwitchBlock
|
import net.shadowfacts.phycon.block.netswitch.SwitchBlock
|
||||||
import net.shadowfacts.phycon.block.p2p.P2PInterfaceBlock
|
|
||||||
import net.shadowfacts.phycon.block.p2p.P2PReceiverBlock
|
|
||||||
import net.shadowfacts.phycon.block.redstone_controller.RedstoneControllerBlock
|
import net.shadowfacts.phycon.block.redstone_controller.RedstoneControllerBlock
|
||||||
import net.shadowfacts.phycon.block.redstone_emitter.RedstoneEmitterBlock
|
import net.shadowfacts.phycon.block.redstone_emitter.RedstoneEmitterBlock
|
||||||
import net.shadowfacts.phycon.block.terminal.CraftingTerminalBlock
|
import net.shadowfacts.phycon.block.terminal.CraftingTerminalBlock
|
||||||
|
@ -34,8 +32,6 @@ object PhyBlocks {
|
||||||
val MINER = MinerBlock()
|
val MINER = MinerBlock()
|
||||||
val REDSTONE_CONTROLLER = RedstoneControllerBlock()
|
val REDSTONE_CONTROLLER = RedstoneControllerBlock()
|
||||||
val REDSTONE_EMITTER = RedstoneEmitterBlock()
|
val REDSTONE_EMITTER = RedstoneEmitterBlock()
|
||||||
val P2P_INTERFACE = P2PInterfaceBlock()
|
|
||||||
val P2P_RECEIVER = P2PReceiverBlock()
|
|
||||||
|
|
||||||
fun init() {
|
fun init() {
|
||||||
for ((color, block) in CABLES) {
|
for ((color, block) in CABLES) {
|
||||||
|
@ -51,8 +47,6 @@ object PhyBlocks {
|
||||||
register(MinerBlock.ID, MINER)
|
register(MinerBlock.ID, MINER)
|
||||||
register(RedstoneControllerBlock.ID, REDSTONE_CONTROLLER)
|
register(RedstoneControllerBlock.ID, REDSTONE_CONTROLLER)
|
||||||
register(RedstoneEmitterBlock.ID, REDSTONE_EMITTER)
|
register(RedstoneEmitterBlock.ID, REDSTONE_EMITTER)
|
||||||
register(P2PInterfaceBlock.ID, P2P_INTERFACE)
|
|
||||||
register(P2PReceiverBlock.ID, P2P_RECEIVER)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun register(id: Identifier, block: Block) {
|
private fun register(id: Identifier, block: Block) {
|
||||||
|
|
|
@ -12,15 +12,12 @@ import net.shadowfacts.phycon.block.inserter.InserterBlock
|
||||||
import net.shadowfacts.phycon.block.miner.MinerBlock
|
import net.shadowfacts.phycon.block.miner.MinerBlock
|
||||||
import net.shadowfacts.phycon.block.netinterface.InterfaceBlock
|
import net.shadowfacts.phycon.block.netinterface.InterfaceBlock
|
||||||
import net.shadowfacts.phycon.block.netswitch.SwitchBlock
|
import net.shadowfacts.phycon.block.netswitch.SwitchBlock
|
||||||
import net.shadowfacts.phycon.block.p2p.P2PInterfaceBlock
|
|
||||||
import net.shadowfacts.phycon.block.p2p.P2PReceiverBlock
|
|
||||||
import net.shadowfacts.phycon.block.redstone_controller.RedstoneControllerBlock
|
import net.shadowfacts.phycon.block.redstone_controller.RedstoneControllerBlock
|
||||||
import net.shadowfacts.phycon.block.redstone_emitter.RedstoneEmitterBlock
|
import net.shadowfacts.phycon.block.redstone_emitter.RedstoneEmitterBlock
|
||||||
import net.shadowfacts.phycon.block.terminal.CraftingTerminalBlock
|
import net.shadowfacts.phycon.block.terminal.CraftingTerminalBlock
|
||||||
import net.shadowfacts.phycon.block.terminal.TerminalBlock
|
import net.shadowfacts.phycon.block.terminal.TerminalBlock
|
||||||
import net.shadowfacts.phycon.item.DeviceBlockItem
|
import net.shadowfacts.phycon.item.DeviceBlockItem
|
||||||
import net.shadowfacts.phycon.item.FaceDeviceBlockItem
|
import net.shadowfacts.phycon.item.FaceDeviceBlockItem
|
||||||
import net.shadowfacts.phycon.util.text
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
|
@ -40,8 +37,6 @@ object PhyItems {
|
||||||
val MINER = DeviceBlockItem(PhyBlocks.MINER, Item.Settings())
|
val MINER = DeviceBlockItem(PhyBlocks.MINER, Item.Settings())
|
||||||
val REDSTONE_CONTROLLER = FaceDeviceBlockItem(PhyBlocks.REDSTONE_CONTROLLER, Item.Settings())
|
val REDSTONE_CONTROLLER = FaceDeviceBlockItem(PhyBlocks.REDSTONE_CONTROLLER, Item.Settings())
|
||||||
val REDSTONE_EMITTER = FaceDeviceBlockItem(PhyBlocks.REDSTONE_EMITTER, Item.Settings())
|
val REDSTONE_EMITTER = FaceDeviceBlockItem(PhyBlocks.REDSTONE_EMITTER, Item.Settings())
|
||||||
val P2P_INTERFACE = FaceDeviceBlockItem(PhyBlocks.P2P_INTERFACE, Item.Settings())
|
|
||||||
val P2P_RECEIVER = FaceDeviceBlockItem(PhyBlocks.P2P_RECEIVER, Item.Settings())
|
|
||||||
|
|
||||||
val SCREWDRIVER = ScrewdriverItem()
|
val SCREWDRIVER = ScrewdriverItem()
|
||||||
val CONSOLE = ConsoleItem()
|
val CONSOLE = ConsoleItem()
|
||||||
|
@ -66,18 +61,6 @@ object PhyItems {
|
||||||
register(MinerBlock.ID, MINER)
|
register(MinerBlock.ID, MINER)
|
||||||
register(RedstoneControllerBlock.ID, REDSTONE_CONTROLLER)
|
register(RedstoneControllerBlock.ID, REDSTONE_CONTROLLER)
|
||||||
register(RedstoneEmitterBlock.ID, REDSTONE_EMITTER)
|
register(RedstoneEmitterBlock.ID, REDSTONE_EMITTER)
|
||||||
register(P2PInterfaceBlock.ID, P2P_INTERFACE)
|
|
||||||
P2P_INTERFACE.addTooltip(text {
|
|
||||||
withStyle(darkGray) {
|
|
||||||
+translate("tooltip.phycon.p2p_interface")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
register(P2PReceiverBlock.ID, P2P_RECEIVER)
|
|
||||||
P2P_RECEIVER.addTooltip(text {
|
|
||||||
withStyle(darkGray) {
|
|
||||||
+translate("tooltip.phycon.p2p_receiver")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
register(ScrewdriverItem.ID, SCREWDRIVER)
|
register(ScrewdriverItem.ID, SCREWDRIVER)
|
||||||
register(ConsoleItem.ID, CONSOLE)
|
register(ConsoleItem.ID, CONSOLE)
|
||||||
|
|
|
@ -27,7 +27,7 @@ class ConsoleItem: Item(Settings().maxCount(1)) {
|
||||||
if (context.world.isClient) {
|
if (context.world.isClient) {
|
||||||
this.openScreen(be)
|
this.openScreen(be)
|
||||||
} else {
|
} else {
|
||||||
be.markUpdate()
|
be.sync()
|
||||||
}
|
}
|
||||||
return ActionResult.SUCCESS
|
return ActionResult.SUCCESS
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ class ConsoleItem: Item(Settings().maxCount(1)) {
|
||||||
private fun openScreen(be: DeviceBlockEntity) {
|
private fun openScreen(be: DeviceBlockEntity) {
|
||||||
// val screen = TestCacaoScreen()
|
// val screen = TestCacaoScreen()
|
||||||
val screen = DeviceConsoleScreen(be)
|
val screen = DeviceConsoleScreen(be)
|
||||||
MinecraftClient.getInstance().setScreen(screen)
|
MinecraftClient.getInstance().openScreen(screen)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,16 +14,8 @@ import net.shadowfacts.phycon.util.text
|
||||||
*/
|
*/
|
||||||
open class DeviceBlockItem(block: DeviceBlock<*>, settings: Settings = Settings()): BlockItem(block, settings) {
|
open class DeviceBlockItem(block: DeviceBlock<*>, settings: Settings = Settings()): BlockItem(block, settings) {
|
||||||
|
|
||||||
private var tooltip = mutableListOf<Text>()
|
|
||||||
|
|
||||||
fun addTooltip(tooltip: Text) {
|
|
||||||
this.tooltip.add(tooltip)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun appendTooltip(stack: ItemStack, world: World?, list: MutableList<Text>, context: TooltipContext) {
|
override fun appendTooltip(stack: ItemStack, world: World?, list: MutableList<Text>, context: TooltipContext) {
|
||||||
list.addAll(tooltip)
|
val beTag = stack.getSubTag("BlockEntityTag")
|
||||||
|
|
||||||
val beTag = stack.getSubNbt("BlockEntityTag")
|
|
||||||
if (beTag != null) {
|
if (beTag != null) {
|
||||||
val ip = IPAddress(beTag.getInt("IPAddress"))
|
val ip = IPAddress(beTag.getInt("IPAddress"))
|
||||||
list.add(text {
|
list.add(text {
|
||||||
|
|
|
@ -2,14 +2,11 @@ package net.shadowfacts.phycon.item
|
||||||
|
|
||||||
import net.minecraft.block.BlockState
|
import net.minecraft.block.BlockState
|
||||||
import net.minecraft.item.ItemPlacementContext
|
import net.minecraft.item.ItemPlacementContext
|
||||||
import net.minecraft.util.math.BlockPos
|
|
||||||
import net.minecraft.util.math.Direction
|
import net.minecraft.util.math.Direction
|
||||||
import net.shadowfacts.phycon.block.FaceDeviceBlock
|
import net.shadowfacts.phycon.block.FaceDeviceBlock
|
||||||
import net.shadowfacts.phycon.block.cable.CableBlock
|
import net.shadowfacts.phycon.block.cable.CableBlock
|
||||||
import net.shadowfacts.phycon.init.PhyBlocks
|
import net.shadowfacts.phycon.init.PhyBlocks
|
||||||
import net.shadowfacts.phycon.util.CableConnection
|
import net.shadowfacts.phycon.util.CableConnection
|
||||||
import kotlin.math.floor
|
|
||||||
import kotlin.math.roundToInt
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
|
@ -21,14 +18,8 @@ class FaceDeviceBlockItem(block: FaceDeviceBlock<*>, settings: Settings = Settin
|
||||||
val hitBlock = hitState.block
|
val hitBlock = hitState.block
|
||||||
if (hitBlock is CableBlock) {
|
if (hitBlock is CableBlock) {
|
||||||
val hitBlockEdge = context.hitPos.getComponentAlongAxis(context.side.axis) % 1 == 0.0
|
val hitBlockEdge = context.hitPos.getComponentAlongAxis(context.side.axis) % 1 == 0.0
|
||||||
val hitBlockBeingPlacedIn = floor(context.hitPos.getComponentAlongAxis(context.side.axis)).toInt() == context.blockPos.getComponentAlongAxis(context.side.axis)
|
|
||||||
|
|
||||||
val placementSide: Direction =
|
val placementSide = if (hitBlockEdge) context.side.opposite else context.side
|
||||||
if (hitBlockEdge xor hitBlockBeingPlacedIn) {
|
|
||||||
context.side
|
|
||||||
} else {
|
|
||||||
context.side.opposite
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hitState[CableBlock.CONNECTIONS[placementSide]] != CableConnection.ON) {
|
if (hitState[CableBlock.CONNECTIONS[placementSide]] != CableConnection.ON) {
|
||||||
var connection = FaceDeviceBlock.FaceCableConnection.NONE
|
var connection = FaceDeviceBlock.FaceCableConnection.NONE
|
||||||
|
|
|
@ -54,12 +54,12 @@ class ScrewdriverItem: Item(Settings().maxCount(1)) {
|
||||||
val be = block.getBlockEntity(context.world, context.blockPos)!!
|
val be = block.getBlockEntity(context.world, context.blockPos)!!
|
||||||
|
|
||||||
val stack = ItemStack(block)
|
val stack = ItemStack(block)
|
||||||
val beTag = be.createNbt()
|
val beTag = stack.getOrCreateSubTag("BlockEntityTag")
|
||||||
|
be.toTag(beTag)
|
||||||
// remove x, y, z entries for stacking purposes
|
// remove x, y, z entries for stacking purposes
|
||||||
beTag.remove("x")
|
beTag.remove("x")
|
||||||
beTag.remove("y")
|
beTag.remove("y")
|
||||||
beTag.remove("z")
|
beTag.remove("z")
|
||||||
stack.setSubNbt("BlockEntityTag", beTag)
|
|
||||||
|
|
||||||
if (block === PhyBlocks.TERMINAL) {
|
if (block === PhyBlocks.TERMINAL) {
|
||||||
// remove the terminal's internal buffer since it drops its items
|
// remove the terminal's internal buffer since it drops its items
|
||||||
|
|
|
@ -3,7 +3,7 @@ package net.shadowfacts.phycon.networking
|
||||||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs
|
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs
|
||||||
import net.fabricmc.fabric.api.networking.v1.PacketSender
|
import net.fabricmc.fabric.api.networking.v1.PacketSender
|
||||||
import net.minecraft.block.entity.BlockEntity
|
import net.minecraft.block.entity.BlockEntity
|
||||||
import net.minecraft.nbt.NbtCompound
|
import net.minecraft.nbt.CompoundTag
|
||||||
import net.minecraft.network.Packet
|
import net.minecraft.network.Packet
|
||||||
import net.minecraft.network.PacketByteBuf
|
import net.minecraft.network.PacketByteBuf
|
||||||
import net.minecraft.server.MinecraftServer
|
import net.minecraft.server.MinecraftServer
|
||||||
|
@ -24,9 +24,9 @@ object C2SConfigureDevice: ServerReceiver {
|
||||||
|
|
||||||
buf.writeIdentifier(be.world!!.registryKey.value)
|
buf.writeIdentifier(be.world!!.registryKey.value)
|
||||||
buf.writeBlockPos(be.pos)
|
buf.writeBlockPos(be.pos)
|
||||||
val tag = NbtCompound()
|
val tag = CompoundTag()
|
||||||
be.writeDeviceConfiguration(tag)
|
be.writeDeviceConfiguration(tag)
|
||||||
buf.writeNbt(tag)
|
buf.writeCompoundTag(tag)
|
||||||
|
|
||||||
return createPacket(buf)
|
return createPacket(buf)
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ object C2SConfigureDevice: ServerReceiver {
|
||||||
override fun receive(server: MinecraftServer, player: ServerPlayerEntity, handler: ServerPlayNetworkHandler, buf: PacketByteBuf, responseSender: PacketSender) {
|
override fun receive(server: MinecraftServer, player: ServerPlayerEntity, handler: ServerPlayNetworkHandler, buf: PacketByteBuf, responseSender: PacketSender) {
|
||||||
val dimID = buf.readIdentifier()
|
val dimID = buf.readIdentifier()
|
||||||
val pos = buf.readBlockPos()
|
val pos = buf.readBlockPos()
|
||||||
val tag = buf.readNbt() ?: return
|
val tag = buf.readCompoundTag() ?: return
|
||||||
|
|
||||||
server.execute {
|
server.execute {
|
||||||
// todo: check if the player is close enough
|
// todo: check if the player is close enough
|
||||||
|
|
|
@ -42,7 +42,7 @@ object C2STerminalCraftingButton: ServerReceiver {
|
||||||
val action = Action.values()[buf.readByte().toInt()]
|
val action = Action.values()[buf.readByte().toInt()]
|
||||||
|
|
||||||
server.execute {
|
server.execute {
|
||||||
val key = RegistryKey.of(Registry.WORLD_KEY, dimID)
|
val key = RegistryKey.of(Registry.DIMENSION, dimID)
|
||||||
val screenHandler = player.currentScreenHandler as? CraftingTerminalScreenHandler ?: return@execute
|
val screenHandler = player.currentScreenHandler as? CraftingTerminalScreenHandler ?: return@execute
|
||||||
if (screenHandler.terminal.pos != pos || screenHandler.terminal.world!!.registryKey != key) return@execute
|
if (screenHandler.terminal.pos != pos || screenHandler.terminal.world!!.registryKey != key) return@execute
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ object C2STerminalRequestItem: ServerReceiver {
|
||||||
val amount = buf.readVarInt()
|
val amount = buf.readVarInt()
|
||||||
|
|
||||||
server.execute {
|
server.execute {
|
||||||
val key = RegistryKey.of(Registry.WORLD_KEY, dimID)
|
val key = RegistryKey.of(Registry.DIMENSION, dimID)
|
||||||
val world = server.getWorld(key) ?: return@execute
|
val world = server.getWorld(key) ?: return@execute
|
||||||
val terminal = world.getBlockEntity(pos) as? AbstractTerminalBlockEntity ?: return@execute
|
val terminal = world.getBlockEntity(pos) as? AbstractTerminalBlockEntity ?: return@execute
|
||||||
terminal.requestItem(stack, amount)
|
terminal.requestItem(stack, amount)
|
||||||
|
|
|
@ -29,7 +29,7 @@ object C2STerminalUpdateDisplayedItems: ServerReceiver {
|
||||||
buf.writeBlockPos(terminal.pos)
|
buf.writeBlockPos(terminal.pos)
|
||||||
|
|
||||||
buf.writeString(query)
|
buf.writeString(query)
|
||||||
buf.writeNbt(PhysicalConnectivityClient.terminalSettings.toTag())
|
buf.writeCompoundTag(PhysicalConnectivityClient.terminalSettings.toTag())
|
||||||
buf.writeFloat(scrollPosition)
|
buf.writeFloat(scrollPosition)
|
||||||
|
|
||||||
return ClientPlayNetworking.createC2SPacket(CHANNEL, buf)
|
return ClientPlayNetworking.createC2SPacket(CHANNEL, buf)
|
||||||
|
@ -40,7 +40,7 @@ object C2STerminalUpdateDisplayedItems: ServerReceiver {
|
||||||
val pos = buf.readBlockPos()
|
val pos = buf.readBlockPos()
|
||||||
val query = buf.readString()
|
val query = buf.readString()
|
||||||
val settings = TerminalSettings()
|
val settings = TerminalSettings()
|
||||||
settings.fromTag(buf.readNbt()!!)
|
settings.fromTag(buf.readCompoundTag()!!)
|
||||||
val scrollPosition = buf.readFloat()
|
val scrollPosition = buf.readFloat()
|
||||||
|
|
||||||
server.execute {
|
server.execute {
|
||||||
|
|
|
@ -33,7 +33,7 @@ object S2CTerminalUpdateDisplayedItems: ClientReceiver {
|
||||||
}
|
}
|
||||||
|
|
||||||
buf.writeString(query)
|
buf.writeString(query)
|
||||||
buf.writeNbt(settings.toTag())
|
buf.writeCompoundTag(settings.toTag())
|
||||||
buf.writeFloat(scrollPosition)
|
buf.writeFloat(scrollPosition)
|
||||||
buf.writeInt(totalEntries)
|
buf.writeInt(totalEntries)
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ object S2CTerminalUpdateDisplayedItems: ClientReceiver {
|
||||||
entries.add(AbstractTerminalScreenHandler.Entry(buf.readItemStackWithoutCount(), buf.readVarInt()))
|
entries.add(AbstractTerminalScreenHandler.Entry(buf.readItemStackWithoutCount(), buf.readVarInt()))
|
||||||
}
|
}
|
||||||
val query = buf.readString()
|
val query = buf.readString()
|
||||||
PhysicalConnectivityClient.terminalSettings.fromTag(buf.readNbt()!!)
|
PhysicalConnectivityClient.terminalSettings.fromTag(buf.readCompoundTag()!!)
|
||||||
val scrollPosition = buf.readFloat()
|
val scrollPosition = buf.readFloat()
|
||||||
val totalEntries = buf.readInt()
|
val totalEntries = buf.readInt()
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,8 @@ import net.shadowfacts.phycon.api.util.IPAddress
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
abstract class BasePacket(
|
abstract class BasePacket(
|
||||||
private val source: IPAddress,
|
@JvmField private val source: IPAddress,
|
||||||
private val destination: IPAddress
|
@JvmField private val destination: IPAddress
|
||||||
): Packet {
|
): Packet {
|
||||||
|
|
||||||
override fun getSource() = source
|
override fun getSource() = source
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
package net.shadowfacts.phycon.packet
|
|
||||||
|
|
||||||
import net.shadowfacts.phycon.api.util.IPAddress
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author shadowfacts
|
|
||||||
*/
|
|
||||||
class PingPacket(source: IPAddress, destination: IPAddress): BasePacket(source, destination)
|
|
||||||
|
|
||||||
class PongPacket(source: IPAddress, destination: IPAddress): BasePacket(source, destination)
|
|
|
@ -6,7 +6,7 @@ import net.shadowfacts.phycon.api.util.IPAddress
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
class ReadGroupedInventoryPacket(
|
class ReadInventoryPacket(
|
||||||
val inventory: GroupedItemInvView,
|
val inventory: GroupedItemInvView,
|
||||||
source: IPAddress,
|
source: IPAddress,
|
||||||
destination: IPAddress
|
destination: IPAddress
|
|
@ -1,14 +0,0 @@
|
||||||
package net.shadowfacts.phycon.packet
|
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant
|
|
||||||
import net.fabricmc.fabric.api.transfer.v1.storage.Storage
|
|
||||||
import net.shadowfacts.phycon.api.util.IPAddress
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author shadowfacts
|
|
||||||
*/
|
|
||||||
class ReadItemStoragePacket(
|
|
||||||
val inventory: Storage<ItemVariant>,
|
|
||||||
source: IPAddress,
|
|
||||||
destination: IPAddress
|
|
||||||
): BasePacket(source, destination)
|
|
|
@ -5,12 +5,4 @@ import net.shadowfacts.phycon.api.util.IPAddress
|
||||||
/**
|
/**
|
||||||
* @author shadowfacts
|
* @author shadowfacts
|
||||||
*/
|
*/
|
||||||
class RequestInventoryPacket(
|
class RequestInventoryPacket(source: IPAddress, destination: IPAddress = IPAddress.BROADCAST): BasePacket(source, destination)
|
||||||
val kind: Kind,
|
|
||||||
source: IPAddress,
|
|
||||||
destination: IPAddress = IPAddress.BROADCAST
|
|
||||||
): BasePacket(source, destination) {
|
|
||||||
enum class Kind {
|
|
||||||
GROUPED, SIDED
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -11,5 +11,5 @@ enum class ActivationMode: RotatableEnum, FriendlyNameable {
|
||||||
MANAGED;
|
MANAGED;
|
||||||
|
|
||||||
override val friendlyName: Text
|
override val friendlyName: Text
|
||||||
get() = TranslatableText("gui.phycon.activation_mode.${name.lowercase()}")
|
get() = TranslatableText("gui.phycon.activation_mode.${name.toLowerCase()}")
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue