mirror of
https://github.com/naalit/slotlink.git
synced 2025-12-31 04:13:02 +00:00
reformat
This commit is contained in:
parent
d6bd601614
commit
e417a6e4cc
17 changed files with 730 additions and 615 deletions
1194
.editorconfig
1194
.editorconfig
File diff suppressed because it is too large
Load diff
|
|
@ -5,7 +5,6 @@ import java.util.HashMap;
|
|||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.block.Block;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
package badasintended.slotlink.block
|
||||
|
||||
import java.util.function.IntFunction
|
||||
import badasintended.slotlink.block.entity.CableBlockEntity
|
||||
import badasintended.slotlink.util.bbCuboid
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
|
||||
import java.util.function.IntFunction
|
||||
import net.fabricmc.fabric.api.`object`.builder.v1.block.FabricBlockSettings
|
||||
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags
|
||||
import net.minecraft.block.Block
|
||||
|
|
|
|||
|
|
@ -19,7 +19,14 @@ abstract class ChildBlock(id: String, private val blockEntity: () -> BlockEntity
|
|||
ModBlock(id, settings), BlockEntityProvider {
|
||||
|
||||
// TODO: Optimize this part
|
||||
override fun neighborUpdate(state: BlockState, world: World, pos: BlockPos, block: Block, neighborPos: BlockPos, moved: Boolean) {
|
||||
override fun neighborUpdate(
|
||||
state: BlockState,
|
||||
world: World,
|
||||
pos: BlockPos,
|
||||
block: Block,
|
||||
neighborPos: BlockPos,
|
||||
moved: Boolean
|
||||
) {
|
||||
val blockEntity = world.getBlockEntity(pos) as ChildBlockEntity
|
||||
val neighborBlock = world.getBlockState(neighborPos).block
|
||||
val neighborBlockEntity = world.getBlockEntity(neighborPos)
|
||||
|
|
@ -64,7 +71,12 @@ abstract class ChildBlock(id: String, private val blockEntity: () -> BlockEntity
|
|||
|
||||
override fun createBlockEntity(world: BlockView) = blockEntity.invoke()
|
||||
|
||||
override fun appendTooltip(stack: ItemStack, world: BlockView?, tooltip: MutableList<Text>, options: TooltipContext) {
|
||||
override fun appendTooltip(
|
||||
stack: ItemStack,
|
||||
world: BlockView?,
|
||||
tooltip: MutableList<Text>,
|
||||
options: TooltipContext
|
||||
) {
|
||||
super.appendTooltip(stack, world, tooltip, options)
|
||||
tooltip.add(TranslatableText("block.slotlink.child.tooltip").formatted(Formatting.GRAY))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,13 @@ abstract class ConnectorCableBlock(id: String, be: () -> BlockEntity) : CableBlo
|
|||
/**
|
||||
* TODO: Optimize, maybe.
|
||||
*/
|
||||
private fun checkLink(world: WorldAccess, pos: BlockPos, facing: Direction, state: BlockState, neighborPos: BlockPos): BlockState {
|
||||
private fun checkLink(
|
||||
world: WorldAccess,
|
||||
pos: BlockPos,
|
||||
facing: Direction,
|
||||
state: BlockState,
|
||||
neighborPos: BlockPos
|
||||
): BlockState {
|
||||
val neighbor = world.getBlockState(neighborPos).block
|
||||
if (!neighbor.isIgnored()) {
|
||||
if ((world.getBlockEntity(neighborPos) is Inventory) or (neighbor is InventoryProvider)) {
|
||||
|
|
@ -101,12 +107,24 @@ abstract class ConnectorCableBlock(id: String, be: () -> BlockEntity) : CableBlo
|
|||
return updatedState
|
||||
}
|
||||
|
||||
override fun appendTooltip(stack: ItemStack, world: BlockView?, tooltip: MutableList<Text>, options: TooltipContext) {
|
||||
override fun appendTooltip(
|
||||
stack: ItemStack,
|
||||
world: BlockView?,
|
||||
tooltip: MutableList<Text>,
|
||||
options: TooltipContext
|
||||
) {
|
||||
super.appendTooltip(stack, world, tooltip, options)
|
||||
tooltip.add(TranslatableText("block.slotlink.cable.tooltipFilter").formatted(Formatting.GRAY))
|
||||
}
|
||||
|
||||
override fun onUse(state: BlockState, world: World, pos: BlockPos, player: PlayerEntity, hand: Hand, hit: BlockHitResult): ActionResult {
|
||||
override fun onUse(
|
||||
state: BlockState,
|
||||
world: World,
|
||||
pos: BlockPos,
|
||||
player: PlayerEntity,
|
||||
hand: Hand,
|
||||
hit: BlockHitResult
|
||||
): ActionResult {
|
||||
if (player.mainHandStack.isEmpty) {
|
||||
player.openHandledScreen(state.createScreenHandlerFactory(world, pos))
|
||||
return ActionResult.SUCCESS
|
||||
|
|
@ -114,7 +132,11 @@ abstract class ConnectorCableBlock(id: String, be: () -> BlockEntity) : CableBlo
|
|||
return ActionResult.PASS
|
||||
}
|
||||
|
||||
override fun createScreenHandlerFactory(state: BlockState, world: World, pos: BlockPos): NamedScreenHandlerFactory? {
|
||||
override fun createScreenHandlerFactory(
|
||||
state: BlockState,
|
||||
world: World,
|
||||
pos: BlockPos
|
||||
): NamedScreenHandlerFactory? {
|
||||
val blockEntity = world.getBlockEntity(pos) ?: return null
|
||||
if (blockEntity !is ConnectorCableBlockEntity) return null
|
||||
return blockEntity
|
||||
|
|
|
|||
|
|
@ -35,7 +35,14 @@ class MasterBlock : ModBlock("master"), BlockEntityProvider {
|
|||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
override fun neighborUpdate(state: BlockState, world: World, pos: BlockPos, block: Block, neighborPos: BlockPos, moved: Boolean) {
|
||||
override fun neighborUpdate(
|
||||
state: BlockState,
|
||||
world: World,
|
||||
pos: BlockPos,
|
||||
block: Block,
|
||||
neighborPos: BlockPos,
|
||||
moved: Boolean
|
||||
) {
|
||||
super.neighborUpdate(state, world, pos, block, neighborPos, moved)
|
||||
|
||||
val neighborState = world.getBlockState(neighborPos)
|
||||
|
|
@ -56,7 +63,14 @@ class MasterBlock : ModBlock("master"), BlockEntityProvider {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onUse(state: BlockState, world: World, pos: BlockPos, player: PlayerEntity, hand: Hand, hit: BlockHitResult): ActionResult {
|
||||
override fun onUse(
|
||||
state: BlockState,
|
||||
world: World,
|
||||
pos: BlockPos,
|
||||
player: PlayerEntity,
|
||||
hand: Hand,
|
||||
hit: BlockHitResult
|
||||
): ActionResult {
|
||||
if (!world.isClient) {
|
||||
val blockEntity = world.getBlockEntity(pos)!! as MasterBlockEntity
|
||||
val inventories = blockEntity.getInventories(world, true)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,14 @@ import net.minecraft.world.World
|
|||
|
||||
class RequestBlock : ChildBlock("request", ::RequestBlockEntity) {
|
||||
|
||||
override fun onUse(state: BlockState, world: World, pos: BlockPos, player: PlayerEntity, hand: Hand, hit: BlockHitResult): ActionResult {
|
||||
override fun onUse(
|
||||
state: BlockState,
|
||||
world: World,
|
||||
pos: BlockPos,
|
||||
player: PlayerEntity,
|
||||
hand: Hand,
|
||||
hit: BlockHitResult
|
||||
): ActionResult {
|
||||
val blockEntity = world.getBlockEntity(pos) as RequestBlockEntity
|
||||
if (!blockEntity.hasMaster) {
|
||||
player.actionBar("${translationKey}.hasNoMaster")
|
||||
|
|
@ -23,7 +30,11 @@ class RequestBlock : ChildBlock("request", ::RequestBlockEntity) {
|
|||
return ActionResult.SUCCESS
|
||||
}
|
||||
|
||||
override fun createScreenHandlerFactory(state: BlockState, world: World, pos: BlockPos): NamedScreenHandlerFactory? {
|
||||
override fun createScreenHandlerFactory(
|
||||
state: BlockState,
|
||||
world: World,
|
||||
pos: BlockPos
|
||||
): NamedScreenHandlerFactory? {
|
||||
val blockEntity = world.getBlockEntity(pos) ?: return null
|
||||
if (blockEntity !is RequestBlockEntity) return null
|
||||
return blockEntity
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package badasintended.slotlink.block.entity
|
||||
|
||||
import java.util.SortedSet
|
||||
import badasintended.slotlink.init.BlockEntityTypes
|
||||
import badasintended.slotlink.inventory.FilteredInventory
|
||||
import badasintended.slotlink.util.BlockPosSet
|
||||
|
|
@ -9,6 +8,7 @@ import badasintended.slotlink.util.fromTag
|
|||
import badasintended.slotlink.util.toTag
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList
|
||||
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet
|
||||
import java.util.SortedSet
|
||||
import net.fabricmc.fabric.api.util.NbtType
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.nbt.CompoundTag
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@ import net.minecraft.text.Text
|
|||
import net.minecraft.text.TranslatableText
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
abstract class ModScreen<H : ScreenHandler>(h: H, inventory: PlayerInventory, title: Text) : HandledScreen<H>(h, inventory, title) {
|
||||
abstract class ModScreen<H : ScreenHandler>(h: H, inventory: PlayerInventory, title: Text) :
|
||||
HandledScreen<H>(h, inventory, title) {
|
||||
|
||||
abstract val baseTlKey: String
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,8 @@ import org.lwjgl.glfw.GLFW
|
|||
var reiSearchHandler: ((String) -> Unit)? = null
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
class RequestScreen<H : RequestScreenHandler>(handler: H, inv: PlayerInventory, title: Text) : ModScreen<H>(handler, inv, title) {
|
||||
class RequestScreen<H : RequestScreenHandler>(handler: H, inv: PlayerInventory, title: Text) :
|
||||
ModScreen<H>(handler, inv, title) {
|
||||
|
||||
private val syncId get() = handler.syncId
|
||||
private val viewedHeight get() = handler.viewedHeight
|
||||
|
|
|
|||
|
|
@ -28,7 +28,13 @@ class FilterSlotWidget(
|
|||
matrices.translate(0.0, 0.0, itemRenderer.zOffset + 200.0)
|
||||
fill(matrices, x + 1, y + 1, x + 17, y + 17, if (nbt) 0x70aa27ba else 0x408b8b8b)
|
||||
if (nbt) {
|
||||
textRenderer.drawWithShadow(matrices, "+", x + 17f - textRenderer.getWidth("+"), y + 17f - textRenderer.fontHeight, 0xaa27ba)
|
||||
textRenderer.drawWithShadow(
|
||||
matrices,
|
||||
"+",
|
||||
x + 17f - textRenderer.getWidth("+"),
|
||||
y + 17f - textRenderer.fontHeight,
|
||||
0xaa27ba
|
||||
)
|
||||
}
|
||||
matrices.pop()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import badasintended.slotlink.client.util.client
|
|||
import badasintended.slotlink.init.Packets
|
||||
import badasintended.slotlink.screen.RequestScreenHandler
|
||||
import badasintended.slotlink.util.toFormattedString
|
||||
import kotlin.math.ceil
|
||||
import net.fabricmc.api.EnvType
|
||||
import net.fabricmc.api.Environment
|
||||
import net.minecraft.client.gui.screen.Screen
|
||||
|
|
@ -14,7 +15,6 @@ import net.minecraft.text.LiteralText
|
|||
import net.minecraft.text.MutableText
|
||||
import net.minecraft.text.Text
|
||||
import net.minecraft.util.Formatting
|
||||
import kotlin.math.ceil
|
||||
|
||||
/**
|
||||
* [MultiSlotWidget] is an impostor.
|
||||
|
|
|
|||
|
|
@ -34,7 +34,18 @@ fun drawNinePatch(matrices: MatrixStack, x: Int, y: Int, w: Int, h: Int, u: Floa
|
|||
drawNinePatch(matrices, x, y, w, h, u, v, ltrb, cm, ltrb)
|
||||
}
|
||||
|
||||
fun drawNinePatch(matrices: MatrixStack, x: Int, y: Int, w: Int, h: Int, u: Float, v: Float, lt: Int, cm: Int, rb: Int) {
|
||||
fun drawNinePatch(
|
||||
matrices: MatrixStack,
|
||||
x: Int,
|
||||
y: Int,
|
||||
w: Int,
|
||||
h: Int,
|
||||
u: Float,
|
||||
v: Float,
|
||||
lt: Int,
|
||||
cm: Int,
|
||||
rb: Int
|
||||
) {
|
||||
drawNinePatch(matrices, x, y, w, h, u, v, lt, cm, rb, lt, cm, rb)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,10 @@ object Screens : Initializer {
|
|||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private fun <H : ScreenHandler, S : HandledScreen<H>> s(type: ScreenHandlerType<H>, function: (H, PlayerInventory, Text) -> S) {
|
||||
private fun <H : ScreenHandler, S : HandledScreen<H>> s(
|
||||
type: ScreenHandlerType<H>,
|
||||
function: (H, PlayerInventory, Text) -> S
|
||||
) {
|
||||
ScreenRegistry.register(type, ScreenRegistry.Factory(function))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -93,7 +93,8 @@ class FilteredInventory(
|
|||
|
||||
override fun getStack(slot: Int): ItemStack = inventory?.getStack(slot) ?: ItemStack.EMPTY
|
||||
|
||||
override fun removeStack(slot: Int, amount: Int): ItemStack = inventory?.removeStack(slot, amount) ?: ItemStack.EMPTY
|
||||
override fun removeStack(slot: Int, amount: Int): ItemStack =
|
||||
inventory?.removeStack(slot, amount) ?: ItemStack.EMPTY
|
||||
|
||||
override fun removeStack(slot: Int): ItemStack = inventory?.removeStack(slot) ?: ItemStack.EMPTY
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,19 @@ import badasintended.slotlink.inventory.FilteredInventory
|
|||
import badasintended.slotlink.mixin.CraftingScreenHandlerAccessor
|
||||
import badasintended.slotlink.mixin.SlotAccessor
|
||||
import badasintended.slotlink.screen.slot.DisabledSlot
|
||||
import badasintended.slotlink.util.*
|
||||
import badasintended.slotlink.util.BlockEntityWatcher
|
||||
import badasintended.slotlink.util.MasterWatcher
|
||||
import badasintended.slotlink.util.Sort
|
||||
import badasintended.slotlink.util.actionBar
|
||||
import badasintended.slotlink.util.allEmpty
|
||||
import badasintended.slotlink.util.isItemAndTagEqual
|
||||
import badasintended.slotlink.util.merge
|
||||
import badasintended.slotlink.util.s2c
|
||||
import badasintended.slotlink.util.stack
|
||||
import java.util.Optional
|
||||
import kotlin.collections.set
|
||||
import kotlin.math.ceil
|
||||
import kotlin.math.min
|
||||
import net.minecraft.entity.player.PlayerEntity
|
||||
import net.minecraft.entity.player.PlayerInventory
|
||||
import net.minecraft.inventory.CraftingInventory
|
||||
|
|
@ -20,7 +32,11 @@ import net.minecraft.inventory.Inventory
|
|||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.network.packet.s2c.play.CloseScreenS2CPacket
|
||||
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket
|
||||
import net.minecraft.recipe.*
|
||||
import net.minecraft.recipe.CraftingRecipe
|
||||
import net.minecraft.recipe.Ingredient
|
||||
import net.minecraft.recipe.Recipe
|
||||
import net.minecraft.recipe.RecipeGridAligner
|
||||
import net.minecraft.recipe.RecipeType
|
||||
import net.minecraft.screen.CraftingScreenHandler
|
||||
import net.minecraft.screen.ScreenHandler
|
||||
import net.minecraft.screen.ScreenHandlerListener
|
||||
|
|
@ -31,10 +47,6 @@ import net.minecraft.screen.slot.SlotActionType
|
|||
import net.minecraft.server.network.ServerPlayerEntity
|
||||
import net.minecraft.util.collection.DefaultedList
|
||||
import net.minecraft.util.registry.Registry
|
||||
import java.util.*
|
||||
import kotlin.collections.set
|
||||
import kotlin.math.ceil
|
||||
import kotlin.math.min
|
||||
|
||||
@Suppress("LeakingThis")
|
||||
open class RequestScreenHandler(
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ package badasintended.slotlink.util
|
|||
import badasintended.slotlink.Slotlink
|
||||
import io.netty.buffer.Unpooled
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet
|
||||
import kotlin.math.ln
|
||||
import kotlin.math.min
|
||||
import kotlin.math.pow
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking
|
||||
import net.fabricmc.fabric.api.tag.TagRegistry
|
||||
import net.fabricmc.loader.api.FabricLoader
|
||||
|
|
@ -24,9 +27,6 @@ import net.minecraft.util.shape.VoxelShape
|
|||
import net.minecraft.util.shape.VoxelShapes
|
||||
import org.apache.logging.log4j.LogManager
|
||||
import org.apache.logging.log4j.Logger
|
||||
import kotlin.math.ln
|
||||
import kotlin.math.min
|
||||
import kotlin.math.pow
|
||||
|
||||
fun BlockPos.toTag(): CompoundTag {
|
||||
val tag = CompoundTag()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue