From ff1cbb8644bb3107392c9e08aff48f5a0fa52fa9 Mon Sep 17 00:00:00 2001 From: YouHaveTrouble Date: Sun, 13 Nov 2022 15:26:18 +0100 Subject: [PATCH] rebrand and first mixin \o/ --- README.md | 10 ++----- .../moregamerules/MoreGameRules.java | 26 ++++++++++++++++++ .../moregamerules/mixin/MagmaBlockMixin.java | 26 ++++++++++++++++++ .../java/net/fabricmc/example/ExampleMod.java | 21 -------------- .../fabricmc/example/mixin/ExampleMixin.java | 16 ----------- .../assets/{modid => moregamerules}/icon.png | Bin .../assets/moregamerules/lang/en_us.json | 4 +++ src/main/resources/fabric.mod.json | 16 +++++------ ....mixins.json => moregamerules.mixins.json} | 10 +++---- 9 files changed, 71 insertions(+), 58 deletions(-) create mode 100644 src/main/java/me/youhavetrouble/moregamerules/MoreGameRules.java create mode 100644 src/main/java/me/youhavetrouble/moregamerules/mixin/MagmaBlockMixin.java delete mode 100644 src/main/java/net/fabricmc/example/ExampleMod.java delete mode 100644 src/main/java/net/fabricmc/example/mixin/ExampleMixin.java rename src/main/resources/assets/{modid => moregamerules}/icon.png (100%) create mode 100644 src/main/resources/assets/moregamerules/lang/en_us.json rename src/main/resources/{modid.mixins.json => moregamerules.mixins.json} (51%) diff --git a/README.md b/README.md index fd96346..bab792d 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,3 @@ -# Fabric Example Mod +# More Game Rules -## Setup - -For setup instructions please see the [fabric wiki page](https://fabricmc.net/wiki/tutorial:setup) that relates to the IDE that you are using. - -## License - -This template is available under the CC0 license. Feel free to learn from it and incorporate it in your own projects. +Self explanatory mod. Adds more game rules. diff --git a/src/main/java/me/youhavetrouble/moregamerules/MoreGameRules.java b/src/main/java/me/youhavetrouble/moregamerules/MoreGameRules.java new file mode 100644 index 0000000..2f3d83e --- /dev/null +++ b/src/main/java/me/youhavetrouble/moregamerules/MoreGameRules.java @@ -0,0 +1,26 @@ +package me.youhavetrouble.moregamerules; + +import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory; +import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry; +import net.minecraft.world.GameRules; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class MoreGameRules implements ModInitializer { + public static final Logger LOGGER = LoggerFactory.getLogger("moregamerules"); + + public static GameRules.Key MAGMA_BLOCK_DAMAGE; + + @Override + public void onInitialize() { + + MAGMA_BLOCK_DAMAGE = GameRuleRegistry.register( + "magmaBlockDamage", + GameRules.Category.MISC, + GameRuleFactory.createBooleanRule(true) + ); + + LOGGER.info("Finished loading up!"); + } +} diff --git a/src/main/java/me/youhavetrouble/moregamerules/mixin/MagmaBlockMixin.java b/src/main/java/me/youhavetrouble/moregamerules/mixin/MagmaBlockMixin.java new file mode 100644 index 0000000..8d3e735 --- /dev/null +++ b/src/main/java/me/youhavetrouble/moregamerules/mixin/MagmaBlockMixin.java @@ -0,0 +1,26 @@ +package me.youhavetrouble.moregamerules.mixin; + +import me.youhavetrouble.moregamerules.MoreGameRules; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.MagmaBlock; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +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(MagmaBlock.class) +public class MagmaBlockMixin extends Block { + + public MagmaBlockMixin(Settings settings) { + super(settings); + } + + @Inject(at = @At("HEAD"), method = "onSteppedOn", cancellable = true) + private void injectedOnSteppedOn(World world, BlockPos pos, BlockState state, Entity entity, CallbackInfo info) { + if (!world.getGameRules().getBoolean(MoreGameRules.MAGMA_BLOCK_DAMAGE)) info.cancel(); + } +} diff --git a/src/main/java/net/fabricmc/example/ExampleMod.java b/src/main/java/net/fabricmc/example/ExampleMod.java deleted file mode 100644 index a964189..0000000 --- a/src/main/java/net/fabricmc/example/ExampleMod.java +++ /dev/null @@ -1,21 +0,0 @@ -package net.fabricmc.example; - -import net.fabricmc.api.ModInitializer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ExampleMod implements ModInitializer { - // This logger is used to write text to the console and the log file. - // It is considered best practice to use your mod id as the logger's name. - // That way, it's clear which mod wrote info, warnings, and errors. - public static final Logger LOGGER = LoggerFactory.getLogger("modid"); - - @Override - public void 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!"); - } -} diff --git a/src/main/java/net/fabricmc/example/mixin/ExampleMixin.java b/src/main/java/net/fabricmc/example/mixin/ExampleMixin.java deleted file mode 100644 index 356cb38..0000000 --- a/src/main/java/net/fabricmc/example/mixin/ExampleMixin.java +++ /dev/null @@ -1,16 +0,0 @@ -package net.fabricmc.example.mixin; - -import net.fabricmc.example.ExampleMod; -import net.minecraft.client.gui.screen.TitleScreen; -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(TitleScreen.class) -public class ExampleMixin { - @Inject(at = @At("HEAD"), method = "init()V") - private void init(CallbackInfo info) { - ExampleMod.LOGGER.info("This line is printed by an example mod mixin!"); - } -} diff --git a/src/main/resources/assets/modid/icon.png b/src/main/resources/assets/moregamerules/icon.png similarity index 100% rename from src/main/resources/assets/modid/icon.png rename to src/main/resources/assets/moregamerules/icon.png diff --git a/src/main/resources/assets/moregamerules/lang/en_us.json b/src/main/resources/assets/moregamerules/lang/en_us.json new file mode 100644 index 0000000..026b7e7 --- /dev/null +++ b/src/main/resources/assets/moregamerules/lang/en_us.json @@ -0,0 +1,4 @@ +{ + "gamerule.magmaBlockDamage": "Magma block damage", + "gamerule.magmaBlockDamage.description": "Controls if magma blocks should do damage when stepped on" +} \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 3428658..913a946 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,16 +1,16 @@ { "schemaVersion": 1, - "id": "modid", + "id": "moregamerules", "version": "${version}", - "name": "Example Mod", - "description": "This is an example description! Tell everyone what your mod is about!", + "name": "More Game Rules", + "description": "More gamerules for easy gameplay customization", "authors": [ - "Me!" + "YouHaveTrouble" ], "contact": { - "homepage": "https://fabricmc.net/", - "sources": "https://github.com/FabricMC/fabric-example-mod" + "homepage": "https://youhavetrouble.me/", + "sources": "https://github.com/YouHaveTrouble/MoreGameRules" }, "license": "CC0-1.0", @@ -19,11 +19,11 @@ "environment": "*", "entrypoints": { "main": [ - "net.fabricmc.example.ExampleMod" + "me.youhavetrouble.moregamerules.MoreGameRules" ] }, "mixins": [ - "modid.mixins.json" + "moregamerules.mixins.json" ], "depends": { diff --git a/src/main/resources/modid.mixins.json b/src/main/resources/moregamerules.mixins.json similarity index 51% rename from src/main/resources/modid.mixins.json rename to src/main/resources/moregamerules.mixins.json index 7c42cb4..3ec2c17 100644 --- a/src/main/resources/modid.mixins.json +++ b/src/main/resources/moregamerules.mixins.json @@ -1,12 +1,12 @@ { "required": true, "minVersion": "0.8", - "package": "net.fabricmc.example.mixin", + "package": "me.youhavetrouble.moregamerules.mixin", "compatibilityLevel": "JAVA_17", - "mixins": [ - ], - "client": [ - "ExampleMixin" + "mixins": [], + "client": [], + "server": [ + "MagmaBlockMixin" ], "injectors": { "defaultRequire": 1