From d3b0eb5f926997afa800f5b362eec1363dc6a66c Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Mon, 8 Jan 2024 21:32:53 +0700 Subject: [PATCH] Add tintindex to holo sign to color its lights --- .../entity/decorative/HoloSignBlockEntity.kt | 26 ++++++++- .../mc/otm/registry/MBlockColors.kt | 54 ++++++++++++++---- .../models/block/holo_sign.json | 42 ++------------ .../textures/block/holo_sign.png | Bin 424 -> 1113 bytes 4 files changed, 72 insertions(+), 50 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/HoloSignBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/HoloSignBlockEntity.kt index c349afb9c..445439897 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/HoloSignBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/decorative/HoloSignBlockEntity.kt @@ -12,10 +12,15 @@ import net.minecraft.world.level.block.state.BlockState import ru.dbotthepony.mc.otm.block.entity.IRedstoneControlled import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity import ru.dbotthepony.mc.otm.block.entity.SynchronizedRedstoneControl +import ru.dbotthepony.mc.otm.client.minecraft import ru.dbotthepony.mc.otm.menu.decorative.HoloSignMenu +import ru.dbotthepony.mc.otm.network.synchronizer.FloatFieldAccess import ru.dbotthepony.mc.otm.once import ru.dbotthepony.mc.otm.registry.MBlockEntities import ru.dbotthepony.mc.otm.registry.MBlocks +import thedarkcolour.kotlinforforge.forge.vectorutil.v3d.component1 +import thedarkcolour.kotlinforforge.forge.vectorutil.v3d.component2 +import thedarkcolour.kotlinforforge.forge.vectorutil.v3d.component3 class HoloSignBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryBlockEntity(MBlockEntities.HOLO_SIGN, blockPos, blockState), MenuProvider, IRedstoneControlled { override val redstoneControl = SynchronizedRedstoneControl(synchronizer) { _, _ -> setChanged() } @@ -25,9 +30,24 @@ class HoloSignBlockEntity(blockPos: BlockPos, blockState: BlockState) : MatteryB access.write(value) }) - var textRed by synchronizer.float(1f).property - var textGreen by synchronizer.float(1f).property - var textBlue by synchronizer.float(85f / 255f).property + private fun colorSetter(value: Float, access: FloatFieldAccess, setByRemote: Boolean) { + if (access.readFloat() != value) { + access.write(value) + + if (setByRemote) { + markDirtyClientside() + } + } + } + + private fun markDirtyClientside() { + val (x, y, z) = blockPos + minecraft.levelRenderer.setBlocksDirty(x, y, z, x, y, z) + } + + var textRed by synchronizer.float(1f, setter = ::colorSetter).property + var textGreen by synchronizer.float(1f, setter = ::colorSetter).property + var textBlue by synchronizer.float(85f / 255f, setter = ::colorSetter).property var textAlpha by synchronizer.float(1f).property var isLocked = false diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MBlockColors.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MBlockColors.kt index 907ed0940..7d17ee06e 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MBlockColors.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MBlockColors.kt @@ -1,5 +1,7 @@ package ru.dbotthepony.mc.otm.registry +import net.minecraft.client.color.block.BlockColor +import net.minecraft.client.color.item.ItemColor import net.minecraft.client.renderer.BiomeColors import net.minecraft.core.BlockPos import net.minecraft.world.item.ItemStack @@ -7,29 +9,59 @@ import net.minecraft.world.level.BlockAndTintGetter import net.minecraft.world.level.block.state.BlockState import net.minecraftforge.client.event.RegisterColorHandlersEvent import net.minecraftforge.eventbus.api.IEventBus +import ru.dbotthepony.mc.otm.block.entity.decorative.HoloSignBlockEntity +import ru.dbotthepony.mc.otm.core.math.RGBAColor object MBlockColors { private const val DEFAULT_WATER_TINT: Int = 0x3F76E4 + private const val DEFAULT_HOLO_SIGN_TINT: Int = 0xffe049 + + private object CobblestoneGeneratorColor : BlockColor, ItemColor { + override fun getColor(state: BlockState, light: BlockAndTintGetter?, pos: BlockPos?, index: Int): Int { + return if (index == 0) { + if (light == null || pos == null) + DEFAULT_WATER_TINT + else + BiomeColors.getAverageWaterColor(light, pos) + } else -1 + } + + override fun getColor(itemStack: ItemStack, index: Int): Int { + return if (index == 0) DEFAULT_WATER_TINT else -1 + } + } + + private object HoloSightColor : BlockColor, ItemColor { + override fun getColor(state: BlockState, light: BlockAndTintGetter?, pos: BlockPos?, index: Int): Int { + if (index != 0) + return -1 + + if (light == null || pos == null) + return DEFAULT_HOLO_SIGN_TINT + + val blockEntity = light.getBlockEntity(pos) as? HoloSignBlockEntity ?: return DEFAULT_HOLO_SIGN_TINT + return RGBAColor(blockEntity.textRed, blockEntity.textGreen, blockEntity.textBlue, blockEntity.textAlpha).toRGB() + } + + override fun getColor(itemStack: ItemStack, index: Int): Int { + return if (index == 0) DEFAULT_HOLO_SIGN_TINT else -1 + } + } private fun registerBlockColors(event: RegisterColorHandlersEvent.Block) { for (it in MBlocks.COBBLESTONE_GENERATOR.values) { - event.register({ state: BlockState, light: BlockAndTintGetter?, pos: BlockPos?, index: Int -> - if (index == 0) { - if (light == null || pos == null) - DEFAULT_WATER_TINT - else - BiomeColors.getAverageWaterColor(light, pos) - } else -1 - }, it) + event.register(CobblestoneGeneratorColor, it) } + + event.register(HoloSightColor, MBlocks.HOLO_SIGN) } private fun registerItemColors(event: RegisterColorHandlersEvent.Item) { for (it in MBlocks.COBBLESTONE_GENERATOR.values) { - event.register({ stack: ItemStack, index: Int -> - if (index == 0) DEFAULT_WATER_TINT else -1 - }, it) + event.register(CobblestoneGeneratorColor, it) } + + event.register(HoloSightColor, MBlocks.HOLO_SIGN) } internal fun register(bus: IEventBus) { diff --git a/src/main/resources/assets/overdrive_that_matters/models/block/holo_sign.json b/src/main/resources/assets/overdrive_that_matters/models/block/holo_sign.json index 70537dc8e..87e56f308 100644 --- a/src/main/resources/assets/overdrive_that_matters/models/block/holo_sign.json +++ b/src/main/resources/assets/overdrive_that_matters/models/block/holo_sign.json @@ -77,12 +77,7 @@ "from": [14, 14, 9.99], "to": [15, 15, 9.99], "faces": { - "north": {"uv": [8.5, 8.5, 9, 9], "texture": "#0", "forge_data": {"block_light": 15}}, - "east": {"uv": [0, 0, 0, 16], "texture": "#missing"}, - "south": {"uv": [0, 0, 16, 16], "texture": "#missing"}, - "west": {"uv": [0, 0, 0, 16], "texture": "#missing"}, - "up": {"uv": [0, 0, 16, 0], "texture": "#missing"}, - "down": {"uv": [0, 0, 16, 0], "texture": "#missing"} + "north": {"uv": [8.5, 8.5, 9, 9], "texture": "#0", "forge_data": {"block_light": 15}, "tintindex": 0} } }, { @@ -90,12 +85,7 @@ "from": [1, 14, 9.99], "to": [2, 15, 9.99], "faces": { - "north": {"uv": [15, 8.5, 15.5, 9], "texture": "#0", "forge_data": {"block_light": 15}}, - "east": {"uv": [0, 0, 0, 16], "texture": "#missing"}, - "south": {"uv": [0, 0, 16, 16], "texture": "#missing"}, - "west": {"uv": [0, 0, 0, 16], "texture": "#missing"}, - "up": {"uv": [0, 0, 16, 0], "texture": "#missing"}, - "down": {"uv": [0, 0, 16, 0], "texture": "#missing"} + "north": {"uv": [15, 8.5, 15.5, 9], "texture": "#0", "forge_data": {"block_light": 15}, "tintindex": 0} } }, { @@ -103,12 +93,7 @@ "from": [1, 1, 9.99], "to": [2, 2, 9.99], "faces": { - "north": {"uv": [15, 15, 15.5, 15.5], "texture": "#0", "forge_data": {"block_light": 15}}, - "east": {"uv": [0, 0, 0, 16], "texture": "#missing"}, - "south": {"uv": [0, 0, 16, 16], "texture": "#missing"}, - "west": {"uv": [0, 0, 0, 16], "texture": "#missing"}, - "up": {"uv": [0, 0, 16, 0], "texture": "#missing"}, - "down": {"uv": [0, 0, 16, 0], "texture": "#missing"} + "north": {"uv": [15, 15, 15.5, 15.5], "texture": "#0", "forge_data": {"block_light": 15}, "tintindex": 0} } }, { @@ -116,12 +101,7 @@ "from": [14, 1, 9.99], "to": [15, 2, 9.99], "faces": { - "north": {"uv": [8.5, 15, 9, 15.5], "texture": "#0", "forge_data": {"block_light": 15}}, - "east": {"uv": [0, 0, 0, 16], "texture": "#missing"}, - "south": {"uv": [0, 0, 16, 16], "texture": "#missing"}, - "west": {"uv": [0, 0, 0, 16], "texture": "#missing"}, - "up": {"uv": [0, 0, 16, 0], "texture": "#missing"}, - "down": {"uv": [0, 0, 16, 0], "texture": "#missing"} + "north": {"uv": [8.5, 15, 9, 15.5], "texture": "#0", "forge_data": {"block_light": 15}, "tintindex": 0} } }, { @@ -129,12 +109,7 @@ "from": [2.01, 6, 9], "to": [2.01, 10, 10], "faces": { - "north": {"uv": [0, 0, 0, 4], "texture": "#missing"}, - "east": {"uv": [1.5, 13, 2, 15], "texture": "#0", "forge_data": {"block_light": 15}}, - "south": {"uv": [0, 0, 0, 4], "texture": "#missing"}, - "west": {"uv": [0, 0, 1, 4], "texture": "#missing"}, - "up": {"uv": [0, 0, 0, 1], "texture": "#missing"}, - "down": {"uv": [0, 0, 0, 1], "texture": "#missing"} + "east": {"uv": [1.5, 13, 2, 15], "texture": "#0", "forge_data": {"block_light": 15}, "tintindex": 0} } }, { @@ -142,12 +117,7 @@ "from": [13.99, 6, 9], "to": [13.99, 10, 10], "faces": { - "north": {"uv": [0, 0, 0, 4], "texture": "#missing"}, - "east": {"uv": [0, 0, 1, 4], "texture": "#missing"}, - "south": {"uv": [0, 0, 0, 4], "texture": "#missing"}, - "west": {"uv": [1.5, 13, 2, 15], "texture": "#0", "forge_data": {"block_light": 15}}, - "up": {"uv": [0, 0, 0, 1], "texture": "#missing"}, - "down": {"uv": [0, 0, 0, 1], "texture": "#missing"} + "west": {"uv": [1.5, 13, 2, 15], "texture": "#0", "forge_data": {"block_light": 15}, "tintindex": 0} } } ], diff --git a/src/main/resources/assets/overdrive_that_matters/textures/block/holo_sign.png b/src/main/resources/assets/overdrive_that_matters/textures/block/holo_sign.png index 8e3d643a89386d032f9f4d0346dc4ad1d521e269..b75f9512eff389f6ee95bb647527ac9a5c2f3fc9 100644 GIT binary patch delta 1103 zcmV-V1hD(41K9|W8Gi-<0047(dh`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