Skip to content

Commit

Permalink
Add mising data values, adding Sittable and Spawner
Browse files Browse the repository at this point in the history
  • Loading branch information
i509VCB committed Jan 9, 2020
1 parent c3d9d45 commit 1b9ce33
Show file tree
Hide file tree
Showing 11 changed files with 253 additions and 129 deletions.
118 changes: 2 additions & 116 deletions src/main/java/org/spongepowered/api/block/entity/MobSpawner.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,12 @@
*/
package org.spongepowered.api.block.entity;

import org.spongepowered.api.data.Keys;
import org.spongepowered.api.data.value.BoundedValue;
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.data.value.WeightedCollectionValue;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.EntityArchetype;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.util.weighted.WeightedSerializableObject;

import java.util.Random;
import org.spongepowered.api.spawner.Spawner;

/**
* Represents a Monster Spawner.
*/
public interface MobSpawner extends BlockEntity {
public interface MobSpawner extends BlockEntity, Spawner {

/**
* Trigger an immediate spawn of a batch of entities.
Expand All @@ -49,109 +40,4 @@ public interface MobSpawner extends BlockEntity {
* @param force Whether to ignore spawning restrictions
*/
void spawnEntityBatchImmediately(boolean force);

/**
* Gets the {@link org.spongepowered.api.data.value.BoundedValue.Mutable} for the remaining delay before
* a new attempt at spawning an {@link Entity} is made.
*
* @return The immutable bounded value for the remaining delay
*/
default BoundedValue.Mutable<Integer> remainingDelay() {
return getValue(Keys.SPAWNER_REMAINING_DELAY).get().asMutable();
}

/**
* Gets the {@link org.spongepowered.api.data.value.BoundedValue.Mutable} for the minimum spawn delay
* required between attempts to spawn an {@link Entity}.
*
* @return The bounded value of the minimum spawn delay
*/
default BoundedValue.Mutable<Integer> minimumSpawnDelay() {
return getValue(Keys.SPAWNER_MINIMUM_DELAY).get().asMutable();
}

/**
* Gets the {@link org.spongepowered.api.data.value.BoundedValue.Mutable} for the maximum spawn delay
* required between attempts to spawn an {@link Entity}.
*
* @return The bounded value of the maximum spawn delay
*/
default BoundedValue.Mutable<Integer> maximumSpawnDelay() {
return getValue(Keys.SPAWNER_MAXIMUM_DELAY).get().asMutable();
}

/**
* Gets the {@link org.spongepowered.api.data.value.BoundedValue.Mutable} for the count of successful
* spawns of all {@link Entity} instances from the owning spawner. This
* count is simply a total count, there is no limitation on how many
* attempts are made to spawn an {@link Entity}.
*
* @return The immutable bounded value
*/
default BoundedValue.Mutable<Integer> spawnCount() {
return getValue(Keys.SPAWNER_SPAWN_COUNT).get().asMutable();
}

/**
* Gets the {@link org.spongepowered.api.data.value.BoundedValue.Mutable} for the limitation on the number
* of nearby {@link Entity} instances can exist near the owning spawner. The
* limitation is that if there are more {@link Entity} instances than the
* provided value, no attempts to spawn a new {@link Entity} will be made.
*
* @return The bounded value of the maximum supported nearby entities
*/
default BoundedValue.Mutable<Integer> maximumNearbyEntities() {
return getValue(Keys.SPAWNER_MAXIMUM_NEARBY_ENTITIES).get().asMutable();
}

/**
* Gets the {@link org.spongepowered.api.data.value.BoundedValue.Mutable} for the minimum range a
* {@link Player} must remain in proximity of the spawner, such that if a
* {@link Player} is NOT within the provided range, no attempts to spawn an
* {@link Entity} is made.
*
* @return The value of the required player range to spawn entities
*/
default BoundedValue.Mutable<Integer> requiredPlayerRange() {
return getValue(Keys.SPAWNER_REQUIRED_PLAYER_RANGE).get().asMutable();
}

/**
* Gets the {@link org.spongepowered.api.data.value.BoundedValue.Mutable} for the maximum range that an
* {@link Entity} can be spawned from the spawner.
*
* @return The immutable value of the maximum spawn range an entity can be
* spawned
*/
default BoundedValue.Mutable<Integer> spawnRange() {
return getValue(Keys.SPAWNER_SPAWN_RANGE).get().asMutable();
}

/**
* Gets the {@link org.spongepowered.api.data.value.Value.Mutable}
* for the overridden
* {@link WeightedSerializableObject}{@code <EntitySnapshot>} to spawn
* next. If possible, the next entity to spawn may be chosen from the
* already provided {@link #possibleEntitiesToSpawn()}.
*
* @return The next possible entity to spawn
*/
default Value.Mutable<WeightedSerializableObject<EntityArchetype>> nextEntityToSpawn() {
return getValue(Keys.SPAWNER_NEXT_ENTITY_TO_SPAWN).get().asMutable();
}

/**
* Gets the {@link org.spongepowered.api.data.value.WeightedCollectionValue.Mutable} of all possible
* {@link Entity} instances that can be spawned by the spawner. As they
* are all {@link WeightedSerializableObject}{@code <EntitySnapshot>}
* instances, their weight is defined as a {@link Random} to determine
* the next {@link Entity} that will be spawned, unless overriden by
* {@link #nextEntityToSpawn()}.
*
* @return The immutable weighted entity collection value of entities
*/
default WeightedCollectionValue.Mutable<EntityArchetype> possibleEntitiesToSpawn() {
return getValue(Keys.SPAWNER_ENTITIES).get().asMutable();
}

}
16 changes: 16 additions & 0 deletions src/main/java/org/spongepowered/api/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,14 @@ default Value.Mutable<Boolean> gravity() {
return this.getValue(Keys.HAS_GRAVITY.get()).get().asMutable();
}

/**
* {@link Keys#IS_SILENT}
* @return Whether this entity is silent
*/
default Value.Mutable<Boolean> silent() {
return this.getValue(Keys.IS_SILENT.get()).get().asMutable();
}

/**
* {@link Keys#CREATOR}
* @return The unique id of the creator of this entity
Expand All @@ -423,4 +431,12 @@ default Optional<Value.Mutable<UUID>> creator() {
default Optional<Value.Mutable<UUID>> notifier() {
return this.getValue(Keys.NOTIFIER.get()).map(Value::asMutable);
}

/**
* {@link Keys#FIRE_TICKS}
* @return The amount of time in ticks an Entity is will continue burn for.
*/
default Optional<Value.Mutable<Integer>> fireTicks() {
return this.getValue(Keys.FIRE_TICKS).map(Value::asMutable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/**
* Represents a Cat, meow.
*/
public interface Cat extends TameableAnimal {
public interface Cat extends TameableAnimal, Sittable {

/**
* {@link Keys#CAT_TYPE}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/**
* Represents a Panda.
*/
public interface Panda extends Animal {
public interface Panda extends Animal, Sittable {

/**
* {@link Keys#KNOWN_GENE}
Expand All @@ -53,14 +53,6 @@ default Value.Mutable<PandaGene> hiddenGene() {
return this.getValue(Keys.HIDDEN_GENE.get()).get().asMutable();
}

/**
* {@link Keys#IS_SITTING}
* @return Whether this panda is sitting
*/
default Value.Mutable<Boolean> sitting() {
return this.getValue(Keys.IS_SITTING.get()).get().asMutable();
}

/**
* {@link Keys#IS_SNEEZING}
* @return Whether this panda is sneezing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
/**
* Represents a Parrot.
*/
public interface Parrot extends TameableAnimal {
public interface Parrot extends TameableAnimal, Sittable {

/**
* {@link Keys#PARROT_TYPE}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.living.animal;

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

/**
* Represents an {@link Entity} which can sit.
*/
public interface Sittable extends Entity {

/**
* {@link Keys#IS_SITTING}
* @return Whether this entity is sitting
*/
default Value.Mutable<Boolean> sitting() {
return this.getValue(Keys.IS_SITTING.get()).get().asMutable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
/**
* Represents a Wolf.
*/
public interface Wolf extends TameableAnimal {
public interface Wolf extends TameableAnimal, Sittable {

/**
* {@link Keys#IS_ANGRY}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/spongepowered/api/entity/vehicle/Boat.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package org.spongepowered.api.entity.vehicle;

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

/**
Expand Down Expand Up @@ -71,4 +72,12 @@ default Value.Mutable<Double> unoccupiedDeceleration() {
default Value.Mutable<Double> occupiedDeceleration() {
return this.getValue(Keys.BOAT_OCCUPIED_DECELERATION.get()).get().asMutable();
}

/**
* {@link Keys#WOOD_TYPE}
* @return The wood type of the boat
*/
default Value.Mutable<WoodType> woodType() {
return this.getValue(Keys.WOOD_TYPE.get()).get().asMutable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
package org.spongepowered.api.entity.vehicle.minecart;

import org.spongepowered.api.block.entity.MobSpawner;
import org.spongepowered.api.spawner.Spawner;

/**
* Represents a {@link Minecart} with a {@link MobSpawner} inside it.
*/
public interface SpawnerMinecart extends BlockOccupiedMinecart {
public interface SpawnerMinecart extends BlockOccupiedMinecart, Spawner {

}
Loading

0 comments on commit 1b9ce33

Please sign in to comment.