mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-30 21:17:53 +01:00
Add BlockHandler.PlayerPlacement#getHand
This commit is contained in:
parent
ae04ca5574
commit
e99d8c6a6f
@ -139,8 +139,7 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public abstract boolean placeBlock(@NotNull Player player, @NotNull Block block, @NotNull Point blockPosition,
|
||||
@NotNull BlockFace blockFace, float cursorX, float cursorY, float cursorZ);
|
||||
public abstract boolean placeBlock(@NotNull BlockHandler.Placement placement);
|
||||
|
||||
/**
|
||||
* Does call {@link net.minestom.server.event.player.PlayerBlockBreakEvent}
|
||||
|
@ -13,7 +13,6 @@ import net.minestom.server.event.instance.InstanceChunkUnloadEvent;
|
||||
import net.minestom.server.event.player.PlayerBlockBreakEvent;
|
||||
import net.minestom.server.instance.batch.ChunkGenerationBatch;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.instance.block.BlockFace;
|
||||
import net.minestom.server.instance.block.BlockHandler;
|
||||
import net.minestom.server.instance.block.rule.BlockPlacementRule;
|
||||
import net.minestom.server.network.packet.server.play.BlockChangePacket;
|
||||
@ -154,12 +153,12 @@ public class InstanceContainer extends Instance {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeBlock(@NotNull Player player, @NotNull Block block, @NotNull Point blockPosition,
|
||||
@NotNull BlockFace blockFace, float cursorX, float cursorY, float cursorZ) {
|
||||
public boolean placeBlock(@NotNull BlockHandler.Placement placement) {
|
||||
final Point blockPosition = placement.getBlockPosition();
|
||||
final Chunk chunk = getChunkAt(blockPosition);
|
||||
if (!ChunkUtils.isLoaded(chunk)) return false;
|
||||
UNSAFE_setBlock(chunk, blockPosition.blockX(), blockPosition.blockY(), blockPosition.blockZ(), block,
|
||||
new BlockHandler.PlayerPlacement(block, this, blockPosition, player, blockFace, cursorX, cursorY, cursorZ), null);
|
||||
UNSAFE_setBlock(chunk, blockPosition.blockX(), blockPosition.blockY(), blockPosition.blockZ(),
|
||||
placement.getBlock(), placement, null);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@ package net.minestom.server.instance;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.instance.block.BlockFace;
|
||||
import net.minestom.server.instance.block.BlockHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -28,9 +28,8 @@ public class SharedInstance extends Instance {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeBlock(@NotNull Player player, @NotNull Block block, @NotNull Point blockPosition,
|
||||
@NotNull BlockFace blockFace, float cursorX, float cursorY, float cursorZ) {
|
||||
return instanceContainer.placeBlock(player, block, blockPosition, blockFace, cursorX, cursorY, cursorZ);
|
||||
public boolean placeBlock(@NotNull BlockHandler.Placement placement) {
|
||||
return instanceContainer.placeBlock(placement);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -114,14 +114,16 @@ public interface BlockHandler {
|
||||
|
||||
final class PlayerPlacement extends Placement {
|
||||
private final Player player;
|
||||
private final Player.Hand hand;
|
||||
private final BlockFace blockFace;
|
||||
private final float cursorX, cursorY, cursorZ;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public PlayerPlacement(Block block, Instance instance, Point blockPosition,
|
||||
Player player, BlockFace blockFace, float cursorX, float cursorY, float cursorZ) {
|
||||
Player player, Player.Hand hand, BlockFace blockFace, float cursorX, float cursorY, float cursorZ) {
|
||||
super(block, instance, blockPosition);
|
||||
this.player = player;
|
||||
this.hand = hand;
|
||||
this.blockFace = blockFace;
|
||||
this.cursorX = cursorX;
|
||||
this.cursorY = cursorY;
|
||||
@ -132,6 +134,10 @@ public interface BlockHandler {
|
||||
return player;
|
||||
}
|
||||
|
||||
public @NotNull Player.Hand getHand() {
|
||||
return hand;
|
||||
}
|
||||
|
||||
public @NotNull BlockFace getBlockFace() {
|
||||
return blockFace;
|
||||
}
|
||||
|
@ -157,8 +157,8 @@ public class BlockPlacementListener {
|
||||
return;
|
||||
}
|
||||
// Place the block
|
||||
instance.placeBlock(player, resultBlock, placementPosition,
|
||||
blockFace, packet.cursorPositionX, packet.cursorPositionY, packet.cursorPositionZ);
|
||||
instance.placeBlock(new BlockHandler.PlayerPlacement(resultBlock, instance, blockPosition, player, hand, blockFace,
|
||||
packet.cursorPositionX, packet.cursorPositionY, packet.cursorPositionZ));
|
||||
// Block consuming
|
||||
if (playerBlockPlaceEvent.doesConsumeBlock()) {
|
||||
// Consume the block in the player's hand
|
||||
|
Loading…
Reference in New Issue
Block a user