mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 02:15:34 -04:00
bump pixlyzer, wip: real block breaking
This commit is contained in:
parent
3b26669b5b
commit
bf66039ca0
@ -45,6 +45,8 @@ data class BlockState(
|
|||||||
val collisionShape: VoxelShape,
|
val collisionShape: VoxelShape,
|
||||||
val occlusionShape: VoxelShape,
|
val occlusionShape: VoxelShape,
|
||||||
val outlineShape: VoxelShape,
|
val outlineShape: VoxelShape,
|
||||||
|
val hardness: Float,
|
||||||
|
val requiresTool: Boolean,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
@ -116,7 +118,7 @@ data class BlockState(
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun deserialize(owner: Block, registries: Registries, data: JsonObject, models: Map<ResourceLocation, BlockModel>): BlockState {
|
fun deserialize(block: Block, registries: Registries, data: JsonObject, models: Map<ResourceLocation, BlockModel>): BlockState {
|
||||||
val properties = data["properties"]?.asJsonObject?.let {
|
val properties = data["properties"]?.asJsonObject?.let {
|
||||||
getProperties(it)
|
getProperties(it)
|
||||||
} ?: mutableMapOf()
|
} ?: mutableMapOf()
|
||||||
@ -149,7 +151,7 @@ data class BlockState(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val tintColor: RGBColor? = data["tint_color"]?.asInt?.let { TintColorCalculator.getJsonColor(it) } ?: owner.tintColor
|
val tintColor: RGBColor? = data["tint_color"]?.asInt?.let { TintColorCalculator.getJsonColor(it) } ?: block.tintColor
|
||||||
|
|
||||||
|
|
||||||
val material = registries.materialRegistry[ResourceLocation(data["material"].asString)]!!
|
val material = registries.materialRegistry[ResourceLocation(data["material"].asString)]!!
|
||||||
@ -173,13 +175,13 @@ data class BlockState(
|
|||||||
val occlusionShape = data["occlusion_shapes"]?.asShape() ?: VoxelShape.EMPTY
|
val occlusionShape = data["occlusion_shapes"]?.asShape() ?: VoxelShape.EMPTY
|
||||||
val outlineShape = data["outline_shape"]?.asShape() ?: VoxelShape.EMPTY
|
val outlineShape = data["outline_shape"]?.asShape() ?: VoxelShape.EMPTY
|
||||||
|
|
||||||
owner.renderOverride?.let {
|
block.renderOverride?.let {
|
||||||
renderers.clear()
|
renderers.clear()
|
||||||
renderers.addAll(it)
|
renderers.addAll(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
return BlockState(
|
return BlockState(
|
||||||
block = owner,
|
block = block,
|
||||||
properties = properties.toMap(),
|
properties = properties.toMap(),
|
||||||
renderers = renderers,
|
renderers = renderers,
|
||||||
tintColor = tintColor,
|
tintColor = tintColor,
|
||||||
@ -187,6 +189,8 @@ data class BlockState(
|
|||||||
collisionShape = collisionShape,
|
collisionShape = collisionShape,
|
||||||
occlusionShape = occlusionShape,
|
occlusionShape = occlusionShape,
|
||||||
outlineShape = outlineShape,
|
outlineShape = outlineShape,
|
||||||
|
hardness = data["hardness"].asFloat,
|
||||||
|
requiresTool = data["requires_tool"]?.asBoolean ?: material.soft,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,6 @@ open class Block(
|
|||||||
mappings: Registries,
|
mappings: Registries,
|
||||||
data: JsonObject,
|
data: JsonObject,
|
||||||
) : RegistryItem {
|
) : RegistryItem {
|
||||||
open val hardness: Float = data["hardness"]?.asFloat ?: 0.0f
|
|
||||||
open val explosionResistance: Float = data["explosion_resistance"]?.asFloat ?: 0.0f
|
open val explosionResistance: Float = data["explosion_resistance"]?.asFloat ?: 0.0f
|
||||||
open val tintColor: RGBColor? = data["tint_color"]?.asInt?.let { TintColorCalculator.getJsonColor(it) }
|
open val tintColor: RGBColor? = data["tint_color"]?.asInt?.let { TintColorCalculator.getJsonColor(it) }
|
||||||
open val randomOffsetType: RandomOffsetTypes? = data["offset_type"]?.asString?.let { RandomOffsetTypes[it] }
|
open val randomOffsetType: RandomOffsetTypes? = data["offset_type"]?.asString?.let { RandomOffsetTypes[it] }
|
||||||
|
@ -28,6 +28,7 @@ data class Material(
|
|||||||
val blockMotion: Boolean,
|
val blockMotion: Boolean,
|
||||||
val flammable: Boolean,
|
val flammable: Boolean,
|
||||||
val liquid: Boolean,
|
val liquid: Boolean,
|
||||||
|
val soft: Boolean,
|
||||||
val solidBlocking: Boolean,
|
val solidBlocking: Boolean,
|
||||||
val replaceable: Boolean,
|
val replaceable: Boolean,
|
||||||
val solid: Boolean,
|
val solid: Boolean,
|
||||||
@ -46,6 +47,7 @@ data class Material(
|
|||||||
blockMotion = data["blocks_motion"]?.asBoolean ?: false,
|
blockMotion = data["blocks_motion"]?.asBoolean ?: false,
|
||||||
flammable = data["flammable"]?.asBoolean ?: false,
|
flammable = data["flammable"]?.asBoolean ?: false,
|
||||||
liquid = data["liquid"]?.asBoolean ?: false,
|
liquid = data["liquid"]?.asBoolean ?: false,
|
||||||
|
soft = data["is_soft"]?.asBoolean ?: false,
|
||||||
solidBlocking = data["solid_blocking"]?.asBoolean ?: false,
|
solidBlocking = data["solid_blocking"]?.asBoolean ?: false,
|
||||||
replaceable = data["replaceable"]?.asBoolean ?: false,
|
replaceable = data["replaceable"]?.asBoolean ?: false,
|
||||||
solid = data["solid"]?.asBoolean ?: false,
|
solid = data["solid"]?.asBoolean ?: false,
|
||||||
|
@ -64,9 +64,9 @@ class RenderWindow(
|
|||||||
val inputHandler = RenderWindowInputHandler(this)
|
val inputHandler = RenderWindowInputHandler(this)
|
||||||
|
|
||||||
var windowId = 0L
|
var windowId = 0L
|
||||||
private var deltaFrameTime = 0L
|
private var deltaFrameTime = 0.0
|
||||||
|
|
||||||
private var lastFrame = 0L
|
private var lastFrame = 0.0
|
||||||
private val latch = CountUpAndDownLatch(1)
|
private val latch = CountUpAndDownLatch(1)
|
||||||
|
|
||||||
private var renderingState = RenderingStates.RUNNING
|
private var renderingState = RenderingStates.RUNNING
|
||||||
@ -312,7 +312,7 @@ class RenderWindow(
|
|||||||
this.lastTickTimer = currentTickTime
|
this.lastTickTimer = currentTickTime
|
||||||
}
|
}
|
||||||
|
|
||||||
val currentFrame = System.currentTimeMillis()
|
val currentFrame = glfwGetTime()
|
||||||
deltaFrameTime = currentFrame - lastFrame
|
deltaFrameTime = currentFrame - lastFrame
|
||||||
lastFrame = currentFrame
|
lastFrame = currentFrame
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ class LeftClickHandler(
|
|||||||
|
|
||||||
private var breakPosition: Vec3i? = null
|
private var breakPosition: Vec3i? = null
|
||||||
private var breakBlockState: BlockState? = null
|
private var breakBlockState: BlockState? = null
|
||||||
private var breakProgress: Float = -1.0f
|
private var breakProgress = -1.0
|
||||||
|
|
||||||
private var breakSelectedSlot: Int = -1
|
private var breakSelectedSlot: Int = -1
|
||||||
private var breakItemInHand: ItemStack? = null
|
private var breakItemInHand: ItemStack? = null
|
||||||
@ -45,7 +45,7 @@ class LeftClickHandler(
|
|||||||
private fun clearDigging() {
|
private fun clearDigging() {
|
||||||
breakPosition = null
|
breakPosition = null
|
||||||
breakBlockState = null
|
breakBlockState = null
|
||||||
breakProgress = -1.0f
|
breakProgress = -1.0
|
||||||
|
|
||||||
breakSelectedSlot = -1
|
breakSelectedSlot = -1
|
||||||
breakItemInHand = null
|
breakItemInHand = null
|
||||||
@ -58,7 +58,16 @@ class LeftClickHandler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkBreaking(isKeyDown: Boolean, deltaTime: Long): Boolean {
|
private fun swingArm() {
|
||||||
|
val currentTime = System.currentTimeMillis()
|
||||||
|
if (currentTime - lastSwing <= ProtocolDefinition.TICK_TIME) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
lastSwing = currentTime
|
||||||
|
connection.sendPacket(ArmSwingC2SP(Hands.MAIN_HAND))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun checkBreaking(isKeyDown: Boolean, deltaTime: Double): Boolean {
|
||||||
val currentTime = System.currentTimeMillis()
|
val currentTime = System.currentTimeMillis()
|
||||||
|
|
||||||
if (!isKeyDown) {
|
if (!isKeyDown) {
|
||||||
@ -97,7 +106,7 @@ class LeftClickHandler(
|
|||||||
|
|
||||||
breakPosition = raycastHit.blockPosition
|
breakPosition = raycastHit.blockPosition
|
||||||
breakBlockState = raycastHit.blockState
|
breakBlockState = raycastHit.blockState
|
||||||
breakProgress = 0.0f
|
breakProgress = 0.0
|
||||||
|
|
||||||
breakSelectedSlot = connection.player.selectedHotbarSlot
|
breakSelectedSlot = connection.player.selectedHotbarSlot
|
||||||
breakItemInHand = connection.player.inventory.getHotbarSlot()
|
breakItemInHand = connection.player.inventory.getHotbarSlot()
|
||||||
@ -109,29 +118,62 @@ class LeftClickHandler(
|
|||||||
connection.world.setBlockState(raycastHit.blockPosition, null)
|
connection.world.setBlockState(raycastHit.blockPosition, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentTime - breakSent <= ProtocolDefinition.TICK_TIME) {
|
val canStartBreaking = currentTime - breakSent >= ProtocolDefinition.TICK_TIME
|
||||||
return true
|
|
||||||
}
|
|
||||||
breakSent = currentTime
|
|
||||||
|
|
||||||
val canInstantBreak = connection.player.baseAbilities.canInstantBreak || connection.player.entity.gamemode == Gamemodes.CREATIVE
|
val canInstantBreak = connection.player.baseAbilities.canInstantBreak || connection.player.entity.gamemode == Gamemodes.CREATIVE
|
||||||
|
|
||||||
if (canInstantBreak) {
|
if (canInstantBreak) {
|
||||||
|
if (!canStartBreaking) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
// creative
|
// creative
|
||||||
if (currentTime - creativeLastHoldBreakTime <= ProtocolDefinition.TICK_TIME * 5) {
|
if (currentTime - creativeLastHoldBreakTime <= ProtocolDefinition.TICK_TIME * 5) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
connection.sendPacket(ArmSwingC2SP(Hands.MAIN_HAND))
|
swingArm()
|
||||||
startDigging()
|
startDigging()
|
||||||
finishDigging()
|
finishDigging()
|
||||||
creativeLastHoldBreakTime = currentTime
|
creativeLastHoldBreakTime = currentTime
|
||||||
|
breakSent = currentTime
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
startDigging()
|
if (breakPosition == null && !canStartBreaking) {
|
||||||
connection.sendPacket(ArmSwingC2SP(Hands.MAIN_HAND))
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
breakProgress += 0.05f
|
breakSent = currentTime
|
||||||
|
|
||||||
|
startDigging()
|
||||||
|
|
||||||
|
swingArm()
|
||||||
|
|
||||||
|
|
||||||
|
var speedMultiplier = 1.0f
|
||||||
|
|
||||||
|
var damage = speedMultiplier / raycastHit.blockState.hardness
|
||||||
|
|
||||||
|
damage /= if (raycastHit.blockState.requiresTool) {
|
||||||
|
100
|
||||||
|
} else {
|
||||||
|
30
|
||||||
|
}
|
||||||
|
|
||||||
|
when {
|
||||||
|
damage > 1.0f -> {
|
||||||
|
breakProgress = 1.0
|
||||||
|
}
|
||||||
|
damage <= 0.0f -> {
|
||||||
|
breakProgress = 0.0
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
val ticks = 1.0f / damage
|
||||||
|
val seconds = (ticks / ProtocolDefinition.TICKS_PER_SECOND)
|
||||||
|
val progress = ((1.0f / seconds) * deltaTime)
|
||||||
|
breakProgress += progress
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (breakProgress >= 1.0f) {
|
if (breakProgress >= 1.0f) {
|
||||||
finishDigging()
|
finishDigging()
|
||||||
@ -143,8 +185,7 @@ class LeftClickHandler(
|
|||||||
renderWindow.inputHandler.registerCheckCallback(KeyBindingsNames.DESTROY_BLOCK)
|
renderWindow.inputHandler.registerCheckCallback(KeyBindingsNames.DESTROY_BLOCK)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun draw(deltaTime: Long) {
|
fun draw(deltaTime: Double) {
|
||||||
val currentTime = System.currentTimeMillis()
|
|
||||||
val isKeyDown = renderWindow.inputHandler.isKeyBindingDown(KeyBindingsNames.DESTROY_BLOCK)
|
val isKeyDown = renderWindow.inputHandler.isKeyBindingDown(KeyBindingsNames.DESTROY_BLOCK)
|
||||||
// ToDo: Entity attacking
|
// ToDo: Entity attacking
|
||||||
val consumed = checkBreaking(isKeyDown, deltaTime)
|
val consumed = checkBreaking(isKeyDown, deltaTime)
|
||||||
@ -155,10 +196,6 @@ class LeftClickHandler(
|
|||||||
if (consumed) {
|
if (consumed) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (currentTime - lastSwing <= ProtocolDefinition.TICK_TIME) {
|
swingArm()
|
||||||
return
|
|
||||||
}
|
|
||||||
connection.sendPacket(ArmSwingC2SP(Hands.MAIN_HAND))
|
|
||||||
lastSwing = currentTime
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ class RightClickHandler(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun draw(deltaTime: Long) {
|
fun draw(deltaTime: Double) {
|
||||||
// ToDo: Entity interaction, shield/sword blocking, etc
|
// ToDo: Entity interaction, shield/sword blocking, etc
|
||||||
checkInteraction(renderWindow.inputHandler.isKeyBindingDown(KeyBindingsNames.BLOCK_INTERACT))
|
checkInteraction(renderWindow.inputHandler.isKeyBindingDown(KeyBindingsNames.BLOCK_INTERACT))
|
||||||
}
|
}
|
||||||
|
@ -211,7 +211,7 @@ class Camera(
|
|||||||
sendPositionToServer()
|
sendPositionToServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun draw(deltaTime: Long) {
|
fun draw(deltaTime: Double) {
|
||||||
if (!currentPositionSent || !currentRotationSent) {
|
if (!currentPositionSent || !currentRotationSent) {
|
||||||
recalculateViewProjectionMatrix()
|
recalculateViewProjectionMatrix()
|
||||||
sendPositionToServer()
|
sendPositionToServer()
|
||||||
@ -224,7 +224,7 @@ class Camera(
|
|||||||
flyingSpeed
|
flyingSpeed
|
||||||
} else {
|
} else {
|
||||||
walkingSpeed
|
walkingSpeed
|
||||||
} * (deltaTime / 1000.0)
|
} * deltaTime
|
||||||
val movementFront = Vec3(cameraFront)
|
val movementFront = Vec3(cameraFront)
|
||||||
if (!Minosoft.getConfig().config.game.camera.noCipMovement) {
|
if (!Minosoft.getConfig().config.game.camera.noCipMovement) {
|
||||||
movementFront.y = 0.0f
|
movementFront.y = 0.0f
|
||||||
|
@ -276,7 +276,7 @@ class RenderWindowInputHandler(
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun draw(delta: Long) {
|
fun draw(delta: Double) {
|
||||||
camera.draw(delta)
|
camera.draw(delta)
|
||||||
leftClickHandler.draw(delta)
|
leftClickHandler.draw(delta)
|
||||||
rightClickHandler.draw(delta)
|
rightClickHandler.draw(delta)
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user