public final class Environment extends java.lang.Object implements IRenderable
Constructor and Description |
---|
Environment(IMap map) |
Environment(java.lang.String mapPath) |
Modifier and Type | Method and Description |
---|---|
void |
add(IEntity entity)
Adds the specified entity to the environment container.
|
void |
add(IRenderable renderable,
RenderType renderType) |
void |
addEntityListener(EnvironmentEntityListener listener) |
void |
addListener(EnvironmentListener listener) |
void |
addRenderListener(RenderType renderType,
EnvironmentRenderListener listener) |
java.util.Collection<IEntity> |
build(Blueprint blueprint,
double x,
double y) |
java.util.Collection<IEntity> |
build(Blueprint blueprint,
java.awt.geom.Point2D location) |
void |
clear() |
java.util.Collection<ICombatEntity> |
findCombatEntities(java.awt.Shape shape) |
java.util.Collection<ICombatEntity> |
findCombatEntities(java.awt.Shape shape,
java.util.function.Predicate<ICombatEntity> condition)
Searches for all combat entities whose hitBox intersect the specified
shape.
|
java.util.Collection<IEntity> |
findEntities(java.awt.Shape shape) |
<T extends IEntity> |
get(java.lang.Class<T> clss,
int mapId) |
<T extends IEntity> |
get(java.lang.Class<T> clss,
java.lang.String name) |
java.util.List<IEntity> |
get(int... mapIds)
Finds the entities in the environment with the specified map IDs.
|
IEntity |
get(int mapId) |
IEntity |
get(java.lang.String name) |
java.util.Collection<java.lang.Integer> |
getAllMapIDs() |
AmbientLight |
getAmbientLight() |
MapArea |
getArea(int mapId) |
MapArea |
getArea(java.lang.String name) |
java.util.Collection<MapArea> |
getAreas() |
<T extends IEntity> |
getByTag(java.lang.Class<? extends T> clss,
java.lang.String... tags) |
java.util.Collection<IEntity> |
getByTag(java.lang.String... tags) |
<T> java.util.Collection<T> |
getByType(java.lang.Class<? extends T> cls) |
java.awt.geom.Point2D |
getCenter() |
CollisionBox |
getCollisionBox(int mapId) |
CollisionBox |
getCollisionBox(java.lang.String name) |
java.util.Collection<CollisionBox> |
getCollisionBoxes() |
java.util.Collection<ICombatEntity> |
getCombatEntities() |
ICombatEntity |
getCombatEntity(int mapId) |
ICombatEntity |
getCombatEntity(java.lang.String name) |
Creature |
getCreature(int mapId) |
Creature |
getCreature(java.lang.String name) |
java.util.Collection<Creature> |
getCreatures() |
Emitter |
getEmitter(int mapId) |
Emitter |
getEmitter(java.lang.String name) |
java.util.Collection<Emitter> |
getEmitters() |
java.util.Collection<IEntity> |
getEntities() |
java.util.Collection<IEntity> |
getEntities(IMapObjectLayer layer)
Gets the entities that are bound to the specified layer.
|
java.util.Collection<IEntity> |
getEntities(RenderType renderType)
Gets the entities with the specified render type that are not bound to layers.
|
java.util.Collection<IEntity> |
getEntitiesByLayer(int layerId)
Gets the entities that are bound to layer with the specified layer ID.
|
java.util.Collection<IEntity> |
getEntitiesByLayer(java.lang.String name)
Gets the entities that are bound to layer with the specified name.
|
java.util.Map<java.lang.String,java.util.Collection<IEntity>> |
getEntitiesByTag() |
int |
getGravity() |
LightSource |
getLightSource(int mapId) |
LightSource |
getLightSource(java.lang.String name) |
java.util.Collection<LightSource> |
getLightSources() |
int |
getLocalMapId()
Gets the next unique local map id.
|
IMap |
getMap() |
java.util.Collection<IMobileEntity> |
getMobileEntities() |
IMobileEntity |
getMobileEntity(int mapId) |
IMobileEntity |
getMobileEntity(java.lang.String name) |
int |
getNextMapId()
Gets the next unique global map id.
|
Prop |
getProp(int mapId) |
Prop |
getProp(java.lang.String name) |
java.util.Collection<Prop> |
getProps() |
java.util.Collection<IRenderable> |
getRenderables(RenderType renderType) |
Spawnpoint |
getSpawnpoint(int mapId) |
Spawnpoint |
getSpawnpoint(java.lang.String name) |
java.util.Collection<Spawnpoint> |
getSpawnPoints() |
StaticShadow |
getStaticShadow(int mapId) |
StaticShadow |
getStaticShadow(java.lang.String name) |
StaticShadowLayer |
getStaticShadowLayer() |
java.util.Collection<StaticShadow> |
getStaticShadows() |
Trigger |
getTrigger(int mapId) |
Trigger |
getTrigger(java.lang.String name) |
java.util.Collection<Trigger> |
getTriggers() |
java.util.Collection<java.lang.String> |
getUsedTags() |
void |
init() |
boolean |
isLoaded() |
void |
load() |
java.util.Collection<IEntity> |
load(IMapObject mapObject) |
void |
loadFromMap(int mapId) |
static <T extends IEntity> |
registerCustomEntityType(java.lang.Class<T> entityType)
Registers a custom
IEntity implementation to support being loaded from an IMap instance. |
static <T extends IEntity> |
registerCustomEntityType(java.lang.String mapObjectType,
java.lang.Class<T> entityType)
Registers a custom
IEntity implementation to support being loaded from an IMap instance. |
static void |
registerMapObjectLoader(IMapObjectLoader mapObjectLoader)
Registers a custom loader instance that is responsible for loading and initializing entities of the defined
MapObjectType.
|
void |
reloadFromMap(int mapId) |
<T extends IEntity> |
remove(java.util.Collection<T> entities) |
void |
remove(IEntity entity) |
void |
remove(int mapId) |
void |
remove(java.lang.String name) |
void |
removeEntityListener(EnvironmentEntityListener listener) |
void |
removeListener(EnvironmentListener listener) |
void |
removeRenderable(IRenderable renderable) |
void |
removeRenderListener(EnvironmentRenderListener listener) |
void |
render(java.awt.Graphics2D g) |
void |
renderLayer(java.awt.Graphics2D g,
IMapObjectLayer layer) |
void |
setGravity(int gravity) |
void |
unload() |
void |
updateLighting() |
void |
updateLighting(IEntity entity) |
void |
updateLighting(java.awt.geom.Rectangle2D section) |
public Environment(IMap map)
public Environment(java.lang.String mapPath)
public void addRenderListener(RenderType renderType, EnvironmentRenderListener listener)
public void removeRenderListener(EnvironmentRenderListener listener)
public void addListener(EnvironmentListener listener)
public void removeListener(EnvironmentListener listener)
public void addEntityListener(EnvironmentEntityListener listener)
public void removeEntityListener(EnvironmentEntityListener listener)
public void add(IEntity entity)
entity
- The entity to add to the environment.public void updateLighting(IEntity entity)
public void updateLighting()
public void updateLighting(java.awt.geom.Rectangle2D section)
public void add(IRenderable renderable, RenderType renderType)
public java.util.Collection<IEntity> build(Blueprint blueprint, java.awt.geom.Point2D location)
public void clear()
public java.util.Collection<ICombatEntity> findCombatEntities(java.awt.Shape shape)
public java.util.Collection<ICombatEntity> findCombatEntities(java.awt.Shape shape, java.util.function.Predicate<ICombatEntity> condition)
shape
- The shape to check intersection for.condition
- An additional condition that allows to specify a condition which
determines if a ICombatEntity
should be considered.Shape
.public java.util.Collection<IEntity> findEntities(java.awt.Shape shape)
public IEntity get(int mapId)
public java.util.List<IEntity> get(int... mapIds)
mapIds
- The map IDs to search for.List
of entities found, in the order given by the parameters.public <T extends IEntity> T get(java.lang.Class<T> clss, int mapId)
public IEntity get(java.lang.String name)
public <T extends IEntity> T get(java.lang.Class<T> clss, java.lang.String name)
public java.util.Collection<IEntity> getByTag(java.lang.String... tags)
public <T extends IEntity> java.util.Collection<T> getByTag(java.lang.Class<? extends T> clss, java.lang.String... tags)
public AmbientLight getAmbientLight()
public java.util.Collection<MapArea> getAreas()
public MapArea getArea(int mapId)
public MapArea getArea(java.lang.String name)
public java.awt.geom.Point2D getCenter()
public java.util.Collection<Emitter> getEmitters()
public Emitter getEmitter(int mapId)
public Emitter getEmitter(java.lang.String name)
public java.util.Collection<CollisionBox> getCollisionBoxes()
public CollisionBox getCollisionBox(int mapId)
public CollisionBox getCollisionBox(java.lang.String name)
public java.util.Collection<ICombatEntity> getCombatEntities()
public ICombatEntity getCombatEntity(int mapId)
public ICombatEntity getCombatEntity(java.lang.String name)
public java.util.Collection<IEntity> getEntities()
public java.util.Collection<IEntity> getEntities(RenderType renderType)
Entities are unbound from there originating MapObjectLayer
if their RenderType
differs
from the layer's RenderType
.
renderType
- The render typeIEntity.getRenderType()
,
ILayer.getRenderType()
public java.util.Collection<IEntity> getEntities(IMapObjectLayer layer)
Entities are bound to a layer if their RenderType
matches the layer's RenderType
layer
- The layer that the entities are bound to.IEntity.getRenderType()
,
ILayer.getRenderType()
public java.util.Collection<IEntity> getEntitiesByLayer(java.lang.String name)
Entities are bound to a layer if their RenderType
matches the layer's RenderType
name
- The name of the layerIEntity.getRenderType()
,
ILayer.getRenderType()
,
ILayer.getName()
public java.util.Collection<IEntity> getEntitiesByLayer(int layerId)
Entities are bound to a layer if their RenderType
matches the layer's RenderType
layerId
- The id of the layerIEntity.getRenderType()
,
ILayer.getRenderType()
,
ILayer.getId()
public java.util.Map<java.lang.String,java.util.Collection<IEntity>> getEntitiesByTag()
public <T> java.util.Collection<T> getByType(java.lang.Class<? extends T> cls)
public java.util.Collection<LightSource> getLightSources()
public LightSource getLightSource(int mapId)
public LightSource getLightSource(java.lang.String name)
public int getLocalMapId()
public IMap getMap()
public java.util.Collection<IMobileEntity> getMobileEntities()
public IMobileEntity getMobileEntity(int mapId)
public IMobileEntity getMobileEntity(java.lang.String name)
public int getNextMapId()
public java.util.Collection<IRenderable> getRenderables(RenderType renderType)
public java.util.Collection<Prop> getProps()
public Prop getProp(int mapId)
public Prop getProp(java.lang.String name)
public Creature getCreature(int mapId)
public Creature getCreature(java.lang.String name)
public java.util.Collection<Creature> getCreatures()
public Spawnpoint getSpawnpoint(int mapId)
public Spawnpoint getSpawnpoint(java.lang.String name)
public java.util.Collection<Spawnpoint> getSpawnPoints()
public java.util.Collection<StaticShadow> getStaticShadows()
public StaticShadow getStaticShadow(int mapId)
public StaticShadow getStaticShadow(java.lang.String name)
public StaticShadowLayer getStaticShadowLayer()
public Trigger getTrigger(int mapId)
public Trigger getTrigger(java.lang.String name)
public java.util.Collection<Trigger> getTriggers()
public java.util.Collection<java.lang.String> getUsedTags()
public final void init()
public boolean isLoaded()
public void load()
public void loadFromMap(int mapId)
public static void registerMapObjectLoader(IMapObjectLoader mapObjectLoader)
mapObjectLoader
- The MapObjectLoader instance to be registered.IMapObjectLoader.getMapObjectType()
public static <T extends IEntity> void registerCustomEntityType(java.lang.String mapObjectType, java.lang.Class<T> entityType)
IEntity
implementation to support being loaded from an IMap
instance.
Note that the specified class needs to be accessible in a static manner. Inner classes that aren't declared statically are not supported.
This is an overload of the registerCustomEntityType(Class)
method that allows to explicitly specify the MapObjectType
without
having to provide an EntityInfo
annotation containing this information.T
- The type of the custom entity.mapObjectType
- The custom mapobjectType that is used by IMapObjects
to determine the target entity implementation.entityType
- The class type of the custom entity implementation.IMapObject.getType()
,
EntityInfo.customMapObjectType()
public static <T extends IEntity> void registerCustomEntityType(java.lang.Class<T> entityType)
IEntity
implementation to support being loaded from an IMap
instance.
Note that the specified class needs to be accessible in a static manner. Inner classes that aren't declared statically are not supported.
This implementation uses the provided EntityInfo.customMapObjectType()
to determine for which type the specified class should be
used.T
- The type of the custom entity.entityType
- The class type of the custom entity implementation.registerCustomEntityType(String, Class)
,
IMapObject.getType()
,
EntityInfo.customMapObjectType()
public void reloadFromMap(int mapId)
public void remove(IEntity entity)
public void remove(int mapId)
public void remove(java.lang.String name)
public <T extends IEntity> void remove(java.util.Collection<T> entities)
public void removeRenderable(IRenderable renderable)
public void render(java.awt.Graphics2D g)
render
in interface IRenderable
public int getGravity()
public void setGravity(int gravity)
public void unload()
public java.util.Collection<IEntity> load(IMapObject mapObject)
public void renderLayer(java.awt.Graphics2D g, IMapObjectLayer layer)
public java.util.Collection<java.lang.Integer> getAllMapIDs()