Skip to content

Commit

Permalink
feat: implement platform biome
Browse files Browse the repository at this point in the history
  • Loading branch information
Bloeckchengrafik committed Jan 2, 2025
1 parent 23b846e commit 6279638
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
import com.dfsek.tectonic.api.loader.type.TypeLoader;

import com.dfsek.terra.AbstractPlatform;
import com.dfsek.terra.api.block.state.BlockState;
import com.dfsek.terra.api.entity.EntityType;
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
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.minestom.biome.MinestomBiomeLoader;
import com.dfsek.terra.minestom.entity.MinestomEntityType;
import com.dfsek.terra.minestom.item.MinestomItemHandle;

import com.dfsek.terra.minestom.world.MinestomWorldHandle;
Expand All @@ -33,7 +37,10 @@ private MinestomPlatform() {
@Override
public void register(TypeRegistry registry) {
super.register(registry);
registry.registerLoader(PlatformBiome.class, (TypeLoader<PlatformBiome>) (annotatedType, o, configLoader, depthTracker) -> () -> o);
registry
.registerLoader(PlatformBiome.class, new MinestomBiomeLoader())
.registerLoader(EntityType.class, (TypeLoader<EntityType>) (annotatedType, o, configLoader, depthTracker) -> new MinestomEntityType((String) o))
.registerLoader(BlockState.class, (TypeLoader<BlockState>) (annotatedType, o, configLoader, depthTracker) -> worldHandle.createBlockState((String) o));
}

@Override
Expand All @@ -59,13 +66,13 @@ public boolean reload() {
@Override
public @NotNull File getDataFolder() {
File file = new File("./terra/");
if (!file.exists()) file.mkdirs();
if(!file.exists()) file.mkdirs();
return file;
}


public static MinestomPlatform getInstance() {
if (INSTANCE == null) {
if(INSTANCE == null) {
INSTANCE = new MinestomPlatform();
}
return INSTANCE;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.dfsek.terra.minestom.biome;

import com.dfsek.terra.api.world.biome.PlatformBiome;

import net.minestom.server.world.biome.Biome;


public class MinestomBiome implements PlatformBiome {
private final Biome biome;

public MinestomBiome(Biome biome) { this.biome = biome; }

@Override
public Biome getHandle() {
return biome;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.dfsek.terra.minestom.biome;

import com.dfsek.tectonic.api.depth.DepthTracker;
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.api.world.biome.PlatformBiome;

import net.minestom.server.MinecraftServer;
import net.minestom.server.registry.DynamicRegistry;
import net.minestom.server.utils.NamespaceID;
import net.minestom.server.world.biome.Biome;
import org.jetbrains.annotations.NotNull;

import java.lang.reflect.AnnotatedType;


public class MinestomBiomeLoader implements TypeLoader<PlatformBiome> {
private final DynamicRegistry<Biome> biomeRegistry = MinecraftServer.getBiomeRegistry();

@Override
public PlatformBiome load(@NotNull AnnotatedType annotatedType, @NotNull Object o, @NotNull ConfigLoader configLoader,
DepthTracker depthTracker) throws LoadException {
String id = (String) o;
NamespaceID biomeID = NamespaceID.from(id);
Biome biome = biomeRegistry.get(biomeID);
if (biome == null) throw new LoadException("Biome %s does not exist in registry".formatted(id), depthTracker);
return new MinestomBiome(biome);
}
}

0 comments on commit 6279638

Please sign in to comment.