Skip to content

Commit

Permalink
Rewrite Fabric compat in Java
Browse files Browse the repository at this point in the history
  • Loading branch information
Juuxel committed Jul 27, 2024
1 parent 73e13f0 commit 935e94c
Show file tree
Hide file tree
Showing 28 changed files with 329 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ object BlockVariantSets : RegistryHelper() {
return variants.toSet()
}

@JvmStatic
fun add(variantSet: BlockVariantSet) {
variantSets += variantSet
}
Expand Down
1 change: 1 addition & 0 deletions common/src/main/kotlin/juuxel/adorn/util/Logging.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@file:JvmName("Logging")

package juuxel.adorn.util

import org.slf4j.Logger
Expand Down
23 changes: 23 additions & 0 deletions fabric/src/main/java/juuxel/adorn/compat/BiomeMakeoverCompat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package juuxel.adorn.compat;

import juuxel.adorn.block.variant.BlockVariant;
import juuxel.adorn.block.variant.BlockVariantSet;

import java.util.Arrays;
import java.util.List;

public final class BiomeMakeoverCompat implements BlockVariantSet {
private static final String[] WOOD_VARIANTS = {
"ancient_oak",
"blighted_balsa",
"willow",
"swamp_cypress",
};

@Override
public List<BlockVariant> getWoodVariants() {
return Arrays.stream(WOOD_VARIANTS)
.<BlockVariant>map(name -> new BlockVariant.Wood("biomemakeover/" + name))
.toList();
}
}
13 changes: 13 additions & 0 deletions fabric/src/main/java/juuxel/adorn/compat/BlockusCompat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package juuxel.adorn.compat;

import juuxel.adorn.block.variant.BlockVariant;
import juuxel.adorn.block.variant.BlockVariantSet;

import java.util.List;

public final class BlockusCompat implements BlockVariantSet {
@Override
public List<BlockVariant> getWoodVariants() {
return List.of(new BlockVariant.Wood("blockus/white_oak"));
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package juuxel.adorn.compat
package juuxel.adorn.compat;

import juuxel.adorn.block.variant.BlockVariant
import juuxel.adorn.block.variant.BlockVariantSet
import juuxel.adorn.block.variant.BlockVariant;
import juuxel.adorn.block.variant.BlockVariantSet;

object BygCompat : BlockVariantSet {
override val woodVariants = listOf(
import java.util.Arrays;
import java.util.List;

public final class BygCompat implements BlockVariantSet {
private static final String[] WOOD_VARIANTS = {
"aspen",
"baobab",
"blue_enchanted",
Expand Down Expand Up @@ -33,10 +36,10 @@
"white_mangrove",
"willow",
"witch_hazel",
"zelkova"
).map { BlockVariant.Wood("byg/$it") }
"zelkova",
};

override val stoneVariants = listOf(
private static final String[] STONE_VARIANTS = {
"dacite",
"dacite_brick",
"dacite_cobblestone",
Expand All @@ -53,6 +56,20 @@
"red_rock_brick",
"mossy_red_rock_brick",
"cracked_red_rock_brick",
"chiseled_red_rock_brick"
).map { BlockVariant.Stone("byg/$it") }
"chiseled_red_rock_brick",
};

@Override
public List<BlockVariant> getWoodVariants() {
return Arrays.stream(WOOD_VARIANTS)
.<BlockVariant>map(name -> new BlockVariant.Wood("byg/" + name))
.toList();
}

@Override
public List<BlockVariant> getStoneVariants() {
return Arrays.stream(STONE_VARIANTS)
.<BlockVariant>map(name -> new BlockVariant.Stone("byg/" + name))
.toList();
}
}
21 changes: 21 additions & 0 deletions fabric/src/main/java/juuxel/adorn/compat/CinderscapesCompat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package juuxel.adorn.compat;

import juuxel.adorn.block.variant.BlockVariant;
import juuxel.adorn.block.variant.BlockVariantSet;

import java.util.Arrays;
import java.util.List;

public final class CinderscapesCompat implements BlockVariantSet {
private static final String[] WOOD_VARIANTS = {
"scorched",
"umbral",
};

@Override
public List<BlockVariant> getWoodVariants() {
return Arrays.stream(WOOD_VARIANTS)
.<BlockVariant>map(name -> new BlockVariant.Wood("cinderscapes/" + name))
.toList();
}
}
38 changes: 38 additions & 0 deletions fabric/src/main/java/juuxel/adorn/compat/Compat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package juuxel.adorn.compat;

import juuxel.adorn.block.variant.BlockVariantSets;
import juuxel.adorn.config.ConfigManager;
import net.fabricmc.loader.api.FabricLoader;

public final class Compat {
public static void init() {
ifModLoaded("byg", () -> BlockVariantSets.add(new BygCompat()));
ifModLoaded("terrestria", () -> BlockVariantSets.add(new TerrestriaCompat()));
ifModLoaded("towelette", ToweletteCompat::init);
ifModLoaded("traverse", () -> BlockVariantSets.add(new TraverseCompat()));
ifModLoaded("woods_and_mires", () -> BlockVariantSets.add(new WamCompat()));
ifModLoaded("biomemakeover", () -> BlockVariantSets.add(new BiomeMakeoverCompat()));
ifModLoaded("cinderscapes", () -> BlockVariantSets.add(new CinderscapesCompat()));
ifModLoaded("promenade", () -> BlockVariantSets.add(new PromenadeCompat()));
ifModLoaded("techreborn", () -> BlockVariantSets.add(new TechRebornCompat()));
ifModLoaded("blockus", () -> BlockVariantSets.add(new BlockusCompat()));
}

public static boolean isCompatEnabled(String mod) {
var compatMap = ConfigManager.Companion.config().compat;

if (!compatMap.containsKey(mod)) {
compatMap.put(mod, true);
ConfigManager.Companion.getINSTANCE().save();
return true;
}

return compatMap.get(mod);
}

private static void ifModLoaded(String mod, Runnable fn) {
if (isCompatEnabled(mod) && FabricLoader.getInstance().isModLoaded(mod)) {
fn.run();
}
}
}
22 changes: 22 additions & 0 deletions fabric/src/main/java/juuxel/adorn/compat/PromenadeCompat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package juuxel.adorn.compat;

import juuxel.adorn.block.variant.BlockVariant;
import juuxel.adorn.block.variant.BlockVariantSet;

import java.util.Arrays;
import java.util.List;

public final class PromenadeCompat implements BlockVariantSet {
private static final String[] WOOD_VARIANTS = {
"dark_amaranth",
"palm",
"sakura",
};

@Override
public List<BlockVariant> getWoodVariants() {
return Arrays.stream(WOOD_VARIANTS)
.<BlockVariant>map(name -> new BlockVariant.Wood("promenade/" + name))
.toList();
}
}
13 changes: 13 additions & 0 deletions fabric/src/main/java/juuxel/adorn/compat/TechRebornCompat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package juuxel.adorn.compat;

import juuxel.adorn.block.variant.BlockVariant;
import juuxel.adorn.block.variant.BlockVariantSet;

import java.util.List;

public final class TechRebornCompat implements BlockVariantSet {
@Override
public List<BlockVariant> getWoodVariants() {
return List.of(new BlockVariant.Wood("techreborn/rubber"));
}
}
44 changes: 44 additions & 0 deletions fabric/src/main/java/juuxel/adorn/compat/TerrestriaCompat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package juuxel.adorn.compat;

import juuxel.adorn.block.variant.BlockVariant;
import juuxel.adorn.block.variant.BlockVariantSet;

import java.util.Arrays;
import java.util.List;

public final class TerrestriaCompat implements BlockVariantSet {
private static final String[] WOOD_VARIANTS = {
"cypress",
"hemlock",
"japanese_maple",
"rainbow_eucalyptus",
"redwood",
"rubber",
"sakura",
"yucca_palm",
"willow",
};

private static final String[] STONE_VARIANTS = {
"basalt",
"basalt_cobblestone",
"smooth_basalt",
"basalt_brick",
"mossy_basalt_cobblestone",
"mossy_basalt_brick",
};

@Override
public List<BlockVariant> getWoodVariants() {
return Arrays.stream(WOOD_VARIANTS)
.<BlockVariant>map(name -> new BlockVariant.Wood("terrestria/" + name))
.toList();
}

@Override
public List<BlockVariant> getStoneVariants() {
return Arrays.stream(STONE_VARIANTS)
.<BlockVariant>map(name -> new BlockVariant.Stone("terrestria/" + name))
.toList();
}
}
67 changes: 67 additions & 0 deletions fabric/src/main/java/juuxel/adorn/compat/ToweletteCompat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package juuxel.adorn.compat;

import juuxel.adorn.block.BenchBlock;
import juuxel.adorn.block.ChairBlock;
import juuxel.adorn.block.ChimneyBlock;
import juuxel.adorn.block.CoffeeTableBlock;
import juuxel.adorn.block.CopperPipeBlock;
import juuxel.adorn.block.PicketFenceBlock;
import juuxel.adorn.block.PlatformBlock;
import juuxel.adorn.block.PostBlock;
import juuxel.adorn.block.PrismarineChimneyBlock;
import juuxel.adorn.block.ShelfBlock;
import juuxel.adorn.block.SofaBlock;
import juuxel.adorn.block.StepBlock;
import juuxel.adorn.block.TableBlock;
import juuxel.adorn.block.TableLampBlock;
import juuxel.adorn.block.TradingStationBlock;
import juuxel.adorn.util.RegistryUtil;
import net.minecraft.block.Block;
import net.minecraft.registry.Registries;
import virtuoel.statement.api.StateRefresher;
import virtuoel.towelette.api.FluidProperties;
import virtuoel.towelette.api.ToweletteConfig;

public final class ToweletteCompat {
public static void init() {
boolean flowing = isFlowingFluidloggingEnabled();

RegistryUtil.visit(Registries.BLOCK, block -> {
if (shouldFluidlog(block)) {
StateRefresher.INSTANCE.addBlockProperty(block, FluidProperties.FLUID, Registries.FLUID.getDefaultId());

if (flowing) {
StateRefresher.INSTANCE.addBlockProperty(block, FluidProperties.LEVEL_1_8, 8);
StateRefresher.INSTANCE.addBlockProperty(block, FluidProperties.FALLING, false);
}
}
});
}

private static boolean isFlowingFluidloggingEnabled() {
var data = ToweletteConfig.DATA.get("flowingFluidlogging");
if (data != null && data.isJsonPrimitive()) {
return data.getAsBoolean();
}

return false;
}

private static boolean shouldFluidlog(Block block) {
return block instanceof BenchBlock ||
block instanceof ChairBlock ||
block instanceof ChimneyBlock ||
block instanceof CoffeeTableBlock ||
block instanceof CopperPipeBlock ||
block instanceof PicketFenceBlock ||
block instanceof PlatformBlock ||
block instanceof PostBlock ||
block instanceof PrismarineChimneyBlock ||
block instanceof ShelfBlock ||
block instanceof SofaBlock ||
block instanceof StepBlock ||
block instanceof TableBlock ||
block instanceof TableLampBlock ||
block instanceof TradingStationBlock;
}
}
13 changes: 13 additions & 0 deletions fabric/src/main/java/juuxel/adorn/compat/TraverseCompat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package juuxel.adorn.compat;

import juuxel.adorn.block.variant.BlockVariant;
import juuxel.adorn.block.variant.BlockVariantSet;

import java.util.List;

public final class TraverseCompat implements BlockVariantSet {
@Override
public List<BlockVariant> getWoodVariants() {
return List.of(new BlockVariant.Wood("traverse/fir"));
}
}
13 changes: 13 additions & 0 deletions fabric/src/main/java/juuxel/adorn/compat/WamCompat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package juuxel.adorn.compat;

import juuxel.adorn.block.variant.BlockVariant;
import juuxel.adorn.block.variant.BlockVariantSet;

import java.util.List;

public final class WamCompat implements BlockVariantSet {
@Override
public List<BlockVariant> getWoodVariants() {
return List.of(new BlockVariant.Wood("woods_and_mires/pine"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package juuxel.adorn.compat.modmenu;

import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import juuxel.adorn.client.gui.screen.MainConfigScreen;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

@Environment(EnvType.CLIENT)
public final class AdornModMenuPlugin implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return MainConfigScreen::new;
}
}
17 changes: 17 additions & 0 deletions fabric/src/main/java/juuxel/adorn/util/RegistryUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package juuxel.adorn.util;

import net.fabricmc.fabric.api.event.registry.RegistryEntryAddedCallback;
import net.minecraft.registry.Registry;

import java.util.function.Consumer;

public final class RegistryUtil {
/**
* Registers a visitor for this registry that will be called for each
* entry currently in the registry, and all future entries.
*/
public static <A> void visit(Registry<? extends A> registry, Consumer<A> callback) {
registry.forEach(callback);
RegistryEntryAddedCallback.event(registry).register((rawId, id, object) -> callback.accept(object));
}
}
13 changes: 0 additions & 13 deletions fabric/src/main/kotlin/juuxel/adorn/compat/BiomeMakeoverCompat.kt

This file was deleted.

Loading

0 comments on commit 935e94c

Please sign in to comment.