/** * Create a new InventoryDimension property with the specified dimensions. * * @param width width of the inventory to match * @param height height of the inventory to match */ public InventoryDimension(int width, int height) { super(new Vector2i(width, height)); }
/** * Returns the y level that precipitation ends falling in the given column. * * <p>A value is still returned for columns in biomes which do not * receive precipitation.</p> * * @param column The column value * @return The y level that precipitation ends */ default int getPrecipitationLevelAt(Vector2i column) { return this.getPrecipitationLevelAt(column.getX(), column.getY()); }
/** * Returns a new transform representing a centered rotation of an area of * tiles. The rotation is given is quarter turns. The actual rotation is * {@code quarterTurns * 90}. Areas with differing parities on the axes can * only be rotated by multiples of 180 degrees. * * @param quarterTurns The amount of quarter turns in this rotation * @param size The size of the area to rotate * @return The new rotation transform */ public static DiscreteTransform2 rotationAroundCenter(int quarterTurns, Vector2i size) { Preconditions.checkArgument(size.getX() > 0, "The size on x must be positive"); Preconditions.checkArgument(size.getY() > 0, "The size on y must be positive"); final boolean mul180 = (quarterTurns & 1) == 0; final boolean xEven = (size.getX() & 1) == 0; final boolean yEven = (size.getY() & 1) == 0; Preconditions.checkArgument(mul180 || xEven == yEven, "The size must have the same parity on all axes for rotations that are " + "not a multiple of 180 degrees"); final Vector2i center = size.sub(1, 1).div(2); if (mul180) { return fromRotation(quarterTurns, center, xEven, yEven); } return fromRotation(quarterTurns, center, xEven); }
/** * Gets the number of columns in this inventory. * * @return column count */ public int getColumns() { return this.getValue().getX(); }
/** * Gets the number of rows in this inventory. * * @return row count */ public int getRows() { return this.getValue().getY(); }
@Override public Vector2i div(int a) { return div(a, a); }
public Vector2i sub(Vector2i v) { return sub(v.x, v.y); }
/** * Returns a new transform representing a rotation in the xy plane, around a * given point. The rotation is given is quarter turns. The actual rotation * is {@code quarterTurns * 90}. The tile corner flag change the point to be * the tile corner instead of the center. * * @param quarterTurns The number of quarter turns in this rotation * @param point The point of rotation, as tile coordinates * @param tileCorner Whether or not to use the corner of the tile instead of * the center * @return The new rotation transform */ public static DiscreteTransform2 fromRotation(int quarterTurns, Vector2i point, boolean tileCorner) { Vector2d pointDouble = point.toDouble(); if (tileCorner) { pointDouble = pointDouble.add(0.5, 0.5); } return new DiscreteTransform2( Matrix3d.createTranslation(pointDouble.negate()).rotate(Complexd.fromAngleDeg(quarterTurns * 90)).translate(pointDouble)); }
@Override public int compareTo(Property<?, ?> other) { if (other == null) { return 1; } return this.getValue().compareTo(Coerce.toVector2i(other.getValue())); }
/** * Gets the X position of this slot within the queried parent. * * @return slot x coordinate */ public int getX() { return this.getValue().getX(); }
/** * Gets the Y position of this slot within the queried parent. * * @return slot y coordinate */ public int getY() { return this.getValue().getY(); }
@Override public Vector2i div(int a) { return div(a, a); }
public Vector2i sub(Vector2i v) { return sub(v.x, v.y); }
/** * Adds a a rotation to this transform, in the xy plane, around a given * point, and returns it as a new transform. The rotation is given is * quarter turns. The actual rotation is {@code quarterTurns * 90}. The tile * corner flag changes the point to be the tile upper corner instead of the * center. * * @param quarterTurns The number of quarter turns in this rotation * @param point The point of rotation, as tile coordinates * @param tileCorner Whether or not to use the corner of the tile instead of * the center * @return The rotated transform as a copy */ public DiscreteTransform2 withRotation(int quarterTurns, Vector2i point, boolean tileCorner) { Vector2d pointDouble = point.toDouble(); if (tileCorner) { pointDouble = pointDouble.add(0.5, 0.5); } return new DiscreteTransform2( this.matrix.translate(pointDouble.negate()).rotate(Complexd.fromAngleDeg(quarterTurns * 90)).translate(pointDouble)); }
@Override public int compareTo(Property<?, ?> other) { if (other == null) { return 1; } return this.getValue().compareTo(Coerce.toVector2i(other.getValue())); }
/** * Create a new SlotPos property for matching the specified value with the * specified operator. * * @param x slot x position * @param y slot y position * @param operator the operator to use when comparing with other properties */ public SlotPos(int x, int y, Operator operator) { super(new Vector2i(x, y), operator); }
/** * Returns a new transform representing a centered rotation of an area of * tiles. The rotation is given is quarter turns. The actual rotation is * {@code quarterTurns * 90}. Areas with differing parities on the axes can * only be rotated by multiples of 180 degrees. * * @param quarterTurns The amount of quarter turns in this rotation * @param size The size of the area to rotate * @return The new rotation transform */ public static DiscreteTransform2 rotationAroundCenter(int quarterTurns, Vector2i size) { Preconditions.checkArgument(size.getX() > 0, "The size on x must be positive"); Preconditions.checkArgument(size.getY() > 0, "The size on y must be positive"); final boolean mul180 = (quarterTurns & 1) == 0; final boolean xEven = (size.getX() & 1) == 0; final boolean yEven = (size.getY() & 1) == 0; Preconditions.checkArgument(mul180 || xEven == yEven, "The size must have the same parity on all axes for rotations that are " + "not a multiple of 180 degrees"); final Vector2i center = size.sub(1, 1).div(2); if (mul180) { return fromRotation(quarterTurns, center, xEven, yEven); } return fromRotation(quarterTurns, center, xEven); }