feat: obtainableReinforcedDeepSlate

This commit is contained in:
zly2006 committed 2024-07-11 12:14:01 +08:00
1 parent d4c2538aa2
commit 4b58aabaa7
13 files changed
+161 -66

No files matched your search

+4 -6
View File
@@ -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/)
+12 -10
View File
@@ -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 {
+4 -3
View File
@@ -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
@@ -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;
}
@@ -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<String, String> canHasTranslations(String lang) {
Map<String, String> 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;
}
}
@@ -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<Boolean> cir, int i, Predicate<?> predicate, DamageSource damageSource2, float f) {
}
}
@@ -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<Boolean> 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);
}
}
}
}
@@ -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!");
}
}
@@ -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!");
}
}
@@ -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."
}
+7 -8
View File
@@ -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": "*"
@@ -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