mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 10:55:01 -04:00
honey collisions
This commit is contained in:
parent
60078b4e91
commit
c0a121eab5
@ -44,6 +44,7 @@ import de.bixilon.minosoft.gui.rendering.util.VecUtil.chunkPosition
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.clearZero
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.empty
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.get
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.inChunkPosition
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.plus
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import de.bixilon.minosoft.protocol.packets.c2s.play.*
|
||||
@ -355,6 +356,14 @@ class LocalPlayerEntity(
|
||||
|
||||
// ToDo: Check for move effect
|
||||
|
||||
// block collision handling
|
||||
val aabb = aabb.shrink(0.001)
|
||||
for (blockPosition in aabb.blockPositions) {
|
||||
val chunk = connection.world[blockPosition.chunkPosition] ?: continue
|
||||
val blockState = chunk[blockPosition.inChunkPosition] ?: continue
|
||||
blockState.block.onEntityCollision(connection, this, blockState, blockPosition)
|
||||
}
|
||||
|
||||
val velocityMultiplier = velocityMultiplier
|
||||
velocity.x *= velocityMultiplier
|
||||
velocity.z *= velocityMultiplier
|
||||
|
@ -109,6 +109,8 @@ open class Block(
|
||||
|
||||
open fun onEntityLand(connection: PlayConnection, entity: Entity, blockPosition: Vec3i, blockState: BlockState) {}
|
||||
|
||||
open fun onEntityCollision(connection: PlayConnection, entity: Entity, blockState: BlockState, blockPosition: Vec3i) {}
|
||||
|
||||
companion object : ResourceLocationDeserializer<Block> {
|
||||
private val CONSTRUCTORS: Map<String, (resourceLocation: ResourceLocation, registries: Registries, data: JsonObject) -> Block> = mapOf(
|
||||
"FluidBlock" to { resourceLocation, registries, data -> FluidBlock(resourceLocation, registries, data) },
|
||||
@ -125,6 +127,7 @@ open class Block(
|
||||
"EnderChestBlock" to { resourceLocation, registries, data -> EnderChestBlock(resourceLocation, registries, data) },
|
||||
"NetherPortalBlock" to { resourceLocation, registries, data -> NetherPortalBlock(resourceLocation, registries, data) },
|
||||
"RedstoneTorchBlock" to { resourceLocation, registries, data -> RedstoneTorchBlock(resourceLocation, registries, data) },
|
||||
"HoneyBlock" to { resourceLocation, registries, data -> HoneyBlock(resourceLocation, registries, data) },
|
||||
)
|
||||
|
||||
override fun deserialize(registries: Registries?, resourceLocation: ResourceLocation, data: JsonObject): Block {
|
||||
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2021 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.data.registries.blocks.types
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import de.bixilon.minosoft.data.entities.entities.Entity
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
import de.bixilon.minosoft.data.registries.blocks.BlockState
|
||||
import de.bixilon.minosoft.data.registries.versions.Registries
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import glm_.vec3.Vec3i
|
||||
import kotlin.math.abs
|
||||
|
||||
open class HoneyBlock(resourceLocation: ResourceLocation, registries: Registries, data: JsonObject) : Block(resourceLocation, registries, data) {
|
||||
|
||||
override fun onEntityCollision(connection: PlayConnection, entity: Entity, blockState: BlockState, blockPosition: Vec3i) {
|
||||
super.onEntityCollision(connection, entity, blockState, blockPosition)
|
||||
|
||||
if (isSliding(entity, blockPosition)) {
|
||||
if (entity.velocity.y < -0.13) {
|
||||
val horizontalMultiplier = -0.05 / entity.velocity.y
|
||||
entity.velocity.x *= horizontalMultiplier
|
||||
entity.velocity.z *= horizontalMultiplier
|
||||
}
|
||||
entity.velocity.y = -0.05
|
||||
}
|
||||
}
|
||||
|
||||
private fun isSliding(entity: Entity, blockPosition: Vec3i): Boolean {
|
||||
if (entity.onGround || (entity.position.y > blockPosition.y + 0.9375 - 1.0E-7) || entity.velocity.y >= -0.08) {
|
||||
return false
|
||||
}
|
||||
val x = abs(blockPosition.x + 0.5 - entity.position.x) + 1.0E-7
|
||||
val z = abs(blockPosition.z + 0.5 - entity.position.z) + 1.0E-7
|
||||
val minSize = 0.4375 + (entity.dimensions.x / 2.0)
|
||||
return x > minSize || z > minSize
|
||||
}
|
||||
}
|
||||
|
@ -109,8 +109,8 @@ class AABB(
|
||||
return this extend direction.vector
|
||||
}
|
||||
|
||||
infix fun grow(value: Double): AABB {
|
||||
return AABB(min - value, max + value)
|
||||
infix fun grow(size: Double): AABB {
|
||||
return AABB(min - size, max + size)
|
||||
}
|
||||
|
||||
fun computeOffset(other: AABB, offset: Double, axis: Axes): Double {
|
||||
|
Loading…
x
Reference in New Issue
Block a user