diff --git a/build.gradle b/build.gradle index 68acba0..43e0329 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ plugins { id "architectury-plugin" version "3.4-SNAPSHOT" - id "dev.architectury.loom" version "1.7-SNAPSHOT" apply false - id "me.modmuss50.mod-publish-plugin" version "0.7.+" + id "dev.architectury.loom" version "1.9-SNAPSHOT" apply false + id "me.modmuss50.mod-publish-plugin" version "0.8.+" id "com.github.johnrengelman.shadow" version "8.1.+" apply false } diff --git a/common/src/main/java/net/anawesomguy/breakingbedrock/BreakingBedrock.java b/common/src/main/java/net/anawesomguy/breakingbedrock/BreakingBedrock.java index 5ec85cf..3994016 100644 --- a/common/src/main/java/net/anawesomguy/breakingbedrock/BreakingBedrock.java +++ b/common/src/main/java/net/anawesomguy/breakingbedrock/BreakingBedrock.java @@ -18,60 +18,87 @@ public final class BreakingBedrock { public static final float DESTROY_TIME; public static final float EXPLOSION_RESIST; public static final int MINING_TIER; + public static final boolean DROP_BEDROCK; static { - LOGGER.info("Initializing Breaking Bedrock. This mod overwrites bedrock, and may break with other mods that do the same!"); + Logger log = LOGGER; + log.info("Initializing Breaking Bedrock. This mod overwrites bedrock, and may break with other mods that do the same!"); Properties properties = new Properties(); float destroyTime, explosionResist; int miningLevel; + boolean dropBedrock; File configFile = configDir().resolve(BreakingBedrock.MOD_ID + ".properties").toFile(); try { Properties temp = new Properties(); temp.load(new FileInputStream(configFile)); String time = temp.getProperty("destroy_time"), resist = temp.getProperty("explosion_resist"), - level = temp.getProperty("mining_level"); - if (time == null || !((destroyTime = Float.parseFloat(time)) > -1) || destroyTime == Float.POSITIVE_INFINITY) { + level = temp.getProperty("mining_level"), + drop = temp.getProperty("drop_bedrock"); + + if (time != null && ((destroyTime = Float.parseFloat(time)) >= 0 || destroyTime == -1F)) + properties.setProperty("destroy_time", time); + else { properties.setProperty("destroy_time", "100"); destroyTime = 100F; - LOGGER.debug("Correcting invalid config value {}!", time); - } else properties.setProperty("destroy_time", time); - if (resist == null || !((explosionResist = Float.parseFloat(resist)) > 0) || explosionResist == Float.POSITIVE_INFINITY) { + log.debug("Correcting invalid config value {}!", time); + } + + if (resist != null && (explosionResist = Float.parseFloat(resist)) >= 0) + properties.setProperty("explosion_resist", resist); + else { properties.setProperty("explosion_resist", "3600000"); explosionResist = 3600000F; - LOGGER.debug("Correcting invalid config value {}!", resist); - } else properties.setProperty("explosion_resist", resist); - if (level == null || !((miningLevel = Integer.parseInt(level)) > 0)) { + log.debug("Correcting invalid config value {}!", resist); + } + + if (level != null && (miningLevel = Integer.parseInt(level)) >= 0) { + properties.setProperty("mining_level", level); + } else { properties.setProperty("mining_level", "4"); miningLevel = 4; - LOGGER.debug("Correcting invalid config value {}!", level); - } else properties.setProperty("mining_level", level); + log.debug("Correcting invalid config value {}!", level); + } + + boolean isFalse = "false".equalsIgnoreCase(drop); + boolean isTrue = "true".equalsIgnoreCase(drop); + if (drop == null || (!isFalse && !isTrue)) { // if value is not set or is neither "false" nor "true" + properties.setProperty("drop_bedrock", "false"); + dropBedrock = false; + log.debug("Correcting invalid config value {}!", drop); + } else + properties.setProperty("drop_bedrock", String.valueOf(dropBedrock = isTrue)); } catch (IOException | IllegalArgumentException e) { - LOGGER.info("Couldn't read config file (likely corrupted or missing)! Attempting to (re)create it."); + log.info("Couldn't read config file (likely corrupted or missing)! Attempting to (re)create it."); properties.setProperty("destroy_time", "100"); properties.setProperty("explosion_resist", "3600000"); properties.setProperty("mining_level", "4"); + properties.setProperty("drop_bedrock", "false"); destroyTime = 100F; explosionResist = 3600000F; miningLevel = 4; + dropBedrock = false; } EXPLOSION_RESIST = explosionResist; DESTROY_TIME = destroyTime; MINING_TIER = miningLevel; + DROP_BEDROCK = dropBedrock; try { properties.store(new FileOutputStream(configFile), - """ - destroy_time: The destroy time for bedrock. (obsidian is 50, stone is 1.5, -1 is indestructible) - explosion_resist: The explosion resistance for bedrock. (stone is 6, glass is 0.3) - mining_level: The mining level required to mine bedrock. (netherite is 4) - """); + """ + destroy_time: The destroy time for bedrock. (obsidian is 50, stone is 1.5, -1 is indestructible) + explosion_resist: The explosion resistance for bedrock. (stone is 6, glass is 0.3) + mining_level: The mining level required to mine bedrock. (netherite is 4) + drop_bedrock: Whether bedrock should drop as a block when broken. + """); } catch (IOException e) { LOGGER.error("Unable to create/modify config file!", e); } - LOGGER.debug("Config initialized with values: destroyTime={}, explosionResist={}, miningLevel={}", destroyTime, explosionResist, miningLevel); + LOGGER.debug("Config initialized with values: destroyTime={}, explosionResist={}, miningLevel={}, drop_bedrock={}", + destroyTime, explosionResist, miningLevel, dropBedrock); } @ExpectPlatform diff --git a/common/src/main/java/net/anawesomguy/breakingbedrock/BreakingBedrockMixinPlugin.java b/common/src/main/java/net/anawesomguy/breakingbedrock/BreakingBedrockMixinPlugin.java new file mode 100644 index 0000000..0dc3bc6 --- /dev/null +++ b/common/src/main/java/net/anawesomguy/breakingbedrock/BreakingBedrockMixinPlugin.java @@ -0,0 +1,44 @@ +package net.anawesomguy.breakingbedrock; + +import org.objectweb.asm.tree.ClassNode; +import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; + +import java.util.List; +import java.util.Set; + +public final class BreakingBedrockMixinPlugin implements IMixinConfigPlugin { + @Override + public void onLoad(String mixinPackage) { + } + + @Override + public String getRefMapperConfig() { + return null; + } + + @Override + public boolean shouldApplyMixin(String targetName, String mixinName) { +// if ("net.anawesomguy.breakingbedrock.mixin.BlocksMixin_LootTable".equals(mixinName)) +// return BreakingBedrock.DROP_BEDROCK; +// return true; + return !"net.anawesomguy.breakingbedrock.mixin.BlocksMixin_LootTable".equals(mixinName) || BreakingBedrock.DROP_BEDROCK; + } + + @Override + public void acceptTargets(Set myTargets, Set otherTargets) { + } + + @Override + public List getMixins() { + return null; + } + + @Override + public void preApply(String targetName, ClassNode targetClass, String mixinName, IMixinInfo mixinInfo) { + } + + @Override + public void postApply(String targetName, ClassNode targetClass, String mixinName, IMixinInfo mixinInfo) { + } +} diff --git a/common/src/main/java/net/anawesomguy/breakingbedrock/mixin/BlocksMixin_LootTable.java b/common/src/main/java/net/anawesomguy/breakingbedrock/mixin/BlocksMixin_LootTable.java new file mode 100644 index 0000000..068045e --- /dev/null +++ b/common/src/main/java/net/anawesomguy/breakingbedrock/mixin/BlocksMixin_LootTable.java @@ -0,0 +1,16 @@ +package net.anawesomguy.breakingbedrock.mixin; + +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockBehaviour.Properties; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.Slice; + +@Mixin(Blocks.class) +public abstract class BlocksMixin_LootTable { + @Redirect(method = "", at = @At(value = "INVOKE", target = "net/minecraft/world/level/block/state/BlockBehaviour$Properties.noLootTable()Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;", ordinal = 0), slice = @Slice(from = @At(value = "CONSTANT", args = "stringValue=bedrock"))) + private static Properties breakingbedrock$addLootTable(Properties properties) { + return properties; + } +} diff --git a/common/src/main/java/net/anawesomguy/breakingbedrock/mixin/BlocksMixin.java b/common/src/main/java/net/anawesomguy/breakingbedrock/mixin/BlocksMixin_ReplaceBedrock.java similarity index 86% rename from common/src/main/java/net/anawesomguy/breakingbedrock/mixin/BlocksMixin.java rename to common/src/main/java/net/anawesomguy/breakingbedrock/mixin/BlocksMixin_ReplaceBedrock.java index 373d7f1..e14492c 100644 --- a/common/src/main/java/net/anawesomguy/breakingbedrock/mixin/BlocksMixin.java +++ b/common/src/main/java/net/anawesomguy/breakingbedrock/mixin/BlocksMixin_ReplaceBedrock.java @@ -11,9 +11,9 @@ import org.spongepowered.asm.mixin.injection.Slice; @Mixin(Blocks.class) -public abstract class BlocksMixin { +public abstract class BlocksMixin_ReplaceBedrock { @Redirect(method = "", at = @At(value = "NEW", target = "net/minecraft/world/level/block/Block", ordinal = 0), slice = @Slice(from = @At(value = "CONSTANT", args = "stringValue=bedrock"))) private static Block breakingbedrock$replaceBedrock(Properties properties) { - return new BedrockBlock(properties.strength(BreakingBedrock.DESTROY_TIME, BreakingBedrock.EXPLOSION_RESIST)); + return new BedrockBlock(properties.strength(BreakingBedrock.DESTROY_TIME, BreakingBedrock.EXPLOSION_RESIST).requiresCorrectToolForDrops()); } } diff --git a/common/src/main/resources/breakingbedrock.mixins.json b/common/src/main/resources/breakingbedrock.mixins.json index 23a23c4..0ba9802 100644 --- a/common/src/main/resources/breakingbedrock.mixins.json +++ b/common/src/main/resources/breakingbedrock.mixins.json @@ -4,9 +4,11 @@ "compatibilityLevel": "JAVA_17", "minVersion": "0.8", "mixins": [ - "BlocksMixin", - "DiggerItemAccessor" + "DiggerItemAccessor", + "BlocksMixin_LootTable", + "BlocksMixin_ReplaceBedrock" ], + "plugin": "net.anawesomguy.breakingbedrock.BreakingBedrockMixinPlugin", "injectors": { "defaultRequire": 1 } diff --git a/common/src/main/resources/data/minecraft/loot_tables/blocks/bedrock.json b/common/src/main/resources/data/minecraft/loot_tables/blocks/bedrock.json new file mode 100644 index 0000000..01f3167 --- /dev/null +++ b/common/src/main/resources/data/minecraft/loot_tables/blocks/bedrock.json @@ -0,0 +1,15 @@ +{ + "type": "block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "item", + "name": "bedrock" + } + ] + } + ], + "random_sequence": "blocks/bedrock" +} \ No newline at end of file diff --git a/forge/src/main/resources/pack.mcmeta b/forge/src/main/resources/pack.mcmeta index 7522421..681ad12 100644 --- a/forge/src/main/resources/pack.mcmeta +++ b/forge/src/main/resources/pack.mcmeta @@ -1,6 +1,6 @@ { "pack": { - "description": "BreakingBedrock", + "description": "${mod_id}", "pack_format": 7 } } diff --git a/gradle.properties b/gradle.properties index 56cd7af..01b4274 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,18 +4,17 @@ minecraft_version=1.20.1 enabled_platforms=fabric,forge mod_id=breakingbedrock -mod_version=1.1.1 +mod_version=1.1.2 maven_group=net.anawesomguy.breakingbedrock description=Allow bedrock to be mined with a netherite pickaxe! github=AnAwesomGuy/breakingbedrock display_name=Breaking Bedrock -fabric_loader_version=0.16.5 -fabric_api_version=0.92.2+1.20.1 +fabric_loader_version=0.16.9 +fabric_api_version=0.92.3+1.20.1 -forge_version=47.3.10 +forge_version=47.3.22 -changelog=small things\ - fix the config (again again) +changelog=add a new config option to allow bedrock to drop curseforge_id=1017910 modrinth_id=s0tNTkDN \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 171d876..18362b7 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists