Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

LiquidBounce Forum

  1. Home
  2. Resources
  3. Scripts
  4. [Script] PearlBlockThrow ?

[Script] PearlBlockThrow ?

Scheduled Pinned Locked Moved Unsolved Scripts
3 Posts 3 Posters 3.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Q13
    wrote on last edited by
    #1

    who can implement a script that allows the use of pearls where prohibited?
    ThunderHack-Recode/src

    1 Reply Last reply
    0
    • C Offline
      C Offline
      commandblock2
      wrote on last edited by commandblock2
      #2

      This is a somewhat faithful transplation of the original source code, which would not work on 1.8.x, this should desync your inventory too.

      
      function __require(path) {
          if (path.startsWith("@embedded")) {
              return globalThis
          }
      
          if (path.startsWith("@minecraft-yarn-definitions/types/")) {
              return {
                  [path.substring(path.lastIndexOf("/") + 1)]: Java.type(path
                      .replaceAll("@minecraft-yarn-definitions/types/", "")
                      .replaceAll("/", ".")
                  )
              }
          }
          return require(path);
      }
      var exports = {}
      
      "use strict";
      Object.defineProperty(exports, "__esModule", { value: true });
      // imports
      /* eslint-disable unused-imports/no-unused-imports */
      const _embedded_1 = __require("@embedded");
      /* eslint-enable unused-imports/no-unused-imports */
      // DO NOT TOUCH ANYTHING ABOVE THIS LINE, also not sure why it didn't work
      const PlayerInteractItemC2SPacket_1 = __require("@minecraft-yarn-definitions/types/net/minecraft/network/packet/c2s/play/PlayerInteractItemC2SPacket");
      const UpdateSelectedSlotC2SPacket_1 = __require("@minecraft-yarn-definitions/types/net/minecraft/network/packet/c2s/play/UpdateSelectedSlotC2SPacket");
      const UpdateSelectedSlotS2CPacket_1 = __require("@minecraft-yarn-definitions/types/net/minecraft/network/packet/s2c/play/UpdateSelectedSlotS2CPacket");
      const Items_1 = __require("@minecraft-yarn-definitions/types/net/minecraft/item/Items");
      const Hand_1 = __require("@minecraft-yarn-definitions/types/net/minecraft/util/Hand");
      const script = _embedded_1.registerScript.apply({
          name: "no-pearl-use",
          version: "1.0.0",
          authors: ["commandblock2"]
      });
      script.registerModule({
          name: "no-pearl-use",
          description: "cancels ender pearl use",
          category: "Player",
      }, (mod) => {
          var slot = 0;
          mod.on("enable", () => {
              var _a, _b;
              slot = (_b = (_a = _embedded_1.mc.player) === null || _a === void 0 ? void 0 : _a.inventory.selectedSlot) !== null && _b !== void 0 ? _b : 0;
          });
          mod.on("packet", (event) => {
              var _a;
              if (event.packet instanceof UpdateSelectedSlotS2CPacket_1.UpdateSelectedSlotS2CPacket) {
                  slot = event.packet.slot();
              }
              if (event.packet instanceof UpdateSelectedSlotC2SPacket_1.UpdateSelectedSlotC2SPacket) {
                  slot = event.packet.selectedSlot;
              }
              if (event.packet instanceof PlayerInteractItemC2SPacket_1.PlayerInteractItemC2SPacket &&
                  ((_a = _embedded_1.mc.player) === null || _a === void 0 ? void 0 : _a.inventory.main[slot].item) == Items_1.Items.ENDER_PEARL) {
                  // use reflection to set the hand to offhand
                  const field = event.packet.class.getDeclaredField("hand");
                  field.setAccessible(true);
                  field.set(event.packet, Hand_1.Hand.OFF_HAND);
                  _embedded_1.Client.displayChatMessage(`§cPearl use changed to hand ${event.packet.hand}`);
              }
          });
      });
      

      original typescript code

      // imports
      /* eslint-disable unused-imports/no-unused-imports */
      import {
          Setting,
          Vec3i,
          Vec3d,
          MathHelper,
          BlockPos,
          Hand,
          RotationAxis,
          mc,
          Client,
          RotationUtil,
          ItemUtil,
          NetworkUtil,
          InteractionUtil,
          BlockUtil,
          MovementUtil,
          ReflectionUtil,
          ParameterValidator,
          UnsafeThread,
          registerScript
      } from "@embedded";
      /* eslint-enable unused-imports/no-unused-imports */
      // DO NOT TOUCH ANYTHING ABOVE THIS LINE, also not sure why it didn't work
      
      import { PlayerInteractItemC2SPacket } from "@minecraft-yarn-definitions/types/net/minecraft/network/packet/c2s/play/PlayerInteractItemC2SPacket";
      import { UpdateSelectedSlotC2SPacket } from "@minecraft-yarn-definitions/types/net/minecraft/network/packet/c2s/play/UpdateSelectedSlotC2SPacket";
      import { UpdateSelectedSlotS2CPacket } from "@minecraft-yarn-definitions/types/net/minecraft/network/packet/s2c/play/UpdateSelectedSlotS2CPacket";
      import { Items } from "@minecraft-yarn-definitions/types/net/minecraft/item/Items";
      import { Hand as MCHand } from "@minecraft-yarn-definitions/types/net/minecraft/util/Hand";
      
      const script = registerScript.apply({
          name: "no-pearl-use",
          version: "1.0.0",
          authors: ["commandblock2"]
      });
      
      script.registerModule({
          name: "no-pearl-use",
          description: "cancels ender pearl use", 
          category: "Player",
      }, (mod) => {
      
          var slot = 0
      
          mod.on("enable", () => {
              slot = mc.player?.inventory.selectedSlot ?? 0;
          })
      
          mod.on("packet", (event) => {
      
              if (event.packet instanceof UpdateSelectedSlotS2CPacket) {
                  slot = event.packet.slot();
              }
      
              if (event.packet instanceof UpdateSelectedSlotC2SPacket) {
                  slot = event.packet.selectedSlot;
              }
      
      
              if (event.packet instanceof PlayerInteractItemC2SPacket &&
                  mc.player?.inventory.main[slot].item == Items.ENDER_PEARL
              ) {
                  // use reflection to set the hand to offhand
                  const field = (event.packet as any).class.getDeclaredField("hand"); 
                  field.setAccessible(true);
                  field.set(event.packet, MCHand.OFF_HAND);
                  Client.displayChatMessage(`§cPearl use changed to hand ${event.packet.hand}`);
              }
          })
      })
      

      This will indeed cancel the usage of the pearl on 1.8.x protocols

      
      
      function __require(path) {
          if (path.startsWith("@embedded")) {
              return globalThis
          }
      
          if (path.startsWith("@minecraft-yarn-definitions/types/")) {
              return {
                  [path.substring(path.lastIndexOf("/") + 1)]: Java.type(path
                      .replaceAll("@minecraft-yarn-definitions/types/", "")
                      .replaceAll("/", ".")
                  )
              }
          }
          return require(path);
      }
      var exports = {}
      
      "use strict";
      Object.defineProperty(exports, "__esModule", { value: true });
      // imports
      /* eslint-disable unused-imports/no-unused-imports */
      const _embedded_1 = __require("@embedded");
      /* eslint-enable unused-imports/no-unused-imports */
      // DO NOT TOUCH ANYTHING ABOVE THIS LINE, also not sure why it didn't work
      const PlayerInteractItemC2SPacket_1 = __require("@minecraft-yarn-definitions/types/net/minecraft/network/packet/c2s/play/PlayerInteractItemC2SPacket");
      const UpdateSelectedSlotC2SPacket_1 = __require("@minecraft-yarn-definitions/types/net/minecraft/network/packet/c2s/play/UpdateSelectedSlotC2SPacket");
      const UpdateSelectedSlotS2CPacket_1 = __require("@minecraft-yarn-definitions/types/net/minecraft/network/packet/s2c/play/UpdateSelectedSlotS2CPacket");
      const Items_1 = __require("@minecraft-yarn-definitions/types/net/minecraft/item/Items");
      const script = _embedded_1.registerScript.apply({
          name: "no-pearl-use",
          version: "1.0.0",
          authors: ["commandblock2"]
      });
      script.registerModule({
          name: "no-pearl-use",
          description: "cancels ender pearl use",
          category: "Player",
      }, (mod) => {
          var slot = 0;
          mod.on("enable", () => {
              var _a, _b;
              slot = (_b = (_a = _embedded_1.mc.player) === null || _a === void 0 ? void 0 : _a.inventory.selectedSlot) !== null && _b !== void 0 ? _b : 0;
          });
          mod.on("packet", (event) => {
              var _a;
              if (event.packet instanceof UpdateSelectedSlotS2CPacket_1.UpdateSelectedSlotS2CPacket) {
                  slot = event.packet.slot();
              }
              if (event.packet instanceof UpdateSelectedSlotC2SPacket_1.UpdateSelectedSlotC2SPacket) {
                  slot = event.packet.selectedSlot;
              }
              if (event.packet instanceof PlayerInteractItemC2SPacket_1.PlayerInteractItemC2SPacket &&
                  ((_a = _embedded_1.mc.player) === null || _a === void 0 ? void 0 : _a.inventory.main[slot].item) == Items_1.Items.ENDER_PEARL) {
                  event.cancelEvent();
              }
          });
      });
      

      This will desync your inventory with the server anyway, but it is true that no end pearl will be thrown if you have one in your hand (unless u have a pearl in server side but not client side). Can be used as a example.
      Later is the original ts file.

      // imports
      /* eslint-disable unused-imports/no-unused-imports */
      import {
          Setting,
          Vec3i,
          Vec3d,
          MathHelper,
          BlockPos,
          Hand,
          RotationAxis,
          mc,
          Client,
          RotationUtil,
          ItemUtil,
          NetworkUtil,
          InteractionUtil,
          BlockUtil,
          MovementUtil,
          ReflectionUtil,
          ParameterValidator,
          UnsafeThread,
          registerScript
      } from "@embedded";
      /* eslint-enable unused-imports/no-unused-imports */
      // DO NOT TOUCH ANYTHING ABOVE THIS LINE, also not sure why it didn't work
      
      import { PlayerInteractItemC2SPacket } from "@minecraft-yarn-definitions/types/net/minecraft/network/packet/c2s/play/PlayerInteractItemC2SPacket";
      import { UpdateSelectedSlotC2SPacket } from "@minecraft-yarn-definitions/types/net/minecraft/network/packet/c2s/play/UpdateSelectedSlotC2SPacket";
      import { UpdateSelectedSlotS2CPacket } from "@minecraft-yarn-definitions/types/net/minecraft/network/packet/s2c/play/UpdateSelectedSlotS2CPacket";
      import { Items } from "@minecraft-yarn-definitions/types/net/minecraft/item/Items";
      
      const script = registerScript.apply({
          name: "no-pearl-use",
          version: "1.0.0",
          authors: ["commandblock2"]
      });
      
      script.registerModule({
          name: "no-pearl-use",
          description: "cancels ender pearl use", 
          category: "Player",
      }, (mod) => {
      
          var slot = 0
      
          mod.on("enable", () => {
              slot = mc.player?.inventory.selectedSlot ?? 0;
          })
      
          mod.on("packet", (event) => {
      
              if (event.packet instanceof UpdateSelectedSlotS2CPacket) {
                  slot = event.packet.slot();
              }
      
              if (event.packet instanceof UpdateSelectedSlotC2SPacket) {
                  slot = event.packet.selectedSlot;
              }
      
      
              if (event.packet instanceof PlayerInteractItemC2SPacket &&
                  mc.player?.inventory.main[slot].item == Items.ENDER_PEARL
              ) {
                  event.cancelEvent();
              }
          })
      })
      
      1 Reply Last reply
      0
      • O Offline
        O Offline
        Otecc
        wrote on last edited by
        #3

        гитхаб плз

        1 Reply Last reply
        0

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        About
        • Terms of Service
        • Privacy Policy
        • Status
        • Contact Us
        Downloads
        • Releases
        • Source code
        • License
        Docs
        • Tutorials
        • CustomHUD
        • AutoSettings
        • ScriptAPI
        Community
        • Forum
        • Guilded
        • YouTube
        • Twitter
        • D.Tube
        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups