Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ repositories {
maven("https://maven.shedaniel.me/")
maven("https://maven.terraformersmc.com/releases")
maven("https://maven.blamejared.com/")
maven("https://ladysnake.jfrog.io/artifactory/mods")
maven("https://maven.ladysnake.org/releases")
}

dependencies {
Expand Down
28 changes: 14 additions & 14 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
kotlin.code.style = official
org.gradle.jvmargs = -Xmx1G
org.gradle.jvmargs = -Xmx2G

run_args = -Dmixin.debug.export=true

# Fabric properties
minecraft = 1.19.4
yarn = 1.19.4+build.2
fabricLoader = 0.14.19
minecraft = 1.20.1
yarn = 1.20.1+build.10
fabricLoader = 0.15.11

# Mod properties
maven_group = com.github.badasintended
archives_base_name = slotlink

# Dependencies
fabricApi = 0.75.3+1.19.4
fabricKotlin = 1.9.2+kotlin.1.8.10
cca = 5.1.0
trinkets = 3.6.0
architectury = 8.1.73
wthit = 7.1.1
badpackets = 0.4.1
fabricApi = 0.92.2+1.20.1
fabricKotlin = 1.10.9+kotlin.1.9.0
cca = 5.2.2
trinkets = 3.7.2
architectury = 9.2.14
wthit = 8.12.0
badpackets = 0.4.3

# Recipe Viewer
recipeViewer = jei
rei = 11.0.593
jei = 1.19.4-13.0.0.1
jei = 1.20.1-15.3.0.4
emi = 0.7.1+1.19.4

# CurseForge
cf.projectId = 391014
cf.releaseType = release
cf.gameVersion = 1.19.4
cf.gameVersion = 1.20.1
cf.require = fabric-api, fabric-language-kotlin
cf.optional = roughly-enough-items, jei, emi, wthit, trinkets

# Modrinth
mr.projectId = FTMcNdhv
mr.releaseType = release
mr.gameVersion = 1.19.4
mr.gameVersion = 1.20.1
mr.require = P7dR8mSH, Ha28R6CL
mr.optional = 6AQIaxuO, u6dRKJwZ, fRiHVvU7, nfn13YXA, 5aaWibi9
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package badasintended.slotlink.mixin;

import net.minecraft.inventory.CraftingInventory;
import net.minecraft.inventory.CraftingResultInventory;
import net.minecraft.inventory.RecipeInputInventory;
import net.minecraft.screen.CraftingScreenHandler;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -12,7 +12,7 @@ public interface CraftingScreenHandlerAccessor {

@NotNull
@Accessor
CraftingInventory getInput();
RecipeInputInventory getInput();

@NotNull
@Accessor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.WorldGenerationProgressListener;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.random.RandomSequencesState;
import net.minecraft.world.PersistentStateManager;
import net.minecraft.world.dimension.DimensionOptions;
import net.minecraft.world.level.ServerWorldProperties;
Expand All @@ -30,7 +31,7 @@ public abstract class ServerWorldMixin implements NetworkStateHolder {
private NetworkState networkState;

@Inject(method = "<init>", at = @At("TAIL"))
private void slotlink$initNetworkState(MinecraftServer server, Executor workerExecutor, LevelStorage.Session session, ServerWorldProperties properties, RegistryKey<?> worldKey, DimensionOptions dimensionOptions, WorldGenerationProgressListener worldGenerationProgressListener, boolean debugWorld, long seed, List<?> spawners, boolean shouldTickTime, CallbackInfo ci) {
private void slotlink$initNetworkState(MinecraftServer server, Executor workerExecutor, LevelStorage.Session session, ServerWorldProperties properties, RegistryKey<?> worldKey, DimensionOptions dimensionOptions, WorldGenerationProgressListener worldGenerationProgressListener, boolean debugWorld, long seed, List<?> spawners, boolean shouldTickTime, RandomSequencesState randomSequencesState, CallbackInfo ci) {
ServerWorld self = (ServerWorld) (Object) this;
networkState = getPersistentStateManager().getOrCreate(nbt -> NetworkState.create(self, nbt), NetworkState::new, "slotlink");
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/badasintended/slotlink/block/CableBlock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
import net.fabricmc.fabric.api.`object`.builder.v1.block.FabricBlockSettings
import net.minecraft.block.Block
import net.minecraft.block.BlockState
import net.minecraft.block.Material
import net.minecraft.block.MapColor
import net.minecraft.block.ShapeContext
import net.minecraft.item.ItemPlacementContext
import net.minecraft.state.StateManager
Expand All @@ -30,7 +30,8 @@ open class CableBlock(id: String = "cable", be: BlockEntityBuilder = ::CableBloc
companion object {

val SETTINGS: Settings = FabricBlockSettings
.of(Material.GLASS)
.create()
.mapColor(MapColor.WHITE)
.hardness(3f)

val PROPERTIES = mapOf(
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/badasintended/slotlink/block/ModBlock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import net.fabricmc.fabric.api.`object`.builder.v1.block.FabricBlockSettings
import net.minecraft.block.BlockRenderType
import net.minecraft.block.BlockState
import net.minecraft.block.BlockWithEntity
import net.minecraft.block.Material
import net.minecraft.block.MapColor

abstract class ModBlock(id: String, settings: Settings = SETTINGS) : BlockWithEntity(settings) {

companion object {

val SETTINGS: Settings = FabricBlockSettings
.of(Material.STONE)
.create()
.mapColor(MapColor.WHITE)
.hardness(5f)

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import badasintended.slotlink.screen.ConnectorCableScreenHandler
import badasintended.slotlink.util.int
import net.fabricmc.api.EnvType
import net.fabricmc.api.Environment
import net.minecraft.client.util.math.MatrixStack
import net.minecraft.client.gui.DrawContext
import net.minecraft.entity.player.PlayerInventory
import net.minecraft.text.Text

Expand Down Expand Up @@ -55,10 +55,10 @@ open class ConnectorCableScreen<H : ConnectorCableScreenHandler>(h: H, inventory
}
}

override fun drawForeground(matrices: MatrixStack, mouseX: Int, mouseY: Int) {
super.drawForeground(matrices, mouseX, mouseY)
override fun drawForeground(context: DrawContext, mouseX: Int, mouseY: Int) {
super.drawForeground(context, mouseX, mouseY)

textRenderer.draw(matrices, "$priority", 7 + 2 * 18f, titleY + 31f, 4210752)
context.drawText(textRenderer, "$priority", 7 + 2 * 18, titleY + 31, 4210752, false)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package badasintended.slotlink.client.gui.screen
import badasintended.slotlink.client.gui.widget.ButtonWidget
import badasintended.slotlink.client.gui.widget.FilterSlotWidget
import badasintended.slotlink.client.util.GuiTextures
import badasintended.slotlink.client.util.bind
import badasintended.slotlink.client.util.c2s
import badasintended.slotlink.init.Packets.FILTER_SETTINGS
import badasintended.slotlink.screen.FilterScreenHandler
import badasintended.slotlink.util.bool
import badasintended.slotlink.util.int
import net.fabricmc.api.EnvType
import net.fabricmc.api.Environment
import net.minecraft.client.util.math.MatrixStack
import net.minecraft.client.gui.DrawContext
import net.minecraft.entity.player.PlayerInventory
import net.minecraft.text.Text

Expand Down Expand Up @@ -53,11 +52,10 @@ open class FilterScreen<H : FilterScreenHandler>(h: H, inventory: PlayerInventor
}
}

override fun drawBackground(matrices: MatrixStack, delta: Float, mouseX: Int, mouseY: Int) {
super.drawBackground(matrices, delta, mouseX, mouseY)
override fun drawBackground(context: DrawContext, delta: Float, mouseX: Int, mouseY: Int) {
super.drawBackground(context, delta, mouseX, mouseY)

GuiTextures.FILTER.bind()
drawTexture(matrices, x, y, 0, 0, 176, 166)
context.drawTexture(GuiTextures.FILTER, x, y, 0, 0, 176, 166)
}

protected open fun sync() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import badasintended.slotlink.client.gui.widget.KeyGrabber
import badasintended.slotlink.client.gui.widget.TooltipRenderer
import net.fabricmc.api.EnvType
import net.fabricmc.api.Environment
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.gui.screen.ingame.HandledScreen
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
import net.minecraft.text.Text
Expand All @@ -27,19 +27,19 @@ abstract class ModScreen<H : ScreenHandler>(h: H, inventory: PlayerInventory, ti
return addDrawableChild(t).apply(func)
}

override fun render(matrices: MatrixStack, mouseX: Int, mouseY: Int, delta: Float) {
super.render(matrices, mouseX, mouseY, delta)
override fun render(context: DrawContext, mouseX: Int, mouseY: Int, delta: Float) {
super.render(context, mouseX, mouseY, delta)

if (handler.cursorStack.isEmpty && focusedSlot != null && focusedSlot!!.hasStack()) {
this.renderTooltip(matrices, focusedSlot!!.stack, mouseX, mouseY)
context.drawTooltip(this.textRenderer, focusedSlot!!.stack.name, mouseX, mouseY)
} else {
hoveredElement = hoveredElement(mouseX.toDouble(), mouseY.toDouble()).orElse(null) as? ClickableWidget
(hoveredElement as? TooltipRenderer)?.renderTooltip(matrices, mouseX, mouseY)
(hoveredElement as? TooltipRenderer)?.renderTooltip(context, mouseX, mouseY)
}
}

override fun drawBackground(matrices: MatrixStack, delta: Float, mouseX: Int, mouseY: Int) {
renderBackground(matrices)
override fun drawBackground(context: DrawContext, delta: Float, mouseX: Int, mouseY: Int) {
renderBackground(context)
}

override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package badasintended.slotlink.client.gui.screen

import badasintended.slotlink.client.gui.widget.ButtonWidget
import badasintended.slotlink.client.gui.widget.CraftingResultSlotWidget
import badasintended.slotlink.client.gui.widget.MultiSlotWidget
import badasintended.slotlink.client.gui.widget.ScrollBarWidget
import badasintended.slotlink.client.gui.widget.TextFieldWidget
import badasintended.slotlink.client.gui.widget.*
import badasintended.slotlink.client.util.GuiTextures
import badasintended.slotlink.client.util.bind
import badasintended.slotlink.client.util.c2s
import badasintended.slotlink.compat.invsort.InventorySortButton
import badasintended.slotlink.compat.recipe.RecipeViewer
Expand All @@ -25,10 +20,10 @@ import badasintended.slotlink.util.int
import badasintended.slotlink.util.string
import net.fabricmc.api.EnvType
import net.fabricmc.api.Environment
import net.minecraft.client.gui.DrawContext
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
import org.lwjgl.glfw.GLFW
Expand All @@ -37,11 +32,19 @@ import badasintended.slotlink.util.backgroundWidth as utilBackgroundWidth
import badasintended.slotlink.util.x as utilX
import badasintended.slotlink.util.y as utilY

import net.minecraft.client.gui.screen.recipebook.RecipeBookProvider
import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget
import net.minecraft.client.gui.widget.TexturedButtonWidget
import net.minecraft.screen.AbstractRecipeScreenHandler
import net.minecraft.util.Identifier

@Environment(EnvType.CLIENT)
class RequestScreen<H : RequestScreenHandler>(handler: H, inv: PlayerInventory, title: Text) :
ModScreen<H>(handler, inv, title) {
ModScreen<H>(handler, inv, title), RecipeBookProvider {

var craftingGrid by config::showCraftingGrid
private val recipeBook = RecipeBookWidget()
private val RECIPE_BUTTON_TEXTURE = Identifier("textures/gui/recipe_button.png")

var arrowX = -1
var arrowY = -1
Expand Down Expand Up @@ -88,9 +91,54 @@ class RequestScreen<H : RequestScreenHandler>(handler: H, inv: PlayerInventory,

playerInventoryTitleY = backgroundHeight - 94

val x = x + 7
var x = x + 7
val y = y + titleY + 11

if (craftingGrid) {
recipeBook.initialize(width, height, client, width < 379, handler as AbstractRecipeScreenHandler<*>)
this.x = recipeBook.findLeftEdge(width, backgroundWidth)
x = this.x + 7
add(TexturedButtonWidget(
x - 2, y + viewedHeight * 18 + 27, 20, 18, 0, 0, 19, RECIPE_BUTTON_TEXTURE
) {
recipeBook.toggleOpen()
val oldX = this.x
this.x = recipeBook.findLeftEdge(width, backgroundWidth)
val offset = this.x - oldX
arrowX += offset
for (i in children()) {
if (i is ClickableWidget) {
i.x += offset
if (i is SlotWidget<*>) {
i.offsetX(offset)
}
}
}
})
addSelectableChild(recipeBook)
setInitialFocus(recipeBook)

// Crafting output slot
add(CraftingResultSlotWidget(handler, x + 108, y + viewedHeight * 18 + 27))

// Clear crafting grid button
add(ButtonWidget(x + 13, y + 18 + viewedHeight * 18, 8)) {
texture = GuiTextures.REQUEST
background = false
u = { 210 }
v = { 16 }
tooltip = { tl("craft.clear") }
onPressed = {
c2s(CLEAR_CRAFTING_GRID) {
int(syncId)
}
}
}

arrowX = x + 83
arrowY = y + 32 + viewedHeight * 18
}

// Linked slot view
for (i in 0 until viewedHeight * 9) {
add(MultiSlotWidget(handler, i, x + (i % 9) * 18, y + (i / 9) * 18))
Expand Down Expand Up @@ -283,36 +331,39 @@ class RequestScreen<H : RequestScreenHandler>(handler: H, inv: PlayerInventory,
if (searchBar.grab) searchBar.tick()
}

override fun drawBackground(matrices: MatrixStack, delta: Float, mouseX: Int, mouseY: Int) {
super.drawBackground(matrices, delta, mouseX, mouseY)
override fun render(context: DrawContext, mouseX: Int, mouseY: Int, delta: Float) {
super.render(context, mouseX, mouseY, delta)

recipeBook.render(context, mouseX, mouseY, delta)
}

override fun drawBackground(context: DrawContext, delta: Float, mouseX: Int, mouseY: Int) {
super.drawBackground(context, delta, mouseX, mouseY)

GuiTextures.REQUEST.bind()
val viewedH = viewedHeight * 18
drawTexture(matrices, x, y, 0, 0, 194, viewedH - 18 + 17)
drawTexture(matrices, x, y + viewedH - 18 + 17, 0, 107, 194, 115)
context.drawTexture(GuiTextures.REQUEST, x, y, 0, 0, 194, viewedH - 18 + 17)
context.drawTexture(GuiTextures.REQUEST, x, y + viewedH - 18 + 17, 0, 107, 194, 115)

if (craftingGrid) {
GuiTextures.CRAFTING.bind()
drawTexture(matrices, x, y + viewedH + 17 + 7, 0, 0, 176, 157)
context.drawTexture(GuiTextures.CRAFTING, x, y + viewedH + 17 + 7, 0, 0, 176, 157)
}
}

override fun drawForeground(matrices: MatrixStack, mouseX: Int, mouseY: Int) {
super.drawForeground(matrices, mouseX, mouseY)
override fun drawForeground(context: DrawContext, mouseX: Int, mouseY: Int) {
super.drawForeground(context, mouseX, mouseY)

GuiTextures.REQUEST.bind()
handler.slots.forEach {
if (it is LockedSlot) {
drawTexture(matrices, it.x, it.y, 240, 0, 16, 16)
context.drawTexture(GuiTextures.REQUEST, it.x, it.y, 240, 0, 16, 16)
}
}

if (craftingGrid) {
textRenderer.draw(matrices, craftingText, titleX + 21f, playerInventoryTitleY - 67f, 0x404040)
context.drawText(textRenderer, craftingText, titleX + 21, playerInventoryTitleY - 67, 0x404040, false)
}

if (x + titleX < mouseX && mouseX <= x + titleX + titleWidth && y + titleY < mouseY && mouseY <= y + titleY + textRenderer.fontHeight) {
renderTooltip(matrices, tl("slotCount", filledSlots, totalSlots), mouseX - x, mouseY - y)
context.drawTooltip(textRenderer, tl("slotCount", filledSlots, totalSlots), mouseX - x, mouseY - y)
}
}

Expand Down Expand Up @@ -359,4 +410,10 @@ class RequestScreen<H : RequestScreenHandler>(handler: H, inv: PlayerInventory,
super.close()
}

override fun refreshRecipeBook() {
recipeBook.refresh()
}

override fun getRecipeBookWidget(): RecipeBookWidget = recipeBook

}
Loading