-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added schematic support
- Loading branch information
Showing
20 changed files
with
563 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
description = 'Miscellaneous utilities which are shared between modules' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
craftlib-commons/src/main/kotlin/dev/zerite/craftlib/commons/world/Block.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package dev.zerite.craftlib.commons.world | ||
|
||
/** | ||
* Stores information about a single block in the world | ||
* | ||
* @author Koding | ||
* @since 0.1.0-SNAPSHOT | ||
*/ | ||
data class Block( | ||
val id: Int, | ||
val metadata: Int, | ||
val blockLight: Int = 0, | ||
val skyLight: Int = 0 | ||
) { | ||
|
||
companion object { | ||
/** | ||
* Constant value for an air block. | ||
*/ | ||
@JvmField | ||
val AIR = Block(0, 0) | ||
} | ||
|
||
/** | ||
* The location of this block. | ||
*/ | ||
lateinit var location: BlockLocation | ||
} | ||
|
||
/** | ||
* Vector for storing a 3D block location. | ||
* | ||
* @author Koding | ||
* @since 0.1.0-SNAPSHOT | ||
*/ | ||
data class BlockLocation( | ||
val x: Int, | ||
val y: Int, | ||
val z: Int | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
craftlib-protocol/src/main/kotlin/dev/zerite/craftlib/protocol/data/world/World.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package dev.zerite.craftlib.protocol.data.world | ||
|
||
import dev.zerite.craftlib.commons.world.Block | ||
|
||
/** | ||
* Simple utility class which allows you to set any coordinate in a world with | ||
* a block and automatically update the chunks map. | ||
* | ||
* @author Koding | ||
* @since 0.1.3 | ||
*/ | ||
@Suppress("UNUSED") | ||
class World @JvmOverloads constructor(var chunks: MutableMap<Pair<Int, Int>, ChunkColumn> = hashMapOf()) { | ||
|
||
/** | ||
* Sets a block a the given position in the world. | ||
* | ||
* @param x The x position to set the block at. | ||
* @param y The y position to set the block at. | ||
* @param z The z position to set the block at. | ||
* @param block The new block for the position to have set. | ||
* | ||
* @author Koding | ||
* @since 0.1.3 | ||
*/ | ||
operator fun set(x: Int, y: Int, z: Int, block: Block) { | ||
val chunkX = x shr 4 | ||
val chunkZ = z shr 4 | ||
val column = chunks.getOrPut(chunkX to chunkZ) { ChunkColumn(chunkX, chunkZ) } | ||
column[x and 0xF, y, z and 0xF] = block | ||
} | ||
|
||
/** | ||
* Gets a block at the given position or null if there | ||
* is no block present. | ||
* | ||
* @param x The x position to set the block at. | ||
* @param y The y position to set the block at. | ||
* @param z The z position to set the block at. | ||
* | ||
* @author Koding | ||
* @since 0.1.3 | ||
*/ | ||
operator fun get(x: Int, y: Int, z: Int): Block? { | ||
val chunkX = x shr 4 | ||
val chunkZ = z shr 4 | ||
val column = chunks[chunkX to chunkZ] ?: return null | ||
return column[x and 0xF, y, z and 0xF] | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
craftlib-protocol/src/main/kotlin/dev/zerite/craftlib/protocol/util/ext/ArrayExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
@file:JvmName("ArrayUtil") | ||
|
||
package dev.zerite.craftlib.protocol.util.ext | ||
|
||
import io.netty.buffer.Unpooled | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...t/kotlin/dev/zerite/craftlib/protocol/packet/play/server/world/ServerPlayChunkDataTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...otlin/dev/zerite/craftlib/protocol/packet/play/server/world/ServerPlayMapChunkBulkTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.