mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-17 18:12:43 +00:00
Merge branch 'ver/6.6.0' into dev/7.0-2
This commit is contained in:
commit
2a40f4af1e
@ -51,6 +51,15 @@ fun Project.configureDependencies() {
|
||||
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") {
|
||||
name = "Sonatype Snapshots"
|
||||
}
|
||||
maven("https://repo.opencollab.dev/maven-releases/") {
|
||||
name = "OpenCollab Releases"
|
||||
}
|
||||
maven("https://repo.opencollab.dev/maven-snapshots/") {
|
||||
name = "OpenCollab Snapshots"
|
||||
}
|
||||
maven("https://storehouse.okaeri.eu/repository/maven-public/") {
|
||||
name = "Okaeri"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
@ -77,4 +77,8 @@ object Versions {
|
||||
const val logback = "1.5.8"
|
||||
const val picocli = "4.7.6"
|
||||
}
|
||||
|
||||
object Allay {
|
||||
const val api = "1cb3bb69c6"
|
||||
}
|
||||
}
|
10
platforms/allay/README.md
Normal file
10
platforms/allay/README.md
Normal file
@ -0,0 +1,10 @@
|
||||
# Allay platform
|
||||
|
||||
## Resource files
|
||||
|
||||
Current mapping version: je 1.21 to be 1.21.30
|
||||
|
||||
- `mapping/biomes.json` obtain from GeyserMC/mappings.
|
||||
- `mapping/items.json` obtain from GeyserMC/mappings.
|
||||
- `mapping/blocks.json` generated by using GeyserMC/mappings-generator, and it's origin name is `generator_blocks.json`.
|
||||
- `je_block_default_states.json` converted from https://zh.minecraft.wiki/w/Module:Block_state_values.
|
5
platforms/allay/build.gradle.kts
Normal file
5
platforms/allay/build.gradle.kts
Normal file
@ -0,0 +1,5 @@
|
||||
dependencies {
|
||||
shadedApi(project(":common:implementation:base"))
|
||||
|
||||
compileOnly("org.allaymc.allay", "api", Versions.Allay.api)
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package com.dfsek.terra.allay;
|
||||
|
||||
import com.dfsek.tectonic.api.TypeRegistry;
|
||||
import com.dfsek.tectonic.api.depth.DepthTracker;
|
||||
import com.dfsek.tectonic.api.exception.LoadException;
|
||||
import org.allaymc.api.server.Server;
|
||||
import org.allaymc.api.world.biome.BiomeId;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.dfsek.terra.AbstractPlatform;
|
||||
import com.dfsek.terra.allay.delegate.AllayBiome;
|
||||
import com.dfsek.terra.allay.generator.AllayGeneratorWrapper;
|
||||
import com.dfsek.terra.allay.handle.AllayItemHandle;
|
||||
import com.dfsek.terra.allay.handle.AllayWorldHandle;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.handle.WorldHandle;
|
||||
import com.dfsek.terra.api.world.biome.PlatformBiome;
|
||||
|
||||
/**
|
||||
* @author daoge_cmd
|
||||
*/
|
||||
public class AllayPlatform extends AbstractPlatform {
|
||||
|
||||
public static final Set<AllayGeneratorWrapper> GENERATOR_WRAPPERS = new HashSet<>();
|
||||
|
||||
protected static final AllayWorldHandle ALLAY_WORLD_HANDLE = new AllayWorldHandle();
|
||||
protected static final AllayItemHandle ALLAY_ITEM_HANDLE = new AllayItemHandle();
|
||||
|
||||
public AllayPlatform() {
|
||||
load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean reload() {
|
||||
getTerraConfig().load(this);
|
||||
getRawConfigRegistry().clear();
|
||||
boolean succeed = getRawConfigRegistry().loadAll(this);
|
||||
|
||||
GENERATOR_WRAPPERS.forEach(wrapper -> {
|
||||
getConfigRegistry().get(wrapper.getConfigPack().getRegistryKey()).ifPresent(pack -> {
|
||||
wrapper.setConfigPack(pack);
|
||||
var dimension = wrapper.getAllayWorldGenerator().getDimension();
|
||||
TerraAllayPlugin.INSTANCE.getPluginLogger().info(
|
||||
"Replaced pack in chunk generator for world {}",
|
||||
dimension.getWorld().getWorldData().getName() + ":" + dimension.getDimensionInfo().dimensionId()
|
||||
);
|
||||
});
|
||||
});
|
||||
return succeed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String platformName() {
|
||||
return "Allay";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull WorldHandle getWorldHandle() {
|
||||
return ALLAY_WORLD_HANDLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ItemHandle getItemHandle() {
|
||||
return ALLAY_ITEM_HANDLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull File getDataFolder() {
|
||||
return TerraAllayPlugin.INSTANCE.getPluginContainer().dataFolder().toFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runPossiblyUnsafeTask(@NotNull Runnable task) {
|
||||
Server.getInstance().getScheduler().runLater(Server.getInstance(), task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(TypeRegistry registry) {
|
||||
super.register(registry);
|
||||
registry.registerLoader(BlockState.class, (type, o, loader, depthTracker) -> ALLAY_WORLD_HANDLE.createBlockState((String) o))
|
||||
.registerLoader(PlatformBiome.class, (type, o, loader, depthTracker) -> parseBiome((String) o, depthTracker));
|
||||
}
|
||||
|
||||
protected AllayBiome parseBiome(String id, DepthTracker depthTracker) throws LoadException {
|
||||
if(!id.startsWith("minecraft:")) throw new LoadException("Invalid biome identifier " + id, depthTracker);
|
||||
return new AllayBiome(BiomeId.fromId(Mapping.biomeIdJeToBe(id)));
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package com.dfsek.terra.allay;
|
||||
|
||||
import org.allaymc.api.utils.HashUtils;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
|
||||
/**
|
||||
* @author daoge_cmd
|
||||
*/
|
||||
public class JeBlockState {
|
||||
protected final String identifier;
|
||||
protected final TreeMap<String, String> properties;
|
||||
protected int hash = Integer.MAX_VALUE;
|
||||
|
||||
public static JeBlockState fromString(String data) {
|
||||
return new JeBlockState(data);
|
||||
}
|
||||
|
||||
public static JeBlockState create(String identifier, TreeMap<String, String> properties) {
|
||||
return new JeBlockState(identifier, properties);
|
||||
}
|
||||
|
||||
private JeBlockState(String data) {
|
||||
String[] strings = data.replace("[", ",").replace("]", ",").replace(" ", "").split(",");
|
||||
this.identifier = strings[0];
|
||||
this.properties = new TreeMap<>();
|
||||
if (strings.length > 1) {
|
||||
for (int i = 1; i < strings.length; i++) {
|
||||
final String tmp = strings[i];
|
||||
final int index = tmp.indexOf("=");
|
||||
properties.put(tmp.substring(0, index), tmp.substring(index + 1));
|
||||
}
|
||||
}
|
||||
completeMissingProperties();
|
||||
}
|
||||
|
||||
public String getPropertyValue(String key) {
|
||||
return properties.get(key);
|
||||
}
|
||||
|
||||
private void completeMissingProperties() {
|
||||
Map<String, String> defaultProperties = Mapping.getJeBlockDefaultProperties(identifier);
|
||||
if(properties.size() == defaultProperties.size()) {
|
||||
return;
|
||||
}
|
||||
defaultProperties.entrySet().stream().filter(entry -> !properties.containsKey(entry.getKey())).forEach(
|
||||
entry -> properties.put(entry.getKey(), entry.getValue()));
|
||||
}
|
||||
|
||||
private JeBlockState(String identifier, TreeMap<String, String> properties) {
|
||||
this.identifier = identifier;
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public String toString(boolean includeProperties) {
|
||||
if(!includeProperties) return identifier;
|
||||
StringBuilder builder = new StringBuilder(identifier).append(";");
|
||||
properties.forEach((k, v) -> builder.append(k).append("=").append(v).append(";"));
|
||||
String str = builder.toString();
|
||||
if (hash == Integer.MAX_VALUE) {
|
||||
hash = HashUtils.fnv1a_32(str.getBytes());
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public int getHash() {
|
||||
if (hash == Integer.MAX_VALUE) {
|
||||
hash = HashUtils.fnv1a_32(toString(true).getBytes());
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toString(true);
|
||||
}
|
||||
}
|
188
platforms/allay/src/main/java/com/dfsek/terra/allay/Mapping.java
Normal file
188
platforms/allay/src/main/java/com/dfsek/terra/allay/Mapping.java
Normal file
@ -0,0 +1,188 @@
|
||||
package com.dfsek.terra.allay;
|
||||
|
||||
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 org.allaymc.api.block.type.BlockState;
|
||||
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.item.type.ItemType;
|
||||
import org.allaymc.api.item.type.ItemTypeSafeGetter;
|
||||
import org.allaymc.api.utils.JSONUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
|
||||
/**
|
||||
* @author daoge_cmd
|
||||
*/
|
||||
public final class Mapping {
|
||||
|
||||
private static final Map<String, Map<String, String>> JE_BLOCK_DEFAULT_PROPERTIES = new Object2ObjectOpenHashMap<>();
|
||||
private static final Map<BlockState, JeBlockState> BLOCK_STATE_BE_TO_JE = new Object2ObjectOpenHashMap<>();
|
||||
private static final Map<Integer, BlockState> BLOCK_STATE_JE_HASH_TO_BE = new Int2ObjectOpenHashMap<>();
|
||||
private static final Map<String, ItemType<?>> ITEM_ID_JE_TO_BE = new Object2ObjectOpenHashMap<>();
|
||||
private static final Map<String, Integer> BIOME_ID_JE_TO_BE = new Object2IntOpenHashMap<>();
|
||||
private static final BlockState BE_AIR_STATE = BlockTypes.AIR.getDefaultState();
|
||||
|
||||
public static void init() {
|
||||
if(!initBlockStateMapping()) error();
|
||||
if(!initJeBlockDefaultProperties()) error();
|
||||
if(!initItemMapping()) error();
|
||||
if(!initBiomeMapping()) error();
|
||||
}
|
||||
|
||||
public static JeBlockState blockStateBeToJe(BlockState beBlockState) {
|
||||
return BLOCK_STATE_BE_TO_JE.get(beBlockState);
|
||||
}
|
||||
|
||||
public static BlockState blockStateJeToBe(JeBlockState jeBlockState) {
|
||||
BlockState result = BLOCK_STATE_JE_HASH_TO_BE.get(jeBlockState.getHash());
|
||||
if(result == null) {
|
||||
TerraAllayPlugin.INSTANCE.getPluginLogger().warn("Failed to find be block state for {}", jeBlockState);
|
||||
return BE_AIR_STATE;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ItemType<?> itemIdJeToBe(String jeItemId) {
|
||||
return ITEM_ID_JE_TO_BE.get(jeItemId);
|
||||
}
|
||||
|
||||
// Enchantment identifiers are same in both versions
|
||||
|
||||
public static String enchantmentIdBeToJe(String beEnchantmentId) {
|
||||
return beEnchantmentId;
|
||||
}
|
||||
|
||||
public static String enchantmentIdJeToBe(String jeEnchantmentId) {
|
||||
return jeEnchantmentId;
|
||||
}
|
||||
|
||||
public static int biomeIdJeToBe(String jeBiomeId) {
|
||||
return BIOME_ID_JE_TO_BE.get(jeBiomeId);
|
||||
}
|
||||
|
||||
public static Map<String, String> getJeBlockDefaultProperties(String jeBlockIdentifier) {
|
||||
Map<String, String> defaultProperties = JE_BLOCK_DEFAULT_PROPERTIES.get(jeBlockIdentifier);
|
||||
if( defaultProperties == null) {
|
||||
TerraAllayPlugin.INSTANCE.getPluginLogger().warn("Failed to find default properties for {}", jeBlockIdentifier);
|
||||
return Map.of();
|
||||
}
|
||||
return defaultProperties;
|
||||
}
|
||||
|
||||
private static void error() {
|
||||
throw new RuntimeException("Mapping not initialized");
|
||||
}
|
||||
|
||||
private static boolean initBiomeMapping() {
|
||||
try (InputStream stream = Mapping.class.getClassLoader().getResourceAsStream("mapping/biomes.json")) {
|
||||
if (stream == null) {
|
||||
TerraAllayPlugin.INSTANCE.getPluginLogger().error("biomes mapping not found");
|
||||
return false;
|
||||
}
|
||||
Set<Entry<String, Map<String, Integer>>> mappings = JSONUtils.from(stream, new TypeToken<Map<String, Map<String, Integer>>>(){}).entrySet();
|
||||
mappings.forEach(mapping -> BIOME_ID_JE_TO_BE.put(mapping.getKey(), mapping.getValue().get("bedrock_id")));
|
||||
} catch(IOException e) {
|
||||
TerraAllayPlugin.INSTANCE.getPluginLogger().error("Failed to load biomes mapping", e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean initItemMapping() {
|
||||
try (InputStream stream = Mapping.class.getClassLoader().getResourceAsStream("mapping/items.json")) {
|
||||
if (stream == null) {
|
||||
TerraAllayPlugin.INSTANCE.getPluginLogger().error("items mapping not found");
|
||||
return false;
|
||||
}
|
||||
Set<Entry<String, Map<String, Object>>> mappings = JSONUtils.from(stream, new TypeToken<Map<String, Map<String, Object>>>(){}).entrySet();
|
||||
mappings.forEach(mapping -> {
|
||||
ItemType<?> item = ItemTypeSafeGetter
|
||||
.name((String) mapping.getValue().get("bedrock_identifier"))
|
||||
// NOTICE: should be cast to double
|
||||
.meta(((Double) mapping.getValue().get("bedrock_data")).intValue())
|
||||
.itemType();
|
||||
ITEM_ID_JE_TO_BE.put(mapping.getKey(), item);
|
||||
});
|
||||
} catch(IOException e) {
|
||||
TerraAllayPlugin.INSTANCE.getPluginLogger().error("Failed to load items mapping", e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean initBlockStateMapping() {
|
||||
try (InputStream stream = Mapping.class.getClassLoader().getResourceAsStream("mapping/blocks.json")) {
|
||||
if (stream == null) {
|
||||
TerraAllayPlugin.INSTANCE.getPluginLogger().error("blocks mapping not found");
|
||||
return false;
|
||||
}
|
||||
// noinspection unchecked
|
||||
List<Map<String, Map<String, Object>>> mappings = (List<Map<String, Map<String, Object>>>) JSONUtils.from(stream, new TypeToken<Map<String, Object>>(){}).get("mappings");
|
||||
mappings.forEach(mapping -> {
|
||||
JeBlockState jeState = createJeBlockState(mapping.get("java_state"));
|
||||
BlockState beState = createBeBlockState(mapping.get("bedrock_state"));
|
||||
BLOCK_STATE_BE_TO_JE.put(beState, jeState);
|
||||
BLOCK_STATE_JE_HASH_TO_BE.put(jeState.getHash(), beState);
|
||||
});
|
||||
} catch(IOException e) {
|
||||
TerraAllayPlugin.INSTANCE.getPluginLogger().error("Failed to load blocks mapping", e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean initJeBlockDefaultProperties() {
|
||||
try (InputStream stream = Mapping.class.getClassLoader().getResourceAsStream("je_block_default_states.json")) {
|
||||
if (stream == null) {
|
||||
TerraAllayPlugin.INSTANCE.getPluginLogger().error("je_block_default_states.json not found");
|
||||
return false;
|
||||
}
|
||||
Map<String, Map<String, String>> states = JSONUtils.from(stream, new TypeToken<Map<String, Map<String, String>>>(){});
|
||||
for(Entry<String, Map<String, String>> entry : states.entrySet()) {
|
||||
String identifier = entry.getKey();
|
||||
Map<String, String> properties = entry.getValue();
|
||||
JE_BLOCK_DEFAULT_PROPERTIES.put(identifier, properties);
|
||||
}
|
||||
} catch(IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static BlockState createBeBlockState(Map<String, Object> data) {
|
||||
Getter getter = BlockStateSafeGetter
|
||||
.name("minecraft:" + data.get("bedrock_identifier"));
|
||||
if (data.containsKey("state")) {
|
||||
// noinspection unchecked
|
||||
convertValueType((Map<String, Object>) data.get("state")).forEach(getter::property);
|
||||
}
|
||||
return getter.blockState();
|
||||
}
|
||||
|
||||
private static Map<String, Object> convertValueType(Map<String, Object> data) {
|
||||
TreeMap<String, Object> result = new TreeMap<>();
|
||||
for (Entry<String, Object> entry : data.entrySet()) {
|
||||
if (entry.getValue() instanceof Number number) {
|
||||
// Convert double to int because the number in json is double
|
||||
result.put(entry.getKey(), number.intValue());
|
||||
} else {
|
||||
result.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static JeBlockState createJeBlockState(Map<String, Object> data) {
|
||||
// noinspection unchecked
|
||||
return JeBlockState.create((String) data.get("Name"), new TreeMap<>((Map<String, String>) data.getOrDefault("Properties", Map.of())));
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package com.dfsek.terra.allay;
|
||||
|
||||
import org.allaymc.api.plugin.Plugin;
|
||||
import org.allaymc.api.registry.Registries;
|
||||
|
||||
import com.dfsek.terra.allay.generator.AllayGeneratorWrapper;
|
||||
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
|
||||
|
||||
/**
|
||||
* @author daoge_cmd
|
||||
*/
|
||||
public class TerraAllayPlugin extends Plugin {
|
||||
|
||||
public static TerraAllayPlugin INSTANCE;
|
||||
public static AllayPlatform PLATFORM;
|
||||
|
||||
{
|
||||
INSTANCE = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
pluginLogger.info("Starting Terra...");
|
||||
|
||||
pluginLogger.info("Loading mapping...");
|
||||
Mapping.init();
|
||||
|
||||
pluginLogger.info("Initializing allay platform...");
|
||||
PLATFORM = new AllayPlatform();
|
||||
PLATFORM.getEventManager().callEvent(new PlatformInitializationEvent());
|
||||
// TODO: adapt command manager
|
||||
|
||||
pluginLogger.info("Registering generator...");
|
||||
Registries.WORLD_GENERATOR_FACTORIES.register("TERRA", preset -> {
|
||||
try {
|
||||
AllayGeneratorWrapper wrapper = new AllayGeneratorWrapper(preset);
|
||||
AllayPlatform.GENERATOR_WRAPPERS.add(wrapper);
|
||||
return wrapper.getAllayWorldGenerator();
|
||||
} catch (IllegalArgumentException e) {
|
||||
TerraAllayPlugin.INSTANCE.getPluginLogger().error("Fail to create world generator with preset: {}", preset);
|
||||
TerraAllayPlugin.INSTANCE.getPluginLogger().error("Reason: {}", e.getMessage());
|
||||
return Registries.WORLD_GENERATOR_FACTORIES.get("FLAT").apply("");
|
||||
}
|
||||
});
|
||||
|
||||
pluginLogger.info("Terra started");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReloadable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
if(PLATFORM.reload()) {
|
||||
pluginLogger.info("Terra reloaded successfully.");
|
||||
} else {
|
||||
pluginLogger.error("Terra failed to reload.");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.dfsek.terra.allay.delegate;
|
||||
|
||||
import org.allaymc.api.world.biome.BiomeType;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.PlatformBiome;
|
||||
|
||||
/**
|
||||
* @author daoge_cmd
|
||||
*/
|
||||
public record AllayBiome(BiomeType allayBiome) implements PlatformBiome {
|
||||
@Override
|
||||
public BiomeType getHandle() {
|
||||
return allayBiome;
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package com.dfsek.terra.allay.delegate;
|
||||
|
||||
import org.allaymc.api.block.type.BlockState;
|
||||
import org.allaymc.api.block.type.BlockTypes;
|
||||
|
||||
import com.dfsek.terra.allay.JeBlockState;
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.properties.Property;
|
||||
|
||||
/**
|
||||
* @author daoge_cmd
|
||||
*/
|
||||
public final class AllayBlockState implements com.dfsek.terra.api.block.state.BlockState {
|
||||
|
||||
public static final AllayBlockState AIR = new AllayBlockState(BlockTypes.AIR.getDefaultState(),
|
||||
JeBlockState.fromString("minecraft:air"));
|
||||
|
||||
private final BlockState allayBlockState;
|
||||
private final JeBlockState jeBlockState;
|
||||
private final boolean containsWater;
|
||||
|
||||
public AllayBlockState(BlockState allayBlockState, JeBlockState jeBlockState) {
|
||||
this.allayBlockState = allayBlockState;
|
||||
this.jeBlockState = jeBlockState;
|
||||
this.containsWater = "true".equals(jeBlockState.getPropertyValue("waterlogged"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(com.dfsek.terra.api.block.state.BlockState o) {
|
||||
AllayBlockState other = ((AllayBlockState) o);
|
||||
return other.allayBlockState == this.allayBlockState && other.containsWater == this.containsWater;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Comparable<T>> boolean has(Property<T> property) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Comparable<T>> T get(Property<T> property) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends Comparable<T>> com.dfsek.terra.api.block.state.BlockState set(Property<T> property, T value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockType getBlockType() {
|
||||
return new AllayBlockType(allayBlockState.getBlockType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsString(boolean properties) {
|
||||
return jeBlockState.toString(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAir() {
|
||||
return allayBlockState.getBlockType() == BlockTypes.AIR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getHandle() {
|
||||
return allayBlockState;
|
||||
}
|
||||
|
||||
public BlockState allayBlockState() { return allayBlockState; }
|
||||
|
||||
public boolean containsWater() { return containsWater; }
|
||||
|
||||
public JeBlockState jeBlockState() { return jeBlockState; }
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.dfsek.terra.allay.delegate;
|
||||
|
||||
import org.allaymc.api.block.tag.BlockTags;
|
||||
import org.allaymc.api.block.type.BlockType;
|
||||
|
||||
import com.dfsek.terra.allay.Mapping;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
|
||||
/**
|
||||
* @author daoge_cmd
|
||||
*/
|
||||
public record AllayBlockType(BlockType<?> allayBlockType) implements com.dfsek.terra.api.block.BlockType {
|
||||
@Override
|
||||
public BlockState getDefaultState() {
|
||||
return new AllayBlockState(allayBlockType.getDefaultState(), Mapping.blockStateBeToJe(allayBlockType.getDefaultState()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid() {
|
||||
return allayBlockType.getMaterial().isSolid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWater() {
|
||||
return allayBlockType.hasBlockTag(BlockTags.WATER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockType<?> getHandle() {
|
||||
return allayBlockType;
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package com.dfsek.terra.allay.delegate;
|
||||
|
||||
import org.allaymc.api.block.property.type.BlockPropertyTypes;
|
||||
import org.allaymc.api.block.tag.BlockTags;
|
||||
import org.allaymc.api.block.type.BlockTypes;
|
||||
import org.allaymc.api.world.chunk.Chunk;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.dfsek.terra.allay.Mapping;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
|
||||
/**
|
||||
* @author daoge_cmd
|
||||
*/
|
||||
public record AllayChunk(ServerWorld world, Chunk allayChunk) implements com.dfsek.terra.api.world.chunk.Chunk {
|
||||
|
||||
private static final org.allaymc.api.block.type.BlockState WATER = BlockTypes.WATER.ofState(BlockPropertyTypes.LIQUID_DEPTH.createValue(0));
|
||||
|
||||
@Override
|
||||
public void setBlock(int x, int y, int z, BlockState data, boolean physics) {
|
||||
AllayBlockState allayBlockState = (AllayBlockState) data;
|
||||
allayChunk.setBlockState(x, y, z, allayBlockState.allayBlockState());
|
||||
boolean containsWater = allayBlockState.containsWater() || allayChunk.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER);
|
||||
if (containsWater) {
|
||||
allayChunk.setBlockState(x, y, z, WATER, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull BlockState getBlock(int x, int y, int z) {
|
||||
org.allaymc.api.block.type.BlockState blockState = allayChunk.getBlockState(x, y, z);
|
||||
return new AllayBlockState(blockState, Mapping.blockStateBeToJe(blockState));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
return allayChunk.getX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getZ() {
|
||||
return allayChunk.getZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerWorld getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Chunk getHandle() {
|
||||
return allayChunk;
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.dfsek.terra.allay.delegate;
|
||||
|
||||
import org.allaymc.api.item.enchantment.EnchantmentType;
|
||||
|
||||
import com.dfsek.terra.allay.Mapping;
|
||||
import com.dfsek.terra.api.inventory.ItemStack;
|
||||
import com.dfsek.terra.api.inventory.item.Enchantment;
|
||||
|
||||
/**
|
||||
* @author daoge_cmd
|
||||
*/
|
||||
public record AllayEnchantment(EnchantmentType allayEnchantment) implements Enchantment {
|
||||
@Override
|
||||
public boolean canEnchantItem(ItemStack itemStack) {
|
||||
return ((AllayItemStack)itemStack).allayItemStack().checkEnchantmentCompatibility(allayEnchantment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean conflictsWith(Enchantment other) {
|
||||
return ((AllayEnchantment)other).allayEnchantment.isIncompatibleWith(allayEnchantment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return Mapping.enchantmentIdBeToJe(allayEnchantment.getIdentifier().toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel() {
|
||||
return allayEnchantment.getMaxLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnchantmentType getHandle() {
|
||||
return allayEnchantment;
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package com.dfsek.terra.allay.delegate;
|
||||
|
||||
import com.dfsek.terra.api.entity.Entity;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
|
||||
/**
|
||||
* NOTICE: Entity is not supported currently, and this is a fake implementation.
|
||||
*
|
||||
* @author daoge_cmd
|
||||
*/
|
||||
public final class AllayFakeEntity implements Entity {
|
||||
|
||||
private final Object fakeHandle = new Object();
|
||||
private Vector3 position;
|
||||
private ServerWorld world;
|
||||
|
||||
public AllayFakeEntity(Vector3 position, ServerWorld world) {
|
||||
this.position = position;
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3 position() {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void position(Vector3 position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void world(ServerWorld world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerWorld world() {
|
||||
return world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getHandle() {
|
||||
return fakeHandle;
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.dfsek.terra.allay.delegate;
|
||||
|
||||
import org.allaymc.api.item.ItemStack;
|
||||
import org.allaymc.api.item.enchantment.EnchantmentInstance;
|
||||
import org.allaymc.api.item.enchantment.EnchantmentType;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.api.inventory.item.Enchantment;
|
||||
import com.dfsek.terra.api.inventory.item.ItemMeta;
|
||||
|
||||
/**
|
||||
* @author daoge_cmd
|
||||
*/
|
||||
public record AllayItemMeta(ItemStack allayItemStack) implements ItemMeta {
|
||||
@Override
|
||||
public void addEnchantment(Enchantment enchantment, int level) {
|
||||
EnchantmentType allayEnchantment = ((AllayEnchantment) enchantment).allayEnchantment();
|
||||
allayItemStack.addEnchantment(allayEnchantment, (short) level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Enchantment, Integer> getEnchantments() {
|
||||
Map<Enchantment, Integer> results = new HashMap<>();
|
||||
for (EnchantmentInstance allayEnchantmentInstance : allayItemStack.getEnchantments()) {
|
||||
results.put(new AllayEnchantment(allayEnchantmentInstance.getType()), allayEnchantmentInstance.getLevel());
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getHandle() {
|
||||
return allayItemStack;
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package com.dfsek.terra.allay.delegate;
|
||||
|
||||
import org.allaymc.api.item.ItemStack;
|
||||
import org.allaymc.api.item.enchantment.EnchantmentInstance;
|
||||
|
||||
import com.dfsek.terra.api.inventory.Item;
|
||||
import com.dfsek.terra.api.inventory.item.ItemMeta;
|
||||
|
||||
/**
|
||||
* @author daoge_cmd
|
||||
*/
|
||||
public record AllayItemStack(ItemStack allayItemStack) implements com.dfsek.terra.api.inventory.ItemStack{
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return allayItemStack.getCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAmount(int i) {
|
||||
allayItemStack.setCount(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getType() {
|
||||
return new AllayItemType(allayItemStack.getItemType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemMeta getItemMeta() {
|
||||
return new AllayItemMeta(allayItemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemMeta(ItemMeta meta) {
|
||||
ItemStack targetItem = ((AllayItemMeta) meta).allayItemStack();
|
||||
allayItemStack.removeAllEnchantments();
|
||||
for (EnchantmentInstance enchantment : targetItem.getEnchantments()) {
|
||||
allayItemStack.addEnchantment(enchantment.getType(), enchantment.getLevel());
|
||||
}
|
||||
allayItemStack.setLore(targetItem.getLore());
|
||||
allayItemStack.setDurability(targetItem.getDurability());
|
||||
allayItemStack.setCustomName(targetItem.getCustomName());
|
||||
allayItemStack.setMeta(targetItem.getMeta());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getHandle() {
|
||||
return allayItemStack;
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.dfsek.terra.allay.delegate;
|
||||
|
||||
import org.allaymc.api.item.data.ItemId;
|
||||
import org.allaymc.api.item.type.ItemType;
|
||||
import org.allaymc.api.registry.Registries;
|
||||
|
||||
import com.dfsek.terra.api.inventory.Item;
|
||||
|
||||
|
||||
/**
|
||||
* @author daoge_cmd
|
||||
*/
|
||||
public final class AllayItemType implements Item {
|
||||
private final ItemType<?> allayItemType;
|
||||
private final double maxDurability;
|
||||
|
||||
public AllayItemType(ItemType<?> allayItemType) {
|
||||
this.allayItemType = allayItemType;
|
||||
this.maxDurability = Registries.ITEM_DATA.get(ItemId.fromIdentifier(allayItemType.getIdentifier())).maxDamage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.dfsek.terra.api.inventory.ItemStack newItemStack(int amount) {
|
||||
return new AllayItemStack(allayItemType.createItemStack(amount));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxDurability() {
|
||||
return maxDurability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemType<?> getHandle() {
|
||||
return allayItemType;
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.dfsek.terra.allay.delegate;
|
||||
|
||||
import org.allaymc.api.block.property.type.BlockPropertyTypes;
|
||||
import org.allaymc.api.block.tag.BlockTags;
|
||||
import org.allaymc.api.block.type.BlockTypes;
|
||||
import org.allaymc.api.world.chunk.UnsafeChunk;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.dfsek.terra.allay.Mapping;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ProtoChunk;
|
||||
|
||||
/**
|
||||
* @author daoge_cmd
|
||||
*/
|
||||
public record AllayProtoChunk(UnsafeChunk allayChunk) implements ProtoChunk {
|
||||
|
||||
private static final org.allaymc.api.block.type.BlockState WATER = BlockTypes.WATER.ofState(BlockPropertyTypes.LIQUID_DEPTH.createValue(0));
|
||||
|
||||
@Override
|
||||
public int getMaxHeight() {
|
||||
return allayChunk.getDimensionInfo().maxHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlock(int x, int y, int z, @NotNull BlockState blockState) {
|
||||
AllayBlockState allayBlockState = (AllayBlockState) blockState;
|
||||
allayChunk.setBlockState(x, y, z, allayBlockState.allayBlockState());
|
||||
boolean containsWater = allayBlockState.containsWater() || allayChunk.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER);
|
||||
if (containsWater) {
|
||||
allayChunk.setBlockState(x, y, z, WATER, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull BlockState getBlock(int x, int y, int z) {
|
||||
org.allaymc.api.block.type.BlockState blockState = allayChunk.getBlockState(x, y, z);
|
||||
return new AllayBlockState(blockState, Mapping.blockStateBeToJe(blockState));
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnsafeChunk getHandle() {
|
||||
return allayChunk;
|
||||
}
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
package com.dfsek.terra.allay.delegate;
|
||||
|
||||
import org.allaymc.api.block.property.type.BlockPropertyTypes;
|
||||
import org.allaymc.api.block.tag.BlockTags;
|
||||
import org.allaymc.api.block.type.BlockTypes;
|
||||
import org.allaymc.api.world.generator.context.OtherChunkAccessibleContext;
|
||||
|
||||
import com.dfsek.terra.allay.Mapping;
|
||||
import com.dfsek.terra.api.block.entity.BlockEntity;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.entity.Entity;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ProtoWorld;
|
||||
|
||||
/**
|
||||
* @author daoge_cmd
|
||||
*/
|
||||
public record AllayProtoWorld(AllayServerWorld allayServerWorld, OtherChunkAccessibleContext context) implements ProtoWorld {
|
||||
|
||||
private static final org.allaymc.api.block.type.BlockState WATER = BlockTypes.WATER.ofState(BlockPropertyTypes.LIQUID_DEPTH.createValue(0));
|
||||
|
||||
@Override
|
||||
public int centerChunkX() {
|
||||
return context.getCurrentChunk().getX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int centerChunkZ() {
|
||||
return context.getCurrentChunk().getZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerWorld getWorld() {
|
||||
return allayServerWorld;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockState(int x, int y, int z, BlockState data, boolean physics) {
|
||||
AllayBlockState allayBlockState = (AllayBlockState)data;
|
||||
boolean containsWater = allayBlockState.containsWater() || context.getBlockState(x, y, z).getBlockType().hasBlockTag(BlockTags.WATER);
|
||||
context.setBlockState(x, y, z, allayBlockState.allayBlockState());
|
||||
if (containsWater) context.setBlockState(x, y, z, WATER, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlockState(int x, int y, int z) {
|
||||
org.allaymc.api.block.type.BlockState blockState = context.getBlockState(x, y, z);
|
||||
return new AllayBlockState(blockState, Mapping.blockStateBeToJe(blockState));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity spawnEntity(double x, double y, double z, EntityType entityType) {
|
||||
return new AllayFakeEntity(Vector3.of(x, y, z), allayServerWorld);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntity getBlockEntity(int x, int y, int z) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkGenerator getGenerator() {
|
||||
return allayServerWorld.getGenerator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeProvider getBiomeProvider() {
|
||||
return allayServerWorld.getBiomeProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigPack getPack() {
|
||||
return allayServerWorld.getPack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSeed() {
|
||||
return allayServerWorld.getSeed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHeight() {
|
||||
return allayServerWorld.getMaxHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinHeight() {
|
||||
return allayServerWorld.getMinHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AllayServerWorld getHandle() {
|
||||
return allayServerWorld;
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package com.dfsek.terra.allay.delegate;
|
||||
|
||||
import org.allaymc.api.block.property.type.BlockPropertyTypes;
|
||||
import org.allaymc.api.block.type.BlockTypes;
|
||||
import org.allaymc.api.world.Dimension;
|
||||
|
||||
import com.dfsek.terra.allay.Mapping;
|
||||
import com.dfsek.terra.allay.generator.AllayGeneratorWrapper;
|
||||
import com.dfsek.terra.api.block.entity.BlockEntity;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.entity.Entity;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.chunk.Chunk;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
||||
|
||||
/**
|
||||
* @author daoge_cmd
|
||||
*/
|
||||
public record AllayServerWorld(AllayGeneratorWrapper allayGeneratorWrapper, Dimension allayDimension) implements ServerWorld {
|
||||
|
||||
private static final org.allaymc.api.block.type.BlockState WATER = BlockTypes.WATER.ofState(BlockPropertyTypes.LIQUID_DEPTH.createValue(0));
|
||||
|
||||
@Override
|
||||
public Chunk getChunkAt(int x, int z) {
|
||||
return new AllayChunk(this, allayDimension.getChunkService().getChunk(x ,z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlockState(int x, int y, int z, BlockState data, boolean physics) {
|
||||
// In dimension#setBlockState() method, Water will be moved to layer 1 if it is placed at layer 0
|
||||
allayDimension.setBlockState(x, y, z, ((AllayBlockState) data).allayBlockState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity spawnEntity(double x, double y, double z, EntityType entityType) {
|
||||
return new AllayFakeEntity(Vector3.of(x, y, z), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlockState(int x, int y, int z) {
|
||||
org.allaymc.api.block.type.BlockState allayBlockState = allayDimension.getBlockState(x, y, z);
|
||||
return new AllayBlockState(allayBlockState, Mapping.blockStateBeToJe(allayBlockState));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntity getBlockEntity(int x, int y, int z) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkGenerator getGenerator() {
|
||||
return allayGeneratorWrapper.getHandle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeProvider getBiomeProvider() {
|
||||
return allayGeneratorWrapper.getBiomeProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigPack getPack() {
|
||||
return allayGeneratorWrapper.getConfigPack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSeed() {
|
||||
return allayGeneratorWrapper.getSeed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHeight() {
|
||||
return allayDimension.getDimensionInfo().maxHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinHeight() {
|
||||
return allayDimension.getDimensionInfo().minHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getHandle() {
|
||||
return allayDimension;
|
||||
}
|
||||
}
|
@ -0,0 +1,180 @@
|
||||
package com.dfsek.terra.allay.generator;
|
||||
|
||||
import org.allaymc.api.utils.AllayStringUtils;
|
||||
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.context.NoiseContext;
|
||||
import org.allaymc.api.world.generator.context.PopulateContext;
|
||||
import org.allaymc.api.world.generator.function.Noiser;
|
||||
import org.allaymc.api.world.generator.function.Populator;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.dfsek.terra.allay.TerraAllayPlugin;
|
||||
import com.dfsek.terra.allay.delegate.AllayProtoChunk;
|
||||
import com.dfsek.terra.allay.delegate.AllayProtoWorld;
|
||||
import com.dfsek.terra.allay.delegate.AllayServerWorld;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
||||
import com.dfsek.terra.api.world.chunk.generation.stage.GenerationStage;
|
||||
import com.dfsek.terra.api.world.chunk.generation.util.GeneratorWrapper;
|
||||
import com.dfsek.terra.api.world.info.WorldProperties;
|
||||
|
||||
/**
|
||||
* @author daoge_cmd
|
||||
*/
|
||||
public class AllayGeneratorWrapper implements GeneratorWrapper {
|
||||
|
||||
protected static final String OPTION_PACK_NAME = "pack";
|
||||
protected static final String OPTION_SEED = "seed";
|
||||
|
||||
protected final BiomeProvider biomeProvider;
|
||||
protected final long seed;
|
||||
protected final WorldGenerator allayWorldGenerator;
|
||||
protected ChunkGenerator chunkGenerator;
|
||||
protected ConfigPack configPack;
|
||||
protected WorldProperties worldProperties;
|
||||
protected AllayServerWorld allayServerWorld;
|
||||
|
||||
public AllayGeneratorWrapper(String preset) {
|
||||
Map<String, String> options = AllayStringUtils.parseOptions(preset);
|
||||
String packName = options.get(OPTION_PACK_NAME);
|
||||
if(packName == null) {
|
||||
throw new IllegalArgumentException("Missing config pack name");
|
||||
}
|
||||
this.seed = Long.parseLong(options.getOrDefault(OPTION_SEED, "0"));
|
||||
this.configPack = getConfigPack(packName);
|
||||
this.chunkGenerator = createGenerator(this.configPack);
|
||||
this.biomeProvider = this.configPack.getBiomeProvider();
|
||||
this.allayWorldGenerator = WorldGenerator
|
||||
.builder()
|
||||
.name("TERRA")
|
||||
.preset(preset)
|
||||
.noisers(new AllayNoiser())
|
||||
.populators(new AllayPopulator())
|
||||
.onDimensionSet(dimension -> {
|
||||
this.allayServerWorld = new AllayServerWorld(this, dimension);
|
||||
this.worldProperties = new WorldProperties() {
|
||||
|
||||
private final Object fakeHandle = new Object();
|
||||
|
||||
@Override
|
||||
public long getSeed() {
|
||||
return seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHeight() {
|
||||
return dimension.getDimensionInfo().maxHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinHeight() {
|
||||
return dimension.getDimensionInfo().minHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getHandle() {
|
||||
return fakeHandle;
|
||||
}
|
||||
};
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkGenerator getHandle() {
|
||||
return chunkGenerator;
|
||||
}
|
||||
|
||||
public BiomeProvider getBiomeProvider() {
|
||||
return this.biomeProvider;
|
||||
}
|
||||
|
||||
public ConfigPack getConfigPack() {
|
||||
return this.configPack;
|
||||
}
|
||||
|
||||
public void setConfigPack(ConfigPack configPack) {
|
||||
this.configPack = configPack;
|
||||
this.chunkGenerator = createGenerator(this.configPack);
|
||||
}
|
||||
|
||||
public long getSeed() {
|
||||
return this.seed;
|
||||
}
|
||||
|
||||
public WorldGenerator getAllayWorldGenerator() {
|
||||
return this.allayWorldGenerator;
|
||||
}
|
||||
|
||||
protected class AllayNoiser implements Noiser {
|
||||
|
||||
@Override
|
||||
public boolean apply(NoiseContext context) {
|
||||
UnsafeChunk chunk = context.getCurrentChunk();
|
||||
int chunkX = chunk.getX();
|
||||
int chunkZ = chunk.getZ();
|
||||
chunkGenerator.generateChunkData(
|
||||
new AllayProtoChunk(chunk),
|
||||
worldProperties, biomeProvider,
|
||||
chunkX, chunkZ
|
||||
);
|
||||
int minHeight = context.getDimensionInfo().minHeight();
|
||||
int 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++) {
|
||||
chunk.setBiome(
|
||||
x, y, z,
|
||||
(BiomeType) biomeProvider.getBiome(chunkX * 16 + x, y, chunkZ * 16 + z, seed).getPlatformBiome().getHandle()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "TERRA_NOISER";
|
||||
}
|
||||
}
|
||||
|
||||
protected class AllayPopulator implements Populator {
|
||||
|
||||
@Override
|
||||
public boolean apply(PopulateContext context) {
|
||||
AllayProtoWorld tmp = new AllayProtoWorld(allayServerWorld, context);
|
||||
try {
|
||||
for(GenerationStage generationStage : configPack.getStages()) {
|
||||
generationStage.populate(tmp);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
TerraAllayPlugin.INSTANCE.getPluginLogger().error("Error while populating chunk", e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "TERRA_POPULATOR";
|
||||
}
|
||||
}
|
||||
|
||||
protected static ConfigPack getConfigPack(String packName) {
|
||||
Optional<ConfigPack> byId = TerraAllayPlugin.PLATFORM.getConfigRegistry().getByID(packName);
|
||||
return byId.orElseGet(
|
||||
() -> TerraAllayPlugin.PLATFORM.getConfigRegistry().getByID(packName.toUpperCase(Locale.ENGLISH))
|
||||
.orElseThrow(() -> new IllegalArgumentException("Cant find terra config pack named " + packName))
|
||||
);
|
||||
}
|
||||
|
||||
protected static ChunkGenerator createGenerator(ConfigPack configPack) {
|
||||
return configPack.getGeneratorProvider().newInstance(configPack);
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.dfsek.terra.allay.handle;
|
||||
|
||||
import org.allaymc.api.registry.Registries;
|
||||
import org.allaymc.api.utils.Identifier;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.dfsek.terra.allay.Mapping;
|
||||
import com.dfsek.terra.allay.delegate.AllayEnchantment;
|
||||
import com.dfsek.terra.allay.delegate.AllayItemType;
|
||||
import com.dfsek.terra.api.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.inventory.Item;
|
||||
import com.dfsek.terra.api.inventory.item.Enchantment;
|
||||
|
||||
/**
|
||||
* @author daoge_cmd
|
||||
*/
|
||||
public class AllayItemHandle implements ItemHandle {
|
||||
@Override
|
||||
public Item createItem(String data) {
|
||||
return new AllayItemType(Mapping.itemIdJeToBe(data));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enchantment getEnchantment(String id) {
|
||||
return new AllayEnchantment(Registries.ENCHANTMENTS.getByK2(new Identifier(Mapping.enchantmentIdJeToBe(id))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Enchantment> getEnchantments() {
|
||||
return Registries.ENCHANTMENTS.getContent().m1().values().stream()
|
||||
.map(AllayEnchantment::new)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.dfsek.terra.allay.handle;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.dfsek.terra.allay.JeBlockState;
|
||||
import com.dfsek.terra.allay.Mapping;
|
||||
import com.dfsek.terra.allay.delegate.AllayBlockState;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import com.dfsek.terra.api.handle.WorldHandle;
|
||||
|
||||
/**
|
||||
* @author daoge_cmd
|
||||
*/
|
||||
public class AllayWorldHandle implements WorldHandle {
|
||||
|
||||
@Override
|
||||
public @NotNull BlockState createBlockState(@NotNull String data) {
|
||||
JeBlockState jeBlockState = JeBlockState.fromString(data);
|
||||
return new AllayBlockState(Mapping.blockStateJeToBe(jeBlockState), jeBlockState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull BlockState air() {
|
||||
return AllayBlockState.AIR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull EntityType getEntity(@NotNull String id) {
|
||||
return new EntityType() {
|
||||
private final Object fakeEntityType = new Object();
|
||||
@Override
|
||||
public Object getHandle() {
|
||||
return fakeEntityType;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
3462
platforms/allay/src/main/resources/je_block_default_states.json
Normal file
3462
platforms/allay/src/main/resources/je_block_default_states.json
Normal file
File diff suppressed because it is too large
Load Diff
1
platforms/allay/src/main/resources/mapping/biomes.json
Normal file
1
platforms/allay/src/main/resources/mapping/biomes.json
Normal file
@ -0,0 +1 @@
|
||||
{ "minecraft:badlands": { "bedrock_id": 37 }, "minecraft:bamboo_jungle": { "bedrock_id": 48 }, "minecraft:basalt_deltas": { "bedrock_id": 181 }, "minecraft:beach": { "bedrock_id": 16 }, "minecraft:birch_forest": { "bedrock_id": 27 }, "minecraft:cherry_grove": { "bedrock_id": 192 }, "minecraft:cold_ocean": { "bedrock_id": 44 }, "minecraft:crimson_forest": { "bedrock_id": 179 }, "minecraft:dark_forest": { "bedrock_id": 29 }, "minecraft:deep_cold_ocean": { "bedrock_id": 45 }, "minecraft:deep_dark": { "bedrock_id": 190 }, "minecraft:deep_frozen_ocean": { "bedrock_id": 47 }, "minecraft:deep_lukewarm_ocean": { "bedrock_id": 43 }, "minecraft:deep_ocean": { "bedrock_id": 24 }, "minecraft:desert": { "bedrock_id": 2 }, "minecraft:dripstone_caves": { "bedrock_id": 188 }, "minecraft:end_barrens": { "bedrock_id": 9 }, "minecraft:end_highlands": { "bedrock_id": 9 }, "minecraft:end_midlands": { "bedrock_id": 9 }, "minecraft:eroded_badlands": { "bedrock_id": 165 }, "minecraft:flower_forest": { "bedrock_id": 132 }, "minecraft:forest": { "bedrock_id": 4 }, "minecraft:frozen_ocean": { "bedrock_id": 46 }, "minecraft:frozen_peaks": { "bedrock_id": 183 }, "minecraft:frozen_river": { "bedrock_id": 11 }, "minecraft:grove": { "bedrock_id": 185 }, "minecraft:ice_spikes": { "bedrock_id": 140 }, "minecraft:jagged_peaks": { "bedrock_id": 182 }, "minecraft:jungle": { "bedrock_id": 21 }, "minecraft:lukewarm_ocean": { "bedrock_id": 42 }, "minecraft:lush_caves": { "bedrock_id": 187 }, "minecraft:mangrove_swamp": { "bedrock_id": 191 }, "minecraft:meadow": { "bedrock_id": 186 }, "minecraft:mushroom_fields": { "bedrock_id": 14 }, "minecraft:nether_wastes": { "bedrock_id": 8 }, "minecraft:ocean": { "bedrock_id": 0 }, "minecraft:old_growth_birch_forest": { "bedrock_id": 155 }, "minecraft:old_growth_pine_taiga": { "bedrock_id": 32 }, "minecraft:old_growth_spruce_taiga": { "bedrock_id": 160 }, "minecraft:plains": { "bedrock_id": 1 }, "minecraft:river": { "bedrock_id": 7 }, "minecraft:savanna": { "bedrock_id": 35 }, "minecraft:savanna_plateau": { "bedrock_id": 36 }, "minecraft:small_end_islands": { "bedrock_id": 9 }, "minecraft:snowy_beach": { "bedrock_id": 26 }, "minecraft:snowy_plains": { "bedrock_id": 12 }, "minecraft:snowy_slopes": { "bedrock_id": 184 }, "minecraft:snowy_taiga": { "bedrock_id": 30 }, "minecraft:soul_sand_valley": { "bedrock_id": 178 }, "minecraft:sparse_jungle": { "bedrock_id": 23 }, "minecraft:stony_peaks": { "bedrock_id": 189 }, "minecraft:stony_shore": { "bedrock_id": 25 }, "minecraft:sunflower_plains": { "bedrock_id": 129 }, "minecraft:swamp": { "bedrock_id": 6 }, "minecraft:taiga": { "bedrock_id": 5 }, "minecraft:the_end": { "bedrock_id": 9 }, "minecraft:the_void": { "bedrock_id": 7 }, "minecraft:warm_ocean": { "bedrock_id": 40 }, "minecraft:warped_forest": { "bedrock_id": 180 }, "minecraft:windswept_forest": { "bedrock_id": 34 }, "minecraft:windswept_gravelly_hills": { "bedrock_id": 131 }, "minecraft:windswept_hills": { "bedrock_id": 3 }, "minecraft:windswept_savanna": { "bedrock_id": 163 }, "minecraft:wooded_badlands": { "bedrock_id": 38 } }
|
1
platforms/allay/src/main/resources/mapping/blocks.json
Normal file
1
platforms/allay/src/main/resources/mapping/blocks.json
Normal file
File diff suppressed because one or more lines are too long
1
platforms/allay/src/main/resources/mapping/items.json
Normal file
1
platforms/allay/src/main/resources/mapping/items.json
Normal file
File diff suppressed because one or more lines are too long
8
platforms/allay/src/main/resources/plugin.json
Normal file
8
platforms/allay/src/main/resources/plugin.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"entrance": "com.dfsek.terra.allay.TerraAllayPlugin",
|
||||
"name": "Terra",
|
||||
"authors": ["daoge_cmd", "dfsek", "duplexsystem", "Astrash", "solonovamax", "Sancires", "Aureus", "RogueShade"],
|
||||
"version": "@VERSION@",
|
||||
"description": "@DESCRIPTION@",
|
||||
"website": "@WIKI@"
|
||||
}
|
@ -33,7 +33,7 @@ import com.dfsek.terra.mod.util.MinecraftAdapter;
|
||||
@Implements(@Interface(iface = com.dfsek.terra.api.entity.Entity.class, prefix = "terra$"))
|
||||
public abstract class EntityMixin {
|
||||
@Shadow
|
||||
public net.minecraft.world.World world;
|
||||
private net.minecraft.world.World world;
|
||||
|
||||
@Shadow
|
||||
private BlockPos blockPos;
|
||||
|
Loading…
x
Reference in New Issue
Block a user