Skip to content

Commit

Permalink
Abstract anger level to a separate interface (#2556)
Browse files Browse the repository at this point in the history
* Abstract angel level to a separate interface

* Move IS_ANGRY key to Neutral

* Rename Neutral to Angerable
  • Loading branch information
ImMorpheus authored Jul 7, 2024
1 parent de8ffba commit d079755
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 39 deletions.
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
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down
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
Expand Up @@ -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
Expand Up @@ -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}
Expand Down
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
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}

0 comments on commit d079755

Please sign in to comment.