Class Chunk
- java.lang.Object
-
- com.bombinggames.wurfelengine.core.map.Chunk
-
- All Implemented Interfaces:
com.badlogic.gdx.ai.msg.Telegraph
public class Chunk extends java.lang.Object implements com.badlogic.gdx.ai.msg.Telegraph
A Chunk is filled with many Blocks and is a part of the map.
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.String
CHUNKFILESUFFIX
The suffix of a chunk files.
-
Constructor Summary
Constructors Constructor Description Chunk(Map map, int coordX, int coordY)
Creates a Chunk filled with empty cells (likely air).Chunk(Map map, java.io.File path, int coordX, int coordY, Generator generator)
Creates a chunk by trying to load and if this fails it generates a new one.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addLogic(AbstractBlockLogicExtension block)
void
dispose(Map map, java.io.File path)
disposes the chunkvoid
fill(Generator generator)
Fills the chunk's block using a generator.int
getBlock(int x, int y, int z)
Get the block data at this coordinate.int
getBlockByIndex(int x, int y, int z)
Get the block data at this index position.byte
getBlockId(int x, int y, int z)
static int
getBlocksX()
The amount of blocks in X directionstatic int
getBlocksY()
The amount of blocks in Y directionstatic int
getBlocksZ()
The amount of blocks in Z directionbyte
getBlockValue(int x, int y, int z)
int
getChunkX()
Get the chunk coordinate of this chunk.int
getChunkY()
Get the chunk coordinate of this chunk.byte[][][]
getData()
Returns the data of the chunk. each block uses three bytes, id, value and healthstatic int
getGameDepth()
y axisstatic int
getGameHeight()
The height of the map. z axisstatic int
getGameWidth()
x axisbyte
getHealth(int x, int y, int z)
AbstractBlockLogicExtension
getLogic(Coordinate coord)
Get the logic to a logicblock.RenderChunk
getRenderChunk(RenderStorage storage)
int
getTopLeftCoordinateX()
int
getTopLeftCoordinateY()
static int
getViewDepth()
Not scaled.static int
getViewWidth()
Not scaled.boolean
handleMessage(com.badlogic.gdx.ai.msg.Telegram msg)
boolean
hasCoord(Coordinate coord)
Check if the chunk has the coordinate inside.boolean
hasPoint(Point point)
Check if the coordinate has the coordinate inside.void
processModification()
checks if the chunk got modified and if that is the case calls the modification methodsboolean
restoreFromRoot(java.io.File path, int saveSlot, int coordX, int coordY)
copies somethingjava.util.ArrayList<AbstractEntity>
retrieveEntities()
Returns entitiesinSaveFile spawned on this chunk.boolean
save(Map map, java.io.File path, int saveSlot)
Save this chunk on storage.void
setBlock(int x, int y, int z, byte id)
Almost lowest level method to set a block in the map.void
setBlock(Coordinate coord, byte id)
Almost lowest level method to set a block in the map.void
setBlock(Coordinate coord, byte id, byte value)
Almost lowest level method to set a block in the map.void
setBlock(Coordinate coord, byte id, byte value, byte health)
Almost lowest level method to set a block in the map.void
setHealth(Coordinate coord, byte health)
Set health of a cell.void
setValue(Coordinate coord, byte value)
java.lang.String
toString()
print the chunk to consolevoid
update(float dt)
Updates the chunk. should be called once per frame.
-
-
-
Field Detail
-
CHUNKFILESUFFIX
protected static final java.lang.String CHUNKFILESUFFIX
The suffix of a chunk files.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Chunk
public Chunk(Map map, int coordX, int coordY)
Creates a Chunk filled with empty cells (likely air).- Parameters:
map
-coordX
-coordY
-
-
Chunk
public Chunk(Map map, java.io.File path, int coordX, int coordY, Generator generator)
Creates a chunk by trying to load and if this fails it generates a new one.- Parameters:
map
-coordX
- the chunk coordinatecoordY
- the chunk coordinatepath
- filename, can be null to skip file loadinggenerator
- used for generating if laoding fails
-
-
Method Detail
-
getBlocksX
public static int getBlocksX()
The amount of blocks in X direction- Returns:
-
getBlocksY
public static int getBlocksY()
The amount of blocks in Y direction- Returns:
-
getBlocksZ
public static int getBlocksZ()
The amount of blocks in Z direction- Returns:
-
getViewWidth
public static int getViewWidth()
Not scaled.- Returns:
-
getViewDepth
public static int getViewDepth()
Not scaled.- Returns:
-
getGameWidth
public static int getGameWidth()
x axis- Returns:
-
getGameDepth
public static int getGameDepth()
y axis- Returns:
-
getGameHeight
public static int getGameHeight()
The height of the map. z axis- Returns:
- in game size
-
update
public void update(float dt)
Updates the chunk. should be called once per frame.- Parameters:
dt
- time since last frame in game time
-
processModification
public void processModification()
checks if the chunk got modified and if that is the case calls the modification methods
-
fill
public void fill(Generator generator)
Fills the chunk's block using a generator.- Parameters:
generator
-
-
restoreFromRoot
public boolean restoreFromRoot(java.io.File path, int saveSlot, int coordX, int coordY)
copies something- Parameters:
path
-saveSlot
-coordX
-coordY
-- Returns:
-
retrieveEntities
public java.util.ArrayList<AbstractEntity> retrieveEntities()
Returns entitiesinSaveFile spawned on this chunk. Can only called once.- Returns:
- list of entitiesinSaveFile on this chunk, can be null if empty
-
save
public boolean save(Map map, java.io.File path, int saveSlot) throws java.io.IOException
Save this chunk on storage.- Parameters:
map
- the map of which this chunk is a part ofpath
- the map name on storagesaveSlot
-- Returns:
- Throws:
java.io.IOException
-
getData
public byte[][][] getData()
Returns the data of the chunk. each block uses three bytes, id, value and health- Returns:
-
hasCoord
public boolean hasCoord(Coordinate coord)
Check if the chunk has the coordinate inside. Only checks x and y.
O(1)- Parameters:
coord
- the coordinate to be checked- Returns:
- true if coord is inside.
-
hasPoint
public boolean hasPoint(Point point)
Check if the coordinate has the coordinate inside.- Parameters:
point
- the coordinate to be checked- Returns:
- true if coord is inside.
-
toString
public java.lang.String toString()
print the chunk to console- Overrides:
toString
in classjava.lang.Object
- Returns:
-
getChunkX
public int getChunkX()
Get the chunk coordinate of this chunk.- Returns:
-
getChunkY
public int getChunkY()
Get the chunk coordinate of this chunk.- Returns:
-
getTopLeftCoordinateX
public int getTopLeftCoordinateX()
- Returns:
- not copy safe
-
getTopLeftCoordinateY
public int getTopLeftCoordinateY()
- Returns:
- not copy safe
-
setBlock
public void setBlock(int x, int y, int z, byte id)
Almost lowest level method to set a block in the map. If the block has logic a newAbstractBlockLogicExtension
instance will be created. Health set to 100 and value set to 0- Parameters:
x
-y
-z
-id
-
-
setBlock
public void setBlock(Coordinate coord, byte id)
Almost lowest level method to set a block in the map. If the block has logic a newAbstractBlockLogicExtension
instance will be created. Health set to 100 and value set to 0- Parameters:
coord
-id
-
-
setBlock
public void setBlock(Coordinate coord, byte id, byte value)
Almost lowest level method to set a block in the map. If the block has logic a newAbstractBlockLogicExtension
instance will be created. Sets health to 100.- Parameters:
coord
-id
-value
-
-
setBlock
public void setBlock(Coordinate coord, byte id, byte value, byte health)
Almost lowest level method to set a block in the map. If the block has logic a new logicinstance will be created.- Parameters:
coord
- The position where you insert the block. Must be inside the bounds of the chunk.id
-value
-health
-
-
setValue
public void setValue(Coordinate coord, byte value)
- Parameters:
coord
-value
-
-
setHealth
public void setHealth(Coordinate coord, byte health)
Set health of a cell.- Parameters:
coord
-health
- 0-100.
-
addLogic
protected void addLogic(AbstractBlockLogicExtension block)
- Parameters:
block
-
-
getLogic
public AbstractBlockLogicExtension getLogic(Coordinate coord)
Get the logic to a logicblock.- Parameters:
coord
-- Returns:
- can return null
-
dispose
public void dispose(Map map, java.io.File path)
disposes the chunk- Parameters:
map
-path
- if null, does not save the file
-
getRenderChunk
public RenderChunk getRenderChunk(RenderStorage storage)
- Parameters:
storage
-- Returns:
-
handleMessage
public boolean handleMessage(com.badlogic.gdx.ai.msg.Telegram msg)
- Specified by:
handleMessage
in interfacecom.badlogic.gdx.ai.msg.Telegraph
-
getBlockId
public byte getBlockId(int x, int y, int z)
- Parameters:
x
- coordinatey
- coordinatez
- coordinate- Returns:
- can be null-pointer
-
getBlockValue
public byte getBlockValue(int x, int y, int z)
- Parameters:
x
-y
-z
-- Returns:
-
getHealth
public byte getHealth(int x, int y, int z)
- Parameters:
x
-y
-z
-- Returns:
-
getBlock
public int getBlock(int x, int y, int z)
Get the block data at this coordinate.- Parameters:
x
- global coordinatesy
- global coordinatesz
- global coordinates- Returns:
- first byte id, second value, third is health.
-
getBlockByIndex
public int getBlockByIndex(int x, int y, int z)
Get the block data at this index position.- Parameters:
x
- only valid indexy
- only valid indexz
- only valid index- Returns:
- first byte id, second value, third is health.
-
-