diff --git a/README.md b/README.md index fd96346..37a458c 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,7 @@ -# Fabric Example Mod +# Carpet SLS Addition -## Setup +This is an extension of the [Carpet Mod](https://github.com/gnembon/fabric-carpet). -For setup instructions please see the [fabric wiki page](https://fabricmc.net/wiki/tutorial:setup) that relates to the IDE that you are using. +## StarLight Server -## License - -This template is available under the CC0 license. Feel free to learn from it and incorporate it in your own projects. +[Homepage](https://www.starlight.cool/) \ No newline at end of file diff --git a/build.gradle b/build.gradle index 6d30805..c67e0f3 100644 --- a/build.gradle +++ b/build.gradle @@ -11,11 +11,15 @@ version = project.mod_version group = project.maven_group repositories { - // Add repositories to retrieve artifacts from in here. - // You should only use this when depending on other mods because - // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. - // See https://docs.gradle.org/current/userguide/declaring_repositories.html - // for more information about repositories. + maven { + url 'https://masa.dy.fi/maven' + } + maven { + url 'https://jitpack.io' + } + maven { + url 'https://www.cursemaven.com' + } } dependencies { @@ -24,13 +28,11 @@ dependencies { mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + // carpet + modImplementation "carpet:fabric-carpet:${project.carpet_core_version}" + // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - - // Uncomment the following line to enable the deprecated Fabric API modules. - // These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time. - - // modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}" } processResources { diff --git a/gradle.properties b/gradle.properties index 93161f4..3b3167c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,9 +8,10 @@ org.gradle.jvmargs=-Xmx1G loader_version=0.14.9 # Mod Properties - mod_version = 1.0.0 - maven_group = com.example - archives_base_name = fabric-example-mod + mod_version = 0.1 + maven_group = com.github.zly2006 + archives_base_name = carpet-sls-addition # Dependencies fabric_version=0.60.0+1.19.2 + carpet_core_version=1.19.2-1.4.84+v221018 diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/SLSCarpetSettings.java b/src/main/java/com/github/zly2006/carpetslsaddition/SLSCarpetSettings.java new file mode 100644 index 0000000..18a5cb6 --- /dev/null +++ b/src/main/java/com/github/zly2006/carpetslsaddition/SLSCarpetSettings.java @@ -0,0 +1,10 @@ +package com.github.zly2006.carpetslsaddition; + +import carpet.api.settings.Rule; + +import static com.github.zly2006.carpetslsaddition.ServerMain.*; + +public class SLSCarpetSettings { + @Rule(categories = {CARPET_ID}) + public static boolean obtainableReinforcedDeepSlate = false; +} diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/ServerMain.java b/src/main/java/com/github/zly2006/carpetslsaddition/ServerMain.java new file mode 100644 index 0000000..d8deebe --- /dev/null +++ b/src/main/java/com/github/zly2006/carpetslsaddition/ServerMain.java @@ -0,0 +1,67 @@ +package com.github.zly2006.carpetslsaddition; + +import carpet.CarpetExtension; +import carpet.CarpetServer; +import carpet.api.settings.*; +import com.google.common.collect.MapMaker; +import com.google.common.collect.Maps; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; +import net.fabricmc.loader.api.FabricLoader; +import net.fabricmc.loader.api.Version; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.Text; +import org.spongepowered.asm.mixin.injection.struct.InjectorGroupInfo; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class ServerMain implements ModInitializer, CarpetExtension { + public static final String MOD_ID = "carpet-sls-addition"; + public static final String MOD_NAME = "Carpet SLS Addition"; + public static final String CARPET_ID = "slsaddition"; + static final Gson GSON = new Gson(); + public static final Version MOD_VERSION = FabricLoader.getInstance().getModContainer(MOD_ID).get().getMetadata().getVersion(); + public static ServerMain INSTANCE; + MinecraftServer server; + + @Override + public void onInitialize() { + INSTANCE = this; + CarpetServer.manageExtension(this); + } + + @Override + public void onServerLoaded(MinecraftServer server) { + this.server = server; + CarpetServer.settingsManager.parseSettingsClass(SLSCarpetSettings.class); + } + + @Override + public Map canHasTranslations(String lang) { + Map translation = Maps.newHashMap(); + String jsonFile; + try (InputStream stream = ServerMain.class.getResourceAsStream("/assets/slsaddition/lang/%s.json".formatted(lang))) { + jsonFile = new String(stream.readAllBytes()); + } catch (IOException ignored) { + try (InputStream stream = ServerMain.class.getResourceAsStream("/assets/slsaddition/lang/%s.json".formatted("en_us"))) { + jsonFile = new String(stream.readAllBytes()); + } catch (IOException e) { + return translation; + } + } + GSON.fromJson(jsonFile, JsonObject.class).entrySet().stream() + .filter(entry -> entry.getKey().startsWith("carpet.rule.")) + .filter(entry -> entry.getValue().isJsonPrimitive()) + .map(entry -> Map.entry(entry.getKey(), entry.getValue().getAsString())) + .forEach(entry -> translation.put(entry.getKey(), entry.getValue())); + return translation; + } +} diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/mixin/MixinFallingBlockEntity.java b/src/main/java/com/github/zly2006/carpetslsaddition/mixin/MixinFallingBlockEntity.java new file mode 100644 index 0000000..fcc586f --- /dev/null +++ b/src/main/java/com/github/zly2006/carpetslsaddition/mixin/MixinFallingBlockEntity.java @@ -0,0 +1,19 @@ +package com.github.zly2006.carpetslsaddition.mixin; + +import net.minecraft.entity.FallingBlockEntity; +import net.minecraft.entity.damage.DamageSource; +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.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import java.util.function.Predicate; + +@Mixin(FallingBlockEntity.class) +public class MixinFallingBlockEntity { + @Inject(method = "handleFallDamage", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getOtherEntities(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/Box;Ljava/util/function/Predicate;)Ljava/util/List;"), locals = LocalCapture.CAPTURE_FAILSOFT) + private void handleFallDamage(float fallDistance, float damageMultiplier, DamageSource damageSource, CallbackInfoReturnable cir, int i, Predicate predicate, DamageSource damageSource2, float f) { + + } +} diff --git a/src/main/java/com/github/zly2006/carpetslsaddition/mixin/MixinItemEntity.java b/src/main/java/com/github/zly2006/carpetslsaddition/mixin/MixinItemEntity.java new file mode 100644 index 0000000..b8004ed --- /dev/null +++ b/src/main/java/com/github/zly2006/carpetslsaddition/mixin/MixinItemEntity.java @@ -0,0 +1,32 @@ +package com.github.zly2006.carpetslsaddition.mixin; + +import com.github.zly2006.carpetslsaddition.SLSCarpetSettings; +import net.minecraft.entity.ItemEntity; +import net.minecraft.entity.damage.DamageSource; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(ItemEntity.class) +public abstract class MixinItemEntity { + @Shadow + public abstract ItemStack getStack(); + + @Shadow + public abstract void setStack(ItemStack stack); + + @Inject(method = "damage", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/ItemEntity;discard()V"), cancellable = true) + private void damage(DamageSource source, float amount, CallbackInfoReturnable cir) { + if (source == DamageSource.ANVIL && SLSCarpetSettings.obtainableReinforcedDeepSlate) { + if ((getStack().isOf(Items.DEEPSLATE) || getStack().isOf(Items.COBBLED_DEEPSLATE)) + && getStack().getCount() == 64) { + setStack(new ItemStack(Items.REINFORCED_DEEPSLATE)); + cir.setReturnValue(true); + } + } + } +} 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/slsaddition/icon.png similarity index 100% rename from src/main/resources/assets/modid/icon.png rename to src/main/resources/assets/slsaddition/icon.png diff --git a/src/main/resources/assets/slsaddition/lang/en_us.json b/src/main/resources/assets/slsaddition/lang/en_us.json new file mode 100644 index 0000000..eb22787 --- /dev/null +++ b/src/main/resources/assets/slsaddition/lang/en_us.json @@ -0,0 +1,3 @@ +{ + "carpet.rule.obtainableReinforcedDeepSlate.desc": "When an anvil falls on 64 dropped deepslates, they will be turned in a reinforced deepslate instead of disappearing." +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 3428658..36fef97 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,36 +1,35 @@ { "schemaVersion": 1, - "id": "modid", + "id": "carpet-sls-addition", "version": "${version}", "name": "Example Mod", "description": "This is an example description! Tell everyone what your mod is about!", "authors": [ - "Me!" + "zly2006" ], "contact": { - "homepage": "https://fabricmc.net/", - "sources": "https://github.com/FabricMC/fabric-example-mod" }, "license": "CC0-1.0", - "icon": "assets/modid/icon.png", + "icon": "assets/slsaddition/icon.png", "environment": "*", "entrypoints": { "main": [ - "net.fabricmc.example.ExampleMod" + "com.github.zly2006.carpetslsaddition.ServerMain" ] }, "mixins": [ - "modid.mixins.json" + "slsaddition.mixins.json" ], "depends": { "fabricloader": ">=0.14.9", "fabric-api": "*", "minecraft": "~1.19", - "java": ">=17" + "java": ">=17", + "carpet": "*" }, "suggests": { "another-mod": "*" diff --git a/src/main/resources/modid.mixins.json b/src/main/resources/slsaddition.mixins.json similarity index 59% rename from src/main/resources/modid.mixins.json rename to src/main/resources/slsaddition.mixins.json index 7c42cb4..cf57d1b 100644 --- a/src/main/resources/modid.mixins.json +++ b/src/main/resources/slsaddition.mixins.json @@ -1,12 +1,13 @@ { "required": true, "minVersion": "0.8", - "package": "net.fabricmc.example.mixin", + "package": "com.github.zly2006.carpetslsaddition.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ + "MixinFallingBlockEntity", + "MixinItemEntity" ], "client": [ - "ExampleMixin" ], "injectors": { "defaultRequire": 1