Skip to content

Commit

Permalink
refactor: Use CGIdentifier in config
Browse files Browse the repository at this point in the history
null2264 committed Dec 6, 2023
1 parent ba3ed2f commit 051d423
Showing 5 changed files with 36 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package io.github.null2264.cobblegen.config;

import io.github.null2264.cobblegen.data.CGIdentifier;

import java.util.List;
import java.util.Map;

public class AdvancedGen
{
public boolean silent = false;
public Map<String, List<WeightedBlock>> results = Map.of();
public Map<String, List<WeightedBlock>> resultsFromTop = Map.of();
public Map<String, List<WeightedBlock>> obsidian = Map.of();
public Map<CGIdentifier, List<WeightedBlock>> results = Map.of();
public Map<CGIdentifier, List<WeightedBlock>> resultsFromTop = Map.of();
public Map<CGIdentifier, List<WeightedBlock>> obsidian = Map.of();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.null2264.cobblegen.config;

import blue.endless.jankson.Comment;
import io.github.null2264.cobblegen.data.CGIdentifier;
import org.jetbrains.annotations.Nullable;

import java.util.List;
@@ -76,20 +77,20 @@ public static ConfigData defaultConfig() {
config.customGen = new CustomGen(
// Cobble Gen
Map.of(
"minecraft:bedrock",
CGIdentifier.of("minecraft:bedrock"),
List.of(
new WeightedBlock("minecraft:emerald_ore", 2.0),
new WeightedBlock("minecraft:diamond_ore", 5.0),
new WeightedBlock("minecraft:lapis_ore", 8.0),
new WeightedBlock("minecraft:gold_ore", 10.0),
new WeightedBlock("minecraft:iron_ore", 15.0),
new WeightedBlock("minecraft:coal_ore", 20.0),
new WeightedBlock("minecraft:cobblestone", 40.0)
new WeightedBlock("minecraft:cobblestone", 80.0)
)
),
// Stone Gen
Map.of(
"minecraft:bedrock",
CGIdentifier.of("minecraft:bedrock"),
List.of(
new WeightedBlock("minecraft:stone", 40.0),
new WeightedBlock("minecraft:diorite", 20.0),
@@ -99,7 +100,7 @@ public static ConfigData defaultConfig() {
),
// Basalt Gen
Map.of(
"minecraft:bedrock",
CGIdentifier.of("minecraft:bedrock"),
List.of(
new WeightedBlock("minecraft:end_stone", 100.0, List.of("minecraft:the_end")),
new WeightedBlock("minecraft:blackstone", 100.0, null, List.of("minecraft:overworld"))
13 changes: 7 additions & 6 deletions src/main/java/io/github/null2264/cobblegen/config/CustomGen.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.null2264.cobblegen.config;

import io.github.null2264.cobblegen.data.CGIdentifier;
import org.jetbrains.annotations.Nullable;

import java.util.List;
@@ -8,19 +9,19 @@
public class CustomGen
{
@Nullable
public Map<String, List<WeightedBlock>> cobbleGen;
public Map<CGIdentifier, List<WeightedBlock>> cobbleGen;
@Nullable
public Map<String, List<WeightedBlock>> stoneGen;
public Map<CGIdentifier, List<WeightedBlock>> stoneGen;
@Nullable
public Map<String, List<WeightedBlock>> basaltGen;
public Map<CGIdentifier, List<WeightedBlock>> basaltGen;

public CustomGen(
@Nullable
Map<String, List<WeightedBlock>> cobbleGen,
Map<CGIdentifier, List<WeightedBlock>> cobbleGen,
@Nullable
Map<String, List<WeightedBlock>> stoneGen,
Map<CGIdentifier, List<WeightedBlock>> stoneGen,
@Nullable
Map<String, List<WeightedBlock>> basaltGen
Map<CGIdentifier, List<WeightedBlock>> basaltGen
) {
this.cobbleGen = cobbleGen;
this.stoneGen = stoneGen;
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package io.github.null2264.cobblegen.data;

import io.github.null2264.cobblegen.util.Util;
import lombok.val;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;

import static io.github.null2264.cobblegen.CobbleGen.MOD_ID;

@@ -48,6 +50,10 @@ public ResourceLocation toMC() {
return new ResourceLocation(modid, name);
}

public static CGIdentifier fromBlock(Block block) {
return fromMC(Util.getBlockId(block));
}

public void writeToBuf(FriendlyByteBuf buf) {
buf.writeUtf(this.toString());
}
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
import io.github.null2264.cobblegen.compat.LoaderCompat;
import io.github.null2264.cobblegen.config.ConfigData;
import io.github.null2264.cobblegen.config.WeightedBlock;
import io.github.null2264.cobblegen.data.CGIdentifier;
import io.github.null2264.cobblegen.data.generator.BasaltGenerator;
import io.github.null2264.cobblegen.data.generator.CobbleGenerator;
import io.github.null2264.cobblegen.data.generator.StoneGenerator;
@@ -59,19 +60,19 @@ public void registerInteraction(CGRegistry registry) {

AtomicInteger count = new AtomicInteger();

Map<String, List<WeightedBlock>> stoneGen = new HashMap<>();
Map<CGIdentifier, List<WeightedBlock>> stoneGen = new HashMap<>();
if (config.customGen != null && config.customGen.stoneGen != null)
stoneGen = new HashMap<>(config.customGen.stoneGen);
Map<String, List<WeightedBlock>> cobbleGen = new HashMap<>();
Map<CGIdentifier, List<WeightedBlock>> cobbleGen = new HashMap<>();
if (config.customGen != null && config.customGen.cobbleGen != null)
cobbleGen = new HashMap<>(config.customGen.cobbleGen);
Map<String, List<WeightedBlock>> basaltGen = new HashMap<>();
Map<CGIdentifier, List<WeightedBlock>> basaltGen = new HashMap<>();
if (config.customGen != null && config.customGen.basaltGen != null)
basaltGen = new HashMap<>(config.customGen.basaltGen);

stoneGen.put(CGBlocks.WILDCARD.toString(), notNullOr(config.stoneGen, new ArrayList<>()));
cobbleGen.put(CGBlocks.WILDCARD.toString(), notNullOr(config.cobbleGen, new ArrayList<>()));
basaltGen.put(CGBlocks.fromBlock(Blocks.SOUL_SOIL), notNullOr(config.basaltGen, new ArrayList<>()));
stoneGen.put(CGIdentifier.wildcard(), notNullOr(config.stoneGen, new ArrayList<>()));
cobbleGen.put(CGIdentifier.wildcard(), notNullOr(config.cobbleGen, new ArrayList<>()));
basaltGen.put(CGIdentifier.fromBlock(Blocks.SOUL_SOIL), notNullOr(config.basaltGen, new ArrayList<>()));

if (config.advanced != null)
config.advanced.forEach((fluid, value) -> {
@@ -86,7 +87,7 @@ public void registerInteraction(CGRegistry registry) {
if (gen.resultsFromTop != null && !gen.resultsFromTop.isEmpty()) {
registry.addGenerator(
actualFluid,
StoneGenerator.fromString(
new StoneGenerator(
gen.resultsFromTop,
getFluidFromString(neighbour),
gen.silent
@@ -98,19 +99,19 @@ public void registerInteraction(CGRegistry registry) {
if (!results.isEmpty()) {
Generator generator;
if (isNeighbourBlock)
generator = BasaltGenerator.fromString(results, getBlockFromString(neighbour), gen.silent);
generator = new BasaltGenerator(results, getBlockFromString(neighbour), gen.silent);
else
generator = CobbleGenerator.fromString(results, getFluidFromString(neighbour), gen.silent, obi);
generator = new CobbleGenerator(results, getFluidFromString(neighbour), gen.silent, obi);

registry.addGenerator(actualFluid, generator);
count.getAndIncrement();
}
});
});

registry.addGenerator(Fluids.LAVA, StoneGenerator.fromString(stoneGen, Fluids.WATER, false));
registry.addGenerator(Fluids.LAVA, CobbleGenerator.fromString(cobbleGen, Fluids.WATER, false, Map.of()));
registry.addGenerator(Fluids.LAVA, BasaltGenerator.fromString(basaltGen, Blocks.BLUE_ICE, false));
registry.addGenerator(Fluids.LAVA, new StoneGenerator(stoneGen, Fluids.WATER, false));
registry.addGenerator(Fluids.LAVA, new CobbleGenerator(cobbleGen, Fluids.WATER, false, Map.of()));
registry.addGenerator(Fluids.LAVA, new BasaltGenerator(basaltGen, Blocks.BLUE_ICE, false));
count.addAndGet(3);

CGLog.info(String.valueOf(count.get()), "generators has been added from config");

0 comments on commit 051d423

Please sign in to comment.