Skip to content

Commit

Permalink
hollow-cube/biome-manager-concurrency (Minestom#39)
Browse files Browse the repository at this point in the history
Co-authored-by: tahmid-23 <60953955+tahmid-23@users.noreply.github.com>

See Minestom#1917

(cherry picked from commit ef37e40)
  • Loading branch information
mworzala authored and NxDs committed Oct 10, 2023
1 parent a943ad3 commit 64e82dc
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/main/java/net/minestom/server/world/biomes/BiomeManager.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package net.minestom.server.world.biomes;

import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import net.minestom.server.utils.NamespaceID;
import org.jglrxavpok.hephaistos.nbt.NBT;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
Expand All @@ -10,6 +8,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


/**
Expand All @@ -18,7 +17,7 @@
* Contains {@link Biome#PLAINS} by default but can be removed.
*/
public final class BiomeManager {
private final Int2ObjectMap<Biome> biomes = new Int2ObjectOpenHashMap<>();
private final Map<Integer, Biome> biomes = new ConcurrentHashMap<>();

public BiomeManager() {
addBiome(Biome.PLAINS);
Expand All @@ -29,7 +28,7 @@ public BiomeManager() {
*
* @param biome the biome to add
*/
public synchronized void addBiome(Biome biome) {
public void addBiome(Biome biome) {
this.biomes.put(biome.id(), biome);
}

Expand All @@ -38,7 +37,7 @@ public synchronized void addBiome(Biome biome) {
*
* @param biome the biome to remove
*/
public synchronized void removeBiome(Biome biome) {
public void removeBiome(Biome biome) {
this.biomes.remove(biome.id());
}

Expand All @@ -47,7 +46,7 @@ public synchronized void removeBiome(Biome biome) {
*
* @return an immutable copy of the biomes already registered
*/
public synchronized Collection<Biome> unmodifiableCollection() {
public Collection<Biome> unmodifiableCollection() {
return Collections.unmodifiableCollection(biomes.values());
}

Expand All @@ -57,11 +56,11 @@ public synchronized Collection<Biome> unmodifiableCollection() {
* @param id the id of the biome
* @return the {@link Biome} linked to this id
*/
public synchronized Biome getById(int id) {
public Biome getById(int id) {
return biomes.get(id);
}

public synchronized Biome getByName(NamespaceID namespaceID) {
public Biome getByName(NamespaceID namespaceID) {
Biome biome = null;
for (final Biome biomeT : biomes.values()) {
if (biomeT.name().equals(namespaceID)) {
Expand All @@ -72,7 +71,7 @@ public synchronized Biome getByName(NamespaceID namespaceID) {
return biome;
}

public synchronized NBTCompound toNBT() {
public NBTCompound toNBT() {
return NBT.Compound(Map.of(
"type", NBT.String("minecraft:worldgen/biome"),
"value", NBT.List(NBTType.TAG_Compound, biomes.values().stream().map(Biome::toNbt).toList())));
Expand Down

0 comments on commit 64e82dc

Please sign in to comment.