feat: obtainableReinforcedDeepSlate
This commit is contained in:
13 files changed
+161
-66
No files matched your search
@@ -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!");
|
||||
}
|
||||
}
|
||||
File renamed without changes.
@@ -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."
|
||||
}
|
||||
@@ -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
|
||||
Reference in new issue
Block a user