Skip to content

Commit

Permalink
Reworked around Processor Screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiiragi283 committed Oct 19, 2024
1 parent 40685c6 commit 70aa686
Show file tree
Hide file tree
Showing 36 changed files with 619 additions and 209 deletions.
24 changes: 17 additions & 7 deletions src/client/kotlin/hiiragi283/ragium/client/RagiumClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ import hiiragi283.ragium.client.renderer.HTAlchemicalInfuserBlockEntityRenderer
import hiiragi283.ragium.client.renderer.HTItemDisplayBlockEntityRenderer
import hiiragi283.ragium.client.renderer.HTMetaMachineBlockEntityRenderer
import hiiragi283.ragium.client.renderer.HTOblivionCubeEntityRenderer
import hiiragi283.ragium.client.util.getBlockEntity
import hiiragi283.ragium.client.util.getMachineEntity
import hiiragi283.ragium.client.util.registerClient
import hiiragi283.ragium.client.util.registerClientReceiver
import hiiragi283.ragium.common.RagiumContents
import hiiragi283.ragium.common.init.*
import hiiragi283.ragium.common.machine.HTHeatGeneratorMachineEntity
import hiiragi283.ragium.common.machine.HTProcessorMachineEntity
import hiiragi283.ragium.common.network.HTFloatingItemPayload
import hiiragi283.ragium.common.network.HTInventoryPayload
import hiiragi283.ragium.common.network.HTMachineRecipePayload
import hiiragi283.ragium.common.network.HTOpenBackpackPayload
import io.wispforest.accessories.api.AccessoriesCapability
import me.shedaniel.rei.api.common.entry.EntryIngredient
Expand Down Expand Up @@ -154,7 +158,7 @@ object RagiumClient : ClientModInitializer, HTMachineTypeInitializer {
ColorProviderRegistry.ITEM.register({ _: ItemStack, _: Int -> fluid.color.rgb }, fluid)
}

ColorProviderRegistry.ITEM.register({ stack: ItemStack, tint: Int ->
ColorProviderRegistry.ITEM.register({ stack: ItemStack, _: Int ->
stack.get(RagiumComponentTypes.COLOR)?.entityColor ?: -1
}, RagiumContents.Misc.BACKPACK)
}
Expand Down Expand Up @@ -197,14 +201,20 @@ object RagiumClient : ClientModInitializer, HTMachineTypeInitializer {
context.client().gameRenderer.showFloatingItem(payload.stack)
}

RagiumNetworks.MACHINE_RECIPE.registerClientReceiver { payload: HTMachineRecipePayload, context: ClientPlayNetworking.Context ->
val (pos: BlockPos, recipe: HTMachineRecipe) = payload
(context.getMachineEntity(pos) as? HTProcessorMachineEntity)?.currentRecipe = recipe
RagiumAPI.log { info("Received recipe!") }
}

RagiumNetworks.SET_STACK.registerClientReceiver { payload: HTInventoryPayload.Setter, context: ClientPlayNetworking.Context ->
val (pos: BlockPos, slot: Int, stack: ItemStack) = payload
(context.player().world.getBlockEntity(pos) as? Inventory)?.setStack(slot, stack)
(context.getBlockEntity(pos) as? Inventory)?.setStack(slot, stack)
}

RagiumNetworks.REMOVE_STACK.registerClientReceiver { payload: HTInventoryPayload.Remover, context: ClientPlayNetworking.Context ->
val (pos: BlockPos, slot: Int) = payload
(context.player().world.getBlockEntity(pos) as? Inventory)?.removeStack(slot)
(context.getBlockEntity(pos) as? Inventory)?.removeStack(slot)
}
}

Expand All @@ -226,7 +236,7 @@ object RagiumClient : ClientModInitializer, HTMachineTypeInitializer {

if (!isModLoaded("roughlyenoughitems")) return
helper.modify(RagiumMachineTypes.FLUID_DRILL) {
set(INPUT_ENTRIES, { recipe: HTMachineRecipe ->
set(INPUT_ENTRIES) { recipe: HTMachineRecipe ->
recipe
.get(HTRecipeComponentTypes.BIOME)
?.let { biome: RegistryKey<Biome> ->
Expand All @@ -240,17 +250,17 @@ object RagiumClient : ClientModInitializer, HTMachineTypeInitializer {
}?.let(EntryIngredient::of)
?.let(::listOf)
?: emptyList()
})
}
}
helper.modify(RagiumMachineTypes.MOB_EXTRACTOR) {
set(INPUT_ENTRIES, { recipe: HTMachineRecipe ->
set(INPUT_ENTRIES) { recipe: HTMachineRecipe ->
recipe
.get(HTRecipeComponentTypes.ENTITY_TYPE)
?.let(SpawnEggItem::forEntity)
?.let(EntryIngredients::of)
?.let(::listOf)
?: emptyList()
})
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import hiiragi283.ragium.api.recipe.alchemy.HTInfusionRecipe
import hiiragi283.ragium.api.recipe.alchemy.HTTransformRecipe
import hiiragi283.ragium.api.recipe.machine.HTMachineRecipe
import hiiragi283.ragium.api.trade.HTTradeOfferRegistry
import hiiragi283.ragium.client.gui.HTProcessorScreen
import hiiragi283.ragium.client.integration.rei.category.HTAlchemyRecipeCategory
import hiiragi283.ragium.client.integration.rei.category.HTMachineRecipeCategory
import hiiragi283.ragium.client.integration.rei.category.HTTradeOfferCategory
Expand All @@ -19,11 +18,9 @@ import hiiragi283.ragium.common.init.RagiumEnchantments
import hiiragi283.ragium.common.init.RagiumMachineTypes
import hiiragi283.ragium.common.init.RagiumRecipeTypes
import hiiragi283.ragium.common.screen.HTProcessorScreenHandler
import me.shedaniel.math.Rectangle
import me.shedaniel.rei.api.client.plugins.REIClientPlugin
import me.shedaniel.rei.api.client.registry.category.CategoryRegistry
import me.shedaniel.rei.api.client.registry.display.DisplayRegistry
import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry
import me.shedaniel.rei.api.client.registry.transfer.TransferHandlerRegistry
import me.shedaniel.rei.api.client.registry.transfer.simple.SimpleTransferHandler
import me.shedaniel.rei.api.common.category.CategoryIdentifier
Expand Down Expand Up @@ -137,14 +134,14 @@ object RagiumREIClient : REIClientPlugin {
}*/
}

override fun registerScreens(registry: ScreenRegistry) {
/*override fun registerScreens(registry: ScreenRegistry) {
// Machines
registry.registerContainerClickArea(
Rectangle(5 + 18 * 4, 5 + 18 * 1, 18, 18),
HTProcessorScreen::class.java,
*getMachineIds().toTypedArray(),
*getMachineIds().toTypedArray(),
)
}
}*/

@Suppress("UnstableApiUsage")
override fun registerTransferHandlers(registry: TransferHandlerRegistry) {
Expand Down
27 changes: 8 additions & 19 deletions src/client/kotlin/hiiragi283/ragium/client/model/HTMachineModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import hiiragi283.ragium.api.extension.machineTier
import hiiragi283.ragium.api.extension.machineType
import hiiragi283.ragium.api.machine.HTMachineEntity
import hiiragi283.ragium.api.machine.HTMachinePropertyKeys
import hiiragi283.ragium.api.machine.HTMachineTier
import hiiragi283.ragium.api.machine.HTMachineType
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter
Expand Down Expand Up @@ -84,37 +83,27 @@ data object HTMachineModel : UnbakedModel, BakedModel {
context: RenderContext,
) {
val machineEntity: HTMachineEntity = blockView.getMachineEntity(pos) ?: return
val type: HTMachineType = machineEntity.machineType
val tier: HTMachineTier = machineEntity.tier
val frontDir: Direction =
blockView.getBlockState(pos).getOrDefault(Properties.HORIZONTAL_FACING, Direction.NORTH)
emitMachineQuads(frontDir, type, tier, machineEntity, context) {
it.emitBlockQuads(blockView, state, pos, randomSupplier, context)
}
emitMachineFront(frontDir, machineEntity.machineType, machineEntity, context)
}

override fun emitItemQuads(stack: ItemStack, randomSupplier: Supplier<Random>, context: RenderContext) {
emitMachineQuads(Direction.NORTH, stack.machineType, stack.machineTier, null, context) {
it.emitItemQuads(stack, randomSupplier, context)
}
MinecraftClient
.getInstance()
.bakedModelManager
.getModel(ModelIdentifier(stack.machineTier.getHull().id, ""))
.emitItemQuads(stack, randomSupplier, context)
emitMachineFront(Direction.NORTH, stack.machineType, null, context)
}

@JvmStatic
private fun emitMachineQuads(
private fun emitMachineFront(
frontDir: Direction,
type: HTMachineType,
tier: HTMachineTier,
machine: HTMachineEntity?,
context: RenderContext,
hullRenderer: (BakedModel) -> Unit,
) {
// render hull model
MinecraftClient
.getInstance()
.bakedModelManager
.getModel(ModelIdentifier(tier.getHull().id, ""))
?.apply(hullRenderer)
// render machine front
val frontId = SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, type.getFrontTex(machine))
this.frontSprite = this.textureGetter.apply(frontId)
val emitter: QuadEmitter = context.emitter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package hiiragi283.ragium.client.renderer

import hiiragi283.ragium.api.extension.getOrNull
import hiiragi283.ragium.api.machine.HTMachineTier
import hiiragi283.ragium.api.machine.HTMachineType
import hiiragi283.ragium.api.machine.multiblock.HTMultiblockController
import hiiragi283.ragium.client.util.renderMultiblock
import hiiragi283.ragium.common.block.entity.HTMetaMachineBlockEntity
import net.fabricmc.api.EnvType
import net.fabricmc.api.Environment
import net.minecraft.block.BlockState
import net.minecraft.client.MinecraftClient
import net.minecraft.client.render.RenderLayers
import net.minecraft.client.render.VertexConsumerProvider
import net.minecraft.client.render.block.entity.BlockEntityRenderer
import net.minecraft.client.util.math.MatrixStack
import net.minecraft.state.property.Properties
import net.minecraft.util.math.random.Random
import net.minecraft.world.World

@Environment(EnvType.CLIENT)
object HTMetaMachineBlockEntityRenderer : BlockEntityRenderer<HTMetaMachineBlockEntity> {
Expand All @@ -21,10 +28,24 @@ object HTMetaMachineBlockEntityRenderer : BlockEntityRenderer<HTMetaMachineBlock
light: Int,
overlay: Int,
) {
val world: World = entity.world ?: return
val (_: HTMachineType, tier: HTMachineTier) = entity.definition
// render hull model
val state: BlockState = tier.getHull().value.defaultState
MinecraftClient.getInstance().blockRenderManager.renderBlock(
state,
entity.pos,
world,
matrices,
vertexConsumers.getBuffer(RenderLayers.getBlockLayer(state)),
true,
Random.create(),
)
// render multiblock preview
(entity.machineEntity as? HTMultiblockController)?.let {
renderMultiblock(
it,
entity.world,
world,
entity.cachedState.getOrNull(Properties.HORIZONTAL_FACING),
matrices,
vertexConsumers,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package hiiragi283.ragium.client.util

import hiiragi283.ragium.api.extension.getMachineEntity
import hiiragi283.ragium.api.machine.HTMachineEntity
import hiiragi283.ragium.api.machine.multiblock.HTMultiblockController
import hiiragi283.ragium.client.renderer.HTMultiblockRenderer
import hiiragi283.ragium.common.fluid.HTFluidContent
Expand All @@ -9,16 +11,19 @@ import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler
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.networking.v1.PacketSender
import net.minecraft.block.entity.BlockEntity
import net.minecraft.client.MinecraftClient
import net.minecraft.client.network.ClientPlayerEntity
import net.minecraft.client.render.OverlayTexture
import net.minecraft.client.render.RenderLayer
import net.minecraft.client.render.VertexConsumerProvider
import net.minecraft.client.render.model.json.ModelTransformationMode
import net.minecraft.client.util.math.MatrixStack
import net.minecraft.client.world.ClientWorld
import net.minecraft.item.ItemStack
import net.minecraft.network.packet.CustomPayload
import net.minecraft.util.Identifier
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Direction
import net.minecraft.util.math.Vec3d
import net.minecraft.util.math.Vec3i
Expand Down Expand Up @@ -101,6 +106,13 @@ fun <T : CustomPayload> CustomPayload.Id<T>.registerClientReceiver(
}
}

val ClientPlayNetworking.Context.world: ClientWorld?
get() = client().world

fun ClientPlayNetworking.Context.getBlockEntity(pos: BlockPos): BlockEntity? = world?.getBlockEntity(pos)

fun ClientPlayNetworking.Context.getMachineEntity(pos: BlockPos): HTMachineEntity? = world?.getMachineEntity(pos)

// HTFluidContent //

fun HTFluidContent.registerClient(stillTex: Identifier, flowingTex: Identifier = stillTex, color: Int = -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ object RagiumLangProviders {
builder.add(RagiumContents.Misc.REMOVER_DYNAMITE, "Remover Dynamite")
builder.add(RagiumContents.Misc.SOAP_INGOT, "Soap Ingot")
builder.add(RagiumContents.Misc.SOLAR_PANEL, "Solar Panel")
builder.add(RagiumContents.Misc.TRADER_CATALOG, "Trader Catalog")

builder.add(HTCrafterHammerItem.Behavior.DEFAULT, "Hammer Module (Default)")
builder.add(HTCrafterHammerItem.Behavior.AXE, "Hammer Module (Axe)")
Expand Down Expand Up @@ -333,6 +334,7 @@ object RagiumLangProviders {
builder.add(RagiumContents.Misc.REMOVER_DYNAMITE, "削除用ダイナマイト")
builder.add(RagiumContents.Misc.SOAP_INGOT, "石鹸インゴット")
builder.add(RagiumContents.Misc.SOLAR_PANEL, "太陽光パネル")
builder.add(RagiumContents.Misc.TRADER_CATALOG, "行商人カタログ")

builder.add(HTCrafterHammerItem.Behavior.DEFAULT, "ハンマーモジュール(デフォルト)")
builder.add(HTCrafterHammerItem.Behavior.AXE, "ハンマーモジュール(アックス)")
Expand Down
1 change: 1 addition & 0 deletions src/main/generated/assets/ragium/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@
"item.ragium.sweet_berries_fluid_cube": "Fluid Cube (Sweet Berries)",
"item.ragium.sweet_potato": "Sweet Potato",
"item.ragium.tallow_fluid_cube": "Fluid Cube (Tallow)",
"item.ragium.trader_catalog": "Trader Catalog",
"item.ragium.trinitrotoluene_fluid_cube": "Fluid Cube (Trinitrotoluene)",
"item.ragium.water_fluid_cube": "Fluid Cube (Water)",
"itemGroup.ragium.item": "Ragium - Items",
Expand Down
1 change: 1 addition & 0 deletions src/main/generated/assets/ragium/lang/ja_jp.json
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@
"item.ragium.sweet_berries_fluid_cube": "液体キューブ(スイートベリー)",
"item.ragium.sweet_potato": "サツマイモ",
"item.ragium.tallow_fluid_cube": "液体キューブ(獣脂)",
"item.ragium.trader_catalog": "行商人カタログ",
"item.ragium.trinitrotoluene_fluid_cube": "液体キューブ(トリニトロトルエン)",
"item.ragium.water_fluid_cube": "液体キューブ(水)",
"itemGroup.ragium.item": "Ragium - アイテム",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"conditions": {
"items": [
{
"items": "ragium:water_fluid_cube"
"items": "ragium:ethylene_fluid_cube"
}
]
},
Expand All @@ -15,7 +15,7 @@
"conditions": {
"items": [
{
"items": "ragium:ethylene_fluid_cube"
"items": "ragium:water_fluid_cube"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"conditions": {
"items": [
{
"items": "ragium:water_fluid_cube"
"items": "ragium:methane_fluid_cube"
}
]
},
Expand All @@ -15,7 +15,7 @@
"conditions": {
"items": [
{
"items": "ragium:methane_fluid_cube"
"items": "ragium:water_fluid_cube"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"conditions": {
"items": [
{
"items": "ragium:fuel_fluid_cube"
"items": "#ragium:fluid_cubes/fuel"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
},
"inputs": [
{
"items": "ragium:water_fluid_cube"
"items": "ragium:ethylene_fluid_cube"
},
{
"items": "ragium:ethylene_fluid_cube"
"items": "ragium:water_fluid_cube"
}
],
"machine_type": "ragium:chemical_reactor",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
},
"inputs": [
{
"items": "ragium:water_fluid_cube"
"items": "ragium:methane_fluid_cube"
},
{
"items": "ragium:methane_fluid_cube"
"items": "ragium:water_fluid_cube"
}
],
"machine_type": "ragium:chemical_reactor",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"inputs": [
{
"count": 4,
"items": "ragium:fuel_fluid_cube"
"items": "#ragium:fluid_cubes/fuel"
},
{
"items": "ragium:nitric_acid_fluid_cube"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"values": [
"ragium:bio_fuel_fluid_cube",
"ragium:fuel_fluid_cube",
"ragium:aromatic_compounds_fluid_cube"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ fun BlockEntity.sendPacket(action: (ServerPlayerEntity) -> Unit) {
}
}

fun World.sendPacket(action: (ServerPlayerEntity) -> Unit) {
(this as? ServerWorld)?.let(PlayerLookup::world)?.firstOrNull()?.let(action)
}

fun World.sendPacketForPlayers(action: (ServerPlayerEntity) -> Unit) {
(this as? ServerWorld)?.let(PlayerLookup::world)?.forEach(action)
}
Expand Down
Loading

0 comments on commit 70aa686

Please sign in to comment.