Noteblocks, Fix sending block interactions to server

This commit is contained in:
Bixilon 2021-05-24 23:48:08 +02:00
parent b4d04229ff
commit ed06322f07
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 41 additions and 5 deletions

View File

@ -103,6 +103,7 @@ open class Block(
"FluidBlock" -> FluidBlock(resourceLocation, mappings, data) "FluidBlock" -> FluidBlock(resourceLocation, mappings, data)
"DoorBlock" -> DoorBlock(resourceLocation, mappings, data) "DoorBlock" -> DoorBlock(resourceLocation, mappings, data)
"LeverBlock" -> LeverBlock(resourceLocation, mappings, data) "LeverBlock" -> LeverBlock(resourceLocation, mappings, data)
"NoteBlock" -> NoteBlock(resourceLocation, mappings, data)
else -> Block(resourceLocation, mappings, data) else -> Block(resourceLocation, mappings, data)
} }

View File

@ -0,0 +1,33 @@
/*
* 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.mappings.blocks.types
import com.google.gson.JsonObject
import de.bixilon.minosoft.data.inventory.ItemStack
import de.bixilon.minosoft.data.mappings.ResourceLocation
import de.bixilon.minosoft.data.mappings.blocks.BlockState
import de.bixilon.minosoft.data.mappings.blocks.BlockUsages
import de.bixilon.minosoft.data.mappings.versions.Registries
import de.bixilon.minosoft.data.player.Hands
import de.bixilon.minosoft.gui.rendering.input.camera.RaycastHit
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
import glm_.vec3.Vec3i
open class NoteBlock(resourceLocation: ResourceLocation, mappings: Registries, data: JsonObject) : Block(resourceLocation, mappings, data) {
override fun use(connection: PlayConnection, blockState: BlockState, blockPosition: Vec3i, raycastHit: RaycastHit, hands: Hands, itemStack: ItemStack?): BlockUsages {
return BlockUsages.SUCCESS
}
}

View File

@ -57,16 +57,18 @@ class RightClickHandler(
raycastHit.blockState.block.use(renderWindow.connection, raycastHit.blockState, raycastHit.blockPosition, raycastHit, Hands.MAIN_HAND, itemInHand) raycastHit.blockState.block.use(renderWindow.connection, raycastHit.blockState, raycastHit.blockPosition, raycastHit, Hands.MAIN_HAND, itemInHand)
} }
if (currentTime - lastInteractionSent < ProtocolDefinition.TICK_TIME) {
return
}
lastInteractionSent = currentTime lastInteractionSent = currentTime
lastInteraction = currentTime lastInteraction = currentTime
when (usage) { when (usage) {
BlockUsages.SUCCESS -> { BlockUsages.CONSUME, BlockUsages.SUCCESS -> {
if (currentTime - lastInteractionSent < ProtocolDefinition.TICK_TIME) { if (usage == BlockUsages.SUCCESS) {
return connection.sendPacket(ArmSwingC2SP(Hands.MAIN_HAND))
} }
connection.sendPacket(ArmSwingC2SP(Hands.MAIN_HAND))
connection.sendPacket(BlockPlaceC2SP( connection.sendPacket(BlockPlaceC2SP(
position = raycastHit.blockPosition, position = raycastHit.blockPosition,
direction = raycastHit.hitDirection, direction = raycastHit.hitDirection,