From 03440062eaf0039c591af9c93ecbf30a8193223f Mon Sep 17 00:00:00 2001 From: millennIumAMbiguity <37588844+millennIumAMbiguity@users.noreply.github.com> Date: Tue, 1 Oct 2024 21:06:36 +0200 Subject: [PATCH 1/2] WoodType compat --- .../valkyrienskies/eureka/block/IWoodType.kt | 13 +++++++++ .../eureka/block/ShipHelmBlock.kt | 2 +- .../valkyrienskies/eureka/block/WoodType.kt | 28 +++++++++---------- .../eureka/blockentity/renderer/WheelModel.kt | 5 ++-- .../eureka/fabric/EurekaModFabric.java | 4 +-- .../eureka/forge/EurekaModForge.kt | 7 +++-- 6 files changed, 37 insertions(+), 22 deletions(-) create mode 100644 common/src/main/kotlin/org/valkyrienskies/eureka/block/IWoodType.kt diff --git a/common/src/main/kotlin/org/valkyrienskies/eureka/block/IWoodType.kt b/common/src/main/kotlin/org/valkyrienskies/eureka/block/IWoodType.kt new file mode 100644 index 00000000..359ff27f --- /dev/null +++ b/common/src/main/kotlin/org/valkyrienskies/eureka/block/IWoodType.kt @@ -0,0 +1,13 @@ +package org.valkyrienskies.eureka.block + +import net.minecraft.world.level.block.Block + +public interface IWoodType { + + fun getWood(): Block + + fun getPlanks(): Block + + fun getSerializedName(): String + +} \ No newline at end of file diff --git a/common/src/main/kotlin/org/valkyrienskies/eureka/block/ShipHelmBlock.kt b/common/src/main/kotlin/org/valkyrienskies/eureka/block/ShipHelmBlock.kt index 613e8beb..40f465fb 100644 --- a/common/src/main/kotlin/org/valkyrienskies/eureka/block/ShipHelmBlock.kt +++ b/common/src/main/kotlin/org/valkyrienskies/eureka/block/ShipHelmBlock.kt @@ -34,7 +34,7 @@ import org.valkyrienskies.mod.common.ValkyrienSkiesMod import org.valkyrienskies.mod.common.getShipManagingPos import org.valkyrienskies.mod.common.getShipObjectManagingPos -class ShipHelmBlock(properties: Properties, val woodType: WoodType) : BaseEntityBlock(properties) { +class ShipHelmBlock(properties: Properties, val woodType: IWoodType) : BaseEntityBlock(properties) { val HELM_BASE = RotShapes.box(2.0, 0.0, 2.0, 14.0, 2.0, 14.0) val HELM_POLE = RotShapes.box(4.0, 2.0, 5.0, 12.0, 13.0, 13.0) diff --git a/common/src/main/kotlin/org/valkyrienskies/eureka/block/WoodType.kt b/common/src/main/kotlin/org/valkyrienskies/eureka/block/WoodType.kt index a5e02783..7ec4ca88 100644 --- a/common/src/main/kotlin/org/valkyrienskies/eureka/block/WoodType.kt +++ b/common/src/main/kotlin/org/valkyrienskies/eureka/block/WoodType.kt @@ -1,22 +1,22 @@ package org.valkyrienskies.eureka.block -import net.minecraft.resources.ResourceLocation import net.minecraft.util.StringRepresentable +import net.minecraft.world.level.block.Block +import net.minecraft.world.level.block.Blocks -// TODO mod compat +public enum class WoodType(final val logBlock: Block, final val plankBlock: Block) : StringRepresentable, IWoodType { + OAK(Blocks.OAK_LOG, Blocks.OAK_PLANKS), + SPRUCE(Blocks.SPRUCE_LOG, Blocks.SPRUCE_PLANKS), + BIRCH(Blocks.BIRCH_LOG, Blocks.BIRCH_PLANKS), + JUNGLE(Blocks.JUNGLE_LOG, Blocks.JUNGLE_PLANKS), + ACACIA(Blocks.ACACIA_LOG, Blocks.ACACIA_PLANKS), + DARK_OAK(Blocks.DARK_OAK_LOG, Blocks.DARK_OAK_PLANKS), + CRIMSON(Blocks.CRIMSON_STEM, Blocks.CRIMSON_PLANKS), + WARPED(Blocks.WARPED_STEM, Blocks.WARPED_PLANKS); -enum class WoodType(val resourceName: String) : StringRepresentable { - OAK("oak"), - SPRUCE("spruce"), - BIRCH("birch"), - JUNGLE("jungle"), - ACACIA("acacia"), - DARK_OAK("dark_oak"), - WARPED("warped"), - CRIMSON("crimson"); + override fun getSerializedName(): String = name.lowercase() - val textureLocationPlanks get() = ResourceLocation("minecraft:block/${resourceName}_planks") - val textureLocationLog get() = ResourceLocation("minecraft:block/${resourceName}_log") + override fun getWood(): Block = logBlock - override fun getSerializedName(): String = resourceName + override fun getPlanks(): Block = plankBlock } diff --git a/common/src/main/kotlin/org/valkyrienskies/eureka/blockentity/renderer/WheelModel.kt b/common/src/main/kotlin/org/valkyrienskies/eureka/blockentity/renderer/WheelModel.kt index bba00f17..644c969e 100644 --- a/common/src/main/kotlin/org/valkyrienskies/eureka/blockentity/renderer/WheelModel.kt +++ b/common/src/main/kotlin/org/valkyrienskies/eureka/blockentity/renderer/WheelModel.kt @@ -9,6 +9,7 @@ import net.minecraft.client.resources.model.BakedModel import net.minecraft.world.level.block.entity.BlockEntity import net.minecraft.world.level.block.state.StateHolder import net.minecraft.world.level.block.state.properties.EnumProperty +import org.valkyrienskies.eureka.block.IWoodType import org.valkyrienskies.eureka.block.ShipHelmBlock import org.valkyrienskies.eureka.block.WoodType import java.util.function.Function @@ -53,14 +54,14 @@ object WheelModels { matrixStack.popPose() } - fun setModelGetter(getter: Function) { + fun setModelGetter(getter: Function) { models.values.forEach { it.getter = getter::apply } } class WheelModel(type: WoodType) : StateHolder(WheelModels, ImmutableMap.of(property, type), null) { - var getter: (WoodType) -> BakedModel = { throw IllegalStateException("Getter not set") } + var getter: (IWoodType) -> BakedModel = { throw IllegalStateException("Getter not set") } val model by lazy { getter(type) } } diff --git a/fabric/src/main/java/org/valkyrienskies/eureka/fabric/EurekaModFabric.java b/fabric/src/main/java/org/valkyrienskies/eureka/fabric/EurekaModFabric.java index 10544db3..a40a380c 100644 --- a/fabric/src/main/java/org/valkyrienskies/eureka/fabric/EurekaModFabric.java +++ b/fabric/src/main/java/org/valkyrienskies/eureka/fabric/EurekaModFabric.java @@ -58,7 +58,7 @@ public void onInitializeClient() { for (final WoodType woodType : WoodType.values()) { out.accept(new ResourceLocation( EurekaMod.MOD_ID, - "block/" + woodType.getResourceName() + "_ship_helm_wheel" + "block/" + woodType.getSerializedName().toLowerCase() + "_ship_helm_wheel" )); } }); @@ -67,7 +67,7 @@ public void onInitializeClient() { BakedModelManagerHelper.getModel(Minecraft.getInstance().getModelManager(), new ResourceLocation( EurekaMod.MOD_ID, - "block/" + woodType.getResourceName() + "_ship_helm_wheel" + "block/" + woodType.getSerializedName().toLowerCase() + "_ship_helm_wheel" ))); } } diff --git a/forge/src/main/kotlin/org/valkyrienskies/eureka/forge/EurekaModForge.kt b/forge/src/main/kotlin/org/valkyrienskies/eureka/forge/EurekaModForge.kt index 1a83bba3..1cb71453 100644 --- a/forge/src/main/kotlin/org/valkyrienskies/eureka/forge/EurekaModForge.kt +++ b/forge/src/main/kotlin/org/valkyrienskies/eureka/forge/EurekaModForge.kt @@ -17,6 +17,7 @@ import org.valkyrienskies.eureka.EurekaConfig import org.valkyrienskies.eureka.EurekaMod import org.valkyrienskies.eureka.EurekaMod.init import org.valkyrienskies.eureka.EurekaMod.initClient +import org.valkyrienskies.eureka.block.IWoodType import org.valkyrienskies.eureka.block.WoodType import org.valkyrienskies.eureka.blockentity.renderer.ShipHelmBlockEntityRenderer import org.valkyrienskies.eureka.blockentity.renderer.WheelModels.setModelGetter @@ -66,13 +67,13 @@ class EurekaModForge { } happendClientSetup = true initClient() - setModelGetter { woodType: WoodType -> + setModelGetter { woodType: IWoodType -> ForgeModelBakery.instance()!! .bakedTopLevelModels .getOrDefault( ResourceLocation( EurekaMod.MOD_ID, - "block/" + woodType.resourceName + "_ship_helm_wheel" + "block/" + woodType.getSerializedName().lowercase() + "_ship_helm_wheel" ), Minecraft.getInstance().modelManager.missingModel ) @@ -91,7 +92,7 @@ class EurekaModForge { for (woodType in WoodType.values()) { ForgeModelBakery.addSpecialModel( ResourceLocation( - EurekaMod.MOD_ID, "block/" + woodType.resourceName + "_ship_helm_wheel" + EurekaMod.MOD_ID, "block/" + woodType.getSerializedName().lowercase() + "_ship_helm_wheel" ) ) } From 559c36fd2f7f6fff33377fc21780345f9258f163 Mon Sep 17 00:00:00 2001 From: millennIumAMbiguity <37588844+millennIumAMbiguity@users.noreply.github.com> Date: Mon, 28 Oct 2024 19:03:16 +0100 Subject: [PATCH 2/2] moved StringRepresentable into IWoodType and more --- .../org/valkyrienskies/eureka/block/IWoodType.kt | 6 ++---- .../org/valkyrienskies/eureka/block/WoodType.kt | 13 ++++++------- .../eureka/fabric/EurekaModFabric.java | 3 ++- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/common/src/main/kotlin/org/valkyrienskies/eureka/block/IWoodType.kt b/common/src/main/kotlin/org/valkyrienskies/eureka/block/IWoodType.kt index 359ff27f..d1d0f9a8 100644 --- a/common/src/main/kotlin/org/valkyrienskies/eureka/block/IWoodType.kt +++ b/common/src/main/kotlin/org/valkyrienskies/eureka/block/IWoodType.kt @@ -1,13 +1,11 @@ package org.valkyrienskies.eureka.block +import net.minecraft.util.StringRepresentable import net.minecraft.world.level.block.Block -public interface IWoodType { +public interface IWoodType : StringRepresentable { fun getWood(): Block fun getPlanks(): Block - - fun getSerializedName(): String - } \ No newline at end of file diff --git a/common/src/main/kotlin/org/valkyrienskies/eureka/block/WoodType.kt b/common/src/main/kotlin/org/valkyrienskies/eureka/block/WoodType.kt index 7ec4ca88..291ac6ae 100644 --- a/common/src/main/kotlin/org/valkyrienskies/eureka/block/WoodType.kt +++ b/common/src/main/kotlin/org/valkyrienskies/eureka/block/WoodType.kt @@ -1,17 +1,16 @@ package org.valkyrienskies.eureka.block -import net.minecraft.util.StringRepresentable import net.minecraft.world.level.block.Block import net.minecraft.world.level.block.Blocks -public enum class WoodType(final val logBlock: Block, final val plankBlock: Block) : StringRepresentable, IWoodType { - OAK(Blocks.OAK_LOG, Blocks.OAK_PLANKS), - SPRUCE(Blocks.SPRUCE_LOG, Blocks.SPRUCE_PLANKS), - BIRCH(Blocks.BIRCH_LOG, Blocks.BIRCH_PLANKS), - JUNGLE(Blocks.JUNGLE_LOG, Blocks.JUNGLE_PLANKS), +public enum class WoodType(final val logBlock: Block, final val plankBlock: Block) : IWoodType { ACACIA(Blocks.ACACIA_LOG, Blocks.ACACIA_PLANKS), - DARK_OAK(Blocks.DARK_OAK_LOG, Blocks.DARK_OAK_PLANKS), + BIRCH(Blocks.BIRCH_LOG, Blocks.BIRCH_PLANKS), CRIMSON(Blocks.CRIMSON_STEM, Blocks.CRIMSON_PLANKS), + DARK_OAK(Blocks.DARK_OAK_LOG, Blocks.DARK_OAK_PLANKS), + JUNGLE(Blocks.JUNGLE_LOG, Blocks.JUNGLE_PLANKS), + OAK(Blocks.OAK_LOG, Blocks.OAK_PLANKS), + SPRUCE(Blocks.SPRUCE_LOG, Blocks.SPRUCE_PLANKS), WARPED(Blocks.WARPED_STEM, Blocks.WARPED_PLANKS); override fun getSerializedName(): String = name.lowercase() diff --git a/fabric/src/main/java/org/valkyrienskies/eureka/fabric/EurekaModFabric.java b/fabric/src/main/java/org/valkyrienskies/eureka/fabric/EurekaModFabric.java index a40a380c..1fcd94f2 100644 --- a/fabric/src/main/java/org/valkyrienskies/eureka/fabric/EurekaModFabric.java +++ b/fabric/src/main/java/org/valkyrienskies/eureka/fabric/EurekaModFabric.java @@ -19,6 +19,7 @@ import org.valkyrienskies.eureka.EurekaBlockEntities; import org.valkyrienskies.eureka.EurekaConfig; import org.valkyrienskies.eureka.EurekaMod; +import org.valkyrienskies.eureka.block.IWoodType; import org.valkyrienskies.eureka.block.WoodType; import org.valkyrienskies.eureka.blockentity.renderer.ShipHelmBlockEntityRenderer; import org.valkyrienskies.eureka.blockentity.renderer.WheelModels; @@ -55,7 +56,7 @@ public void onInitializeClient() { ); ModelLoadingRegistry.INSTANCE.registerModelProvider((manager, out) -> { - for (final WoodType woodType : WoodType.values()) { + for (final IWoodType woodType : WoodType.getEntries()) { out.accept(new ResourceLocation( EurekaMod.MOD_ID, "block/" + woodType.getSerializedName().toLowerCase() + "_ship_helm_wheel"