Update to 1.20.1, and show vanilla recipe book on crafting grid

This commit is contained in:
tolziplohu 2024-06-09 22:01:07 -05:00
parent 76698973ef
commit eea76dc912
21 changed files with 195 additions and 126 deletions

View file

@ -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 {

View file

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

View file

@ -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;
@ -12,7 +12,7 @@ public interface CraftingScreenHandlerAccessor {
@NotNull
@Accessor
CraftingInventory getInput();
RecipeInputInventory getInput();
@NotNull
@Accessor

View file

@ -8,6 +8,7 @@ import net.minecraft.registry.RegistryKey;
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;
@ -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");
}

View file

@ -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
@ -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(

View file

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

View file

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

View file

@ -3,7 +3,6 @@ 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
@ -11,7 +10,7 @@ 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
@ -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() {

View file

@ -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
@ -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 {

View file

@ -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
@ -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
@ -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
@ -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))
@ -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)
}
}
@ -359,4 +410,10 @@ class RequestScreen<H : RequestScreenHandler>(handler: H, inv: PlayerInventory,
super.close()
}
override fun refreshRecipeBook() {
recipeBook.refresh()
}
override fun getRecipeBookWidget(): RecipeBookWidget = recipeBook
}

View file

@ -1,14 +1,13 @@
package badasintended.slotlink.client.gui.widget
import badasintended.slotlink.client.util.GuiTextures
import badasintended.slotlink.client.util.bind
import badasintended.slotlink.client.util.client
import net.fabricmc.api.EnvType
import net.fabricmc.api.Environment
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder
import net.minecraft.client.gui.tooltip.Tooltip
import net.minecraft.client.gui.widget.ClickableWidget
import net.minecraft.client.util.math.MatrixStack
import net.minecraft.screen.ScreenTexts
import net.minecraft.text.Text
@ -41,7 +40,7 @@ class ButtonWidget(x: Int, y: Int, w: Int, h: Int = w) : ClickableWidget(x, y, w
padding.b = b
}
override fun renderButton(matrices: MatrixStack, mouseX: Int, mouseY: Int, delta: Float) {
override fun renderButton(context: DrawContext, mouseX: Int, mouseY: Int, delta: Float) {
val tooltip = this.tooltip()
if (tooltip != lastTooltip) {
setTooltip(Tooltip.of(tooltip))
@ -49,15 +48,14 @@ class ButtonWidget(x: Int, y: Int, w: Int, h: Int = w) : ClickableWidget(x, y, w
}
if (!visible) return
texture.bind()
if (background) {
val u = if (hovered) bgU + width else bgU
drawTexture(matrices, x, y, u, bgV, width, height)
context.drawTexture(texture, x, y, u, bgV, width, height)
}
padding.apply {
drawTexture(matrices, x + l, y + t, u(), v(), width - l - r, height - t - b)
context.drawTexture(texture, x + l, y + t, u(), v(), width - l - r, height - t - b)
}
}

View file

@ -12,8 +12,8 @@ import badasintended.slotlink.util.stack
import net.fabricmc.api.EnvType
import net.fabricmc.api.Environment
import net.minecraft.client.MinecraftClient
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.gui.screen.Screen
import net.minecraft.client.util.math.MatrixStack
import net.minecraft.item.ItemStack
import net.minecraft.text.Text
import net.minecraft.util.Formatting
@ -42,21 +42,21 @@ class FilterSlotWidget(
tooltip.add(Text.translatable("container.slotlink.filter.slot.nbt.scroll").formatted(Formatting.GRAY))
}
override fun renderOverlay(matrices: MatrixStack, stack: ItemStack) {
super.renderOverlay(matrices, stack)
override fun renderOverlay(context: DrawContext, stack: ItemStack) {
super.renderOverlay(context, stack)
client.apply {
itemRenderer.renderGuiItemOverlay(matrices, textRenderer, stack, x + 1, y + 1, "")
context.drawItemInSlot(textRenderer, stack, x + 1, y + 1, "")
matrices.wrap {
matrices.translate(0.0, 0.0, 250.0)
fill(matrices, x + 1, y + 1, x + 17, y + 17, if (nbt) 0x70aa27ba else 0x408b8b8b)
context.matrices.wrap {
context.matrices.translate(0.0, 0.0, 250.0)
context.fill(x + 1, y + 1, x + 17, y + 17, if (nbt) 0x70aa27ba else 0x408b8b8b)
if (nbt) {
textRenderer.drawWithShadow(
matrices,
context.drawTextWithShadow(
textRenderer,
"+",
x + 17f - textRenderer.getWidth("+"),
y + 17f - textRenderer.fontHeight,
x + 17 - textRenderer.getWidth("+"),
y + 17 - textRenderer.fontHeight,
0xaa27ba
)
}
@ -64,16 +64,17 @@ class FilterSlotWidget(
}
}
override fun renderTooltip(matrices: MatrixStack, mouseX: Int, mouseY: Int) {
super.renderTooltip(matrices, mouseX, mouseY)
override fun renderTooltip(context: DrawContext, mouseX: Int, mouseY: Int) {
super.renderTooltip(context, mouseX, mouseY)
if (!handler.cursorStack.isEmpty || RecipeViewer.instance?.isDraggingStack == true) context.matrices.wrap {
context.matrices.translate(0.0, 0.0, +256.0)
if (!handler.cursorStack.isEmpty || RecipeViewer.instance?.isDraggingStack == true) matrices.wrap {
matrices.translate(0.0, 0.0, +256.0)
val tlKey = "container.slotlink.filter.slot.tip." +
if (Screen.hasControlDown()) "pressed" else
if (MinecraftClient.IS_SYSTEM_MAC) "cmd"
else "ctrl"
client.currentScreen?.renderTooltip(matrices, Text.translatable(tlKey), mouseX, mouseY)
context.drawTooltip(client.textRenderer, Text.translatable(tlKey), mouseX, mouseY)
}
}

View file

@ -11,8 +11,8 @@ import badasintended.slotlink.util.toFormattedString
import kotlin.math.ceil
import net.fabricmc.api.EnvType
import net.fabricmc.api.Environment
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.gui.screen.Screen
import net.minecraft.client.util.math.MatrixStack
import net.minecraft.item.ItemStack
import net.minecraft.screen.slot.SlotActionType.CLONE
import net.minecraft.screen.slot.SlotActionType.PICKUP
@ -36,21 +36,21 @@ class MultiSlotWidget(
private val count get() = handler.itemViews[index].count
override fun renderOverlay(matrices: MatrixStack, stack: ItemStack) {
override fun renderOverlay(context: DrawContext, stack: ItemStack) {
client.apply {
itemRenderer.renderGuiItemOverlay(matrices, textRenderer, stack, x + 1, y + 1, "")
context.drawItemInSlot(textRenderer, stack, x + 1, y + 1, "")
val factor = window.scaleFactor.toFloat()
val scale = (1 / factor) * ceil(factor / 2)
val countText = if (count <= 1) "" else count.toFormattedString()
matrices.wrap {
matrices.translate(0.0, 0.0, 250.0)
matrices.scale(scale, scale, 1f)
textRenderer.drawWithShadow(
matrices, countText, ((x + 17 - (textRenderer.getWidth(countText) * scale)) / scale),
((y + 17 - (textRenderer.fontHeight * scale)) / scale), 0xFFFFFF
context.matrices.wrap {
context.matrices.translate(0.0, 0.0, 250.0)
context.matrices.scale(scale, scale, 1f)
context.drawTextWithShadow(
textRenderer, countText, ((x + 17 - (textRenderer.getWidth(countText) * scale)) / scale).toInt(),
((y + 17 - (textRenderer.fontHeight * scale)) / scale).toInt(), 0xFFFFFF
)
}
}

View file

@ -1,10 +1,9 @@
package badasintended.slotlink.client.gui.widget
import badasintended.slotlink.client.util.GuiTextures
import badasintended.slotlink.client.util.bind
import net.fabricmc.api.EnvType
import net.fabricmc.api.Environment
import net.minecraft.client.util.math.MatrixStack
import net.minecraft.client.gui.DrawContext
@Environment(EnvType.CLIENT)
class ScrollBarWidget(x: Int, y: Int, h: Int) : NoSoundWidget(x, y, 14, h.coerceAtLeast(17)) {
@ -18,13 +17,12 @@ class ScrollBarWidget(x: Int, y: Int, h: Int) : NoSoundWidget(x, y, 14, h.coerce
private var knobY = 1
private var clicked = false
override fun renderButton(matrices: MatrixStack, mouseX: Int, mouseY: Int, delta: Float) {
override fun renderButton(context: DrawContext, mouseX: Int, mouseY: Int, delta: Float) {
if (!visible) return
GuiTextures.REQUEST.bind()
knobY = y + 1 + ((height - 17) * knob).toInt()
val u = 194 + if (hasKnob.invoke()) 0 else 12
drawTexture(matrices, x + 1, knobY, u, 0, 12, 15)
context.drawTexture(GuiTextures.REQUEST, x + 1, knobY, u, 0, 12, 15)
}
override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {

View file

@ -5,9 +5,9 @@ import badasintended.slotlink.client.util.wrap
import badasintended.slotlink.compat.recipe.RecipeViewer
import net.fabricmc.api.EnvType
import net.fabricmc.api.Environment
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder
import net.minecraft.client.item.TooltipContext
import net.minecraft.client.util.math.MatrixStack
import net.minecraft.item.ItemStack
import net.minecraft.screen.ScreenHandler
import net.minecraft.screen.ScreenTexts
@ -23,25 +23,29 @@ abstract class SlotWidget<SH : ScreenHandler>(
val stack get() = stackGetter.invoke()
private val stackX = x - 8 + width / 2
private var stackX = x - 8 + width / 2
private val stackY = y - 8 + height / 2
fun offsetX(offset: Int) {
stackX += offset
}
abstract fun onClick(button: Int)
protected open fun appendTooltip(tooltip: MutableList<Text>) {}
protected open fun renderOverlay(matrices: MatrixStack, stack: ItemStack) {
protected open fun renderOverlay(context: DrawContext, stack: ItemStack) {
client.apply {
itemRenderer.renderGuiItemOverlay(matrices, textRenderer, stack, stackX, stackY)
context.drawItemInSlot(textRenderer, stack, stackX, stackY)
}
}
override fun renderTooltip(matrices: MatrixStack, mouseX: Int, mouseY: Int) {
matrices.wrap {
matrices.translate(0.0, 0.0, +256.0)
override fun renderTooltip(context: DrawContext, mouseX: Int, mouseY: Int) {
context.matrices.wrap {
context.matrices.translate(0.0, 0.0, +256.0)
val x = stackX
val y = stackY
fill(matrices, x, y, x + 16, y + 16, -2130706433 /*0x80ffffff fuck*/)
context.fill(x, y, x + 16, y + 16, -2130706433 /*0x80ffffff fuck*/)
if (!stack.isEmpty && handler.cursorStack.isEmpty && RecipeViewer.instance?.isDraggingStack != true)
client.apply {
val tooltips = stack.getTooltip(
@ -49,15 +53,15 @@ abstract class SlotWidget<SH : ScreenHandler>(
TooltipContext.Default(options.advancedItemTooltips, player?.isCreative ?: false)
)
appendTooltip(tooltips)
currentScreen?.renderTooltip(matrices, tooltips, mouseX, mouseY)
context.drawTooltip(textRenderer, tooltips, mouseX, mouseY)
}
}
}
final override fun renderButton(matrices: MatrixStack, mouseX: Int, mouseY: Int, delta: Float) {
final override fun renderButton(context: DrawContext, mouseX: Int, mouseY: Int, delta: Float) {
if (!visible) return
client.itemRenderer.renderGuiItemIcon(matrices, stack, stackX, stackY)
renderOverlay(matrices, stack)
context.drawItem(stack, stackX, stackY)
renderOverlay(context, stack)
}
final override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {

View file

@ -4,8 +4,8 @@ import badasintended.slotlink.client.util.client
import badasintended.slotlink.util.focusedTicks
import net.fabricmc.api.EnvType
import net.fabricmc.api.Environment
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.gui.widget.TextFieldWidget
import net.minecraft.client.util.math.MatrixStack
import net.minecraft.text.Text
@Environment(EnvType.CLIENT)
@ -27,8 +27,8 @@ class TextFieldWidget(bgX: Int, bgY: Int, bgW: Int, bgH: Int, text: Text) :
setEditableColor(0xffffff)
}
override fun renderTooltip(matrices: MatrixStack, mouseX: Int, mouseY: Int) {
if (visible && !isActive) client.currentScreen?.renderTooltip(matrices, tooltip, mouseX, mouseY)
override fun renderTooltip(context: DrawContext, mouseX: Int, mouseY: Int) {
if (visible && !isActive) context.drawTooltip(client.textRenderer, tooltip, mouseX, mouseY)
}
override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {

View file

@ -1,7 +1,7 @@
package badasintended.slotlink.client.gui.widget
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.gui.widget.ClickableWidget
import net.minecraft.client.util.math.MatrixStack
inline fun <T> ClickableWidget.bounds(action: (Int, Int, Int, Int) -> T): T {
return action(x, y, width, height)
@ -21,6 +21,6 @@ interface CharGrabber {
interface TooltipRenderer {
fun renderTooltip(matrices: MatrixStack, mouseX: Int, mouseY: Int)
fun renderTooltip(context: DrawContext, mouseX: Int, mouseY: Int)
}

View file

@ -6,20 +6,19 @@ import badasintended.slotlink.item.MultiDimRemoteItem
import badasintended.slotlink.item.UnlimitedRemoteItem
import badasintended.slotlink.util.modId
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup
import net.minecraft.item.ItemGroup
import net.minecraft.item.ItemStack
import net.minecraft.registry.Registries
import net.minecraft.registry.Registries.ITEM
import net.minecraft.registry.Registry
import net.minecraft.registry.RegistryKey
import net.minecraft.registry.RegistryKeys
import net.minecraft.text.Text
@Suppress("MemberVisibilityCanBePrivate", "unused")
object Items : Initializer {
val GROUP = FabricItemGroup.builder(modId("group"))
.icon { ItemStack(Blocks.MASTER) }
.entries { _, entries ->
Blocks.BLOCKS.forEach { entries.add(ItemStack(it)) }
ITEMS.forEach { entries.add(ItemStack(it)) }
}
.build()!!
val GROUP: RegistryKey<ItemGroup> = RegistryKey.of(RegistryKeys.ITEM_GROUP, modId("group"))
val ITEMS = arrayListOf<ModItem>()
@ -29,6 +28,15 @@ object Items : Initializer {
override fun main() {
r(MULTI_DIM_REMOTE, UNLIMITED_REMOTE, LIMITED_REMOTE)
Registry.register(Registries.ITEM_GROUP, GROUP, FabricItemGroup.builder()
.displayName(Text.literal("Slotlink"))
.icon { ItemStack(Blocks.MASTER) }
.entries { _, entries ->
Blocks.BLOCKS.forEach { entries.add(ItemStack(it)) }
ITEMS.forEach { entries.add(ItemStack(it)) }
}
.build()!!)
}
private fun r(vararg items: ModItem) {

View file

@ -10,7 +10,8 @@ interface Node {
fun connect(adjacentNode: Node?): Boolean {
val other = adjacentNode ?: return false
val side = Direction.fromVector(connection.pos.subtract(other.connection.pos))!!
val vector = connection.pos.subtract(other.connection.pos)
val side = Direction.fromVector(vector.x, vector.y, vector.z)!!
connection.sides.add(side.opposite)
other.connection.sides.add(side)

View file

@ -32,6 +32,7 @@ import kotlin.collections.set
import kotlin.math.ceil
import kotlin.math.min
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant
import net.fabricmc.fabric.api.transfer.v1.storage.StorageUtil
import net.fabricmc.fabric.api.transfer.v1.storage.StorageView
import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction
import net.minecraft.entity.player.PlayerEntity
@ -190,7 +191,7 @@ open class RequestScreenHandler(
}
QUICK_MOVE -> Transaction.openOuter().use { transaction ->
val stock = storage.simulateExtract(variant, variant.item.maxCount.toLong(), transaction)
val stock = StorageUtil.simulateExtract(storage, variant, variant.item.maxCount.toLong(), transaction)
val inserted = player.storage.offer(variant, stock, transaction)
storage.extract(variant, inserted, transaction)
transaction.commit()
@ -263,7 +264,7 @@ open class RequestScreenHandler(
}
}
}
result.unlockLastRecipe(player)
result.unlockLastRecipe(player, null) // TODO is null okay here
result.setStack(0, ItemStack.EMPTY)
onContentChanged(input)
if (!quickMove || finished) break
@ -296,7 +297,7 @@ open class RequestScreenHandler(
if (it.inventory is PlayerInventory
&& it.index >= 9
&& it.canTakeItems(player)
&& (cursor.isEmpty || cursor.isItemEqual(it.stack))
&& (cursor.isEmpty || ItemStack.areItemsEqual(cursor, it.stack))
) {
it.stack = moveStackToNetwork(it.stack)
}

View file

@ -95,7 +95,7 @@ fun s2c(player: PlayerEntity, packet: Packet<*>) {
val ignoredTag: TagKey<Block> = TagKey.of(RegistryKeys.BLOCK, modId("ignored"))
fun ItemStack.isItemAndTagEqual(other: ItemStack): Boolean {
return ItemStack.areItemsEqual(this, other) && ItemStack.areNbtEqual(this, other)
return ItemStack.canCombine(this, other)
}
fun ItemStack.merge(from: ItemStack): Pair<ItemStack, ItemStack> {