Skip to content

Commit

Permalink
fix: Java 8 moment pt.2
Browse files Browse the repository at this point in the history
  • Loading branch information
null2264 committed Jan 6, 2024
1 parent fb802eb commit a4603ca
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
33 changes: 17 additions & 16 deletions src/main/java/io/github/null2264/cobblegen/compat/LoaderCompat.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
package io.github.null2264.cobblegen.compat;

import java.nio.file.Path;

//#if FABRIC>=1
import net.fabricmc.loader.api.FabricLoader;
//#if MC<=1.16.5
//$$ import java.io.IOException;
//$$ import java.nio.file.Files;
//#endif
//#if MC<=1.16.5
//$$ import java.io.IOException;
//$$ import java.nio.file.FileSystems;
//$$ import java.nio.file.Files;
//#endif
//#else
//#if FORGE>=2 && MC>=1.20.2
//$$ import net.neoforged.fml.loading.FMLPaths;
//$$ import net.neoforged.fml.ModList;
//$$ import net.neoforged.fml.loading.LoadingModList;
//#else
//#if FORGE>=2 && MC>=1.20.2
//$$ import net.neoforged.fml.loading.FMLPaths;
//$$ import net.neoforged.fml.ModList;
//$$ import net.neoforged.fml.loading.LoadingModList;
//#else
//$$ import net.minecraftforge.fml.loading.FMLPaths;
//$$ import net.minecraftforge.fml.ModList;
//$$ import net.minecraftforge.fml.loading.LoadingModList;
//#endif
//$$ import net.minecraftforge.fml.loading.FMLPaths;
//$$ import net.minecraftforge.fml.ModList;
//$$ import net.minecraftforge.fml.loading.LoadingModList;
//#endif
//#endif

import java.nio.file.Path;

public class LoaderCompat {
public static boolean isModLoaded(String mod) {
Expand All @@ -38,7 +39,7 @@ public static Path getConfigDir() {
return FabricLoader.getInstance().getConfigDir();
//#else
// Not ideal, but configDir is null somehow in 1.16.5
//$$ Path configDir = Path.of(".", "config");
//$$ Path configDir = FileSystems.getDefault().getPath(".", "config");
//$$ if (!Files.exists(configDir)) { // Stolen from fabric loader
//$$ try {
//$$ Files.createDirectories(configDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;

import static io.github.null2264.cobblegen.compat.CollectionCompat.listOf;
import static io.github.null2264.cobblegen.util.Constants.LAVA_FIZZ;
import static io.github.null2264.cobblegen.util.Util.notNullOr;

Expand Down Expand Up @@ -149,7 +150,7 @@ public boolean interact(LevelAccessor level, BlockPos pos, BlockState state) {
public boolean interact(LevelAccessor level, BlockPos pos, BlockState state, boolean fromTop) {
FluidState fluidState = state.getFluidState();
Fluid fluid = Generator.getStillFluid(fluidState);
final List<Generator> generators = generatorMap.getOrDefault(fluid, List.of());
final List<Generator> generators = generatorMap.getOrDefault(fluid, listOf());

for (Generator generator : generators) {
if (!generator.check(level, pos, state, fromTop)) continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class CobbleGenerator extends BlockGenerator
private final boolean silent;

public CobbleGenerator(List<WeightedBlock> possibleBlocks, Fluid fluid, boolean silent) {
this(possibleBlocks, fluid, silent, Map.of());
this(possibleBlocks, fluid, silent, mapOf());
}

public CobbleGenerator(List<WeightedBlock> possibleBlocks, Fluid fluid, boolean silent, Map<String, List<WeightedBlock>> obsidianReplacements) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public abstract class BlockGenerator implements BuiltInGenerator
public Optional<BlockState> tryGenerate(LevelAccessor level, BlockPos pos, BlockState state) {
for (Direction direction : FLOW_DIRECTIONS) {
final Optional<BlockState> candidate = tryGenerate(level, pos, state, direction);
if (candidate.isEmpty()) continue;
if (!candidate.isPresent()) continue;
return candidate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.Map;
import java.util.Optional;

import static io.github.null2264.cobblegen.compat.CollectionCompat.mapOf;

public interface Generator extends PacketSerializable<Generator>
{
static Fluid getStillFluid(FluidState fluidState) {
Expand Down Expand Up @@ -57,7 +59,7 @@ default Optional<BlockState> tryGenerate(LevelAccessor level, BlockPos pos, Flui
* @return The output block when a source fluid met another fluid (e.g. Water -> Stone / Lava -> Obsidian)
*/
default Map<String, List<WeightedBlock>> getObsidianOutput() {
return Map.of();
return mapOf();
}

@NotNull
Expand Down

0 comments on commit a4603ca

Please sign in to comment.