Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstract anger level to a separate interface #2556

Merged
merged 3 commits into from
Jul 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/org/spongepowered/api/data/Keys.java
Original file line number Diff line number Diff line change
@@ -110,6 +110,7 @@
import org.spongepowered.api.effect.sound.SoundType;
import org.spongepowered.api.effect.sound.music.MusicDisc;
import org.spongepowered.api.entity.Ageable;
import org.spongepowered.api.entity.Angerable;
import org.spongepowered.api.entity.AreaEffectCloud;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.EntityArchetype;
@@ -372,7 +373,7 @@ public final class Keys {
public static final Key<Value<SoundType>> AMBIENT_SOUND = Keys.key(ResourceKey.sponge("ambient_sound"), SoundType.class);

/**
* The anger level of a {@link ZombifiedPiglin}.
* The anger level of a {@link Angerable}.
*
* <p>Unlike {@link Keys#IS_ANGRY}, the aggressiveness represented by this key may
* fade over time and the entity will become peaceful again once its anger
@@ -1551,8 +1552,7 @@ public final class Keys {
public static final Key<Value<Boolean>> IS_AI_ENABLED = Keys.key(ResourceKey.sponge("is_ai_enabled"), Boolean.class);

/**
* Whether an entity is currently aggressive.
* e.g. {@link Wolf wolves} or {@link ZombifiedPiglin}
* Whether a {@link Angerable} is currently aggressive.
*/
public static final Key<Value<Boolean>> IS_ANGRY = Keys.key(ResourceKey.sponge("is_angry"), Boolean.class);

49 changes: 49 additions & 0 deletions src/main/java/org/spongepowered/api/entity/Angerable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.api.entity;

import org.spongepowered.api.data.Keys;
import org.spongepowered.api.data.value.Value;

public interface Angerable extends Entity {

/**
* {@link Keys#IS_ANGRY}
*
* @return Whether this entity is currently angry
*/
default Value.Mutable<Boolean> angry() {
return this.requireValue(Keys.IS_ANGRY).asMutable();
}

/**
* {@link Keys#ANGER_LEVEL}
*
* @return The anger level, decays over time
*/
default Value.Mutable<Integer> angerLevel() {
return this.requireValue(Keys.ANGER_LEVEL).asMutable();
}
}
Original file line number Diff line number Diff line change
@@ -25,9 +25,10 @@
package org.spongepowered.api.entity.living.animal;

import org.spongepowered.api.entity.Aerial;
import org.spongepowered.api.entity.Angerable;

/**
* Represents a Bee.
*/
public interface Bee extends Animal, Aerial {
public interface Bee extends Animal, Aerial, Angerable {
}
Original file line number Diff line number Diff line change
@@ -26,11 +26,12 @@

import org.spongepowered.api.data.Keys;
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.entity.Angerable;

/**
* Represents a Polar Bear.
*/
public interface PolarBear extends Animal {
public interface PolarBear extends Animal, Angerable {

/**
* {@link Keys#IS_STANDING}
12 changes: 2 additions & 10 deletions src/main/java/org/spongepowered/api/entity/living/animal/Wolf.java
Original file line number Diff line number Diff line change
@@ -27,20 +27,12 @@
import org.spongepowered.api.data.Keys;
import org.spongepowered.api.data.type.DyeColor;
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.entity.Angerable;

/**
* Represents a Wolf.
*/
public interface Wolf extends TameableAnimal {

/**
* {@link Keys#IS_ANGRY}
*
* @return Whether this wolf is currently aggressive
*/
default Value.Mutable<Boolean> angry() {
return this.requireValue(Keys.IS_ANGRY).asMutable();
}
public interface Wolf extends TameableAnimal, Angerable {

/**
* {@link Keys#DYE_COLOR}
Original file line number Diff line number Diff line change
@@ -26,11 +26,12 @@

import org.spongepowered.api.data.Keys;
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.entity.Angerable;

/**
* Represents an Iron Golem.
*/
public interface IronGolem extends Golem {
public interface IronGolem extends Golem, Angerable {

/**
* {@link Keys#IS_PLAYER_CREATED}
Original file line number Diff line number Diff line change
@@ -26,12 +26,13 @@

import org.spongepowered.api.data.Keys;
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.entity.Angerable;
import org.spongepowered.api.entity.living.Monster;

/**
* Represents an Enderman.
*/
public interface Enderman extends Monster {
public interface Enderman extends Monster, Angerable {

/**
* {@link Keys#IS_SCREAMING}.
Original file line number Diff line number Diff line change
@@ -24,30 +24,10 @@
*/
package org.spongepowered.api.entity.living.monster.zombie;

import org.spongepowered.api.data.Keys;
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.entity.Angerable;

/**
* Represents a Zombie Pigman.
*/
public interface ZombifiedPiglin extends Zombie {

/**
* {@link Keys#ANGER_LEVEL}
*
* @return The anger level, decays over time
*/
default Value.Mutable<Integer> angerLevel() {
return this.requireValue(Keys.ANGER_LEVEL).asMutable();
}

/**
* {@link Keys#IS_ANGRY}
*
* @return Whether this zombified piglin is currently aggressive
*/
default Value.Mutable<Boolean> angry() {
return this.requireValue(Keys.IS_ANGRY).asMutable();
}

public interface ZombifiedPiglin extends Zombie, Angerable {
}