Skip to content

zaapr0x/mc-hook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mc-hook


An Utility Tool For Minecraft Bedrock Sripting!

This project contains three utility modules for Minecraft Bedrock scripting using the @minecraft/server and @minecraft/server-net APIs:

  • Block Break Event Listener
  • Item Pickup Tracker
  • HTTP Request Utility

📁 Contents


Installation

Go to you behaviour folder and run this command

npx mc-hook@latest init
or
pnpm dlx mc-hook@latest init

Block Break Events

File: api/events/blockBreak.js

Use this module to register callbacks when a player breaks a block.

Example

import blockBreak from "./api/events/blockBreak.js";

blockBreak.listen((data, actions) => {
  const { player, blockId, location, toolTypeId } = data;

  console.log(`${player.name} broke a ${blockId} using ${toolTypeId}`);

  // Restore the block
  actions.restore();
});

Event Data

Property Description
player The player who broke the block
blockId ID of the block broken
location Location of the block
dimension Dimension in which block exists
toolTypeId Type ID of the tool used

Actions

  • restore() – Restores the block at the location.

Item Pickup Events

File: api/events/itemPickup.js

Use this module to track when a player picks up items (based on inventory changes).

Example

import itemPickup from "./api/events/itemPickup.js";

itemPickup.listen((data, actions) => {
  const { player, typeId, amount } = data;

  console.log(`${player.name} picked up ${amount}x ${typeId}`);

  // Optionally remove items
  actions.remove();
}, 20); // Check every 20 ticks

Parameters

  • callback – Function called on item pickup.
  • tick – Interval in ticks to check inventories (default: 10).

Event Data

Property Description
player Player who picked up the item
typeId The item type ID
amount Number of items picked up

Actions

  • remove() – Removes the picked-up items from the inventory.

🌐 HTTP Requests

File: api/lib/httpReq.js

A wrapper for making HTTP requests using @minecraft/server-net.

Important

This Script Only Works On Server Side, If You Running On Client Side It will be error! Read More

Example – GET

import httpReq from "./api/lib/httpReq.js";

httpReq
  .get("https://api.example.com/data")
  .then((response) => {
    console.log("Status:", response.status);
    console.log("Data:", response.data);
  })
  .catch((err) => console.error("Request failed:", err.message));

Example – POST

httpReq
  .post("https://api.example.com/post", { key: "value" })
  .then((res) => console.log(res.data))
  .catch((err) => console.error(err.message));

Supported Methods

  • httpReq.get(url, config)
  • httpReq.post(url, body, config)
  • httpReq.put(url, body, config)
  • httpReq.delete(url, config)
  • httpReq.head(url, config)

Response Object

Property Description
status HTTP status code
data Parsed response body (if JSON)
headers Response headers

About

An Utility Tool For Minecraft Bedrock Scripting!

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published