Created
January 17, 2018 20:04
-
-
Save ItsSpyce/105c3795a67e99fd114eca6cb8da2dbc to your computer and use it in GitHub Desktop.
Summ Thiq Pipes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A quick writeup as to what custom pipes might look like in JS. This is basically a plugin version of BuildCraft's pipe system. | |
// On any container, you can place a piston that points to the container (i.e.: chest, furnace, etc). | |
// Chests can output and input items from any side. | |
// Furnaces can only receive smeltable items from the top, fuel from bottom, and only output from side faces. | |
// Pipes are glass blocks. They act as standard pipes. Stained glass blocks can only transport to other stained glass blocks of the same color OR standard pipes. | |
// Modifying blocks can be placed between the pipes to add flow mechanics: | |
// Diamond blocks act as gates. You can place up to 9 different blocks per stained color. Those that match no criteria will pass through any pipe that has no filter at random. | |
// Gold blocks speed up the item. | |
// Obsidian acts as a teleporting block. The obsidian must have a sign at the end of it in the format: | |
// [TX:0] (sends on channel 0. Max of 65535, min of 0) | |
// [RX:0] (receives on channel 0. Doesn't have to match TX) | |
// At normal speed, it should take a block 3 seconds to move 1 MCU (minecraft unit), no matter which vector direction. At high speed, it'll move 1 block in .5 seconds, increasing time by .5 seconds every block, essentially boosting it for 5 blocks. | |
// If an item reaches the container and there is no room, it will drop onto the ground. | |
class Pipe { | |
constructor(position, type) { | |
this.position = position; | |
this.type = type; | |
} | |
} | |
var PipeType = { | |
0: "STANDARD", | |
1: "RED", | |
2: "BLUE", | |
3: "GREEN", | |
RED: 0, | |
BLUE: 1, | |
GREEN: 2 | |
} | |
// show items moving through pipes | |
// to do this, we get the piston being powered event and then call setInterval() to process what items are being transported. All movements are async promise based. | |
class PipedStack { | |
constructor(itemstack, startAt) { | |
this.itemstack = itemstack; | |
temstack.setCanPickup(false); | |
this.startat = startAt + new Location(0.5, 0.5, 0.5); | |
this.at = this.startat.clone(); | |
} | |
// Gets the count of updates during a stack moving animation. | |
getUpdateCount(time) { | |
// if high drag results in 3000ms over 1 MCU and 500ms with low drag | |
// we should have an update every 50ms | |
return time / 50; | |
} | |
animate(target, speed) { | |
return new Promise(function (resolve, reject) { | |
var updateCount = getUpdateCount(speed); | |
var diff = (target - this.start) / updateCount; | |
this.itemstack.spawn(this.at); | |
var interval = setInterval(function (currentCount) { | |
try { | |
if (currentCount >= updateCount) { | |
clearInterval(interval); | |
} | |
this.at += diff; | |
this.itemstack.teleport(this.at); | |
currentCount++; | |
resolve(this); | |
} catch (ex) { | |
clearInterval(interval); | |
reject(ex); | |
} | |
}, 50, 0); | |
}); | |
} | |
animateUp(speed) { | |
return this.animate(this.at + new Location(0, 1, 0), speed); | |
} | |
animateDown(speed) { | |
return this.animate(this.at - new Location(0, 1, 0), speed); | |
} | |
animateEast(speed) { | |
return this.animate(this.at + new Location(1, 0, 0), speed); | |
} | |
animateWest(speed) { | |
return this.animate(this.at - new Location(1, 0, 0), speed); | |
} | |
animateNorth(speed) { | |
return this.animate(this.at + new Location(0, 0, 1), speed); | |
} | |
animateSouth(speed) { | |
return this.animate(this.at - new Location(0, 0, 1), speed); | |
} | |
tryInventoryMerge(inventory) { | |
var leftOver = inventory.add(this.itemstack); | |
return leftOver.amount == 0; | |
} | |
drop() { | |
// basically, this'll spawn a new itemstack off of this one | |
var newstack = this.itemstack.clone(); | |
newstack.setCanPickup(true); | |
newstack.spawn(this.at); | |
} | |
destroy() { | |
this.itemstack.delete(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment