Skip to content

Commit

Permalink
WoodType compat (#410)
Browse files Browse the repository at this point in the history
* WoodType compat

* moved StringRepresentable into IWoodType and more
  • Loading branch information
millennIumAMbiguity authored Oct 29, 2024
1 parent 7caa63d commit 42c5a56
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.valkyrienskies.eureka.block

import net.minecraft.util.StringRepresentable
import net.minecraft.world.level.block.Block

public interface IWoodType : StringRepresentable {

fun getWood(): Block

fun getPlanks(): Block
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
29 changes: 14 additions & 15 deletions common/src/main/kotlin/org/valkyrienskies/eureka/block/WoodType.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
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) : IWoodType {
ACACIA(Blocks.ACACIA_LOG, Blocks.ACACIA_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);

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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,14 +54,14 @@ object WheelModels {
matrixStack.popPose()
}

fun setModelGetter(getter: Function<WoodType, BakedModel>) {
fun setModelGetter(getter: Function<IWoodType, BakedModel>) {
models.values.forEach { it.getter = getter::apply }
}

class WheelModel(type: WoodType) :
StateHolder<WheelModels, WheelModel>(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) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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;
Expand Down Expand Up @@ -54,10 +55,10 @@ public void onInitializeClient() {
);

ModelLoadingRegistry.INSTANCE.registerModelProvider((manager, out) -> {
for (final WoodType woodType : WoodType.getEntries()) {
for (final IWoodType woodType : WoodType.getEntries()) {
out.accept(new ResourceLocation(
EurekaMod.MOD_ID,
"block/" + woodType.getResourceName() + "_ship_helm_wheel"
"block/" + woodType.getSerializedName().toLowerCase() + "_ship_helm_wheel"
));
}
});
Expand All @@ -66,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"
)));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,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
Expand Down Expand Up @@ -65,13 +66,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
)
Expand All @@ -90,7 +91,7 @@ class EurekaModForge {
for (woodType in WoodType.entries) {
ForgeModelBakery.addSpecialModel(
ResourceLocation(
EurekaMod.MOD_ID, "block/" + woodType.resourceName + "_ship_helm_wheel"
EurekaMod.MOD_ID, "block/" + woodType.getSerializedName().lowercase() + "_ship_helm_wheel"
)
)
}
Expand Down

0 comments on commit 42c5a56

Please sign in to comment.