SteamWar/BauSystem2.0
Archiviert
12
0

Update Checkerboard3DMask
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-12-18 10:42:54 +01:00
Ursprung 807a3fddaf
Commit 3ccdec1141
4 geänderte Dateien mit 37 neuen und 62 gelöschten Zeilen

Datei anzeigen

@ -1,43 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.worldedit.mask.checkerboard;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.math.BlockVector3;
public class CheckerboardMask implements Mask {
private int size;
public CheckerboardMask(int size) {
this.size = size;
}
@Override
public boolean test(BlockVector3 vector) {
if (size == 0) return true;
return (vector.getBlockX() / size + vector.getBlockZ() / size) % 2 == 0;
}
@Override
public Mask copy() {
return new CheckerboardMask(size);
}
}

Datei anzeigen

@ -24,20 +24,30 @@ import com.sk89q.worldedit.math.BlockVector3;
public class Checkerboard3DMask implements Mask {
private int size;
private int x;
private int y;
private int z;
public Checkerboard3DMask(int size) {
this.size = size;
public Checkerboard3DMask(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
@Override
public boolean test(BlockVector3 vector) {
if (size == 0) return true;
return (vector.getBlockX() / size + vector.getBlockY() / size + vector.getBlockZ() / size) % 2 == 0;
if (x == 0 && y == 0 && z == 0) return true;
if (x == 0 && y == 0) return (vector.getBlockZ() / z) % 2 == 0;
if (x == 0 && z == 0) return (vector.getBlockY() / y) % 2 == 0;
if (y == 0 && z == 0) return (vector.getBlockX() / x) % 2 == 0;
if (x == 0) return (vector.getBlockY() / y + vector.getBlockZ() / z) % 2 == 0;
if (y == 0) return (vector.getBlockX() / x + vector.getBlockZ() / z) % 2 == 0;
if (z == 0) return (vector.getBlockX() / x + vector.getBlockY() / y) % 2 == 0;
return (vector.getBlockX() / x + vector.getBlockY() / y + vector.getBlockZ() / z) % 2 == 0;
}
@Override
public Mask copy() {
return new Checkerboard3DMask(size);
return new Checkerboard3DMask(x, y, z);
}
}

Datei anzeigen

@ -39,7 +39,7 @@ public class FAWECheckerboard3DMaskParser extends FAWEMaskParser {
@Override
protected Stream<String> getSuggestions(String argumentInput, int index) {
if (index == 0) {
if (index < 3) {
return SuggestionHelper.suggestPositiveIntegers(argumentInput);
}
return Stream.empty();
@ -47,13 +47,24 @@ public class FAWECheckerboard3DMaskParser extends FAWEMaskParser {
@Override
protected Mask parseFromInput(@Nonnull String[] arguments, ParserContext context) throws InputParseException {
if (arguments.length != 1) {
return new Checkerboard3DMask(1);
if (arguments.length == 1) {
try {
int size = Integer.parseInt(arguments[0]);
return new Checkerboard3DMask(size, size, size);
} catch (NumberFormatException e) {
throw new InputParseException("Invalid number: " + arguments[0]);
}
}
try {
return new Checkerboard3DMask(Integer.parseInt(arguments[0]));
} catch (NumberFormatException e) {
throw new InputParseException("Invalid number: " + arguments[0]);
if (arguments.length == 3) {
try {
int sizeX = Integer.parseInt(arguments[0]);
int sizeY = Integer.parseInt(arguments[1]);
int sizeZ = Integer.parseInt(arguments[2]);
return new Checkerboard3DMask(sizeX, sizeY, sizeZ);
} catch (NumberFormatException e) {
throw new InputParseException("Invalid numbers: " + arguments[0] + ", " + arguments[1] + ", " + arguments[2]);
}
}
throw new InputParseException("Invalid number of arguments");
}
}

Datei anzeigen

@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.worldedit.mask.checkerboard;
package de.steamwar.bausystem.features.worldedit.mask.checkerboard3d;
import com.sk89q.worldedit.command.util.SuggestionHelper;
import com.sk89q.worldedit.extension.input.InputParseException;
@ -25,7 +25,6 @@ import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.function.mask.Mask;
import de.steamwar.bausystem.features.worldedit.utils.FAWEMaskParser;
import de.steamwar.linkage.Linked;
import de.steamwar.linkage.PluginCheck;
import javax.annotation.Nonnull;
import java.util.stream.Stream;
@ -47,11 +46,9 @@ public class FAWECheckerboardMaskParser extends FAWEMaskParser {
@Override
protected Mask parseFromInput(@Nonnull String[] arguments, ParserContext context) throws InputParseException {
if (arguments.length != 1) {
return new CheckerboardMask(1);
}
try {
return new CheckerboardMask(Integer.parseInt(arguments[0]));
int size = Integer.parseInt(arguments[0]);
return new Checkerboard3DMask(size, 0, size);
} catch (NumberFormatException e) {
throw new InputParseException("Invalid number: " + arguments[0]);
}