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.TelegraphA 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.StringCHUNKFILESUFFIXThe 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 voidaddLogic(AbstractBlockLogicExtension block)voiddispose(Map map, java.io.File path)disposes the chunkvoidfill(Generator generator)Fills the chunk's block using a generator.intgetBlock(int x, int y, int z)Get the block data at this coordinate.intgetBlockByIndex(int x, int y, int z)Get the block data at this index position.bytegetBlockId(int x, int y, int z)static intgetBlocksX()The amount of blocks in X directionstatic intgetBlocksY()The amount of blocks in Y directionstatic intgetBlocksZ()The amount of blocks in Z directionbytegetBlockValue(int x, int y, int z)intgetChunkX()Get the chunk coordinate of this chunk.intgetChunkY()Get the chunk coordinate of this chunk.byte[][][]getData()Returns the data of the chunk. each block uses three bytes, id, value and healthstatic intgetGameDepth()y axisstatic intgetGameHeight()The height of the map. z axisstatic intgetGameWidth()x axisbytegetHealth(int x, int y, int z)AbstractBlockLogicExtensiongetLogic(Coordinate coord)Get the logic to a logicblock.RenderChunkgetRenderChunk(RenderStorage storage)intgetTopLeftCoordinateX()intgetTopLeftCoordinateY()static intgetViewDepth()Not scaled.static intgetViewWidth()Not scaled.booleanhandleMessage(com.badlogic.gdx.ai.msg.Telegram msg)booleanhasCoord(Coordinate coord)Check if the chunk has the coordinate inside.booleanhasPoint(Point point)Check if the coordinate has the coordinate inside.voidprocessModification()checks if the chunk got modified and if that is the case calls the modification methodsbooleanrestoreFromRoot(java.io.File path, int saveSlot, int coordX, int coordY)copies somethingjava.util.ArrayList<AbstractEntity>retrieveEntities()Returns entitiesinSaveFile spawned on this chunk.booleansave(Map map, java.io.File path, int saveSlot)Save this chunk on storage.voidsetBlock(int x, int y, int z, byte id)Almost lowest level method to set a block in the map.voidsetBlock(Coordinate coord, byte id)Almost lowest level method to set a block in the map.voidsetBlock(Coordinate coord, byte id, byte value)Almost lowest level method to set a block in the map.voidsetBlock(Coordinate coord, byte id, byte value, byte health)Almost lowest level method to set a block in the map.voidsetHealth(Coordinate coord, byte health)Set health of a cell.voidsetValue(Coordinate coord, byte value)java.lang.StringtoString()print the chunk to consolevoidupdate(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:
toStringin 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 newAbstractBlockLogicExtensioninstance 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 newAbstractBlockLogicExtensioninstance 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 newAbstractBlockLogicExtensioninstance 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:
handleMessagein 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.
-
-