001/*
002 * Trident - A Multithreaded Server Alternative
003 * Copyright 2014 The TridentSDK Team
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *    http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package net.tridentsdk.world;
019
020import net.tridentsdk.base.Block;
021import net.tridentsdk.base.BoundingBox;
022import net.tridentsdk.base.Position;
023import net.tridentsdk.effect.particle.ParticleEffect;
024import net.tridentsdk.effect.particle.ParticleEffectType;
025import net.tridentsdk.effect.sound.SoundEffect;
026import net.tridentsdk.effect.sound.SoundEffectType;
027import net.tridentsdk.effect.visual.VisualEffect;
028import net.tridentsdk.effect.visual.VisualEffectType;
029import net.tridentsdk.entity.Entity;
030import net.tridentsdk.entity.types.EntityType;
031import net.tridentsdk.registry.Registered;
032import net.tridentsdk.world.settings.WorldSettings;
033
034import javax.annotation.concurrent.ThreadSafe;
035import java.util.ArrayList;
036import java.util.Collection;
037import java.util.Set;
038import java.util.function.Predicate;
039
040/**
041 * A Minecraft world
042 *
043 * <p>Worlds can be created using the following code:
044 * <pre>{@code
045 *      WorldLoader loader = WorldLoader.newLoader();
046 *      // Set world settings
047 *      loader.createWorld("New world");
048 * }</pre>
049 * You can use your own generator using {@link WorldLoader#newLoader(Class)}</p>
050 *
051 * <p>A collection of the worlds on the server can be obtained using {@link Registered#worlds()}</p>
052 *
053 * @author The TridentSDK Team
054 * @since 0.3-alpha-DP
055 */
056@ThreadSafe
057public interface World extends Cloneable {
058    /**
059     * Gets the name of the world
060     *
061     * @return the name of the world
062     */
063    String name();
064
065    /**
066     * Obtains the loaded chunks in the world
067     *
068     * @return the loaded chunks
069     */
070    Collection<Chunk> chunks();
071
072    /**
073     * Gets the chunk on the given position, and generates the chunk if it does not exist.
074     *
075     * @return The chunk on the given position
076     */
077    Chunk chunkAt(ChunkLocation loc, boolean generateIfNotFound);
078
079    /**
080     * Gets the chunk on the given x and z , and generates the chunk if it does not exist
081     *
082     * @return The chunk on the given position
083     */
084    Chunk chunkAt(int x, int z, boolean generateIfNotFound);
085
086    /**
087     * Generates the chunk on the given position
088     *
089     * @return The generated chunk
090     */
091    Chunk generateChunk(int x, int z);
092
093    /**
094     * Generates the chunk on the given position
095     *
096     * @return The generated chunk
097     */
098    Chunk generateChunk(ChunkLocation position);
099
100    /**
101     * Gets the block on the given position
102     *
103     * @return The block on the given position
104     */
105    Block blockAt(Position position);
106
107    /**
108     * Obtains the loading handler which created this object, passed in from the constructor
109     *
110     * @return the world loader for this world
111     */
112    WorldLoader loader();
113
114    /**
115     * Gets the time in the world
116     *
117     * @return The time in the world
118     */
119    long time();
120
121    /**
122     * Gets the spawn position of the world
123     *
124     * @return The spawn position in the world
125     */
126    Position spawnPosition();
127
128    /**
129     * Obtains the weather controller for the world
130     *
131     * @return the weather controller
132     */
133    WeatherConditions weather();
134
135    /**
136     * Obtains the settings which modify the behavior of the world
137     *
138     * @return the world settigs
139     */
140    WorldSettings settings();
141
142    /**
143     * Obtains the world border properties of this world
144     *
145     * @return the border properties
146     */
147    WorldBorder border();
148
149    /**
150     * Spawns an entity in the world
151     *
152     * @param type the type of entity to spawn
153     * @return the entity spawn
154     */
155    Entity spawn(EntityType type, Position spawnPosition);
156
157    /**
158     * Get the entities currently in this world
159     *
160     * @return the entities in the world
161     */
162    Set<Entity> entities();
163
164    /**
165     * Find all entities that are colliding with the bounding box
166     *
167     * @param exclude the entity to exclude from searching
168     * @param boundingBox The bounding box to search in
169     * @param predicate Predicate to filter results
170     * @return List of entities inside the bounding box
171     */
172    ArrayList<Entity> getEntities(Entity exclude, BoundingBox boundingBox, Predicate<? super Entity> predicate);
173
174    /**
175     * Creates a new particle effect
176     *
177     * @param particle The particle to spawn
178     * @return A new instance of ParticleEffect
179     */
180    ParticleEffect spawnParticle(ParticleEffectType particle);
181
182    /**
183     * Creates a new visual effect
184     *
185     * @param visual The visual to spawn
186     * @return A new instance of VisualEffect
187     */
188    VisualEffect spawnVisual(VisualEffectType visual);
189
190    /**
191     * Creates a new sound effect
192     *
193     * @param sound The sound to play
194     * @return A new instance of VisualEffect
195     */
196    SoundEffect playSound(SoundEffectType sound);
197
198    /**
199     * Strikes lightning at the given location.
200     *
201     * @param location the location that the lightning will hit
202     * @param isEffect determines if the lightning is just a effect or can cause damage
203     */
204    void lightning(Position location, boolean isEffect);
205
206    /**
207     * Sets the time of the world
208     *
209     * @param time the new time of the world
210     */
211    void setTime(long time);
212}