Skip to content

Commit

Permalink
Merge pull request #4 from Hiiragi283/active_machine
Browse files Browse the repository at this point in the history
Release v0.9.0
  • Loading branch information
Hiiragi283 authored Nov 24, 2024
2 parents 7cca757 + 67cf748 commit f7164e2
Show file tree
Hide file tree
Showing 464 changed files with 5,069 additions and 4,587 deletions.
12 changes: 10 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType
import java.net.URI

plugins {
kotlin("jvm") version libs.versions.kotlin
Expand All @@ -8,7 +9,7 @@ plugins {
}

group = "hiiragi283.ragium"
version = "0.8.0+121x"
version = "0.9.0+121x"

sourceSets {
main {
Expand All @@ -35,14 +36,21 @@ repositories {
maven(url = "https://dl.cloudsmith.io/public/klikli-dev/mods/maven/") // Modonomicon
maven(url = "https://maven.modmuss50.me/")
maven(url = "https://maven.blamejared.com") // Patchouli
maven {
url = URI("https://maven.pkg.github.com/refinedmods/refinedstorage2")
credentials {
username = "anything"
password = "\u0067hp_oGjcDFCn8jeTzIj4Ke9pLoEVtpnZMP4VQgaX"
}
} // RS2
}

fabricApi {
configureDataGeneration()
}

loom {
// accessWidenerPath = file("src/main/resources/ht_materials.accesswidener")
accessWidenerPath = file("src/main/resources/ragium.accesswidener")
splitEnvironmentSourceSets()
mods {
create("ragium") {
Expand Down
5 changes: 4 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ fabric-kotlin = "1.12.+"
energy = "4.1.0"
jade = "15.8.2+fabric"
mod-menu = "11.0.3"
refined-storage = "2.0.0-milestone.4.9"
rei = "16.0.788"

[libraries]
Expand All @@ -21,13 +22,15 @@ fabric-kotlin = { group = "net.fabricmc", name = "fabric-language-kotlin", versi
energy = { group = "teamreborn", name = "energy", version.ref = "energy" }
jade = { group = "maven.modrinth", name = "jade", version.ref = "jade" }
mod-modmenu = { group = "com.terraformersmc", name = "modmenu", version.ref = "mod-menu" }
rs-fabric = { group = "com.refinedmods.refinedstorage", name = "refinedstorage-fabric", version.ref = "refined-storage" }
rei = { group = "me.shedaniel", name = "RoughlyEnoughItems-fabric", version.ref = "rei" }

[bundles]
mods-fabric = [
"fabric-api",
"fabric-kotlin",
"fabric-loader"
"fabric-loader",
"rs-fabric"
]
mods-include = [
"energy"
Expand Down
94 changes: 88 additions & 6 deletions src/client/kotlin/hiiragi283/ragium/client/RagiumClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ package hiiragi283.ragium.client

import hiiragi283.ragium.api.RagiumAPI
import hiiragi283.ragium.api.content.HTContent
import hiiragi283.ragium.api.extension.energyPercent
import hiiragi283.ragium.api.extension.getOrNull
import hiiragi283.ragium.api.extension.longText
import hiiragi283.ragium.api.machine.HTMachineKey
import hiiragi283.ragium.api.machine.HTMachinePacket
import hiiragi283.ragium.api.machine.HTMachineRegistry
import hiiragi283.ragium.api.machine.block.HTMachineBlock
import hiiragi283.ragium.api.machine.block.HTMachineBlockEntityBase
import hiiragi283.ragium.api.machine.property.HTMachinePropertyKeys
import hiiragi283.ragium.client.extension.getBlockEntity
import hiiragi283.ragium.client.extension.registerClientReceiver
import hiiragi283.ragium.client.gui.*
Expand All @@ -21,13 +27,16 @@ import net.fabricmc.api.EnvType
import net.fabricmc.api.Environment
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback
import net.fabricmc.fabric.api.client.model.loading.v1.BlockStateResolver
import net.fabricmc.fabric.api.client.model.loading.v1.ModelLoadingPlugin
import net.fabricmc.fabric.api.client.model.loading.v1.ModelModifier
import net.fabricmc.fabric.api.client.model.loading.v1.ModelResolver
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry
import net.fabricmc.fabric.api.client.render.fluid.v1.SimpleFluidRenderHandler
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry
import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry
import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant
import net.minecraft.block.Block
import net.minecraft.block.BlockState
Expand All @@ -37,15 +46,23 @@ import net.minecraft.client.gui.screen.ingame.HandledScreens
import net.minecraft.client.render.RenderLayer
import net.minecraft.client.render.block.entity.BlockEntityRendererFactories
import net.minecraft.client.render.entity.FlyingItemEntityRenderer
import net.minecraft.client.render.model.ModelRotation
import net.minecraft.client.render.model.UnbakedModel
import net.minecraft.client.render.model.json.ModelVariant
import net.minecraft.client.render.model.json.WeightedUnbakedModel
import net.minecraft.inventory.Inventory
import net.minecraft.item.Item
import net.minecraft.item.ItemStack
import net.minecraft.item.tooltip.TooltipType
import net.minecraft.registry.Registries
import net.minecraft.state.property.Properties
import net.minecraft.text.Text
import net.minecraft.util.Formatting
import net.minecraft.util.Identifier
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Direction
import net.minecraft.world.BlockRenderView
import team.reborn.energy.api.EnergyStorage

@Environment(EnvType.CLIENT)
object RagiumClient : ClientModInitializer {
Expand All @@ -58,7 +75,7 @@ object RagiumClient : ClientModInitializer {
registerEvents()
registerNetworks()

RagiumAPI.log { info("Ragium-Client initialized!") }
RagiumAPI.LOGGER.info("Ragium-Client initialized!")
}

// Blocks //
Expand All @@ -82,11 +99,11 @@ object RagiumClient : ClientModInitializer {
registerCutoutMipped(RagiumBlocks.ITEM_DISPLAY)
registerCutoutMipped(RagiumBlocks.POROUS_NETHERRACK)
// block entity renderer
BlockEntityRendererFactories.register(RagiumBlockEntityTypes.BEDROCK_MINER) { HTBedrockMinerBlockEntityRenderer }
BlockEntityRendererFactories.register(RagiumBlockEntityTypes.MANUAL_FORGE) { HTManualForgeBlockEntityRenderer }
BlockEntityRendererFactories.register(RagiumBlockEntityTypes.ITEM_DISPLAY) { HTItemDisplayBlockEntityRenderer }
BlockEntityRendererFactories.register(RagiumBlockEntityTypes.LARGE_PROCESSOR) { HTLargeProcessorBlockEntityRenderer }

registerMachineRenderer(RagiumBlockEntityTypes.BEDROCK_MINER)
registerMachineRenderer(RagiumBlockEntityTypes.BLAST_FURNACE)
registerMachineRenderer(RagiumBlockEntityTypes.DISTILLATION_TOWER)
registerMachineRenderer(RagiumBlockEntityTypes.FLUID_DRILL)
Expand Down Expand Up @@ -150,21 +167,73 @@ object RagiumClient : ClientModInitializer {
@JvmStatic
private fun registerScreens() {
HandledScreens.register(RagiumScreenHandlerTypes.CHEMICAL_MACHINE, ::HTChemicalMachineScreen)
HandledScreens.register(RagiumScreenHandlerTypes.FLUID_DRILL, ::HTFluidDrillScreen)
HandledScreens.register(RagiumScreenHandlerTypes.DISTILLATION_TOWER, ::HTDistillationTowerScreen)
HandledScreens.register(RagiumScreenHandlerTypes.LARGE_MACHINE, ::HTLargeMachineScreen)
HandledScreens.register(RagiumScreenHandlerTypes.SIMPLE_MACHINE, ::HTSimpleMachineScreen)
HandledScreens.register(RagiumScreenHandlerTypes.STEAM, ::HTSteamGeneratorScreen)
HandledScreens.register(RagiumScreenHandlerTypes.SMALL_MACHINE, ::HTSmallMachineScreen)
}

// Events //

@JvmStatic
private fun registerEvents() {
ModelLoadingPlugin.register { context: ModelLoadingPlugin.Context ->
// register block state resolver
RagiumAPI.getInstance().machineRegistry.entryMap.forEach { (_: HTMachineKey, entry: HTMachineRegistry.Entry) ->
entry.blocks.forEach { block: HTMachineBlock ->
context.registerBlockStateResolver(block) { context: BlockStateResolver.Context ->
Properties.HORIZONTAL_FACING.values.forEach { direction: Direction ->
RagiumBlockProperties.ACTIVE.values.forEach { isActive: Boolean ->
val state: BlockState = block.defaultState
.with(Properties.HORIZONTAL_FACING, direction)
.with(RagiumBlockProperties.ACTIVE, isActive)
val modelId: Identifier = when (isActive) {
true -> HTMachinePropertyKeys.ACTIVE_MODEL_ID
false -> HTMachinePropertyKeys.MODEL_ID
}.let(entry::getOrDefault)
val variant = ModelVariant(
modelId,
ModelRotation
.get(
0,
when (direction) {
Direction.SOUTH -> 180
Direction.WEST -> 270
Direction.EAST -> 90
else -> 0
},
).rotation,
false,
1,
)
val model = WeightedUnbakedModel(listOf(variant))
context.setModel(state, model)
}
}
}
}
}
// register item model resolver
context.resolveModel().register { context1: ModelResolver.Context ->
val id: Identifier = context1.id() ?: return@register null
if (id.namespace != RagiumAPI.MOD_ID) return@register null
val item: Item = Registries.ITEM.get(id.withPath { it.removePrefix("item/") })
item.components
.get(HTMachineKey.COMPONENT_TYPE)
?.let(HTMachineKey::entry)
?.getOrDefault(HTMachinePropertyKeys.MODEL_ID)
?.let { modelId: Identifier ->
when (modelId) {
RagiumAPI.id("block/dynamic_processor") -> HTProcessorMachineModel.INACTIVE
RagiumAPI.id("block/active_dynamic_processor") -> HTProcessorMachineModel.ACTIVE
else -> context1.getOrLoadModel(modelId)
}
}
}
context.modifyModelOnLoad().register onLoad@{ original: UnbakedModel, _: ModelModifier.OnLoad.Context ->
when {
RagiumAPI.id("block/dynamic_processor") in original.modelDependencies -> HTProcessorMachineModel
RagiumAPI.id("block/dynamic_processor") in original.modelDependencies -> HTProcessorMachineModel.INACTIVE
RagiumAPI.id("block/active_dynamic_processor") in original.modelDependencies -> HTProcessorMachineModel.ACTIVE
RagiumAPI.id("item/fluid_cube") in original.modelDependencies -> HTFluidCubeModel
else -> original
}
Expand All @@ -173,11 +242,24 @@ object RagiumClient : ClientModInitializer {
RagiumAPI.id("block/generator"),
RagiumAPI.id("block/solar_generator"),
)
RagiumAPI.LOGGER.info("Loaded runtime models!")
}
ItemTooltipCallback.EVENT.register(
RagiumAPI.id("description"),
) { stack: ItemStack, _: Item.TooltipContext, _: TooltipType, tooltips: MutableList<Text> ->
stack.get(RagiumComponentTypes.DESCRIPTION)?.let(tooltips::add)
val texts: List<Text> = stack.get(RagiumComponentTypes.DESCRIPTION)
?: ContainerItemContext.withConstant(stack).find(EnergyStorage.ITEM)?.let { storage: EnergyStorage ->
listOf(
Text.literal("- Stored Energy: ${longText(storage.amount).string} E (${storage.energyPercent} %)"),
)
}
?: listOf()
if (texts.isEmpty()) return@register
if (Screen.hasControlDown()) {
texts.map(Text::copy).map { it.formatted(Formatting.AQUA) }.forEach(tooltips::add)
} else {
tooltips.add(Text.translatable(RagiumTranslationKeys.PRESS_CTRL).formatted(Formatting.YELLOW))
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import net.minecraft.block.Block
import net.minecraft.client.MinecraftClient
import net.minecraft.client.render.OverlayTexture
import net.minecraft.client.render.VertexConsumerProvider
import net.minecraft.client.render.block.entity.BeaconBlockEntityRenderer
import net.minecraft.client.render.model.BakedModel
import net.minecraft.client.render.model.BakedModelManager
import net.minecraft.client.render.model.json.JsonUnbakedModel
Expand All @@ -22,6 +23,7 @@ import net.minecraft.fluid.Fluid
import net.minecraft.item.ItemStack
import net.minecraft.registry.Registries
import net.minecraft.resource.Resource
import net.minecraft.util.DyeColor
import net.minecraft.util.Identifier
import net.minecraft.util.math.Direction
import net.minecraft.util.math.RotationAxis
Expand Down Expand Up @@ -97,6 +99,29 @@ fun <T : HTMultiblockController> renderMultiblock(
}
}

fun renderBeam(
matrices: MatrixStack,
vertexConsumers: VertexConsumerProvider,
tickDelta: Float,
world: World,
color: DyeColor = DyeColor.WHITE,
textureId: Identifier = Identifier.ofVanilla("textures/entity/beacon_beam.png"),
) {
BeaconBlockEntityRenderer.renderBeam(
matrices,
vertexConsumers,
textureId,
tickDelta,
1f,
world.time,
-2,
2,
color.entityColor,
0.2f,
0.25f,
)
}

// Fluid //

fun Fluid.getSpriteAndColor(): Pair<Sprite, Int>? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,20 @@ import net.minecraft.client.gui.DrawContext
import net.minecraft.entity.player.PlayerInventory
import net.minecraft.text.Text
import net.minecraft.util.Identifier
import net.minecraft.util.math.MathHelper

@Environment(EnvType.CLIENT)
class HTChemicalMachineScreen(handler: HTChemicalMachineScreenHandler, inventory: PlayerInventory, title: Text) :
HTMachineScreenBase<HTChemicalMachineScreenHandler>(handler, inventory, title) {
companion object {
@JvmField
val TEXTURE: Identifier = RagiumAPI.id("textures/gui/chemical_machine.png")
}

override val texture: Identifier = RagiumAPI.id("textures/gui/chemical_machine.png")
override val fluidCache: Array<FluidVariant> = Array(4) { FluidVariant.blank() }
override val amountCache: LongArray = LongArray(4) { 0 }

override fun drawMouseoverTooltip(context: DrawContext, x: Int, y: Int) {
super.drawMouseoverTooltip(context, x, y)

drawFluidTooltip(context, fluidCache[0], amountCache[0], 2, 2, x, y)
drawFluidTooltip(context, fluidCache[1], amountCache[1], 3, 2, x, y)
drawFluidTooltip(context, fluidCache[2], amountCache[2], 5, 2, x, y)
drawFluidTooltip(context, fluidCache[3], amountCache[3], 6, 2, x, y)

drawEnergyTooltip(context, handler.player.world.registryKey, 4, 1, x, y)
}

override fun drawBackground(
Expand All @@ -39,23 +31,10 @@ class HTChemicalMachineScreen(handler: HTChemicalMachineScreenHandler, inventory
mouseX: Int,
mouseY: Int,
) {
context.drawTexture(TEXTURE, startX, startY, 0, 0, backgroundWidth, backgroundHeight)

super.drawBackground(context, delta, mouseX, mouseY)
drawFluid(context, fluidCache[0], 2, 2)
drawFluid(context, fluidCache[1], 3, 2)
drawFluid(context, fluidCache[2], 5, 2)
drawFluid(context, fluidCache[3], 6, 2)

context.drawGuiTexture(
RagiumAPI.id("progress_bar"),
16,
16,
0,
0,
startX + getSlotPosX(4),
startY + getSlotPosY(1),
MathHelper.ceil(handler.getProgress() * 16f),
16,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package hiiragi283.ragium.client.gui

import hiiragi283.ragium.api.RagiumAPI
import hiiragi283.ragium.common.screen.HTDistillationTowerScreenHandler
import net.fabricmc.api.EnvType
import net.fabricmc.api.Environment
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant
import net.minecraft.client.gui.DrawContext
import net.minecraft.entity.player.PlayerInventory
import net.minecraft.text.Text
import net.minecraft.util.Identifier

@Environment(EnvType.CLIENT)
class HTDistillationTowerScreen(handler: HTDistillationTowerScreenHandler, inventory: PlayerInventory, title: Text) :
HTMachineScreenBase<HTDistillationTowerScreenHandler>(handler, inventory, title) {
override val texture: Identifier = RagiumAPI.id("textures/gui/distillation_tower.png")
override val fluidCache: Array<FluidVariant> = Array(4) { FluidVariant.blank() }
override val amountCache: LongArray = LongArray(4) { 0 }

override fun drawMouseoverTooltip(context: DrawContext, x: Int, y: Int) {
super.drawMouseoverTooltip(context, x, y)
drawFluidTooltip(context, fluidCache[0], amountCache[0], 2, 2, x, y)
drawFluidTooltip(context, fluidCache[1], amountCache[1], 5, 2, x, y)
drawFluidTooltip(context, fluidCache[2], amountCache[2], 6, 2, x, y)
drawFluidTooltip(context, fluidCache[3], amountCache[3], 7, 2, x, y)
}

override fun drawBackground(
context: DrawContext,
delta: Float,
mouseX: Int,
mouseY: Int,
) {
super.drawBackground(context, delta, mouseX, mouseY)
drawFluid(context, fluidCache[0], 2, 2)
drawFluid(context, fluidCache[1], 5, 2)
drawFluid(context, fluidCache[2], 6, 2)
drawFluid(context, fluidCache[3], 7, 2)
}
}
Loading

0 comments on commit f7164e2

Please sign in to comment.