refactor: replace 'var' with explicit type

This commit is contained in:
daoge_cmd
2024-10-14 21:13:00 +08:00
parent b0bc37c34d
commit 8d63c40e2f
11 changed files with 75 additions and 63 deletions

View File

@@ -2,6 +2,7 @@ package com.dfsek.terra.allay;
import org.allaymc.api.utils.HashUtils; import org.allaymc.api.utils.HashUtils;
import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
@@ -22,13 +23,13 @@ public class JeBlockState {
} }
private JeBlockState(String data) { private JeBlockState(String data) {
var strings = data.replace("[", ",").replace("]", ",").replace(" ", "").split(","); String[] strings = data.replace("[", ",").replace("]", ",").replace(" ", "").split(",");
this.identifier = strings[0]; this.identifier = strings[0];
this.properties = new TreeMap<>(); this.properties = new TreeMap<>();
if (strings.length > 1) { if (strings.length > 1) {
for (int i = 1; i < strings.length; i++) { for (int i = 1; i < strings.length; i++) {
final var tmp = strings[i]; final String tmp = strings[i];
final var index = tmp.indexOf("="); final int index = tmp.indexOf("=");
properties.put(tmp.substring(0, index), tmp.substring(index + 1)); properties.put(tmp.substring(0, index), tmp.substring(index + 1));
} }
} }
@@ -40,14 +41,12 @@ public class JeBlockState {
} }
private void completeMissingProperties() { private void completeMissingProperties() {
var defaultProperties = Mapping.getJeBlockDefaultProperties(identifier); Map<String, String> defaultProperties = Mapping.getJeBlockDefaultProperties(identifier);
if(properties.size() == defaultProperties.size()) { if(properties.size() == defaultProperties.size()) {
return; return;
} }
for (var entry : defaultProperties.entrySet()) { defaultProperties.entrySet().stream().filter(entry -> !properties.containsKey(entry.getKey())).forEach(
if (properties.containsKey(entry.getKey())) continue; entry -> properties.put(entry.getKey(), entry.getValue()));
properties.put(entry.getKey(), entry.getValue());
}
} }
private JeBlockState(String identifier, TreeMap<String, String> properties) { private JeBlockState(String identifier, TreeMap<String, String> properties) {
@@ -59,7 +58,7 @@ public class JeBlockState {
if(!includeProperties) return identifier; if(!includeProperties) return identifier;
StringBuilder builder = new StringBuilder(identifier).append(";"); StringBuilder builder = new StringBuilder(identifier).append(";");
properties.forEach((k, v) -> builder.append(k).append("=").append(v).append(";")); properties.forEach((k, v) -> builder.append(k).append("=").append(v).append(";"));
var str = builder.toString(); String str = builder.toString();
if (hash == Integer.MAX_VALUE) { if (hash == Integer.MAX_VALUE) {
hash = HashUtils.fnv1a_32(str.getBytes()); hash = HashUtils.fnv1a_32(str.getBytes());
} }

View File

@@ -6,14 +6,18 @@ import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import org.allaymc.api.block.type.BlockState; import org.allaymc.api.block.type.BlockState;
import org.allaymc.api.block.type.BlockStateSafeGetter; import org.allaymc.api.block.type.BlockStateSafeGetter;
import org.allaymc.api.block.type.BlockStateSafeGetter.Getter;
import org.allaymc.api.block.type.BlockTypes; import org.allaymc.api.block.type.BlockTypes;
import org.allaymc.api.item.type.ItemType; import org.allaymc.api.item.type.ItemType;
import org.allaymc.api.item.type.ItemTypeSafeGetter; import org.allaymc.api.item.type.ItemTypeSafeGetter;
import org.allaymc.api.utils.JSONUtils; import org.allaymc.api.utils.JSONUtils;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap; import java.util.TreeMap;
@@ -41,7 +45,7 @@ public final class Mapping {
} }
public static BlockState blockStateJeToBe(JeBlockState jeBlockState) { public static BlockState blockStateJeToBe(JeBlockState jeBlockState) {
var result = BLOCK_STATE_JE_HASH_TO_BE.get(jeBlockState.getHash()); BlockState result = BLOCK_STATE_JE_HASH_TO_BE.get(jeBlockState.getHash());
if(result == null) { if(result == null) {
TerraAllayPlugin.INSTANCE.getPluginLogger().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 BE_AIR_STATE;
@@ -68,7 +72,7 @@ public final class Mapping {
} }
public static Map<String, String> getJeBlockDefaultProperties(String jeBlockIdentifier) { public static Map<String, String> getJeBlockDefaultProperties(String jeBlockIdentifier) {
var defaultProperties = JE_BLOCK_DEFAULT_PROPERTIES.get(jeBlockIdentifier); Map<String, String> defaultProperties = JE_BLOCK_DEFAULT_PROPERTIES.get(jeBlockIdentifier);
if( defaultProperties == null) { if( defaultProperties == null) {
TerraAllayPlugin.INSTANCE.getPluginLogger().warn("Failed to find default properties for {}", jeBlockIdentifier); TerraAllayPlugin.INSTANCE.getPluginLogger().warn("Failed to find default properties for {}", jeBlockIdentifier);
return Map.of(); return Map.of();
@@ -81,15 +85,13 @@ public final class Mapping {
} }
private static boolean initBiomeMapping() { private static boolean initBiomeMapping() {
try (var stream = Mapping.class.getClassLoader().getResourceAsStream("mapping/biomes.json")) { try (InputStream stream = Mapping.class.getClassLoader().getResourceAsStream("mapping/biomes.json")) {
if (stream == null) { if (stream == null) {
TerraAllayPlugin.INSTANCE.getPluginLogger().error("biomes mapping not found"); TerraAllayPlugin.INSTANCE.getPluginLogger().error("biomes mapping not found");
return false; return false;
} }
var mappings = JSONUtils.from(stream, new TypeToken<Map<String, Map<String, Integer>>>(){}).entrySet(); Set<Entry<String, Map<String, Integer>>> mappings = JSONUtils.from(stream, new TypeToken<Map<String, Map<String, Integer>>>(){}).entrySet();
for(var mapping : mappings) { mappings.forEach(mapping -> BIOME_ID_JE_TO_BE.put(mapping.getKey(), mapping.getValue().get("bedrock_id")));
BIOME_ID_JE_TO_BE.put(mapping.getKey(), mapping.getValue().get("bedrock_id"));
}
} catch(IOException e) { } catch(IOException e) {
TerraAllayPlugin.INSTANCE.getPluginLogger().error("Failed to load biomes mapping", e); TerraAllayPlugin.INSTANCE.getPluginLogger().error("Failed to load biomes mapping", e);
return false; return false;
@@ -98,20 +100,20 @@ public final class Mapping {
} }
private static boolean initItemMapping() { private static boolean initItemMapping() {
try (var stream = Mapping.class.getClassLoader().getResourceAsStream("mapping/items.json")) { try (InputStream stream = Mapping.class.getClassLoader().getResourceAsStream("mapping/items.json")) {
if (stream == null) { if (stream == null) {
TerraAllayPlugin.INSTANCE.getPluginLogger().error("items mapping not found"); TerraAllayPlugin.INSTANCE.getPluginLogger().error("items mapping not found");
return false; return false;
} }
var mappings = JSONUtils.from(stream, new TypeToken<Map<String, Map<String, Object>>>(){}).entrySet(); Set<Entry<String, Map<String, Object>>> mappings = JSONUtils.from(stream, new TypeToken<Map<String, Map<String, Object>>>(){}).entrySet();
for(var mapping : mappings) { mappings.forEach(mapping -> {
var item = ItemTypeSafeGetter ItemType<?> item = ItemTypeSafeGetter
.name((String) mapping.getValue().get("bedrock_identifier")) .name((String) mapping.getValue().get("bedrock_identifier"))
// NOTICE: should be cast to double // NOTICE: should be cast to double
.meta(((Double) mapping.getValue().get("bedrock_data")).intValue()) .meta(((Double) mapping.getValue().get("bedrock_data")).intValue())
.itemType(); .itemType();
ITEM_ID_JE_TO_BE.put(mapping.getKey(), item); ITEM_ID_JE_TO_BE.put(mapping.getKey(), item);
} });
} catch(IOException e) { } catch(IOException e) {
TerraAllayPlugin.INSTANCE.getPluginLogger().error("Failed to load items mapping", e); TerraAllayPlugin.INSTANCE.getPluginLogger().error("Failed to load items mapping", e);
} }
@@ -119,19 +121,19 @@ public final class Mapping {
} }
private static boolean initBlockStateMapping() { private static boolean initBlockStateMapping() {
try (var stream = Mapping.class.getClassLoader().getResourceAsStream("mapping/blocks.json")) { try (InputStream stream = Mapping.class.getClassLoader().getResourceAsStream("mapping/blocks.json")) {
if (stream == null) { if (stream == null) {
TerraAllayPlugin.INSTANCE.getPluginLogger().error("blocks mapping not found"); TerraAllayPlugin.INSTANCE.getPluginLogger().error("blocks mapping not found");
return false; return false;
} }
// noinspection unchecked // noinspection unchecked
var mappings = (List<Map<String, Map<String, Object>>>) JSONUtils.from(stream, new TypeToken<Map<String, Object>>(){}).get("mappings"); List<Map<String, Map<String, Object>>> mappings = (List<Map<String, Map<String, Object>>>) JSONUtils.from(stream, new TypeToken<Map<String, Object>>(){}).get("mappings");
for(var mapping : mappings) { mappings.forEach(mapping -> {
var jeState = createJeBlockState(mapping.get("java_state")); JeBlockState jeState = createJeBlockState(mapping.get("java_state"));
var beState = createBeBlockState(mapping.get("bedrock_state")); BlockState beState = createBeBlockState(mapping.get("bedrock_state"));
BLOCK_STATE_BE_TO_JE.put(beState, jeState); BLOCK_STATE_BE_TO_JE.put(beState, jeState);
BLOCK_STATE_JE_HASH_TO_BE.put(jeState.getHash(), beState); BLOCK_STATE_JE_HASH_TO_BE.put(jeState.getHash(), beState);
} });
} catch(IOException e) { } catch(IOException e) {
TerraAllayPlugin.INSTANCE.getPluginLogger().error("Failed to load blocks mapping", e); TerraAllayPlugin.INSTANCE.getPluginLogger().error("Failed to load blocks mapping", e);
} }
@@ -139,15 +141,15 @@ public final class Mapping {
} }
private static boolean initJeBlockDefaultProperties() { private static boolean initJeBlockDefaultProperties() {
try (var stream = Mapping.class.getClassLoader().getResourceAsStream("je_block_default_states.json")) { try (InputStream stream = Mapping.class.getClassLoader().getResourceAsStream("je_block_default_states.json")) {
if (stream == null) { if (stream == null) {
TerraAllayPlugin.INSTANCE.getPluginLogger().error("je_block_default_states.json not found"); TerraAllayPlugin.INSTANCE.getPluginLogger().error("je_block_default_states.json not found");
return false; return false;
} }
var states = JSONUtils.from(stream, new TypeToken<Map<String, Map<String, String>>>(){}); Map<String, Map<String, String>> states = JSONUtils.from(stream, new TypeToken<Map<String, Map<String, String>>>(){});
for(var entry : states.entrySet()) { for(Entry<String, Map<String, String>> entry : states.entrySet()) {
var identifier = entry.getKey(); String identifier = entry.getKey();
var properties = entry.getValue(); Map<String, String> properties = entry.getValue();
JE_BLOCK_DEFAULT_PROPERTIES.put(identifier, properties); JE_BLOCK_DEFAULT_PROPERTIES.put(identifier, properties);
} }
} catch(IOException e) { } catch(IOException e) {
@@ -157,7 +159,7 @@ public final class Mapping {
} }
private static BlockState createBeBlockState(Map<String, Object> data) { private static BlockState createBeBlockState(Map<String, Object> data) {
var getter = BlockStateSafeGetter Getter getter = BlockStateSafeGetter
.name("minecraft:" + data.get("bedrock_identifier")); .name("minecraft:" + data.get("bedrock_identifier"));
if (data.containsKey("state")) { if (data.containsKey("state")) {
// noinspection unchecked // noinspection unchecked
@@ -167,8 +169,8 @@ public final class Mapping {
} }
private static Map<String, Object> convertValueType(Map<String, Object> data) { private static Map<String, Object> convertValueType(Map<String, Object> data) {
var result = new TreeMap<String, Object>(); TreeMap<String, Object> result = new TreeMap<>();
for (var entry : data.entrySet()) { for (Entry<String, Object> entry : data.entrySet()) {
if (entry.getValue() instanceof Number number) { if (entry.getValue() instanceof Number number) {
// Convert double to int because the number in json is double // Convert double to int because the number in json is double
result.put(entry.getKey(), number.intValue()); result.put(entry.getKey(), number.intValue());
@@ -180,8 +182,7 @@ public final class Mapping {
} }
private static JeBlockState createJeBlockState(Map<String, Object> data) { private static JeBlockState createJeBlockState(Map<String, Object> data) {
var identifier = (String) data.get("Name");
// noinspection unchecked // noinspection unchecked
return JeBlockState.create(identifier, new TreeMap<>((Map<String, String>) data.getOrDefault("Properties", Map.of()))); return JeBlockState.create((String) data.get("Name"), new TreeMap<>((Map<String, String>) data.getOrDefault("Properties", Map.of())));
} }
} }

View File

@@ -27,7 +27,7 @@ public final class AllayBlockState implements com.dfsek.terra.api.block.state.Bl
@Override @Override
public boolean matches(com.dfsek.terra.api.block.state.BlockState o) { public boolean matches(com.dfsek.terra.api.block.state.BlockState o) {
var other = ((AllayBlockState) o); AllayBlockState other = ((AllayBlockState) o);
return other.allayBlockState == this.allayBlockState && other.containsWater == this.containsWater; return other.allayBlockState == this.allayBlockState && other.containsWater == this.containsWater;
} }

View File

@@ -19,9 +19,9 @@ public record AllayChunk(ServerWorld world, Chunk allayChunk) implements com.dfs
@Override @Override
public void setBlock(int x, int y, int z, BlockState data, boolean physics) { public void setBlock(int x, int y, int z, BlockState data, boolean physics) {
var allayBlockState = (AllayBlockState) data; AllayBlockState allayBlockState = (AllayBlockState) data;
allayChunk.setBlockState(x, y, z, allayBlockState.allayBlockState()); allayChunk.setBlockState(x, y, z, allayBlockState.allayBlockState());
var containsWater = allayBlockState.containsWater() || allayChunk.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER); boolean containsWater = allayBlockState.containsWater() || allayChunk.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER);
if (containsWater) { if (containsWater) {
allayChunk.setBlockState(x, y, z, WATER, 1); allayChunk.setBlockState(x, y, z, WATER, 1);
} }
@@ -29,7 +29,7 @@ public record AllayChunk(ServerWorld world, Chunk allayChunk) implements com.dfs
@Override @Override
public @NotNull BlockState getBlock(int x, int y, int z) { public @NotNull BlockState getBlock(int x, int y, int z) {
var blockState = allayChunk.getBlockState(x, y, z); org.allaymc.api.block.type.BlockState blockState = allayChunk.getBlockState(x, y, z);
return new AllayBlockState(blockState, Mapping.blockStateBeToJe(blockState)); return new AllayBlockState(blockState, Mapping.blockStateBeToJe(blockState));
} }

View File

@@ -8,20 +8,24 @@ import java.util.Map;
import com.dfsek.terra.api.inventory.item.Enchantment; import com.dfsek.terra.api.inventory.item.Enchantment;
import com.dfsek.terra.api.inventory.item.ItemMeta; import com.dfsek.terra.api.inventory.item.ItemMeta;
import org.allaymc.api.item.enchantment.EnchantmentInstance;
import org.allaymc.api.item.enchantment.EnchantmentType;
/** /**
* @author daoge_cmd * @author daoge_cmd
*/ */
public record AllayItemMeta(ItemStack allayItemStack) implements ItemMeta { public record AllayItemMeta(ItemStack allayItemStack) implements ItemMeta {
@Override @Override
public void addEnchantment(Enchantment enchantment, int level) { public void addEnchantment(Enchantment enchantment, int level) {
var allayEnchantment = ((AllayEnchantment) enchantment).allayEnchantment(); EnchantmentType allayEnchantment = ((AllayEnchantment) enchantment).allayEnchantment();
allayItemStack.addEnchantment(allayEnchantment, (short) level); allayItemStack.addEnchantment(allayEnchantment, (short) level);
} }
@Override @Override
public Map<Enchantment, Integer> getEnchantments() { public Map<Enchantment, Integer> getEnchantments() {
Map<Enchantment, Integer> results = new HashMap<>(); Map<Enchantment, Integer> results = new HashMap<>();
for (var allayEnchantmentInstance : allayItemStack.getEnchantments()) { for (EnchantmentInstance allayEnchantmentInstance : allayItemStack.getEnchantments()) {
results.put(new AllayEnchantment(allayEnchantmentInstance.getType()), allayEnchantmentInstance.getLevel()); results.put(new AllayEnchantment(allayEnchantmentInstance.getType()), allayEnchantmentInstance.getLevel());
} }
return results; return results;

View File

@@ -5,6 +5,9 @@ import org.allaymc.api.item.ItemStack;
import com.dfsek.terra.api.inventory.Item; import com.dfsek.terra.api.inventory.Item;
import com.dfsek.terra.api.inventory.item.ItemMeta; import com.dfsek.terra.api.inventory.item.ItemMeta;
import org.allaymc.api.item.enchantment.EnchantmentInstance;
/** /**
* @author daoge_cmd * @author daoge_cmd
*/ */
@@ -31,9 +34,9 @@ public record AllayItemStack(ItemStack allayItemStack) implements com.dfsek.terr
@Override @Override
public void setItemMeta(ItemMeta meta) { public void setItemMeta(ItemMeta meta) {
var targetItem = ((AllayItemMeta) meta).allayItemStack(); ItemStack targetItem = ((AllayItemMeta) meta).allayItemStack();
allayItemStack.removeAllEnchantments(); allayItemStack.removeAllEnchantments();
for (var enchantment : targetItem.getEnchantments()) { for (EnchantmentInstance enchantment : targetItem.getEnchantments()) {
allayItemStack.addEnchantment(enchantment.getType(), enchantment.getLevel()); allayItemStack.addEnchantment(enchantment.getType(), enchantment.getLevel());
} }
allayItemStack.setLore(targetItem.getLore()); allayItemStack.setLore(targetItem.getLore());

View File

@@ -24,9 +24,9 @@ public record AllayProtoChunk(UnsafeChunk allayChunk) implements ProtoChunk {
@Override @Override
public void setBlock(int x, int y, int z, @NotNull BlockState blockState) { public void setBlock(int x, int y, int z, @NotNull BlockState blockState) {
var allayBlockState = (AllayBlockState) blockState; AllayBlockState allayBlockState = (AllayBlockState) blockState;
allayChunk.setBlockState(x, y, z, allayBlockState.allayBlockState()); allayChunk.setBlockState(x, y, z, allayBlockState.allayBlockState());
var containsWater = allayBlockState.containsWater() || allayChunk.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER); boolean containsWater = allayBlockState.containsWater() || allayChunk.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER);
if (containsWater) { if (containsWater) {
allayChunk.setBlockState(x, y, z, WATER, 1); allayChunk.setBlockState(x, y, z, WATER, 1);
} }
@@ -34,7 +34,7 @@ public record AllayProtoChunk(UnsafeChunk allayChunk) implements ProtoChunk {
@Override @Override
public @NotNull BlockState getBlock(int x, int y, int z) { public @NotNull BlockState getBlock(int x, int y, int z) {
var blockState = allayChunk.getBlockState(x, y, z); org.allaymc.api.block.type.BlockState blockState = allayChunk.getBlockState(x, y, z);
return new AllayBlockState(blockState, Mapping.blockStateBeToJe(blockState)); return new AllayBlockState(blockState, Mapping.blockStateBeToJe(blockState));
} }

View File

@@ -41,15 +41,15 @@ public record AllayProtoWorld(AllayServerWorld allayServerWorld, OtherChunkAcces
@Override @Override
public void setBlockState(int x, int y, int z, BlockState data, boolean physics) { public void setBlockState(int x, int y, int z, BlockState data, boolean physics) {
var allayBlockState = (AllayBlockState)data; AllayBlockState allayBlockState = (AllayBlockState)data;
var containsWater = allayBlockState.containsWater() || context.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER); boolean containsWater = allayBlockState.containsWater() || context.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER);
context.setBlockState(x, y, z, allayBlockState.allayBlockState()); context.setBlockState(x, y, z, allayBlockState.allayBlockState());
if (containsWater) context.setBlockState(x, y, z, WATER, 1); if (containsWater) context.setBlockState(x, y, z, WATER, 1);
} }
@Override @Override
public BlockState getBlockState(int x, int y, int z) { public BlockState getBlockState(int x, int y, int z) {
var blockState = context.getBlockState(x, y, z); org.allaymc.api.block.type.BlockState blockState = context.getBlockState(x, y, z);
return new AllayBlockState(blockState, Mapping.blockStateBeToJe(blockState)); return new AllayBlockState(blockState, Mapping.blockStateBeToJe(blockState));
} }

View File

@@ -42,7 +42,7 @@ public record AllayServerWorld(AllayGeneratorWrapper allayGeneratorWrapper, Dime
@Override @Override
public BlockState getBlockState(int x, int y, int z) { public BlockState getBlockState(int x, int y, int z) {
var allayBlockState = allayDimension.getBlockState(x, y, z); org.allaymc.api.block.type.BlockState allayBlockState = allayDimension.getBlockState(x, y, z);
return new AllayBlockState(allayBlockState, Mapping.blockStateBeToJe(allayBlockState)); return new AllayBlockState(allayBlockState, Mapping.blockStateBeToJe(allayBlockState));
} }

View File

@@ -1,7 +1,10 @@
package com.dfsek.terra.allay.generator; package com.dfsek.terra.allay.generator;
import com.dfsek.terra.api.world.chunk.generation.stage.GenerationStage;
import org.allaymc.api.utils.AllayStringUtils; import org.allaymc.api.utils.AllayStringUtils;
import org.allaymc.api.world.biome.BiomeType; import org.allaymc.api.world.biome.BiomeType;
import org.allaymc.api.world.chunk.UnsafeChunk;
import org.allaymc.api.world.generator.WorldGenerator; import org.allaymc.api.world.generator.WorldGenerator;
import org.allaymc.api.world.generator.context.NoiseContext; import org.allaymc.api.world.generator.context.NoiseContext;
import org.allaymc.api.world.generator.context.PopulateContext; import org.allaymc.api.world.generator.context.PopulateContext;
@@ -13,6 +16,8 @@ import com.dfsek.terra.allay.delegate.AllayProtoWorld;
import com.dfsek.terra.allay.delegate.AllayServerWorld; import com.dfsek.terra.allay.delegate.AllayServerWorld;
import java.util.Locale; import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import com.dfsek.terra.api.config.ConfigPack; import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.world.biome.generation.BiomeProvider; import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
@@ -39,8 +44,8 @@ public class AllayGeneratorWrapper implements GeneratorWrapper {
protected AllayServerWorld allayServerWorld; protected AllayServerWorld allayServerWorld;
public AllayGeneratorWrapper(String preset) { public AllayGeneratorWrapper(String preset) {
var options = AllayStringUtils.parseOptions(preset); Map<String, String> options = AllayStringUtils.parseOptions(preset);
var packName = options.getOrDefault(OPTION_PACK_NAME, DEFAULT_PACK_NAME); String packName = options.getOrDefault(OPTION_PACK_NAME, DEFAULT_PACK_NAME);
this.seed = Long.parseLong(options.getOrDefault(OPTION_SEED, "0")); this.seed = Long.parseLong(options.getOrDefault(OPTION_SEED, "0"));
this.configPack = createConfigPack(packName); this.configPack = createConfigPack(packName);
this.chunkGenerator = createGenerator(this.configPack); this.chunkGenerator = createGenerator(this.configPack);
@@ -85,16 +90,16 @@ public class AllayGeneratorWrapper implements GeneratorWrapper {
@Override @Override
public boolean apply(NoiseContext context) { public boolean apply(NoiseContext context) {
var chunk = context.getCurrentChunk(); UnsafeChunk chunk = context.getCurrentChunk();
var chunkX = chunk.getX(); int chunkX = chunk.getX();
var chunkZ = chunk.getZ(); int chunkZ = chunk.getZ();
chunkGenerator.generateChunkData( chunkGenerator.generateChunkData(
new AllayProtoChunk(chunk), new AllayProtoChunk(chunk),
worldProperties, biomeProvider, worldProperties, biomeProvider,
chunkX, chunkZ chunkX, chunkZ
); );
var minHeight = context.getDimensionInfo().minHeight(); int minHeight = context.getDimensionInfo().minHeight();
var maxHeight = context.getDimensionInfo().maxHeight(); int maxHeight = context.getDimensionInfo().maxHeight();
for(int x = 0; x < 16; x++) { for(int x = 0; x < 16; x++) {
for(int y = minHeight; y < maxHeight; y++) { for(int y = minHeight; y < maxHeight; y++) {
for(int z = 0; z < 16; z++) { for(int z = 0; z < 16; z++) {
@@ -119,9 +124,9 @@ public class AllayGeneratorWrapper implements GeneratorWrapper {
@Override @Override
public boolean apply(PopulateContext context) { public boolean apply(PopulateContext context) {
var tmp = new AllayProtoWorld(allayServerWorld, context); AllayProtoWorld tmp = new AllayProtoWorld(allayServerWorld, context);
try { try {
for(var generationStage : configPack.getStages()) { for(GenerationStage generationStage : configPack.getStages()) {
generationStage.populate(tmp); generationStage.populate(tmp);
} }
} catch(Exception e) { } catch(Exception e) {
@@ -137,7 +142,7 @@ public class AllayGeneratorWrapper implements GeneratorWrapper {
} }
protected static ConfigPack createConfigPack(String packName) { protected static ConfigPack createConfigPack(String packName) {
var byId = TerraAllayPlugin.PLATFORM.getConfigRegistry().getByID(packName); Optional<ConfigPack> byId = TerraAllayPlugin.PLATFORM.getConfigRegistry().getByID(packName);
return byId.orElseGet( return byId.orElseGet(
() -> TerraAllayPlugin.PLATFORM.getConfigRegistry().getByID(packName.toUpperCase(Locale.ENGLISH)) () -> TerraAllayPlugin.PLATFORM.getConfigRegistry().getByID(packName.toUpperCase(Locale.ENGLISH))
.orElseThrow(() -> new IllegalArgumentException("Cant find terra config pack named " + packName)) .orElseThrow(() -> new IllegalArgumentException("Cant find terra config pack named " + packName))

View File

@@ -16,7 +16,7 @@ public class AllayWorldHandle implements WorldHandle {
@Override @Override
public @NotNull BlockState createBlockState(@NotNull String data) { public @NotNull BlockState createBlockState(@NotNull String data) {
var jeBlockState = JeBlockState.fromString(data); JeBlockState jeBlockState = JeBlockState.fromString(data);
return new AllayBlockState(Mapping.blockStateJeToBe(jeBlockState), jeBlockState); return new AllayBlockState(Mapping.blockStateJeToBe(jeBlockState), jeBlockState);
} }