Skip to content

Commit

Permalink
TrialSpawner and Crafter
Browse files Browse the repository at this point in the history
  • Loading branch information
Faithcaio committed Jun 14, 2024
1 parent 8dde7d6 commit 909f89b
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 12 deletions.
45 changes: 45 additions & 0 deletions src/main/java/org/spongepowered/api/block/entity/TrialSpawner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.block.entity;

import org.spongepowered.api.data.Keys;
import org.spongepowered.api.world.generation.structure.Structures;

/**
* Represents a {@link Structures#TRIAL_CHAMBERS Trial} Spawner.
*/
public interface TrialSpawner extends BlockEntity {

/**
* Trigger an immediate spawn of the next entity
*
* <p>This will obey the restrictions of maximum simultaneous entities ({@link Keys#SPAWN_COUNT})
* unless the {@code force} flag is set.</p>
*
* @param force Whether to ignore spawning restrictions
*/
void spawnImmediately(boolean force);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.block.entity.carrier;

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

/**
* Represents a Crafter.
*/
public interface Crafter extends CarrierBlockEntity {

// TODO can we rename that?


// TODO toggled off slots

/**
* TODO is there a cooldown
* {@link Keys#COOLDOWN}
* @return The amount of time in ticks till the hopper can transfer another
* item.
*/
default Value.Mutable<Ticks> cooldown() {
return this.requireValue(Keys.COOLDOWN).asMutable();
}

/**
* Requests this {@link Crafter} to craft an item.
*
* @return true if an item was crafted
*/
boolean craftItem();
}
25 changes: 14 additions & 11 deletions src/main/java/org/spongepowered/api/data/Keys.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.spongepowered.api.block.entity.Piston;
import org.spongepowered.api.block.entity.Sign;
import org.spongepowered.api.block.entity.StructureBlock;
import org.spongepowered.api.block.entity.TrialSpawner;
import org.spongepowered.api.block.entity.carrier.Beacon;
import org.spongepowered.api.block.entity.carrier.BrewingStand;
import org.spongepowered.api.block.entity.carrier.CarrierBlockEntity;
Expand Down Expand Up @@ -2344,9 +2345,9 @@ public final class Keys {
public static final Key<Value<Double>> MAX_HEALTH = Keys.key(ResourceKey.sponge("max_health"), Double.class);

/**
* The maximum number of entities around a {@link MobSpawner}.
* A spawner will not spawn entities if there are more
* entities around than this value permits.
* The maximum number of entities tracked by a {@link MobSpawner} or {@link TrialSpawner}
* <p>A spawner will not spawn entities if there are more
* entities tracked than this value permits.</p>
*/
public static final Key<Value<Integer>> MAX_NEARBY_ENTITIES = Keys.key(ResourceKey.sponge("max_nearby_entities"), Integer.class);

Expand All @@ -2359,7 +2360,7 @@ public final class Keys {

/**
* The maximum amount of ticks between two
* batches of entities spawned by a {@link MobSpawner}.
* batches of entities spawned by a {@link MobSpawner} or {@link TrialSpawner}
*/
public static final Key<Value<Ticks>> MAX_SPAWN_DELAY = Keys.key(ResourceKey.sponge("max_spawn_delay"), Ticks.class);

Expand All @@ -2381,7 +2382,7 @@ public final class Keys {

/**
* The minimum amount of ticks between two
* batches of entities spawned by a {@link MobSpawner}.
* batches of entities spawned by a {@link MobSpawner} or {@link TrialSpawner}
*/
public static final Key<Value<Ticks>> MIN_SPAWN_DELAY = Keys.key(ResourceKey.sponge("min_spawn_delay"), Ticks.class);

Expand Down Expand Up @@ -2425,13 +2426,13 @@ public final class Keys {
public static final Key<Value<Boolean>> NATURAL_WORLD_TYPE = Keys.key(ResourceKey.sponge("natural_world_type"), Boolean.class);

/**
* The next entity that will be spawned by a {@link MobSpawner}.
* The next entity that will be spawned by a {@link MobSpawner} or {@link TrialSpawner}
*
* <p>Normally the entities to be spawned are determined by a random value
* applied to the {@link #SPAWNABLE_ENTITIES} weighted collection. If this
* value exists, it will override the random spawn with a definite one.</p>
*/
public static final Key<Value<WeightedSerializableObject<EntityArchetype>>> NEXT_ENTITY_TO_SPAWN = Keys.key(ResourceKey.sponge("next_entity_to_spawn"), new TypeToken<WeightedSerializableObject<EntityArchetype>>() {});
public static final Key<Value<EntityArchetype>> NEXT_ENTITY_TO_SPAWN = Keys.key(ResourceKey.sponge("next_entity_to_spawn"), EntityArchetype.class);

/**
* The pitch of a {@link BlockTypes#NOTE_BLOCK} {@link BlockState}.
Expand Down Expand Up @@ -2722,7 +2723,8 @@ public final class Keys {

/**
* Represents the {@link Key} for the remaining number of ticks to pass
* before another attempt to spawn entities is made by a {@link MobSpawner}.
* before another attempt to spawn entities is made by a {@link MobSpawner}
* or {@link TrialSpawner}
*/
public static final Key<Value<Ticks>> REMAINING_SPAWN_DELAY = Keys.key(ResourceKey.sponge("remaining_spawn_delay"), Ticks.class);

Expand Down Expand Up @@ -2967,7 +2969,7 @@ public final class Keys {
public static final Key<Value<Ticks>> SNEEZING_TIME = Keys.key(ResourceKey.sponge("sneezing_time"), Ticks.class);

/**
* The list of {@link EntityArchetype}s able to be spawned by a {@link MobSpawner}.
* The list of {@link EntityArchetype}s able to be spawned by a {@link MobSpawner} or {@link TrialSpawner}
*/
public static final Key<WeightedCollectionValue<EntityArchetype>> SPAWNABLE_ENTITIES = Keys.weightedKey(ResourceKey.sponge("spawnable_entities"), EntityArchetype.class);

Expand All @@ -2980,7 +2982,7 @@ public final class Keys {
public static final Key<Value<Double>> SPAWN_CHANCE = Keys.key(ResourceKey.sponge("spawn_chance"), Double.class);

/**
* How many entities a {@link MobSpawner} has spawned so far.
* How many entities a {@link MobSpawner} spawns at once.
*/
public static final Key<Value<Integer>> SPAWN_COUNT = Keys.key(ResourceKey.sponge("spawn_count"), Integer.class);

Expand All @@ -3001,7 +3003,8 @@ public final class Keys {
public static final Key<Value<Vector3i>> SPAWN_POSITION = Keys.key(ResourceKey.sponge("spawn_position"), Vector3i.class);

/**
* How far away from the {@link MobSpawner} the entities spawned by it may appear.
* How far away from the {@link MobSpawner} or {@link TrialSpawner}
* the entities spawned by it may appear.
*/
public static final Key<Value<Double>> SPAWN_RANGE = Keys.key(ResourceKey.sponge("spawn_range"), Double.class);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/spongepowered/api/spawner/Spawner.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ default Value.Mutable<Double> spawnRange() {
*
* @return The next possible entity to spawn
*/
default Value.Mutable<WeightedSerializableObject<EntityArchetype>> nextEntityToSpawn() {
default Value.Mutable<EntityArchetype> nextEntityToSpawn() {
return this.requireValue(Keys.NEXT_ENTITY_TO_SPAWN).asMutable();
}

Expand Down

0 comments on commit 909f89b

Please sign in to comment.