Skip to content

Commit

Permalink
fix: biome type registry bind error
Browse files Browse the repository at this point in the history
Former-commit-id: 4832064
  • Loading branch information
CoolLoong committed Jul 8, 2023
1 parent 9e6a2fc commit fd7694c
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/.gradle/
buildSrc/**
**/build
**/logs
/Data/bedrock-samples/behavior_pack/
/Data/bedrock-samples/documentation/
/Data/bedrock-samples/resource_pack/
Expand Down
33 changes: 0 additions & 33 deletions Allay-API/src/main/java/cn/allay/api/world/biome/BiomeType.java
Original file line number Diff line number Diff line change
@@ -1,53 +1,20 @@
package cn.allay.api.world.biome;

import cn.allay.api.data.VanillaBiomeId;
import lombok.ToString;

/**
* Allay Project 2023/6/3
*
* @author daoge_cmd
*/
public interface BiomeType {

static BiomeType create(VanillaBiomeId id) {
var type = new SimpleBiomeType(id.getName(), id.getId());
BiomeTypeRegistry.getRegistry().register(type.getName(), type);
return type;
}

//TODO: Custom biome

String getName();

int getId();

@ToString
final class SimpleBiomeType implements BiomeType {
private final String name;
private final int id;

public SimpleBiomeType(String name, int id) {
this.name = name;
this.id = id;
}

@Override
public String getName() {
return name;
}

@Override
public int getId() {
return id;
}

public String name() {
return name;
}

public int id() {
return id;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cn.allay.api.world.biome;

import cn.allay.api.ApiInstanceHolder;
import cn.allay.api.identifier.Identifier;
import cn.allay.api.registry.MappedRegistry;
import org.cloudburstmc.nbt.NbtMap;

Expand All @@ -19,5 +18,5 @@ static BiomeTypeRegistry getRegistry() {
return REGISTRY.get();
}

NbtMap getBiomeDefinitionListTag();
NbtMap getBiomeDefinition();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package cn.allay.api.world.biome;

import com.google.common.base.Objects;

final class SimpleBiomeType implements BiomeType {
private final String name;
private final int id;

public SimpleBiomeType(String name, int id) {
this.name = name;
this.id = id;
}

@Override
public String getName() {
return name;
}

@Override
public int getId() {
return id;
}

public String name() {
return name;
}

public int id() {
return id;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SimpleBiomeType that = (SimpleBiomeType) o;
return Objects.equal(name, that.name);
}

@Override
public int hashCode() {
return Objects.hashCode(name);
}
}
6 changes: 5 additions & 1 deletion Allay-Server/src/main/java/cn/allay/server/Allay.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import cn.allay.api.item.type.ItemTypeRegistry;
import cn.allay.api.scheduler.Scheduler;
import cn.allay.api.server.Server;
import cn.allay.api.world.biome.BiomeType;
import cn.allay.api.world.biome.BiomeTypeRegistry;
import cn.allay.api.world.biome.VanillaBiomeTypes;
import cn.allay.server.block.attribute.AllayVanillaBlockAttributeRegistry;
import cn.allay.server.block.palette.AllayVanillaBlockStatePalette;
import cn.allay.server.block.type.AllayBlockStateHashPalette;
Expand Down Expand Up @@ -73,7 +75,9 @@ public static void initAllayAPI() throws MissingImplementationException {
api.bind(EntityTypeRegistry.class, AllayEntityTypeRegistry::new, instance -> ((AllayEntityTypeRegistry) instance).init());

//Biome
api.bind(BiomeTypeRegistry.class, AllayBiomeTypeRegistry::new);
api.bind(BiomeTypeRegistry.class, AllayBiomeTypeRegistry::new, (r) -> {
BiomeType ocean = VanillaBiomeTypes.OCEAN;
});

api.implement("Allay");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private void sendStartGamePacket() {
sendPacket(startGamePacket);

var biomeDefinitionListPacket = new BiomeDefinitionListPacket();
biomeDefinitionListPacket.setDefinitions(BiomeTypeRegistry.getRegistry().getBiomeDefinitionListTag());
biomeDefinitionListPacket.setDefinitions(BiomeTypeRegistry.getRegistry().getBiomeDefinition());
sendPacket(biomeDefinitionListPacket);

var availableEntityIdentifiersPacket = new AvailableEntityIdentifiersPacket();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package cn.allay.server.world.biome;

import cn.allay.api.identifier.Identifier;
import cn.allay.api.registry.SimpleMappedRegistry;
import cn.allay.api.world.biome.BiomeType;
import cn.allay.api.world.biome.BiomeTypeRegistry;
import cn.allay.api.world.biome.VanillaBiomeTypes;
import lombok.SneakyThrows;
import org.cloudburstmc.nbt.MutableNbtMap;
import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.nbt.NbtUtils;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -19,23 +19,23 @@
*/
public class AllayBiomeTypeRegistry extends SimpleMappedRegistry<String, BiomeType, Map<String, BiomeType>> implements BiomeTypeRegistry {

private NbtMap biomeDefinitionListTag;
private MutableNbtMap biomeDefinition;

public AllayBiomeTypeRegistry() {
super(null, input -> new HashMap<>());
//Load vanilla biome type constants
BiomeType ocean = VanillaBiomeTypes.OCEAN;
loadVanillaBiomeDefinitionListTag();
loadVanillaBiomeDefinition();
}

@SneakyThrows
private void loadVanillaBiomeDefinitionListTag() {
//TODO: Support custom biome
biomeDefinitionListTag = (NbtMap) NbtUtils.createNetworkReader(AllayBiomeTypeRegistry.class.getClassLoader().getResourceAsStream("biome_definitions_full.nbt")).readTag();
private void loadVanillaBiomeDefinition() {
try (InputStream stream = AllayBiomeTypeRegistry.class.getClassLoader().getResourceAsStream("biome_definitions_full.nbt")) {
assert stream != null;
biomeDefinition = MutableNbtMap.from((NbtMap) NbtUtils.createNetworkReader(stream).readTag());
}
}

@Override
public NbtMap getBiomeDefinitionListTag() {
return biomeDefinitionListTag;
public NbtMap getBiomeDefinition() {
return biomeDefinition.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import cn.allay.api.world.chunk.Chunk;
import cn.allay.server.world.chunk.AllayChunk;
import cn.allay.testutils.AllayTestExtension;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import static org.junit.jupiter.api.Assertions.assertEquals;

@Slf4j
@ExtendWith(AllayTestExtension.class)
public class AllayChunkTest {
@Test
Expand All @@ -20,6 +22,7 @@ void testParallelUpdateBlock() throws InterruptedException {
for (int j = 0; j < 16; j++) {
for (int k = 0; k < 100; k++) {
chunk.setBlock(i, k, j, VanillaBlockTypes.WOOD_TYPE.getDefaultState());
log.info("%d %d %d write".formatted(i, k, j));
}
}
}
Expand All @@ -29,6 +32,7 @@ void testParallelUpdateBlock() throws InterruptedException {
for (int j = 0; j < 16; j++) {
for (int k = 0; k < 100; k++) {
assertEquals(VanillaBlockTypes.WOOD_TYPE.getDefaultState(), chunk.getBlock(i, k, j), "(" + i + "," + k + "," + j + ") GET BLOCK ERROR!");
log.info("%d %d %d read".formatted(i, k, j));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ log4j = "2.20.0"
jline = "3.23.0"

[libraries]
nbt = { group = "com.github.AllayMC", name = "NBT", version = "3.0.5" }
nbt = { group = "com.github.AllayMC", name = "NBT", version = "3.0.6" }
network = { group = "org.cloudburstmc.protocol", name = "bedrock-connection", version = "3.0.0.Beta1-SNAPSHOT" }
guava = { group = "com.google.guava", name = "guava", version = "31.1-jre" }
gson = { group = "com.google.code.gson", name = "gson", version = "2.10.1" }
Expand Down

0 comments on commit fd7694c

Please sign in to comment.