Search in sources :

Example 6 with Vector2

use of com.sk89q.worldedit.math.Vector2 in project FastAsyncWorldEdit by IntellectualSites.

the class YAMLNode method prepareSerialization.

/**
 * Prepare a value for serialization, in case it's not a native type
 * (and we don't want to serialize objects as YAML objects).
 *
 * @param value the value to serialize
 * @return the new object
 */
private Object prepareSerialization(Object value) {
    if (value instanceof Vector3) {
        Map<String, Double> out = new LinkedHashMap<>();
        Vector3 vec = (Vector3) value;
        out.put("x", vec.getX());
        out.put("y", vec.getY());
        out.put("z", vec.getZ());
        return out;
    } else if (value instanceof BlockVector3) {
        Map<String, Integer> out = new LinkedHashMap<>();
        BlockVector3 vec = (BlockVector3) value;
        out.put("x", vec.getBlockX());
        out.put("y", vec.getBlockY());
        out.put("z", vec.getBlockZ());
        return out;
    } else if (value instanceof Vector2) {
        Map<String, Double> out = new LinkedHashMap<>();
        Vector2 vec = (Vector2) value;
        out.put("x", vec.getX());
        out.put("z", vec.getZ());
        return out;
    } else if (value instanceof BlockVector2) {
        Map<String, Integer> out = new LinkedHashMap<>();
        BlockVector2 vec = (BlockVector2) value;
        out.put("x", vec.getBlockX());
        out.put("z", vec.getBlockZ());
        return out;
    }
    return value;
}
Also used : BlockVector2(com.sk89q.worldedit.math.BlockVector2) Vector2(com.sk89q.worldedit.math.Vector2) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Vector3(com.sk89q.worldedit.math.Vector3) BlockVector3(com.sk89q.worldedit.math.BlockVector3) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) BlockVector2(com.sk89q.worldedit.math.BlockVector2) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with Vector2

use of com.sk89q.worldedit.math.Vector2 in project FastAsyncWorldEdit by IntellectualSites.

the class CylinderRegion method contract.

/**
 * Contract the region.
 *
 * @param changes array/arguments with multiple related changes
 */
@Override
public void contract(BlockVector3... changes) throws RegionOperationException {
    center = center.subtract(calculateDiff2D(changes));
    Vector2 newRadius = radius.subtract(calculateChanges2D(changes).toVector2());
    radius = Vector2.at(1.5, 1.5).getMaximum(newRadius);
    this.radiusInverse = Vector2.ONE.divide(radius);
    for (BlockVector3 change : changes) {
        int height = maxY - minY;
        int changeY = change.getBlockY();
        if (changeY > 0) {
            minY += Math.min(height, changeY);
        } else {
            maxY += Math.max(-height, changeY);
        }
    }
}
Also used : BlockVector2(com.sk89q.worldedit.math.BlockVector2) Vector2(com.sk89q.worldedit.math.Vector2) BlockVector3(com.sk89q.worldedit.math.BlockVector3)

Aggregations

Vector2 (com.sk89q.worldedit.math.Vector2)7 BlockVector2 (com.sk89q.worldedit.math.BlockVector2)6 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)3 Vector3 (com.sk89q.worldedit.math.Vector3)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1