Skip to content

Commit 4ab7641

Browse files
committed
feat: assembler foundation
1 parent 4c940ee commit 4ab7641

File tree

7 files changed

+106
-24
lines changed

7 files changed

+106
-24
lines changed

src/main/kotlin/com/sifsstudio/botjs/BotJS.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.sifsstudio.botjs
22

3-
import com.sifsstudio.botjs.attachment.Attachments
43
import com.sifsstudio.botjs.block.Blocks
54
import com.sifsstudio.botjs.blockentity.BlockEntities
65
import com.sifsstudio.botjs.entity.Entities
@@ -43,7 +42,6 @@ object BotJS {
4342
Entities.REGISTRY.register(MOD_BUS)
4443
BlockEntities.REGISTRY.register(MOD_BUS)
4544
MenuTypes.REGISTRY.register(MOD_BUS)
46-
Attachments.REGISTRY.register(MOD_BUS)
4745
FORGE_BUS.addListener(BotRuntime.Companion::onServerStarting)
4846
}
4947
}

src/main/kotlin/com/sifsstudio/botjs/attachment/Attachments.kt

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/main/kotlin/com/sifsstudio/botjs/blockentity/BotAssemblerEntity.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
package com.sifsstudio.botjs.blockentity
22

3+
import com.sifsstudio.botjs.inventory.BotAssemblerMenu
34
import com.sifsstudio.botjs.item.BotModuleItem
45
import com.sifsstudio.botjs.item.McuItem
56
import com.sifsstudio.botjs.item.StorageItem
67
import net.minecraft.core.BlockPos
78
import net.minecraft.core.HolderLookup
89
import net.minecraft.nbt.CompoundTag
10+
import net.minecraft.network.chat.Component
11+
import net.minecraft.world.MenuProvider
12+
import net.minecraft.world.entity.player.Inventory
13+
import net.minecraft.world.entity.player.Player
14+
import net.minecraft.world.inventory.AbstractContainerMenu
915
import net.minecraft.world.item.ItemStack
1016
import net.minecraft.world.level.block.entity.BlockEntity
1117
import net.minecraft.world.level.block.state.BlockState
1218
import net.neoforged.neoforge.items.ItemStackHandler
1319

1420
class BotAssemblerEntity(pPos: BlockPos, pBlockState: BlockState) :
15-
BlockEntity(BlockEntities.BOT_ASSEMBLER, pPos, pBlockState) {
21+
BlockEntity(BlockEntities.BOT_ASSEMBLER, pPos, pBlockState), MenuProvider {
1622
val mcu = object : ItemStackHandler(1) {
1723
override fun isItemValid(slot: Int, stack: ItemStack): Boolean {
1824
return stack.item is McuItem
@@ -42,4 +48,9 @@ class BotAssemblerEntity(pPos: BlockPos, pBlockState: BlockState) :
4248
storage.deserializeNBT(pRegistries, pTag.getCompound("storage"))
4349
components.deserializeNBT(pRegistries, pTag.getCompound("components"))
4450
}
51+
52+
override fun createMenu(pContainerId: Int, pPlayerInventory: Inventory, pPlayer: Player): AbstractContainerMenu =
53+
BotAssemblerMenu(pContainerId, pPlayerInventory, mcu, storage, components)
54+
55+
override fun getDisplayName(): Component = Component.translatable("menu.botjs.bot_assembler.title")
4556
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.sifsstudio.botjs.inventory
2+
3+
import net.minecraft.world.entity.player.Inventory
4+
import net.minecraft.world.entity.player.Player
5+
import net.minecraft.world.inventory.AbstractContainerMenu
6+
import net.minecraft.world.item.ItemStack
7+
import net.neoforged.neoforge.items.IItemHandler
8+
import net.neoforged.neoforge.items.ItemStackHandler
9+
10+
class BotAssemblerMenu(
11+
pContainerId: Int, pPlayerInventory: Inventory, mcu: IItemHandler, storage: IItemHandler, components: IItemHandler
12+
) : AbstractContainerMenu(MenuTypes.BOT_ASSEMBLER, pContainerId) {
13+
init {
14+
15+
}
16+
17+
constructor(pContainerId: Int, pPlayerInventory: Inventory): this(
18+
pContainerId, pPlayerInventory, ItemStackHandler(1), ItemStackHandler(1), ItemStackHandler(18)
19+
)
20+
21+
override fun quickMoveStack(pPlayer: Player, pIndex: Int): ItemStack {
22+
return ItemStack.EMPTY
23+
}
24+
25+
override fun stillValid(pPlayer: Player): Boolean = true
26+
}

src/main/kotlin/com/sifsstudio/botjs/inventory/MenuTypes.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ object MenuTypes {
2020
Supplier {
2121
IMenuTypeExtension.create(::FirmwareProgrammerMenu)
2222
})
23+
val BOT_ASSEMBLER: MenuType<BotAssemblerMenu> by REGISTRY.register("bot_assembler_menu", Supplier {
24+
MenuType(::BotAssemblerMenu, FeatureFlagSet.of())
25+
})
2326
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.sifsstudio.botjs.runtime
2+
3+
import org.mozilla.javascript.Scriptable
4+
5+
class StorageComponent(private val storage: IntArray): Scriptable {
6+
private var prototype: Scriptable? = null
7+
private var parent: Scriptable? = null
8+
9+
override fun getClassName() = "Storage"
10+
11+
override fun get(name: String, start: Scriptable?): Any {
12+
TODO("Not yet implemented")
13+
}
14+
15+
override fun get(index: Int, start: Scriptable?): Any {
16+
TODO("Not yet implemented")
17+
}
18+
19+
override fun has(name: String?, start: Scriptable?): Boolean {
20+
TODO("Not yet implemented")
21+
}
22+
23+
override fun has(index: Int, start: Scriptable?): Boolean {
24+
TODO("Not yet implemented")
25+
}
26+
27+
override fun put(name: String?, start: Scriptable?, value: Any?) {
28+
TODO("Not yet implemented")
29+
}
30+
31+
override fun put(index: Int, start: Scriptable?, value: Any?) {
32+
33+
}
34+
35+
override fun delete(name: String?) = Unit
36+
37+
override fun delete(index: Int) = Unit
38+
39+
override fun getPrototype(): Scriptable? = prototype
40+
41+
override fun setPrototype(prototype: Scriptable?) {
42+
this.prototype = prototype
43+
}
44+
45+
override fun getParentScope(): Scriptable? = parent
46+
47+
override fun setParentScope(parent: Scriptable?) {
48+
this.parent = parent
49+
}
50+
51+
override fun getIds(): Array<Any> = Array(0) {}
52+
53+
override fun getDefaultValue(hint: Class<*>?): Any = "[object Storage]"
54+
55+
override fun hasInstance(instance: Scriptable): Boolean {
56+
var proto = instance.prototype
57+
while (proto != null) {
58+
if (proto.equals(this)) {
59+
return true
60+
}
61+
proto = proto.prototype
62+
}
63+
return false
64+
}
65+
}

src/main/kotlin/com/sifsstudio/botjs/runtime/module/BotModule.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.sifsstudio.botjs.runtime.module
22

33
import com.sifsstudio.botjs.entity.BotEntity
4-
import org.mozilla.javascript.annotations.JSFunction
54

65
class Register(private val resetValue: Int, private val rwFlag: RWFlag) {
76
companion object {
@@ -16,15 +15,13 @@ class Register(private val resetValue: Int, private val rwFlag: RWFlag) {
1615
ReadWrite,
1716
}
1817

19-
@JSFunction
2018
fun write(data: Int) {
2119
when (rwFlag) {
2220
RWFlag.ReadWrite, RWFlag.WriteOnly -> content = data
2321
else -> Unit
2422
}
2523
}
2624

27-
@JSFunction
2825
fun read() =
2926
when (rwFlag) {
3027
RWFlag.ReadOnly, RWFlag.ReadWrite -> content

0 commit comments

Comments
 (0)