This repository was archived by the owner on Jun 1, 2021. It is now read-only.
forked from MightyPirates/OpenComputers
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathClientInit.kt
More file actions
69 lines (59 loc) · 2.8 KB
/
Copy pathClientInit.kt
File metadata and controls
69 lines (59 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package li.cli.oc.client
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.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
import net.minecraft.util.Identifier
import net.minecraft.util.math.BlockPos
import net.minecraft.world.BlockRenderView
object ClientInit : ClientModInitializer {
override fun onInitializeClient() {
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,
Components.Blocks.CaseThree.block,
Components.Blocks.CaseCreative.block,
Components.Blocks.ScreenOne.block,
Components.Blocks.ScreenTwo.block,
Components.Blocks.ScreenThree.block,
)
ColorProviderRegistry.ITEM.register(handleItemColor,
Components.Items.CaseOne.item,
Components.Items.CaseTwo.item,
Components.Items.CaseThree.item,
Components.Items.CaseCreative.item,
Components.Items.ScreenOne.item,
Components.Items.ScreenTwo.item,
Components.Items.ScreenThree.item,
)
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 {
if(item.item is ComponentBlockItem)
return (item.item as ComponentBlockItem).getColor() ?: 0xFF0000
return 0xFF0000
}
private val handleBlockColor = fun (state: BlockState, view: BlockRenderView?, pos: BlockPos?, tintIndex: Int): Int {
if(state.block is Case)
return (state.block as Case).getColor()
else if(state.block is Screen)
return (state.block as Screen).getColor()
return 0xFF0000
}
}