Skip to content

Commit bdff3e7

Browse files
committed
Add checkerboard validator
Took 14 minutes
1 parent 2b9d675 commit bdff3e7

File tree

3 files changed

+78
-3
lines changed

3 files changed

+78
-3
lines changed

src/main/java/de/derfrzocker/chunkremover/ChunkRemover.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import de.derfrzocker.chunkremover.impl.ChunkRemoverServiceImpl;
2929
import de.derfrzocker.chunkremover.impl.WorldDataYamlImpl;
3030
import de.derfrzocker.chunkremover.impl.v1_16_R3.WorldHandler_v1_16_R3;
31+
import de.derfrzocker.chunkremover.impl.validators.CheckerboardValidator;
3132
import de.derfrzocker.chunkremover.impl.validators.RandomValidator;
3233
import de.derfrzocker.spigot.utils.Config;
3334
import de.derfrzocker.spigot.utils.Version;
@@ -81,6 +82,7 @@ public void onEnable() {
8182

8283
private void registerValidators(ChunkRemoverService chunkRemoverService) {
8384
chunkRemoverService.registerChunkValidator("random", new RandomValidator());
85+
chunkRemoverService.registerChunkValidator("checkerboard", new CheckerboardValidator());
8486
chunkRemoverService.registerChunkValidator("always-true", (worldInfo, chunkPosition) -> true);
8587
}
8688

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2021 Marvin (DerFrZocker)
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package de.derfrzocker.chunkremover.impl.validators;
26+
27+
import de.derfrzocker.chunkremover.api.ChunkPosition;
28+
import de.derfrzocker.chunkremover.api.ChunkValidator;
29+
import de.derfrzocker.chunkremover.api.ValidatorData;
30+
import de.derfrzocker.chunkremover.api.WorldInfo;
31+
import org.bukkit.util.NumberConversions;
32+
import org.jetbrains.annotations.NotNull;
33+
34+
// config values:
35+
// 'inverted': [true, false] removed chunks become solid and solid removed
36+
// 'tile-length.x/z': integer the length of one tile
37+
public class CheckerboardValidator implements ChunkValidator {
38+
39+
@Override
40+
public boolean shouldGenerate(@NotNull WorldInfo worldInfo, @NotNull ChunkPosition chunkPosition) {
41+
ValidatorData validatorData = worldInfo.getWorldData().getValidatorData();
42+
int tileLengthX = NumberConversions.toInt(validatorData.get("tile-length.x", 2));
43+
int tileLengthZ = NumberConversions.toInt(validatorData.get("tile-length.z", 2));
44+
boolean inverted = validatorData.getBoolean("inverted", false);
45+
46+
int x = chunkPosition.getX();
47+
int z = chunkPosition.getZ();
48+
49+
if (x < 0) {
50+
x++;
51+
inverted = !inverted;
52+
}
53+
54+
if (z < 0) {
55+
z++;
56+
inverted = !inverted;
57+
}
58+
59+
int tileX = x / tileLengthX;
60+
int tileZ = z / tileLengthZ;
61+
boolean resultX = (tileX & 1) == 0;
62+
boolean resultZ = (tileZ & 1) == 0;
63+
64+
if ((resultX && resultZ) || (!resultX && !resultZ)) {
65+
return !inverted;
66+
}
67+
68+
return inverted;
69+
}
70+
71+
}

src/main/resources/config.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ world-datas:
4949
# the end cristal on top), regardless if the chunk is removed or not.
5050
affect-spawn-chunks: true
5151
chunk-validator:
52-
name: "random"
52+
name: "checkerboard" # generateds a checkerboard stile world
5353
data:
54-
name-seeded: false
55-
chance: 10.5
54+
inverted: false # removed becomes generated and generated removed
55+
tile-length: # the tile length in chunks
56+
x: 2
57+
z: 2

0 commit comments

Comments
 (0)