Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
chore: add checks when creating dimension types to client registry er…
Browse files Browse the repository at this point in the history
…rors
  • Loading branch information
mworzala committed Feb 9, 2024
1 parent 6d4eec1 commit 1619ced
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/main/java/net/minestom/server/world/DimensionType.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.minestom.server.world;

import net.minestom.server.utils.NamespaceID;
import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jglrxavpok.hephaistos.mcdata.SizesKt;
Expand Down Expand Up @@ -64,6 +65,15 @@ public class DimensionType {
boolean skylightEnabled, @Nullable Long fixedTime, boolean raidCapable,
boolean respawnAnchorSafe, boolean ultrawarm, boolean bedSafe, String effects, boolean piglinSafe,
int minY, int height, int logicalHeight, double coordinateScale, NamespaceID infiniburn) {
Check.argCondition(minY < -2032, "minY cannot be lower than -2032");
Check.argCondition(minY > 2031, "minY cannot be higher than 2031");
Check.argCondition(minY % 16 != 0, "minY must be a multiple of 16");
Check.argCondition(height < 16, "height cannot be lower than 16");
Check.argCondition(height > 4064, "height cannot be higher than 4064");
Check.argCondition(height % 16 != 0, "height must be a multiple of 16");
Check.argCondition(minY + height > 2031, "buildable height (minY + height) cannot be higher than 2031");
Check.argCondition(logicalHeight > height, "logicalHeight cannot be higher than height");

this.name = name;
this.natural = natural;
this.ambientLight = ambientLight;
Expand Down Expand Up @@ -356,9 +366,13 @@ public DimensionType.DimensionTypeBuilder infiniburn(NamespaceID infiniburn) {
}

public DimensionType build() {
return new DimensionType(name, natural, ambientLight, ceilingEnabled, skylightEnabled,
fixedTime, raidCapable, respawnAnchorSafe, ultrawarm, bedSafe, effects,
piglinSafe, minY, height, logicalHeight, coordinateScale, infiniburn);
try {
return new DimensionType(name, natural, ambientLight, ceilingEnabled, skylightEnabled,
fixedTime, raidCapable, respawnAnchorSafe, ultrawarm, bedSafe, effects,
piglinSafe, minY, height, logicalHeight, coordinateScale, infiniburn);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Invalid dimension type (" + name + "): " + e.getMessage());
}
}
}
}

0 comments on commit 1619ced

Please sign in to comment.