Skip to content

Commit

Permalink
forge still not working for some stupid reason
Browse files Browse the repository at this point in the history
  • Loading branch information
AnAwesomGuy committed May 8, 2024
1 parent 745f89e commit bf8a3b7
Show file tree
Hide file tree
Showing 13 changed files with 175 additions and 110 deletions.
26 changes: 22 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,27 @@ jobs:
run: chmod +x ./gradlew
- name: build
run: ./gradlew build
- name: capture build artifacts
if: ${{ matrix.java == '21' }} # Only upload artifacts built from latest java
- name: Upload build artifacts (Common)
continue-on-error: true
uses: actions/upload-artifact@v4
with:
name: Artifacts
path: build/libs/
name: ${{ github.event.repository.name }}-common-${{ github.sha }}
path: |
common/build/libs/*.jar
!common/build/libs/*-transformProduction*.jar
- name: Upload build artifacts (Fabric)
continue-on-error: true
uses: actions/upload-artifact@v4
with:
name: ${{ github.event.repository.name }}-fabric-${{ github.sha }}
path: |
fabric/build/libs/*.jar
!fabric/build/libs/*-dev*.jar
- name: Upload build artifacts (Forge)
continue-on-error: true
uses: actions/upload-artifact@v4
with:
name: ${{ github.event.repository.name }}-forge-${{ github.sha }}
path: |
forge/build/libs/*.jar
!forge/build/libs/*-dev*.jar
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ out/
output/
bin/
libs/
.architectury-transformer/

.classpath
.project
Expand All @@ -16,4 +17,5 @@ classes/
.metadata
.vscode
.settings
*.launch
*.launch
/.architectury-transformer/debug.log
18 changes: 17 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ architectury {
minecraft = minecraft_version
}

version = mod_version

import groovy.json.JsonSlurper
import groovy.json.JsonOutput

subprojects {
apply plugin: "dev.architectury.loom"

Expand All @@ -20,14 +25,25 @@ subprojects {

processResources {
def properties = [
version: project.version, mod_id: mod_id, description: description,
version: mod_version, mod_id: mod_id, description: description,
github: github, display_name: display_name
]

inputs.properties properties

filesMatching(["META-INF/mods.toml", "fabric.mod.json", "pack.mcmeta"]) {
expand properties
filter {
it.empty ? null : it
}
}

doLast {
fileTree(dir: outputs.files.asPath).each {
var name = it.name
if (name.endsWith(".json") || name.endsWith(".mcmeta"))
it.text = JsonOutput.toJson(new JsonSlurper().parse(it))
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package net.anawesomguy.breakingbedrock;

import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.TieredItem;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;

import static net.anawesomguy.breakingbedrock.BreakingBedrock.getBedrockDestroyTime;
import static net.anawesomguy.breakingbedrock.BreakingBedrock.getBedrockExplosionResist;

public class BedrockBlock extends Block {
public BedrockBlock(Properties properties) {
super(properties.strength(getBedrockDestroyTime(), getBedrockExplosionResist()));
}

@Override @SuppressWarnings("deprecation")
public float getDestroyProgress(BlockState state, Player player, BlockGetter level, BlockPos pos) {
return player.getInventory().getSelected().getItem() instanceof TieredItem item && item.getTier().getLevel() > 3 ?
player.getDestroySpeed(state) / state.getDestroySpeed(level, pos) / 100F :
0F;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,69 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Properties;

public final class BreakingBedrock {
public static final String MOD_ID = "breakingbedrock";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

@ExpectPlatform
public static final float BEDROCK_DESTROY_TIME;
public static final float BEDROCK_EXPLOSION_RESIST;

static {
Properties properties = new Properties();
float destroyTime, explosionResist;
File configFile = configDir().resolve(BreakingBedrock.MOD_ID + ".properties").toFile();
try {
Properties temp = new Properties();
temp.load(new FileInputStream(configFile));
String time = temp.getProperty("bedrockDestroyTime"),
resist = temp.getProperty("bedrockExplosionResist");
if (time == null || !((destroyTime = Float.parseFloat(time)) > -1) || destroyTime == Float.POSITIVE_INFINITY) {
properties.setProperty("bedrockDestroyTime", "60");
destroyTime = 60;
} else properties.setProperty("bedrockDestroyTime", time);
if (resist == null || !((explosionResist = Float.parseFloat(resist)) > 0) || explosionResist == Float.POSITIVE_INFINITY) {
properties.setProperty("bedrockExplosionResist", "3600000");
explosionResist = 3600000;
} else properties.setProperty("bedrockExplosionResist", resist);
} catch (IOException | IllegalArgumentException e) {
LOGGER.info("Could not read config file (likely corrupted or missing)! Attempting to (re)create it.");
properties.setProperty("bedrockDestroyTime", "60");
properties.setProperty("bedrockExplosionResist", "3600000");
explosionResist = 60;
destroyTime = 3600000;
}

BEDROCK_EXPLOSION_RESIST = explosionResist;
BEDROCK_DESTROY_TIME = destroyTime;

try {
properties.store(new FileOutputStream(configFile),
"""
bedrockDestroyTime: The destroy time for bedrock, allows decimals. (obsidian is 50, stone is 1.5, use -1 to make it indestructible)
bedrockExplosionResist: The explosion resistance for bedrock, allows decimals. (stone is 6, glass is 0.3)
""");
} catch (IOException e) {
LOGGER.error("Unable to create/modify config file!", e);
}
}

public static float getBedrockDestroyTime() {
throw new AssertionError();
return BEDROCK_DESTROY_TIME;
}

@ExpectPlatform
public static float getBedrockExplosionResist() {
return BEDROCK_EXPLOSION_RESIST;
}

@ExpectPlatform
public static Path configDir() {
throw new AssertionError();
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package net.anawesomguy.breakingbedrock.mixin;

import net.anawesomguy.breakingbedrock.BreakingBedrock;
import net.anawesomguy.breakingbedrock.BedrockBlock;
import net.minecraft.world.level.block.Block;
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.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.Slice;

@Mixin(Blocks.class)
public abstract class BlocksMixin {
@ModifyConstant(method = "<clinit>", constant = @Constant(floatValue = -1F, ordinal = 0), slice = @Slice(from = @At(value = "FIELD", target = "Lnet/minecraft/world/level/block/Blocks;BEDROCK:Lnet/minecraft/world/level/block/Block;")))
private static float bedrockBreaking$modifyBedrockDestroyTime(float constant) {
return BreakingBedrock.getBedrockDestroyTime();
}

@ModifyConstant(method = "<clinit>", constant = @Constant(floatValue = -1F, ordinal = 1), slice = @Slice(from = @At(value = "FIELD", target = "Lnet/minecraft/world/level/block/Blocks;BEDROCK:Lnet/minecraft/world/level/block/Block;")))
private static float bedrockBreaking$modifyBedrockExplosionResist(float constant) {
return BreakingBedrock.getBedrockExplosionResist();
@Redirect(method = "<clinit>", at = @At(value = "NEW", target = "(Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)Lnet/minecraft/world/level/block/Block;"), slice = @Slice(from = @At(value = "CONSTANT", args = "stringValue=bedrock")))
private static Block breakingbedrock$replaceBedrock(Properties properties) {
return new BedrockBlock(properties);
}
}
20 changes: 20 additions & 0 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@ architectury {
fabric()
}

loom {
runs {
clientMixinDebug {
client()
ideConfigGenerated true
name = "Client Mixin Debug"
source sourceSets.main
property 'mixin.debug', 'true'
}

serverMixinDebug {
server()
ideConfigGenerated true
name = "Server Mixin Debug"
source sourceSets.main
property 'mixin.debug', 'true'
}
}
}

configurations {
common
shadowCommon // Don't use shadow from the shadow plugin since it *excludes* files.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,66 +1,11 @@
package net.anawesomguy.breakingbedrock.fabric;

import net.anawesomguy.breakingbedrock.BreakingBedrock;
import net.fabricmc.loader.api.FabricLoader;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import java.nio.file.Path;

public final class BreakingBedrockImpl {
public static final float BEDROCK_DESTROY_TIME;
public static final float BEDROCK_EXPLOSION_RESIST;

static {
File configFile = FabricLoader.getInstance().getConfigDir().resolve(BreakingBedrock.MOD_ID + ".properties").toFile();
Properties properties = new Properties();
float destroyTime, explosionResist;
try {
Properties temp = new Properties();
temp.load(new FileInputStream(configFile));
String time = temp.getProperty("bedrockDestroyTime"),
resist = temp.getProperty("bedrockExplosionResist");
destroyTime = Float.parseFloat(time);
explosionResist = Float.parseFloat(resist);
boolean timeBounds = !(destroyTime > -1) || Float.isInfinite(destroyTime),
resistBounds = !(explosionResist > 0) || Float.isInfinite(destroyTime);
if (timeBounds) {
properties.setProperty("bedrockDestroyTime", "60");
destroyTime = 60;
} else properties.setProperty("bedrockDestroyTime", time);
if (resistBounds) {
properties.setProperty("bedrockDestroyTime", "3600000");
explosionResist = 3600000;
} else properties.setProperty("bedrockDestroyTime", resist);
} catch (IOException | IllegalArgumentException e) {
BreakingBedrock.LOGGER.info("Could not read config file (likely corrupted or missing)! Attempting to (re)create it.");
properties.setProperty("bedrockDestroyTime", "60");
properties.setProperty("bedrockExplosionResist", "3600000");
explosionResist = 60;
destroyTime = 3600000;
}

BEDROCK_EXPLOSION_RESIST = explosionResist;
BEDROCK_DESTROY_TIME = destroyTime;

try {
properties.store(new FileOutputStream(configFile),
"""
bedrockDestroyTime: The destroy time for bedrock, allows decimals. (obsidian is 50, stone is 1.5, use -1 to make it indestructible)
bedrockExplosionResist: The explosion resistance for bedrock, allows decimals. (stone is 6, glass is 0.3)
""");
} catch (IOException e) {
BreakingBedrock.LOGGER.error("Unable to create/modify config file!", e);
}
}

public static float getBedrockDestroyTime() {
return BEDROCK_DESTROY_TIME;
}

public static float getBedrockExplosionResist() {
return BEDROCK_EXPLOSION_RESIST;
public static Path configDir() {
return FabricLoader.getInstance().getConfigDir();
}
}
2 changes: 1 addition & 1 deletion fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
],
"depends": {
"fabric": "*",
"minecraft": ">=20w12a"
"minecraft": ">=1.16-alpha.20.12.a"
}
}
18 changes: 18 additions & 0 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ loom {
forge {
mixinConfig "${mod_id}.mixins.json"
}

runs {
clientMixinDebug {
client()
ideConfigGenerated true
name = "Client Mixin Debug"
source sourceSets.main
property 'mixin.debug', 'true'
}

serverMixinDebug {
server()
ideConfigGenerated true
name = "Server Mixin Debug"
source sourceSets.main
property 'mixin.debug', 'true'
}
}
}

configurations {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,14 @@
package net.anawesomguy.breakingbedrock.forge;

import net.anawesomguy.breakingbedrock.BreakingBedrock;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.loading.FMLPaths;

import java.nio.file.Path;

@Mod(BreakingBedrock.MOD_ID)
public final class BreakingBedrockImpl {
public static final ForgeConfigSpec CONFIG_SPEC;
public static final ForgeConfigSpec.DoubleValue BEDROCK_DESTROY_TIME;
public static final ForgeConfigSpec.DoubleValue BEDROCK_EXPLOSION_RESIST;

static {
ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
BEDROCK_DESTROY_TIME = builder.comment("The destroy time for bedrock, allows decimals. (obsidian is 50, stone is 1.5, use -1 to make it indestructible)")
.defineInRange("bedrockDestroyTime", 60, -1, Float.MAX_VALUE);
BEDROCK_EXPLOSION_RESIST = builder.comment("The explosion resistance for bedrock, allows decimals. (stone is 6, glass is 0.3)")
.defineInRange("bedrockExplosionResist", 3600000, 0, Float.MAX_VALUE);
CONFIG_SPEC = builder.build();
}

public BreakingBedrockImpl() {
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, CONFIG_SPEC);
}

public static float getBedrockDestroyTime() {
return BEDROCK_DESTROY_TIME.get().floatValue();
}

public static float getBedrockExplosionResist() {
return BEDROCK_EXPLOSION_RESIST.get().floatValue();
public static Path configDir() {
return FMLPaths.CONFIGDIR.get();
}
}

This file was deleted.

0 comments on commit bf8a3b7

Please sign in to comment.