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)
Adds the specified instance to be rendered with the defined
RenderType whenever the environment's render pipeline is executed. |
void |
addAll(IEntity... entities)
Adds all the specified entities to the environment container.
|
<T extends IEntity> |
addAll(java.lang.Iterable<T> entities)
Adds all the specified entities to the environment container.
|
void |
addEntityListener(EnvironmentEntityListener listener) |
void |
addListener(EnvironmentListener 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() |
boolean |
contains(IEntity entity)
Determines whether the environment contains the specified entity.
|
boolean |
contains(int mapId)
Determines whether the environment contains any entity with the specified map ID.
|
java.util.Collection<ICombatEntity> |
findCombatEntities(java.awt.Shape shape) |
java.util.Collection<ICombatEntity> |
findCombatEntities(java.awt.Shape shape,
java.util.function.Predicate<ICombatEntity> condition)
Attempts to find all combat entities whose hitBox intersects with 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)
Gets all entities with the specified map IDs from the environment .
|
IEntity |
get(int mapId) |
IEntity |
get(java.lang.String name) |
java.util.Collection<java.lang.Integer> |
getAllMapIDs()
Gets an immutable collection with all assigned map IDs on the environment.
|
AmbientLight |
getAmbientLight() |
MapArea |
getArea(int mapId)
Gets the
MapArea with the specified map ID from the environment. |
MapArea |
getArea(java.lang.String name)
Gets the
MapArea with the specified name from the environment. |
java.util.Collection<MapArea> |
getAreas()
Gets an immutable collection containing all
MapArea entities on the environment. |
<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)
Gets the
CollisionBox with the specified map ID from the environment. |
CollisionBox |
getCollisionBox(java.lang.String name)
Gets the
CollisionBox with the specified name from the environment. |
java.util.Collection<CollisionBox> |
getCollisionBoxes()
Gets an immutable collection containing all
CollisionBox entities on the environment. |
java.util.Collection<ICombatEntity> |
getCombatEntities()
Gets an immutable collection containing all
ICombatEntity entities on the environment. |
ICombatEntity |
getCombatEntity(int mapId)
Gets the
ICombatEntity with the specified map ID from the environment. |
ICombatEntity |
getCombatEntity(java.lang.String name)
Gets the
ICombatEntity with the specified name from the environment. |
Creature |
getCreature(int mapId)
Gets the
Creature with the specified map ID from the environment. |
Creature |
getCreature(java.lang.String name)
Gets the
Creature with the specified name from the environment. |
java.util.Collection<Creature> |
getCreatures()
Gets an immutable collection containing all
Creature entities on the environment. |
Emitter |
getEmitter(int mapId)
Gets the
Emitter with the specified map ID from the environment. |
Emitter |
getEmitter(java.lang.String name)
Gets the
Emitter with the specified name from the environment. |
java.util.Collection<Emitter> |
getEmitters()
Gets an immutable collection containing all
Emitter entities on the environment. |
java.util.Collection<IEntity> |
getEntities()
Gets an immutable collection containing all entities on the environment.
|
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)
Gets the
LightSource with the specified map ID from the environment. |
LightSource |
getLightSource(java.lang.String name)
Gets the
LightSource with the specified name from the environment. |
java.util.Collection<LightSource> |
getLightSources()
Gets an immutable collection containing all
LightSource entities on the environment. |
int |
getLocalMapId()
Gets the next unique local map id.
|
IMap |
getMap() |
java.util.Collection<IMobileEntity> |
getMobileEntities()
Gets an immutable collection containing all
IMobileEntity instances on the environment. |
IMobileEntity |
getMobileEntity(int mapId)
Gets the
IMobileEntity with the specified map ID from the environment. |
IMobileEntity |
getMobileEntity(java.lang.String name)
Gets the
IMobileEntity with the specified name from the environment. |
int |
getNextMapId()
Gets the next unique global map id.
|
Prop |
getProp(int mapId)
Gets the
Prop with the specified map ID from the environment. |
Prop |
getProp(java.lang.String name)
Gets the
Prop with the specified name from the environment. |
java.util.Collection<Prop> |
getProps()
Gets an immutable collection containing all
Prop entities on the environment. |
java.util.Collection<IRenderable> |
getRenderables(RenderType renderType)
Gets an immutable collection containing all
IRenderable instances for the specified render type on the environment. |
Spawnpoint |
getSpawnpoint(int mapId)
Gets the
Spawnpoint with the specified map ID from the environment. |
Spawnpoint |
getSpawnpoint(java.lang.String name)
Gets the
Spawnpoint with the specified name from the environment. |
java.util.Collection<Spawnpoint> |
getSpawnPoints()
Gets an immutable collection containing all
Spawnpoint entities on the environment. |
StaticShadow |
getStaticShadow(int mapId)
Gets the
StaticShadow with the specified map ID from the environment. |
StaticShadow |
getStaticShadow(java.lang.String name)
Gets the
StaticShadow with the specified name from the environment. |
StaticShadowLayer |
getStaticShadowLayer() |
java.util.Collection<StaticShadow> |
getStaticShadows()
Gets an immutable collection containing all
StaticShadow entities on the environment. |
Trigger |
getTrigger(int mapId)
Gets the
Trigger with the specified map ID from the environment. |
Trigger |
getTrigger(java.lang.String name)
Gets the
Trigger with the specified name from the environment. |
java.util.Collection<Trigger> |
getTriggers()
Gets an immutable collection containing all
Trigger entities on the environment. |
java.util.Collection<java.lang.String> |
getUsedTags()
Gets all tags that are assigned to entities on this environment.
|
void |
init() |
Trigger |
interact(ICollisionEntity source)
Attempts to interact with triggers on this environment.
|
Trigger |
interact(ICollisionEntity source,
java.util.function.Predicate<Trigger> condition) |
boolean |
isLoaded() |
void |
load() |
java.util.Collection<IEntity> |
load(IMapObject mapObject) |
void |
loadFromMap(int mapId) |
void |
onRendered(RenderType renderType,
EnvironmentRenderedListener listener) |
static void |
registerCustomEntityType(java.lang.Class<? extends IEntity> entityType)
Registers a custom
IEntity implementation to support being loaded from an IMap instance. |
static void |
registerCustomEntityType(java.lang.String mapObjectType,
java.lang.Class<? extends IEntity> 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) |
void |
remove(IEntity entity) |
void |
remove(int mapId) |
void |
remove(java.lang.String name) |
void |
removeAll(IEntity... entities) |
<T extends IEntity> |
removeAll(java.lang.Iterable<T> entities) |
void |
removeEntityListener(EnvironmentEntityListener listener) |
void |
removeListener(EnvironmentListener listener) |
void |
removeRenderable(IRenderable renderable) |
void |
removeRenderListener(EnvironmentRenderedListener listener) |
void |
render(java.awt.Graphics2D g)
Renders the visual contents of this instance onto the provided graphics context.
|
void |
setGravity(int gravity) |
void |
unload() |
void |
updateLighting()
Forces an update on the lighting layers for the entire map.
|
void |
updateLighting(java.awt.geom.Rectangle2D section)
Forces an update on the lighting layers for the specified section on the map.
|
public Environment(IMap map)
public Environment(java.lang.String mapPath)
public static void registerMapObjectLoader(IMapObjectLoader mapObjectLoader)
mapObjectLoader - The MapObjectLoader instance to be registered.IMapObjectLoader.getMapObjectType()public static void registerCustomEntityType(java.lang.String mapObjectType,
java.lang.Class<? extends IEntity> 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.
Custom entity types need to provide at least one constructor that matches the following criteria:
Environment, IMapObjectIMapObject, EnvironmentIMapObjectEnvironmentmapObjectType - 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 void registerCustomEntityType(java.lang.Class<? extends IEntity> 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.entityType - The class type of the custom entity implementation.registerCustomEntityType(String, Class),
IMapObject.getType(),
EntityInfo.customMapObjectType()public void onRendered(RenderType renderType, EnvironmentRenderedListener listener)
public void removeRenderListener(EnvironmentRenderedListener 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.isLoaded(),
IEntity.loaded(Environment),
EnvironmentEntityListener.entityAdded(IEntity)public <T extends IEntity> void addAll(java.lang.Iterable<T> entities)
T - The type of the entity.entities - The entities to be added to the environment.add(IEntity),
addAll(IEntity...),
remove(IEntity),
removeAll(Iterable)public void addAll(IEntity... entities)
entities - The entities to be added to the environment.add(IEntity),
addAll(Iterable),
remove(IEntity),
removeAll(Iterable)public void updateLighting()
public void updateLighting(java.awt.geom.Rectangle2D section)
section - The section for which to update the lighting layers.getStaticShadowLayer(),
getAmbientLight(),
ColorLayer.updateSection(Rectangle2D)public void add(IRenderable renderable, RenderType renderType)
RenderType whenever the environment's render pipeline is executed.
This method can be used for any custom rendering that is not related to an entity, a GUI component or the map.
Note that you don't need to explicitly add an Entity if it implements IRenderable. The render engine will inherently
call an entity's render method.
renderable - The instance that should be rendered.renderType - The render type that determines how the instance is processed by the environment's render pipeline.render(Graphics2D),
RenderEngine.renderEntity(Graphics2D, IEntity)public java.util.Collection<IEntity> build(Blueprint blueprint, java.awt.geom.Point2D location)
public void clear()
public boolean contains(IEntity entity)
entity - The entity to check for.public boolean contains(int mapId)
mapId - The map ID of the entity to check for.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<java.lang.Integer> getAllMapIDs()
public java.util.Collection<MapArea> getAreas()
MapArea entities on the environment.
To add or remove entities, use the corresponding methods on the environment.
MapArea entities.add(IEntity),
addAll(Iterable),
remove(IEntity),
removeAll(Iterable)public MapArea getArea(int mapId)
MapArea with the specified map ID from the environment.mapId - The map ID of the entity.MapArea with the specified map ID or null if no entity is found.getArea(String),
getAreas()public MapArea getArea(java.lang.String name)
MapArea with the specified name from the environment.name - The name of the entity.MapArea with the specified name or null if no entity is found.getArea(int),
getAreas()public java.util.Collection<Emitter> getEmitters()
Emitter entities on the environment.
To add or remove entities, use the corresponding methods on the environment.
Emitter entities.add(IEntity),
addAll(Iterable),
remove(IEntity),
removeAll(Iterable)public Emitter getEmitter(int mapId)
Emitter with the specified map ID from the environment.mapId - The map ID of the entity.Emitter with the specified map ID or null if no entity is found.getEmitter(String),
getEmitters()public Emitter getEmitter(java.lang.String name)
Emitter with the specified name from the environment.name - The name of the entity.Emitter with the specified name or null if no entity is found.getEmitter(int),
getEmitters()public java.util.Collection<CollisionBox> getCollisionBoxes()
CollisionBox entities on the environment.
To add or remove entities, use the corresponding methods on the environment.
CollisionBox entities.add(IEntity),
addAll(Iterable),
remove(IEntity),
removeAll(Iterable)public CollisionBox getCollisionBox(int mapId)
CollisionBox with the specified map ID from the environment.mapId - The map ID of the entity.CollisionBox with the specified map ID or null if no entity is found.getCollisionBox(String),
getCollisionBoxes()public CollisionBox getCollisionBox(java.lang.String name)
CollisionBox with the specified name from the environment.name - The name of the entity.CollisionBox with the specified name or null if no entity is found.getCollisionBox(int),
getCollisionBoxes()public java.util.Collection<ICombatEntity> getCombatEntities()
ICombatEntity entities on the environment.
To add or remove entities, use the corresponding methods on the environment.
ICombatEntity entities.add(IEntity),
addAll(Iterable),
remove(IEntity),
removeAll(Iterable)public ICombatEntity getCombatEntity(int mapId)
ICombatEntity with the specified map ID from the environment.mapId - The map ID of the entity.ICombatEntity with the specified map ID or null if no entity is found.getCombatEntity(String),
getCombatEntities()public ICombatEntity getCombatEntity(java.lang.String name)
ICombatEntity with the specified name from the environment.name - The name of the entity.ICombatEntity with the specified name or null if no entity is found.getCombatEntity(int),
getCombatEntities()public java.util.Collection<IEntity> getEntities()
To add or remove entities, use the corresponding methods on the environment.
add(IEntity),
addAll(Iterable),
remove(IEntity),
removeAll(Iterable)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()
LightSource entities on the environment.
To add or remove entities, use the corresponding methods on the environment.
LightSource entities.add(IEntity),
addAll(Iterable),
remove(IEntity),
removeAll(Iterable)public LightSource getLightSource(int mapId)
LightSource with the specified map ID from the environment.mapId - The map ID of the entity.LightSource with the specified map ID or null if no entity is found.getLightSource(String),
getLightSources()public LightSource getLightSource(java.lang.String name)
LightSource with the specified name from the environment.name - The name of the entity.LightSource with the specified name or null if no entity is found.getLightSource(int),
getLightSources()public int getLocalMapId()
public IMap getMap()
public java.util.Collection<IMobileEntity> getMobileEntities()
IMobileEntity instances on the environment.
To add or remove entities, use the corresponding methods on the environment.
IMobileEntity instances.add(IEntity),
addAll(Iterable),
remove(IEntity),
removeAll(Iterable)public IMobileEntity getMobileEntity(int mapId)
IMobileEntity with the specified map ID from the environment.mapId - The map ID of the entity.IMobileEntity with the specified map ID or null if no entity is found.getMobileEntity(String),
getMobileEntities()public IMobileEntity getMobileEntity(java.lang.String name)
IMobileEntity with the specified name from the environment.name - The name of the entity.IMobileEntity with the specified name or null if no entity is found.getMobileEntity(int),
getMobileEntities()public int getNextMapId()
public java.util.Collection<IRenderable> getRenderables(RenderType renderType)
IRenderable instances for the specified render type on the environment.
To add or remove instances, use the corresponding methods on the environment.
renderType - The render type of the renderable instances.IRenderable instances.add(IRenderable, RenderType),
removeRenderable(IRenderable)public java.util.Collection<Prop> getProps()
Prop entities on the environment.
To add or remove entities, use the corresponding methods on the environment.
Prop entities.add(IEntity),
addAll(Iterable),
remove(IEntity),
removeAll(Iterable)public Prop getProp(int mapId)
Prop with the specified map ID from the environment.mapId - The map ID of the entity.Prop with the specified map ID or null if no entity is found.getProp(String),
getProps()public Prop getProp(java.lang.String name)
Prop with the specified name from the environment.name - The name of the entity.Prop with the specified name or null if no entity is found.getProp(int),
getProps()public java.util.Collection<Creature> getCreatures()
Creature entities on the environment.
To add or remove entities, use the corresponding methods on the environment.
Creature entities.add(IEntity),
addAll(Iterable),
remove(IEntity),
removeAll(Iterable)public Creature getCreature(int mapId)
Creature with the specified map ID from the environment.mapId - The map ID of the entity.Creature with the specified map ID or null if no entity is found.getCreature(String),
getCreatures()public Creature getCreature(java.lang.String name)
Creature with the specified name from the environment.name - The name of the entity.Creature with the specified name or null if no entity is found.getCreature(int),
getCreatures()public java.util.Collection<Spawnpoint> getSpawnPoints()
Spawnpoint entities on the environment.
To add or remove entities, use the corresponding methods on the environment.
Spawnpoint entities.add(IEntity),
addAll(Iterable),
remove(IEntity),
removeAll(Iterable)public Spawnpoint getSpawnpoint(int mapId)
Spawnpoint with the specified map ID from the environment.mapId - The map ID of the entity.Spawnpoint with the specified map ID or null if no entity is found.getSpawnpoint(String),
getSpawnPoints()public Spawnpoint getSpawnpoint(java.lang.String name)
Spawnpoint with the specified name from the environment.name - The name of the entity.Spawnpoint with the specified name or null if no entity is found.getSpawnpoint(int),
getSpawnPoints()public java.util.Collection<StaticShadow> getStaticShadows()
StaticShadow entities on the environment.
To add or remove entities, use the corresponding methods on the environment.
StaticShadow entities.add(IEntity),
addAll(Iterable),
remove(IEntity),
removeAll(Iterable)public StaticShadow getStaticShadow(int mapId)
StaticShadow with the specified map ID from the environment.mapId - The map ID of the entity.StaticShadow with the specified map ID or null if no entity is found.getStaticShadow(String),
getStaticShadows()public StaticShadow getStaticShadow(java.lang.String name)
StaticShadow with the specified name from the environment.name - The name of the entity.StaticShadow with the specified name or null if no entity is found.getStaticShadow(int),
getStaticShadows()public StaticShadowLayer getStaticShadowLayer()
public java.util.Collection<Trigger> getTriggers()
Trigger entities on the environment.
To add or remove entities, use the corresponding methods on the environment.
Trigger entities.add(IEntity),
addAll(Iterable),
remove(IEntity),
removeAll(Iterable)public Trigger getTrigger(int mapId)
Trigger with the specified map ID from the environment.mapId - The map ID of the entity.Trigger with the specified map ID or null if no entity is found.getTrigger(String),
getTriggers()public Trigger getTrigger(java.lang.String name)
Trigger with the specified name from the environment.name - The name of the entity.Trigger with the specified name or null if no entity is found.getTrigger(int),
getTriggers()public java.util.Collection<java.lang.String> getUsedTags()
public java.awt.geom.Point2D getCenter()
public final void init()
public boolean isLoaded()
public void load()
public void loadFromMap(int mapId)
public java.util.Collection<IEntity> load(IMapObject mapObject)
public Trigger interact(ICollisionEntity source)
source - The entity that attempts to interacts with triggers.public Trigger interact(ICollisionEntity source, java.util.function.Predicate<Trigger> condition)
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 removeAll(java.lang.Iterable<T> entities)
public void removeAll(IEntity... entities)
public void removeRenderable(IRenderable renderable)
public void render(java.awt.Graphics2D g)
IRenderable
If an Entity implements this interface, this method will be called right after the entity was rendered from the environment.
Allowing for a custom rendering mechanism.
This interface can be implemented in general by anything that should be rendered to the game's screen.
render in interface IRenderableg - The current graphics object onto which this instance will render its visual contents.RenderEngine.renderEntity(Graphics2D, de.gurkenlabs.litiengine.entities.IEntity)public int getGravity()
public void setGravity(int gravity)
public void unload()