Skip to content
This repository was archived by the owner on Jun 1, 2021. It is now read-only.
Draft
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ kotlin.code.style=official
loom_version=0.5-SNAPSHOT
# Kotlin
kotlin_version=1.4.0
fabric_kotlin_version=1.4.0+build.1
fabric_kotlin_version=1.4.21+build.1
20 changes: 15 additions & 5 deletions src/main/kotlin/li/cli/oc/Components.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ package li.cli.oc

import java.util.function.Supplier
import li.cli.oc.blocks.*
import li.cli.oc.client.gui.blocks.CaseScreen
import li.cli.oc.client.gui.blocks.CaseScreenHandler
import li.cli.oc.items.Analyzer
import li.cli.oc.items.commons.ComponentBlockItem
import li.cli.oc.items.commons.ComponentItem
import net.fabricmc.fabric.api.`object`.builder.v1.block.FabricBlockSettings
import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry
import net.minecraft.block.Block
import net.minecraft.block.Material
import net.minecraft.block.entity.BlockEntity
import net.minecraft.block.entity.BlockEntityType
import net.minecraft.item.Item
import net.minecraft.screen.ScreenHandlerType
import net.minecraft.util.Identifier
import net.minecraft.util.registry.Registry

Expand All @@ -33,10 +39,10 @@ object Components {
Cable("cable", Cable()),
Capacitor("capacitor", Capacitor()),
CarpatedCapacitor("carpetedcapacitor", CarpetedCapacitor()),
CaseOne("case1", Case(1)),
CaseTwo("case2", Case(2)),
CaseThree("case3", Case(3)),
CaseCreative("casecreative", Case(4)),
CaseOne("case1", Case(1, FabricBlockSettings.of(Material.METAL).nonOpaque())),
CaseTwo("case2", Case(2, FabricBlockSettings.of(Material.METAL).nonOpaque())),
CaseThree("case3", Case(3, FabricBlockSettings.of(Material.METAL).nonOpaque())),
CaseCreative("casecreative", Case(4, FabricBlockSettings.of(Material.METAL).nonOpaque())),
Charger("charger", Charger()),
Disassembler("disassembler", Disassembler()),
DiskDrive("diskdrive", DiskDrive()),
Expand Down Expand Up @@ -178,7 +184,7 @@ object Components {
fun registerComponents() {

caseEntityType = Registry.register(Registry.BLOCK_ENTITY_TYPE, Identifier(OpenComputers.modId, "case"),
BlockEntityType.Builder.create({ CaseEntity() }, Case(4)).build(null))
BlockEntityType.Builder.create({ CaseEntity() }, Case(4, FabricBlockSettings.of(Material.METAL).nonOpaque())).build(null))

BlockEntities.values().iterator().forEach { x ->
Registry.register(Registry.BLOCK_ENTITY_TYPE, Identifier(OpenComputers.modId, x.id), x.entityType)
Expand All @@ -192,4 +198,8 @@ object Components {
Registry.register(Registry.ITEM, Identifier(OpenComputers.modId, x.id), x.item)
}
}

val CASE1 = Case(1, FabricBlockSettings.of(Material.METAL).nonOpaque(), )
val CASE_SCREEN_HANDLER: ScreenHandlerType<CaseScreenHandler> = ScreenHandlerRegistry.registerSimple(Identifier(OpenComputers.modId, "case1"), ::CaseScreenHandler)

}
2 changes: 0 additions & 2 deletions src/main/kotlin/li/cli/oc/OpenComputers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@ object OpenComputers: ModInitializer {
ConfigLoader.initializeConfig()
Components.registerComponents()
}


}
34 changes: 32 additions & 2 deletions src/main/kotlin/li/cli/oc/blocks/Case.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,40 @@ package li.cli.oc.blocks;
import li.cli.oc.Components
import li.cli.oc.blocks.commons.TecBlock;
import li.cli.oc.blocks.commons.RedstoneAwareEntity;
import li.cli.oc.client.gui.blocks.CaseScreenHandler
import li.cli.oc.render.Color
import net.fabricmc.fabric.api.`object`.builder.v1.block.FabricBlockSettings
import net.minecraft.block.*
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.entity.player.PlayerInventory
import net.minecraft.item.ItemPlacementContext
import net.minecraft.screen.NamedScreenHandlerFactory
import net.minecraft.screen.ScreenHandler
import net.minecraft.state.StateManager
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.text.Text
import net.minecraft.text.TranslatableText
import net.minecraft.util.ActionResult
import net.minecraft.util.Hand
import net.minecraft.util.hit.BlockHitResult
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Direction
import net.minecraft.world.BlockView;
import net.minecraft.world.World

class CaseEntity : RedstoneAwareEntity(Components.caseEntityType) {
class CaseEntity : RedstoneAwareEntity(Components.caseEntityType), NamedScreenHandlerFactory {

override fun createMenu(syncId: Int, inv: PlayerInventory, player: PlayerEntity): ScreenHandler {
return CaseScreenHandler(syncId, inv)
}

override fun getDisplayName(): Text {
return Text.of("Computer")
}
}

class Case(var Tear: Int) : TecBlock(FabricBlockSettings.of(Material.METAL)) {
class Case(var Tear: Int, settings: Settings) : TecBlock(settings) {


override fun getColor(): Int {
Expand Down Expand Up @@ -48,4 +67,15 @@ class Case(var Tear: Int) : TecBlock(FabricBlockSettings.of(Material.METAL)) {
override fun getRenderType(state: BlockState?): BlockRenderType {
return BlockRenderType.MODEL;
}

override fun onUse(state: BlockState, world: World, pos: BlockPos?, player: PlayerEntity, hand: Hand?, hit: BlockHitResult?): ActionResult? {
// Open the case screen if we can
if (!world.isClient) {
val screenHandlerFactory = state.createScreenHandlerFactory(world, pos)
if (screenHandlerFactory != null) {
player.openHandledScreen(screenHandlerFactory)
}
}
return ActionResult.SUCCESS
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package li.cli.oc.blocks.commons;

import li.cli.oc.client.gui.blocks.CaseScreenHandler
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.entity.player.PlayerInventory
import net.minecraft.screen.NamedScreenHandlerFactory
import net.minecraft.screen.ScreenHandler
import net.minecraft.text.Text
import net.minecraft.util.math.Direction;
import java.util.*

Expand All @@ -10,7 +16,6 @@ open class RedstoneAwareEntity(type: BlockEntityType<*>?) : BlockEntity(type) {
// val input = Arrays.asList(-1, -1, -1, -1, -1, -1)
val output = listOf(0, 0, 0, 0, 0, 0)


fun getOutput(direction: Direction): Int {

for (i in 0..Direction.values().size) {
Expand Down
7 changes: 6 additions & 1 deletion src/main/kotlin/li/cli/oc/client/ClientInit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import li.cli.oc.Components
import li.cli.oc.OpenComputers
import li.cli.oc.blocks.Case
import li.cli.oc.blocks.Screen
import li.cli.oc.client.gui.blocks.CaseScreen
import li.cli.oc.items.commons.ComponentBlockItem
import li.cli.oc.render.BaseModelProvider
import li.cli.oc.render.block.CableModel
import li.cli.oc.render.block.ScreenModel
import li.cli.oc.render.block.CableModel
import net.fabricmc.api.ClientModInitializer
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap
import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry
import net.fabricmc.fabric.api.client.screenhandler.v1.ScreenRegistry
import net.minecraft.block.BlockState
import net.minecraft.client.render.RenderLayer
import net.minecraft.item.ItemStack
Expand All @@ -25,6 +27,7 @@ object ClientInit : ClientModInitializer {
ModelLoadingRegistry.INSTANCE.registerResourceProvider { BaseModelProvider(Identifier(OpenComputers.modId, "block/cable"), CableModel()) }
ModelLoadingRegistry.INSTANCE.registerResourceProvider { BaseModelProvider(Identifier(OpenComputers.modId, "block/screen"), ScreenModel()) }


ColorProviderRegistry.BLOCK.register(handleBlockColor,
Components.Blocks.CaseOne.block,
Components.Blocks.CaseTwo.block,
Expand All @@ -46,6 +49,8 @@ object ClientInit : ClientModInitializer {
)

BlockRenderLayerMap.INSTANCE.putBlock(Components.Blocks.Assembler.block, RenderLayer.getTranslucent());

ScreenRegistry.register(Components.CASE_SCREEN_HANDLER, ::CaseScreen)
}

private val handleItemColor = fun (item: ItemStack, tintIndex: Int): Int {
Expand Down
57 changes: 57 additions & 0 deletions src/main/kotlin/li/cli/oc/client/gui/blocks/CaseScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package li.cli.oc.client.gui.blocks

import com.mojang.blaze3d.systems.RenderSystem
import li.cli.oc.OpenComputers
import net.minecraft.client.gui.screen.ingame.HandledScreen
import net.minecraft.client.gui.widget.TexturedButtonWidget
import net.minecraft.client.util.math.MatrixStack
import net.minecraft.entity.player.PlayerInventory
import net.minecraft.screen.ScreenHandler
import net.minecraft.text.Text
import net.minecraft.util.Identifier

class CaseScreen(handler: ScreenHandler?, inventory: PlayerInventory?, title: Text?) : HandledScreen<ScreenHandler?>(handler, inventory, title) {

override fun drawBackground(matrices: MatrixStack?, delta: Float, mouseX: Int, mouseY: Int) {
RenderSystem.color4f(1.0f, 1.0f, 1.0f, 1.0f)
assert(client != null)
client!!.textureManager.bindTexture(TEXTURE)
val x = (width - backgroundWidth) / 2
val y = (height - backgroundHeight) / 2
drawTexture(matrices, x, y, 0, 0, backgroundWidth, backgroundHeight)

client!!.textureManager.bindTexture(COMP_TEXTURE)
drawTexture(matrices, x, y + 1, 0, 0, 256, 256)
}


override fun render(matrices: MatrixStack, mouseX: Int, mouseY: Int, delta: Float) {
renderBackground(matrices)
super.render(matrices, mouseX, mouseY, delta)
drawMouseoverTooltip(matrices, mouseX, mouseY)
}

override fun init() {
super.init()
val x = (width - backgroundWidth) / 2
val y = (height - backgroundHeight) / 2
// Center the title
titleX = 7
val powerButton = TexturedButtonWidget(x + (backgroundWidth / 2) - 18 , y + 34, 18, 18, 0, 0, 0, BUTTON_TEXTURE, 36, 36) { button ->
TODO(
"Computer start/stop here"
)
}
addButton(powerButton)


}

companion object {
private val TEXTURE = Identifier(OpenComputers.modId, "textures/gui/background.png")
private val COMP_TEXTURE = Identifier(OpenComputers.modId, "textures/gui/computer.png")
private val BUTTON_TEXTURE = Identifier(OpenComputers.modId, "textures/gui/button_power.png")
private val SLOT_TEXTURE = Identifier(OpenComputers.modId, "textures/gui/slot.png")
}

}
36 changes: 36 additions & 0 deletions src/main/kotlin/li/cli/oc/client/gui/blocks/CaseScreenHandler.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package li.cli.oc.client.gui.blocks

import li.cli.oc.Components
import li.cli.oc.client.gui.blocks.slots.*
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.entity.player.PlayerInventory
import net.minecraft.inventory.SimpleInventory
import net.minecraft.screen.ScreenHandler
import net.minecraft.screen.slot.Slot

class CaseScreenHandler(syncId: Int, playerInventory: PlayerInventory) : ScreenHandler(Components.CASE_SCREEN_HANDLER, syncId) {
private val inventory = SimpleInventory(10)

override fun canUse(player: PlayerEntity?): Boolean {
return inventory.canPlayerUse(player)
}

init {
// BIOS Slot to the left of the power button
addSlot(Slot(inventory, 0, 20, 20))

// Two Expansion Slot Cards to the left of the component grid
addSlot(Slot(inventory, 1, 80, 10))
addSlot(Slot(inventory, 2, 80, 30))

// One CPU Slot in the center top of the component grid
addSlot(Slot(inventory, 3, 100, 10))

// Two RAM Slots in the direct middle and bottom middle of the component grid
addSlot(Slot(inventory, 4, 100, 30))
addSlot(Slot(inventory, 5, 100, 50))

// One HDD Slot in the top right of the component grid
addSlot(Slot(inventory, 6, 120, 10))
}
}
18 changes: 18 additions & 0 deletions src/main/kotlin/li/cli/oc/client/gui/blocks/slots/CPUSlot.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package li.cli.oc.client.gui.blocks.slots

import li.cli.oc.items.CPU
import net.minecraft.inventory.Inventory
import net.minecraft.item.ItemStack
import net.minecraft.screen.slot.Slot

class CPUSlot(inventory: Inventory, index: Int, x: Int, y: Int, level: Int) : Slot(inventory, index, x, y) {
private val tier: Int = 0

/* override fun canInsert(stack: ItemStack?): Boolean {
if (stack != null) {
return stack.item is CPU && CPU.tier <= tier
}

return false
}*/
}
16 changes: 16 additions & 0 deletions src/main/kotlin/li/cli/oc/client/gui/blocks/slots/EEPROMSlot.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package li.cli.oc.client.gui.blocks.slots

import net.minecraft.inventory.Inventory
import net.minecraft.item.ItemStack
import net.minecraft.screen.slot.Slot

class EEPROMSlot(inventory: Inventory, index: Int, x: Int, y: Int) : Slot(inventory, index, x, y) {

/* override fun canInsert(stack: ItemStack?): Boolean {
if (stack != null) {
return stack.item is EEPROM // TODO: Rename once BIOS Card item class is created
}

return false
}*/
}
17 changes: 17 additions & 0 deletions src/main/kotlin/li/cli/oc/client/gui/blocks/slots/ExpSlot.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package li.cli.oc.client.gui.blocks.slots

import net.minecraft.inventory.Inventory
import net.minecraft.item.ItemStack
import net.minecraft.screen.slot.Slot

class ExpSlot(inventory: Inventory, index: Int, x: Int, y: Int, level: Int) : Slot(inventory, index, x, y) {
private val level: Int = 0

/* override fun canInsert(stack: ItemStack?): Boolean {
if (stack != null) {
return stack.item is ExpansionCard && ExpansionCard.level <= level// TODO: Rename once Expansion Card item class is created
}

return false
}*/
}
17 changes: 17 additions & 0 deletions src/main/kotlin/li/cli/oc/client/gui/blocks/slots/HDSlot.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package li.cli.oc.client.gui.blocks.slots

import net.minecraft.inventory.Inventory
import net.minecraft.item.ItemStack
import net.minecraft.screen.slot.Slot

class HDSlot(inventory: Inventory, index: Int, x: Int, y: Int, level: Int) : Slot(inventory, index, x, y) {
private val level: Int = 0

/* override fun canInsert(stack: ItemStack?): Boolean {
if (stack != null) {
return stack.item is HardDrive && HardDrive.level <= level// TODO: Rename once Expansion Card item class is created
}

return false
}*/
}
17 changes: 17 additions & 0 deletions src/main/kotlin/li/cli/oc/client/gui/blocks/slots/RAMSlot.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package li.cli.oc.client.gui.blocks.slots

import net.minecraft.inventory.Inventory
import net.minecraft.item.ItemStack
import net.minecraft.screen.slot.Slot

class RAMSlot(inventory: Inventory, index: Int, x: Int, y: Int, level: Int) : Slot(inventory, index, x, y) {
private val level: Int = 0

/* override fun canInsert(stack: ItemStack?): Boolean {
if (stack != null) {
return stack.item is RAMCard && RAMCard.level <= level// TODO: Rename once RAM Card item class is created
}

return false
}*/
}
9 changes: 9 additions & 0 deletions src/main/kotlin/li/cli/oc/items/CPU.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package li.cli.oc.items

import li.cli.oc.OpenComputers
import net.minecraft.item.Item

class CPU(tier: Int) : Item(Settings().group(OpenComputers.ITEM_GROUP)) {


}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"fabric": "*",
"minecraft": "1.16.x"
},
"requires": {
"depends": {
"fabric-language-kotlin": ">=1.4.0"
},
"suggests": {
Expand Down