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.entity.Entity; 023import net.tridentsdk.meta.block.Tile; 024 025import javax.annotation.concurrent.ThreadSafe; 026import java.util.ArrayList; 027import java.util.Collection; 028import java.util.Set; 029import java.util.function.Predicate; 030 031/** 032 * Represents a 16x16x256 cube of blocks which stores a partition of the world's data 033 * 034 * @author The TridentSDK Team 035 * @since 0.3-alpha-DP 036 */ 037@ThreadSafe 038public interface Chunk { 039 /** 040 * Generates the chunk 041 */ 042 void generate(); 043 044 /** 045 * Loads the chunk 046 * 047 * @return {@code true} to signify that the chunk was successfully loaded from file, {@code false} to signify that 048 * it does not exist on file, or already loaded 049 */ 050 boolean load(); 051 052 /** 053 * Checks the chunk to ensure it is loaded 054 * 055 * @return {@code true} to signify that the chunk is loaded, {@code false} if it is not 056 */ 057 boolean isLoaded(); 058 059 /** 060 * Unloads the chunk 061 */ 062 void unload(); 063 064 /** 065 * The entities in the chunk 066 * 067 * @return the entities 068 */ 069 Set<Entity> entities(); 070 071 /** 072 * Find all entities that are colliding with the bounding box 073 * 074 * @param exclude the entity to exclude from the search 075 * @param boundingBox The bounding box to search in 076 * @param predicate Predicate to filter results 077 * @return List of entities inside the bounding box 078 */ 079 ArrayList<Entity> getEntities(Entity exclude, BoundingBox boundingBox, Predicate<? super Entity> predicate); 080 081 /** 082 * Obtains the tile entities in this chunk 083 * 084 * @return the tile entities 085 */ 086 Collection<Tile> tiles(); 087 088 /** 089 * The location of the chunk 090 * 091 * @return the chunk's location 092 */ 093 ChunkLocation location(); 094 095 /** 096 * Shortcut for: {@code location().x()} 097 * 098 * @return the chunk's x coordinate 099 */ 100 int x(); 101 102 /** 103 * Shortcut for: {@code location().z()} 104 * 105 * @return the chunk's z coordinate 106 */ 107 int z(); 108 109 /** 110 * The world which contains this chunk 111 * 112 * @return the containing world 113 */ 114 World world(); 115 116 /** 117 * Obtains a block relative to the chunk 118 * 119 * @param relX the relative x 0-15 120 * @param y the y coordinate 121 * @param relZ the relative z 0-15 122 * @return the block at that coordinate 123 */ 124 Block blockAt(int relX, int y, int relZ); 125 126 /** 127 * Obtains a snapshot of the state of the chunk 128 * 129 * @return the chunk's frozen state which can be restored 130 */ 131 ChunkSnapshot snapshot(); 132}