|
| 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 | +} |
0 commit comments