Skip to content

Commit

Permalink
Merge pull request #19 from TheNextLvl-net/fawe-brushes
Browse files Browse the repository at this point in the history
Completely utilize FAWE API
  • Loading branch information
NonSwag authored Jun 30, 2024
2 parents c76e9c1 + 81152e3 commit 05708a0
Show file tree
Hide file tree
Showing 53 changed files with 1,021 additions and 938 deletions.
151 changes: 0 additions & 151 deletions api/src/main/java/net/thenextlvl/gopaint/api/brush/Brush.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,37 @@ public interface BrushRegistry {
*
* @return The stream of available brushes.
*/
Stream<Brush> getBrushes();
Stream<PatternBrush> getBrushes();

/**
* Checks if a brush is registered in the BrushController.
*
* @param brush The brush to check if it is registered.
* @return true if the brush is registered, false otherwise.
*/
boolean isRegistered(Brush brush);
boolean isRegistered(PatternBrush brush);

/**
* Registers a brush in the BrushManager.
*
* @param brush The brush to be registered.
* @throws IllegalStateException if the brush is already registered.
*/
void registerBrush(Brush brush) throws IllegalStateException;
void registerBrush(PatternBrush brush) throws IllegalStateException;

/**
* Unregisters a brush from the Brush Controller.
*
* @param brush The brush to be unregistered.
* @throws IllegalStateException if the brush is not registered.
*/
void unregisterBrush(Brush brush) throws IllegalStateException;
void unregisterBrush(PatternBrush brush) throws IllegalStateException;

/**
* Retrieves the brush associated with the provided NamespacedKey.
*
* @param key The NamespacedKey of the brush to retrieve.
* @return An Optional containing the brush if found, or an empty Optional if not found.
*/
Optional<Brush> getBrush(Key key);
Optional<PatternBrush> getBrush(Key key);
}
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());
}
}
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);
}
}
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());
}
}
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;
Loading

0 comments on commit 05708a0

Please sign in to comment.