Skip to content

Instantly share code, notes, and snippets.

@brfitzpatrick
Last active July 26, 2017 00:52
Show Gist options
  • Save brfitzpatrick/406a30d1c6b86fd05284cd48a64db989 to your computer and use it in GitHub Desktop.
Save brfitzpatrick/406a30d1c6b86fd05284cd48a64db989 to your computer and use it in GitHub Desktop.
fire a ray of blocks in Minecraft

Ray(s) of blocks

a function for interacting with a Minecraft world via ROpenSci's miner package

ray produces one or more rays of blocks of length rng from the fid player's position in the direction given by their view orientation (center the cross hairs on your target). Rays of lava are particularly effective for igniting enemies. Persistent rays (pst = TRUE) of some safe block type provide quick but messy staircases and bridges. If you accidentally ignite yourself, a ray of water starting adjacent to your position (disp = 1) can save you if you run into it but you'll need to type fast. Non-persistant rays replace all blocks in their path first with the block type specified by rid then with empty blocks (air type) and thus may be thought of as destroying all in their path. To ignite a pack of enemies in rapid succession set rpt to the number of successive rays you would like a single execution of this function to produce. Successive rays will be generated with ttt seconds between each for you to target new enemies...heady stuff but while you are laying waste to your foes remember old Nietzsche who said, 'He who fights with monsters should look to it that he himself does not become a monster'.

Usage:

ray(rid = 11, rng = 50, ttt = 3, disp = 5, fid = getPlayerIds(), dur = 1, pst = FALSE, rpt = 1)

Arguments

rid ray identity, the numeric code identifying type of the blocks that will be use to construct the ray (use miner::find_item()to find item identity codes)

rng range of ray (units = blocks)

ttt time to target (seconds), time between function execution and ray initiation (use this time to position the cross hairs over your target)

disp displacement of ray origin from player (important if your ray is composed of damaging blocks e.g. lava)

fid focal identity, player identity from which ray originates

pst persistent, TRUE/FALSE should the blocks of the ray persist in the world permanently? If FALSE blocks are removed after durseconds have elapsed from the placement of the first block

dur duration of ray (seconds)

rpt repeats, number of repeats to perform i.e. the number of rays that will be fired successively with a pause of ttt seconds between each to mouse over a new target

ray <- function(rid = 11, rng = 50, ttt = 3, disp = 5, fid = getPlayerIds(), dur = 1, pst = FALSE, rpt = 1){
  for(k in 1:rpt){
    Sys.sleep(ttt)
    rot <- getPlayerRotation(player_id = fid)
    pos <- getPlayerPos(player_id = fid)
    pitch <- getPlayerPitch(player_id = fid)
    for(i in disp:rng){
      delta.x.i <- i*sin(x = pi*-rot/180)
      delta.z.i <- i*cos(x = pi*-rot/180)
      delta.y.i <- i*sin(x = pi*-pitch/180)
      setBlock(x = pos[1]+delta.x.i,
               y = pos[2]+delta.y.i,
               z = pos[3]+delta.z.i,
               id = rid)
    }
    if(pst == FALSE){
      Sys.sleep(time = dur)
      for(i in disp:rng){
        delta.x.i <- i*sin(x = pi*-rot/180)
        delta.z.i <- i*cos(x = pi*-rot/180)
        delta.y.i <- i*sin(x = pi*-pitch/180)
        setBlock(x = pos[1]+delta.x.i,
                 y = pos[2]+delta.y.i,
                 z = pos[3]+delta.z.i,
                 id = 0)
      }
    }
  }
}

Examples

Follow ROpenSci instructions to set up a Minecraft server and connect to it from R with their R package miner

library(miner)

mc_connect()

A persistant stone staircase/bridge originating from the player and terminating 50 blocks away in the direction given by the player's mouse position (point where you'd like it to go):

ray(rid = 1, rng = 50, ttt = 3, disp = 0, pst = TRUE)

DANGER!!! The following LIVE FIRE examples are primarily offensive in effect and designed for battlefield execution. Lava burns things, including you!

A ray of Lava originating 5 blocks from the player and terminating 50 blocks away in the direction given by the player's mouse position (point where you'd like it to go). The lava will persist in the world for 1 second, this is long enough to ignite targets but reduces the risk of the player being immolated by lava flow when fired uphill:

ray(rid = 11, rng = 50, ttt = 3, disp = 5, pst = FALSE, dur = 1)

3 rays of Lava with 3 seconds between the removal of the previous ray from the world and the initiation of the next, otherwise as above:

ray(rid = 11, rng = 50, ttt = 3, disp = 5, pst = FALSE, dur = 1, rpt = 3)

Coming soon...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment