aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-04-01 21:57:16 +0200
committerLinnea Gräf <nea@nea.moe>2024-04-01 21:57:16 +0200
commitab30c1128b42eed24d0decf9ecf9e6a2c98a79e2 (patch)
treee0b23161678b97c09e89fda00dfa5f3d7569238f /src
parent0fe5e487922a6ff50b9c415b9384157fbd64b2b5 (diff)
downloadpotato-crimes-ab30c1128b42eed24d0decf9ecf9e6a2c98a79e2.tar.gz
potato-crimes-ab30c1128b42eed24d0decf9ecf9e6a2c98a79e2.tar.bz2
potato-crimes-ab30c1128b42eed24d0decf9ecf9e6a2c98a79e2.zip
Add potato guard
Diffstat (limited to 'src')
-rw-r--r--src/client/kotlin/moe/nea/potatocrime/PotatoCrimeClient.kt16
-rw-r--r--src/client/kotlin/moe/nea/potatocrime/client/entity/PotatoGuardRenderer.kt95
-rw-r--r--src/client/resources/assets/potato-crime/textures/entity/potato_guard.pngbin0 -> 385 bytes
-rw-r--r--src/main/generated/assets/potato-crime/lang/en_us.json2
-rw-r--r--src/main/generated/data/potato-crime/tags/items/carrotish.json8
-rw-r--r--src/main/kotlin/moe/nea/potatocrime/PotatoCrime.kt3
-rw-r--r--src/main/kotlin/moe/nea/potatocrime/PotatoCrimeDataGenerator.kt18
-rw-r--r--src/main/kotlin/moe/nea/potatocrime/entity/PotatoGuard.kt50
-rw-r--r--src/main/kotlin/moe/nea/potatocrime/registry/PotatoRegistry.kt28
-rw-r--r--src/main/kotlin/moe/nea/potatocrime/registry/PotatoTranslations.kt1
10 files changed, 215 insertions, 6 deletions
diff --git a/src/client/kotlin/moe/nea/potatocrime/PotatoCrimeClient.kt b/src/client/kotlin/moe/nea/potatocrime/PotatoCrimeClient.kt
index b724800..baba5d2 100644
--- a/src/client/kotlin/moe/nea/potatocrime/PotatoCrimeClient.kt
+++ b/src/client/kotlin/moe/nea/potatocrime/PotatoCrimeClient.kt
@@ -1,9 +1,19 @@
package moe.nea.potatocrime
+import moe.nea.potatocrime.client.entity.PotatoGuardModel
+import moe.nea.potatocrime.client.entity.PotatoGuardRenderer
+import moe.nea.potatocrime.registry.PotatoRegistry
import net.fabricmc.api.ClientModInitializer
+import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry
+import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry
+
object PotatoCrimeClient : ClientModInitializer {
- override fun onInitializeClient() {
- // This entrypoint is suitable for setting up client-specific logic, such as rendering.
- }
+ override fun onInitializeClient() {
+ EntityRendererRegistry.register(PotatoRegistry.potatoGuard, ::PotatoGuardRenderer)
+ EntityModelLayerRegistry.registerModelLayer(
+ PotatoGuardRenderer.modelLayer,
+ PotatoGuardModel::getTexturedModelData
+ )
+ }
} \ No newline at end of file
diff --git a/src/client/kotlin/moe/nea/potatocrime/client/entity/PotatoGuardRenderer.kt b/src/client/kotlin/moe/nea/potatocrime/client/entity/PotatoGuardRenderer.kt
new file mode 100644
index 0000000..c22e2e0
--- /dev/null
+++ b/src/client/kotlin/moe/nea/potatocrime/client/entity/PotatoGuardRenderer.kt
@@ -0,0 +1,95 @@
+package moe.nea.potatocrime.client.entity
+
+import moe.nea.potatocrime.entity.PotatoGuardEntity
+import moe.nea.potatocrime.registry.PotatoRegistry
+import net.minecraft.client.model.*
+import net.minecraft.client.render.VertexConsumer
+import net.minecraft.client.render.entity.EntityRendererFactory
+import net.minecraft.client.render.entity.MobEntityRenderer
+import net.minecraft.client.render.entity.model.EntityModel
+import net.minecraft.client.render.entity.model.EntityModelLayer
+import net.minecraft.client.util.math.MatrixStack
+import net.minecraft.util.Identifier
+
+
+class PotatoGuardRenderer(context: EntityRendererFactory.Context) :
+ MobEntityRenderer<PotatoGuardEntity, PotatoGuardModel>(
+ context,
+ PotatoGuardModel(context.getPart(modelLayer)),
+ 0.5f
+ ) {
+ companion object {
+ val modelLayer = EntityModelLayer(PotatoRegistry.identifier("potato_guard"), "main")
+ }
+
+ override fun getTexture(entity: PotatoGuardEntity): Identifier {
+ return PotatoRegistry.identifier("textures/entity/potato_guard.png")
+ }
+}
+
+class PotatoGuardModel(val part: ModelPart) : EntityModel<PotatoGuardEntity>() {
+ val PotatoGuard = part.getChild("PotatoGuard")
+ val PotatoHead = part.getChild("PotatoHead")
+
+ companion object {
+ fun getTexturedModelData(): TexturedModelData {
+ val modelData = ModelData()
+ val modelPartData = modelData.root
+ val PotatoGuard = modelPartData.addChild(
+ "PotatoGuard",
+ ModelPartBuilder.create().uv(0, 37).cuboid(-7.0f, -21.5f, -7.0f, 14.0f, 21.0f, 14.0f, Dilation(0.0f))
+ .uv(0, 0).cuboid(-8.0f, 0.5f, -8.0f, 16.0f, 21.0f, 16.0f, Dilation(0.0f)),
+ ModelTransform.pivot(0.0f, 0.5f, 0.0f)
+ )
+
+ val PotatoHead = modelPartData.addChild(
+ "PotatoHead",
+ ModelPartBuilder.create().uv(56, 29).cuboid(-4.0f, -6.5f, -4.0f, 8.0f, 13.0f, 8.0f, Dilation(0.0f)),
+ ModelTransform.pivot(0.0f, -28.5f, 0.0f)
+ )
+
+ return TexturedModelData.of(modelData, 128, 128)
+
+ }
+ }
+
+ override fun render(
+ matrices: MatrixStack?,
+ vertices: VertexConsumer?,
+ light: Int,
+ overlay: Int,
+ red: Float,
+ green: Float,
+ blue: Float,
+ alpha: Float
+ ) {
+ listOf(PotatoGuard, PotatoHead).forEach {
+ it.render(matrices, vertices, light, overlay, red, green, blue, alpha)
+ }
+ }
+ fun lerpAngle(angleOne: Float, angleTwo: Float, magnitude: Float): Float {
+ var f = (magnitude - angleTwo) % 6.2831855f
+ if (f < -3.1415927f) {
+ f += 6.2831855f
+ }
+
+ if (f >= 3.1415927f) {
+ f -= 6.2831855f
+ }
+
+ return angleTwo + angleOne * f
+ }
+
+ override fun setAngles(
+ entity: PotatoGuardEntity?,
+ limbAngle: Float,
+ limbDistance: Float,
+ animationProgress: Float,
+ headYaw: Float,
+ headPitch: Float
+ ) {
+ PotatoHead.yaw = headYaw / 180 * Math.PI.toFloat()
+ PotatoHead.pitch = headPitch / 180 * Math.PI.toFloat()
+// PotatoGuard.setAngles(limbAngle, 0F, 0F)
+ }
+} \ No newline at end of file
diff --git a/src/client/resources/assets/potato-crime/textures/entity/potato_guard.png b/src/client/resources/assets/potato-crime/textures/entity/potato_guard.png
new file mode 100644
index 0000000..3cfa2f1
--- /dev/null
+++ b/src/client/resources/assets/potato-crime/textures/entity/potato_guard.png
Binary files differ
diff --git a/src/main/generated/assets/potato-crime/lang/en_us.json b/src/main/generated/assets/potato-crime/lang/en_us.json
index 4a5dee4..7a5c3e9 100644
--- a/src/main/generated/assets/potato-crime/lang/en_us.json
+++ b/src/main/generated/assets/potato-crime/lang/en_us.json
@@ -1,5 +1,7 @@
{
+ "entity.potato-crime.potato_guard": "Potato Guard",
"item.potato-crime.contraband": "Contraband",
"potato-crime.text.fill-level": "Hidden carrots: %s/1000.",
+ "potato-crime.text.item-group": "Potato Crimes",
"potato-crime.text.no-carrots": "No carrots to deposit."
} \ No newline at end of file
diff --git a/src/main/generated/data/potato-crime/tags/items/carrotish.json b/src/main/generated/data/potato-crime/tags/items/carrotish.json
new file mode 100644
index 0000000..d8737d8
--- /dev/null
+++ b/src/main/generated/data/potato-crime/tags/items/carrotish.json
@@ -0,0 +1,8 @@
+{
+ "values": [
+ "minecraft:carrot",
+ "minecraft:carrot_on_a_stick",
+ "minecraft:golden_carrot",
+ "minecraft:orange_dye"
+ ]
+} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/potatocrime/PotatoCrime.kt b/src/main/kotlin/moe/nea/potatocrime/PotatoCrime.kt
index a421e35..5d0cddc 100644
--- a/src/main/kotlin/moe/nea/potatocrime/PotatoCrime.kt
+++ b/src/main/kotlin/moe/nea/potatocrime/PotatoCrime.kt
@@ -1,7 +1,9 @@
package moe.nea.potatocrime
+import moe.nea.potatocrime.entity.PotatoGuardEntity
import moe.nea.potatocrime.registry.PotatoRegistry
import net.fabricmc.api.ModInitializer
+import net.fabricmc.fabric.api.`object`.builder.v1.entity.FabricDefaultAttributeRegistry
import org.slf4j.LoggerFactory
object PotatoCrime : ModInitializer {
@@ -15,5 +17,6 @@ object PotatoCrime : ModInitializer {
// Proceed with mild caution.
logger.info("Hello Fabric world!")
PotatoRegistry.registerAll()
+ FabricDefaultAttributeRegistry.register(PotatoRegistry.potatoGuard, PotatoGuardEntity.createMobAttributes())
}
} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/potatocrime/PotatoCrimeDataGenerator.kt b/src/main/kotlin/moe/nea/potatocrime/PotatoCrimeDataGenerator.kt
index 09c9469..3e87a49 100644
--- a/src/main/kotlin/moe/nea/potatocrime/PotatoCrimeDataGenerator.kt
+++ b/src/main/kotlin/moe/nea/potatocrime/PotatoCrimeDataGenerator.kt
@@ -8,13 +8,16 @@ import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput
import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider
import net.fabricmc.fabric.api.datagen.v1.provider.FabricModelProvider
import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider
+import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider
import net.minecraft.data.client.BlockStateModelGenerator
import net.minecraft.data.client.ItemModelGenerator
import net.minecraft.data.client.Models
import net.minecraft.data.server.recipe.RecipeExporter
import net.minecraft.data.server.recipe.ShapelessRecipeJsonBuilder
+import net.minecraft.item.Item
import net.minecraft.item.Items
import net.minecraft.recipe.book.RecipeCategory
+import net.minecraft.registry.RegistryKeys
import net.minecraft.registry.RegistryWrapper
import java.util.concurrent.CompletableFuture
@@ -24,6 +27,19 @@ class PotatoCrimeDataGenerator : DataGeneratorEntrypoint {
pack.addProvider(::NameProvider)
pack.addProvider(::RecipeProvider)
pack.addProvider(::DefaultModels)
+ pack.addProvider(::TagProvider)
+ }
+}
+
+class TagProvider(
+ output: FabricDataOutput?, registriesFuture: CompletableFuture<RegistryWrapper.WrapperLookup>?,
+) : FabricTagProvider<Item>(output, RegistryKeys.ITEM, registriesFuture) {
+ override fun configure(wrapperLookup: RegistryWrapper.WrapperLookup) {
+ getOrCreateTagBuilder(PotatoRegistry.carrotIshItems)
+ .add(Items.CARROT)
+ .add(Items.CARROT_ON_A_STICK)
+ .add(Items.GOLDEN_CARROT)
+ .add(Items.ORANGE_DYE)
}
}
@@ -36,7 +52,6 @@ class RecipeProvider(
.input(Items.PAPER, 3)
.input(Items.BROWN_DYE)
.input(Items.CARROT)
- .criterion(hasItem(Items.PAPER), conditionsFromItem(Items.PAPER))
.criterion(hasItem(Items.CARROT), conditionsFromItem(Items.CARROT))
.offerTo(exporter)
}
@@ -60,6 +75,7 @@ class NameProvider(dataOutput: FabricDataOutput, registryLookup: CompletableFutu
registryLookup: RegistryWrapper.WrapperLookup,
translationBuilder: TranslationBuilder
) {
+ translationBuilder.add(PotatoRegistry.potatoGuard, "Potato Guard")
translationBuilder.add(PotatoRegistry.contraband, "Contraband")
PotatoTranslations.allTranslations.forEach {
translationBuilder.add(it.translationKey, it.default)
diff --git a/src/main/kotlin/moe/nea/potatocrime/entity/PotatoGuard.kt b/src/main/kotlin/moe/nea/potatocrime/entity/PotatoGuard.kt
index b7282ea..33ea7d1 100644
--- a/src/main/kotlin/moe/nea/potatocrime/entity/PotatoGuard.kt
+++ b/src/main/kotlin/moe/nea/potatocrime/entity/PotatoGuard.kt
@@ -1,3 +1,51 @@
package moe.nea.potatocrime.entity
-import net.minecraft.entity.LivingEntity
+import moe.nea.potatocrime.registry.PotatoRegistry
+import net.minecraft.entity.EntityType
+import net.minecraft.entity.ai.goal.*
+import net.minecraft.entity.attribute.DefaultAttributeContainer
+import net.minecraft.entity.attribute.EntityAttributes
+import net.minecraft.entity.mob.HostileEntity
+import net.minecraft.entity.mob.PathAwareEntity
+import net.minecraft.entity.player.PlayerEntity
+import net.minecraft.world.World
+
+class PotatoGuardEntity(entityType: EntityType<out PotatoGuardEntity>, world: World?) :
+ PathAwareEntity(entityType, world) {
+ companion object {
+ fun createMobAttributes(): DefaultAttributeContainer.Builder {
+ return HostileEntity.createHostileAttributes()
+ .add(EntityAttributes.GENERIC_FOLLOW_RANGE, 35.0)
+ .add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.4)
+ .add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 10.0)
+ .add(EntityAttributes.GENERIC_ARMOR, 4.0)
+ .add(EntityAttributes.GENERIC_MAX_HEALTH, 40.0)
+ }
+ }
+
+
+ override fun initGoals() {
+ goalSelector.add(3, MeleeAttackGoal(this, 1.0, false))
+ goalSelector.add(8, LookAroundGoal(this))
+ goalSelector.add(7, WanderAroundFarGoal(this, 1.0))
+ goalSelector.add(6, object : Goal() {
+ override fun canStart(): Boolean {
+ return this@PotatoGuardEntity.target == null && this@PotatoGuardEntity.getRandom().nextFloat() < 0.01
+ }
+ })
+ targetSelector.add(
+ 1,
+ ActiveTargetGoal(
+ this,
+ PlayerEntity::class.java,
+ true
+ ) { player ->
+ (player as PlayerEntity)
+ .inventory
+ .getMatchingStacks { it.isIn(PotatoRegistry.carrotIshItems) }
+ .isNotEmpty()
+ }
+ )
+ }
+
+}
diff --git a/src/main/kotlin/moe/nea/potatocrime/registry/PotatoRegistry.kt b/src/main/kotlin/moe/nea/potatocrime/registry/PotatoRegistry.kt
index 2e5fa5f..53944f3 100644
--- a/src/main/kotlin/moe/nea/potatocrime/registry/PotatoRegistry.kt
+++ b/src/main/kotlin/moe/nea/potatocrime/registry/PotatoRegistry.kt
@@ -2,16 +2,25 @@ package moe.nea.potatocrime.registry
import com.mojang.serialization.Codec
import moe.nea.potatocrime.PotatoCrime
+import moe.nea.potatocrime.entity.PotatoGuardEntity
import moe.nea.potatocrime.item.ContrabandItem
+import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup
+import net.fabricmc.fabric.api.`object`.builder.v1.entity.FabricEntityTypeBuilder
import net.minecraft.component.DataComponentType
+import net.minecraft.entity.EntityDimensions
+import net.minecraft.entity.SpawnGroup
import net.minecraft.item.Item
+import net.minecraft.item.ItemStack
import net.minecraft.network.codec.PacketCodecs
import net.minecraft.registry.Registries
import net.minecraft.registry.Registry
+import net.minecraft.registry.RegistryKeys
+import net.minecraft.registry.tag.TagKey
import net.minecraft.util.Identifier
object PotatoRegistry {
private val delayedRegistries = mutableListOf<() -> Unit>()
+ private val items = mutableListOf<Item>()
fun registerAll() {
delayedRegistries.forEach { it.invoke() }
}
@@ -23,15 +32,32 @@ object PotatoRegistry {
return t
}
- private fun <T : Item> item(name: String, t: T): T = register(Registries.ITEM, name, t)
+ private fun <T : Item> item(name: String, t: T): T = register(Registries.ITEM, name, t).also(items::add)
private fun <T> dataComponent(name: String, block: (DataComponentType.Builder<T>) -> DataComponentType.Builder<T>) =
register(
Registries.DATA_COMPONENT_TYPE, name,
block(DataComponentType.builder()).build()
)
+ fun identifier(name: String) = Identifier(PotatoCrime.modId, name)
+
+ val group = register(Registries.ITEM_GROUP, "default_group", FabricItemGroup.builder()
+ .icon { ItemStack(contraband) }
+ .displayName(PotatoTranslations.itemGroup.format())
+ .entries { _, entries ->
+ items.forEach(entries::add)
+ }
+ .build())
+ val carrotIshItems = TagKey.of(RegistryKeys.ITEM, identifier("carrotish"))
val contraband = item("contraband", ContrabandItem())
val contrabandData = dataComponent("contraband_data") {
it.codec(Codec.INT).packetCodec(PacketCodecs.VAR_INT)
}
+ val potatoGuard = register(
+ Registries.ENTITY_TYPE, "potato_guard",
+ FabricEntityTypeBuilder.create(SpawnGroup.CREATURE, ::PotatoGuardEntity)
+ .dimensions(EntityDimensions.fixed(1f, 3f))
+ .build()
+ )
+
} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/potatocrime/registry/PotatoTranslations.kt b/src/main/kotlin/moe/nea/potatocrime/registry/PotatoTranslations.kt
index 062c88d..8d7fd19 100644
--- a/src/main/kotlin/moe/nea/potatocrime/registry/PotatoTranslations.kt
+++ b/src/main/kotlin/moe/nea/potatocrime/registry/PotatoTranslations.kt
@@ -19,6 +19,7 @@ object PotatoTranslations {
}
val noCarrotsToDeposit = PT("no-carrots", "No carrots to deposit.")
+ val itemGroup = PT("item-group", "Potato Crimes")
val contrabandFillText = PT("fill-level", "Hidden carrots: %s/1000.")
} \ No newline at end of file