Skip to content

Commit 112569f

Browse files
authored
Reformat codebase (#13)
* format code * revert undesired formatting
1 parent b2ef014 commit 112569f

File tree

88 files changed

+2243
-2160
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+2243
-2160
lines changed

src/main/kotlin/elan/tweaks/common/container/SpecializedContainer.kt

Lines changed: 112 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -15,129 +15,133 @@ constructor(
1515
private val specializedSlotIndexRange: IntRange,
1616
) : Container() {
1717

18-
override fun enchantItem(player: EntityPlayer, id: Int): Boolean = onEnchantItem(player, id)
19-
override fun canInteractWith(player: EntityPlayer): Boolean = onCanInteractWith(player)
18+
override fun enchantItem(player: EntityPlayer, id: Int): Boolean = onEnchantItem(player, id)
19+
override fun canInteractWith(player: EntityPlayer): Boolean = onCanInteractWith(player)
2020

21-
public override fun addSlotToContainer(slot: Slot) = super.addSlotToContainer(slot)!!
21+
public override fun addSlotToContainer(slot: Slot) = super.addSlotToContainer(slot)!!
2222

23-
/** Avoiding stack overflow crash on shift-click. */
24-
override fun transferStackInSlot(player: EntityPlayer, slotIndex: Int): ItemStack? {
25-
val slot: Slot = inventorySlots[slotIndex] as Slot
26-
if (slot.hasStack) {
27-
val stack = slot.stack
28-
val stackCopy = stack.copy()
29-
if (slotIndex in specializedSlotIndexRange) {
30-
if (!transferFromSpecializedSlot(stack)) {
31-
return null
23+
/** Avoiding stack overflow crash on shift-click. */
24+
override fun transferStackInSlot(player: EntityPlayer, slotIndex: Int): ItemStack? {
25+
val slot: Slot = inventorySlots[slotIndex] as Slot
26+
if (slot.hasStack) {
27+
val stack = slot.stack
28+
val stackCopy = stack.copy()
29+
if (slotIndex in specializedSlotIndexRange) {
30+
if (!transferFromSpecializedSlot(stack)) {
31+
return null
32+
}
33+
} else if (!transferToSpecializedSlot(stack)) {
34+
return null
35+
}
36+
if (stack.stackSize == 0) {
37+
slot.putStack(null)
38+
} else {
39+
slot.onSlotChanged()
40+
}
41+
return stackCopy
3242
}
33-
} else if (!transferToSpecializedSlot(stack)) {
3443
return null
35-
}
36-
if (stack.stackSize == 0) {
37-
slot.putStack(null)
38-
} else {
39-
slot.onSlotChanged()
40-
}
41-
return stackCopy
4244
}
43-
return null
44-
}
4545

46-
private fun transferFromSpecializedSlot(stack: ItemStack) =
47-
mergeItemStack(stack, specializedSlotIndexRange.count(), inventorySlots.size, true)
46+
private fun transferFromSpecializedSlot(stack: ItemStack) =
47+
mergeItemStack(stack, specializedSlotIndexRange.count(), inventorySlots.size, true)
4848

49-
private fun transferToSpecializedSlot(stack: ItemStack) =
50-
mergeItemStack(
51-
stack, specializedSlotIndexRange.first, specializedSlotIndexRange.count(), false)
49+
private fun transferToSpecializedSlot(stack: ItemStack) =
50+
mergeItemStack(
51+
stack, specializedSlotIndexRange.first, specializedSlotIndexRange.count(), false
52+
)
5253

53-
/** Copy-paste from original Container with addition of isItemValid check */
54-
override fun mergeItemStack(
55-
sourceStack: ItemStack,
56-
startIndex: Int,
57-
endIndex: Int,
58-
reverseDirection: Boolean
59-
): Boolean {
60-
var mergeSuccess = false
61-
var begining = startIndex
62-
if (reverseDirection) {
63-
begining = endIndex - 1
64-
}
65-
if (sourceStack.isStackable) {
66-
while (sourceStack.stackSize > 0 &&
67-
(!reverseDirection && begining < endIndex ||
68-
reverseDirection && begining >= startIndex)) {
69-
val targetSlot: Slot = inventorySlots[begining] as Slot
70-
val targetStack = targetSlot.stack
71-
if (targetStack != null &&
72-
targetSlot.isItemValid(sourceStack) &&
73-
targetStack.item === sourceStack.item &&
74-
(!sourceStack.hasSubtypes || sourceStack.itemDamage == targetStack.itemDamage) &&
75-
ItemStack.areItemStackTagsEqual(sourceStack, targetStack)) {
76-
val targetStackSize = targetStack.stackSize + sourceStack.stackSize
77-
if (targetStackSize <= sourceStack.maxStackSize) {
78-
sourceStack.stackSize = 0
79-
targetStack.stackSize = targetStackSize
80-
targetSlot.onSlotChanged()
81-
mergeSuccess = true
82-
} else if (targetStack.stackSize < sourceStack.maxStackSize) {
83-
sourceStack.stackSize -= sourceStack.maxStackSize - targetStack.stackSize
84-
targetStack.stackSize = sourceStack.maxStackSize
85-
targetSlot.onSlotChanged()
86-
mergeSuccess = true
87-
}
88-
}
54+
/** Copy-paste from original Container with addition of isItemValid check */
55+
override fun mergeItemStack(
56+
sourceStack: ItemStack,
57+
startIndex: Int,
58+
endIndex: Int,
59+
reverseDirection: Boolean
60+
): Boolean {
61+
var mergeSuccess = false
62+
var begining = startIndex
8963
if (reverseDirection) {
90-
--begining
91-
} else {
92-
++begining
64+
begining = endIndex - 1
9365
}
94-
}
95-
}
96-
if (sourceStack.stackSize > 0) {
97-
begining =
98-
if (reverseDirection) {
99-
endIndex - 1
100-
} else {
101-
startIndex
102-
}
103-
while (!reverseDirection && begining < endIndex ||
104-
reverseDirection && begining >= startIndex) {
105-
val targetSlot: Slot = inventorySlots[begining] as Slot
106-
val targetStack = targetSlot.stack
107-
if (targetStack == null && targetSlot.isItemValid(sourceStack)) {
108-
targetSlot.putStack(sourceStack.copy())
109-
targetSlot.onSlotChanged()
110-
sourceStack.stackSize = 0
111-
mergeSuccess = true
112-
break
66+
if (sourceStack.isStackable) {
67+
while (sourceStack.stackSize > 0 &&
68+
(!reverseDirection && begining < endIndex ||
69+
reverseDirection && begining >= startIndex)
70+
) {
71+
val targetSlot: Slot = inventorySlots[begining] as Slot
72+
val targetStack = targetSlot.stack
73+
if (targetStack != null &&
74+
targetSlot.isItemValid(sourceStack) &&
75+
targetStack.item === sourceStack.item &&
76+
(!sourceStack.hasSubtypes || sourceStack.itemDamage == targetStack.itemDamage) &&
77+
ItemStack.areItemStackTagsEqual(sourceStack, targetStack)
78+
) {
79+
val targetStackSize = targetStack.stackSize + sourceStack.stackSize
80+
if (targetStackSize <= sourceStack.maxStackSize) {
81+
sourceStack.stackSize = 0
82+
targetStack.stackSize = targetStackSize
83+
targetSlot.onSlotChanged()
84+
mergeSuccess = true
85+
} else if (targetStack.stackSize < sourceStack.maxStackSize) {
86+
sourceStack.stackSize -= sourceStack.maxStackSize - targetStack.stackSize
87+
targetStack.stackSize = sourceStack.maxStackSize
88+
targetSlot.onSlotChanged()
89+
mergeSuccess = true
90+
}
91+
}
92+
if (reverseDirection) {
93+
--begining
94+
} else {
95+
++begining
96+
}
97+
}
11398
}
114-
if (reverseDirection) {
115-
--begining
116-
} else {
117-
++begining
99+
if (sourceStack.stackSize > 0) {
100+
begining =
101+
if (reverseDirection) {
102+
endIndex - 1
103+
} else {
104+
startIndex
105+
}
106+
while (!reverseDirection && begining < endIndex ||
107+
reverseDirection && begining >= startIndex
108+
) {
109+
val targetSlot: Slot = inventorySlots[begining] as Slot
110+
val targetStack = targetSlot.stack
111+
if (targetStack == null && targetSlot.isItemValid(sourceStack)) {
112+
targetSlot.putStack(sourceStack.copy())
113+
targetSlot.onSlotChanged()
114+
sourceStack.stackSize = 0
115+
mergeSuccess = true
116+
break
117+
}
118+
if (reverseDirection) {
119+
--begining
120+
} else {
121+
++begining
122+
}
123+
}
118124
}
119-
}
125+
return mergeSuccess
120126
}
121-
return mergeSuccess
122-
}
123127

124-
class SpecializedSlot(
125-
private val targetClass: Class<*>,
126-
inventory: IInventory,
127-
slotIndex: Int,
128-
displayPosition: Vector2D
129-
) : Slot(inventory, slotIndex, displayPosition.x, displayPosition.y) {
128+
class SpecializedSlot(
129+
private val targetClass: Class<*>,
130+
inventory: IInventory,
131+
slotIndex: Int,
132+
displayPosition: Vector2D
133+
) : Slot(inventory, slotIndex, displayPosition.x, displayPosition.y) {
130134

131-
override fun isItemValid(stack: ItemStack): Boolean {
132-
return stack.item != null && targetClass.isAssignableFrom(stack.item.javaClass)
133-
}
135+
override fun isItemValid(stack: ItemStack): Boolean {
136+
return stack.item != null && targetClass.isAssignableFrom(stack.item.javaClass)
137+
}
134138

135-
companion object {
136-
inline fun <reified TargetClassT> specializedOn(
137-
inventory: IInventory,
138-
slotIndex: Int,
139-
displayPosition: Vector2D
140-
) = SpecializedSlot(TargetClassT::class.java, inventory, slotIndex, displayPosition)
139+
companion object {
140+
inline fun <reified TargetClassT> specializedOn(
141+
inventory: IInventory,
142+
slotIndex: Int,
143+
displayPosition: Vector2D
144+
) = SpecializedSlot(TargetClassT::class.java, inventory, slotIndex, displayPosition)
145+
}
141146
}
142-
}
143147
}

src/main/kotlin/elan/tweaks/common/ext/Hex.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@ package elan.tweaks.common.ext
22

33
import elan.tweaks.common.gui.dto.Vector2D
44
import elan.tweaks.common.gui.dto.VectorXY
5+
import thaumcraft.common.lib.utils.HexUtils
56
import kotlin.math.roundToInt
67
import kotlin.math.sqrt
7-
import thaumcraft.common.lib.utils.HexUtils
88

99
object HexMath {
10-
fun toCenterVector(hex: HexUtils.Hex, hexSize: Int) = toCenterVector(hex.q, hex.r, hexSize)
10+
fun toCenterVector(hex: HexUtils.Hex, hexSize: Int) = toCenterVector(hex.q, hex.r, hexSize)
1111

12-
fun toCenterVector(q: Int, r: Int, hexSize: Int): VectorXY =
13-
Vector2D(
14-
x = (hexSize * (1.5 * q)).roundToInt(),
15-
y = (hexSize * sqrt(3.0) * (r + q / 2.0)).roundToInt())
12+
fun toCenterVector(q: Int, r: Int, hexSize: Int): VectorXY =
13+
Vector2D(
14+
x = (hexSize * (1.5 * q)).roundToInt(),
15+
y = (hexSize * sqrt(3.0) * (r + q / 2.0)).roundToInt()
16+
)
1617

17-
fun toOrigin(q: Int, r: Int, hexSize: Int): VectorXY =
18-
toOrigin(toCenterVector(q, r, hexSize), hexSize)
18+
fun toOrigin(q: Int, r: Int, hexSize: Int): VectorXY =
19+
toOrigin(toCenterVector(q, r, hexSize), hexSize)
1920

20-
fun toOrigin(centerVector: VectorXY, hexSize: Int): VectorXY = centerVector - hexSize + 1
21+
fun toOrigin(centerVector: VectorXY, hexSize: Int): VectorXY = centerVector - hexSize + 1
2122
}

src/main/kotlin/elan/tweaks/common/ext/HexUtilsHexExt.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ package elan.tweaks.common.ext
33
import thaumcraft.common.lib.utils.HexUtils
44

55
val HexUtils.Hex.key
6-
get() = toString()
6+
get() = toString()
77
val HexUtils.Hex.allNeighbors
8-
get() = (0..5).map(::getNeighbour)
8+
get() = (0..5).map(::getNeighbour)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package elan.tweaks.common.ext
22

33
object ResultExt {
4-
private val success = Result.success(Unit)
4+
private val success = Result.success(Unit)
55

6-
fun success() = success
6+
fun success() = success
77
}

src/main/kotlin/elan/tweaks/common/ext/TesselatorExt.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ package elan.tweaks.common.ext
33
import net.minecraft.client.renderer.Tessellator
44

55
fun Tessellator.drawQuads(configureTesselation: Tessellator.() -> Unit) {
6-
startDrawingQuads()
7-
configureTesselation()
8-
draw()
6+
startDrawingQuads()
7+
configureTesselation()
8+
draw()
99
}
1010

1111
fun Tessellator.draw(drawMode: Int, configureTesselation: Tessellator.() -> Unit) {
12-
startDrawing(drawMode)
13-
configureTesselation()
14-
draw()
12+
startDrawing(drawMode)
13+
configureTesselation()
14+
draw()
1515
}

0 commit comments

Comments
 (0)