Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed Jun 30, 2024
2 parents baca231 + ab67837 commit 01c7244
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.UnmodifiableView;
import org.joml.Vector3ic;

import java.util.Map;

Expand Down Expand Up @@ -133,7 +134,11 @@ default void setAction(boolean value) {

void showForm(Form form);

default boolean canInteract(float x, float y, float z) {
default boolean canReach(Vector3ic pos) {
return canReach(pos.x(), pos.y(), pos.z());
}

default boolean canReach(float x, float y, float z) {
var maxDistance = getMaxInteractDistance();
var location = getLocation();
if (location.distanceSquared(x, y, z) > maxDistance * maxDistance) return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.allaymc.api.container.FullContainerType;
import org.allaymc.api.entity.interfaces.EntityPlayer;
import org.allaymc.api.item.registry.CreativeItemRegistry;
import org.cloudburstmc.protocol.bedrock.data.GameType;
import org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.action.CraftCreativeAction;
import org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.action.ItemStackRequestAction;
import org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.action.ItemStackRequestActionType;
Expand All @@ -19,6 +20,9 @@
public class CraftCreativeActionProcessor implements ContainerActionProcessor<CraftCreativeAction> {
@Override
public ActionResponse handle(CraftCreativeAction action, EntityPlayer player, int currentActionIndex, ItemStackRequestAction[] actions, Map<Object, Object> dataPool) {
if (player.getGameType() != GameType.CREATIVE || player.getGameType() != GameType.SPECTATOR)
return error();

var item = CreativeItemRegistry.getRegistry().get(action.getCreativeItemNetworkId() - 1);
if (item == null) {
log.warn("Unknown creative item network id: {}", action.getCreativeItemNetworkId() - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.allaymc.api.container.FullContainerType;
import org.allaymc.api.entity.interfaces.EntityPlayer;
import org.allaymc.api.network.processor.PacketProcessor;
import org.allaymc.api.utils.MathUtils;
import org.cloudburstmc.protocol.bedrock.data.GameType;
import org.cloudburstmc.protocol.bedrock.packet.BedrockPacketType;
import org.cloudburstmc.protocol.bedrock.packet.BlockPickRequestPacket;
Expand All @@ -18,15 +19,10 @@
public class BlockPickRequestPacketProcessor extends PacketProcessor<BlockPickRequestPacket> {
@Override
public void handleSync(EntityPlayer player, BlockPickRequestPacket packet) {
if (player.getGameType() != GameType.CREATIVE) {
log.warn("Player {} tried to pick block in non-creative mode!", player.getOriginName());
return;
}
var blockPos = MathUtils.CBVecToJOMLVec(packet.getBlockPosition());
if (!player.canReach(blockPos) || player.getGameType() != GameType.CREATIVE) return;

var pos = packet.getBlockPosition();
// TODO: includeBlockEntityData
var includeBlockEntityData = packet.isAddUserData();
var block = player.getLocation().dimension().getBlockState(pos.getX(), pos.getY(), pos.getZ());
var block = player.getLocation().dimension().getBlockState(blockPos);
if (block.getBlockType() == BlockTypes.AIR_TYPE) {
log.warn("Player {} tried to pick air!", player.getOriginName());
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,12 @@ protected void handleMovement(EntityPlayer player, Vector3f newPos, Vector3f new
}

protected void handleBlockAction(EntityPlayer player, List<PlayerBlockActionData> blockActions) {
if (blockActions.isEmpty()) return;
for (var action : blockActions) {
var pos = action.getBlockPosition();
// Check interact distance
switch (action.getAction()) {
case START_BREAK, BLOCK_CONTINUE_DESTROY -> {
if (!player.canInteract(pos.getX(), pos.getY(), pos.getZ())) {
if (!player.canReach(pos.getX(), pos.getY(), pos.getZ())) {
log.warn("Player {} tried to break a block out of reach", player.getOriginName());
continue;
}
Expand Down Expand Up @@ -202,7 +201,7 @@ protected void sendBreakingPracticeAndTime(EntityPlayer player) {
}

protected void checkInteractDistance(EntityPlayer player) {
if (!player.canInteract(breakBlockX, breakBlockY, breakBlockZ)) {
if (!player.canReach(breakBlockX, breakBlockY, breakBlockZ)) {
log.warn("Player {} tried to interact with a block out of reach", player.getOriginName());
stopBreak(player);
}
Expand Down

0 comments on commit 01c7244

Please sign in to comment.