@@ -50,13 +50,15 @@ import net.minecraft.item.BlockItem
5050import net.minecraft.item.ItemPlacementContext
5151import net.minecraft.item.ItemStack
5252import net.minecraft.item.ItemUsageContext
53+ import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket
5354import net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket
5455import net.minecraft.registry.RegistryKeys
5556import net.minecraft.sound.SoundCategory
5657import net.minecraft.util.ActionResult
5758import net.minecraft.util.Hand
5859import net.minecraft.util.hit.BlockHitResult
5960import net.minecraft.util.math.BlockPos
61+ import net.minecraft.util.math.Direction
6062import net.minecraft.world.GameMode
6163
6264object PlaceManager : RequestHandler<PlaceRequest>(), PositionBlocking {
@@ -197,12 +199,10 @@ object PlaceManager : RequestHandler<PlaceRequest>(), PositionBlocking {
197199 return ActionResult .FAIL
198200 }
199201
200- // checks if the player should be able to interact with the block for if its something
201- // like a furnace or chest where an action would happen
202- // val actionResult = blockState.onUse(world, player, hand, hitResult)
203- // if (actionResult.isAccepted) {
204- // return actionResult
205- // }
202+ val actionResult = blockState.onUse(world, player, hand, hitResult)
203+ if (actionResult.isAccepted) {
204+ return actionResult
205+ }
206206 }
207207
208208 val itemStack = player.getStackInHand(hand)
@@ -261,12 +261,16 @@ object PlaceManager : RequestHandler<PlaceRequest>(), PositionBlocking {
261261 else
262262 pendingPlacements.add(request)
263263
264- interaction.sendSequencedPacket(world) { sequence: Int ->
265- PlayerInteractBlockC2SPacket (hand, hitResult, sequence)
264+ if (request.buildConfig.placeSettings.airPlace == PlaceConfig .AirPlaceMode .Grim ) {
265+ airPlaceOffhandSwap()
266+ sendPlacePacket(hand, hitResult)
267+ airPlaceOffhandSwap()
268+ } else {
269+ sendPlacePacket(hand, hitResult)
266270 }
267271
268272 if (request.buildConfig.placeSettings.swing) {
269- swingHand(request.buildConfig.placeSettings.swingType)
273+ swingHand(request.buildConfig.placeSettings.swingType, hand )
270274 }
271275
272276 if (! stackInHand.isEmpty && (stackInHand.count != stackCountPre || interaction.hasCreativeInventory())) {
@@ -296,6 +300,11 @@ object PlaceManager : RequestHandler<PlaceRequest>(), PositionBlocking {
296300 return ActionResult .success(world.isClient)
297301 }
298302
303+ private fun SafeContext.sendPlacePacket (hand : Hand , hitResult : BlockHitResult ) =
304+ interaction.sendSequencedPacket(world) { sequence: Int ->
305+ PlayerInteractBlockC2SPacket (hand, hitResult, sequence)
306+ }
307+
299308 private fun SafeContext.placeSound (item : BlockItem , state : BlockState , pos : BlockPos ) {
300309 val blockSoundGroup = state.soundGroup
301310 world.playSound(
@@ -308,6 +317,16 @@ object PlaceManager : RequestHandler<PlaceRequest>(), PositionBlocking {
308317 )
309318 }
310319
320+ private fun SafeContext.airPlaceOffhandSwap () {
321+ connection.sendPacket(
322+ PlayerActionC2SPacket (
323+ PlayerActionC2SPacket .Action .SWAP_ITEM_WITH_OFFHAND ,
324+ BlockPos .ORIGIN ,
325+ Direction .DOWN
326+ )
327+ )
328+ }
329+
311330 override fun preEvent () = UpdateManagerEvent .Place .Pre ().post()
312331 override fun postEvent () = UpdateManagerEvent .Place .Post ().post()
313332}
0 commit comments