Skip to content

Commit

Permalink
Removed Lombok & Improved Performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Outspending committed Jan 3, 2024
1 parent db8f630 commit 352bce0
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 37 deletions.
4 changes: 0 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ allprojects {
}
}

dependencies {
compileOnly("org.projectlombok:lombok:1.18.30")
annotationProcessor("org.projectlombok:lombok:1.18.30")
}
}

val nmsVersions = listOf("1.19_R2", "1.19_R3", "1.20_R1", "1.20_R2", "1.20_R3")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package me.outspending.biomesapi.benchmarks;

import me.outspending.biomesapi.biome.CustomBiome;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;

Expand Down
11 changes: 9 additions & 2 deletions src/main/java/me/outspending/biomesapi/BiomeTempModifier.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.outspending.biomesapi;

import lombok.Getter;
import me.outspending.biomesapi.annotations.AsOf;
import net.minecraft.world.level.biome.Biome;

Expand All @@ -11,7 +10,6 @@
*
* @version 0.0.1
*/
@Getter
@AsOf("0.0.1")
public enum BiomeTempModifier {

Expand Down Expand Up @@ -45,4 +43,13 @@ public enum BiomeTempModifier {
this.modifier = modifier;
}

/**
* This method returns the TemperatureModifier that corresponds to the enum value.
*
* @return The TemperatureModifier that corresponds to the enum value.
*/
public Biome.TemperatureModifier getModifier() {
return modifier;
}

}
7 changes: 5 additions & 2 deletions src/main/java/me/outspending/biomesapi/BiomeUpdaterImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ public void updateChunk(Chunk chunk) {

@Override
public void updateChunks(Location from, Location to) {
if (from == null || to == null)
if (from == null || to == null) {
throw new IllegalArgumentException("Locations cannot be null.");
} else {
List<Chunk> updateChunks = getChunksBetweenLocations(from, to);

updateChunks(getChunksBetweenLocations(from, to));
updateChunks(updateChunks);
}
}

@Override
Expand Down
19 changes: 15 additions & 4 deletions src/main/java/me/outspending/biomesapi/biome/BiomeHandler.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package me.outspending.biomesapi.biome;

import lombok.Getter;
import lombok.experimental.UtilityClass;
import me.outspending.biomesapi.annotations.AsOf;
import me.outspending.biomesapi.exceptions.UnknownBiomeException;
import me.outspending.biomesapi.registry.BiomeResourceKey;
Expand All @@ -20,12 +18,25 @@
* @version 0.0.1
*/
@AsOf("0.0.1")
@UtilityClass
public class BiomeHandler {

@Getter
private static final List<CustomBiome> registeredBiomes = new ArrayList<>();

public BiomeHandler() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated.");
}

/**
* This method gets the registered biomes list
*
* @version 0.0.1
* @return
*/
@AsOf("0.0.1")
public static List<CustomBiome> getRegisteredBiomes() {
return registeredBiomes;
}

/**
* This method retrieves a Biome object from the Minecraft server's biome registry.
* It uses the Bukkit API to get the server instance and then accesses the server's biome registry.
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/me/outspending/biomesapi/nms/NMSHandler.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.outspending.biomesapi.nms;

import lombok.experimental.UtilityClass;
import me.outspending.biomesapi.annotations.AsOf;
import me.outspending.biomesapi.exceptions.UnknownNMSVersionException;
import org.bukkit.Bukkit;
Expand All @@ -16,7 +15,6 @@
*
* @version 0.0.1
*/
@UtilityClass
@AsOf("0.0.1")
public class NMSHandler {

Expand All @@ -25,6 +23,10 @@ public class NMSHandler {
*/
private static NMS NMS_VERSION;

public NMSHandler() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated.");
}

/**
* Static initializer for the NMSHandler class.
* This method is invoked when the class is loaded by the JVM.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,15 @@ public String toString() {
@Override
@AsOf("0.0.1")
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
if (obj instanceof BiomeResourceKey key) {
ResourceLocation location = key.resourceLocation();
String namespace = location.getNamespace();
String path = location.getPath();

BiomeResourceKey key = (BiomeResourceKey) obj;
String namespace = key.resourceLocation().getNamespace();
String path = key.resourceLocation().getPath();
return namespace.equals(this.resourceLocation.getNamespace()) && path.equals(this.resourceLocation.getPath());
}

return namespace.equals(this.resourceLocation.getNamespace()) && path.equals(this.resourceLocation.getPath());
return false;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.outspending.biomesapi.renderer;

import lombok.Getter;
import me.outspending.biomesapi.annotations.AsOf;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.core.particles.SimpleParticleType;
Expand All @@ -12,7 +11,6 @@
*
* @version 0.0.1
*/
@Getter
@AsOf("0.0.1")
public enum AmbientParticle {
ASH(ParticleTypes.ASH),
Expand Down Expand Up @@ -105,4 +103,16 @@ public enum AmbientParticle {
this.particle = particle;
}

/**
* This method returns the SimpleParticleType associated with the ambient particle.
* The @AsOf annotation indicates the version when this method was introduced.
*
* @return the SimpleParticleType associated with the ambient particle
* @version 0.0.1
*/
@AsOf("0.0.1")
public SimpleParticleType getParticle() {
return particle;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.outspending.biomesapi;
package me.outspending.biomesapi.setter;

import lombok.experimental.UtilityClass;
import me.outspending.biomesapi.annotations.AsOf;
import me.outspending.biomesapi.biome.CustomBiome;
import org.bukkit.Chunk;
Expand All @@ -22,6 +21,9 @@
@AsOf("0.0.1")
public interface BiomeSetter {

int MIN_HEIGHT = -64;
int MAX_HEIGHT = 320;

/**
* Returns the RegionAccessor for the given location.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package me.outspending.biomesapi.setter;

import me.outspending.biomesapi.biome.CustomBiome;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.util.BoundingBox;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;

public class ClientBiomeSetter implements BiomeSetter {

private final Player client;

public ClientBiomeSetter(@NotNull Player client) {
this.client = client;
}

public Player getClient() {
return client;
}

@Override
public void setBlockBiome(@NotNull Block block, @NotNull CustomBiome customBiome) {
setBlockBiome(block, customBiome, false);
}

@Override
public void setBlockBiome(@NotNull Block block, @NotNull CustomBiome customBiome, boolean updateBiome) {
// TODO: Method
}

@Override
public void setChunkBiome(@NotNull Chunk chunk, @NotNull CustomBiome customBiome) {
setChunkBiome(chunk, customBiome, false);
}

@Override
public void setChunkBiome(@NotNull Chunk chunk, @NotNull CustomBiome customBiome, boolean updateBiome) {
setChunkBiome(chunk, MIN_HEIGHT, MAX_HEIGHT, customBiome, false);
}

@Override
public void setChunkBiome(@NotNull Chunk chunk, int minHeight, int maxHeight, @NotNull CustomBiome customBiome) {
setChunkBiome(chunk, minHeight, maxHeight, customBiome, false);
}

@Override
public void setChunkBiome(@NotNull Chunk chunk, int minHeight, int maxHeight, @NotNull CustomBiome customBiome, boolean updateBiome) {
// TODO: Method
}

@Override
public void setBoundingBoxBiome(@NotNull World world, @NotNull BoundingBox boundingBox, @NotNull CustomBiome customBiome) {
// TODO: Method
}

@Override
public void setRegionBiome(@NotNull Location from, @NotNull Location to, @NotNull CustomBiome customBiome) {
setRegionBiome(from, to , customBiome, false);
}

@Override
public void setRegionBiome(@NotNull Location from, @NotNull Location to, @NotNull CustomBiome customBiome, boolean updateBiome) {
// TODO: Method
}

@Override
public void setRegionBiome(@NotNull World world, @NotNull Vector from, @NotNull Vector to, @NotNull CustomBiome customBiome) {
setRegionBiome(world, from, to, customBiome, false);
}

@Override
public void setRegionBiome(@NotNull World world, @NotNull Vector from, @NotNull Vector to, @NotNull CustomBiome customBiome, boolean updateBiome) {
setRegionBiome(world, from.toLocation(world), to.toLocation(world), customBiome, updateBiome);
}

@Override
public void setRegionBiome(@NotNull World world, @NotNull Location from, @NotNull Location to, @NotNull CustomBiome customBiome, boolean updateBiome) {

}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
package me.outspending.biomesapi;
package me.outspending.biomesapi.setter;

import me.outspending.biomesapi.BiomeUpdater;
import me.outspending.biomesapi.biome.CustomBiome;
import me.outspending.biomesapi.misc.PointRange3D;
import me.outspending.biomesapi.nms.NMSHandler;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.util.BoundingBox;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;

public class BiomeSetterImpl implements BiomeSetter {
public class GlobalBiomeSetter implements BiomeSetter {

@SuppressWarnings("deprecation")
private static final UnsafeValues UNSAFE = Bukkit.getUnsafe();
private static final BiomeUpdater BIOME_UPDATER = BiomeUpdater.of();

private static final int MAX_HEIGHT = 320;
private static final int MIN_HEIGHT = -64;

@Override
public void setBlockBiome(@NotNull Block block, @NotNull CustomBiome customBiome) {
setBlockBiome(block, customBiome, false);
Expand Down Expand Up @@ -112,14 +109,23 @@ public void setRegionBiome(@NotNull World world, @NotNull Vector from, @NotNull

@Override
public void setRegionBiome(@NotNull World world, @NotNull Location from, @NotNull Location to, @NotNull CustomBiome customBiome, boolean updateBiome) {
NMSHandler.executeNMS(nms -> {
if (!from.getWorld().equals(to.getWorld())) {
throw new RuntimeException("Locations must be in the same world!");
} else {
NamespacedKey key = customBiome.toNamespacedKey();
PointRange3D range = PointRange3D.of(from, to);

nms.updateBiome(range.getMinLocation(world), range.getMaxLocation(world), customBiome.toNamespacedKey());
});
for (int x = range.minX(); x <= range.maxX(); x++) {
for (int y = range.minY(); y <= range.maxY(); y++) {
for (int z = range.minZ(); z <= range.maxZ(); z++) {
UNSAFE.setBiomeKey(world, x, y, z, key);
}
}
}

if (updateBiome) {
BIOME_UPDATER.updateChunks(from, to);
if (updateBiome) {
BIOME_UPDATER.updateChunks(from, to);
}
}
}

Expand Down

0 comments on commit 352bce0

Please sign in to comment.