mirror of
https://github.com/naalit/slotlink.git
synced 2025-12-31 04:13:02 +00:00
update to 1.17-pre1
This commit is contained in:
parent
eb6db05f39
commit
cdbbd56e39
46 changed files with 374 additions and 396 deletions
3
.github/workflows/build_head.yml
vendored
3
.github/workflows/build_head.yml
vendored
|
|
@ -20,13 +20,12 @@ jobs:
|
|||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 1.8
|
||||
java-version: 16
|
||||
- run: chmod +x gradlew
|
||||
- uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.gradle/caches
|
||||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
|
||||
restore-keys: ${{ runner.os }}-gradle
|
||||
- run: ./gradlew build
|
||||
env:
|
||||
MOD_VERSION: ${{ steps.vars.outputs.VERSION }}
|
||||
|
|
|
|||
3
.github/workflows/build_release.yml
vendored
3
.github/workflows/build_release.yml
vendored
|
|
@ -12,13 +12,12 @@ jobs:
|
|||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 1.8
|
||||
java-version: 16
|
||||
- run: chmod +x gradlew
|
||||
- uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.gradle/caches
|
||||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
|
||||
restore-keys: ${{ runner.os }}-gradle
|
||||
- run: ./gradlew build curseforge
|
||||
env:
|
||||
MOD_VERSION: ${{ steps.vars.outputs.VERSION }}
|
||||
|
|
|
|||
141
build.gradle
141
build.gradle
|
|
@ -1,141 +0,0 @@
|
|||
import net.fabricmc.loom.task.RunGameTask
|
||||
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.jvm" version "1.5.0"
|
||||
id "org.jetbrains.kotlin.plugin.serialization" version "1.5.0"
|
||||
id "com.matthewprenger.cursegradle" version "1.4.0"
|
||||
id "fabric-loom" version "0.6-SNAPSHOT"
|
||||
id "maven-publish"
|
||||
}
|
||||
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
compileKotlin.kotlinOptions.jvmTarget = "1.8"
|
||||
|
||||
archivesBaseName = project.archives_base_name
|
||||
group = project.maven_group
|
||||
|
||||
def versionEnv = System.getenv("MOD_VERSION")
|
||||
if (versionEnv == null || versionEnv.isBlank()) {
|
||||
versionEnv = "SNAPSHOT"
|
||||
}
|
||||
|
||||
version = "${versionEnv}+${project.minecraft_version}"
|
||||
|
||||
sourceSets {
|
||||
dev {
|
||||
compileClasspath += main.compileClasspath
|
||||
runtimeClasspath += main.runtimeClasspath
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(RunGameTask) {
|
||||
classpath sourceSets.dev.runtimeClasspath
|
||||
jvmArgs project.run_args
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven { url "https://maven.shedaniel.me/" }
|
||||
maven { url "https://maven.terraformersmc.com/releases" }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
//to change the versions see the gradle.properties file
|
||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api}"
|
||||
modImplementation "net.fabricmc:fabric-language-kotlin:${project.fabric_kotlin}"
|
||||
|
||||
modImplementation "me.shedaniel:RoughlyEnoughItems:${project.rei}"
|
||||
|
||||
modRuntime "com.terraformersmc:modmenu:${project.modmenu}"
|
||||
|
||||
devImplementation sourceSets.main.output
|
||||
}
|
||||
|
||||
curseforge {
|
||||
if (System.getenv("CURSEFORGE_API") != null) {
|
||||
apiKey = System.getenv("CURSEFORGE_API")
|
||||
project {
|
||||
id = "391014"
|
||||
releaseType = "release"
|
||||
|
||||
changelogType = "html"
|
||||
changelog = "<a href=\"https://github.com/badasintended/slotlink/releases/tag/${versionEnv}\"></a>"
|
||||
|
||||
mainArtifact remapJar
|
||||
|
||||
addGameVersion "Fabric"
|
||||
addGameVersion project.minecraft_version
|
||||
|
||||
relations {
|
||||
requiredDependency "fabric-api"
|
||||
requiredDependency "fabric-language-kotlin"
|
||||
optionalDependency "roughly-enough-items"
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
uploadTask.dependsOn "build"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
include "fabric.mod.json"
|
||||
expand "version": project.version
|
||||
}
|
||||
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
exclude "fabric.mod.json"
|
||||
}
|
||||
}
|
||||
|
||||
// ensure that the encoding is set to UTF-8, no matter what the system default is
|
||||
// this fixes some edge cases with special characters not displaying correctly
|
||||
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
|
||||
tasks.withType(JavaCompile) {
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
||||
// if it is present.
|
||||
// If you remove this task, sources will not be generated.
|
||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
classifier = "sources"
|
||||
from sourceSets.main.allSource
|
||||
}
|
||||
|
||||
jar {
|
||||
from "LICENSE"
|
||||
}
|
||||
|
||||
// configure the maven publication
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
// add all the jars that should be included when publishing to maven
|
||||
artifact(jar) {
|
||||
builtBy remapJar
|
||||
}
|
||||
artifact("${project.buildDir.absolutePath}/libs/${archivesBaseName}-${project.version}.jar") {
|
||||
builtBy remapJar
|
||||
}
|
||||
artifact(sourcesJar) {
|
||||
builtBy remapSourcesJar
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// select the repositories you want to publish to
|
||||
repositories {
|
||||
// uncomment to publish to the local maven
|
||||
// mavenLocal()
|
||||
}
|
||||
}
|
||||
107
build.gradle.kts
Normal file
107
build.gradle.kts
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
import com.matthewprenger.cursegradle.CurseArtifact
|
||||
import com.matthewprenger.cursegradle.CurseProject
|
||||
import com.matthewprenger.cursegradle.CurseRelation
|
||||
import net.fabricmc.loom.task.RunGameTask
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
kotlin("jvm").version("1.5.0")
|
||||
kotlin("plugin.serialization").version("1.5.0")
|
||||
|
||||
id("fabric-loom").version("0.8-SNAPSHOT")
|
||||
id("com.matthewprenger.cursegradle").version("1.4.0")
|
||||
id("maven-publish")
|
||||
}
|
||||
|
||||
val prop = Property()
|
||||
val env: Map<String, String> = System.getenv()
|
||||
|
||||
version = env["MOD_VERSION"] ?: "local"
|
||||
|
||||
sourceSets {
|
||||
val main by getting
|
||||
create("dev") {
|
||||
compileClasspath += main.compileClasspath
|
||||
runtimeClasspath += main.runtimeClasspath
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven("https://maven.shedaniel.me/")
|
||||
maven("https://maven.terraformersmc.com/releases")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
val devImplementation by configurations.getting
|
||||
|
||||
minecraft("com.mojang:minecraft:${prop["minecraft"]}")
|
||||
mappings("net.fabricmc:yarn:${prop["yarn"]}:v2")
|
||||
|
||||
modImplementation("net.fabricmc:fabric-loader:${prop["fabricLoader"]}")
|
||||
|
||||
modImplementation("net.fabricmc.fabric-api:fabric-api:${prop["fabricApi"]}")
|
||||
modImplementation("net.fabricmc:fabric-language-kotlin:${prop["fabricKotlin"]}")
|
||||
|
||||
devImplementation(sourceSets["main"].output)
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_16
|
||||
targetCompatibility = JavaVersion.VERSION_16
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile> {
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile> {
|
||||
kotlinOptions {
|
||||
jvmTarget = "15"
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<RunGameTask> {
|
||||
classpath = sourceSets["dev"].runtimeClasspath
|
||||
}
|
||||
|
||||
tasks.processResources {
|
||||
inputs.property("version", project.version)
|
||||
|
||||
filesMatching("fabric.mod.json") {
|
||||
expand("version" to project.version)
|
||||
}
|
||||
}
|
||||
|
||||
curseforge {
|
||||
env["CURSEFORGE_API"]?.let { CURSEFORGE_API ->
|
||||
apiKey = CURSEFORGE_API
|
||||
project(closureOf<CurseProject> {
|
||||
id = "391014"
|
||||
releaseType = "release"
|
||||
|
||||
changelogType = "markdown"
|
||||
changelog = "https://github.com/badasintended/slotlink/releases/tag/${project.version}"
|
||||
|
||||
mainArtifact(tasks["remapJar"], closureOf<CurseArtifact> {
|
||||
displayName = "[${prop["minecraft"]}] v${project.version}"
|
||||
})
|
||||
|
||||
addGameVersion("Fabric")
|
||||
addGameVersion(prop["minecraft"])
|
||||
|
||||
relations(closureOf<CurseRelation> {
|
||||
requiredDependency("fabric-api")
|
||||
requiredDependency("fabric-language-kotlin")
|
||||
optionalDependency("roughly-enough-items")
|
||||
})
|
||||
|
||||
uploadTask.dependsOn("build")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
class Property {
|
||||
|
||||
operator fun get(name: String) = project.property(name).toString()
|
||||
|
||||
}
|
||||
|
|
@ -4,16 +4,16 @@ org.gradle.jvmargs = -Xmx1G
|
|||
run_args = -Dmixin.debug.export=true
|
||||
|
||||
# Fabric properties
|
||||
minecraft_version = 1.16.5
|
||||
yarn_mappings = 1.16.5+build.4
|
||||
loader_version = 0.11.1
|
||||
minecraft = 1.17-pre1
|
||||
yarn = 1.17-pre1+build.10
|
||||
fabricLoader = 0.11.3
|
||||
|
||||
# Mod properties
|
||||
maven_group = com.github.badasintended
|
||||
archives_base_name = slotlink
|
||||
|
||||
# Dependencies
|
||||
fabric_api = 0.34.0+1.16
|
||||
fabric_kotlin = 1.6.0+kotlin.1.5.0
|
||||
fabricApi = 0.34.8+1.17
|
||||
fabricKotlin = 1.6.0+kotlin.1.5.0
|
||||
modmenu = 1.16.9
|
||||
rei = 5.11.218
|
||||
|
|
|
|||
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
|
|
@ -1,5 +1,4 @@
|
|||
#Thu May 28 11:20:34 ICT 2020
|
||||
distributionUrl = https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
|
||||
distributionUrl = https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
|
||||
distributionBase = GRADLE_USER_HOME
|
||||
distributionPath = wrapper/dists
|
||||
zipStorePath = wrapper/dists
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
pluginManagement {
|
||||
repositories {
|
||||
maven {
|
||||
name = 'Fabric'
|
||||
url = 'https://maven.fabricmc.net/'
|
||||
}
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
8
settings.gradle.kts
Normal file
8
settings.gradle.kts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
pluginManagement {
|
||||
repositories {
|
||||
maven(url = "https://maven.fabricmc.net") {
|
||||
name = "Fabric"
|
||||
}
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
package badasintended.slotlink.mixin;
|
||||
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(Slot.class)
|
||||
public interface SlotAccessor {
|
||||
|
||||
@Accessor
|
||||
int getIndex();
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package badasintended.slotlink.block
|
||||
|
||||
import badasintended.slotlink.block.entity.CableBlockEntity
|
||||
import badasintended.slotlink.util.BlockEntityBuilder
|
||||
import badasintended.slotlink.util.bbCuboid
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
|
||||
import java.util.function.IntFunction
|
||||
|
|
@ -10,7 +11,6 @@ import net.minecraft.block.Block
|
|||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.block.Material
|
||||
import net.minecraft.block.ShapeContext
|
||||
import net.minecraft.block.entity.BlockEntity
|
||||
import net.minecraft.item.ItemPlacementContext
|
||||
import net.minecraft.state.StateManager
|
||||
import net.minecraft.state.property.BooleanProperty
|
||||
|
|
@ -21,7 +21,8 @@ import net.minecraft.util.shape.VoxelShapes
|
|||
import net.minecraft.world.BlockView
|
||||
import net.minecraft.world.WorldAccess
|
||||
|
||||
open class CableBlock(id: String = "cable", be: () -> BlockEntity = ::CableBlockEntity) : ChildBlock(id, be, SETTINGS) {
|
||||
open class CableBlock(id: String = "cable", be: BlockEntityBuilder = ::CableBlockEntity) :
|
||||
ChildBlock(id, be, SETTINGS) {
|
||||
|
||||
companion object {
|
||||
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ package badasintended.slotlink.block
|
|||
|
||||
import badasintended.slotlink.block.entity.ChildBlockEntity
|
||||
import badasintended.slotlink.block.entity.MasterBlockEntity
|
||||
import badasintended.slotlink.util.BlockEntityBuilder
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.block.BlockEntityProvider
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.block.entity.BlockEntity
|
||||
import net.minecraft.client.item.TooltipContext
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.text.Text
|
||||
|
|
@ -15,8 +15,12 @@ import net.minecraft.util.math.BlockPos
|
|||
import net.minecraft.world.BlockView
|
||||
import net.minecraft.world.World
|
||||
|
||||
abstract class ChildBlock(id: String, private val blockEntity: () -> BlockEntity, settings: Settings = SETTINGS) :
|
||||
ModBlock(id, settings), BlockEntityProvider {
|
||||
abstract class ChildBlock(
|
||||
id: String,
|
||||
private val blockEntityBuilder: BlockEntityBuilder,
|
||||
settings: Settings = SETTINGS
|
||||
) : ModBlock(id, settings),
|
||||
BlockEntityProvider {
|
||||
|
||||
// TODO: Optimize this part
|
||||
override fun neighborUpdate(
|
||||
|
|
@ -69,7 +73,7 @@ abstract class ChildBlock(id: String, private val blockEntity: () -> BlockEntity
|
|||
}
|
||||
}
|
||||
|
||||
override fun createBlockEntity(world: BlockView) = blockEntity.invoke()
|
||||
override fun createBlockEntity(pos: BlockPos, state: BlockState) = blockEntityBuilder(pos, state)
|
||||
|
||||
override fun appendTooltip(
|
||||
stack: ItemStack,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
package badasintended.slotlink.block
|
||||
|
||||
import badasintended.slotlink.block.entity.ConnectorCableBlockEntity
|
||||
import badasintended.slotlink.util.BlockEntityBuilder
|
||||
import badasintended.slotlink.util.bbCuboid
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.block.InventoryProvider
|
||||
import net.minecraft.block.entity.BlockEntity
|
||||
import net.minecraft.client.item.TooltipContext
|
||||
import net.minecraft.entity.LivingEntity
|
||||
import net.minecraft.entity.player.PlayerEntity
|
||||
|
|
@ -25,7 +25,7 @@ import net.minecraft.world.BlockView
|
|||
import net.minecraft.world.World
|
||||
import net.minecraft.world.WorldAccess
|
||||
|
||||
abstract class ConnectorCableBlock(id: String, be: () -> BlockEntity) : CableBlock(id, be) {
|
||||
abstract class ConnectorCableBlock(id: String, builder: BlockEntityBuilder) : CableBlock(id, builder) {
|
||||
|
||||
companion object {
|
||||
|
||||
|
|
|
|||
|
|
@ -2,35 +2,33 @@ package badasintended.slotlink.block
|
|||
|
||||
import badasintended.slotlink.block.entity.MasterBlockEntity
|
||||
import badasintended.slotlink.util.chat
|
||||
import badasintended.slotlink.util.toTag
|
||||
import badasintended.slotlink.util.toNbt
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.block.BlockEntityProvider
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.block.entity.BlockEntity
|
||||
import net.minecraft.entity.LivingEntity
|
||||
import net.minecraft.entity.player.PlayerEntity
|
||||
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 net.minecraft.util.ActionResult
|
||||
import net.minecraft.util.Hand
|
||||
import net.minecraft.util.hit.BlockHitResult
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.world.BlockView
|
||||
import net.minecraft.world.World
|
||||
|
||||
class MasterBlock : ModBlock("master"), BlockEntityProvider {
|
||||
|
||||
override fun createBlockEntity(view: BlockView): BlockEntity = MasterBlockEntity()
|
||||
override fun createBlockEntity(pos: BlockPos, state: BlockState) = MasterBlockEntity(pos, state)
|
||||
|
||||
override fun onPlaced(world: World, pos: BlockPos, state: BlockState, placer: LivingEntity?, itemStack: ItemStack) {
|
||||
super.onPlaced(world, pos, state, placer, itemStack)
|
||||
|
||||
val blockEntity = world.getBlockEntity(pos)
|
||||
val nbt = blockEntity!!.toTag(CompoundTag())
|
||||
val blockEntity = world.getBlockEntity(pos)!!
|
||||
val nbt = blockEntity.writeNbt(NbtCompound())
|
||||
|
||||
nbt.put("storagePos", ListTag())
|
||||
blockEntity.fromTag(state, nbt)
|
||||
nbt.put("storagePos", NbtList())
|
||||
blockEntity.readNbt(nbt)
|
||||
blockEntity.markDirty()
|
||||
}
|
||||
|
||||
|
|
@ -49,14 +47,14 @@ class MasterBlock : ModBlock("master"), BlockEntityProvider {
|
|||
val neighborBlock = neighborState.block
|
||||
|
||||
if (neighborBlock is ChildBlock) {
|
||||
val neighborBlockEntity = world.getBlockEntity(neighborPos)
|
||||
val neighborNbt = neighborBlockEntity!!.toTag(CompoundTag())
|
||||
val neighborBlockEntity = world.getBlockEntity(neighborPos)!!
|
||||
val neighborNbt = neighborBlockEntity.writeNbt(NbtCompound())
|
||||
val neighborHasMaster = neighborNbt.getBoolean("hasMaster")
|
||||
if (!neighborHasMaster) {
|
||||
val masterPos = pos.toTag()
|
||||
val masterPos = pos.toNbt()
|
||||
neighborNbt.put("masterPos", masterPos)
|
||||
neighborNbt.putBoolean("hasMaster", true)
|
||||
neighborBlockEntity.fromTag(neighborState, neighborNbt)
|
||||
neighborBlockEntity.readNbt(neighborNbt)
|
||||
neighborBlockEntity.markDirty()
|
||||
world.updateNeighbors(neighborPos, neighborBlock)
|
||||
}
|
||||
|
|
@ -80,10 +78,10 @@ class MasterBlock : ModBlock("master"), BlockEntityProvider {
|
|||
player.chat("$translationKey.use2", inventories.size)
|
||||
player.chat(
|
||||
"$translationKey.use3",
|
||||
inventories.map { it.size() }.sum(),
|
||||
inventories.map { inv -> (0 until inv.size()).filter { inv.getStack(it).isEmpty }.size }.sum()
|
||||
inventories.sumOf { it.size() },
|
||||
inventories.sumOf { inv -> (0 until inv.size()).filter { inv.getStack(it).isEmpty }.size }
|
||||
)
|
||||
player.chat("$translationKey.use4", inventories.map { it.size() * it.maxCountPerStack }.sum())
|
||||
player.chat("$translationKey.use4", inventories.sumOf { it.size() * it.maxCountPerStack })
|
||||
}
|
||||
return ActionResult.SUCCESS
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
package badasintended.slotlink.block
|
||||
|
||||
import badasintended.slotlink.util.BlockEntityBuilder
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.block.LeverBlock
|
||||
import net.minecraft.block.entity.BlockEntity
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.world.WorldAccess
|
||||
|
||||
abstract class TransferCableBlock(id: String, be: () -> BlockEntity) : ConnectorCableBlock(id, be) {
|
||||
abstract class TransferCableBlock(id: String, builder: BlockEntityBuilder) : ConnectorCableBlock(id, builder) {
|
||||
|
||||
override fun Block.isIgnored() = this is ModBlock
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package badasintended.slotlink.block.entity
|
||||
|
||||
import badasintended.slotlink.init.BlockEntityTypes
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.util.math.BlockPos
|
||||
|
||||
class CableBlockEntity : ChildBlockEntity(BlockEntityTypes.CABLE)
|
||||
class CableBlockEntity(pos: BlockPos, state: BlockState) : ChildBlockEntity(BlockEntityTypes.CABLE, pos, state)
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
package badasintended.slotlink.block.entity
|
||||
|
||||
import badasintended.slotlink.util.toNbt
|
||||
import badasintended.slotlink.util.toPos
|
||||
import badasintended.slotlink.util.toTag
|
||||
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.nbt.NbtCompound
|
||||
import net.minecraft.util.math.BlockPos
|
||||
|
||||
abstract class ChildBlockEntity(type: BlockEntityType<out BlockEntity>) : ModBlockEntity(type) {
|
||||
abstract class ChildBlockEntity(type: BlockEntityType<out BlockEntity>, pos: BlockPos, state: BlockState) :
|
||||
ModBlockEntity(type, pos, state) {
|
||||
|
||||
var hasMaster = false
|
||||
var masterPos: BlockPos = BlockPos.ORIGIN
|
||||
|
|
@ -16,17 +17,17 @@ abstract class ChildBlockEntity(type: BlockEntityType<out BlockEntity>) : ModBlo
|
|||
field = value.toImmutable()
|
||||
}
|
||||
|
||||
override fun toTag(tag: CompoundTag): CompoundTag {
|
||||
super.toTag(tag)
|
||||
override fun writeNbt(tag: NbtCompound): NbtCompound {
|
||||
super.writeNbt(tag)
|
||||
|
||||
tag.putBoolean("hasMaster", hasMaster)
|
||||
tag.put("masterPos", masterPos.toTag())
|
||||
tag.put("masterPos", masterPos.toNbt())
|
||||
|
||||
return tag
|
||||
}
|
||||
|
||||
override fun fromTag(state: BlockState, tag: CompoundTag) {
|
||||
super.fromTag(state, tag)
|
||||
override fun readNbt(tag: NbtCompound) {
|
||||
super.readNbt(tag)
|
||||
|
||||
hasMaster = tag.getBoolean("hasMaster")
|
||||
masterPos = tag.getCompound("masterPos").toPos()
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ package badasintended.slotlink.block.entity
|
|||
|
||||
import badasintended.slotlink.api.Compat
|
||||
import badasintended.slotlink.inventory.FilteredInventory
|
||||
import badasintended.slotlink.util.toNbt
|
||||
import badasintended.slotlink.util.toPos
|
||||
import badasintended.slotlink.util.toTag
|
||||
import badasintended.slotlink.util.writeFilter
|
||||
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory
|
||||
import net.fabricmc.fabric.api.util.NbtType
|
||||
|
|
@ -16,8 +16,8 @@ import net.minecraft.block.entity.BlockEntityType
|
|||
import net.minecraft.block.entity.ChestBlockEntity
|
||||
import net.minecraft.inventory.Inventory
|
||||
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 net.minecraft.network.PacketByteBuf
|
||||
import net.minecraft.server.network.ServerPlayerEntity
|
||||
import net.minecraft.server.world.ServerWorld
|
||||
|
|
@ -28,7 +28,8 @@ import net.minecraft.util.math.ChunkPos
|
|||
import net.minecraft.world.World
|
||||
import net.minecraft.world.WorldAccess
|
||||
|
||||
abstract class ConnectorCableBlockEntity(type: BlockEntityType<out BlockEntity>) : ChildBlockEntity(type), ExtendedScreenHandlerFactory {
|
||||
abstract class ConnectorCableBlockEntity(type: BlockEntityType<out BlockEntity>, pos: BlockPos, state: BlockState) :
|
||||
ChildBlockEntity(type, pos, state), ExtendedScreenHandlerFactory {
|
||||
|
||||
var linkedPos: BlockPos = BlockPos.ORIGIN
|
||||
set(value) {
|
||||
|
|
@ -43,7 +44,11 @@ abstract class ConnectorCableBlockEntity(type: BlockEntityType<out BlockEntity>)
|
|||
|
||||
private val filtered = FilteredInventory(filter) { isBlackList }
|
||||
|
||||
fun getInventory(world: WorldAccess, master: MasterBlockEntity? = null, request: Boolean = false): FilteredInventory {
|
||||
fun getInventory(
|
||||
world: WorldAccess,
|
||||
master: MasterBlockEntity? = null,
|
||||
request: Boolean = false
|
||||
): FilteredInventory {
|
||||
if (world !is World) return filtered.none
|
||||
if (!hasMaster) return filtered.none
|
||||
|
||||
|
|
@ -83,21 +88,21 @@ abstract class ConnectorCableBlockEntity(type: BlockEntityType<out BlockEntity>)
|
|||
|
||||
protected abstract fun Block.isIgnored(): Boolean
|
||||
|
||||
override fun toTag(tag: CompoundTag): CompoundTag {
|
||||
super.toTag(tag)
|
||||
override fun writeNbt(tag: NbtCompound): NbtCompound {
|
||||
super.writeNbt(tag)
|
||||
|
||||
tag.putInt("priority", priority)
|
||||
tag.put("linkedPos", linkedPos.toTag())
|
||||
tag.put("linkedPos", linkedPos.toNbt())
|
||||
tag.putBoolean("isBlacklist", isBlackList)
|
||||
|
||||
val filterTag = CompoundTag()
|
||||
val list = ListTag()
|
||||
val filterTag = NbtCompound()
|
||||
val list = NbtList()
|
||||
filter.forEachIndexed { i, pair ->
|
||||
if (!pair.first.isEmpty) {
|
||||
val compound = CompoundTag()
|
||||
val compound = NbtCompound()
|
||||
compound.putByte("Slot", i.toByte())
|
||||
compound.putBoolean("matchNbt", pair.second)
|
||||
pair.first.toTag(compound)
|
||||
pair.first.writeNbt(compound)
|
||||
list.add(compound)
|
||||
}
|
||||
}
|
||||
|
|
@ -107,8 +112,8 @@ abstract class ConnectorCableBlockEntity(type: BlockEntityType<out BlockEntity>)
|
|||
return tag
|
||||
}
|
||||
|
||||
override fun fromTag(state: BlockState, tag: CompoundTag) {
|
||||
super.fromTag(state, tag)
|
||||
override fun readNbt(tag: NbtCompound) {
|
||||
super.readNbt(tag)
|
||||
|
||||
priority = tag.getInt("priority")
|
||||
linkedPos = tag.getCompound("linkedPos").toPos()
|
||||
|
|
@ -118,11 +123,11 @@ abstract class ConnectorCableBlockEntity(type: BlockEntityType<out BlockEntity>)
|
|||
val list = filterTag.getList("Items", NbtType.COMPOUND)
|
||||
|
||||
list.forEach {
|
||||
it as CompoundTag
|
||||
it as NbtCompound
|
||||
val slot = it.getByte("Slot").toInt()
|
||||
val nbt = it.getBoolean("matchNbt")
|
||||
if (slot in 0 until 9) {
|
||||
val stack = ItemStack.fromTag(it)
|
||||
val stack = ItemStack.fromNbt(it)
|
||||
filter[slot] = stack to nbt
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
package badasintended.slotlink.block.entity
|
||||
|
||||
import badasintended.slotlink.init.BlockEntityTypes
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.util.math.Direction
|
||||
import net.minecraft.world.World
|
||||
|
||||
class ExportCableBlockEntity : TransferCableBlockEntity(BlockEntityTypes.EXPORT_CABLE) {
|
||||
class ExportCableBlockEntity(pos: BlockPos, state: BlockState) :
|
||||
TransferCableBlockEntity(BlockEntityTypes.EXPORT_CABLE, pos, state) {
|
||||
|
||||
override var side = Direction.UP
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
package badasintended.slotlink.block.entity
|
||||
|
||||
import badasintended.slotlink.init.BlockEntityTypes
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.util.math.Direction
|
||||
import net.minecraft.world.World
|
||||
|
||||
class ImportCableBlockEntity : TransferCableBlockEntity(BlockEntityTypes.IMPORT_CABLE) {
|
||||
class ImportCableBlockEntity(pos: BlockPos, state: BlockState) :
|
||||
TransferCableBlockEntity(BlockEntityTypes.IMPORT_CABLE, pos, state) {
|
||||
|
||||
override var side = Direction.DOWN
|
||||
|
||||
|
|
|
|||
|
|
@ -6,12 +6,15 @@ import badasintended.slotlink.init.BlockEntityTypes
|
|||
import badasintended.slotlink.screen.LinkScreenHandler
|
||||
import badasintended.slotlink.util.ignoredTag
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.entity.player.PlayerEntity
|
||||
import net.minecraft.entity.player.PlayerInventory
|
||||
import net.minecraft.screen.ScreenHandler
|
||||
import net.minecraft.screen.ScreenHandlerContext
|
||||
import net.minecraft.util.math.BlockPos
|
||||
|
||||
class LinkCableBlockEntity : ConnectorCableBlockEntity(BlockEntityTypes.LINK_CABLE) {
|
||||
class LinkCableBlockEntity(pos: BlockPos, state: BlockState) :
|
||||
ConnectorCableBlockEntity(BlockEntityTypes.LINK_CABLE, pos, state) {
|
||||
|
||||
override fun Block.isIgnored(): Boolean {
|
||||
if (this is ModBlock || Compat.isBlacklisted(this)) return true
|
||||
|
|
|
|||
|
|
@ -5,18 +5,19 @@ import badasintended.slotlink.inventory.FilteredInventory
|
|||
import badasintended.slotlink.util.BlockPosSet
|
||||
import badasintended.slotlink.util.MasterWatcher
|
||||
import badasintended.slotlink.util.fromTag
|
||||
import badasintended.slotlink.util.toTag
|
||||
import badasintended.slotlink.util.toNbt
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList
|
||||
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet
|
||||
import java.util.SortedSet
|
||||
import java.util.*
|
||||
import net.fabricmc.fabric.api.util.NbtType
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.block.entity.BlockEntityTicker
|
||||
import net.minecraft.nbt.NbtCompound
|
||||
import net.minecraft.server.world.ServerWorld
|
||||
import net.minecraft.util.Tickable
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.world.World
|
||||
|
||||
class MasterBlockEntity : ModBlockEntity(BlockEntityTypes.MASTER), Tickable {
|
||||
class MasterBlockEntity(pos: BlockPos, state: BlockState) : ModBlockEntity(BlockEntityTypes.MASTER, pos, state) {
|
||||
|
||||
val linkPos = BlockPosSet()
|
||||
val importPos = BlockPosSet()
|
||||
|
|
@ -97,18 +98,18 @@ class MasterBlockEntity : ModBlockEntity(BlockEntityTypes.MASTER), Tickable {
|
|||
}
|
||||
}
|
||||
|
||||
override fun toTag(tag: CompoundTag): CompoundTag {
|
||||
super.toTag(tag)
|
||||
override fun writeNbt(tag: NbtCompound): NbtCompound {
|
||||
super.writeNbt(tag)
|
||||
|
||||
tag.put("linkCables", linkPos.toTag())
|
||||
tag.put("exportCables", exportPos.toTag())
|
||||
tag.put("importCables", importPos.toTag())
|
||||
tag.put("linkCables", linkPos.toNbt())
|
||||
tag.put("exportCables", exportPos.toNbt())
|
||||
tag.put("importCables", importPos.toNbt())
|
||||
|
||||
return tag
|
||||
}
|
||||
|
||||
override fun fromTag(state: BlockState, tag: CompoundTag) {
|
||||
super.fromTag(state, tag)
|
||||
override fun readNbt(tag: NbtCompound) {
|
||||
super.readNbt(tag)
|
||||
|
||||
linkPos.fromTag(tag.getList("linkCables", NbtType.COMPOUND))
|
||||
exportPos.fromTag(tag.getList("exportCables", NbtType.COMPOUND))
|
||||
|
|
@ -127,32 +128,36 @@ class MasterBlockEntity : ModBlockEntity(BlockEntityTypes.MASTER), Tickable {
|
|||
watchers.forEach { it.onMasterRemoved() }
|
||||
}
|
||||
|
||||
override fun tick() {
|
||||
tick++
|
||||
if (tick == 10) {
|
||||
importCables.clear()
|
||||
val world = getWorld() ?: return
|
||||
importPos.forEach {
|
||||
val blockEntity = world.getBlockEntity(it)
|
||||
if (blockEntity is ImportCableBlockEntity) importCables.add(blockEntity)
|
||||
}
|
||||
importCables.sortByDescending { it.priority }
|
||||
for (cable in importCables) {
|
||||
if (cable.transfer(world, this)) break
|
||||
}
|
||||
} else if (tick == 20) {
|
||||
tick = 0
|
||||
exportCables.clear()
|
||||
val world = getWorld() ?: return
|
||||
exportPos.forEach {
|
||||
val blockEntity = world.getBlockEntity(it)
|
||||
if (blockEntity is ExportCableBlockEntity) exportCables.add(blockEntity)
|
||||
}
|
||||
exportCables.sortByDescending { it.priority }
|
||||
for (cable in exportCables) {
|
||||
if (cable.transfer(world, this)) break
|
||||
object Ticker : BlockEntityTicker<MasterBlockEntity> {
|
||||
|
||||
override fun tick(world: World, pos: BlockPos, state: BlockState, masterBlockEntity: MasterBlockEntity) {
|
||||
masterBlockEntity.apply {
|
||||
tick++
|
||||
if (tick == 10) {
|
||||
importCables.clear()
|
||||
importPos.forEach {
|
||||
val blockEntity = world.getBlockEntity(it)
|
||||
if (blockEntity is ImportCableBlockEntity) importCables.add(blockEntity)
|
||||
}
|
||||
importCables.sortByDescending { it.priority }
|
||||
for (cable in importCables) {
|
||||
if (cable.transfer(world, this)) break
|
||||
}
|
||||
} else if (tick == 20) {
|
||||
tick = 0
|
||||
exportCables.clear()
|
||||
exportPos.forEach {
|
||||
val blockEntity = world.getBlockEntity(it)
|
||||
if (blockEntity is ExportCableBlockEntity) exportCables.add(blockEntity)
|
||||
}
|
||||
exportCables.sortByDescending { it.priority }
|
||||
for (cable in exportCables) {
|
||||
if (cable.transfer(world, this)) break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
package badasintended.slotlink.block.entity
|
||||
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.block.entity.BlockEntity
|
||||
import net.minecraft.block.entity.BlockEntityType
|
||||
import net.minecraft.server.world.ServerWorld
|
||||
import net.minecraft.util.math.BlockPos
|
||||
|
||||
abstract class ModBlockEntity(type: BlockEntityType<out BlockEntity>) : BlockEntity(type) {
|
||||
abstract class ModBlockEntity(type: BlockEntityType<out BlockEntity>, pos: BlockPos, state: BlockState) :
|
||||
BlockEntity(type, pos, state) {
|
||||
|
||||
override fun markDirty() {
|
||||
super.markDirty()
|
||||
|
|
|
|||
|
|
@ -4,13 +4,17 @@ import badasintended.slotlink.init.BlockEntityTypes
|
|||
import badasintended.slotlink.screen.RequestScreenHandler
|
||||
import badasintended.slotlink.util.BlockEntityWatcher
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.entity.player.PlayerEntity
|
||||
import net.minecraft.entity.player.PlayerInventory
|
||||
import net.minecraft.screen.NamedScreenHandlerFactory
|
||||
import net.minecraft.screen.ScreenHandler
|
||||
import net.minecraft.text.TranslatableText
|
||||
import net.minecraft.util.math.BlockPos
|
||||
|
||||
class RequestBlockEntity : ChildBlockEntity(BlockEntityTypes.REQUEST), NamedScreenHandlerFactory {
|
||||
class RequestBlockEntity(pos: BlockPos, state: BlockState) :
|
||||
ChildBlockEntity(BlockEntityTypes.REQUEST, pos, state),
|
||||
NamedScreenHandlerFactory {
|
||||
|
||||
val watchers = ObjectOpenHashSet<BlockEntityWatcher<RequestBlockEntity>>()
|
||||
|
||||
|
|
|
|||
|
|
@ -13,15 +13,17 @@ import net.minecraft.block.entity.BlockEntity
|
|||
import net.minecraft.block.entity.BlockEntityType
|
||||
import net.minecraft.entity.player.PlayerEntity
|
||||
import net.minecraft.entity.player.PlayerInventory
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.NbtCompound
|
||||
import net.minecraft.network.PacketByteBuf
|
||||
import net.minecraft.screen.ScreenHandler
|
||||
import net.minecraft.screen.ScreenHandlerContext
|
||||
import net.minecraft.server.network.ServerPlayerEntity
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.util.math.Direction
|
||||
import net.minecraft.world.World
|
||||
|
||||
abstract class TransferCableBlockEntity(type: BlockEntityType<out BlockEntity>) : ConnectorCableBlockEntity(type) {
|
||||
abstract class TransferCableBlockEntity(type: BlockEntityType<out BlockEntity>, pos: BlockPos, state: BlockState) :
|
||||
ConnectorCableBlockEntity(type, pos, state) {
|
||||
|
||||
var redstone = OFF
|
||||
|
||||
|
|
@ -41,15 +43,15 @@ abstract class TransferCableBlockEntity(type: BlockEntityType<out BlockEntity>)
|
|||
|
||||
override fun Block.isIgnored() = this is ModBlock
|
||||
|
||||
override fun fromTag(state: BlockState, tag: CompoundTag) {
|
||||
super.fromTag(state, tag)
|
||||
override fun readNbt(tag: NbtCompound) {
|
||||
super.readNbt(tag)
|
||||
|
||||
side = Direction.byId(tag.getInt("side"))
|
||||
redstone = RedstoneMode.of(tag.getInt("redstone"))
|
||||
}
|
||||
|
||||
override fun toTag(tag: CompoundTag): CompoundTag {
|
||||
super.toTag(tag)
|
||||
override fun writeNbt(tag: NbtCompound): NbtCompound {
|
||||
super.writeNbt(tag)
|
||||
|
||||
tag.putInt("side", side.id)
|
||||
tag.putInt("redstone", redstone.ordinal)
|
||||
|
|
@ -58,7 +60,16 @@ abstract class TransferCableBlockEntity(type: BlockEntityType<out BlockEntity>)
|
|||
}
|
||||
|
||||
override fun createMenu(syncId: Int, inv: PlayerInventory, player: PlayerEntity): ScreenHandler? {
|
||||
return TransferScreenHandler(syncId, inv, priority, isBlackList, filter, side, redstone, ScreenHandlerContext.create(world, pos))
|
||||
return TransferScreenHandler(
|
||||
syncId,
|
||||
inv,
|
||||
priority,
|
||||
isBlackList,
|
||||
filter,
|
||||
side,
|
||||
redstone,
|
||||
ScreenHandlerContext.create(world, pos)
|
||||
)
|
||||
}
|
||||
|
||||
override fun writeScreenOpeningData(player: ServerPlayerEntity, buf: PacketByteBuf) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
package badasintended.slotlink.client.compat.rei
|
||||
|
||||
/*
|
||||
import badasintended.slotlink.client.gui.screen.RequestScreen
|
||||
import badasintended.slotlink.client.gui.screen.reiSearchHandler
|
||||
import badasintended.slotlink.client.gui.widget.MultiSlotWidget
|
||||
|
|
@ -88,4 +88,4 @@ class ReiPlugin : REIPluginV0 {
|
|||
})
|
||||
}
|
||||
|
||||
}
|
||||
}*/
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import badasintended.slotlink.util.bool
|
|||
import badasintended.slotlink.util.int
|
||||
import net.fabricmc.api.EnvType
|
||||
import net.fabricmc.api.Environment
|
||||
import net.minecraft.client.MinecraftClient
|
||||
import net.minecraft.client.util.math.MatrixStack
|
||||
import net.minecraft.entity.player.PlayerInventory
|
||||
import net.minecraft.text.Text
|
||||
|
|
@ -27,6 +26,8 @@ open class LinkScreen<H : LinkScreenHandler>(h: H, inventory: PlayerInventory, t
|
|||
override fun init() {
|
||||
super.init()
|
||||
|
||||
titleX = (backgroundWidth - textRenderer.getWidth(title)) / 2
|
||||
|
||||
val x = x + 7
|
||||
val y = y + titleY + 11
|
||||
|
||||
|
|
@ -74,12 +75,6 @@ open class LinkScreen<H : LinkScreenHandler>(h: H, inventory: PlayerInventory, t
|
|||
}
|
||||
}
|
||||
|
||||
override fun init(client: MinecraftClient, width: Int, height: Int) {
|
||||
super.init(client, width, height)
|
||||
|
||||
titleX = (backgroundWidth - textRenderer.getWidth(title)) / 2
|
||||
}
|
||||
|
||||
override fun drawForeground(matrices: MatrixStack, mouseX: Int, mouseY: Int) {
|
||||
super.drawForeground(matrices, mouseX, mouseY)
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import badasintended.slotlink.screen.slot.LockedSlot
|
|||
import net.fabricmc.api.EnvType
|
||||
import net.fabricmc.api.Environment
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen
|
||||
import net.minecraft.client.gui.widget.AbstractButtonWidget
|
||||
import net.minecraft.client.gui.widget.ClickableWidget
|
||||
import net.minecraft.client.util.math.MatrixStack
|
||||
import net.minecraft.entity.player.PlayerInventory
|
||||
import net.minecraft.screen.ScreenHandler
|
||||
|
|
@ -22,22 +22,22 @@ abstract class ModScreen<H : ScreenHandler>(h: H, inventory: PlayerInventory, ti
|
|||
|
||||
abstract val baseTlKey: String
|
||||
|
||||
private var clickedElement: AbstractButtonWidget? = null
|
||||
var hoveredElement: AbstractButtonWidget? = null
|
||||
private var clickedElement: ClickableWidget? = null
|
||||
var hoveredElement: ClickableWidget? = null
|
||||
|
||||
fun tl(key: String, vararg args: Any) = TranslatableText("$baseTlKey.$key", *args)
|
||||
|
||||
protected inline fun <T : AbstractButtonWidget> add(t: T, func: T.() -> Unit = {}): T {
|
||||
return addButton(t).apply(func)
|
||||
protected inline fun <T : ClickableWidget> add(t: T, func: T.() -> Unit = {}): T {
|
||||
return addDrawableChild(t).apply(func)
|
||||
}
|
||||
|
||||
override fun render(matrices: MatrixStack, mouseX: Int, mouseY: Int, delta: Float) {
|
||||
super.render(matrices, mouseX, mouseY, delta)
|
||||
|
||||
if (playerInventory.cursorStack.isEmpty && focusedSlot != null && focusedSlot!!.hasStack()) {
|
||||
if (handler.cursorStack.isEmpty && focusedSlot != null && focusedSlot!!.hasStack()) {
|
||||
this.renderTooltip(matrices, focusedSlot!!.stack, mouseX, mouseY)
|
||||
} else {
|
||||
hoveredElement = hoveredElement(mouseX.toDouble(), mouseY.toDouble()).orElse(null) as? AbstractButtonWidget
|
||||
hoveredElement = hoveredElement(mouseX.toDouble(), mouseY.toDouble()).orElse(null) as? ClickableWidget
|
||||
if (hoveredElement !is InventorySortButton) hoveredElement?.renderToolTip(matrices, mouseX, mouseY)
|
||||
}
|
||||
}
|
||||
|
|
@ -83,12 +83,12 @@ abstract class ModScreen<H : ScreenHandler>(h: H, inventory: PlayerInventory, ti
|
|||
}
|
||||
|
||||
override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
|
||||
return buttons.any { it is KeyGrabber && it.onKey(keyCode, scanCode, modifiers) }
|
||||
return children().any { it is KeyGrabber && it.onKey(keyCode, scanCode, modifiers) }
|
||||
|| super.keyPressed(keyCode, scanCode, modifiers)
|
||||
}
|
||||
|
||||
override fun charTyped(char: Char, modifiers: Int): Boolean {
|
||||
return buttons.any { it is CharGrabber && it.onChar(char, modifiers) }
|
||||
return children().any { it is CharGrabber && it.onChar(char, modifiers) }
|
||||
|| super.charTyped(char, modifiers)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,8 +22,9 @@ import badasintended.slotlink.util.int
|
|||
import badasintended.slotlink.util.string
|
||||
import net.fabricmc.api.EnvType
|
||||
import net.fabricmc.api.Environment
|
||||
import net.minecraft.client.MinecraftClient
|
||||
import net.minecraft.client.gui.widget.AbstractButtonWidget
|
||||
import net.minecraft.client.gui.Element
|
||||
import net.minecraft.client.gui.Selectable
|
||||
import net.minecraft.client.gui.widget.ClickableWidget
|
||||
import net.minecraft.client.util.math.MatrixStack
|
||||
import net.minecraft.entity.player.PlayerInventory
|
||||
import net.minecraft.text.Text
|
||||
|
|
@ -65,12 +66,27 @@ class RequestScreen<H : RequestScreenHandler>(handler: H, inv: PlayerInventory,
|
|||
|
||||
private var skipChar = false
|
||||
|
||||
private var inventorySortButton: AbstractButtonWidget? = null
|
||||
private var inventorySortButton: ClickableWidget? = null
|
||||
|
||||
override val baseTlKey: String
|
||||
get() = "container.slotlink.request"
|
||||
|
||||
override fun init() {
|
||||
val craftHeight = if (craftingGrid) 67 else 0
|
||||
|
||||
var viewedHeight = 3
|
||||
for (i in 3..6) if (height > (119 + craftHeight + (i * 18))) viewedHeight = i
|
||||
|
||||
backgroundWidth = 9 * 18 + 14
|
||||
backgroundHeight = viewedHeight * 18 + 114 + craftHeight
|
||||
|
||||
handler.resize(viewedHeight, craftingGrid)
|
||||
c2s(RESIZE) {
|
||||
int(syncId)
|
||||
int(viewedHeight)
|
||||
bool(craftingGrid)
|
||||
}
|
||||
|
||||
super.init()
|
||||
|
||||
playerInventoryTitleY = backgroundHeight - 94
|
||||
|
|
@ -78,8 +94,6 @@ class RequestScreen<H : RequestScreenHandler>(handler: H, inv: PlayerInventory,
|
|||
val x = x + 7
|
||||
val y = y + titleY + 11
|
||||
|
||||
val craftHeight = if (craftingGrid) 67 else 0
|
||||
|
||||
// Linked slot view
|
||||
for (i in 0 until viewedHeight * 9) {
|
||||
add(MultiSlotWidget(handler, i, x + (i % 9) * 18, y + (i / 9) * 18))
|
||||
|
|
@ -162,7 +176,7 @@ class RequestScreen<H : RequestScreenHandler>(handler: H, inv: PlayerInventory,
|
|||
}
|
||||
}
|
||||
onHovered = { matrices, x, y ->
|
||||
if (playerInventory.cursorStack.isEmpty) {
|
||||
if (handler.cursorStack.isEmpty) {
|
||||
renderTooltip(matrices, tl("move.all"), x, y)
|
||||
} else {
|
||||
renderTooltip(matrices, tl("move.type"), x, y)
|
||||
|
|
@ -181,7 +195,7 @@ class RequestScreen<H : RequestScreenHandler>(handler: H, inv: PlayerInventory,
|
|||
}
|
||||
}
|
||||
onHovered = { matrices, x, y ->
|
||||
if (playerInventory.cursorStack.isEmpty) {
|
||||
if (handler.cursorStack.isEmpty) {
|
||||
renderTooltip(matrices, tl("restock.all"), x, y)
|
||||
} else {
|
||||
renderTooltip(matrices, tl("restock.cursor"), x, y)
|
||||
|
|
@ -251,35 +265,13 @@ class RequestScreen<H : RequestScreenHandler>(handler: H, inv: PlayerInventory,
|
|||
}
|
||||
}
|
||||
|
||||
override fun <T : AbstractButtonWidget?> addButton(button: T): T {
|
||||
if (button is InventorySortButton && !button.initialized) {
|
||||
button.initialized = true
|
||||
inventorySortButton = button
|
||||
return button
|
||||
override fun <T> addSelectableChild(child: T): T where T : Element?, T : Selectable? {
|
||||
if (child is ClickableWidget && child is InventorySortButton && !child.initialized) {
|
||||
child.initialized = true
|
||||
inventorySortButton = child
|
||||
return child
|
||||
}
|
||||
return super.addButton(button)
|
||||
}
|
||||
|
||||
/**
|
||||
* apparently this also called on resize
|
||||
*/
|
||||
override fun init(client: MinecraftClient, width: Int, height: Int) {
|
||||
val craftHeight = if (craftingGrid) 67 else 0
|
||||
|
||||
var viewedHeight = 3
|
||||
for (i in 3..6) if (height > (119 + craftHeight + (i * 18))) viewedHeight = i
|
||||
|
||||
backgroundWidth = 9 * 18 + 14
|
||||
backgroundHeight = viewedHeight * 18 + 114 + craftHeight
|
||||
|
||||
handler.resize(viewedHeight, craftingGrid)
|
||||
c2s(RESIZE) {
|
||||
int(syncId)
|
||||
int(viewedHeight)
|
||||
bool(craftingGrid)
|
||||
}
|
||||
|
||||
super.init(client, width, height)
|
||||
return super.addSelectableChild(child)
|
||||
}
|
||||
|
||||
override fun tick() {
|
||||
|
|
|
|||
|
|
@ -4,12 +4,13 @@ import badasintended.slotlink.client.util.bindGuiTexture
|
|||
import badasintended.slotlink.client.util.drawNinePatch
|
||||
import net.fabricmc.api.EnvType
|
||||
import net.fabricmc.api.Environment
|
||||
import net.minecraft.client.gui.widget.AbstractButtonWidget
|
||||
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder
|
||||
import net.minecraft.client.gui.widget.ClickableWidget
|
||||
import net.minecraft.client.util.math.MatrixStack
|
||||
import net.minecraft.text.LiteralText
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
class ButtonWidget(x: Int, y: Int, w: Int, h: Int = w) : AbstractButtonWidget(x, y, w, h, LiteralText.EMPTY) {
|
||||
class ButtonWidget(x: Int, y: Int, w: Int, h: Int = w) : ClickableWidget(x, y, w, h, LiteralText.EMPTY) {
|
||||
|
||||
var onHovered: (MatrixStack, Int, Int) -> Unit = { _, _, _ -> }
|
||||
var onPressed = { }
|
||||
|
|
@ -65,6 +66,8 @@ class ButtonWidget(x: Int, y: Int, w: Int, h: Int = w) : AbstractButtonWidget(x,
|
|||
return super.mouseReleased(mouseX, mouseY, button)
|
||||
}
|
||||
|
||||
override fun appendNarrations(builder: NarrationMessageBuilder?) {}
|
||||
|
||||
override fun renderToolTip(matrices: MatrixStack, mouseX: Int, mouseY: Int) {
|
||||
if (visible) onHovered.invoke(matrices, mouseX, mouseY)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,10 +11,8 @@ import net.fabricmc.api.Environment
|
|||
import net.minecraft.client.gui.screen.Screen
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
class CraftingResultSlotWidget(
|
||||
private val handler: RequestScreenHandler,
|
||||
x: Int, y: Int
|
||||
) : SlotWidget(x, y, 26, handler.playerInventory, { handler.result.getStack(0) }) {
|
||||
class CraftingResultSlotWidget(handler: RequestScreenHandler, x: Int, y: Int) :
|
||||
SlotWidget<RequestScreenHandler>(x, y, 26, handler, { handler.result.getStack(0) }) {
|
||||
|
||||
override fun onClick(button: Int) {
|
||||
c2s(Packets.CRAFTING_RESULT_SLOT_CLICK) {
|
||||
|
|
|
|||
|
|
@ -12,10 +12,10 @@ import net.minecraft.item.ItemStack
|
|||
|
||||
@Environment(EnvType.CLIENT)
|
||||
class FilterSlotWidget(
|
||||
private val handler: LinkScreenHandler,
|
||||
handler: LinkScreenHandler,
|
||||
private val index: Int,
|
||||
x: Int, y: Int
|
||||
) : SlotWidget(x, y, 18, handler.playerInv, { handler.filter[index].first }) {
|
||||
) : SlotWidget<LinkScreenHandler>(x, y, 18, handler, { handler.filter[index].first }) {
|
||||
|
||||
private val nbt get() = handler.filter[index].second
|
||||
|
||||
|
|
|
|||
|
|
@ -28,10 +28,10 @@ import net.minecraft.util.Formatting
|
|||
*/
|
||||
@Environment(EnvType.CLIENT)
|
||||
class MultiSlotWidget(
|
||||
private val handler: RequestScreenHandler,
|
||||
handler: RequestScreenHandler,
|
||||
private val index: Int,
|
||||
x: Int, y: Int
|
||||
) : SlotWidget(x, y, 18, handler.playerInventory, { handler.viewedStacks[index].first }),
|
||||
) : SlotWidget<RequestScreenHandler>(x, y, 18, handler, { handler.viewedStacks[index].first }),
|
||||
KeyGrabber {
|
||||
|
||||
private val count get() = handler.viewedStacks[index].second
|
||||
|
|
|
|||
|
|
@ -2,15 +2,18 @@ package badasintended.slotlink.client.gui.widget
|
|||
|
||||
import net.fabricmc.api.EnvType
|
||||
import net.fabricmc.api.Environment
|
||||
import net.minecraft.client.gui.widget.AbstractButtonWidget
|
||||
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder
|
||||
import net.minecraft.client.gui.widget.ClickableWidget
|
||||
import net.minecraft.client.sound.SoundManager
|
||||
import net.minecraft.text.LiteralText
|
||||
import net.minecraft.text.Text
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
abstract class NoSoundWidget(x: Int, y: Int, w: Int, h: Int, text: Text = LiteralText.EMPTY) :
|
||||
AbstractButtonWidget(x, y, w, h, text) {
|
||||
ClickableWidget(x, y, w, h, text) {
|
||||
|
||||
override fun playDownSound(soundManager: SoundManager) {}
|
||||
|
||||
override fun appendNarrations(builder: NarrationMessageBuilder) {}
|
||||
|
||||
}
|
||||
|
|
@ -6,15 +6,15 @@ import badasintended.slotlink.client.util.drawNinePatch
|
|||
import net.fabricmc.api.EnvType
|
||||
import net.fabricmc.api.Environment
|
||||
import net.minecraft.client.util.math.MatrixStack
|
||||
import net.minecraft.entity.player.PlayerInventory
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.screen.ScreenHandler
|
||||
import net.minecraft.text.LiteralText
|
||||
import net.minecraft.text.Text
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
abstract class SlotWidget(
|
||||
abstract class SlotWidget<SH : ScreenHandler>(
|
||||
x: Int, y: Int, s: Int,
|
||||
private val playerInventory: PlayerInventory,
|
||||
protected val handler: SH,
|
||||
private val stackGetter: () -> ItemStack
|
||||
) : NoSoundWidget(x, y, s, s, LiteralText.EMPTY) {
|
||||
|
||||
|
|
@ -51,7 +51,7 @@ abstract class SlotWidget(
|
|||
fill(matrices, x, y, x + 16, y + 16, -2130706433 /*0x80ffffff fuck*/)
|
||||
|
||||
client.apply {
|
||||
if (playerInventory.cursorStack.isEmpty && !stack.isEmpty) {
|
||||
if (handler.cursorStack.isEmpty && !stack.isEmpty) {
|
||||
val tooltips = stack.getTooltip(player) { options.advancedItemTooltips }
|
||||
appendTooltip(tooltips)
|
||||
currentScreen?.renderTooltip(matrices, tooltips, mouseX, mouseY)
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class TextFieldWidget(
|
|||
val tooltip = arrayListOf<Text>()
|
||||
|
||||
init {
|
||||
setHasBorder(false)
|
||||
setDrawsBackground(false)
|
||||
setEditableColor(0xffffff)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,11 +4,13 @@ package badasintended.slotlink.client.util
|
|||
|
||||
import badasintended.slotlink.util.buf
|
||||
import badasintended.slotlink.util.modId
|
||||
import com.mojang.blaze3d.systems.RenderSystem
|
||||
import net.fabricmc.api.EnvType
|
||||
import net.fabricmc.api.Environment
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking
|
||||
import net.minecraft.client.MinecraftClient
|
||||
import net.minecraft.client.gui.DrawableHelper
|
||||
import net.minecraft.client.render.GameRenderer
|
||||
import net.minecraft.client.util.math.MatrixStack
|
||||
import net.minecraft.network.PacketByteBuf
|
||||
import net.minecraft.util.Identifier
|
||||
|
|
@ -26,7 +28,8 @@ inline fun c2s(id: Identifier, buf: PacketByteBuf.() -> Unit) {
|
|||
}
|
||||
|
||||
fun bindGuiTexture() {
|
||||
client.textureManager.bindTexture(guiTexture)
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader)
|
||||
RenderSystem.setShaderTexture(0, guiTexture)
|
||||
}
|
||||
|
||||
private typealias DH = DrawableHelper
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ import badasintended.slotlink.block.entity.ExportCableBlockEntity
|
|||
import badasintended.slotlink.block.entity.ImportCableBlockEntity
|
||||
import badasintended.slotlink.block.entity.LinkCableBlockEntity
|
||||
import badasintended.slotlink.block.entity.MasterBlockEntity
|
||||
import badasintended.slotlink.block.entity.ModBlockEntity
|
||||
import badasintended.slotlink.block.entity.RequestBlockEntity
|
||||
import badasintended.slotlink.util.BlockEntityBuilder
|
||||
import net.minecraft.block.entity.BlockEntityType
|
||||
import net.minecraft.util.registry.Registry
|
||||
import badasintended.slotlink.init.Blocks as B
|
||||
|
|
@ -34,7 +34,7 @@ object BlockEntityTypes : Initializer {
|
|||
EXPORT_CABLE = r(B.EXPORT_CABLE, ::ExportCableBlockEntity)
|
||||
}
|
||||
|
||||
private fun <E : ModBlockEntity> r(block: ModBlock, function: () -> E): BlockEntityType<E> {
|
||||
private fun r(block: ModBlock, function: BlockEntityBuilder): T {
|
||||
return Registry.register(
|
||||
Registry.BLOCK_ENTITY_TYPE, block.id, BlockEntityType.Builder.create(function, block).build(null)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -223,7 +223,7 @@ object Packets : Initializer {
|
|||
val stack = buf.stack
|
||||
|
||||
client.execute {
|
||||
client.player!!.inventory.cursorStack = stack
|
||||
client.player!!.currentScreenHandler.cursorStack = stack
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,15 +4,14 @@ import badasintended.slotlink.block.MasterBlock
|
|||
import badasintended.slotlink.block.entity.MasterBlockEntity
|
||||
import badasintended.slotlink.screen.RemoteScreenHandler
|
||||
import badasintended.slotlink.util.actionBar
|
||||
import badasintended.slotlink.util.toNbt
|
||||
import badasintended.slotlink.util.toPos
|
||||
import badasintended.slotlink.util.toTag
|
||||
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory
|
||||
import net.minecraft.client.item.TooltipContext
|
||||
import net.minecraft.entity.player.PlayerEntity
|
||||
import net.minecraft.entity.player.PlayerInventory
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.item.ItemUsageContext
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.network.PacketByteBuf
|
||||
import net.minecraft.screen.ScreenHandler
|
||||
import net.minecraft.server.network.ServerPlayerEntity
|
||||
|
|
@ -64,9 +63,9 @@ open class MultiDimRemoteItem(id: String = "multi_dim_remote") : ModItem(id, SET
|
|||
}
|
||||
|
||||
val masterPosTag = stack.orCreateTag.getCompound("masterPos")
|
||||
val masterDim = RegistryKey.of(Registry.DIMENSION, Identifier(stack.orCreateTag.getString("masterDim")))
|
||||
val masterDim = RegistryKey.of(Registry.WORLD_KEY, Identifier(stack.orCreateTag.getString("masterDim")))
|
||||
|
||||
if (masterPosTag == CompoundTag()) {
|
||||
if (masterPosTag.isEmpty) {
|
||||
player.actionBar("${baseTlKey}.hasNoMaster")
|
||||
} else use(world, player, stack, hand, masterPosTag.toPos(), masterDim)
|
||||
|
||||
|
|
@ -83,7 +82,7 @@ open class MultiDimRemoteItem(id: String = "multi_dim_remote") : ModItem(id, SET
|
|||
val block = world.getBlockState(pos).block
|
||||
if (block is MasterBlock) {
|
||||
if (player != null) if (player.isSneaking) {
|
||||
stack.orCreateTag.put("masterPos", pos.toTag())
|
||||
stack.orCreateTag.put("masterPos", pos.toNbt())
|
||||
stack.orCreateTag.putString("masterDim", dimId)
|
||||
player.actionBar("${baseTlKey}.linked", pos.x, pos.y, pos.z, dimId)
|
||||
return ActionResult.SUCCESS
|
||||
|
|
@ -99,7 +98,7 @@ open class MultiDimRemoteItem(id: String = "multi_dim_remote") : ModItem(id, SET
|
|||
tooltip.add(TranslatableText("${baseTlKey}.useTooltip").formatted(Formatting.GRAY))
|
||||
|
||||
val masterPosTag = stack.orCreateTag.getCompound("masterPos")
|
||||
if (masterPosTag != CompoundTag()) {
|
||||
if (!masterPosTag.isEmpty) {
|
||||
val masterPos = masterPosTag.toPos()
|
||||
val masterDim = Identifier(stack.orCreateTag.getString("masterDim"))
|
||||
tooltip.add(
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import net.minecraft.screen.slot.Slot
|
|||
@Suppress("LeakingThis")
|
||||
open class LinkScreenHandler(
|
||||
syncId: Int,
|
||||
val playerInv: PlayerInventory,
|
||||
playerInv: PlayerInventory,
|
||||
var priority: Int,
|
||||
var blacklist: Boolean,
|
||||
val filter: MutableList<Pair<ItemStack, Boolean>>,
|
||||
|
|
@ -37,14 +37,14 @@ open class LinkScreenHandler(
|
|||
|
||||
fun filterSlotClick(i: Int, button: Int) {
|
||||
if (button !in 0..1) return
|
||||
val stack = playerInv.cursorStack.copy().apply { count = 1 }
|
||||
val stack = cursorStack.copy().apply { count = 1 }
|
||||
if (button != 1) stack.tag = null
|
||||
filter[i] = stack to (button == 1 && !playerInv.cursorStack.isEmpty)
|
||||
filter[i] = stack to (button == 1 && cursorStack.isEmpty)
|
||||
}
|
||||
|
||||
override fun transferSlot(player: PlayerEntity, index: Int): ItemStack {
|
||||
var itemStack = ItemStack.EMPTY
|
||||
val slot = slots[index] ?: return itemStack
|
||||
val slot = slots[index]
|
||||
if (slot.hasStack()) {
|
||||
val itemStack2 = slot.stack
|
||||
itemStack = itemStack2.copy()
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import badasintended.slotlink.init.Screens
|
|||
import badasintended.slotlink.inventory.FilteredInventory
|
||||
import badasintended.slotlink.item.MultiDimRemoteItem
|
||||
import badasintended.slotlink.screen.slot.LockedSlot
|
||||
import badasintended.slotlink.util.index
|
||||
import net.minecraft.entity.player.PlayerInventory
|
||||
import net.minecraft.network.PacketByteBuf
|
||||
import net.minecraft.screen.ScreenHandlerType
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ import badasintended.slotlink.util.MasterWatcher
|
|||
import badasintended.slotlink.util.Sort
|
||||
import badasintended.slotlink.util.actionBar
|
||||
import badasintended.slotlink.util.allEmpty
|
||||
import badasintended.slotlink.util.index
|
||||
import badasintended.slotlink.util.input
|
||||
import badasintended.slotlink.util.int
|
||||
import badasintended.slotlink.util.isItemAndTagEqual
|
||||
|
|
@ -114,7 +113,6 @@ open class RequestScreenHandler(
|
|||
}
|
||||
|
||||
addListener(object : ScreenHandlerListener {
|
||||
override fun onHandlerRegistered(handler: ScreenHandler, stacks: DefaultedList<ItemStack>) {}
|
||||
override fun onPropertyUpdate(handler: ScreenHandler, property: Int, value: Int) {}
|
||||
|
||||
override fun onSlotUpdate(handler: ScreenHandler, slotId: Int, stack: ItemStack) {
|
||||
|
|
@ -153,8 +151,9 @@ open class RequestScreenHandler(
|
|||
!Registry.ITEM.getId(it.stack.item).toString().contains(value, true)
|
||||
}
|
||||
'#' -> filledSlots.removeIf r@{ entry ->
|
||||
val tags =
|
||||
player.world.tagManager.items.tags.filterValues { it.contains(entry.stack.item) }.keys
|
||||
val tags = player.world.tagManager
|
||||
.getOrCreateTagGroup(Registry.ITEM_KEY)
|
||||
.tags.filterValues { it.contains(entry.stack.item) }.keys
|
||||
if (tags.isEmpty() && value.isBlank()) return@r false
|
||||
else return@r tags.none { it.toString().contains(value, true) }
|
||||
}
|
||||
|
|
@ -207,7 +206,7 @@ open class RequestScreenHandler(
|
|||
/** server only **/
|
||||
fun multiSlotAction(i: Int, data: Int, type: SlotActionType) {
|
||||
val viewed = viewedStacks[i].first
|
||||
var cursor = playerInventory.cursorStack
|
||||
var cursor = cursorStack
|
||||
|
||||
if (cursor.isEmpty) {
|
||||
if (type == CLONE) {
|
||||
|
|
@ -256,7 +255,7 @@ open class RequestScreenHandler(
|
|||
fun craftingResultSlotClick(button: Int, quickMove: Boolean) {
|
||||
if (button !in 0..2) return
|
||||
|
||||
var cursor = playerInventory.cursorStack
|
||||
var cursor = cursorStack
|
||||
val resultStack = result.getStack(0)
|
||||
|
||||
if (button == 2) {
|
||||
|
|
@ -316,7 +315,7 @@ open class RequestScreenHandler(
|
|||
if (recipe.type == RecipeType.CRAFTING) {
|
||||
clearCraftingGrid()
|
||||
sendContentUpdates()
|
||||
alignRecipeToGrid(3, 3, -1, recipe, recipe.previewInputs.iterator(), 0)
|
||||
alignRecipeToGrid(3, 3, -1, recipe, recipe.ingredients.iterator(), 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -328,7 +327,7 @@ open class RequestScreenHandler(
|
|||
}
|
||||
|
||||
fun move() {
|
||||
var cursor = playerInventory.cursorStack
|
||||
var cursor = cursorStack
|
||||
slots.forEach {
|
||||
if (it.inventory is PlayerInventory
|
||||
&& it.index >= 9
|
||||
|
|
@ -347,7 +346,7 @@ open class RequestScreenHandler(
|
|||
}
|
||||
|
||||
fun restock() {
|
||||
var cursor = playerInventory.cursorStack
|
||||
var cursor = cursorStack
|
||||
if (cursor.isEmpty) slots.filter { it.inventory is PlayerInventory }.forEach {
|
||||
it.stack = it.stack.restock()
|
||||
} else {
|
||||
|
|
@ -382,7 +381,7 @@ open class RequestScreenHandler(
|
|||
}
|
||||
|
||||
private fun updateCursor(stack: ItemStack) {
|
||||
playerInventory.cursorStack = stack
|
||||
cursorStack = stack
|
||||
s2c(player, UPDATE_CURSOR) {
|
||||
stack(stack)
|
||||
}
|
||||
|
|
@ -433,13 +432,12 @@ open class RequestScreenHandler(
|
|||
}
|
||||
}
|
||||
|
||||
override fun onSlotClick(i: Int, j: Int, actionType: SlotActionType, playerEntity: PlayerEntity): ItemStack {
|
||||
if (playerEntity !is ServerPlayerEntity) return ItemStack.EMPTY
|
||||
val result = super.onSlotClick(i, j, actionType, playerEntity)
|
||||
override fun onSlotClick(i: Int, j: Int, actionType: SlotActionType, playerEntity: PlayerEntity) {
|
||||
if (playerEntity !is ServerPlayerEntity) return
|
||||
super.onSlotClick(i, j, actionType, playerEntity)
|
||||
s2c(playerEntity, UPDATE_CURSOR) {
|
||||
stack(playerEntity.inventory.cursorStack)
|
||||
stack(cursorStack)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
override fun transferSlot(player: PlayerEntity, index: Int): ItemStack {
|
||||
|
|
@ -548,7 +546,7 @@ open class RequestScreenHandler(
|
|||
slots.filter { it.inventory is CraftingInventory }.forEach {
|
||||
it.stack = moveStack(it.stack)
|
||||
}
|
||||
dropInventory(player, player.world, input)
|
||||
dropInventory(player, input)
|
||||
request?.watchers?.remove(this)
|
||||
request?.markDirty()
|
||||
master?.watchers?.remove(this)
|
||||
|
|
|
|||
|
|
@ -1,13 +1,9 @@
|
|||
package badasintended.slotlink.util
|
||||
|
||||
import badasintended.slotlink.mixin.CraftingScreenHandlerAccessor
|
||||
import badasintended.slotlink.mixin.SlotAccessor
|
||||
import badasintended.slotlink.mixin.TextFieldWidgetAccessor
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget
|
||||
import net.minecraft.screen.CraftingScreenHandler
|
||||
import net.minecraft.screen.slot.Slot
|
||||
|
||||
inline val Slot.index get() = (this as SlotAccessor).index
|
||||
|
||||
inline val CraftingScreenHandler.input get() = (this as CraftingScreenHandlerAccessor).input
|
||||
inline val CraftingScreenHandler.result get() = (this as CraftingScreenHandlerAccessor).result
|
||||
|
|
|
|||
|
|
@ -10,11 +10,13 @@ import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking
|
|||
import net.fabricmc.fabric.api.tag.TagRegistry
|
||||
import net.fabricmc.loader.api.FabricLoader
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.block.entity.BlockEntity
|
||||
import net.minecraft.entity.player.PlayerEntity
|
||||
import net.minecraft.inventory.Inventory
|
||||
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 net.minecraft.network.Packet
|
||||
import net.minecraft.network.PacketByteBuf
|
||||
import net.minecraft.server.network.ServerPlayerEntity
|
||||
|
|
@ -28,15 +30,18 @@ import net.minecraft.util.shape.VoxelShapes
|
|||
import org.apache.logging.log4j.LogManager
|
||||
import org.apache.logging.log4j.Logger
|
||||
|
||||
fun BlockPos.toTag(): CompoundTag {
|
||||
val tag = CompoundTag()
|
||||
typealias BlockPosSet = ObjectOpenHashSet<BlockPos>
|
||||
typealias BlockEntityBuilder = (BlockPos, BlockState) -> BlockEntity
|
||||
|
||||
fun BlockPos.toNbt(): NbtCompound {
|
||||
val tag = NbtCompound()
|
||||
tag.putInt("x", x)
|
||||
tag.putInt("y", y)
|
||||
tag.putInt("z", z)
|
||||
return tag
|
||||
}
|
||||
|
||||
fun CompoundTag.toPos(): BlockPos {
|
||||
fun NbtCompound.toPos(): BlockPos {
|
||||
return BlockPos(getInt("x"), getInt("y"), getInt("z"))
|
||||
}
|
||||
|
||||
|
|
@ -131,13 +136,12 @@ var Pair<Inventory, Int>.stack: ItemStack
|
|||
get() = first.getStack(second)
|
||||
set(value) = first.setStack(second, value)
|
||||
|
||||
typealias BlockPosSet = ObjectOpenHashSet<BlockPos>
|
||||
|
||||
fun BlockPosSet.toTag() = mapTo(ListTag(), BlockPos::toTag)
|
||||
fun BlockPosSet.toNbt() = mapTo(NbtList(), BlockPos::toNbt)
|
||||
|
||||
fun BlockPosSet.fromTag(tag: ListTag) {
|
||||
fun BlockPosSet.fromTag(tag: NbtList) {
|
||||
clear()
|
||||
tag.mapTo(this) { (it as CompoundTag).toPos() }
|
||||
tag.mapTo(this) { (it as NbtCompound).toPos() }
|
||||
}
|
||||
|
||||
fun hasMod(id: String) = FabricLoader.getInstance().isModLoaded(id)
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
"mixins" : ["slotlink.mixins.json"],
|
||||
"depends" : {
|
||||
"fabricloader" : ">=0.8",
|
||||
"minecraft" : "1.16.x",
|
||||
"minecraft" : "1.17.x",
|
||||
"fabric" : "*",
|
||||
"fabric-language-kotlin": ">=1.6"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,18 +2,14 @@
|
|||
"required" : true,
|
||||
"minVersion" : "0.8",
|
||||
"package" : "badasintended.slotlink.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"compatibilityLevel": "JAVA_16",
|
||||
"mixins" : [
|
||||
"CraftingScreenHandlerAccessor",
|
||||
"DoubleInventoryMixin",
|
||||
"SlotAccessor",
|
||||
"TextFieldWidgetAccessor",
|
||||
"WallMountedBlockMixin",
|
||||
"pseudo.DoubleSidedInventoryMixin"
|
||||
],
|
||||
"client" : [
|
||||
"pseudo.SortButtonWidgetMixin"
|
||||
],
|
||||
"client" : ["TextFieldWidgetAccessor", "pseudo.SortButtonWidgetMixin"],
|
||||
"injectors" : {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue