mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-03 00:15:35 +00:00
chore: reformat
This commit is contained in:
parent
992ae592fd
commit
d0bc006faa
@ -1,32 +1,25 @@
|
|||||||
package com.dfsek.terra.minestom;
|
package com.dfsek.terra.minestom;
|
||||||
|
|
||||||
import com.dfsek.tectonic.api.TypeRegistry;
|
import com.dfsek.tectonic.api.TypeRegistry;
|
||||||
|
|
||||||
import com.dfsek.tectonic.api.loader.type.TypeLoader;
|
import com.dfsek.tectonic.api.loader.type.TypeLoader;
|
||||||
|
|
||||||
import com.dfsek.terra.AbstractPlatform;
|
import com.dfsek.terra.AbstractPlatform;
|
||||||
import com.dfsek.terra.api.block.state.BlockState;
|
import com.dfsek.terra.api.block.state.BlockState;
|
||||||
import com.dfsek.terra.api.entity.EntityType;
|
import com.dfsek.terra.api.entity.EntityType;
|
||||||
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
|
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
|
||||||
import com.dfsek.terra.api.handle.ItemHandle;
|
import com.dfsek.terra.api.handle.ItemHandle;
|
||||||
import com.dfsek.terra.api.handle.WorldHandle;
|
import com.dfsek.terra.api.handle.WorldHandle;
|
||||||
|
|
||||||
import com.dfsek.terra.api.world.biome.PlatformBiome;
|
import com.dfsek.terra.api.world.biome.PlatformBiome;
|
||||||
|
|
||||||
import com.dfsek.terra.minestom.biome.MinestomBiomeLoader;
|
import com.dfsek.terra.minestom.biome.MinestomBiomeLoader;
|
||||||
import com.dfsek.terra.minestom.entity.MinestomEntityType;
|
import com.dfsek.terra.minestom.entity.MinestomEntityType;
|
||||||
import com.dfsek.terra.minestom.item.MinestomItemHandle;
|
import com.dfsek.terra.minestom.item.MinestomItemHandle;
|
||||||
|
|
||||||
import com.dfsek.terra.minestom.world.MinestomChunkGeneratorWrapper;
|
import com.dfsek.terra.minestom.world.MinestomChunkGeneratorWrapper;
|
||||||
import com.dfsek.terra.minestom.world.MinestomWorldHandle;
|
import com.dfsek.terra.minestom.world.MinestomWorldHandle;
|
||||||
|
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
|
|
||||||
public final class MinestomPlatform extends AbstractPlatform {
|
public final class MinestomPlatform extends AbstractPlatform {
|
||||||
|
@ -25,7 +25,7 @@ public class MinestomBiomeLoader implements TypeLoader<PlatformBiome> {
|
|||||||
String id = (String) o;
|
String id = (String) o;
|
||||||
NamespaceID biomeID = NamespaceID.from(id);
|
NamespaceID biomeID = NamespaceID.from(id);
|
||||||
Biome biome = biomeRegistry.get(biomeID);
|
Biome biome = biomeRegistry.get(biomeID);
|
||||||
if (biome == null) throw new LoadException("Biome %s does not exist in registry".formatted(id), depthTracker);
|
if(biome == null) throw new LoadException("Biome %s does not exist in registry".formatted(id), depthTracker);
|
||||||
return new MinestomBiome(biome);
|
return new MinestomBiome(biome);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ public class MinestomBlockState implements BlockState {
|
|||||||
private final Block block;
|
private final Block block;
|
||||||
|
|
||||||
public MinestomBlockState(Block block) {
|
public MinestomBlockState(Block block) {
|
||||||
if (block == null) {
|
if(block == null) {
|
||||||
this.block = Block.AIR;
|
this.block = Block.AIR;
|
||||||
} else {
|
} else {
|
||||||
this.block = block;
|
this.block = block;
|
||||||
@ -23,7 +23,7 @@ public class MinestomBlockState implements BlockState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MinestomBlockState(String data) {
|
public MinestomBlockState(String data) {
|
||||||
if (!data.contains("[")) {
|
if(!data.contains("[")) {
|
||||||
block = Block.fromNamespaceId(data);
|
block = Block.fromNamespaceId(data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -34,7 +34,7 @@ public class MinestomBlockState implements BlockState {
|
|||||||
Block block = Block.fromNamespaceId(namespaceId);
|
Block block = Block.fromNamespaceId(namespaceId);
|
||||||
HashMap<String, String> propertiesMap = new HashMap<>();
|
HashMap<String, String> propertiesMap = new HashMap<>();
|
||||||
|
|
||||||
for (String property : properties.split(",")) {
|
for(String property : properties.split(",")) {
|
||||||
String[] kv = property.split("=");
|
String[] kv = property.split("=");
|
||||||
propertiesMap.put(kv[0].strip(), kv[1].strip());
|
propertiesMap.put(kv[0].strip(), kv[1].strip());
|
||||||
}
|
}
|
||||||
@ -71,18 +71,12 @@ public class MinestomBlockState implements BlockState {
|
|||||||
@Override
|
@Override
|
||||||
public String getAsString(boolean properties) {
|
public String getAsString(boolean properties) {
|
||||||
String name = block.namespace().asString();
|
String name = block.namespace().asString();
|
||||||
if (!properties || block.properties().isEmpty()) {
|
if(!properties || block.properties().isEmpty()) {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
name += "[" + block
|
name += "[" + block.properties().entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).collect(
|
||||||
.properties()
|
Collectors.joining(",")) + "]";
|
||||||
.entrySet()
|
|
||||||
.stream()
|
|
||||||
.map(entry ->
|
|
||||||
entry.getKey() + "=" + entry.getValue()
|
|
||||||
)
|
|
||||||
.collect(Collectors.joining(",")) + "]";
|
|
||||||
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ public class MinestomBlockType implements BlockType {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (obj instanceof MinestomBlockType other) {
|
if(obj instanceof MinestomBlockType other) {
|
||||||
return block.id() == other.block.id();
|
return block.id() == other.block.id();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -27,26 +27,20 @@ public class GeneratedChunkCache {
|
|||||||
this.generator = generator;
|
this.generator = generator;
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.biomeProvider = world.getBiomeProvider();
|
this.biomeProvider = world.getBiomeProvider();
|
||||||
this.cache = Caffeine.newBuilder()
|
this.cache = Caffeine.newBuilder().maximumSize(128).recordStats().build(
|
||||||
.maximumSize(128)
|
(Pair<Integer, Integer> key) -> generateChunk(key.getLeft(), key.getRight()));
|
||||||
.recordStats()
|
|
||||||
.build((Pair<Integer, Integer> key) -> generateChunk(key.getLeft(), key.getRight()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private CachedChunk generateChunk(int x, int z) {
|
private CachedChunk generateChunk(int x, int z) {
|
||||||
CachedChunk chunk = new CachedChunk(dimensionType.minY(), dimensionType.maxY());
|
CachedChunk chunk = new CachedChunk(dimensionType.minY(), dimensionType.maxY());
|
||||||
generator.generateChunkData(
|
generator.generateChunkData(chunk, world, biomeProvider, x, z);
|
||||||
chunk,
|
|
||||||
world,
|
|
||||||
biomeProvider,
|
|
||||||
x, z
|
|
||||||
);
|
|
||||||
return chunk;
|
return chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void displayStats() {
|
public void displayStats() {
|
||||||
CacheStats stats = cache.stats();
|
CacheStats stats = cache.stats();
|
||||||
log.info("Avg load time: {}ms | Hit rate: {}% | Load Count: {}", stats.averageLoadPenalty(), stats.hitRate() * 100, stats.loadCount());
|
log.info("Avg load time: {}ms | Hit rate: {}% | Load Count: {}", stats.averageLoadPenalty(), stats.hitRate() * 100,
|
||||||
|
stats.loadCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
public CachedChunk at(int x, int z) {
|
public CachedChunk at(int x, int z) {
|
||||||
|
@ -5,6 +5,7 @@ import com.dfsek.terra.api.world.ServerWorld;
|
|||||||
import com.dfsek.terra.api.world.chunk.Chunk;
|
import com.dfsek.terra.api.world.chunk.Chunk;
|
||||||
|
|
||||||
import com.dfsek.terra.minestom.block.MinestomBlockState;
|
import com.dfsek.terra.minestom.block.MinestomBlockState;
|
||||||
|
|
||||||
import net.minestom.server.instance.block.Block;
|
import net.minestom.server.instance.block.Block;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
@ -23,11 +23,6 @@ public class MinestomItemHandle implements ItemHandle {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Enchantment> getEnchantments() {
|
public Set<Enchantment> getEnchantments() {
|
||||||
return MinecraftServer
|
return MinecraftServer.getEnchantmentRegistry().values().stream().map(MinestomEnchantment::new).collect(Collectors.toSet());
|
||||||
.getEnchantmentRegistry()
|
|
||||||
.values()
|
|
||||||
.stream()
|
|
||||||
.map(MinestomEnchantment::new)
|
|
||||||
.collect(Collectors.toSet());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,10 +50,8 @@ public class MinestomItemStack implements com.dfsek.terra.api.inventory.ItemStac
|
|||||||
EnchantmentList enchantmentList = base.get(ItemComponent.ENCHANTMENTS);
|
EnchantmentList enchantmentList = base.get(ItemComponent.ENCHANTMENTS);
|
||||||
if(enchantmentList != null) {
|
if(enchantmentList != null) {
|
||||||
enchantmentList.enchantments().forEach((enchantmentKey, integer) -> {
|
enchantmentList.enchantments().forEach((enchantmentKey, integer) -> {
|
||||||
enchantments.put(new MinestomEnchantment(
|
enchantments.put(
|
||||||
Objects.requireNonNull(MinecraftServer.getEnchantmentRegistry().get(enchantmentKey))),
|
new MinestomEnchantment(Objects.requireNonNull(MinecraftServer.getEnchantmentRegistry().get(enchantmentKey))), integer);
|
||||||
integer
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return new MinestomItemMeta(enchantments);
|
return new MinestomItemMeta(enchantments);
|
||||||
@ -63,12 +61,10 @@ public class MinestomItemStack implements com.dfsek.terra.api.inventory.ItemStac
|
|||||||
public void setItemMeta(ItemMeta meta) {
|
public void setItemMeta(ItemMeta meta) {
|
||||||
HashMap<Key<net.minestom.server.item.enchant.Enchantment>, Integer> enchantments = new HashMap<>();
|
HashMap<Key<net.minestom.server.item.enchant.Enchantment>, Integer> enchantments = new HashMap<>();
|
||||||
DynamicRegistry<net.minestom.server.item.enchant.Enchantment> registry = MinecraftServer.getEnchantmentRegistry();
|
DynamicRegistry<net.minestom.server.item.enchant.Enchantment> registry = MinecraftServer.getEnchantmentRegistry();
|
||||||
meta
|
meta.getEnchantments().forEach((key, value) -> {
|
||||||
.getEnchantments()
|
MinestomEnchantment enchantment = (MinestomEnchantment) key;
|
||||||
.forEach((key, value) -> {
|
enchantments.put(registry.getKey(enchantment.getHandle()), value);
|
||||||
MinestomEnchantment enchantment = (MinestomEnchantment) key;
|
});
|
||||||
enchantments.put(registry.getKey(enchantment.getHandle()), value);
|
|
||||||
});
|
|
||||||
|
|
||||||
EnchantmentList list = new EnchantmentList(enchantments);
|
EnchantmentList list = new EnchantmentList(enchantments);
|
||||||
base = base.with(ItemComponent.ENCHANTMENTS, list);
|
base = base.with(ItemComponent.ENCHANTMENTS, list);
|
||||||
|
@ -19,12 +19,7 @@ public class MinestomMaterial implements Item {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack newItemStack(int amount) {
|
public ItemStack newItemStack(int amount) {
|
||||||
return new MinestomItemStack(
|
return new MinestomItemStack(net.minestom.server.item.ItemStack.builder(delegate).amount(amount).build());
|
||||||
net.minestom.server.item.ItemStack
|
|
||||||
.builder(delegate)
|
|
||||||
.amount(amount)
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,13 +25,7 @@ public class MinestomProtoWorld implements ProtoWorld {
|
|||||||
private final TerraMinestomWorld world;
|
private final TerraMinestomWorld world;
|
||||||
private final Setter modifier;
|
private final Setter modifier;
|
||||||
|
|
||||||
public MinestomProtoWorld(
|
public MinestomProtoWorld(GeneratedChunkCache cache, int x, int z, TerraMinestomWorld world, Setter modifier) {
|
||||||
GeneratedChunkCache cache,
|
|
||||||
int x,
|
|
||||||
int z,
|
|
||||||
TerraMinestomWorld world,
|
|
||||||
Setter modifier
|
|
||||||
) {
|
|
||||||
this.cache = cache;
|
this.cache = cache;
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
|
@ -37,13 +37,8 @@ public final class TerraMinestomWorld implements ServerWorld, WorldProperties {
|
|||||||
private final EntityFactory entityFactory;
|
private final EntityFactory entityFactory;
|
||||||
private final BlockEntityFactory blockEntityFactory;
|
private final BlockEntityFactory blockEntityFactory;
|
||||||
|
|
||||||
public TerraMinestomWorld(
|
public TerraMinestomWorld(Instance instance, ConfigPack pack, long seed, EntityFactory entityFactory,
|
||||||
Instance instance,
|
BlockEntityFactory blockEntityFactory) {
|
||||||
ConfigPack pack,
|
|
||||||
long seed,
|
|
||||||
EntityFactory entityFactory,
|
|
||||||
BlockEntityFactory blockEntityFactory
|
|
||||||
) {
|
|
||||||
this.instance = instance;
|
this.instance = instance;
|
||||||
this.pack = pack;
|
this.pack = pack;
|
||||||
this.seed = seed;
|
this.seed = seed;
|
||||||
@ -51,11 +46,7 @@ public final class TerraMinestomWorld implements ServerWorld, WorldProperties {
|
|||||||
this.dimensionType = MinecraftServer.getDimensionTypeRegistry().get(instance.getDimensionType());
|
this.dimensionType = MinecraftServer.getDimensionTypeRegistry().get(instance.getDimensionType());
|
||||||
this.blockEntityFactory = blockEntityFactory;
|
this.blockEntityFactory = blockEntityFactory;
|
||||||
|
|
||||||
this.wrapper = new MinestomChunkGeneratorWrapper(
|
this.wrapper = new MinestomChunkGeneratorWrapper(pack.getGeneratorProvider().newInstance(pack), this, pack);
|
||||||
pack.getGeneratorProvider().newInstance(pack),
|
|
||||||
this,
|
|
||||||
pack
|
|
||||||
);
|
|
||||||
this.entityFactory = entityFactory;
|
this.entityFactory = entityFactory;
|
||||||
|
|
||||||
instance.setGenerator(this.wrapper);
|
instance.setGenerator(this.wrapper);
|
||||||
|
@ -9,6 +9,7 @@ import com.dfsek.terra.minestom.api.BlockEntityFactory;
|
|||||||
import com.dfsek.terra.minestom.api.EntityFactory;
|
import com.dfsek.terra.minestom.api.EntityFactory;
|
||||||
import com.dfsek.terra.minestom.block.DefaultBlockEntityFactory;
|
import com.dfsek.terra.minestom.block.DefaultBlockEntityFactory;
|
||||||
import com.dfsek.terra.minestom.entity.DefaultEntityFactory;
|
import com.dfsek.terra.minestom.entity.DefaultEntityFactory;
|
||||||
|
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.instance.Instance;
|
import net.minestom.server.instance.Instance;
|
||||||
|
|
||||||
@ -39,11 +40,7 @@ public class TerraMinestomWorldBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public TerraMinestomWorldBuilder packById(String id) {
|
public TerraMinestomWorldBuilder packById(String id) {
|
||||||
this.pack = MinestomPlatform
|
this.pack = MinestomPlatform.getInstance().getConfigRegistry().getByID(id).orElseThrow();
|
||||||
.getInstance()
|
|
||||||
.getConfigRegistry()
|
|
||||||
.getByID(id)
|
|
||||||
.orElseThrow();
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user