Skip to content

Commit 05708a0

Browse files
authored
Merge pull request #19 from TheNextLvl-net/fawe-brushes
Completely utilize FAWE API
2 parents c76e9c1 + 81152e3 commit 05708a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1021
-938
lines changed

api/src/main/java/net/thenextlvl/gopaint/api/brush/Brush.java

Lines changed: 0 additions & 151 deletions
This file was deleted.

api/src/main/java/net/thenextlvl/gopaint/api/brush/BrushRegistry.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,37 @@ public interface BrushRegistry {
1515
*
1616
* @return The stream of available brushes.
1717
*/
18-
Stream<Brush> getBrushes();
18+
Stream<PatternBrush> getBrushes();
1919

2020
/**
2121
* Checks if a brush is registered in the BrushController.
2222
*
2323
* @param brush The brush to check if it is registered.
2424
* @return true if the brush is registered, false otherwise.
2525
*/
26-
boolean isRegistered(Brush brush);
26+
boolean isRegistered(PatternBrush brush);
2727

2828
/**
2929
* Registers a brush in the BrushManager.
3030
*
3131
* @param brush The brush to be registered.
3232
* @throws IllegalStateException if the brush is already registered.
3333
*/
34-
void registerBrush(Brush brush) throws IllegalStateException;
34+
void registerBrush(PatternBrush brush) throws IllegalStateException;
3535

3636
/**
3737
* Unregisters a brush from the Brush Controller.
3838
*
3939
* @param brush The brush to be unregistered.
4040
* @throws IllegalStateException if the brush is not registered.
4141
*/
42-
void unregisterBrush(Brush brush) throws IllegalStateException;
42+
void unregisterBrush(PatternBrush brush) throws IllegalStateException;
4343

4444
/**
4545
* Retrieves the brush associated with the provided NamespacedKey.
4646
*
4747
* @param key The NamespacedKey of the brush to retrieve.
4848
* @return An Optional containing the brush if found, or an empty Optional if not found.
4949
*/
50-
Optional<Brush> getBrush(Key key);
50+
Optional<PatternBrush> getBrush(Key key);
5151
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package net.thenextlvl.gopaint.api.brush;
2+
3+
import com.sk89q.worldedit.EditSession;
4+
import com.sk89q.worldedit.MaxChangedBlocksException;
5+
import com.sk89q.worldedit.command.tool.brush.Brush;
6+
import com.sk89q.worldedit.entity.Player;
7+
import com.sk89q.worldedit.function.pattern.Pattern;
8+
import com.sk89q.worldedit.math.BlockVector3;
9+
import lombok.EqualsAndHashCode;
10+
import lombok.Getter;
11+
import lombok.RequiredArgsConstructor;
12+
import lombok.ToString;
13+
import lombok.experimental.Accessors;
14+
import net.kyori.adventure.audience.Audience;
15+
import net.kyori.adventure.key.Key;
16+
import net.kyori.adventure.key.Keyed;
17+
import net.kyori.adventure.text.Component;
18+
import net.thenextlvl.gopaint.api.brush.setting.BrushSettings;
19+
import org.jetbrains.annotations.NotNull;
20+
21+
/**
22+
* This interface represents a brush used for painting blocks in a world.
23+
*/
24+
@Getter
25+
@ToString
26+
@EqualsAndHashCode
27+
@RequiredArgsConstructor
28+
public abstract class PatternBrush implements Comparable<PatternBrush>, Keyed, Brush {
29+
/**
30+
* Retrieves the base64 head value.
31+
*/
32+
private final String headValue;
33+
/**
34+
* The key that identifies this brush
35+
*/
36+
private final @Accessors(fluent = true) Key key;
37+
38+
/**
39+
* Retrieves the localized name of this brush.
40+
*
41+
* @param audience The audience for whom the name is retrieved.
42+
* @return The localized name of the brush.
43+
*/
44+
public abstract Component getName(Audience audience);
45+
46+
/**
47+
* Retrieves the localized description of this brush.
48+
*
49+
* @param audience The audience for whom the description is retrieved.
50+
* @return The localized description of the brush.
51+
*/
52+
public abstract Component[] getDescription(Audience audience);
53+
54+
/**
55+
* Builds a pattern for the brush based on the provided parameters.
56+
*
57+
* @param session The EditSession to build the pattern for.
58+
* @param position The position of the block where the pattern is located.
59+
* @param player The player using the brush.
60+
* @param settings The brush settings to be used for building.
61+
* @return The built pattern.
62+
*/
63+
public abstract Pattern buildPattern(EditSession session, BlockVector3 position, Player player, BrushSettings settings);
64+
65+
/**
66+
* Builds a pattern in the specified EditSession at the given position with the provided size.
67+
*
68+
* @param session The EditSession to build the pattern in.
69+
* @param position The position of the center block of the pattern.
70+
* @param pattern The pattern.
71+
* @param size The size of the pattern.
72+
* @throws MaxChangedBlocksException If the maximum number of changed blocks is exceeded.
73+
*/
74+
@Override
75+
public abstract void build(EditSession session, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException;
76+
77+
@Override
78+
public int compareTo(@NotNull PatternBrush brush) {
79+
return key().compareTo(brush.key());
80+
}
81+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package net.thenextlvl.gopaint.api.brush;
2+
3+
import com.sk89q.worldedit.EditSession;
4+
import com.sk89q.worldedit.MaxChangedBlocksException;
5+
import com.sk89q.worldedit.function.pattern.Pattern;
6+
import com.sk89q.worldedit.math.BlockVector3;
7+
import net.kyori.adventure.key.Key;
8+
9+
public abstract class SpherePatternBrush extends PatternBrush {
10+
public SpherePatternBrush(String headValue, Key key) {
11+
super(headValue, key);
12+
}
13+
14+
@Override
15+
public final void build(EditSession session, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
16+
session.makeSphere(position, pattern, size, size, size, true);
17+
}
18+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package net.thenextlvl.gopaint.api.brush.mask;
2+
3+
import com.fastasyncworldedit.core.math.MutableVector3;
4+
import com.sk89q.worldedit.extent.Extent;
5+
import com.sk89q.worldedit.function.mask.Mask;
6+
import com.sk89q.worldedit.math.BlockVector3;
7+
import com.sk89q.worldedit.math.Vector3;
8+
9+
public record VisibleMask(Extent extent, Vector3 viewPoint) implements Mask {
10+
11+
@Override
12+
public boolean test(BlockVector3 vector) {
13+
14+
var location = new MutableVector3(
15+
vector.getX(),
16+
vector.getY(),
17+
vector.getZ()
18+
);
19+
20+
var distanceX = viewPoint().getX() - location.getX();
21+
var distanceY = viewPoint().getY() - location.getY();
22+
var distanceZ = viewPoint().getZ() - location.getZ();
23+
24+
location.setComponents(
25+
location.getX() + (distanceX > 1 ? 1 : distanceX > 0 ? 0.5 : 0),
26+
location.getY() + (distanceY > 1 ? 1 : distanceY > 0 ? 0.5 : 0),
27+
location.getZ() + (distanceZ > 1 ? 1 : distanceZ > 0 ? 0.5 : 0)
28+
);
29+
30+
var distance = location.distance(viewPoint());
31+
for (var x = 1; x < distance; x++) {
32+
33+
var moveX = distanceX * (x / distance);
34+
var moveY = distanceY * (x / distance);
35+
var moveZ = distanceZ * (x / distance);
36+
37+
var point = location.add(moveX, moveY, moveZ).toBlockPoint();
38+
39+
if (!extent().getBlock(point).getMaterial().isAir()) return false;
40+
}
41+
return true;
42+
}
43+
44+
@Override
45+
public Mask copy() {
46+
return new VisibleMask(extent(), viewPoint());
47+
}
48+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@TypesAreNotNullByDefault
2+
@FieldsAreNotNullByDefault
3+
@MethodsReturnNotNullByDefault
4+
@ParametersAreNotNullByDefault
5+
package net.thenextlvl.gopaint.api.brush.mask;
6+
7+
import core.annotation.FieldsAreNotNullByDefault;
8+
import core.annotation.MethodsReturnNotNullByDefault;
9+
import core.annotation.ParametersAreNotNullByDefault;
10+
import core.annotation.TypesAreNotNullByDefault;

0 commit comments

Comments
 (0)