refactor: delombok and move version info to Versions.kt

This commit is contained in:
daoge_cmd
2024-10-14 20:55:11 +08:00
parent cc14c716bf
commit 8a6ad95947
5 changed files with 45 additions and 37 deletions

View File

@@ -75,4 +75,9 @@ object Versions {
const val nbt = "6.1"
const val logback = "1.5.8"
}
object Allay {
const val api = "master-SNAPSHOT"
}
}

View File

@@ -1,9 +1,5 @@
dependencies {
shadedApi(project(":common:implementation:base"))
implementation("com.google.code.gson", "gson", "2.11.0")
compileOnly("org.projectlombok:lombok:1.18.32")
compileOnly("org.allaymc.allay:api:master-SNAPSHOT")
annotationProcessor("org.projectlombok:lombok:1.18.32")
}
compileOnly("org.allaymc.allay", "api", Versions.Allay.api)
}

View File

@@ -4,7 +4,6 @@ import com.google.gson.reflect.TypeToken;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import lombok.extern.slf4j.Slf4j;
import org.allaymc.api.block.type.BlockState;
import org.allaymc.api.block.type.BlockStateSafeGetter;
import org.allaymc.api.block.type.BlockTypes;
@@ -21,7 +20,6 @@ import java.util.TreeMap;
/**
* @author daoge_cmd
*/
@Slf4j
public final class Mapping {
private static final Map<String, Map<String, String>> JE_BLOCK_DEFAULT_PROPERTIES = new Object2ObjectOpenHashMap<>();
@@ -45,7 +43,7 @@ public final class Mapping {
public static BlockState blockStateJeToBe(JeBlockState jeBlockState) {
var result = BLOCK_STATE_JE_HASH_TO_BE.get(jeBlockState.getHash());
if(result == null) {
log.warn("Failed to find be block state for {}", jeBlockState);
TerraAllayPlugin.INSTANCE.getPluginLogger().warn("Failed to find be block state for {}", jeBlockState);
return BE_AIR_STATE;
}
return result;
@@ -72,7 +70,7 @@ public final class Mapping {
public static Map<String, String> getJeBlockDefaultProperties(String jeBlockIdentifier) {
var defaultProperties = JE_BLOCK_DEFAULT_PROPERTIES.get(jeBlockIdentifier);
if( defaultProperties == null) {
log.warn("Failed to find default properties for {}", jeBlockIdentifier);
TerraAllayPlugin.INSTANCE.getPluginLogger().warn("Failed to find default properties for {}", jeBlockIdentifier);
return Map.of();
}
return defaultProperties;
@@ -85,7 +83,7 @@ public final class Mapping {
private static boolean initBiomeMapping() {
try (var stream = Mapping.class.getClassLoader().getResourceAsStream("mapping/biomes_JE_1_21_to_BE_1_21_30.json")) {
if (stream == null) {
log.error("biomes mapping not found");
TerraAllayPlugin.INSTANCE.getPluginLogger().error("biomes mapping not found");
return false;
}
var mappings = JSONUtils.from(stream, new TypeToken<Map<String, Map<String, Integer>>>(){}).entrySet();
@@ -93,7 +91,7 @@ public final class Mapping {
BIOME_ID_JE_TO_BE.put(mapping.getKey(), mapping.getValue().get("bedrock_id"));
}
} catch(IOException e) {
log.error("Failed to load biomes mapping", e);
TerraAllayPlugin.INSTANCE.getPluginLogger().error("Failed to load biomes mapping", e);
return false;
}
return true;
@@ -102,7 +100,7 @@ public final class Mapping {
private static boolean initItemMapping() {
try (var stream = Mapping.class.getClassLoader().getResourceAsStream("mapping/items_JE_1_21_to_BE_1_21_30.json")) {
if (stream == null) {
log.error("items mapping not found");
TerraAllayPlugin.INSTANCE.getPluginLogger().error("items mapping not found");
return false;
}
var mappings = JSONUtils.from(stream, new TypeToken<Map<String, Map<String, Object>>>(){}).entrySet();
@@ -115,7 +113,7 @@ public final class Mapping {
ITEM_ID_JE_TO_BE.put(mapping.getKey(), item);
}
} catch(IOException e) {
log.error("Failed to load items mapping", e);
TerraAllayPlugin.INSTANCE.getPluginLogger().error("Failed to load items mapping", e);
}
return true;
}
@@ -123,7 +121,7 @@ public final class Mapping {
private static boolean initBlockStateMapping() {
try (var stream = Mapping.class.getClassLoader().getResourceAsStream("mapping/blocks_JE_1_21_to_BE_1_21_30.json")) {
if (stream == null) {
log.error("blocks mapping not found");
TerraAllayPlugin.INSTANCE.getPluginLogger().error("blocks mapping not found");
return false;
}
// noinspection unchecked
@@ -135,7 +133,7 @@ public final class Mapping {
BLOCK_STATE_JE_HASH_TO_BE.put(jeState.getHash(), beState);
}
} catch(IOException e) {
log.error("Failed to load blocks mapping", e);
TerraAllayPlugin.INSTANCE.getPluginLogger().error("Failed to load blocks mapping", e);
}
return true;
}
@@ -143,7 +141,7 @@ public final class Mapping {
private static boolean initJeBlockDefaultProperties() {
try (var stream = Mapping.class.getClassLoader().getResourceAsStream("je_block_default_states_1_21.json")) {
if (stream == null) {
log.error("je_block_default_states.json not found");
TerraAllayPlugin.INSTANCE.getPluginLogger().error("je_block_default_states.json not found");
return false;
}
var states = JSONUtils.from(stream, new TypeToken<Map<String, Map<String, String>>>(){});

View File

@@ -1,6 +1,5 @@
package org.allaymc.terra.allay;
import lombok.extern.slf4j.Slf4j;
import org.allaymc.api.plugin.Plugin;
import org.allaymc.api.registry.Registries;
import org.allaymc.terra.allay.generator.AllayGeneratorWrapper;
@@ -10,7 +9,6 @@ import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
/**
* @author daoge_cmd
*/
@Slf4j
public class TerraAllayPlugin extends Plugin {
public static TerraAllayPlugin INSTANCE;
@@ -23,18 +21,18 @@ public class TerraAllayPlugin extends Plugin {
// TODO: Adapt command manager
@Override
public void onLoad() {
log.info("Starting Terra...");
pluginLogger.info("Starting Terra...");
log.info("Loading mapping...");
pluginLogger.info("Loading mapping...");
Mapping.init();
log.info("Initializing allay platform...");
pluginLogger.info("Initializing allay platform...");
PLATFORM = new AllayPlatform();
PLATFORM.getEventManager().callEvent(new PlatformInitializationEvent());
log.info("Registering generator...");
pluginLogger.info("Registering generator...");
Registries.WORLD_GENERATOR_FACTORIES.register("TERRA", preset -> new AllayGeneratorWrapper(preset).getAllayWorldGenerator());
log.info("Terra started");
pluginLogger.info("Terra started");
}
}

View File

@@ -1,7 +1,5 @@
package org.allaymc.terra.allay.generator;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.allaymc.api.utils.AllayStringUtils;
import org.allaymc.api.world.biome.BiomeType;
import org.allaymc.api.world.generator.WorldGenerator;
@@ -22,24 +20,20 @@ import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
import com.dfsek.terra.api.world.chunk.generation.util.GeneratorWrapper;
import com.dfsek.terra.api.world.info.WorldProperties;
/**
* @author daoge_cmd
*/
@Slf4j
public class AllayGeneratorWrapper implements GeneratorWrapper {
protected static final String DEFAULT_PACK_NAME = "overworld";
protected static final String OPTION_PACK_NAME = "pack";
protected static final String OPTION_SEED = "seed";
@Getter
protected final BiomeProvider biomeProvider;
@Getter
protected final ConfigPack configPack;
protected final ChunkGenerator chunkGenerator;
@Getter
protected final long seed;
@Getter
protected final WorldGenerator allayWorldGenerator;
protected WorldProperties worldProperties;
protected AllayServerWorld allayServerWorld;
@@ -101,9 +95,9 @@ public class AllayGeneratorWrapper implements GeneratorWrapper {
);
var minHeight = context.getDimensionInfo().minHeight();
var maxHeight = context.getDimensionInfo().maxHeight();
for (int x = 0; x < 16; x++) {
for (int y = minHeight; y < maxHeight; y++) {
for (int z = 0; z < 16; z++) {
for(int x = 0; x < 16; x++) {
for(int y = minHeight; y < maxHeight; y++) {
for(int z = 0; z < 16; z++) {
chunk.setBiome(
x, y, z,
(BiomeType) biomeProvider.getBiome(chunkX * 16 + x, y, chunkZ * 16 + z, seed).getPlatformBiome().getHandle()
@@ -120,17 +114,18 @@ public class AllayGeneratorWrapper implements GeneratorWrapper {
}
}
public class AllayPopulator implements Populator {
@Override
public boolean apply(PopulateContext context) {
var tmp = new AllayProtoWorld(allayServerWorld, context);
try {
for (var generationStage : configPack.getStages()) {
for(var generationStage : configPack.getStages()) {
generationStage.populate(tmp);
}
} catch (Exception e) {
log.error("Error while populating chunk", e);
} catch(Exception e) {
TerraAllayPlugin.INSTANCE.getPluginLogger().error("Error while populating chunk", e);
}
return true;
}
@@ -157,4 +152,20 @@ public class AllayGeneratorWrapper implements GeneratorWrapper {
public ChunkGenerator getHandle() {
return chunkGenerator;
}
public BiomeProvider getBiomeProvider() {
return this.biomeProvider;
}
public ConfigPack getConfigPack() {
return this.configPack;
}
public long getSeed() {
return this.seed;
}
public WorldGenerator getAllayWorldGenerator() {
return this.allayWorldGenerator;
}
}