diff --git a/build.gradle b/build.gradle index c9a2241..e6faa37 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.6-SNAPSHOT' + id 'fabric-loom' version '1.11-SNAPSHOT' id 'maven-publish' } diff --git a/gradle.properties b/gradle.properties index ad6bc36..9300d58 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://modmuss50.me/fabric.html - minecraft_version=1.21 - yarn_mappings=1.21+build.8 - loader_version=0.15.11 +minecraft_version=1.21.8 +yarn_mappings=1.21.8+build.1 +loader_version=0.17.2 # Mod Properties - mod_version = 1.1 + mod_version = 1.2 maven_group = com.kasetoatz archives_base_name = noexplosiongrief # Dependencies # check this on https://modmuss50.me/fabric.html - fabric_version=0.100.6+1.21 +fabric_version=0.133.4+1.21.8 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e096528..0ceb5e9 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1 +1 @@ -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip diff --git a/src/main/java/com/kasetoatz/noexplosiongrief/NoExplosionGrief.java b/src/main/java/com/kasetoatz/noexplosiongrief/NoExplosionGrief.java index 1e37d2e..8bd276a 100644 --- a/src/main/java/com/kasetoatz/noexplosiongrief/NoExplosionGrief.java +++ b/src/main/java/com/kasetoatz/noexplosiongrief/NoExplosionGrief.java @@ -1,11 +1,14 @@ package com.kasetoatz.noexplosiongrief; -import com.kasetoatz.noexplosiongrief.config.Config; import net.fabricmc.api.ModInitializer; -public class NoExplosionGrief implements ModInitializer { +import static com.kasetoatz.noexplosiongrief.config.Config.load; + +public class NoExplosionGrief implements ModInitializer +{ @Override - public void onInitialize() { - Config.load(); + public void onInitialize() + { + load(); } } diff --git a/src/main/java/com/kasetoatz/noexplosiongrief/config/Config.java b/src/main/java/com/kasetoatz/noexplosiongrief/config/Config.java index 8097fca..e07daa9 100644 --- a/src/main/java/com/kasetoatz/noexplosiongrief/config/Config.java +++ b/src/main/java/com/kasetoatz/noexplosiongrief/config/Config.java @@ -3,44 +3,45 @@ package com.kasetoatz.noexplosiongrief.config; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; -import net.minecraft.client.MinecraftClient; +import net.fabricmc.loader.api.FabricLoader; import net.minecraft.util.crash.CrashException; import net.minecraft.util.crash.CrashReport; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; -public class Config { - public static boolean blockCreeper = true; - public static boolean blockGhast = true; - public static boolean blockWither = true; +public class Config +{ + public static boolean BLOCK_CREEPER = true; + public static boolean BLOCK_GHAST = true; + public static boolean BLOCK_WITHER = true; - private static final File config = new File(MinecraftClient.getInstance().runDirectory, "config/noexplosiongrief.json"); - private static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + private static final Path FILE = FabricLoader.getInstance().getConfigDir().resolve("noexplosiongrief.json"); + private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); public static void load() { - if (!config.exists()) + if (!Files.exists(FILE)) { save(); return; } - try (FileReader reader = new FileReader(config)) + try { - JsonObject json = gson.fromJson(reader, JsonObject.class); - if (json.has("blockCreeper")) + String json = Files.readString(FILE); + JsonObject data = GSON.fromJson(json, JsonObject.class); + if (data.has("block-creeper")) { - blockCreeper = json.get("blockCreeper").getAsBoolean(); + BLOCK_CREEPER = data.get("block-creeper").getAsBoolean(); } - if (json.has("blockGhast")) + if (data.has("block-ghast")) { - blockGhast = json.get("blockGhast").getAsBoolean(); + BLOCK_GHAST = data.get("block-ghast").getAsBoolean(); } - if (json.has("blockWither")) + if (data.has("block-wither")) { - blockWither = json.get("blockWither").getAsBoolean(); + BLOCK_WITHER = data.get("block-wither").getAsBoolean(); } save(); } @@ -52,13 +53,13 @@ public class Config { public static void save() { - JsonObject json = new JsonObject(); - json.addProperty("blockCreeper", blockCreeper); - json.addProperty("blockGhast", blockGhast); - json.addProperty("blockWither", blockWither); - try (FileWriter writer = new FileWriter(config)) + try { - gson.toJson(json, writer); + JsonObject data = new JsonObject(); + data.addProperty("block-creeper", BLOCK_CREEPER); + data.addProperty("block-ghast", BLOCK_GHAST); + data.addProperty("block-wither", BLOCK_WITHER); + Files.writeString(FILE, GSON.toJson(data)); } catch (IOException exc) { diff --git a/src/main/java/com/kasetoatz/noexplosiongrief/mixin/EntityMixin.java b/src/main/java/com/kasetoatz/noexplosiongrief/mixin/EntityMixin.java index f980489..541f4c7 100644 --- a/src/main/java/com/kasetoatz/noexplosiongrief/mixin/EntityMixin.java +++ b/src/main/java/com/kasetoatz/noexplosiongrief/mixin/EntityMixin.java @@ -3,9 +3,7 @@ package com.kasetoatz.noexplosiongrief.mixin; import com.kasetoatz.noexplosiongrief.config.Config; import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; -import net.minecraft.entity.boss.WitherEntity; import net.minecraft.entity.mob.CreeperEntity; -import net.minecraft.entity.mob.GhastEntity; import net.minecraft.entity.projectile.FireballEntity; import net.minecraft.entity.projectile.WitherSkullEntity; import net.minecraft.util.math.BlockPos; @@ -16,14 +14,18 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import static com.kasetoatz.noexplosiongrief.config.Config.BLOCK_CREEPER; + @Mixin(Entity.class) -public abstract class EntityMixin { - @Inject(method="canExplosionDestroyBlock", at = @At("HEAD"), cancellable = true) - public void onExplosion(Explosion explosion, BlockView world, BlockPos pos, BlockState state, float explosionPower, CallbackInfoReturnable cir) { +public abstract class EntityMixin +{ + @Inject(method="canExplosionDestroyBlock", at=@At("HEAD"), cancellable=true) + public void onExplosion(Explosion explosion, BlockView world, BlockPos pos, BlockState state, float explosionPower, CallbackInfoReturnable cir) + { Entity entity = (Entity)(Object)this; - if ((entity instanceof CreeperEntity && Config.blockCreeper) || ((entity instanceof FireballEntity && ((FireballEntity)entity).getOwner() instanceof GhastEntity) && Config.blockGhast) || ((entity instanceof WitherSkullEntity && ((WitherSkullEntity)entity).getOwner() instanceof WitherEntity) && Config.blockWither)) + if ((entity instanceof CreeperEntity && BLOCK_CREEPER) || (entity instanceof FireballEntity && Config.BLOCK_GHAST) || (entity instanceof WitherSkullEntity && Config.BLOCK_WITHER)) { cir.setReturnValue(false); } } -} \ No newline at end of file +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index b030c44..46e6b15 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -12,7 +12,7 @@ "repo": "https://github.com/KaseToatz1337/NoExplosionGrief" }, "license": "MIT", - "environment": "*", + "environment": "server", "entrypoints": { "main": [ "com.kasetoatz.noexplosiongrief.NoExplosionGrief"