Skip to content

Commit

Permalink
Merge pull request #1 from Hiiragi283/machine_rebuild
Browse files Browse the repository at this point in the history
Release v0.6.0
  • Loading branch information
Hiiragi283 authored Nov 5, 2024
2 parents 66d3233 + d76bad8 commit 22be7f7
Show file tree
Hide file tree
Showing 551 changed files with 5,920 additions and 8,704 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "hiiragi283.ragium"
version = "0.5.1+121x"
version = "0.6.0+121x"

sourceSets {
main {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ package hiiragi283.ragium.api.machine
import hiiragi283.ragium.api.RagiumAPI
import hiiragi283.ragium.api.property.HTPropertyKey
import hiiragi283.ragium.api.renderer.HTMachineEntityRenderer
import hiiragi283.ragium.client.model.HTProcessorMachineModel
import net.fabricmc.api.EnvType
import net.fabricmc.api.Environment
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel
import net.minecraft.util.Identifier

@Environment(EnvType.CLIENT)
object HTClientMachinePropertyKeys {
@JvmField
val DYNAMIC_RENDERER: HTPropertyKey.Simple<HTMachineEntityRenderer> =
HTPropertyKey.Simple(RagiumAPI.id("dynamic_renderer"))
HTPropertyKey.ofSimple(RagiumAPI.id("dynamic_renderer"))

@JvmField
val STATIC_RENDERER: HTPropertyKey.Simple<FabricBakedModel> =
HTPropertyKey.Simple(RagiumAPI.id("static_renderer"))
val MODEL_ID: HTPropertyKey.Defaulted<Identifier> =
HTPropertyKey.ofDefaulted(RagiumAPI.id("model_id")) { HTProcessorMachineModel.MODEL_ID }
}
31 changes: 0 additions & 31 deletions src/client/kotlin/hiiragi283/ragium/api/model/HTAliasedModel.kt

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package hiiragi283.ragium.api.renderer

import hiiragi283.ragium.api.machine.entity.HTMachineEntity
import hiiragi283.ragium.api.machine.block.HTMachineBlockEntityBase
import net.fabricmc.api.EnvType
import net.fabricmc.api.Environment
import net.minecraft.client.render.VertexConsumerProvider
Expand All @@ -11,7 +11,7 @@ import net.minecraft.world.World
@Environment(EnvType.CLIENT)
fun interface HTMachineEntityRenderer {
fun render(
machine: HTMachineEntity<*>,
entity: HTMachineBlockEntityBase,
world: World,
pos: BlockPos,
tickDelta: Float,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package hiiragi283.ragium.api.renderer

import hiiragi283.ragium.api.extension.getOrNull
import hiiragi283.ragium.api.machine.entity.HTMachineEntity
import hiiragi283.ragium.api.machine.block.HTMachineBlockEntityBase
import hiiragi283.ragium.api.machine.multiblock.HTMultiblockController
import hiiragi283.ragium.client.extension.renderMultiblock
import net.fabricmc.api.EnvType
Expand All @@ -15,7 +15,7 @@ import net.minecraft.world.World
@Environment(EnvType.CLIENT)
object HTMultiblockPreviewRenderer : HTMachineEntityRenderer {
override fun render(
machine: HTMachineEntity<*>,
entity: HTMachineBlockEntityBase,
world: World,
pos: BlockPos,
tickDelta: Float,
Expand All @@ -24,9 +24,9 @@ object HTMultiblockPreviewRenderer : HTMachineEntityRenderer {
light: Int,
overlay: Int,
) {
if (machine is HTMultiblockController) {
if (entity is HTMultiblockController) {
renderMultiblock(
machine,
entity,
world,
world.getBlockState(pos).getOrNull(Properties.HORIZONTAL_FACING),
matrices,
Expand Down
59 changes: 31 additions & 28 deletions src/client/kotlin/hiiragi283/ragium/client/RagiumClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@ package hiiragi283.ragium.client

import hiiragi283.ragium.api.RagiumAPI
import hiiragi283.ragium.api.content.HTRegistryContent
import hiiragi283.ragium.api.extension.getMachineEntity
import hiiragi283.ragium.api.extension.getOrNull
import hiiragi283.ragium.api.gui.HTMachineScreenBase
import hiiragi283.ragium.api.machine.property.HTMachinePropertyKeys
import hiiragi283.ragium.api.machine.block.HTMachineBlockEntityBase
import hiiragi283.ragium.client.extension.getBlockEntity
import hiiragi283.ragium.client.extension.registerClientReceiver
import hiiragi283.ragium.client.gui.HTFireboxMachineScreen
import hiiragi283.ragium.client.gui.HTLargeMachineScreen
import hiiragi283.ragium.client.gui.HTSimpleMachineScreen
import hiiragi283.ragium.client.gui.HTSteamMachineScreen
import hiiragi283.ragium.client.model.HTFluidCubeModel
import hiiragi283.ragium.client.model.HTMachineModel
import hiiragi283.ragium.client.model.HTProcessorMachineModel
import hiiragi283.ragium.client.renderer.HTFireboxBlockEntityRenderer
import hiiragi283.ragium.client.renderer.HTItemDisplayBlockEntityRenderer
import hiiragi283.ragium.client.renderer.HTMetaMachineBlockEntityRenderer
import hiiragi283.ragium.client.renderer.HTMachineBlockEntityRenderer
import hiiragi283.ragium.common.RagiumContents
import hiiragi283.ragium.common.init.*
import hiiragi283.ragium.common.network.HTFloatingItemPayload
Expand All @@ -36,6 +35,7 @@ import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant
import net.minecraft.block.Block
import net.minecraft.block.BlockState
import net.minecraft.block.entity.BlockEntityType
import net.minecraft.client.gui.screen.Screen
import net.minecraft.client.gui.screen.ingame.HandledScreens
import net.minecraft.client.render.RenderLayer
Expand Down Expand Up @@ -64,6 +64,7 @@ object RagiumClient : ClientModInitializer {

// Blocks //

@JvmStatic
private fun registerBlocks() {
// cutout
buildList {
Expand All @@ -74,12 +75,13 @@ object RagiumClient : ClientModInitializer {
// cutout mipped
BlockRenderLayerMap.INSTANCE.putBlocks(
RenderLayer.getCutoutMipped(),
RagiumBlocks.META_CONSUMER,
RagiumBlocks.META_GENERATOR,
RagiumBlocks.META_PROCESSOR,
RagiumBlocks.POROUS_NETHERRACK,
RagiumBlocks.FIREBOX,
)
RagiumAPI
.getInstance()
.machineRegistry.blocks.values
.forEach(::registerCutoutMipped)

buildList {
addAll(RagiumContents.Ores.entries)
Expand All @@ -88,41 +90,46 @@ object RagiumClient : ClientModInitializer {

BlockEntityRendererFactories.register(RagiumBlockEntityTypes.FIREBOX) { HTFireboxBlockEntityRenderer }
BlockEntityRendererFactories.register(RagiumBlockEntityTypes.ITEM_DISPLAY) { HTItemDisplayBlockEntityRenderer }
BlockEntityRendererFactories.register(RagiumBlockEntityTypes.META_MACHINE) { HTMetaMachineBlockEntityRenderer }

registerMachineRenderer(RagiumBlockEntityTypes.BLAST_FURNACE)
registerMachineRenderer(RagiumBlockEntityTypes.DISTILLATION_TOWER)
registerMachineRenderer(RagiumBlockEntityTypes.LARGE_PROCESSOR)
registerMachineRenderer(RagiumBlockEntityTypes.MULTI_SMELTER)
registerMachineRenderer(RagiumBlockEntityTypes.SAW_MILL)

ColorProviderRegistry.BLOCK.register({ state: BlockState, _: BlockRenderView?, _: BlockPos?, _: Int ->
state.getOrNull(RagiumBlockProperties.COLOR)?.fireworkColor ?: -1
}, RagiumBlocks.BACKPACK_INTERFACE)

ColorProviderRegistry.BLOCK.register({ _: BlockState, view: BlockRenderView?, pos: BlockPos?, _: Int ->
pos
?.let { view?.getMachineEntity(it) }
?.machineType
?.get(HTMachinePropertyKeys.GENERATOR_COLOR)
?.fireworkColor
?: -1
}, RagiumBlocks.META_GENERATOR)
}

@JvmStatic
private fun registerCutout(block: Block) {
BlockRenderLayerMap.INSTANCE.putBlock(block, RenderLayer.getCutout())
}

@JvmStatic
private fun registerCutoutMipped(block: Block) {
BlockRenderLayerMap.INSTANCE.putBlock(block, RenderLayer.getCutoutMipped())
}

@JvmStatic
private fun <T : HTMachineBlockEntityBase> registerMachineRenderer(type: BlockEntityType<T>) {
BlockEntityRendererFactories.register(type) { HTMachineBlockEntityRenderer }
}

// Entities //

@JvmStatic
private fun registerEntities() {
EntityRendererRegistry.register(RagiumEntityTypes.REMOVER_DYNAMITE, ::FlyingItemEntityRenderer)
EntityRendererRegistry.register(RagiumEntityTypes.DYNAMITE, ::FlyingItemEntityRenderer)
}

// Fluids //

@JvmStatic
private fun registerFluids() {
RagiumContents.Fluids.entries.forEach { fluid: RagiumContents.Fluids ->
RagiumFluids.entries.forEach { fluid: RagiumFluids ->
FluidRenderHandlerRegistry.INSTANCE.register(
fluid.value,
SimpleFluidRenderHandler(
Expand All @@ -136,22 +143,16 @@ object RagiumClient : ClientModInitializer {

// Items //

@JvmStatic
private fun registerItems() {
ColorProviderRegistry.ITEM.register({ stack: ItemStack, _: Int ->
stack.get(RagiumComponentTypes.COLOR)?.entityColor ?: -1
}, RagiumContents.Misc.BACKPACK)

ColorProviderRegistry.ITEM.register({ stack: ItemStack, _: Int ->
stack
.get(RagiumComponentTypes.MACHINE_TYPE)
?.get(HTMachinePropertyKeys.GENERATOR_COLOR)
?.fireworkColor
?: -1
}, RagiumBlocks.META_GENERATOR)
}, RagiumItems.BACKPACK)
}

// Screens //

@JvmStatic
private fun registerScreens() {
HandledScreens.register(RagiumScreenHandlerTypes.FIREBOX, ::HTFireboxMachineScreen)
HandledScreens.register(RagiumScreenHandlerTypes.LARGE_MACHINE, ::HTLargeMachineScreen)
Expand All @@ -161,12 +162,13 @@ object RagiumClient : ClientModInitializer {

// Events //

@JvmStatic
private fun registerEvents() {
ModelLoadingPlugin.register { context: ModelLoadingPlugin.Context ->
// register item model resolver
context.modifyModelOnLoad().register onLoad@{ original: UnbakedModel, _: ModelModifier.OnLoad.Context ->
when {
HTMachineModel.MODEL_ID in original.modelDependencies -> HTMachineModel
HTProcessorMachineModel.MODEL_ID in original.modelDependencies -> HTProcessorMachineModel
HTFluidCubeModel.MODEL_ID in original.modelDependencies -> HTFluidCubeModel
else -> original
}
Expand All @@ -180,6 +182,7 @@ object RagiumClient : ClientModInitializer {

// Networks //

@JvmStatic
private fun registerNetworks() {
RagiumNetworks.FLOATING_ITEM.registerClientReceiver { payload: HTFloatingItemPayload, context: ClientPlayNetworking.Context ->
context.client().gameRenderer.showFloatingItem(payload.stack)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,33 @@ import hiiragi283.ragium.api.RagiumAPI
import hiiragi283.ragium.api.RagiumPlugin
import hiiragi283.ragium.api.extension.isClientEnv
import hiiragi283.ragium.api.machine.HTClientMachinePropertyKeys
import hiiragi283.ragium.api.machine.HTMachineTypeKey
import hiiragi283.ragium.api.model.HTAliasedModel
import hiiragi283.ragium.api.model.HTDefaultProcessorModel
import hiiragi283.ragium.api.machine.HTMachineKey
import hiiragi283.ragium.api.renderer.HTMultiblockPreviewRenderer
import hiiragi283.ragium.common.init.RagiumMachineTypes
import hiiragi283.ragium.common.init.RagiumMachineKeys

object RagiumDefaultClientPlugin : RagiumPlugin {
override val priority: Int = -100

override fun afterRagiumInit() {}
override fun afterRagiumInit(instance: RagiumAPI) {}

override fun shouldLoad(): Boolean = isClientEnv()

override fun setupClientMachineProperties(helper: RagiumPlugin.PropertyHelper) {
helper.modify(HTMachineTypeKey::isProcessor) {
set(HTClientMachinePropertyKeys.STATIC_RENDERER, HTDefaultProcessorModel)
}
helper.modify(RagiumMachineTypes.BLAST_FURNACE) {
override fun setupClientMachineProperties(helper: RagiumPlugin.PropertyHelper<HTMachineKey>) {
helper.modify(RagiumMachineKeys.BLAST_FURNACE) {
set(HTClientMachinePropertyKeys.DYNAMIC_RENDERER, HTMultiblockPreviewRenderer)
}
helper.modify(RagiumMachineTypes.DISTILLATION_TOWER) {
helper.modify(RagiumMachineKeys.DISTILLATION_TOWER) {
set(HTClientMachinePropertyKeys.DYNAMIC_RENDERER, HTMultiblockPreviewRenderer)
}
helper.modify(RagiumMachineTypes.SAW_MILL) {
helper.modify(RagiumMachineKeys.SAW_MILL) {
set(HTClientMachinePropertyKeys.DYNAMIC_RENDERER, HTMultiblockPreviewRenderer)
}

helper.modify(HTMachineTypeKey::isGenerator) {
set(HTClientMachinePropertyKeys.STATIC_RENDERER, HTAliasedModel(RagiumAPI.id("block/generator")))
}
helper.modify(RagiumMachineTypes.Generator.STEAM) {
set(HTClientMachinePropertyKeys.STATIC_RENDERER, HTDefaultProcessorModel)
helper.modify(RagiumMachineKeys.GENERATORS::contains) {
set(HTClientMachinePropertyKeys.MODEL_ID, RagiumAPI.id("block/generator"))
}
helper.modify(RagiumMachineTypes.Generator.SOLAR) {
set(HTClientMachinePropertyKeys.STATIC_RENDERER, HTAliasedModel(RagiumAPI.id("block/solar_generator")))
helper.modify(RagiumMachineKeys.SOLAR_PANEL) {
set(HTClientMachinePropertyKeys.MODEL_ID, RagiumAPI.id("block/solar_generator"))
}
}
}
Loading

0 comments on commit 22be7f7

Please sign in to comment.