Initial update to 1.18.1
This commit is contained in:
parent
172536cdb8
commit
5488cc295a
89
build.gradle
89
build.gradle
|
@ -1,7 +1,7 @@
|
|||
plugins {
|
||||
id "fabric-loom" version "0.6.49"
|
||||
id "fabric-loom" version "0.10-SNAPSHOT"
|
||||
id "maven-publish"
|
||||
id "org.jetbrains.kotlin.jvm" version "1.4.30"
|
||||
id "org.jetbrains.kotlin.jvm" version "1.6.10"
|
||||
}
|
||||
|
||||
archivesBaseName = project.archives_base_name
|
||||
|
@ -10,8 +10,8 @@ group = project.maven_group
|
|||
|
||||
allprojects {
|
||||
pluginManager.withPlugin("java") {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,8 @@ configure(allprojects.findAll { it.name != "kiwi-java" }) {
|
|||
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
|
||||
tasks.withType(JavaCompile) {
|
||||
options.encoding = "UTF-8"
|
||||
// Minecraft 1.18 (1.18-pre2) upwards uses Java 17.
|
||||
options.release = 17
|
||||
}
|
||||
|
||||
java {
|
||||
|
@ -55,43 +57,54 @@ configure(allprojects.findAll { it.name != "kiwi-java" }) {
|
|||
|
||||
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
|
||||
compileKotlin {
|
||||
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8
|
||||
kotlinOptions.jvmTarget = JavaVersion.VERSION_17
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
minecraft {
|
||||
loom {
|
||||
log4jConfigs.from "PhyConDebugLogging.xml"
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven { url "https://mod-buildcraft.com/maven" }
|
||||
maven { url "http://server.bbkr.space:8081/artifactory/libs-release/" }
|
||||
// maven { url "https://server.bbkr.space:8081/artifactory/libs-release/" }
|
||||
maven { url "https://maven.terraformersmc.com/releases" }
|
||||
jcenter()
|
||||
maven { url "https://maven.shedaniel.me/" }
|
||||
maven { url "https://maven.siphalor.de/" }
|
||||
maven { url "https://jitpack.io" }
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
|
||||
// You may need to force-disable transitiveness on them.
|
||||
modCompile "alexiil.mc.lib:libblockattributes-all:${project.libblockattributes_version}"
|
||||
modImplementation "alexiil.mc.lib:libblockattributes-all:${project.libblockattributes_version}"
|
||||
include "alexiil.mc.lib:libblockattributes-core:${project.libblockattributes_version}"
|
||||
include "alexiil.mc.lib:libblockattributes-items:${project.libblockattributes_version}"
|
||||
|
||||
compile project(":kiwi-java")
|
||||
implementation project(":kiwi-java")
|
||||
include project(":kiwi-java")
|
||||
|
||||
runtimeOnly project(":plugin:mousewheelie")
|
||||
include project(":plugin:mousewheelie")
|
||||
runtimeOnly project(":plugin:rei")
|
||||
include project(":plugin:rei")
|
||||
runtimeOnly project(":plugin:techreborn")
|
||||
include project(":plugin:techreborn")
|
||||
|
||||
modRuntime("io.github.cottonmc:cotton-resources:${project.cotton_resources_version}") {
|
||||
exclude group: "net.fabricmc.fabric-api"
|
||||
modRuntimeOnly "de.siphalor:mousewheelie-1.18:${project.mousewheelie_version}"
|
||||
runtimeOnly(project(":plugin:mousewheelie")) {
|
||||
transitive = false
|
||||
}
|
||||
modRuntime("com.terraformersmc:modmenu:${project.modmenu_version}") {
|
||||
include project(":plugin:mousewheelie")
|
||||
|
||||
modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}"
|
||||
runtimeOnly(project(":plugin:rei")) {
|
||||
transitive = false
|
||||
}
|
||||
include project(":plugin:rei")
|
||||
|
||||
// runtimeOnly project(":plugin:techreborn")
|
||||
// include project(":plugin:techreborn")
|
||||
|
||||
// modRuntime("io.github.cottonmc:cotton-resources:${project.cotton_resources_version}") {
|
||||
// exclude group: "net.fabricmc.fabric-api"
|
||||
// }
|
||||
modRuntimeOnly("com.terraformersmc:modmenu:${project.modmenu_version}") {
|
||||
exclude group: "net.fabricmc.fabric-api"
|
||||
}
|
||||
|
||||
|
@ -105,22 +118,22 @@ jar {
|
|||
}
|
||||
|
||||
// configure the maven publication
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
// add all the jars that should be included when publishing to maven
|
||||
artifact(remapJar) {
|
||||
builtBy remapJar
|
||||
}
|
||||
artifact(sourcesJar) {
|
||||
builtBy remapSourcesJar
|
||||
}
|
||||
}
|
||||
}
|
||||
// publishing {
|
||||
// publications {
|
||||
// mavenJava(MavenPublication) {
|
||||
// // add all the jars that should be included when publishing to maven
|
||||
// artifact(remapJar) {
|
||||
// builtBy remapJar
|
||||
// }
|
||||
// artifact(sourcesJar) {
|
||||
// builtBy remapSourcesJar
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// select the repositories you want to publish to
|
||||
repositories {
|
||||
// uncomment to publish to the local maven
|
||||
// mavenLocal()
|
||||
}
|
||||
}
|
||||
// // select the repositories you want to publish to
|
||||
// repositories {
|
||||
// // uncomment to publish to the local maven
|
||||
// // mavenLocal()
|
||||
// }
|
||||
// }
|
||||
|
|
|
@ -1,19 +1,21 @@
|
|||
org.gradle.jvmargs=-Xmx1G
|
||||
org.gradle.daemon=false
|
||||
|
||||
minecraft_version=1.16.5
|
||||
yarn_mappings=1.16.5+build.4
|
||||
loader_version=0.11.1
|
||||
minecraft_version=1.18.1
|
||||
yarn_mappings=1.18.1+build.7
|
||||
loader_version=0.12.12
|
||||
|
||||
mod_version=0.2.0
|
||||
maven_group=net.shadowfacts
|
||||
archives_base_name=PhysicalConnectivity
|
||||
|
||||
fabric_version=0.30.0+1.16
|
||||
fabric_kotlin_version=1.4.30+build.2
|
||||
fabric_version=0.44.0+1.18
|
||||
fabric_kotlin_version=1.7.1+kotlin.1.6.10
|
||||
|
||||
libblockattributes_version=0.8.5
|
||||
cotton_resources_version=1.7.4
|
||||
modmenu_version=1.16.8
|
||||
libblockattributes_version=0.10.0
|
||||
# cotton_resources_version=1.7.4
|
||||
modmenu_version=3.0.1
|
||||
rei_version=7.1.356
|
||||
mousewheelie_version=1.8.0+mc1.18-pre5
|
||||
|
||||
junit_version = 5.4.0
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 1cbaea53d207f1e16c6e5ee2e6bf6e3c1440ac44
|
||||
Subproject commit abe783ae7ce45ccf296ed7b7e5c1b194e7c560fa
|
|
@ -3,7 +3,7 @@ plugins {
|
|||
id "org.jetbrains.kotlin.jvm"
|
||||
}
|
||||
|
||||
archivesBaseName = project.archives_base_name
|
||||
archivesBaseName = "PhyCon-Plugin-MouseWheelie"
|
||||
version = project.mod_version
|
||||
group = project.maven_group
|
||||
|
||||
|
@ -11,13 +11,18 @@ repositories {
|
|||
maven {
|
||||
url = "https://maven.siphalor.de/"
|
||||
}
|
||||
jcenter()
|
||||
maven {
|
||||
url = "https://jitpack.io"
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(":")
|
||||
implementation(project(":")) {
|
||||
transitive = false
|
||||
}
|
||||
|
||||
modImplementation("de.siphalor:mousewheelie-1.16:${project.mousewheelie_version}") {
|
||||
modImplementation("de.siphalor:mousewheelie-1.18:${project.mousewheelie_version}") {
|
||||
exclude group: "net.fabricmc"
|
||||
exclude group: "net.fabricmc.fabric-api"
|
||||
exclude module: "modmenu"
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
archives_base_name=PhyCon-Plugin-MouseWheelie
|
||||
|
||||
mousewheelie_version=1.6.4+mc1.16.4
|
||||
|
|
@ -3,7 +3,7 @@ plugins {
|
|||
id "org.jetbrains.kotlin.jvm"
|
||||
}
|
||||
|
||||
archivesBaseName = project.archives_base_name
|
||||
archivesBaseName = "PhyCon-Plugin-REI"
|
||||
version = project.mod_version
|
||||
group = project.maven_group
|
||||
|
||||
|
@ -11,16 +11,15 @@ repositories {
|
|||
maven {
|
||||
url = "https://maven.shedaniel.me/"
|
||||
}
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(":")
|
||||
implementation(project(":")) {
|
||||
transitive = false
|
||||
}
|
||||
|
||||
modCompileOnly("me.shedaniel:RoughlyEnoughItems-api:${project.rei_version}") {
|
||||
exclude group: "net.fabricmc.fabric-api"
|
||||
}
|
||||
modRuntime("me.shedaniel:RoughlyEnoughItems:${project.rei_version}") {
|
||||
modCompileOnly("me.shedaniel:RoughlyEnoughItems-api-fabric:${project.rei_version}") {
|
||||
exclude group: "net.fabricmc.fabric-api"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
archives_base_name=PhyCon-Plugin-REI
|
||||
|
||||
rei_version=5.10.184
|
|
@ -1,25 +1,23 @@
|
|||
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 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.minecraft.util.Identifier
|
||||
import net.shadowfacts.phycon.block.terminal.AbstractTerminalScreen
|
||||
|
||||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
object PhyConPlugin: ClientModInitializer, REIPluginV0 {
|
||||
object PhyConPlugin: ClientModInitializer, REIClientPlugin {
|
||||
const val MODID = "phycon_rei"
|
||||
|
||||
override fun onInitializeClient() {
|
||||
AbstractTerminalScreen.registerClickHandler { mouseX, mouseY, button ->
|
||||
REIHelper.getInstance().searchTextField?.also {
|
||||
if (it.bounds.contains(mouseX, mouseY)) {
|
||||
REIRuntime.getInstance().searchTextField?.also {
|
||||
if (it.isFocused) {
|
||||
this.terminalVC.searchField.resignFirstResponder()
|
||||
} else {
|
||||
this.terminalVC.searchField.becomeFirstResponder()
|
||||
|
@ -29,10 +27,8 @@ object PhyConPlugin: ClientModInitializer, REIPluginV0 {
|
|||
}
|
||||
}
|
||||
|
||||
override fun getPluginIdentifier() = Identifier(MODID, "rei_plugin")
|
||||
|
||||
override fun registerBounds(helper: DisplayHelper) {
|
||||
BaseBoundsHandler.getInstance().registerExclusionZones(AbstractTerminalScreen::class.java) {
|
||||
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)
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package net.shadowfacts.phycon.plugin.rei
|
||||
|
||||
import me.shedaniel.rei.server.ContainerContext
|
||||
import me.shedaniel.rei.server.ContainerInfo
|
||||
import me.shedaniel.rei.server.ContainerInfoHandler
|
||||
import me.shedaniel.rei.server.StackAccessor
|
||||
import me.shedaniel.rei.api.common.display.Display
|
||||
import me.shedaniel.rei.api.common.transfer.info.MenuInfo
|
||||
import net.fabricmc.api.ModInitializer
|
||||
import net.minecraft.util.Identifier
|
||||
import net.shadowfacts.phycon.block.terminal.CraftingTerminalScreenHandler
|
||||
|
@ -14,34 +12,34 @@ import net.shadowfacts.phycon.block.terminal.CraftingTerminalScreenHandler
|
|||
object PhyConPluginCommon: ModInitializer {
|
||||
|
||||
override fun onInitialize() {
|
||||
ContainerInfoHandler.registerContainerInfo(Identifier("minecraft", "plugins/crafting"), TerminalInfo)
|
||||
// ContainerInfoHandler.registerContainerInfo(Identifier("minecraft", "plugins/crafting"), TerminalInfo)
|
||||
}
|
||||
|
||||
object TerminalInfo: ContainerInfo<CraftingTerminalScreenHandler> {
|
||||
override fun getContainerClass() = CraftingTerminalScreenHandler::class.java
|
||||
|
||||
override fun getCraftingResultSlotIndex(container: CraftingTerminalScreenHandler): Int {
|
||||
return container.resultSlot.id
|
||||
}
|
||||
|
||||
override fun getCraftingWidth(container: CraftingTerminalScreenHandler): Int {
|
||||
return 3
|
||||
}
|
||||
|
||||
override fun getCraftingHeight(container: CraftingTerminalScreenHandler): Int {
|
||||
return 3
|
||||
}
|
||||
|
||||
override fun getGridStacks(context: ContainerContext<CraftingTerminalScreenHandler>): List<StackAccessor> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
// object TerminalInfo: ContainerInfo<CraftingTerminalScreenHandler> {
|
||||
// override fun getContainerClass() = CraftingTerminalScreenHandler::class.java
|
||||
//
|
||||
// override fun getCraftingResultSlotIndex(container: CraftingTerminalScreenHandler): Int {
|
||||
// return container.resultSlot.id
|
||||
// }
|
||||
//
|
||||
// override fun getCraftingWidth(container: CraftingTerminalScreenHandler): Int {
|
||||
// return 3
|
||||
// }
|
||||
//
|
||||
// override fun getCraftingHeight(container: CraftingTerminalScreenHandler): Int {
|
||||
// return 3
|
||||
// }
|
||||
//
|
||||
// override fun getGridStacks(context: ContainerContext<CraftingTerminalScreenHandler>): List<StackAccessor> {
|
||||
// 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)
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
"value": "net.shadowfacts.phycon.plugin.rei.PhyConPlugin"
|
||||
}
|
||||
],
|
||||
"rei_plugins": [
|
||||
"rei": [
|
||||
{
|
||||
"adapter": "kotlin",
|
||||
"value": "net.shadowfacts.phycon.plugin.rei.PhyConPlugin"
|
||||
|
@ -39,7 +39,7 @@
|
|||
"fabric": "*",
|
||||
"fabric-language-kotlin": ">=1.3.50",
|
||||
"phycon": "*",
|
||||
"roughlyenoughitems": "^5.0.0"
|
||||
"roughlyenoughitems": "^7.0.0"
|
||||
},
|
||||
|
||||
"custom": {
|
||||
|
|
|
@ -11,11 +11,13 @@ repositories {
|
|||
maven {
|
||||
url = "https://maven.modmuss50.me/"
|
||||
}
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(":")
|
||||
implementation(project(":")) {
|
||||
transitive = false
|
||||
}
|
||||
|
||||
modImplementation("TechReborn:TechReborn-1.16:${project.techreborn_version}") {
|
||||
exclude group: "net.fabricmc.fabric-api"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
pluginManagement {
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
maven {
|
||||
name = 'Fabric'
|
||||
url = 'https://maven.fabricmc.net/'
|
||||
|
@ -12,4 +12,4 @@ pluginManagement {
|
|||
include("kiwi-java")
|
||||
include("plugin:mousewheelie")
|
||||
include("plugin:rei")
|
||||
include("plugin:techreborn")
|
||||
// include("plugin:techreborn")
|
||||
|
|
|
@ -41,7 +41,7 @@ public class MixinHandledScreen {
|
|||
AbstractTerminalScreen<?, ?> self = (AbstractTerminalScreen<?, ?>)(Object)this;
|
||||
AbstractTerminalScreenHandler<?> handler = self.getScreenHandler();
|
||||
if (slot.id < handler.getNetworkSlotsEnd() && stack.getCount() > 1) {
|
||||
self.drawNetworkSlotAmount(stack, x, y, slot, matrixStack);
|
||||
self.drawNetworkSlotAmount(stack, x, y);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package net.shadowfacts.cacao
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen
|
||||
import net.minecraft.client.util.math.MatrixStack
|
||||
import net.minecraft.entity.player.PlayerInventory
|
||||
|
@ -14,6 +13,7 @@ import net.shadowfacts.cacao.util.RenderHelper
|
|||
import net.shadowfacts.cacao.window.ScreenHandlerWindow
|
||||
import net.shadowfacts.cacao.window.Window
|
||||
import org.lwjgl.glfw.GLFW
|
||||
import org.lwjgl.opengl.GL11
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
|
@ -82,8 +82,8 @@ open class CacaoHandledScreen<Handler: ScreenHandler>(
|
|||
override fun render(matrixStack: MatrixStack, mouseX: Int, mouseY: Int, delta: Float) {
|
||||
val mouse = Point(mouseX, mouseY)
|
||||
|
||||
RenderSystem.pushMatrix()
|
||||
RenderSystem.translatef(0f, 0f, -350f)
|
||||
matrixStack.push()
|
||||
matrixStack.translate(0.0, 0.0, -350.0)
|
||||
|
||||
for (i in windows.indices) {
|
||||
val it = windows[i]
|
||||
|
@ -100,7 +100,7 @@ open class CacaoHandledScreen<Handler: ScreenHandler>(
|
|||
super.render(matrixStack, -1, -1, delta)
|
||||
}
|
||||
|
||||
RenderSystem.popMatrix()
|
||||
matrixStack.pop()
|
||||
}
|
||||
|
||||
it.draw(matrixStack, mouse, delta)
|
||||
|
|
|
@ -1,20 +1,21 @@
|
|||
package net.shadowfacts.cacao.util
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager
|
||||
import com.mojang.blaze3d.systems.RenderSystem
|
||||
import net.minecraft.client.MinecraftClient
|
||||
import net.minecraft.client.gui.DrawableHelper
|
||||
import net.minecraft.client.gui.screen.Screen
|
||||
import net.minecraft.client.render.*
|
||||
import net.minecraft.client.sound.PositionedSoundInstance
|
||||
import net.minecraft.client.util.math.MatrixStack
|
||||
import net.minecraft.sound.SoundEvent
|
||||
import net.minecraft.text.LiteralText
|
||||
import net.minecraft.text.OrderedText
|
||||
import net.minecraft.text.Text
|
||||
import net.minecraft.util.math.Matrix4f
|
||||
import net.shadowfacts.cacao.geometry.Point
|
||||
import net.shadowfacts.cacao.geometry.Rect
|
||||
import net.shadowfacts.cacao.util.texture.Texture
|
||||
import org.lwjgl.opengl.GL11
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* Helper methods for rendering using Minecraft's utilities from Cacao views.
|
||||
|
@ -45,18 +46,18 @@ object RenderHelper: DrawableHelper() {
|
|||
*/
|
||||
fun draw(matrixStack: MatrixStack, rect: Rect, texture: Texture) {
|
||||
if (disabled) return
|
||||
color(1f, 1f, 1f, 1f)
|
||||
MinecraftClient.getInstance().textureManager.bindTexture(texture.location)
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader)
|
||||
RenderSystem.setShaderTexture(0, texture.location)
|
||||
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) {
|
||||
if (disabled) return
|
||||
|
||||
GlStateManager.lineWidth(width)
|
||||
RenderSystem.lineWidth(width)
|
||||
val tessellator = Tessellator.getInstance()
|
||||
val buffer = tessellator.buffer
|
||||
buffer.begin(GL11.GL_LINES, VertexFormats.POSITION_COLOR)
|
||||
buffer.begin(VertexFormat.DrawMode.LINES, VertexFormats.POSITION_COLOR)
|
||||
buffer.vertex(start.x, start.y, z).color(color).next()
|
||||
buffer.vertex(end.x, end.y, z).color(color).next()
|
||||
tessellator.draw()
|
||||
|
@ -71,19 +72,19 @@ object RenderHelper: DrawableHelper() {
|
|||
val uEnd = (u + width).toFloat() / textureWidth
|
||||
val vStart = v.toFloat() / textureHeight
|
||||
val vEnd = (v + height).toFloat() / textureHeight
|
||||
drawTexturedQuad(matrixStack.peek().model, x, x + width, y, y + height, 0.0, uStart, uEnd, vStart, vEnd)
|
||||
drawTexturedQuad(matrixStack.peek().positionMatrix, x, x + width, y, y + height, 0.0, uStart, uEnd, vStart, vEnd)
|
||||
}
|
||||
|
||||
// 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) {
|
||||
val bufferBuilder = Tessellator.getInstance().buffer
|
||||
bufferBuilder.begin(GL11.GL_QUADS, VertexFormats.POSITION_TEXTURE)
|
||||
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE)
|
||||
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(), y0.toFloat(), z.toFloat()).texture(u1, v0).next()
|
||||
bufferBuilder.vertex(matrix, x0.toFloat(), y0.toFloat(), z.toFloat()).texture(u0, v0).next()
|
||||
bufferBuilder.end()
|
||||
RenderSystem.enableAlphaTest()
|
||||
BufferRenderer.draw(bufferBuilder)
|
||||
}
|
||||
|
||||
|
@ -95,110 +96,22 @@ object RenderHelper: DrawableHelper() {
|
|||
drawTooltip(matrixStack, texts.map(Text::asOrderedText), mouse)
|
||||
}
|
||||
|
||||
// Based on Screen.renderOrderedTooltip
|
||||
private val dummyScreen = object: Screen(LiteralText("")) {
|
||||
init {
|
||||
textRenderer = MinecraftClient.getInstance().textRenderer
|
||||
itemRenderer = MinecraftClient.getInstance().itemRenderer
|
||||
}
|
||||
}
|
||||
|
||||
@JvmName("drawOrderedTooltip")
|
||||
fun drawTooltip(matrixStack: MatrixStack, texts: List<OrderedText>, mouse: Point) {
|
||||
if (disabled) return
|
||||
if (texts.isEmpty()) return
|
||||
|
||||
val client = MinecraftClient.getInstance()
|
||||
val textRenderer = client.textRenderer
|
||||
|
||||
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)
|
||||
dummyScreen.width = client.window.scaledWidth
|
||||
dummyScreen.height = client.window.scaledHeight
|
||||
dummyScreen.renderOrderedTooltip(matrixStack, texts, mouse.x.roundToInt(), mouse.y.roundToInt())
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -206,7 +119,7 @@ object RenderHelper: DrawableHelper() {
|
|||
*/
|
||||
fun color(r: Float, g: Float, b: Float, alpha: Float) {
|
||||
if (disabled) return
|
||||
RenderSystem.color4f(r, g, b, alpha)
|
||||
RenderSystem.setShaderColor(r, g, b, alpha)
|
||||
}
|
||||
|
||||
private fun VertexConsumer.color(color: Color): VertexConsumer {
|
||||
|
|
|
@ -26,11 +26,13 @@ class BezierCurveView(val curve: BezierCurve): View() {
|
|||
var lineColor = Color.BLACK
|
||||
|
||||
override fun drawContent(matrixStack: MatrixStack, mouse: Point, delta: Float) {
|
||||
RenderHelper.scale(bounds.width, bounds.height)
|
||||
matrixStack.push()
|
||||
matrixStack.scale(bounds.width.toFloat(), bounds.height.toFloat(), 1f)
|
||||
for ((index, point) in points.withIndex()) {
|
||||
val next = points.getOrNull(index + 1) ?: break
|
||||
RenderHelper.drawLine(point, next, zIndex, lineWidth, lineColor)
|
||||
}
|
||||
matrixStack.pop()
|
||||
}
|
||||
|
||||
}
|
|
@ -29,7 +29,7 @@ class DialogView(
|
|||
CANCEL, CONFIRM, OK, CLOSE;
|
||||
|
||||
override val localizedName: Text
|
||||
get() = LiteralText(name.toLowerCase().capitalize()) // todo: actually localize me
|
||||
get() = LiteralText(name.lowercase().replaceFirstChar(Char::titlecase)) // todo: actually localize me
|
||||
}
|
||||
|
||||
private lateinit var background: NinePatchView
|
||||
|
|
|
@ -12,7 +12,6 @@ import no.birkett.kiwi.Constraint
|
|||
import no.birkett.kiwi.Solver
|
||||
import java.lang.RuntimeException
|
||||
import java.util.*
|
||||
import kotlin.collections.HashSet
|
||||
import kotlin.math.floor
|
||||
|
||||
/**
|
||||
|
@ -368,8 +367,8 @@ open class View(): Responder {
|
|||
* @param delta The time since the last frame.
|
||||
*/
|
||||
open fun draw(matrixStack: MatrixStack, mouse: Point, delta: Float) {
|
||||
RenderHelper.pushMatrix()
|
||||
RenderHelper.translate(floor(frame.left), floor(frame.top))
|
||||
matrixStack.push()
|
||||
matrixStack.translate(frame.left, frame.top, 0.0)
|
||||
|
||||
RenderHelper.fill(matrixStack, bounds, backgroundColor)
|
||||
|
||||
|
@ -380,7 +379,7 @@ open class View(): Responder {
|
|||
it.draw(matrixStack, mouseInView, delta)
|
||||
}
|
||||
|
||||
RenderHelper.popMatrix()
|
||||
matrixStack.pop()
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -109,8 +109,8 @@ abstract class AbstractButton<Impl: AbstractButton<Impl>>(val content: View, val
|
|||
}
|
||||
|
||||
override fun draw(matrixStack: MatrixStack, mouse: Point, delta: Float) {
|
||||
RenderHelper.pushMatrix()
|
||||
RenderHelper.translate(floor(frame.left), floor(frame.top))
|
||||
matrixStack.push()
|
||||
matrixStack.translate(frame.left, frame.top, 0.0)
|
||||
|
||||
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
|
||||
|
||||
RenderHelper.popMatrix()
|
||||
matrixStack.pop()
|
||||
|
||||
if (tooltip != null && mouse in bounds) {
|
||||
window!!.drawTooltip(listOf(tooltip!!))
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
package net.shadowfacts.cacao.view.textfield
|
||||
|
||||
import net.minecraft.client.MinecraftClient
|
||||
import net.minecraft.client.gui.screen.TickableElement
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget
|
||||
import net.minecraft.client.util.math.MatrixStack
|
||||
import net.minecraft.text.LiteralText
|
||||
import net.shadowfacts.cacao.geometry.Point
|
||||
import net.shadowfacts.cacao.util.Color
|
||||
import net.shadowfacts.cacao.util.KeyModifiers
|
||||
import net.shadowfacts.cacao.util.MouseButton
|
||||
import net.shadowfacts.cacao.util.RenderHelper
|
||||
import net.shadowfacts.cacao.view.View
|
||||
import net.shadowfacts.phycon.mixin.client.TextFieldWidgetAccessor
|
||||
import org.lwjgl.glfw.GLFW
|
||||
|
@ -25,7 +22,7 @@ import org.lwjgl.glfw.GLFW
|
|||
*/
|
||||
abstract class AbstractTextField<Impl: AbstractTextField<Impl>>(
|
||||
initialText: String
|
||||
): View(), TickableElement {
|
||||
): View() {
|
||||
|
||||
/**
|
||||
* A function that is invoked when the text in this text field changes.
|
||||
|
@ -70,7 +67,7 @@ abstract class AbstractTextField<Impl: AbstractTextField<Impl>>(
|
|||
var drawBackground = true
|
||||
set(value) {
|
||||
field = value
|
||||
minecraftWidget.setHasBorder(value)
|
||||
minecraftWidget.setDrawsBackground(value)
|
||||
}
|
||||
|
||||
private lateinit var originInWindow: Point
|
||||
|
@ -79,7 +76,7 @@ abstract class AbstractTextField<Impl: AbstractTextField<Impl>>(
|
|||
init {
|
||||
minecraftWidget.text = initialText
|
||||
minecraftWidget.setTextPredicate { this.validate(it) }
|
||||
minecraftWidget.setHasBorder(drawBackground)
|
||||
minecraftWidget.setDrawsBackground(drawBackground)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,14 +100,14 @@ abstract class AbstractTextField<Impl: AbstractTextField<Impl>>(
|
|||
}
|
||||
|
||||
override fun drawContent(matrixStack: MatrixStack, mouse: Point, delta: Float) {
|
||||
RenderHelper.pushMatrix()
|
||||
RenderHelper.translate(-originInWindow.x, -originInWindow.y)
|
||||
matrixStack.push()
|
||||
matrixStack.translate(-originInWindow.x, -originInWindow.y, 0.0)
|
||||
|
||||
val mouseXInWindow = (mouse.x + originInWindow.x).toInt()
|
||||
val mouseYInWindow = (mouse.y + originInWindow.y).toInt()
|
||||
minecraftWidget.render(matrixStack, mouseXInWindow, mouseYInWindow, delta)
|
||||
|
||||
RenderHelper.popMatrix()
|
||||
matrixStack.pop()
|
||||
}
|
||||
|
||||
override fun mouseClicked(point: Point, mouseButton: MouseButton): Boolean {
|
||||
|
@ -135,12 +132,12 @@ abstract class AbstractTextField<Impl: AbstractTextField<Impl>>(
|
|||
|
||||
override fun didBecomeFirstResponder() {
|
||||
super.didBecomeFirstResponder()
|
||||
minecraftWidget.setSelected(true)
|
||||
minecraftWidget.setTextFieldFocused(true)
|
||||
}
|
||||
|
||||
override fun didResignFirstResponder() {
|
||||
super.didResignFirstResponder()
|
||||
minecraftWidget.setSelected(false)
|
||||
minecraftWidget.setTextFieldFocused(false)
|
||||
}
|
||||
|
||||
override fun charTyped(char: Char, modifiers: KeyModifiers): Boolean {
|
||||
|
@ -164,7 +161,7 @@ abstract class AbstractTextField<Impl: AbstractTextField<Impl>>(
|
|||
return result || (isFirstResponder && keyCode != GLFW.GLFW_KEY_ESCAPE)
|
||||
}
|
||||
|
||||
override fun tick() {
|
||||
fun tick() {
|
||||
minecraftWidget.tick()
|
||||
}
|
||||
|
||||
|
|
|
@ -2,15 +2,20 @@ package net.shadowfacts.phycon.block
|
|||
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.block.BlockEntityProvider
|
||||
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.util.math.BlockPos
|
||||
import net.minecraft.world.BlockView
|
||||
import net.minecraft.world.World
|
||||
|
||||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
abstract class BlockWithEntity<T: BlockEntity>(settings: Settings): Block(settings), BlockEntityProvider {
|
||||
abstract override fun createBlockEntity(world: BlockView): T?
|
||||
abstract override fun createBlockEntity(pos: BlockPos, state: BlockState): T?
|
||||
|
||||
fun getBlockEntity(world: BlockView, pos: BlockPos): T? {
|
||||
val entity = world.getBlockEntity(pos)
|
||||
return if (entity != null) {
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package net.shadowfacts.phycon.block
|
||||
|
||||
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.util.math.BlockPos
|
||||
import net.minecraft.util.math.Direction
|
||||
|
@ -25,4 +28,14 @@ abstract class DeviceBlock<T: DeviceBlockEntity>(settings: Settings): BlockWithE
|
|||
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,34 +1,32 @@
|
|||
package net.shadowfacts.phycon.block
|
||||
|
||||
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.block.entity.BlockEntity
|
||||
import net.minecraft.block.entity.BlockEntityType
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.util.Tickable
|
||||
import net.minecraft.nbt.NbtCompound
|
||||
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.shadowfacts.phycon.PhysicalConnectivity
|
||||
import net.shadowfacts.phycon.api.PacketSink
|
||||
import net.shadowfacts.phycon.api.PacketSource
|
||||
import net.shadowfacts.phycon.api.Interface
|
||||
import net.shadowfacts.phycon.api.NetworkComponentBlock
|
||||
import net.shadowfacts.phycon.api.PacketSink
|
||||
import net.shadowfacts.phycon.api.PacketSource
|
||||
import net.shadowfacts.phycon.api.frame.EthernetFrame
|
||||
import net.shadowfacts.phycon.api.frame.PacketFrame
|
||||
import net.shadowfacts.phycon.api.packet.Packet
|
||||
import net.shadowfacts.phycon.api.util.IPAddress
|
||||
import net.shadowfacts.phycon.api.util.MACAddress
|
||||
import net.shadowfacts.phycon.util.NetworkUtil
|
||||
import net.shadowfacts.phycon.frame.ARPQueryFrame
|
||||
import net.shadowfacts.phycon.frame.ARPResponseFrame
|
||||
import net.shadowfacts.phycon.frame.BasePacketFrame
|
||||
import net.shadowfacts.phycon.packet.*
|
||||
import net.shadowfacts.phycon.util.NetworkUtil
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
abstract class DeviceBlockEntity(type: BlockEntityType<*>): BlockEntity(type),
|
||||
BlockEntityClientSerializable,
|
||||
Tickable,
|
||||
abstract class DeviceBlockEntity(type: BlockEntityType<*>, pos: BlockPos, state: BlockState): BlockEntity(type, pos, state),
|
||||
PacketSink,
|
||||
PacketSource,
|
||||
Interface {
|
||||
|
@ -126,7 +124,7 @@ abstract class DeviceBlockEntity(type: BlockEntityType<*>): BlockEntity(type),
|
|||
}
|
||||
}
|
||||
|
||||
override fun tick() {
|
||||
open fun tick() {
|
||||
counter++
|
||||
|
||||
if (!world!!.isClient) {
|
||||
|
@ -148,33 +146,50 @@ abstract class DeviceBlockEntity(type: BlockEntityType<*>): BlockEntity(type),
|
|||
}
|
||||
}
|
||||
|
||||
protected open fun toCommonTag(tag: CompoundTag) {
|
||||
protected open fun toCommonTag(tag: NbtCompound) {
|
||||
tag.putInt("IPAddress", ipAddress.address)
|
||||
tag.putLong("MACAddress", macAddress.address)
|
||||
}
|
||||
|
||||
protected open fun fromCommonTag(tag: CompoundTag) {
|
||||
protected open fun fromCommonTag(tag: NbtCompound) {
|
||||
ipAddress = IPAddress(tag.getInt("IPAddress"))
|
||||
macAddress = MACAddress(tag.getLong("MACAddress"))
|
||||
}
|
||||
|
||||
override fun toTag(tag: CompoundTag): CompoundTag {
|
||||
override fun writeNbt(tag: NbtCompound) {
|
||||
super.writeNbt(tag)
|
||||
toCommonTag(tag)
|
||||
return super.toTag(tag)
|
||||
}
|
||||
|
||||
override fun fromTag(state: BlockState, tag: CompoundTag) {
|
||||
super.fromTag(state, tag)
|
||||
override fun readNbt(tag: NbtCompound) {
|
||||
super.readNbt(tag)
|
||||
fromCommonTag(tag)
|
||||
if (tag.getBoolean("_SyncPacket")) {
|
||||
fromClientTag(tag)
|
||||
}
|
||||
}
|
||||
|
||||
override fun toClientTag(tag: CompoundTag): CompoundTag {
|
||||
override fun toUpdatePacket(): BlockEntityUpdateS2CPacket {
|
||||
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)
|
||||
return tag
|
||||
}
|
||||
|
||||
override fun fromClientTag(tag: CompoundTag) {
|
||||
fromCommonTag(tag)
|
||||
open fun fromClientTag(tag: NbtCompound) {
|
||||
}
|
||||
|
||||
fun markUpdate() {
|
||||
markDirty()
|
||||
world!!.updateListeners(pos, cachedState, cachedState, 3)
|
||||
}
|
||||
|
||||
fun onBreak() {
|
||||
|
|
|
@ -42,7 +42,7 @@ class CableBlock(
|
|||
), NetworkCableBlock {
|
||||
companion object {
|
||||
val ID = Identifier(PhysicalConnectivity.MODID, "cable")
|
||||
val CABLE_MATERIAL = Material.Builder(MaterialColor.BLUE).build()
|
||||
val CABLE_MATERIAL = Material.Builder(MapColor.BLUE).build()
|
||||
val CENTER_SHAPE = createCuboidShape(6.0, 6.0, 6.0, 10.0, 10.0, 10.0)
|
||||
val SIDE_SHAPES = mapOf<Direction, VoxelShape>(
|
||||
Direction.DOWN to createCuboidShape(6.0, 0.0, 6.0, 10.0, 6.0, 10.0),
|
||||
|
|
|
@ -15,6 +15,8 @@ import net.minecraft.world.BlockView
|
|||
import net.minecraft.world.World
|
||||
import net.shadowfacts.phycon.PhysicalConnectivity
|
||||
import net.shadowfacts.phycon.block.FaceDeviceBlock
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
/**
|
||||
* @author shadowfacts
|
||||
|
@ -57,7 +59,7 @@ class ExtractorBlock: FaceDeviceBlock<ExtractorBlockEntity>(
|
|||
arr[i] = 16.0 - arr[i]
|
||||
}
|
||||
}
|
||||
createCuboidShape(arr[0], arr[1], arr[2], arr[3], arr[4], arr[5])
|
||||
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]))
|
||||
}
|
||||
EXTRACTOR_SHAPES[dir] = shapes.reduce { a, b -> VoxelShapes.union(a, b) }
|
||||
}
|
||||
|
@ -67,7 +69,7 @@ class ExtractorBlock: FaceDeviceBlock<ExtractorBlockEntity>(
|
|||
override val faceThickness = 6.0
|
||||
override val faceShapes: Map<Direction, VoxelShape> = EXTRACTOR_SHAPES
|
||||
|
||||
override fun createBlockEntity(world: BlockView) = ExtractorBlockEntity()
|
||||
override fun createBlockEntity(pos: BlockPos, state: BlockState) = ExtractorBlockEntity(pos, state)
|
||||
|
||||
override fun onPlaced(world: World, pos: BlockPos, state: BlockState, entity: LivingEntity?, stack: ItemStack) {
|
||||
if (!world.isClient) {
|
||||
|
|
|
@ -5,8 +5,10 @@ import alexiil.mc.lib.attributes.Simulation
|
|||
import alexiil.mc.lib.attributes.item.FixedItemInv
|
||||
import alexiil.mc.lib.attributes.item.ItemAttributes
|
||||
import alexiil.mc.lib.attributes.item.filter.ExactItemStackFilter
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.NbtCompound
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.util.math.Direction
|
||||
import net.shadowfacts.phycon.api.packet.Packet
|
||||
import net.shadowfacts.phycon.init.PhyBlockEntities
|
||||
|
@ -26,7 +28,7 @@ import kotlin.properties.Delegates
|
|||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
class ExtractorBlockEntity: DeviceBlockEntity(PhyBlockEntities.EXTRACTOR),
|
||||
class ExtractorBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockEntity(PhyBlockEntities.EXTRACTOR, pos, state),
|
||||
NetworkStackDispatcher<ExtractorBlockEntity.PendingInsertion>,
|
||||
ActivationController.ActivatableDevice,
|
||||
ClientConfigurableDevice {
|
||||
|
@ -106,21 +108,21 @@ class ExtractorBlockEntity: DeviceBlockEntity(PhyBlockEntities.EXTRACTOR),
|
|||
return false
|
||||
}
|
||||
|
||||
override fun toCommonTag(tag: CompoundTag) {
|
||||
override fun toCommonTag(tag: NbtCompound) {
|
||||
super.toCommonTag(tag)
|
||||
writeDeviceConfiguration(tag)
|
||||
}
|
||||
|
||||
override fun fromCommonTag(tag: CompoundTag) {
|
||||
override fun fromCommonTag(tag: NbtCompound) {
|
||||
super.fromCommonTag(tag)
|
||||
loadDeviceConfiguration(tag)
|
||||
}
|
||||
|
||||
override fun writeDeviceConfiguration(tag: CompoundTag) {
|
||||
override fun writeDeviceConfiguration(tag: NbtCompound) {
|
||||
tag.putString("ActivationMode", controller.activationMode.name)
|
||||
}
|
||||
|
||||
override fun loadDeviceConfiguration(tag: CompoundTag) {
|
||||
override fun loadDeviceConfiguration(tag: NbtCompound) {
|
||||
controller.activationMode = ActivationMode.valueOf(tag.getString("ActivationMode"))
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@ import net.minecraft.world.World
|
|||
import net.shadowfacts.phycon.PhysicalConnectivity
|
||||
import net.shadowfacts.phycon.block.FaceDeviceBlock
|
||||
import java.util.*
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
/**
|
||||
* @author shadowfacts
|
||||
|
@ -66,7 +68,7 @@ class InserterBlock: FaceDeviceBlock<InserterBlockEntity>(
|
|||
arr[i] = 16.0 - arr[i]
|
||||
}
|
||||
}
|
||||
createCuboidShape(arr[0], arr[1], arr[2], arr[3], arr[4], arr[5])
|
||||
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]))
|
||||
}
|
||||
INSERTER_SHAPES[dir] = shapes.reduce { a, b -> VoxelShapes.union(a, b) }
|
||||
}
|
||||
|
@ -76,7 +78,7 @@ class InserterBlock: FaceDeviceBlock<InserterBlockEntity>(
|
|||
override val faceThickness = 6.0
|
||||
override val faceShapes: Map<Direction, VoxelShape> = INSERTER_SHAPES
|
||||
|
||||
override fun createBlockEntity(world: BlockView) = InserterBlockEntity()
|
||||
override fun createBlockEntity(pos: BlockPos, state: BlockState) = InserterBlockEntity(pos, state)
|
||||
|
||||
override fun onPlaced(world: World, pos: BlockPos, state: BlockState, entity: LivingEntity?, stack: ItemStack) {
|
||||
if (!world.isClient) {
|
||||
|
@ -94,7 +96,7 @@ class InserterBlock: FaceDeviceBlock<InserterBlockEntity>(
|
|||
if (!world.isClient) {
|
||||
val be = getBlockEntity(world, pos)!!
|
||||
|
||||
be.sync()
|
||||
be.markUpdate()
|
||||
|
||||
val factory = object: ExtendedScreenHandlerFactory {
|
||||
override fun createMenu(syncId: Int, playerInv: PlayerInventory, player: PlayerEntity): ScreenHandler {
|
||||
|
|
|
@ -5,8 +5,10 @@ import alexiil.mc.lib.attributes.Simulation
|
|||
import alexiil.mc.lib.attributes.item.ItemAttributes
|
||||
import alexiil.mc.lib.attributes.item.ItemInsertable
|
||||
import alexiil.mc.lib.attributes.item.ItemStackUtil
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.NbtCompound
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.util.math.Direction
|
||||
import net.shadowfacts.phycon.api.packet.Packet
|
||||
import net.shadowfacts.phycon.block.DeviceBlockEntity
|
||||
|
@ -25,7 +27,7 @@ import kotlin.math.min
|
|||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
class InserterBlockEntity: DeviceBlockEntity(PhyBlockEntities.INSERTER),
|
||||
class InserterBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockEntity(PhyBlockEntities.INSERTER, pos, state),
|
||||
ItemStackPacketHandler,
|
||||
ActivationController.ActivatableDevice,
|
||||
ClientConfigurableDevice,
|
||||
|
@ -132,24 +134,24 @@ class InserterBlockEntity: DeviceBlockEntity(PhyBlockEntities.INSERTER),
|
|||
currentRequest = null
|
||||
}
|
||||
|
||||
override fun toCommonTag(tag: CompoundTag) {
|
||||
override fun toCommonTag(tag: NbtCompound) {
|
||||
super.toCommonTag(tag)
|
||||
writeDeviceConfiguration(tag)
|
||||
tag.put("StackToExtract", stackToExtract.toTag(CompoundTag()))
|
||||
tag.put("StackToExtract", stackToExtract.writeNbt(NbtCompound()))
|
||||
}
|
||||
|
||||
override fun fromCommonTag(tag: CompoundTag) {
|
||||
override fun fromCommonTag(tag: NbtCompound) {
|
||||
super.fromCommonTag(tag)
|
||||
loadDeviceConfiguration(tag)
|
||||
stackToExtract = ItemStack.fromTag(tag.getCompound("StackToExtract"))
|
||||
stackToExtract = ItemStack.fromNbt(tag.getCompound("StackToExtract"))
|
||||
}
|
||||
|
||||
override fun writeDeviceConfiguration(tag: CompoundTag) {
|
||||
override fun writeDeviceConfiguration(tag: NbtCompound) {
|
||||
tag.putString("ActivationMode", controller.activationMode.name)
|
||||
tag.putInt("AmountToExtract", amountToExtract)
|
||||
}
|
||||
|
||||
override fun loadDeviceConfiguration(tag: CompoundTag) {
|
||||
override fun loadDeviceConfiguration(tag: NbtCompound) {
|
||||
controller.activationMode = ActivationMode.valueOf(tag.getString("ActivationMode"))
|
||||
amountToExtract = tag.getInt("AmountToExtract")
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.shadowfacts.phycon.block.inserter
|
|||
import com.mojang.blaze3d.systems.RenderSystem
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget
|
||||
import net.minecraft.client.render.GameRenderer
|
||||
import net.minecraft.client.util.math.MatrixStack
|
||||
import net.minecraft.entity.player.PlayerInventory
|
||||
import net.minecraft.screen.slot.Slot
|
||||
|
@ -44,9 +45,9 @@ class InserterScreen(
|
|||
|
||||
amountField = TextFieldWidget(textRenderer, x + 57, y + 24, 80, 9, LiteralText("Amount"))
|
||||
amountField.text = handler.inserter.amountToExtract.toString()
|
||||
amountField.setHasBorder(false)
|
||||
amountField.setDrawsBackground(false)
|
||||
amountField.isVisible = true
|
||||
amountField.setSelected(true)
|
||||
amountField.setTextFieldFocused(true)
|
||||
amountField.setEditableColor(0xffffff)
|
||||
amountField.setTextPredicate {
|
||||
if (it.isEmpty()) {
|
||||
|
@ -60,7 +61,7 @@ class InserterScreen(
|
|||
}
|
||||
}
|
||||
}
|
||||
addChild(amountField)
|
||||
addDrawableChild(amountField)
|
||||
}
|
||||
|
||||
fun amountUpdated() {
|
||||
|
@ -70,16 +71,16 @@ class InserterScreen(
|
|||
}
|
||||
}
|
||||
|
||||
override fun tick() {
|
||||
super.tick()
|
||||
override fun handledScreenTick() {
|
||||
super.handledScreenTick()
|
||||
amountField.tick()
|
||||
}
|
||||
|
||||
override fun drawBackground(matrixStack: MatrixStack, delta: Float, mouseX: Int, mouseY: Int) {
|
||||
renderBackground(matrixStack)
|
||||
|
||||
RenderSystem.color4f(1f, 1f, 1f, 1f)
|
||||
client!!.textureManager.bindTexture(BACKGROUND)
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader)
|
||||
RenderSystem.setShaderTexture(0, BACKGROUND)
|
||||
val x = (width - backgroundWidth) / 2
|
||||
val y = (height - backgroundHeight) / 2
|
||||
drawTexture(matrixStack, x, y, 0, 0, backgroundWidth, backgroundHeight)
|
||||
|
@ -96,7 +97,7 @@ class InserterScreen(
|
|||
override fun onMouseClick(slot: Slot?, invSlot: Int, clickData: Int, slotActionType: SlotActionType?) {
|
||||
super.onMouseClick(slot, invSlot, clickData, slotActionType)
|
||||
|
||||
amountField.setSelected(true)
|
||||
amountField.setTextFieldFocused(true)
|
||||
}
|
||||
|
||||
override fun charTyped(c: Char, i: Int): Boolean {
|
||||
|
|
|
@ -60,17 +60,17 @@ class InserterScreenHandler(
|
|||
return true
|
||||
}
|
||||
|
||||
override fun onSlotClick(slotId: Int, clickData: Int, actionType: SlotActionType, player: PlayerEntity): ItemStack {
|
||||
override fun onSlotClick(slotId: Int, clickData: Int, actionType: SlotActionType, player: PlayerEntity) {
|
||||
// fake slot
|
||||
if (slotId == 0) {
|
||||
if (player.inventory.cursorStack.isEmpty) {
|
||||
if (cursorStack.isEmpty) {
|
||||
inserter.stackToExtract = ItemStack.EMPTY
|
||||
} else {
|
||||
inserter.stackToExtract = player.inventory.cursorStack.copyWithCount(1)
|
||||
inserter.stackToExtract = cursorStack.copyWithCount(1)
|
||||
}
|
||||
stackToExtractChanged()
|
||||
}
|
||||
return super.onSlotClick(slotId, clickData, actionType, player)
|
||||
super.onSlotClick(slotId, clickData, actionType, player)
|
||||
}
|
||||
|
||||
override fun transferSlot(player: PlayerEntity, slotId: Int): ItemStack {
|
||||
|
|
|
@ -51,7 +51,7 @@ class MinerBlock: DeviceBlock<MinerBlockEntity>(
|
|||
builder.add(FACING)
|
||||
}
|
||||
|
||||
override fun createBlockEntity(world: BlockView) = MinerBlockEntity()
|
||||
override fun createBlockEntity(pos: BlockPos, state: BlockState) = MinerBlockEntity(pos, state)
|
||||
|
||||
override fun getPlacementState(context: ItemPlacementContext): BlockState? {
|
||||
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.item.ItemStack
|
||||
import net.minecraft.item.Items
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.NbtCompound
|
||||
import net.minecraft.server.world.ServerWorld
|
||||
import net.minecraft.text.TranslatableText
|
||||
import net.minecraft.util.math.BlockPos
|
||||
|
@ -27,7 +27,7 @@ import kotlin.math.min
|
|||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
class MinerBlockEntity: DeviceBlockEntity(PhyBlockEntities.MINER),
|
||||
class MinerBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockEntity(PhyBlockEntities.MINER, pos, state),
|
||||
NetworkStackProvider,
|
||||
NetworkStackDispatcher<MinerBlockEntity.PendingInsertion>,
|
||||
ActivationController.ActivatableDevice,
|
||||
|
@ -156,23 +156,23 @@ class MinerBlockEntity: DeviceBlockEntity(PhyBlockEntities.MINER),
|
|||
return minerMode == MinerMode.ON_DEMAND
|
||||
}
|
||||
|
||||
override fun toCommonTag(tag: CompoundTag) {
|
||||
override fun toCommonTag(tag: NbtCompound) {
|
||||
super.toCommonTag(tag)
|
||||
writeDeviceConfiguration(tag)
|
||||
}
|
||||
|
||||
override fun fromCommonTag(tag: CompoundTag) {
|
||||
override fun fromCommonTag(tag: NbtCompound) {
|
||||
super.fromCommonTag(tag)
|
||||
loadDeviceConfiguration(tag)
|
||||
}
|
||||
|
||||
override fun writeDeviceConfiguration(tag: CompoundTag) {
|
||||
override fun writeDeviceConfiguration(tag: NbtCompound) {
|
||||
tag.putString("MinerMode", minerMode.name)
|
||||
tag.putString("ActivationMode", controller.activationMode.name)
|
||||
tag.putInt("ProviderPriority", providerPriority)
|
||||
}
|
||||
|
||||
override fun loadDeviceConfiguration(tag: CompoundTag) {
|
||||
override fun loadDeviceConfiguration(tag: NbtCompound) {
|
||||
minerMode = MinerMode.valueOf(tag.getString("MinerMode"))
|
||||
controller.activationMode = ActivationMode.valueOf(tag.getString("ActivationMode"))
|
||||
providerPriority = tag.getInt("ProviderPriority")
|
||||
|
@ -181,7 +181,7 @@ class MinerBlockEntity: DeviceBlockEntity(PhyBlockEntities.MINER),
|
|||
enum class MinerMode {
|
||||
ON_DEMAND, AUTOMATIC;
|
||||
|
||||
val friendlyName = TranslatableText("gui.phycon.miner_mode.${name.toLowerCase()}")
|
||||
val friendlyName = TranslatableText("gui.phycon.miner_mode.${name.lowercase()}")
|
||||
}
|
||||
|
||||
class MinerInvProxy(val miner: MinerBlockEntity): GroupedItemInvView {
|
||||
|
@ -205,7 +205,8 @@ class MinerBlockEntity: DeviceBlockEntity(PhyBlockEntities.MINER),
|
|||
// todo: does BlockState.equals actually work or is reference equality fine for BlockStates?
|
||||
if (cachedDrops == null || realState != cachedState || recalculate) {
|
||||
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)
|
||||
}
|
||||
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)
|
||||
)
|
||||
|
||||
override fun createBlockEntity(world: BlockView) = InterfaceBlockEntity()
|
||||
override fun createBlockEntity(pos: BlockPos, state: BlockState) = InterfaceBlockEntity(pos, state)
|
||||
|
||||
override fun onPlaced(world: World, pos: BlockPos, state: BlockState, placer: LivingEntity?, stack: ItemStack) {
|
||||
if (!world.isClient) {
|
||||
|
|
|
@ -6,7 +6,8 @@ import alexiil.mc.lib.attributes.item.GroupedItemInv
|
|||
import alexiil.mc.lib.attributes.item.ItemAttributes
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.NbtCompound
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.util.math.Direction
|
||||
import net.shadowfacts.phycon.api.packet.Packet
|
||||
import net.shadowfacts.phycon.init.PhyBlockEntities
|
||||
|
@ -23,7 +24,7 @@ import kotlin.math.min
|
|||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
class InterfaceBlockEntity: DeviceBlockEntity(PhyBlockEntities.INTERFACE),
|
||||
class InterfaceBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockEntity(PhyBlockEntities.INTERFACE, pos, state),
|
||||
ItemStackPacketHandler,
|
||||
NetworkStackProvider,
|
||||
NetworkStackReceiver,
|
||||
|
@ -109,23 +110,23 @@ class InterfaceBlockEntity: DeviceBlockEntity(PhyBlockEntities.INTERFACE),
|
|||
}
|
||||
}
|
||||
|
||||
override fun toCommonTag(tag: CompoundTag) {
|
||||
override fun toCommonTag(tag: NbtCompound) {
|
||||
super.toCommonTag(tag)
|
||||
writeDeviceConfiguration(tag)
|
||||
}
|
||||
|
||||
override fun fromCommonTag(tag: CompoundTag) {
|
||||
override fun fromCommonTag(tag: NbtCompound) {
|
||||
super.fromCommonTag(tag)
|
||||
loadDeviceConfiguration(tag)
|
||||
}
|
||||
|
||||
override fun writeDeviceConfiguration(tag: CompoundTag) {
|
||||
override fun writeDeviceConfiguration(tag: NbtCompound) {
|
||||
tag.putInt("ProviderPriority", providerPriority)
|
||||
tag.putInt("ReceiverPriority", receiverPriority)
|
||||
tag.putBoolean("SyncPriorities", syncPriorities)
|
||||
}
|
||||
|
||||
override fun loadDeviceConfiguration(tag: CompoundTag) {
|
||||
override fun loadDeviceConfiguration(tag: NbtCompound) {
|
||||
providerPriority = tag.getInt("ProviderPriority")
|
||||
receiverPriority = tag.getInt("ReceiverPriority")
|
||||
syncPriorities = tag.getBoolean("SyncPriorities")
|
||||
|
|
|
@ -4,6 +4,9 @@ import alexiil.mc.lib.attributes.AttributeList
|
|||
import alexiil.mc.lib.attributes.AttributeProvider
|
||||
import net.minecraft.block.BlockState
|
||||
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.util.Identifier
|
||||
import net.minecraft.util.math.BlockPos
|
||||
|
@ -40,7 +43,17 @@ class SwitchBlock: BlockWithEntity<SwitchBlockEntity>(
|
|||
return getBlockEntity(world, pos)?.interfaces?.find { it.side == side }
|
||||
}
|
||||
|
||||
override fun createBlockEntity(world: BlockView) = SwitchBlockEntity()
|
||||
override fun createBlockEntity(pos: BlockPos, state: BlockState) = SwitchBlockEntity(pos, state)
|
||||
|
||||
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<*>) {
|
||||
to.offer(getBlockEntity(world, pos))
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
package net.shadowfacts.phycon.block.netswitch
|
||||
|
||||
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.block.entity.BlockEntity
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.ListTag
|
||||
import net.minecraft.util.Tickable
|
||||
import net.minecraft.nbt.NbtCompound
|
||||
import net.minecraft.nbt.NbtList
|
||||
import net.minecraft.network.Packet
|
||||
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.shadowfacts.phycon.PhysicalConnectivity
|
||||
import net.shadowfacts.phycon.api.Interface
|
||||
|
@ -25,9 +27,7 @@ import java.util.LinkedList
|
|||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
class SwitchBlockEntity: BlockEntity(PhyBlockEntities.SWITCH),
|
||||
BlockEntityClientSerializable,
|
||||
Tickable {
|
||||
class SwitchBlockEntity(pos: BlockPos, state: BlockState): BlockEntity(PhyBlockEntities.SWITCH, pos, state) {
|
||||
|
||||
companion object {
|
||||
var SWITCHING_CAPACITY = 256 // 256 packets/tick
|
||||
|
@ -82,7 +82,7 @@ class SwitchBlockEntity: BlockEntity(PhyBlockEntities.SWITCH),
|
|||
return NetworkUtil.findConnectedInterface(world!!, pos, side)
|
||||
}
|
||||
|
||||
override fun tick() {
|
||||
fun tick() {
|
||||
packetsHandledThisTick = 0
|
||||
|
||||
while (delayedPackets.isNotEmpty() && packetsHandledThisTick <= SWITCHING_CAPACITY) {
|
||||
|
@ -91,39 +91,41 @@ class SwitchBlockEntity: BlockEntity(PhyBlockEntities.SWITCH),
|
|||
}
|
||||
}
|
||||
|
||||
override fun toTag(tag: CompoundTag): CompoundTag {
|
||||
override fun writeNbt(tag: NbtCompound) {
|
||||
super.writeNbt(tag)
|
||||
|
||||
tag.putLongArray("InterfaceAddresses", interfaces.map { it.macAddress.address })
|
||||
val list = ListTag()
|
||||
val list = NbtList()
|
||||
for ((frame, fromItf) in delayedPackets) {
|
||||
val packet = frame.packet
|
||||
if (packet !is ItemStackPacket) continue
|
||||
val compound = CompoundTag()
|
||||
val compound = NbtCompound()
|
||||
compound.putInt("FromItfSide", fromItf.side.ordinal)
|
||||
compound.putInt("SourceIP", packet.source.address)
|
||||
compound.putInt("DestinationIP", packet.destination.address)
|
||||
compound.putLong("SourceMAC", frame.source.address)
|
||||
compound.putLong("DestinationMAC", frame.destination.address)
|
||||
compound.put("Stack", packet.stack.toTag(CompoundTag()))
|
||||
compound.put("Stack", packet.stack.writeNbt(NbtCompound()))
|
||||
list.add(compound)
|
||||
}
|
||||
tag.put("DelayedStackPackets", list)
|
||||
return super.toTag(tag)
|
||||
}
|
||||
|
||||
override fun fromTag(state: BlockState, tag: CompoundTag) {
|
||||
super.fromTag(state, tag)
|
||||
override fun readNbt(tag: NbtCompound) {
|
||||
super.readNbt(tag)
|
||||
|
||||
tag.getLongArray("InterfaceAddresses")?.forEachIndexed { i, l ->
|
||||
interfaces[i].macAddress = MACAddress(l)
|
||||
}
|
||||
tag.getList("DelayedStackPackets", 10).forEach { it ->
|
||||
val compound = it as CompoundTag
|
||||
val compound = it as NbtCompound
|
||||
val fromItfSide = Direction.values()[compound.getInt("FromItfSide")]
|
||||
val fromItf = interfaces.find { it.side == fromItfSide }!!
|
||||
val sourceIP = IPAddress(compound.getInt("SourceIP"))
|
||||
val destinationIP = IPAddress(compound.getInt("DestinationIP"))
|
||||
val sourceMAC = MACAddress(compound.getLong("SourceMAC"))
|
||||
val destinationMAC = MACAddress(compound.getLong("DestinationMAC"))
|
||||
val stack = ItemStack.fromTag(compound.getCompound("Stack"))
|
||||
val stack = ItemStack.fromNbt(compound.getCompound("Stack"))
|
||||
if (!stack.isEmpty) {
|
||||
val packet = ItemStackPacket(stack, sourceIP, destinationIP)
|
||||
val frame = BasePacketFrame(packet, sourceMAC, destinationMAC)
|
||||
|
@ -132,15 +134,14 @@ class SwitchBlockEntity: BlockEntity(PhyBlockEntities.SWITCH),
|
|||
}
|
||||
}
|
||||
|
||||
override fun toClientTag(tag: CompoundTag): CompoundTag {
|
||||
tag.putLongArray("InterfaceAddresses", interfaces.map { it.macAddress.address })
|
||||
return tag
|
||||
override fun toUpdatePacket(): Packet<ClientPlayPacketListener>? {
|
||||
return BlockEntityUpdateS2CPacket.create(this)
|
||||
}
|
||||
|
||||
override fun fromClientTag(tag: CompoundTag) {
|
||||
tag.getLongArray("InterfaceAddresses")?.forEachIndexed { i, l ->
|
||||
interfaces[i].macAddress = MACAddress(l)
|
||||
}
|
||||
override fun toInitialChunkDataNbt(): NbtCompound {
|
||||
val tag = NbtCompound()
|
||||
tag.putLongArray("InterfaceAddresses", interfaces.map { it.macAddress.address })
|
||||
return tag
|
||||
}
|
||||
|
||||
class SwitchInterface(
|
||||
|
|
|
@ -44,7 +44,7 @@ class RedstoneControllerBlock: FaceDeviceBlock<RedstoneControllerBlockEntity>(
|
|||
builder.add(POWERED)
|
||||
}
|
||||
|
||||
override fun createBlockEntity(world: BlockView) = RedstoneControllerBlockEntity()
|
||||
override fun createBlockEntity(pos: BlockPos, state: BlockState) = RedstoneControllerBlockEntity(pos, state)
|
||||
|
||||
override fun getPlacementState(context: ItemPlacementContext): BlockState {
|
||||
val state = super.getPlacementState(context)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package net.shadowfacts.phycon.block.redstone_controller
|
||||
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.nbt.NbtCompound
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.shadowfacts.phycon.api.packet.Packet
|
||||
import net.shadowfacts.phycon.api.util.IPAddress
|
||||
import net.shadowfacts.phycon.init.PhyBlockEntities
|
||||
|
@ -12,7 +14,7 @@ import net.shadowfacts.phycon.util.RedstoneMode
|
|||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
class RedstoneControllerBlockEntity: DeviceBlockEntity(PhyBlockEntities.REDSTONE_CONTROLLER),
|
||||
class RedstoneControllerBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockEntity(PhyBlockEntities.REDSTONE_CONTROLLER, pos, state),
|
||||
ClientConfigurableDevice {
|
||||
|
||||
var managedDevices = Array<IPAddress?>(5) { null }
|
||||
|
@ -53,22 +55,22 @@ class RedstoneControllerBlockEntity: DeviceBlockEntity(PhyBlockEntities.REDSTONE
|
|||
}
|
||||
}
|
||||
|
||||
override fun toCommonTag(tag: CompoundTag) {
|
||||
override fun toCommonTag(tag: NbtCompound) {
|
||||
super.toCommonTag(tag)
|
||||
writeDeviceConfiguration(tag)
|
||||
}
|
||||
|
||||
override fun fromCommonTag(tag: CompoundTag) {
|
||||
override fun fromCommonTag(tag: NbtCompound) {
|
||||
super.fromCommonTag(tag)
|
||||
loadDeviceConfiguration(tag)
|
||||
}
|
||||
|
||||
override fun writeDeviceConfiguration(tag: CompoundTag) {
|
||||
override fun writeDeviceConfiguration(tag: NbtCompound) {
|
||||
tag.putIntArray("ManagedDevices", managedDevices.mapNotNull { it?.address })
|
||||
tag.putString("RedstoneMode", redstoneMode.name)
|
||||
}
|
||||
|
||||
override fun loadDeviceConfiguration(tag: CompoundTag) {
|
||||
override fun loadDeviceConfiguration(tag: NbtCompound) {
|
||||
val addresses = tag.getIntArray("ManagedDevices")
|
||||
managedDevices = (0..4).map { if (it >= addresses.size) null else IPAddress(addresses[it]) }.toTypedArray()
|
||||
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)
|
||||
)
|
||||
|
||||
override fun createBlockEntity(world: BlockView) = RedstoneEmitterBlockEntity()
|
||||
override fun createBlockEntity(pos: BlockPos, state: BlockState) = RedstoneEmitterBlockEntity(pos, state)
|
||||
|
||||
override fun emitsRedstonePower(state: BlockState): Boolean {
|
||||
return true
|
||||
|
@ -67,7 +67,7 @@ class RedstoneEmitterBlock: FaceDeviceBlock<RedstoneEmitterBlockEntity>(
|
|||
if (!world.isClient) {
|
||||
val be = getBlockEntity(world, pos)!!
|
||||
|
||||
be.sync()
|
||||
be.markUpdate()
|
||||
|
||||
val factory = object: ExtendedScreenHandlerFactory {
|
||||
override fun createMenu(syncId: Int, playerInv: PlayerInventory, player: PlayerEntity): ScreenHandler {
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package net.shadowfacts.phycon.block.redstone_emitter
|
||||
|
||||
import alexiil.mc.lib.attributes.item.GroupedItemInvView
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.NbtCompound
|
||||
import net.minecraft.text.TranslatableText
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.shadowfacts.phycon.api.packet.Packet
|
||||
import net.shadowfacts.phycon.api.util.IPAddress
|
||||
import net.shadowfacts.phycon.block.DeviceBlockEntity
|
||||
|
@ -19,7 +21,7 @@ import kotlin.math.round
|
|||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
class RedstoneEmitterBlockEntity: DeviceBlockEntity(PhyBlockEntities.REDSTONE_EMITTER),
|
||||
class RedstoneEmitterBlockEntity(pos: BlockPos, state: BlockState): DeviceBlockEntity(PhyBlockEntities.REDSTONE_EMITTER, pos, state),
|
||||
ClientConfigurableDevice,
|
||||
GhostInv {
|
||||
|
||||
|
@ -100,26 +102,26 @@ class RedstoneEmitterBlockEntity: DeviceBlockEntity(PhyBlockEntities.REDSTONE_EM
|
|||
world!!.updateNeighborsAlways(pos.offset(cachedState[FaceDeviceBlock.FACING]), cachedState.block)
|
||||
}
|
||||
|
||||
override fun toCommonTag(tag: CompoundTag) {
|
||||
override fun toCommonTag(tag: NbtCompound) {
|
||||
super.toCommonTag(tag)
|
||||
tag.putInt("CachedEmittedPower", cachedEmittedPower)
|
||||
tag.put("StackToMonitor", stackToMonitor.toTag(CompoundTag()))
|
||||
tag.put("StackToMonitor", stackToMonitor.writeNbt(NbtCompound()))
|
||||
writeDeviceConfiguration(tag)
|
||||
}
|
||||
|
||||
override fun fromCommonTag(tag: CompoundTag) {
|
||||
override fun fromCommonTag(tag: NbtCompound) {
|
||||
super.fromCommonTag(tag)
|
||||
cachedEmittedPower = tag.getInt("CachedEmittedPower")
|
||||
stackToMonitor = ItemStack.fromTag(tag.getCompound("StackToMonitor"))
|
||||
stackToMonitor = ItemStack.fromNbt(tag.getCompound("StackToMonitor"))
|
||||
loadDeviceConfiguration(tag)
|
||||
}
|
||||
|
||||
override fun writeDeviceConfiguration(tag: CompoundTag) {
|
||||
override fun writeDeviceConfiguration(tag: NbtCompound) {
|
||||
tag.putInt("MaxAmount", maxAmount)
|
||||
tag.putString("Mode", mode.name)
|
||||
}
|
||||
|
||||
override fun loadDeviceConfiguration(tag: CompoundTag) {
|
||||
override fun loadDeviceConfiguration(tag: NbtCompound) {
|
||||
maxAmount = tag.getInt("MaxAmount")
|
||||
mode = Mode.valueOf(tag.getString("Mode"))
|
||||
}
|
||||
|
@ -127,7 +129,7 @@ class RedstoneEmitterBlockEntity: DeviceBlockEntity(PhyBlockEntities.REDSTONE_EM
|
|||
enum class Mode {
|
||||
ANALOG, DIGITAL;
|
||||
|
||||
val friendlyName = TranslatableText("gui.phycon.redstone_emitter_mode.${name.toLowerCase()}")
|
||||
val friendlyName = TranslatableText("gui.phycon.redstone_emitter_mode.${name.lowercase()}")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.shadowfacts.phycon.block.redstone_emitter
|
|||
|
||||
import com.mojang.blaze3d.systems.RenderSystem
|
||||
import net.minecraft.client.MinecraftClient
|
||||
import net.minecraft.client.render.GameRenderer
|
||||
import net.minecraft.client.util.math.MatrixStack
|
||||
import net.minecraft.entity.player.PlayerInventory
|
||||
import net.minecraft.text.Text
|
||||
|
@ -49,8 +50,8 @@ class RedstoneEmitterScreen(
|
|||
override fun drawBackground(matrixStack: MatrixStack, delta: Float, mouseX: Int, mouseY: Int) {
|
||||
super.drawBackground(matrixStack, delta, mouseX, mouseY)
|
||||
|
||||
RenderSystem.color4f(1f, 1f, 1f, 1f)
|
||||
client!!.textureManager.bindTexture(BACKGROUND)
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader)
|
||||
RenderSystem.setShaderTexture(0, BACKGROUND)
|
||||
val x = (width - backgroundWidth) / 2
|
||||
val y = (height - backgroundHeight) / 2
|
||||
drawTexture(matrixStack, x, y, 0, 0, backgroundWidth, backgroundHeight)
|
||||
|
|
|
@ -55,16 +55,16 @@ class RedstoneEmitterScreenHandler(
|
|||
return true
|
||||
}
|
||||
|
||||
override fun onSlotClick(slotId: Int, clickData: Int, slotActionType: SlotActionType, player: PlayerEntity): ItemStack {
|
||||
override fun onSlotClick(slotId: Int, clickData: Int, slotActionType: SlotActionType, player: PlayerEntity) {
|
||||
// fake slot
|
||||
if (slotId == 0) {
|
||||
if (player.inventory.cursorStack.isEmpty) {
|
||||
if (cursorStack.isEmpty) {
|
||||
emitter.stackToMonitor = ItemStack.EMPTY
|
||||
} else {
|
||||
emitter.stackToMonitor = player.inventory.cursorStack.copyWithCount(1)
|
||||
emitter.stackToMonitor = cursorStack.copyWithCount(1)
|
||||
}
|
||||
}
|
||||
return super.onSlotClick(slotId, clickData, slotActionType, player)
|
||||
super.onSlotClick(slotId, clickData, slotActionType, player)
|
||||
}
|
||||
|
||||
override fun transferSlot(player: PlayerEntity, slotId: Int): ItemStack {
|
||||
|
|
|
@ -3,42 +3,34 @@ package net.shadowfacts.phycon.block.terminal
|
|||
import alexiil.mc.lib.attributes.item.GroupedItemInvView
|
||||
import alexiil.mc.lib.attributes.item.ItemStackCollections
|
||||
import alexiil.mc.lib.attributes.item.ItemStackUtil
|
||||
import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable
|
||||
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.block.entity.BlockEntityType
|
||||
import net.minecraft.entity.player.PlayerEntity
|
||||
import net.minecraft.entity.player.PlayerInventory
|
||||
import net.minecraft.inventory.Inventory
|
||||
import net.minecraft.inventory.InventoryChangedListener
|
||||
import net.minecraft.item.ItemStack
|
||||
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.nbt.NbtCompound
|
||||
import net.minecraft.util.ItemScatterer
|
||||
import net.minecraft.util.Tickable
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.util.math.Direction
|
||||
import net.shadowfacts.phycon.api.Interface
|
||||
import net.shadowfacts.phycon.api.packet.Packet
|
||||
import net.shadowfacts.phycon.api.util.IPAddress
|
||||
import net.shadowfacts.phycon.init.PhyBlockEntities
|
||||
import net.shadowfacts.phycon.block.DeviceBlockEntity
|
||||
import net.shadowfacts.phycon.util.NetworkUtil
|
||||
import net.shadowfacts.phycon.component.*
|
||||
import net.shadowfacts.phycon.packet.*
|
||||
import net.shadowfacts.phycon.util.NetworkUtil
|
||||
import java.lang.ref.WeakReference
|
||||
import java.util.*
|
||||
import java.util.function.IntBinaryOperator
|
||||
import kotlin.math.min
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
abstract class AbstractTerminalBlockEntity(type: BlockEntityType<*>): DeviceBlockEntity(type),
|
||||
abstract class AbstractTerminalBlockEntity(type: BlockEntityType<*>, pos: BlockPos, state: BlockState): DeviceBlockEntity(type, pos, state),
|
||||
InventoryChangedListener,
|
||||
BlockEntityClientSerializable,
|
||||
Tickable,
|
||||
ItemStackPacketHandler,
|
||||
NetworkStackDispatcher<AbstractTerminalBlockEntity.PendingInsertion> {
|
||||
|
||||
|
@ -129,7 +121,7 @@ abstract class AbstractTerminalBlockEntity(type: BlockEntityType<*>): DeviceBloc
|
|||
protected fun updateAndSync() {
|
||||
updateNetItems()
|
||||
// syncs the internal buffer to the client
|
||||
sync()
|
||||
markUpdate()
|
||||
// syncs the open container (if any) to the client
|
||||
netItemObserver?.get()?.netItemsChanged()
|
||||
}
|
||||
|
@ -139,7 +131,7 @@ abstract class AbstractTerminalBlockEntity(type: BlockEntityType<*>): DeviceBloc
|
|||
for (inventory in inventoryCache.values) {
|
||||
for (stack in inventory.storedStacks) {
|
||||
val amount = inventory.getAmount(stack)
|
||||
cachedNetItems.mergeInt(stack, amount) { a, b -> a + b }
|
||||
cachedNetItems.mergeInt(stack, amount, IntBinaryOperator { a, b -> a + b })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -225,8 +217,7 @@ abstract class AbstractTerminalBlockEntity(type: BlockEntityType<*>): DeviceBloc
|
|||
|
||||
override fun onInventoryChanged(inv: Inventory) {
|
||||
if (inv == internalBuffer && world != null && !world!!.isClient) {
|
||||
markDirty()
|
||||
sync()
|
||||
markUpdate()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -234,12 +225,12 @@ abstract class AbstractTerminalBlockEntity(type: BlockEntityType<*>): DeviceBloc
|
|||
ItemScatterer.spawn(world, pos, internalBuffer)
|
||||
}
|
||||
|
||||
override fun toCommonTag(tag: CompoundTag) {
|
||||
override fun toCommonTag(tag: NbtCompound) {
|
||||
super.toCommonTag(tag)
|
||||
tag.put("InternalBuffer", internalBuffer.toTag())
|
||||
}
|
||||
|
||||
override fun fromCommonTag(tag: CompoundTag) {
|
||||
override fun fromCommonTag(tag: NbtCompound) {
|
||||
super.fromCommonTag(tag)
|
||||
internalBuffer.fromTag(tag.getCompound("InternalBuffer"))
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import net.minecraft.client.MinecraftClient
|
|||
import net.minecraft.client.gui.DrawableHelper
|
||||
import net.minecraft.client.gui.Element
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget
|
||||
import net.minecraft.client.render.GameRenderer
|
||||
import net.minecraft.client.render.Tessellator
|
||||
import net.minecraft.client.render.VertexConsumerProvider
|
||||
import net.minecraft.client.util.math.MatrixStack
|
||||
|
@ -100,7 +101,7 @@ abstract class AbstractTerminalScreen<BE: AbstractTerminalBlockEntity, T: Abstra
|
|||
private val DECIMAL_FORMAT = DecimalFormat("#.#").apply { roundingMode = RoundingMode.HALF_UP }
|
||||
private val FORMAT = DecimalFormat("##").apply { roundingMode = RoundingMode.HALF_UP }
|
||||
|
||||
fun drawNetworkSlotAmount(stack: ItemStack, x: Int, y: Int, slot: Slot, matrixStack: MatrixStack) {
|
||||
fun drawNetworkSlotAmount(stack: ItemStack, x: Int, y: Int) {
|
||||
val amount = stack.count
|
||||
val s = when {
|
||||
amount < 1_000 -> amount.toString()
|
||||
|
@ -121,16 +122,17 @@ abstract class AbstractTerminalScreen<BE: AbstractTerminalBlockEntity, T: Abstra
|
|||
// empty string for label because vanilla renders the count behind the damage bar
|
||||
itemRenderer.renderGuiItemOverlay(textRenderer, stack, x, y, "")
|
||||
|
||||
matrixStack.push()
|
||||
// ItemRenderer.renderGuiItemOverlay creates a new MatrixStack specifically for drawing the overlay
|
||||
val matrixStack = MatrixStack()
|
||||
matrixStack.translate(x.toDouble(), y.toDouble(), itemRenderer.zOffset + 200.0)
|
||||
val scale = 2 / 3f
|
||||
matrixStack.scale(scale, scale, 1.0f)
|
||||
val immediate = VertexConsumerProvider.immediate(Tessellator.getInstance().buffer)
|
||||
val textX = (1 / scale * 18) - textRenderer.getWidth(s).toFloat() - 3
|
||||
val textY = (1 / scale * 18) - 11
|
||||
textRenderer.draw(s, textX, textY, 0xffffff, true, matrixStack.peek().model, immediate, false, 0, 0xF000F0)
|
||||
textRenderer.draw(s, textX, textY, 0xffffff, true, matrixStack.peek().positionMatrix, immediate, false, 0, 0xF000F0)
|
||||
RenderSystem.enableDepthTest()
|
||||
immediate.draw()
|
||||
matrixStack.pop()
|
||||
}
|
||||
|
||||
override fun drawBackground(matrixStack: MatrixStack, delta: Float, mouseX: Int, mouseY: Int) {
|
||||
|
@ -140,15 +142,16 @@ abstract class AbstractTerminalScreen<BE: AbstractTerminalBlockEntity, T: Abstra
|
|||
}
|
||||
|
||||
open fun drawBackgroundTexture(matrixStack: MatrixStack) {
|
||||
RenderSystem.color4f(1f, 1f, 1f, 1f)
|
||||
client!!.textureManager.bindTexture(backgroundTexture)
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexColorShader)
|
||||
RenderSystem.setShaderTexture(0, backgroundTexture)
|
||||
RenderSystem.setShaderColor(1f, 1f, 1f, 1f)
|
||||
val x = (width - backgroundWidth) / 2
|
||||
val y = (height - backgroundHeight) / 2
|
||||
drawTexture(matrixStack, x, y, 0, 0, backgroundWidth, backgroundHeight)
|
||||
}
|
||||
|
||||
override fun tick() {
|
||||
super.tick()
|
||||
override fun handledScreenTick() {
|
||||
super.handledScreenTick()
|
||||
|
||||
if (amountVC != null) {
|
||||
amountVC!!.field.tick()
|
||||
|
@ -171,7 +174,7 @@ abstract class AbstractTerminalScreen<BE: AbstractTerminalBlockEntity, T: Abstra
|
|||
override fun onMouseClick(slot: Slot?, invSlot: Int, clickData: Int, type: SlotActionType?) {
|
||||
super.onMouseClick(slot, invSlot, clickData, type)
|
||||
|
||||
if (slot != null && !slot.stack.isEmpty && handler.isNetworkSlot(slot.id) && playerInventory.cursorStack.isEmpty) {
|
||||
if (slot != null && !slot.stack.isEmpty && handler.isNetworkSlot(slot.id) && handler.cursorStack.isEmpty) {
|
||||
val stack = slot.stack
|
||||
|
||||
if (type == SlotActionType.QUICK_MOVE) {
|
||||
|
|
|
@ -170,16 +170,16 @@ abstract class AbstractTerminalScreenHandler<T: AbstractTerminalBlockEntity>(
|
|||
terminal.netItemObserver = null
|
||||
}
|
||||
|
||||
override fun onSlotClick(slotId: Int, clickData: Int, actionType: SlotActionType, player: PlayerEntity): ItemStack {
|
||||
override fun onSlotClick(slotId: Int, clickData: Int, actionType: SlotActionType, player: PlayerEntity) {
|
||||
if (isBufferSlot(slotId)) {
|
||||
// todo: why does this think it's quick_craft sometimes?
|
||||
if ((actionType == SlotActionType.PICKUP || actionType == SlotActionType.QUICK_CRAFT) && !player.inventory.cursorStack.isEmpty) {
|
||||
if ((actionType == SlotActionType.PICKUP || actionType == SlotActionType.QUICK_CRAFT) && !cursorStack.isEmpty) {
|
||||
// placing cursor stack into buffer
|
||||
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)
|
||||
}
|
||||
}
|
||||
return super.onSlotClick(slotId, clickData, actionType, player)
|
||||
super.onSlotClick(slotId, clickData, actionType, player)
|
||||
}
|
||||
|
||||
override fun transferSlot(player: PlayerEntity, slotId: Int): ItemStack {
|
||||
|
@ -227,7 +227,7 @@ abstract class AbstractTerminalScreenHandler<T: AbstractTerminalBlockEntity>(
|
|||
|
||||
slot.markDirty()
|
||||
slotsInsertedInto.add(index)
|
||||
} else if (canStacksCombine(slotStack, stack) && slotStack.count < slotStack.maxCount) {
|
||||
} else if (ItemStack.canCombine(slotStack, stack) && slotStack.count < slotStack.maxCount) {
|
||||
val maxToMove = slotStack.maxCount - slotStack.count
|
||||
val toMove = min(maxToMove, stack.count)
|
||||
slotStack.increment(toMove)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package net.shadowfacts.phycon.block.terminal
|
||||
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.util.Identifier
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.world.BlockView
|
||||
import net.shadowfacts.phycon.PhysicalConnectivity
|
||||
|
||||
|
@ -13,6 +15,6 @@ class CraftingTerminalBlock: AbstractTerminalBlock<CraftingTerminalBlockEntity>(
|
|||
val ID = Identifier(PhysicalConnectivity.MODID, "crafting_terminal")
|
||||
}
|
||||
|
||||
override fun createBlockEntity(world: BlockView) = CraftingTerminalBlockEntity()
|
||||
override fun createBlockEntity(pos: BlockPos, state: BlockState) = CraftingTerminalBlockEntity(pos, state)
|
||||
|
||||
}
|
||||
|
|
|
@ -2,19 +2,18 @@ package net.shadowfacts.phycon.block.terminal
|
|||
|
||||
import alexiil.mc.lib.attributes.item.ItemStackCollections
|
||||
import alexiil.mc.lib.attributes.item.ItemStackUtil
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap
|
||||
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.entity.player.PlayerEntity
|
||||
import net.minecraft.entity.player.PlayerInventory
|
||||
import net.minecraft.inventory.CraftingInventory
|
||||
import net.minecraft.inventory.SimpleInventory
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.NbtCompound
|
||||
import net.minecraft.network.PacketByteBuf
|
||||
import net.minecraft.screen.ScreenHandler
|
||||
import net.minecraft.server.network.ServerPlayerEntity
|
||||
import net.minecraft.text.Text
|
||||
import net.minecraft.text.TranslatableText
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.shadowfacts.phycon.init.PhyBlockEntities
|
||||
import net.shadowfacts.phycon.packet.ItemStackPacket
|
||||
import net.shadowfacts.phycon.packet.LocateStackPacket
|
||||
|
@ -27,7 +26,7 @@ import kotlin.math.min
|
|||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
class CraftingTerminalBlockEntity: AbstractTerminalBlockEntity(PhyBlockEntities.CRAFTING_TERMINAL) {
|
||||
class CraftingTerminalBlockEntity(pos: BlockPos, state: BlockState): AbstractTerminalBlockEntity(PhyBlockEntities.CRAFTING_TERMINAL, pos, state) {
|
||||
|
||||
val craftingInv = SimpleInventory(9)
|
||||
|
||||
|
@ -119,12 +118,12 @@ class CraftingTerminalBlockEntity: AbstractTerminalBlockEntity(PhyBlockEntities.
|
|||
}
|
||||
}
|
||||
|
||||
override fun toCommonTag(tag: CompoundTag) {
|
||||
override fun toCommonTag(tag: NbtCompound) {
|
||||
super.toCommonTag(tag)
|
||||
tag.put("CraftingInv", craftingInv.toTag())
|
||||
}
|
||||
|
||||
override fun fromCommonTag(tag: CompoundTag) {
|
||||
override fun fromCommonTag(tag: NbtCompound) {
|
||||
super.fromCommonTag(tag)
|
||||
craftingInv.fromTag(tag.getList("CraftingInv", 10))
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package net.shadowfacts.phycon.block.terminal
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem
|
||||
import net.minecraft.client.render.GameRenderer
|
||||
import net.minecraft.client.util.math.MatrixStack
|
||||
import net.minecraft.entity.player.PlayerInventory
|
||||
import net.minecraft.text.Text
|
||||
|
@ -34,13 +35,13 @@ class CraftingTerminalScreen(
|
|||
}
|
||||
|
||||
override fun drawBackgroundTexture(matrixStack: MatrixStack) {
|
||||
RenderSystem.color4f(1f, 1f, 1f, 1f)
|
||||
client!!.textureManager.bindTexture(BACKGROUND_1)
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader)
|
||||
RenderSystem.setShaderTexture(0, BACKGROUND_1)
|
||||
val x = (width - backgroundWidth) / 2
|
||||
val y = (height - backgroundHeight) / 2
|
||||
drawTexture(matrixStack, x, y, 0, 0, 256, 252)
|
||||
|
||||
client!!.textureManager.bindTexture(BACKGROUND_2)
|
||||
RenderSystem.setShaderTexture(0, BACKGROUND_2)
|
||||
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.network.PacketByteBuf
|
||||
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket
|
||||
import net.minecraft.recipe.RecipeFinder
|
||||
import net.minecraft.recipe.RecipeMatcher
|
||||
import net.minecraft.recipe.RecipeType
|
||||
import net.minecraft.screen.slot.CraftingResultSlot
|
||||
import net.minecraft.screen.slot.Slot
|
||||
|
@ -73,7 +73,7 @@ class CraftingTerminalScreenHandler(
|
|||
ItemStack.EMPTY
|
||||
}
|
||||
result.setStack(0, resultStack)
|
||||
player.networkHandler.sendPacket(ScreenHandlerSlotUpdateS2CPacket(syncId, resultSlot.id, resultStack))
|
||||
player.networkHandler.sendPacket(ScreenHandlerSlotUpdateS2CPacket(syncId, nextRevision(), resultSlot.id, resultStack))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,7 @@ class CraftingTerminalScreenHandler(
|
|||
if (!insertItem(craftingResult, playerSlotsStart, playerSlotsEnd, true)) {
|
||||
return ItemStack.EMPTY
|
||||
}
|
||||
resultSlot.onStackChanged(craftingResult, originalResult)
|
||||
resultSlot.onQuickTransfer(craftingResult, originalResult)
|
||||
|
||||
if (craftingResult.isEmpty) {
|
||||
resultSlot.stack = ItemStack.EMPTY
|
||||
|
@ -115,8 +115,8 @@ class CraftingTerminalScreenHandler(
|
|||
return ItemStack.EMPTY
|
||||
}
|
||||
|
||||
val taken = resultSlot.onTakeItem(player, craftingResult)
|
||||
player.dropItem(taken, false)
|
||||
resultSlot.onTakeItem(player, craftingResult)
|
||||
player.dropItem(craftingResult, false)
|
||||
|
||||
return originalResult
|
||||
} else {
|
||||
|
@ -157,7 +157,7 @@ class CraftingTerminalScreenHandler(
|
|||
backing.clear()
|
||||
}
|
||||
|
||||
override fun provideRecipeInputs(finder: RecipeFinder) {
|
||||
override fun provideRecipeInputs(finder: RecipeMatcher) {
|
||||
TODO()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package net.shadowfacts.phycon.block.terminal
|
||||
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.util.Identifier
|
||||
import net.minecraft.world.BlockView
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.shadowfacts.phycon.PhysicalConnectivity
|
||||
|
||||
/**
|
||||
|
@ -13,6 +14,6 @@ class TerminalBlock: AbstractTerminalBlock<TerminalBlockEntity>() {
|
|||
val ID = Identifier(PhysicalConnectivity.MODID, "terminal")
|
||||
}
|
||||
|
||||
override fun createBlockEntity(world: BlockView) = TerminalBlockEntity()
|
||||
override fun createBlockEntity(pos: BlockPos, state: BlockState) = TerminalBlockEntity(pos, state)
|
||||
|
||||
}
|
||||
|
|
|
@ -1,19 +1,21 @@
|
|||
package net.shadowfacts.phycon.block.terminal
|
||||
|
||||
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.entity.player.PlayerEntity
|
||||
import net.minecraft.entity.player.PlayerInventory
|
||||
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.math.BlockPos
|
||||
import net.shadowfacts.phycon.init.PhyBlockEntities
|
||||
import net.shadowfacts.phycon.packet.RequestInventoryPacket
|
||||
|
||||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
class TerminalBlockEntity: AbstractTerminalBlockEntity(PhyBlockEntities.TERMINAL) {
|
||||
class TerminalBlockEntity(pos: BlockPos, state: BlockState): AbstractTerminalBlockEntity(PhyBlockEntities.TERMINAL, pos, state) {
|
||||
|
||||
override fun onActivate(player: PlayerEntity) {
|
||||
if (!world!!.isClient) {
|
||||
|
|
|
@ -3,8 +3,8 @@ package net.shadowfacts.phycon.block.terminal
|
|||
import alexiil.mc.lib.attributes.item.ItemStackUtil
|
||||
import net.minecraft.inventory.SimpleInventory
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.IntArrayTag
|
||||
import net.minecraft.nbt.NbtCompound
|
||||
import net.minecraft.nbt.NbtIntArray
|
||||
import net.shadowfacts.phycon.util.fromTag
|
||||
import net.shadowfacts.phycon.util.toTag
|
||||
import kotlin.math.min
|
||||
|
@ -21,14 +21,14 @@ class TerminalBufferInventory(size: Int): SimpleInventory(size) {
|
|||
var modes = Array(size) { Mode.UNASSIGNED }
|
||||
private set
|
||||
|
||||
fun toTag(): CompoundTag {
|
||||
val compound = CompoundTag()
|
||||
fun toTag(): NbtCompound {
|
||||
val compound = NbtCompound()
|
||||
compound.put("Inventory", (this as SimpleInventory).toTag())
|
||||
compound.put("Modes", IntArrayTag(modes.map(Mode::ordinal)))
|
||||
compound.put("Modes", NbtIntArray(modes.map(Mode::ordinal)))
|
||||
return compound
|
||||
}
|
||||
|
||||
fun fromTag(tag: CompoundTag) {
|
||||
fun fromTag(tag: NbtCompound) {
|
||||
val inventory = tag.getList("Inventory", 10)
|
||||
(this as SimpleInventory).fromTag(inventory)
|
||||
tag.getIntArray("Modes").forEachIndexed { i, it -> modes[i] = Mode.values()[it] }
|
||||
|
|
|
@ -6,6 +6,7 @@ import net.minecraft.client.render.model.*
|
|||
import net.minecraft.client.texture.Sprite
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture
|
||||
import net.minecraft.client.util.SpriteIdentifier
|
||||
import net.minecraft.screen.PlayerScreenHandler
|
||||
import net.minecraft.util.DyeColor
|
||||
import net.minecraft.util.Identifier
|
||||
import net.minecraft.util.math.Direction
|
||||
|
@ -85,7 +86,7 @@ class ColoredCableModel(
|
|||
rotationContainer: ModelBakeSettings,
|
||||
modelId: Identifier
|
||||
): BakedModel {
|
||||
centerSprite = textureGetter.apply(SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, Identifier(PhysicalConnectivity.MODID, "block/cable/${color.getName()}/straight")))
|
||||
centerSprite = textureGetter.apply(SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, Identifier(PhysicalConnectivity.MODID, "block/cable/${color.getName()}/straight")))
|
||||
|
||||
sideRotations.forEach { (side, rot) ->
|
||||
this.side[side.ordinal] = loader.bakeRecoloredCable(SIDE, rot, textureGetter, color)
|
||||
|
@ -260,7 +261,7 @@ class ColoredCableModel(
|
|||
|
||||
override fun isBuiltin() = false
|
||||
|
||||
override fun getSprite() = centerSprite
|
||||
override fun getParticleSprite() = centerSprite
|
||||
|
||||
override fun getTransformation() = null
|
||||
|
||||
|
|
|
@ -120,9 +120,9 @@ abstract class FaceDeviceModel: UnbakedModel, BakedModel {
|
|||
|
||||
val sideQuads = getSideModel(state)?.getQuads(state, face, random) ?: listOf()
|
||||
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) {
|
||||
interfaceCableCap[color]!![facing.ordinal]?.getQuads(state, face, random) ?: listOf()
|
||||
interfaceCableCap[color]!![facing.ordinal].getQuads(state, face, random) ?: listOf()
|
||||
} else {
|
||||
val model = when (facing) {
|
||||
Direction.DOWN -> when (connection) {
|
||||
|
@ -183,7 +183,7 @@ abstract class FaceDeviceModel: UnbakedModel, BakedModel {
|
|||
|
||||
override fun isBuiltin() = false
|
||||
|
||||
abstract override fun getSprite(): Sprite
|
||||
abstract override fun getParticleSprite(): Sprite
|
||||
|
||||
override fun getTransformation() = null
|
||||
|
||||
|
|
|
@ -40,8 +40,8 @@ object RedstoneControllerModel: FaceDeviceModel() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun getSprite(): Sprite {
|
||||
return offModels.first()!!.sprite
|
||||
override fun getParticleSprite(): Sprite {
|
||||
return offModels.first()!!.particleSprite
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import net.minecraft.client.texture.Sprite
|
|||
import net.minecraft.client.texture.SpriteAtlasTexture
|
||||
import net.minecraft.client.util.SpriteIdentifier
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.screen.PlayerScreenHandler
|
||||
import net.minecraft.util.Identifier
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.util.math.Direction
|
||||
|
@ -32,10 +33,10 @@ class ScreenDeviceModel(
|
|||
): UnbakedModel, BakedModel, FabricBakedModel {
|
||||
|
||||
companion object {
|
||||
private val CASING = SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, Identifier(PhysicalConnectivity.MODID, "block/casing"))
|
||||
private val CASING = SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, Identifier(PhysicalConnectivity.MODID, "block/casing"))
|
||||
}
|
||||
|
||||
private val screenTexture = SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, screenTexture)
|
||||
private val screenTexture = SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, screenTexture)
|
||||
|
||||
private lateinit var meshes: Array<Mesh>
|
||||
private lateinit var screenSprite: Sprite
|
||||
|
@ -171,7 +172,7 @@ class ScreenDeviceModel(
|
|||
|
||||
override fun isBuiltin() = false
|
||||
|
||||
override fun getSprite() = screenSprite
|
||||
override fun getParticleSprite() = screenSprite
|
||||
|
||||
override fun getTransformation() = null
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ class SimpleFaceDeviceModel(
|
|||
return sideModels[state[FaceDeviceBlock.COLOR]]!![state[FaceDeviceBlock.FACING].ordinal]
|
||||
}
|
||||
|
||||
override fun getSprite(): Sprite {
|
||||
return sideModels[DyeColor.BLACK]!!.first().sprite
|
||||
override fun getParticleSprite(): Sprite {
|
||||
return sideModels[DyeColor.BLACK]!!.first().particleSprite
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
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()
|
||||
}
|
||||
|
||||
}
|
|
@ -50,16 +50,16 @@ class ScrollTrackView(
|
|||
})
|
||||
}
|
||||
|
||||
override fun mouseDragged(point: Point, delta: Point, mouseButton: MouseButton): Boolean {
|
||||
if (grabbedY == null && point !in thumbView.frame) {
|
||||
val newCenter = MathHelper.clamp(point.y, THUMB_HEIGHT / 2, frame.height - THUMB_HEIGHT / 2)
|
||||
override fun mouseDragged(startPoint: Point, delta: Point, mouseButton: MouseButton): Boolean {
|
||||
if (grabbedY == null && startPoint !in thumbView.frame) {
|
||||
val newCenter = MathHelper.clamp(startPoint.y, THUMB_HEIGHT / 2, frame.height - THUMB_HEIGHT / 2)
|
||||
thumbView.frame = Rect(0.0, newCenter - THUMB_HEIGHT / 2, THUMB_WIDTH, THUMB_HEIGHT)
|
||||
}
|
||||
|
||||
if (grabbedY == null) {
|
||||
grabbedY = point.y - thumbView.frame.top
|
||||
grabbedY = startPoint.y - thumbView.frame.top
|
||||
}
|
||||
val newTop = MathHelper.clamp(point.y - grabbedY!!, 0.0, frame.height - THUMB_HEIGHT)
|
||||
val newTop = MathHelper.clamp(startPoint.y - grabbedY!!, 0.0, frame.height - THUMB_HEIGHT)
|
||||
thumbView.frame = Rect(0.0, newTop, THUMB_WIDTH, THUMB_HEIGHT)
|
||||
|
||||
scrollPositionChanged(this)
|
||||
|
|
|
@ -7,8 +7,8 @@ import net.shadowfacts.phycon.api.util.MACAddress
|
|||
* @author shadowfacts
|
||||
*/
|
||||
open class BaseFrame(
|
||||
@JvmField private val source: MACAddress,
|
||||
@JvmField private val destination: MACAddress
|
||||
private val source: MACAddress,
|
||||
private val destination: MACAddress
|
||||
): EthernetFrame {
|
||||
override fun getSource() = source
|
||||
override fun getDestination() = destination
|
||||
|
|
|
@ -8,7 +8,7 @@ import net.shadowfacts.phycon.api.util.MACAddress
|
|||
* @author shadowfacts
|
||||
*/
|
||||
class BasePacketFrame(
|
||||
@JvmField private val packet: Packet,
|
||||
private val packet: Packet,
|
||||
source: MACAddress,
|
||||
destination: MACAddress,
|
||||
): BaseFrame(source, destination), PacketFrame {
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package net.shadowfacts.phycon.init
|
||||
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.block.entity.BlockEntity
|
||||
import net.minecraft.block.entity.BlockEntityType
|
||||
import net.minecraft.util.Identifier
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.util.registry.Registry
|
||||
import net.shadowfacts.phycon.block.extractor.ExtractorBlock
|
||||
import net.shadowfacts.phycon.block.extractor.ExtractorBlockEntity
|
||||
|
@ -39,7 +41,7 @@ object PhyBlockEntities {
|
|||
val REDSTONE_CONTROLLER = create(::RedstoneControllerBlockEntity, PhyBlocks.REDSTONE_CONTROLLER)
|
||||
val REDSTONE_EMITTER = create(::RedstoneEmitterBlockEntity, PhyBlocks.REDSTONE_EMITTER)
|
||||
|
||||
private fun <T: BlockEntity> create(builder: () -> T, block: Block): BlockEntityType<T> {
|
||||
private fun <T: BlockEntity> create(builder: (BlockPos, BlockState) -> T, block: Block): BlockEntityType<T> {
|
||||
return BlockEntityType.Builder.create(builder, block).build(null)
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ class ConsoleItem: Item(Settings().maxCount(1)) {
|
|||
if (context.world.isClient) {
|
||||
this.openScreen(be)
|
||||
} else {
|
||||
be.sync()
|
||||
be.markUpdate()
|
||||
}
|
||||
return ActionResult.SUCCESS
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ class ConsoleItem: Item(Settings().maxCount(1)) {
|
|||
private fun openScreen(be: DeviceBlockEntity) {
|
||||
// val screen = TestCacaoScreen()
|
||||
val screen = DeviceConsoleScreen(be)
|
||||
MinecraftClient.getInstance().openScreen(screen)
|
||||
MinecraftClient.getInstance().setScreen(screen)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ import net.shadowfacts.phycon.util.text
|
|||
open class DeviceBlockItem(block: DeviceBlock<*>, settings: Settings = Settings()): BlockItem(block, settings) {
|
||||
|
||||
override fun appendTooltip(stack: ItemStack, world: World?, list: MutableList<Text>, context: TooltipContext) {
|
||||
val beTag = stack.getSubTag("BlockEntityTag")
|
||||
val beTag = stack.getSubNbt("BlockEntityTag")
|
||||
if (beTag != null) {
|
||||
val ip = IPAddress(beTag.getInt("IPAddress"))
|
||||
list.add(text {
|
||||
|
|
|
@ -54,12 +54,12 @@ class ScrewdriverItem: Item(Settings().maxCount(1)) {
|
|||
val be = block.getBlockEntity(context.world, context.blockPos)!!
|
||||
|
||||
val stack = ItemStack(block)
|
||||
val beTag = stack.getOrCreateSubTag("BlockEntityTag")
|
||||
be.toTag(beTag)
|
||||
val beTag = be.createNbt()
|
||||
// remove x, y, z entries for stacking purposes
|
||||
beTag.remove("x")
|
||||
beTag.remove("y")
|
||||
beTag.remove("z")
|
||||
stack.setSubNbt("BlockEntityTag", beTag)
|
||||
|
||||
if (block === PhyBlocks.TERMINAL) {
|
||||
// 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.PacketSender
|
||||
import net.minecraft.block.entity.BlockEntity
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.NbtCompound
|
||||
import net.minecraft.network.Packet
|
||||
import net.minecraft.network.PacketByteBuf
|
||||
import net.minecraft.server.MinecraftServer
|
||||
|
@ -24,9 +24,9 @@ object C2SConfigureDevice: ServerReceiver {
|
|||
|
||||
buf.writeIdentifier(be.world!!.registryKey.value)
|
||||
buf.writeBlockPos(be.pos)
|
||||
val tag = CompoundTag()
|
||||
val tag = NbtCompound()
|
||||
be.writeDeviceConfiguration(tag)
|
||||
buf.writeCompoundTag(tag)
|
||||
buf.writeNbt(tag)
|
||||
|
||||
return createPacket(buf)
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ object C2SConfigureDevice: ServerReceiver {
|
|||
override fun receive(server: MinecraftServer, player: ServerPlayerEntity, handler: ServerPlayNetworkHandler, buf: PacketByteBuf, responseSender: PacketSender) {
|
||||
val dimID = buf.readIdentifier()
|
||||
val pos = buf.readBlockPos()
|
||||
val tag = buf.readCompoundTag() ?: return
|
||||
val tag = buf.readNbt() ?: return
|
||||
|
||||
server.execute {
|
||||
// todo: check if the player is close enough
|
||||
|
|
|
@ -42,7 +42,7 @@ object C2STerminalCraftingButton: ServerReceiver {
|
|||
val action = Action.values()[buf.readByte().toInt()]
|
||||
|
||||
server.execute {
|
||||
val key = RegistryKey.of(Registry.DIMENSION, dimID)
|
||||
val key = RegistryKey.of(Registry.WORLD_KEY, dimID)
|
||||
val screenHandler = player.currentScreenHandler as? CraftingTerminalScreenHandler ?: 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()
|
||||
|
||||
server.execute {
|
||||
val key = RegistryKey.of(Registry.DIMENSION, dimID)
|
||||
val key = RegistryKey.of(Registry.WORLD_KEY, dimID)
|
||||
val world = server.getWorld(key) ?: return@execute
|
||||
val terminal = world.getBlockEntity(pos) as? AbstractTerminalBlockEntity ?: return@execute
|
||||
terminal.requestItem(stack, amount)
|
||||
|
|
|
@ -29,7 +29,7 @@ object C2STerminalUpdateDisplayedItems: ServerReceiver {
|
|||
buf.writeBlockPos(terminal.pos)
|
||||
|
||||
buf.writeString(query)
|
||||
buf.writeCompoundTag(PhysicalConnectivityClient.terminalSettings.toTag())
|
||||
buf.writeNbt(PhysicalConnectivityClient.terminalSettings.toTag())
|
||||
buf.writeFloat(scrollPosition)
|
||||
|
||||
return ClientPlayNetworking.createC2SPacket(CHANNEL, buf)
|
||||
|
@ -40,7 +40,7 @@ object C2STerminalUpdateDisplayedItems: ServerReceiver {
|
|||
val pos = buf.readBlockPos()
|
||||
val query = buf.readString()
|
||||
val settings = TerminalSettings()
|
||||
settings.fromTag(buf.readCompoundTag()!!)
|
||||
settings.fromTag(buf.readNbt()!!)
|
||||
val scrollPosition = buf.readFloat()
|
||||
|
||||
server.execute {
|
||||
|
|
|
@ -33,7 +33,7 @@ object S2CTerminalUpdateDisplayedItems: ClientReceiver {
|
|||
}
|
||||
|
||||
buf.writeString(query)
|
||||
buf.writeCompoundTag(settings.toTag())
|
||||
buf.writeNbt(settings.toTag())
|
||||
buf.writeFloat(scrollPosition)
|
||||
buf.writeInt(totalEntries)
|
||||
|
||||
|
@ -49,7 +49,7 @@ object S2CTerminalUpdateDisplayedItems: ClientReceiver {
|
|||
entries.add(AbstractTerminalScreenHandler.Entry(buf.readItemStackWithoutCount(), buf.readVarInt()))
|
||||
}
|
||||
val query = buf.readString()
|
||||
PhysicalConnectivityClient.terminalSettings.fromTag(buf.readCompoundTag()!!)
|
||||
PhysicalConnectivityClient.terminalSettings.fromTag(buf.readNbt()!!)
|
||||
val scrollPosition = buf.readFloat()
|
||||
val totalEntries = buf.readInt()
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ import net.shadowfacts.phycon.api.util.IPAddress
|
|||
* @author shadowfacts
|
||||
*/
|
||||
abstract class BasePacket(
|
||||
@JvmField private val source: IPAddress,
|
||||
@JvmField private val destination: IPAddress
|
||||
private val source: IPAddress,
|
||||
private val destination: IPAddress
|
||||
): Packet {
|
||||
|
||||
override fun getSource() = source
|
||||
|
|
|
@ -11,5 +11,5 @@ enum class ActivationMode: RotatableEnum, FriendlyNameable {
|
|||
MANAGED;
|
||||
|
||||
override val friendlyName: Text
|
||||
get() = TranslatableText("gui.phycon.activation_mode.${name.toLowerCase()}")
|
||||
get() = TranslatableText("gui.phycon.activation_mode.${name.lowercase()}")
|
||||
}
|
||||
|
|
|
@ -3,20 +3,20 @@ package net.shadowfacts.phycon.util
|
|||
import alexiil.mc.lib.attributes.item.ItemStackUtil
|
||||
import net.minecraft.inventory.SimpleInventory
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.ListTag
|
||||
import net.minecraft.nbt.NbtCompound
|
||||
import net.minecraft.nbt.NbtList
|
||||
import java.lang.RuntimeException
|
||||
import kotlin.math.min
|
||||
|
||||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
fun SimpleInventory.toTag(): ListTag {
|
||||
val list = ListTag()
|
||||
fun SimpleInventory.toTag(): NbtList {
|
||||
val list = NbtList()
|
||||
for (slot in 0 until size()) {
|
||||
val stack = getStack(slot)
|
||||
if (!stack.isEmpty) {
|
||||
val stackTag = stack.toTag(CompoundTag())
|
||||
val stackTag = stack.writeNbt(NbtCompound())
|
||||
stackTag.putInt("Slot", slot)
|
||||
list.add(stackTag)
|
||||
}
|
||||
|
@ -24,16 +24,16 @@ fun SimpleInventory.toTag(): ListTag {
|
|||
return list
|
||||
}
|
||||
|
||||
fun SimpleInventory.fromTag(list: ListTag) {
|
||||
fun SimpleInventory.fromTag(list: NbtList) {
|
||||
if (list.isEmpty()) {
|
||||
this.clear()
|
||||
return
|
||||
}
|
||||
if (list.elementType != 10.toByte()) throw RuntimeException("Can't decode BasicInventory from list tag that does not contain compound tags")
|
||||
if (list.heldType != 10.toByte()) throw RuntimeException("Can't decode BasicInventory from list tag that does not contain compound tags")
|
||||
this.clear()
|
||||
for (tag in list) {
|
||||
val compound = tag as CompoundTag
|
||||
val stack = ItemStack.fromTag(compound)
|
||||
val compound = tag as NbtCompound
|
||||
val stack = ItemStack.fromNbt(compound)
|
||||
val slot = compound.getInt("Slot")
|
||||
setStack(slot, stack)
|
||||
}
|
||||
|
|
|
@ -10,5 +10,5 @@ enum class CableConnection: StringIdentifiable {
|
|||
OFF,
|
||||
DISABLED;
|
||||
|
||||
override fun asString() = name.toLowerCase()
|
||||
override fun asString() = name.lowercase()
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package net.shadowfacts.phycon.util
|
||||
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.NbtCompound
|
||||
|
||||
/**
|
||||
* @author shadowfacts
|
||||
*/
|
||||
interface ClientConfigurableDevice {
|
||||
|
||||
fun writeDeviceConfiguration(tag: CompoundTag)
|
||||
fun writeDeviceConfiguration(tag: NbtCompound)
|
||||
|
||||
fun loadDeviceConfiguration(tag: CompoundTag)
|
||||
fun loadDeviceConfiguration(tag: NbtCompound)
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package net.shadowfacts.phycon.util
|
|||
|
||||
import net.minecraft.item.Item
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.NbtCompound
|
||||
import net.minecraft.network.PacketByteBuf
|
||||
|
||||
/**
|
||||
|
@ -14,13 +14,13 @@ fun PacketByteBuf.writeItemStackWithoutCount(stack: ItemStack) {
|
|||
} else {
|
||||
writeBoolean(true)
|
||||
writeVarInt(Item.getRawId(stack.item))
|
||||
val tag: CompoundTag? =
|
||||
if (stack.item.isDamageable || stack.item.shouldSyncTagToClient()) {
|
||||
stack.tag
|
||||
val tag: NbtCompound? =
|
||||
if (stack.item.isDamageable || stack.item.isNbtSynced()) {
|
||||
stack.nbt
|
||||
} else {
|
||||
null
|
||||
}
|
||||
writeCompoundTag(tag)
|
||||
writeNbt(tag)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ fun PacketByteBuf.readItemStackWithoutCount(): ItemStack {
|
|||
val id = readVarInt()
|
||||
val count = 1
|
||||
val stack = ItemStack(Item.byRawId(id), count)
|
||||
stack.tag = readCompoundTag()
|
||||
stack.nbt = readNbt()
|
||||
stack
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,5 +26,5 @@ enum class RedstoneMode: RotatableEnum, FriendlyNameable {
|
|||
}
|
||||
|
||||
override val friendlyName: Text
|
||||
get() = TranslatableText("gui.phycon.redstone_mode.${name.toLowerCase()}")
|
||||
get() = TranslatableText("gui.phycon.redstone_mode.${name.lowercase()}")
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package net.shadowfacts.phycon.util
|
||||
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.NbtCompound
|
||||
import net.minecraft.util.Identifier
|
||||
import net.shadowfacts.phycon.PhysicalConnectivityClient
|
||||
import net.shadowfacts.phycon.api.TerminalSettingKey
|
||||
|
@ -56,15 +56,15 @@ class TerminalSettings {
|
|||
settings[key] = value
|
||||
}
|
||||
|
||||
fun toTag(): CompoundTag {
|
||||
return CompoundTag().also {
|
||||
fun toTag(): NbtCompound {
|
||||
return NbtCompound().also {
|
||||
settings.forEach { (s, v) ->
|
||||
it.putInt(s.id.toString(), v.ordinal)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun fromTag(tag: CompoundTag) {
|
||||
fun fromTag(tag: NbtCompound) {
|
||||
settings.clear()
|
||||
tag.keys.forEach { k ->
|
||||
val id = Identifier.tryParse(k) ?: return@forEach
|
||||
|
|
Loading…
Reference in New Issue