Skip to content

Commit

Permalink
pretty much release
Browse files Browse the repository at this point in the history
  • Loading branch information
AnAwesomGuy committed Jan 7, 2025
1 parent 799e4ed commit 96744ae
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 32 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> myTargets, Set<String> otherTargets) {
}

@Override
public List<String> 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) {
}
}
Original file line number Diff line number Diff line change
@@ -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 = "<clinit>", 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<clinit>", 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());
}
}
6 changes: 4 additions & 2 deletions common/src/main/resources/breakingbedrock.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"type": "block",
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "item",
"name": "bedrock"
}
]
}
],
"random_sequence": "blocks/bedrock"
}
2 changes: 1 addition & 1 deletion forge/src/main/resources/pack.mcmeta
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"pack": {
"description": "BreakingBedrock",
"description": "${mod_id}",
"pack_format": 7
}
}
11 changes: 5 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 96744ae

Please sign in to comment.