aboutsummaryrefslogtreecommitdiff
path: root/src/main
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/main
parent0fe5e487922a6ff50b9c415b9384157fbd64b2b5 (diff)
downloadpotato-crimes-ab30c1128b42eed24d0decf9ecf9e6a2c98a79e2.tar.gz
potato-crimes-ab30c1128b42eed24d0decf9ecf9e6a2c98a79e2.tar.bz2
potato-crimes-ab30c1128b42eed24d0decf9ecf9e6a2c98a79e2.zip
Add potato guard
Diffstat (limited to 'src/main')
-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
7 files changed, 107 insertions, 3 deletions
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