aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/generated/assets/potato-crime/lang/en_us.json5
-rw-r--r--src/main/generated/assets/potato-crime/models/item/contraband.json6
-rw-r--r--src/main/generated/data/potato-crime/advancements/recipes/tools/contraband.json43
-rw-r--r--src/main/generated/data/potato-crime/recipes/contraband.json25
-rw-r--r--src/main/java/moe/nea/potatocrime/mixin/ExampleMixin.java15
-rw-r--r--src/main/kotlin/moe/nea/potatocrime/PotatoCrime.kt19
-rw-r--r--src/main/kotlin/moe/nea/potatocrime/PotatoCrimeDataGenerator.kt68
-rw-r--r--src/main/kotlin/moe/nea/potatocrime/entity/PotatoGuard.kt3
-rw-r--r--src/main/kotlin/moe/nea/potatocrime/item/ContrabandItem.kt70
-rw-r--r--src/main/kotlin/moe/nea/potatocrime/registry/PotatoRegistry.kt37
-rw-r--r--src/main/kotlin/moe/nea/potatocrime/registry/PotatoTranslations.kt24
-rw-r--r--src/main/resources/assets/potato-crime/icon.pngbin0 -> 5913 bytes
-rw-r--r--src/main/resources/fabric.mod.json53
-rw-r--r--src/main/resources/potato-crime.mixins.json11
14 files changed, 379 insertions, 0 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
new file mode 100644
index 0000000..4a5dee4
--- /dev/null
+++ b/src/main/generated/assets/potato-crime/lang/en_us.json
@@ -0,0 +1,5 @@
+{
+ "item.potato-crime.contraband": "Contraband",
+ "potato-crime.text.fill-level": "Hidden carrots: %s/1000.",
+ "potato-crime.text.no-carrots": "No carrots to deposit."
+} \ No newline at end of file
diff --git a/src/main/generated/assets/potato-crime/models/item/contraband.json b/src/main/generated/assets/potato-crime/models/item/contraband.json
new file mode 100644
index 0000000..f5f420d
--- /dev/null
+++ b/src/main/generated/assets/potato-crime/models/item/contraband.json
@@ -0,0 +1,6 @@
+{
+ "parent": "minecraft:item/generated",
+ "textures": {
+ "layer0": "potato-crime:item/contraband"
+ }
+} \ No newline at end of file
diff --git a/src/main/generated/data/potato-crime/advancements/recipes/tools/contraband.json b/src/main/generated/data/potato-crime/advancements/recipes/tools/contraband.json
new file mode 100644
index 0000000..c13496b
--- /dev/null
+++ b/src/main/generated/data/potato-crime/advancements/recipes/tools/contraband.json
@@ -0,0 +1,43 @@
+{
+ "parent": "minecraft:recipes/root",
+ "criteria": {
+ "has_carrot": {
+ "conditions": {
+ "items": [
+ {
+ "items": "minecraft:carrot"
+ }
+ ]
+ },
+ "trigger": "minecraft:inventory_changed"
+ },
+ "has_paper": {
+ "conditions": {
+ "items": [
+ {
+ "items": "minecraft:paper"
+ }
+ ]
+ },
+ "trigger": "minecraft:inventory_changed"
+ },
+ "has_the_recipe": {
+ "conditions": {
+ "recipe": "potato-crime:contraband"
+ },
+ "trigger": "minecraft:recipe_unlocked"
+ }
+ },
+ "requirements": [
+ [
+ "has_the_recipe",
+ "has_paper",
+ "has_carrot"
+ ]
+ ],
+ "rewards": {
+ "recipes": [
+ "potato-crime:contraband"
+ ]
+ }
+} \ No newline at end of file
diff --git a/src/main/generated/data/potato-crime/recipes/contraband.json b/src/main/generated/data/potato-crime/recipes/contraband.json
new file mode 100644
index 0000000..2e9780c
--- /dev/null
+++ b/src/main/generated/data/potato-crime/recipes/contraband.json
@@ -0,0 +1,25 @@
+{
+ "type": "minecraft:crafting_shapeless",
+ "category": "equipment",
+ "ingredients": [
+ {
+ "item": "minecraft:paper"
+ },
+ {
+ "item": "minecraft:paper"
+ },
+ {
+ "item": "minecraft:paper"
+ },
+ {
+ "item": "minecraft:brown_dye"
+ },
+ {
+ "item": "minecraft:carrot"
+ }
+ ],
+ "result": {
+ "count": 1,
+ "id": "potato-crime:contraband"
+ }
+} \ No newline at end of file
diff --git a/src/main/java/moe/nea/potatocrime/mixin/ExampleMixin.java b/src/main/java/moe/nea/potatocrime/mixin/ExampleMixin.java
new file mode 100644
index 0000000..79e4299
--- /dev/null
+++ b/src/main/java/moe/nea/potatocrime/mixin/ExampleMixin.java
@@ -0,0 +1,15 @@
+package moe.nea.potatocrime.mixin;
+
+import net.minecraft.server.MinecraftServer;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+@Mixin(MinecraftServer.class)
+public class ExampleMixin {
+ @Inject(at = @At("HEAD"), method = "loadWorld")
+ private void init(CallbackInfo info) {
+ // This code is injected into the start of MinecraftServer.loadWorld()V
+ }
+} \ 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
new file mode 100644
index 0000000..a421e35
--- /dev/null
+++ b/src/main/kotlin/moe/nea/potatocrime/PotatoCrime.kt
@@ -0,0 +1,19 @@
+package moe.nea.potatocrime
+
+import moe.nea.potatocrime.registry.PotatoRegistry
+import net.fabricmc.api.ModInitializer
+import org.slf4j.LoggerFactory
+
+object PotatoCrime : ModInitializer {
+
+ val modId = "potato-crime"
+ private val logger = LoggerFactory.getLogger("potato-crime")
+
+ override fun onInitialize() {
+ // This code runs as soon as Minecraft is in a mod-load-ready state.
+ // However, some things (like resources) may still be uninitialized.
+ // Proceed with mild caution.
+ logger.info("Hello Fabric world!")
+ PotatoRegistry.registerAll()
+ }
+} \ 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
new file mode 100644
index 0000000..09c9469
--- /dev/null
+++ b/src/main/kotlin/moe/nea/potatocrime/PotatoCrimeDataGenerator.kt
@@ -0,0 +1,68 @@
+package moe.nea.potatocrime
+
+import moe.nea.potatocrime.registry.PotatoRegistry
+import moe.nea.potatocrime.registry.PotatoTranslations
+import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint
+import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator
+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.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.Items
+import net.minecraft.recipe.book.RecipeCategory
+import net.minecraft.registry.RegistryWrapper
+import java.util.concurrent.CompletableFuture
+
+class PotatoCrimeDataGenerator : DataGeneratorEntrypoint {
+ override fun onInitializeDataGenerator(fabricDataGenerator: FabricDataGenerator) {
+ val pack = fabricDataGenerator.createPack()
+ pack.addProvider(::NameProvider)
+ pack.addProvider(::RecipeProvider)
+ pack.addProvider(::DefaultModels)
+ }
+}
+
+class RecipeProvider(
+ output: FabricDataOutput?,
+ registriesFuture: CompletableFuture<RegistryWrapper.WrapperLookup>?
+) : FabricRecipeProvider(output, registriesFuture) {
+ override fun generate(exporter: RecipeExporter) {
+ ShapelessRecipeJsonBuilder.create(RecipeCategory.TOOLS, PotatoRegistry.contraband)
+ .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)
+ }
+}
+
+class DefaultModels(output: FabricDataOutput?) : FabricModelProvider(output) {
+ override fun generateBlockStateModels(blockStateModelGenerator: BlockStateModelGenerator) {
+
+ }
+
+ override fun generateItemModels(itemModelGenerator: ItemModelGenerator) {
+ itemModelGenerator.register(PotatoRegistry.contraband, Models.GENERATED)
+ }
+
+}
+
+
+class NameProvider(dataOutput: FabricDataOutput, registryLookup: CompletableFuture<RegistryWrapper.WrapperLookup>) :
+ FabricLanguageProvider(dataOutput, registryLookup) {
+ override fun generateTranslations(
+ registryLookup: RegistryWrapper.WrapperLookup,
+ translationBuilder: TranslationBuilder
+ ) {
+ translationBuilder.add(PotatoRegistry.contraband, "Contraband")
+ PotatoTranslations.allTranslations.forEach {
+ translationBuilder.add(it.translationKey, it.default)
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/potatocrime/entity/PotatoGuard.kt b/src/main/kotlin/moe/nea/potatocrime/entity/PotatoGuard.kt
new file mode 100644
index 0000000..b7282ea
--- /dev/null
+++ b/src/main/kotlin/moe/nea/potatocrime/entity/PotatoGuard.kt
@@ -0,0 +1,3 @@
+package moe.nea.potatocrime.entity
+
+import net.minecraft.entity.LivingEntity
diff --git a/src/main/kotlin/moe/nea/potatocrime/item/ContrabandItem.kt b/src/main/kotlin/moe/nea/potatocrime/item/ContrabandItem.kt
new file mode 100644
index 0000000..728d84a
--- /dev/null
+++ b/src/main/kotlin/moe/nea/potatocrime/item/ContrabandItem.kt
@@ -0,0 +1,70 @@
+package moe.nea.potatocrime.item
+
+import moe.nea.potatocrime.registry.PotatoRegistry
+import moe.nea.potatocrime.registry.PotatoTranslations
+import net.minecraft.client.item.TooltipContext
+import net.minecraft.entity.player.PlayerEntity
+import net.minecraft.item.Item
+import net.minecraft.item.ItemStack
+import net.minecraft.item.Items
+import net.minecraft.server.network.ServerPlayerEntity
+import net.minecraft.text.Text
+import net.minecraft.util.Formatting
+import net.minecraft.util.Hand
+import net.minecraft.util.TypedActionResult
+import net.minecraft.world.World
+
+class ContrabandItem : Item(
+ Settings().maxCount(1)
+) {
+
+ fun ItemStack.getContrabandCount(): Int {
+ return getOrDefault(PotatoRegistry.contrabandData, 0)
+ }
+
+ fun ItemStack.setContrabandCount(count: Int) {
+ set(PotatoRegistry.contrabandData, count)
+ }
+
+ fun dropCarrots(user: PlayerEntity, oldCount: Int): Int {
+ val carrotCount = oldCount.coerceAtMost(Items.CARROT.maxCount)
+ val stack = ItemStack(Items.CARROT, carrotCount)
+ if (user is ServerPlayerEntity)
+ user.dropItem(stack, false, true)
+ return oldCount - carrotCount
+ }
+
+ override fun appendTooltip(
+ stack: ItemStack,
+ world: World?,
+ tooltip: MutableList<Text>,
+ context: TooltipContext
+ ) {
+ val count = stack.getContrabandCount()
+ tooltip.add(
+ PotatoTranslations.contrabandFillText.format(count.toString()).styled { it.withColor(Formatting.DARK_GRAY) })
+ }
+
+ override fun use(world: World, user: PlayerEntity, hand: Hand): TypedActionResult<ItemStack> {
+ val stack = user.getStackInHand(hand)
+ if (user.isSneaking) {
+ val count = stack.getContrabandCount()
+ if (count <= 0)
+ return TypedActionResult.fail(stack)
+ val newCount = dropCarrots(user, count)
+ stack.setContrabandCount(newCount)
+ return TypedActionResult.success(stack)
+ } else {
+ val count = stack.getContrabandCount()
+ val carrotSlot = user.inventory.getSlotWithStack(ItemStack(Items.CARROT))
+ if (carrotSlot < 0) {
+ if (user is ServerPlayerEntity)
+ user.sendMessage(PotatoTranslations.noCarrotsToDeposit.format())
+ return TypedActionResult.fail(stack)
+ }
+ val removed = user.inventory.removeStack(carrotSlot, (1000 - count).coerceAtLeast(0))
+ stack.setContrabandCount(removed.count + count)
+ return TypedActionResult.pass(stack)
+ }
+ }
+}
diff --git a/src/main/kotlin/moe/nea/potatocrime/registry/PotatoRegistry.kt b/src/main/kotlin/moe/nea/potatocrime/registry/PotatoRegistry.kt
new file mode 100644
index 0000000..2e5fa5f
--- /dev/null
+++ b/src/main/kotlin/moe/nea/potatocrime/registry/PotatoRegistry.kt
@@ -0,0 +1,37 @@
+package moe.nea.potatocrime.registry
+
+import com.mojang.serialization.Codec
+import moe.nea.potatocrime.PotatoCrime
+import moe.nea.potatocrime.item.ContrabandItem
+import net.minecraft.component.DataComponentType
+import net.minecraft.item.Item
+import net.minecraft.network.codec.PacketCodecs
+import net.minecraft.registry.Registries
+import net.minecraft.registry.Registry
+import net.minecraft.util.Identifier
+
+object PotatoRegistry {
+ private val delayedRegistries = mutableListOf<() -> Unit>()
+ fun registerAll() {
+ delayedRegistries.forEach { it.invoke() }
+ }
+
+ private fun <U, T : U> register(registry: Registry<U>, name: String, t: T): T {
+ delayedRegistries.add {
+ Registry.register(registry, Identifier(PotatoCrime.modId, name), t)
+ }
+ return t
+ }
+
+ private fun <T : Item> item(name: String, t: T): T = register(Registries.ITEM, name, t)
+ private fun <T> dataComponent(name: String, block: (DataComponentType.Builder<T>) -> DataComponentType.Builder<T>) =
+ register(
+ Registries.DATA_COMPONENT_TYPE, name,
+ block(DataComponentType.builder()).build()
+ )
+
+ val contraband = item("contraband", ContrabandItem())
+ val contrabandData = dataComponent("contraband_data") {
+ it.codec(Codec.INT).packetCodec(PacketCodecs.VAR_INT)
+ }
+} \ 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
new file mode 100644
index 0000000..062c88d
--- /dev/null
+++ b/src/main/kotlin/moe/nea/potatocrime/registry/PotatoTranslations.kt
@@ -0,0 +1,24 @@
+package moe.nea.potatocrime.registry
+
+import net.minecraft.text.MutableText
+import net.minecraft.text.Text
+
+object PotatoTranslations {
+ val allTranslations = mutableListOf<PT>()
+
+ data class PT(val name: String, val default: String) {
+ fun format(vararg params: String): MutableText {
+ return Text.translatable(translationKey, *params)
+ }
+
+ val translationKey = "potato-crime.text.$name"
+
+ init {
+ allTranslations.add(this)
+ }
+ }
+
+ val noCarrotsToDeposit = PT("no-carrots", "No carrots to deposit.")
+ val contrabandFillText = PT("fill-level", "Hidden carrots: %s/1000.")
+
+} \ No newline at end of file
diff --git a/src/main/resources/assets/potato-crime/icon.png b/src/main/resources/assets/potato-crime/icon.png
new file mode 100644
index 0000000..2b4adc3
--- /dev/null
+++ b/src/main/resources/assets/potato-crime/icon.png
Binary files differ
diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json
new file mode 100644
index 0000000..c82fa1e
--- /dev/null
+++ b/src/main/resources/fabric.mod.json
@@ -0,0 +1,53 @@
+{
+ "schemaVersion": 1,
+ "id": "potato-crime",
+ "version": "${version}",
+ "name": "Potato Crime",
+ "description": "This is an example description! Tell everyone what your mod is about!",
+ "authors": [
+ "Me!"
+ ],
+ "contact": {
+ "homepage": "https://fabricmc.net/",
+ "sources": "https://github.com/FabricMC/fabric-example-mod"
+ },
+ "license": "CC0-1.0",
+ "icon": "assets/potato-crime/icon.png",
+ "environment": "*",
+ "entrypoints": {
+ "main": [
+ {
+ "value": "moe.nea.potatocrime.PotatoCrime",
+ "adapter": "kotlin"
+ }
+ ],
+ "client": [
+ {
+ "value": "moe.nea.potatocrime.PotatoCrimeClient",
+ "adapter": "kotlin"
+ }
+ ],
+ "fabric-datagen": [
+ {
+ "value": "moe.nea.potatocrime.PotatoCrimeDataGenerator",
+ "adapter": "kotlin"
+ }
+ ]
+ },
+ "mixins": [
+ "potato-crime.mixins.json",
+ {
+ "config": "potato-crime.client.mixins.json",
+ "environment": "client"
+ }
+ ],
+ "depends": {
+ "fabricloader": ">=0.15.9",
+ "minecraft": "~1.20.4",
+ "java": ">=17",
+ "fabric-language-kotlin": ">=1.9.23"
+ },
+ "suggests": {
+ "another-mod": "*"
+ }
+} \ No newline at end of file
diff --git a/src/main/resources/potato-crime.mixins.json b/src/main/resources/potato-crime.mixins.json
new file mode 100644
index 0000000..ba5b256
--- /dev/null
+++ b/src/main/resources/potato-crime.mixins.json
@@ -0,0 +1,11 @@
+{
+ "required": true,
+ "package": "moe.nea.potatocrime.mixin",
+ "compatibilityLevel": "JAVA_17",
+ "mixins": [
+ "ExampleMixin"
+ ],
+ "injectors": {
+ "defaultRequire": 1
+ }
+} \ No newline at end of file