Package com.petrolpark.util
Class Mask
java.lang.Object
com.petrolpark.util.Mask
- All Implemented Interfaces:
Cloneable
A set of "enabled" pixels in a global 2D grid.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidSubtract the givenMaskfrom this one.voidclear(int x, int y) Removes the given pixel from thisMask.clone()voidcombine(Mask mask, Mask.Combination combination) voidcover(int minX, int minY, int maxX, int maxY) Does not change thisMask, but expands the BitSet internally to cover at least the given space.voiddownsample(int factor) Get a newMaskby splitting this Mask intofactorbyfactorblocks and setting pixels in that Mask if any pixels in the corresponding block in this Mask are set.booleanstatic final com.mojang.serialization.Codec<Mask> friendlyCodecSized(int maxWidth, int maxHeight) static final MaskfromRowStrings(int xOffset, int yOffset, List<String> rowStrings) Deserialize aMask.static final MaskfromTo(int fromX, int fromY, int toX, int toY) Construct aMaskwith the given upper and lower corners.booleanget(int x, int y) booleangetRegion(int minX, int minY, int maxX, int maxY) trueif any pixels are set in the given regionintmaxX()Get the internal x maximum of thisMask.intmaxY()Get the internal y maximum of thisMask.intminX()Get the internal x origin of thisMask.intminY()Get the internal y origin of thisMask.voidmove(int dX, int dY) Moves every pixel in thisMask.voidEffectively add the givenMaskto this one.static final Maskrect(int x, int y, int width, int height) Construct aMaskat the given position of the given size.List<net.minecraft.client.renderer.Rect2i> Convert thisMaskto a List ofrectangles.Serialize thisMask.voidset(int x, int y) Sets the given pixel in thisMask.
-
Field Details
-
FRIENDLY_CODEC
-
-
Method Details
-
friendlyCodecSized
public static final com.mojang.serialization.Codec<Mask> friendlyCodecSized(int maxWidth, int maxHeight) -
cover
Does not change thisMask, but expands the BitSet internally to cover the space occupied by the givenMask.- See Also:
-
cover
public void cover(int minX, int minY, int maxX, int maxY) Does not change thisMask, but expands the BitSet internally to cover at least the given space.- See Also:
-
minX
public int minX()Get the internal x origin of thisMask. This is at most but not necessarily equal to the x coordinate of the leftmost set pixel. To ensure equality, calltrim(). -
minY
public int minY()Get the internal y origin of thisMask. This is at most but not necessarily equal to the y coordinate of the topmost set pixel. To ensure equality, calltrim(). -
maxX
public int maxX()Get the internal x maximum of thisMask. This is at most but not necessarily equal to the x coordinate of the rightmost set pixel. To ensure equality, calltrim(). -
maxY
public int maxY()Get the internal y maximum of thisMask. This is at most but not necessarily equal to the y coordinate of the bottommost set pixel. To ensure equality, calltrim(). -
get
public boolean get(int x, int y) -
getRegion
public boolean getRegion(int minX, int minY, int maxX, int maxY) trueif any pixels are set in the given region- Parameters:
minX-minY-maxX-maxY-
-
set
public void set(int x, int y) Sets the given pixel in thisMask.- Parameters:
x-y-
-
clear
public void clear(int x, int y) Removes the given pixel from thisMask.- Parameters:
x-y-- See Also:
-
move
public void move(int dX, int dY) Moves every pixel in thisMask.- Parameters:
dX-dY-
-
combine
Perform a binary operation on thisMaskbased on the contents of the givenMask. This modifies thisMask, but not the given one.- Parameters:
mask-combination-- See Also:
-
or
- Parameters:
mask-- See Also:
-
and
- Parameters:
mask-- See Also:
-
andNot
- Parameters:
mask-- See Also:
-
equals
-
clone
-
rowStrings
Serialize thisMask. Set pixels will be represented with a.and unset pixels with a space. -
downsample
Get a newMaskby splitting this Mask intofactorbyfactorblocks and setting pixels in that Mask if any pixels in the corresponding block in this Mask are set.- Parameters:
factor-
-
fromRowStrings
Deserialize aMask. Spaces represent unset pixels and any other symbols represent set pixels.- Parameters:
xOffset- Horizontal offset to apply to the wholeMask. The same effect would be achieved by includingxOffsetspaces at the front of every line, but this field can also work for negative offsets.yOffset- Vertical offset to apply to the wholeMask. The same effect would be achieved by includingyOffsetempty lines at the start, but this field can also work for negative offsets.rowStrings- Must have all Strings the same length
-
rectangularize
Convert thisMaskto a List ofrectangles. More horizontal rectangles are preferred.- Returns:
- List of
rectanglescovering every pixel in thisMaskexactly once.
-
rect
Construct aMaskat the given position of the given size.- Parameters:
x-y-width-height-- See Also:
-
fromTo
Construct aMaskwith the given upper and lower corners.- Parameters:
fromX-fromY-toX-toY-- See Also:
-