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