forked from OneLiteFeatherNET/BetterGoPaint
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from TheNextLvl-net/fawe-brushes
Completely utilize FAWE API
- Loading branch information
Showing
53 changed files
with
1,021 additions
and
938 deletions.
There are no files selected for viewing
151 changes: 0 additions & 151 deletions
151
api/src/main/java/net/thenextlvl/gopaint/api/brush/Brush.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
api/src/main/java/net/thenextlvl/gopaint/api/brush/PatternBrush.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package net.thenextlvl.gopaint.api.brush; | ||
|
||
import com.sk89q.worldedit.EditSession; | ||
import com.sk89q.worldedit.MaxChangedBlocksException; | ||
import com.sk89q.worldedit.command.tool.brush.Brush; | ||
import com.sk89q.worldedit.entity.Player; | ||
import com.sk89q.worldedit.function.pattern.Pattern; | ||
import com.sk89q.worldedit.math.BlockVector3; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.ToString; | ||
import lombok.experimental.Accessors; | ||
import net.kyori.adventure.audience.Audience; | ||
import net.kyori.adventure.key.Key; | ||
import net.kyori.adventure.key.Keyed; | ||
import net.kyori.adventure.text.Component; | ||
import net.thenextlvl.gopaint.api.brush.setting.BrushSettings; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* This interface represents a brush used for painting blocks in a world. | ||
*/ | ||
@Getter | ||
@ToString | ||
@EqualsAndHashCode | ||
@RequiredArgsConstructor | ||
public abstract class PatternBrush implements Comparable<PatternBrush>, Keyed, Brush { | ||
/** | ||
* Retrieves the base64 head value. | ||
*/ | ||
private final String headValue; | ||
/** | ||
* The key that identifies this brush | ||
*/ | ||
private final @Accessors(fluent = true) Key key; | ||
|
||
/** | ||
* Retrieves the localized name of this brush. | ||
* | ||
* @param audience The audience for whom the name is retrieved. | ||
* @return The localized name of the brush. | ||
*/ | ||
public abstract Component getName(Audience audience); | ||
|
||
/** | ||
* Retrieves the localized description of this brush. | ||
* | ||
* @param audience The audience for whom the description is retrieved. | ||
* @return The localized description of the brush. | ||
*/ | ||
public abstract Component[] getDescription(Audience audience); | ||
|
||
/** | ||
* Builds a pattern for the brush based on the provided parameters. | ||
* | ||
* @param session The EditSession to build the pattern for. | ||
* @param position The position of the block where the pattern is located. | ||
* @param player The player using the brush. | ||
* @param settings The brush settings to be used for building. | ||
* @return The built pattern. | ||
*/ | ||
public abstract Pattern buildPattern(EditSession session, BlockVector3 position, Player player, BrushSettings settings); | ||
|
||
/** | ||
* Builds a pattern in the specified EditSession at the given position with the provided size. | ||
* | ||
* @param session The EditSession to build the pattern in. | ||
* @param position The position of the center block of the pattern. | ||
* @param pattern The pattern. | ||
* @param size The size of the pattern. | ||
* @throws MaxChangedBlocksException If the maximum number of changed blocks is exceeded. | ||
*/ | ||
@Override | ||
public abstract void build(EditSession session, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException; | ||
|
||
@Override | ||
public int compareTo(@NotNull PatternBrush brush) { | ||
return key().compareTo(brush.key()); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
api/src/main/java/net/thenextlvl/gopaint/api/brush/SpherePatternBrush.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package net.thenextlvl.gopaint.api.brush; | ||
|
||
import com.sk89q.worldedit.EditSession; | ||
import com.sk89q.worldedit.MaxChangedBlocksException; | ||
import com.sk89q.worldedit.function.pattern.Pattern; | ||
import com.sk89q.worldedit.math.BlockVector3; | ||
import net.kyori.adventure.key.Key; | ||
|
||
public abstract class SpherePatternBrush extends PatternBrush { | ||
public SpherePatternBrush(String headValue, Key key) { | ||
super(headValue, key); | ||
} | ||
|
||
@Override | ||
public final void build(EditSession session, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { | ||
session.makeSphere(position, pattern, size, size, size, true); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
api/src/main/java/net/thenextlvl/gopaint/api/brush/mask/VisibleMask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package net.thenextlvl.gopaint.api.brush.mask; | ||
|
||
import com.fastasyncworldedit.core.math.MutableVector3; | ||
import com.sk89q.worldedit.extent.Extent; | ||
import com.sk89q.worldedit.function.mask.Mask; | ||
import com.sk89q.worldedit.math.BlockVector3; | ||
import com.sk89q.worldedit.math.Vector3; | ||
|
||
public record VisibleMask(Extent extent, Vector3 viewPoint) implements Mask { | ||
|
||
@Override | ||
public boolean test(BlockVector3 vector) { | ||
|
||
var location = new MutableVector3( | ||
vector.getX(), | ||
vector.getY(), | ||
vector.getZ() | ||
); | ||
|
||
var distanceX = viewPoint().getX() - location.getX(); | ||
var distanceY = viewPoint().getY() - location.getY(); | ||
var distanceZ = viewPoint().getZ() - location.getZ(); | ||
|
||
location.setComponents( | ||
location.getX() + (distanceX > 1 ? 1 : distanceX > 0 ? 0.5 : 0), | ||
location.getY() + (distanceY > 1 ? 1 : distanceY > 0 ? 0.5 : 0), | ||
location.getZ() + (distanceZ > 1 ? 1 : distanceZ > 0 ? 0.5 : 0) | ||
); | ||
|
||
var distance = location.distance(viewPoint()); | ||
for (var x = 1; x < distance; x++) { | ||
|
||
var moveX = distanceX * (x / distance); | ||
var moveY = distanceY * (x / distance); | ||
var moveZ = distanceZ * (x / distance); | ||
|
||
var point = location.add(moveX, moveY, moveZ).toBlockPoint(); | ||
|
||
if (!extent().getBlock(point).getMaterial().isAir()) return false; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public Mask copy() { | ||
return new VisibleMask(extent(), viewPoint()); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
api/src/main/java/net/thenextlvl/gopaint/api/brush/mask/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@TypesAreNotNullByDefault | ||
@FieldsAreNotNullByDefault | ||
@MethodsReturnNotNullByDefault | ||
@ParametersAreNotNullByDefault | ||
package net.thenextlvl.gopaint.api.brush.mask; | ||
|
||
import core.annotation.FieldsAreNotNullByDefault; | ||
import core.annotation.MethodsReturnNotNullByDefault; | ||
import core.annotation.ParametersAreNotNullByDefault; | ||
import core.annotation.TypesAreNotNullByDefault; |
Oops, something went wrong.