Skip to content

Examples

Anarchick edited this page Oct 9, 2022 · 2 revisions

I play on latest version of MC so I only made examples for 1.16.X or 1.17.X . This does not mean that it can't works with other versions of MC, try by yourself ;)

Works with 1.16.X and 1.17.X
function fakeBlock(loc: location, toBlock: itemtype, players: players):
    set {_packet} to new play_server_block_change packet
    set field 0 of {_packet} to {_loc}
    set field 1 of {_packet} to {_toBlock}
    send {_players::*} packet {_packet}
function unloadChunk(x: number, z: number, players: players):
    set {_packet} to new play_server_unload_chunk packet
    set field 0 of {_packet} to {_x}
    set field 1 of {_packet} to {_z}
    send {_players::*} packet {_packet}
on packet event play_client_steer_vehicle:
    set {_sideways} to field 0
    set {_forward} to field 1
    set {_jump} to field 2
    set {_unmount} to field 3
function packetActionBar(text: text, receivers: players):
    set {_packet} to new play_server_chat packet
    set field 2 of {_packet} to {_text}
    set field 3 of {_packet} to "GAME_INFO"
    send packet {_packet} to {_receivers::*} without calling event
function breakAnimation(block: block, stage: number, receivers: players):
    set {_stage} to (round down {_stage}) ? 0
    {_stage} is between 0 and 9
    set {_packet} to new play_server_block_break_animation packet
    set field 0 of {_packet} to random integer between 0 and 999999
    set field 1 of {_packet} to {_block}
    set field 2 of {_packet} to {_stage}
    send {_receivers::*} packet {_packet} without calling event
effect change client side equipment %string% of %entity% to %itemstack% for %players%:
    trigger:
        set {_slot} to expression-1 in upper case
        {_slot} is "CHEST" or "FEET" or "HEAD" or "LEGS" or "MAINHAND" or "OFFHAND"
        set {_entity} to expression-2
        {_entity} is an entity
        set {_item} to expression-3 ? air
        set {_nmsItem} to nms of (random item out of {_item})
        {_nmsItem} is set
        set {_players::*} to expression-4
        set {_packet} to new play_server_entity_equipment packet
        set field 0 of {_packet} to {_entity}
        set {_itemSlot} to enum {_slot} from nms class "world.entity.EnumItemSlot"
        set {_pair} to pair {_itemSlot} with {_nmsItem}
        set field 1 of {_packet} to {_pair} # Auto-convert as List
        send {_players::*} packet {_packet}
import:
    net.minecraft.server.v1_16_R3.PacketPlayOutGameStateChange$a
    net.minecraft.network.protocol.game.PacketPlayOutGameStateChange$a
effect change client side gamemode of %players% to %gamemode%:
    trigger:
        set {_packet} to new play_server_game_state_change packet
        set {_gm} to "%expression-2%"
        set field 1 of {_packet} to 0 if {_gm} is "survival"
        set field 1 of {_packet} to 1 if {_gm} is "creative"
        set field 1 of {_packet} to 2 if {_gm} is "adventure"
        set field 1 of {_packet} to 3 if {_gm} is "spectator" 
        set field 0 of {_packet} to new a(3) # reason
        send packet {_packet} to expression-1 without calling event

effect change client weather of %players% to level %number%:
    trigger:
        set {_packet} to new play_server_game_state_change packet
        set field 0 of {_packet} to new a(7) # reason
        set field 1 of {_packet} to expression-2
        send packet {_packet} to expression-1 without calling event
# Use : packet update {_entity} for all players in world of {_entity}
# To reveal the hidden entity
function HideEntity(e: entities, p: players):
    loop {_e::*}:
        add entity id of loop-value to {_id::*}
    set {_packet} to new play_server_entity_destroy packet
    set field 0 of {_packet} to {_id::*}
    send {_p::*} packet {_packet}
Works with 1.16.X
# DO NOT CHANGE FOV WHEN PLAYER WALK/FLY SPEED IS MODIFIED
on packet event play_server_abilities:
    set field 5 to {%event-player%::FOV}

function FOV(p: players, x: number):
    set {_packet} to new play_server_abilities packet
    set field 5 of {_packet} to {_x}
    loop {_p::*}:
        set {_player} to loop-value
        set {%{_player}%::FOV} to {_x}
        send {_player} packet {_packet}
function BiomeStorage(biome: biome) :: object:
    set {_id} to nms biome id of {_biome}
    if {BiomeStorage::%{_id}%} is not set:
        loop 1024 times:
            set {_biomeId::%loop-value%} to {_id}
        set {BiomeStorage::%{_id}%} to {_biomeId::*} as primitive int array
    return {BiomeStorage::%{_id}%}

import:
    net.minecraft.server.v1_16_R3.PacketPlayOutMapChunk

effect change client side biome of [chunk] %chunk% to %biome% for %players% :
    trigger:
        await 0.toString() # Async
        set {_chunk} to expression-1
        set {_MapChunk} to new PacketPlayOutMapChunk(nms chunk of {_chunk}, 65535)
        set {_packet} to new play_server_map_chunk packet
        set field 0 of {_packet} to {_chunk}.getX()
        set field 1 of {_packet} to {_chunk}.getZ()
        set field 2 of {_packet} to {_MapChunk}.c # int
        set field 3 of {_packet} to {_MapChunk}.d # NBTTagCompound
        set field 4 of {_packet} to BiomeStorage(expression-2)
        set {_byte::*} to ...{_MapChunk}.f
        set field 5 of {_packet} to {_byte::*} as primitive byte Array
        set field 6 of {_packet} to {_MapChunk}.g # Represent all Tiles Entities
        set field 7 of {_packet} to true # Represent a full chunk, biomes are store only if true
        set field 8 of {_packet} to true
        set field 9 of {_packet} to {_} as arraylist # Empty ArrayList
        send packet {_packet} to expression-3 without calling event
        
command /biome [<biome>] [<int>]:
    permission: fakebiome.cmd
    trigger:
        delete {biome}
        if arg-1 is set:
            set {biome} to arg-1
            BiomeStorage({biome})
        send "Fake biome set to %{biome}%" to sender

on packet event play_server_map_chunk:
    {biome} is set
    field 7 of event-packet is true # Represent a full chunk, biomes are store only if true
    set field 4 of event-packet to BiomeStorage({biome})
    #cancel event
    #send packet event-packet to event-player without calling event
Clone this wiki locally