Skip to content

Commit

Permalink
chore: update from api-13
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Harris-Rouquette <[email protected]>
  • Loading branch information
gabizou committed Nov 26, 2024
2 parents 4220ac0 + c0f65a1 commit f61b932
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,60 @@
import org.spongepowered.api.world.LocatableBlock;
import org.spongepowered.math.vector.Vector3i;

/**
* Represents a notification that is being proposed to the engine.
*/
public interface NotificationTicket {

/**
* Gets the notifier block that scheduled this notification.
*
* @return The notifier block
*/
LocatableBlock notifier();

/**
* Gets the notifier position that scheduled this notification.
*
* @return The notifier position
*/
default Vector3i notifierPosition() {
return this.notifier().blockPosition();
}

/**
* Gets the target block of this notification.
*
* @return The target block
*/
BlockSnapshot target();

/**
* Gets the target position of this notification.
*
* @return The target position
*/
default Vector3i targetPosition() {
return this.target().position();
}

/**
* Gets whether this ticket is marked as valid.
*
* @return The valid state of this ticket
*/
boolean valid();

/**
* Sets whether this ticket is valid or not.
*
* @param valid The valid state of this ticket
*/
void setValid(boolean valid);

/**
* Invalidates this ticket.
*/
default void invalidate() {
this.setValid(false);
}
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/org/spongepowered/api/data/Keys.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@
import org.spongepowered.api.world.weather.Weather;
import org.spongepowered.api.world.weather.WeatherType;
import org.spongepowered.api.world.weather.WeatherTypes;
import org.spongepowered.math.matrix.Matrix4d;
import org.spongepowered.math.vector.Vector2i;
import org.spongepowered.math.vector.Vector3d;
import org.spongepowered.math.vector.Vector3i;
Expand Down Expand Up @@ -576,6 +577,24 @@ public final class Keys {
*/
public static final Key<Value<BossBar>> BOSS_BAR = Keys.key(ResourceKey.sponge("boss_bar"), BossBar.class);

/**
* The width of the interactable form of an {@link Entity}.
*
* <p>Together with {@link #BOUNDING_BOX_HEIGHT} this defines
* the size of the {@link Entity}'s bounding box.</p>
* Readonly(Entity.class) expect Interaction
*/
public static final Key<Value<Double>> BOUNDING_BOX_BASE_SIZE = Keys.key(ResourceKey.sponge("bounding_box_base_size"), Double.class);

/**
* The height of the interactable form of an {@link Entity}.
*
* <p>Together with {@link #BOUNDING_BOX_BASE_SIZE} this defines
* the size of the {@link Entity}'s bounding box.</p>
* Readonly(Entity.class) expect Interaction
*/
public static final Key<Value<Double>> BOUNDING_BOX_HEIGHT = Keys.key(ResourceKey.sponge("bounding_box_height"), Double.class);

/**
* The {@link BlockType}s able to be broken by an {@link ItemStack}.
*/
Expand Down Expand Up @@ -2323,6 +2342,11 @@ public final class Keys {
*/
public static final Key<Value<ResourceKey>> MAP_WORLD = Keys.key(ResourceKey.sponge("map_world"), ResourceKey.class);

/**
* The {@link Matrix4d} of a {@link DisplayEntity}
*/
public static final Key<Value<Matrix4d>> MATRIX = Keys.key(ResourceKey.sponge("matrix"), Matrix4d.class);

/**
* The matter state of a {@link BlockState}
* Readonly
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/spongepowered/api/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -659,4 +659,22 @@ default Optional<Value.Mutable<Double>> swiftness() {

@Override
HoverEvent<HoverEvent.ShowEntity> asHoverEvent(final UnaryOperator<HoverEvent.ShowEntity> op);

/**
* {@link Keys#BOUNDING_BOX_BASE_SIZE}
*
* @return The bounding box base size of the entity
*/
default Value.Mutable<Double> boundingBoxBaseSize() {
return this.requireValue(Keys.BOUNDING_BOX_BASE_SIZE).asMutable();
}

/**
* {@link Keys#BOUNDING_BOX_HEIGHT}
*
* @return The bounding box height of the entity
*/
default Value.Mutable<Double> boundingBoxHeight() {
return this.requireValue(Keys.BOUNDING_BOX_HEIGHT).asMutable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.util.Ticks;
import org.spongepowered.api.util.Transform;
import org.spongepowered.math.matrix.Matrix4d;

import java.util.Optional;

Expand Down Expand Up @@ -125,6 +126,15 @@ default Double viewRange() {
return this.require(Keys.VIEW_RANGE);
}

/**
* Returns the matrix.
*
* @return the matrix.
*/
default Matrix4d matrix() {
return this.require(Keys.MATRIX);
}

// TODO bounding box (maybe BASE_SIZE if this is not smth. else in the entity)
// TODO glow_color_override -1 = use team color

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/spongepowered/api/event/EventManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ public interface EventManager {
* @param plugin The plugin container
* @param obj The object
* @return This manager, for fluency
* @deprecated In order to be compatible with the JPMS, it is highly
* recommended that plugins instead use the
* {@link #registerListeners(PluginContainer, Object, MethodHandles.Lookup)} overload.
*/
@Deprecated(since = "13")
EventManager registerListeners(PluginContainer plugin, Object obj);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,50 @@
import java.util.function.Predicate;

/**
*
* Fired when a neighbour notification is being proposed to the engine.
*/
public interface NotifyNeighborBlockEvent extends Event, Cancellable {

/**
* Gets a list of the {@link NotificationTicket}s for this event.
* If a ticket is requested to be marked as "invalid",
* {@link NotificationTicket#setValid(boolean)} can be used.
*
* @return The unmodifiable list of tickets
*/
List<NotificationTicket> tickets();

/**
* Applies the provided {@link Predicate} to the {@link List} of
* {@link NotificationTicket}s from {@link #tickets()} such that
* any time that {@link Predicate#test(Object)} returns {@code false}
* on the location of the {@link NotificationTicket}, the
* {@link NotificationTicket} is marked as "invalid".
*
* <p>{@link NotificationTicket#targetPosition()} is used to get the {@link Vector3i}</p>
*
* @param predicate The predicate to use for filtering
*/
default void filterTargetPositions(final Predicate<Vector3i> predicate) {
this.tickets().forEach(ticket -> {
if (predicate.test(ticket.targetPosition())) {
if (!predicate.test(ticket.targetPosition())) {
ticket.setValid(false);
}
});
}

/**
* Applies the provided {@link Predicate} to the {@link List} of
* {@link NotificationTicket}s from {@link #tickets()} such that
* any time that {@link Predicate#test(Object)} returns {@code false}
* on the location of the {@link NotificationTicket}, the
* {@link NotificationTicket} is marked as "invalid".
*
* @param predicate The predicate to use for filtering
*/
default void filterTickets(final Predicate<NotificationTicket> predicate) {
this.tickets().forEach(ticket -> {
if (predicate.test(ticket)) {
if (!predicate.test(ticket)) {
ticket.setValid(false);
}
});
Expand Down

0 comments on commit f61b932

Please sign in to comment.