From 3a9195e347817cef6bdd5186ddfd1b449b46b05a Mon Sep 17 00:00:00 2001 From: Aleteoryx Date: Sun, 29 Dec 2024 23:07:53 -0500 Subject: [PATCH] a block! --- build.gradle | 4 +- build.sh | 3 ++ .../me/aleteoryx/mc/fedimc/ClientMod.java | 17 +++++++ .../java/me/aleteoryx/mc/fedimc/CoreMod.java | 19 +++++++- .../me/aleteoryx/mc/fedimc/ModBlocks.java | 44 ++++++++++++++++++ .../me/aleteoryx/mc/fedimc/ServerMod.java | 17 +++++++ .../assets/fedimc/blockstates/antenna.json | 5 ++ .../assets/{modid => fedimc}/icon.png | Bin .../assets/fedimc/items/antenna.json | 6 +++ .../resources/assets/fedimc/lang/en_us.json | 3 ++ .../assets/fedimc/models/block/antenna.json | 6 +++ .../assets/fedimc/textures/block/antenna.png | Bin 0 -> 636 bytes .../fedimc/loot_table/blocks/antenna.json | 19 ++++++++ .../tags/block/mineable/pickaxe.json | 4 ++ .../tags/block/needs_stone_tool.json | 4 ++ src/main/resources/fabric.mod.json | 4 +- 16 files changed, 150 insertions(+), 5 deletions(-) create mode 100755 build.sh create mode 100644 src/main/java/me/aleteoryx/mc/fedimc/ModBlocks.java create mode 100644 src/main/resources/assets/fedimc/blockstates/antenna.json rename src/main/resources/assets/{modid => fedimc}/icon.png (100%) create mode 100644 src/main/resources/assets/fedimc/items/antenna.json create mode 100644 src/main/resources/assets/fedimc/lang/en_us.json create mode 100644 src/main/resources/assets/fedimc/models/block/antenna.json create mode 100644 src/main/resources/assets/fedimc/textures/block/antenna.png create mode 100644 src/main/resources/data/fedimc/loot_table/blocks/antenna.json create mode 100644 src/main/resources/data/minecraft/tags/block/mineable/pickaxe.json create mode 100644 src/main/resources/data/minecraft/tags/block/needs_stone_tool.json diff --git a/build.gradle b/build.gradle index d6b6d0e..f7b3989 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.8.13' + id 'fabric-loom' version '1.9.2' id 'maven-publish' } @@ -22,7 +22,7 @@ loom { splitEnvironmentSourceSets() mods { - "me.aleteoryx.mc.fedimc" { + "fedimc" { sourceSet sourceSets.main sourceSet sourceSets.client } diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..07593fb --- /dev/null +++ b/build.sh @@ -0,0 +1,3 @@ +#!/bin/sh +./gradlew build +cp build/libs/fedimc-0.0.1.jar ~/.var/app/org.prismlauncher.PrismLauncher/data/PrismLauncher/instances/fedimc-dev/minecraft/mods/ diff --git a/src/client/java/me/aleteoryx/mc/fedimc/ClientMod.java b/src/client/java/me/aleteoryx/mc/fedimc/ClientMod.java index 8b2e262..fc532ba 100644 --- a/src/client/java/me/aleteoryx/mc/fedimc/ClientMod.java +++ b/src/client/java/me/aleteoryx/mc/fedimc/ClientMod.java @@ -1,10 +1,27 @@ package me.aleteoryx.mc.fedimc; import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; + +import net.minecraft.text.Text; +import net.minecraft.client.MinecraftClient; public class ClientMod implements ClientModInitializer { @Override public void onInitializeClient() { CoreMod.LOGGER.info("Hello Fabric client!"); + + ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> { + if (client.getServer() != null) { + chatMessage("This mod requires a dedicated server. Federation is not available in this environment."); + } + }); + } + + public static void chatMessage(String message) { + MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(CoreMod.prefixMessage(message)); + } + public static void chatMessage(Text message) { + MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(CoreMod.prefixMessage(message)); } } diff --git a/src/main/java/me/aleteoryx/mc/fedimc/CoreMod.java b/src/main/java/me/aleteoryx/mc/fedimc/CoreMod.java index bf52556..3aaa4fd 100644 --- a/src/main/java/me/aleteoryx/mc/fedimc/CoreMod.java +++ b/src/main/java/me/aleteoryx/mc/fedimc/CoreMod.java @@ -2,16 +2,33 @@ package me.aleteoryx.mc.fedimc; import net.fabricmc.api.ModInitializer; +import net.minecraft.text.Style; +import net.minecraft.text.Text; +import net.minecraft.text.MutableText; +import net.minecraft.text.PlainTextContent; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class CoreMod implements ModInitializer { - public static final String MOD_ID = "me.aleteoryx.mc.fedimc"; + public static final String MOD_ID = "fedimc"; public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); + public static final Text chatPrefix = MutableText.of(PlainTextContent.of("[FediMC] ")) + .setStyle(Style.EMPTY.withBold(true).withColor(0xCDCD00)); + @Override public void onInitialize() { LOGGER.info("Hello Fabric world!"); + + ModBlocks.init(); + } + + public static MutableText prefixMessage(Text contents) { + return MutableText.of(PlainTextContent.of("")).append(chatPrefix).append(contents); + } + public static MutableText prefixMessage(String contents) { + return MutableText.of(PlainTextContent.of("")).append(chatPrefix).append(contents); } } diff --git a/src/main/java/me/aleteoryx/mc/fedimc/ModBlocks.java b/src/main/java/me/aleteoryx/mc/fedimc/ModBlocks.java new file mode 100644 index 0000000..734e874 --- /dev/null +++ b/src/main/java/me/aleteoryx/mc/fedimc/ModBlocks.java @@ -0,0 +1,44 @@ +package me.aleteoryx.mc.fedimc; + +import java.util.function.Function; + +import net.minecraft.block.AbstractBlock; +import net.minecraft.block.Block; +import net.minecraft.item.BlockItem; +import net.minecraft.item.Item; +import net.minecraft.registry.Registry; +import net.minecraft.registry.Registries; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.sound.BlockSoundGroup; +import net.minecraft.util.Identifier; + +public class ModBlocks { + public static Block registerWith(Function ctor, String name, boolean shouldRegisterItem) { + Identifier id = Identifier.of(CoreMod.MOD_ID, name); + + AbstractBlock.Settings blocksettings = AbstractBlock.Settings.create() + .registryKey(RegistryKey.of(RegistryKeys.BLOCK, id)); + + Block block = ctor.apply(blocksettings); + + if (shouldRegisterItem) { + Item.Settings itemsettings = (new Item.Settings()) + .useBlockPrefixedTranslationKey() + .registryKey(RegistryKey.of(RegistryKeys.ITEM, id)); + BlockItem blockItem = new BlockItem(block, itemsettings); + Registry.register(Registries.ITEM, id, blockItem); + } + + return Registry.register(Registries.BLOCK, id, block); + } + + public static void init() {} + + + public static final Block ANTENNA = registerWith( + (settings) -> new Block(settings.hardness(1.5f)), + "antenna", + true + ); +} diff --git a/src/main/java/me/aleteoryx/mc/fedimc/ServerMod.java b/src/main/java/me/aleteoryx/mc/fedimc/ServerMod.java index 14311da..380136f 100644 --- a/src/main/java/me/aleteoryx/mc/fedimc/ServerMod.java +++ b/src/main/java/me/aleteoryx/mc/fedimc/ServerMod.java @@ -2,9 +2,26 @@ package me.aleteoryx.mc.fedimc; import net.fabricmc.api.DedicatedServerModInitializer; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.Text; + public class ServerMod implements DedicatedServerModInitializer { @Override public void onInitializeServer() { CoreMod.LOGGER.info("Hello Fabric server!"); } + + public static void chatMessage(MinecraftServer server, String message) { + server.sendMessage(CoreMod.prefixMessage(message)); + } + public static void chatMessage(MinecraftServer server, Text message) { + server.sendMessage(CoreMod.prefixMessage(message)); + } + public static void chatMessage(ServerPlayerEntity player, String message) { + player.sendMessage(CoreMod.prefixMessage(message)); + } + public static void chatMessage(ServerPlayerEntity player, Text message) { + player.sendMessage(CoreMod.prefixMessage(message)); + } } diff --git a/src/main/resources/assets/fedimc/blockstates/antenna.json b/src/main/resources/assets/fedimc/blockstates/antenna.json new file mode 100644 index 0000000..162b42b --- /dev/null +++ b/src/main/resources/assets/fedimc/blockstates/antenna.json @@ -0,0 +1,5 @@ +{ + "variants": { + "": { "model": "fedimc:block/antenna" } + } +} diff --git a/src/main/resources/assets/modid/icon.png b/src/main/resources/assets/fedimc/icon.png similarity index 100% rename from src/main/resources/assets/modid/icon.png rename to src/main/resources/assets/fedimc/icon.png diff --git a/src/main/resources/assets/fedimc/items/antenna.json b/src/main/resources/assets/fedimc/items/antenna.json new file mode 100644 index 0000000..d853242 --- /dev/null +++ b/src/main/resources/assets/fedimc/items/antenna.json @@ -0,0 +1,6 @@ +{ + "model": { + "type": "minecraft:model", + "model": "fedimc:block/antenna" + } +} diff --git a/src/main/resources/assets/fedimc/lang/en_us.json b/src/main/resources/assets/fedimc/lang/en_us.json new file mode 100644 index 0000000..0d25ff9 --- /dev/null +++ b/src/main/resources/assets/fedimc/lang/en_us.json @@ -0,0 +1,3 @@ +{ + "block.fedimc.antenna": "Fediverse Antenna" +} diff --git a/src/main/resources/assets/fedimc/models/block/antenna.json b/src/main/resources/assets/fedimc/models/block/antenna.json new file mode 100644 index 0000000..3631c03 --- /dev/null +++ b/src/main/resources/assets/fedimc/models/block/antenna.json @@ -0,0 +1,6 @@ +{ + "parent": "block/cube_all", + "textures": { + "all": "fedimc:block/antenna" + } +} diff --git a/src/main/resources/assets/fedimc/textures/block/antenna.png b/src/main/resources/assets/fedimc/textures/block/antenna.png new file mode 100644 index 0000000000000000000000000000000000000000..1264df8108f24b4f64279ee891710cba42dfe301 GIT binary patch literal 636 zcmV-?0)zdDP)EX>4Tx04R}tkv&MmKpe$iQ>7vm1v`j{WT;MdQ4z;lg(6f4wL+^7CYOFelZGV4 z#ZhoAIQX$xb#QUk)xlK|1V2EW9h?+hq{ROvg%&X$9QWhhy~o`Y(Cli&xt2Yx*+i**AGr4P0EeHDwRD+yRE34B3=jDM(W&6oB_L`lcK(cnkEddA+svaryvcsH@ZsaBv8W z7b$z)=iNP>z5RQp)!z@0aB{Mi;Bzzp000SaNLh0L04^f{04^f|c%?sf00007bV*G` z2j~nQ11AFlf1_jo000?uMObu0Z*6U5Zgc=ca%Ew3Wn>_CX>@2HM@dakSAh-}0001I zNkl