mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 02:20:57 +00:00
implement block data stuff
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
package com.dfsek.terra.cli;
|
||||
|
||||
import com.dfsek.tectonic.api.TypeRegistry;
|
||||
|
||||
import com.dfsek.tectonic.api.exception.LoadException;
|
||||
import com.dfsek.tectonic.api.loader.ConfigLoader;
|
||||
import com.dfsek.tectonic.api.loader.type.TypeLoader;
|
||||
|
||||
import com.dfsek.terra.AbstractPlatform;
|
||||
import com.dfsek.terra.api.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.handle.WorldHandle;
|
||||
|
||||
import com.dfsek.terra.api.world.biome.PlatformBiome;
|
||||
import com.dfsek.terra.cli.handle.CLIItemHandle;
|
||||
import com.dfsek.terra.cli.handle.CLIWorldHandle;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.AnnotatedType;
|
||||
|
||||
|
||||
public class CLIPlatform extends AbstractPlatform {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CLIPlatform.class);
|
||||
|
||||
private final CLIWorldHandle worldHandle = new CLIWorldHandle();
|
||||
private final CLIItemHandle itemHandle = new CLIItemHandle();
|
||||
public CLIPlatform() {
|
||||
LOGGER.info("Root directory: {}", getDataFolder().getAbsoluteFile());
|
||||
load();
|
||||
LOGGER.info("Initialized Terra platform.");
|
||||
}
|
||||
@Override
|
||||
public boolean reload() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String platformName() {
|
||||
return "CLI";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull WorldHandle getWorldHandle() {
|
||||
return worldHandle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull File getDataFolder() {
|
||||
return new File("./");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ItemHandle getItemHandle() {
|
||||
return itemHandle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(TypeRegistry registry) {
|
||||
super.register(registry);
|
||||
registry.registerLoader(PlatformBiome.class, (TypeLoader<PlatformBiome>) (annotatedType, o, configLoader) -> () -> o);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.cli;
|
||||
|
||||
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -9,5 +11,8 @@ public final class TerraCLI {
|
||||
|
||||
public static void main(String... args) {
|
||||
LOGGER.info("Starting Terra CLI...");
|
||||
|
||||
CLIPlatform platform = new CLIPlatform();
|
||||
platform.getEventManager().callEvent(new PlatformInitializationEvent());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.dfsek.terra.cli.block;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.state.properties.Property;
|
||||
|
||||
|
||||
public class CLIBlockState implements BlockState {
|
||||
private final String value;
|
||||
private final CLIBlockType type;
|
||||
private final boolean isAir;
|
||||
|
||||
public CLIBlockState(String value) {
|
||||
this.value = value;
|
||||
if(value.contains("[")) {
|
||||
this.type = new CLIBlockType(value.substring(0, value.indexOf("[")));
|
||||
} else {
|
||||
this.type = new CLIBlockType(value);
|
||||
}
|
||||
this.isAir = value.startsWith("minecraft:air");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getHandle() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(BlockState other) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@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>> BlockState set(Property<T> property, T value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockType getBlockType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsString(boolean properties) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAir() {
|
||||
return isAir;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.dfsek.terra.cli.block;
|
||||
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.util.generic.Lazy;
|
||||
|
||||
|
||||
public class CLIBlockType implements BlockType {
|
||||
private final String value;
|
||||
private final boolean solid;
|
||||
private final boolean water;
|
||||
private final Lazy<CLIBlockState> defaultState;
|
||||
|
||||
public CLIBlockType(String value) {
|
||||
if(value.contains("[")) throw new IllegalArgumentException("Block Type must not contain properties");
|
||||
this.value = value;
|
||||
this.solid = value.equals("minecraft:air");
|
||||
this.water = value.equals("minecraft:water");
|
||||
this.defaultState = Lazy.lazy(() -> new CLIBlockState(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getHandle() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getDefaultState() {
|
||||
return defaultState.value();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid() {
|
||||
return solid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWater() {
|
||||
return water;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.dfsek.terra.cli.handle;
|
||||
|
||||
import com.dfsek.terra.api.handle.ItemHandle;
|
||||
import com.dfsek.terra.api.inventory.Item;
|
||||
import com.dfsek.terra.api.inventory.item.Enchantment;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class CLIItemHandle implements ItemHandle {
|
||||
@Override
|
||||
public Item createItem(String data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enchantment getEnchantment(String id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Enchantment> getEnchantments() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.dfsek.terra.cli.handle;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
import com.dfsek.terra.api.handle.WorldHandle;
|
||||
|
||||
import com.dfsek.terra.cli.block.CLIBlockState;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
public class CLIWorldHandle implements WorldHandle {
|
||||
private static final CLIBlockState AIR = new CLIBlockState("minecraft:air");
|
||||
@Override
|
||||
public @NotNull BlockState createBlockState(@NotNull String data) {
|
||||
return new CLIBlockState(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull BlockState air() {
|
||||
return AIR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull EntityType getEntity(@NotNull String id) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user