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 8e3d643a8..b75f9512e 100644 Binary files a/src/main/resources/assets/overdrive_that_matters/textures/block/holo_sign.png and b/src/main/resources/assets/overdrive_that_matters/textures/block/holo_sign.png differ