Added bed() and improved low-level drone methods.
This commit is contained in:
parent
72e0b6246e
commit
a63648cb97
7 changed files with 113 additions and 63 deletions
|
@ -10,8 +10,6 @@ if (__plugin.canary){
|
|||
var lookup = {};
|
||||
function initLookup(){
|
||||
var Facing = Packages.net.minecraft.util.EnumFacing,
|
||||
DoorHalf = Packages.net.minecraft.block.BlockDoor.EnumDoorHalf,
|
||||
HingePosition = Packages.net.minecraft.block.BlockDoor.EnumHingePosition,
|
||||
DyeColor = Packages.net.minecraft.item.EnumDyeColor;
|
||||
|
||||
lookup = {
|
||||
|
@ -28,8 +26,6 @@ function initLookup(){
|
|||
up: Facing.UP,
|
||||
down: Facing.DOWN
|
||||
},
|
||||
half: { upper: DoorHalf.UPPER, lower: DoorHalf.LOWER },
|
||||
hinge: { left: HingePosition.LEFT, right: HingePosition.RIGHT },
|
||||
color: {
|
||||
black: DyeColor.BLACK,
|
||||
blue: DyeColor.BLUE,
|
||||
|
@ -141,26 +137,7 @@ function applyRotation( block, metadata ){
|
|||
}
|
||||
}
|
||||
}
|
||||
function applyDoors( block, metadata ){
|
||||
switch (block.typeId){
|
||||
case blocks.door_wood:
|
||||
case blocks.door_iron:
|
||||
switch (metadata) {
|
||||
case 8:
|
||||
property(block).set('hinge','left');
|
||||
property(block).set('half','upper');
|
||||
break;
|
||||
case 9:
|
||||
property(block).set('hinge','right');
|
||||
property(block).set('half','upper');
|
||||
break;
|
||||
|
||||
default:
|
||||
property(block).set('facing',metadata);
|
||||
property(block).set('half','lower');
|
||||
}
|
||||
}
|
||||
}
|
||||
function applyProperties( block, metadata ){
|
||||
if (!bountiful){
|
||||
block.data = metadata;
|
||||
|
@ -172,6 +149,5 @@ function applyProperties( block, metadata ){
|
|||
applyFacing( block, metadata );
|
||||
applyColors( block, metadata );
|
||||
applyRotation( block, metadata );
|
||||
applyDoors( block, metadata );
|
||||
}
|
||||
exports.applyProperties = applyProperties;
|
||||
|
|
31
src/main/js/plugins/drone/bed.js
Normal file
31
src/main/js/plugins/drone/bed.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
'use strict';
|
||||
/*global require, Packages*/
|
||||
var Drone = require('./drone').Drone,
|
||||
blocks = require('blocks');
|
||||
var bedDirections = {
|
||||
0:3, // east
|
||||
1:0, // south
|
||||
2:1, // west
|
||||
3:2 // north
|
||||
};
|
||||
function bed(){
|
||||
this.then(function(){
|
||||
var foot = this.setBlock(blocks.bed, bedDirections[this.dir], 0,0,0, false);
|
||||
var head = this.setBlock(blocks.bed, bedDirections[this.dir] + 8, 0,0,1, false);
|
||||
if (Drone.bountiful){
|
||||
var prop = require('blockhelper').property;
|
||||
var BedHalf = Packages.net.canarymod.api.world.blocks.properties.BlockPropertyEnums.BedHalf;
|
||||
prop(foot)
|
||||
.set('facing',this.dir)
|
||||
.set('part', BedHalf.FOOT);
|
||||
prop(head)
|
||||
.set('facing',this.dir)
|
||||
.set('part', BedHalf.HEAD);
|
||||
}
|
||||
foot.update();
|
||||
head.update();
|
||||
});
|
||||
|
||||
}
|
||||
Drone.extend( bed );
|
||||
|
|
@ -22,13 +22,26 @@ function cottage( ) {
|
|||
.box( blocks.glass_pane )
|
||||
.left(5)
|
||||
.up()
|
||||
.prism0( blocks.stairs.oak, 7, 6)
|
||||
.prism0( blocks.stairs.oak, 7, 6) // add a roof
|
||||
.down()
|
||||
.right(4)
|
||||
.back()
|
||||
.wallsign(['Home','Sweet','Home'])
|
||||
.fwd()
|
||||
.move('cottage');
|
||||
.move('cottage')
|
||||
.right(3)
|
||||
.fwd(4)
|
||||
.up()
|
||||
.hangtorch() // place a torch on wall
|
||||
.move('cottage')
|
||||
.right()
|
||||
.fwd(3)
|
||||
.bed() // place a bed against left wall
|
||||
.fwd()
|
||||
.right(4)
|
||||
.box(blocks.furnace) // place a furnace against right wall
|
||||
.move('cottage')
|
||||
;
|
||||
}
|
||||
//
|
||||
// a more complex script that builds an tree-lined avenue with
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
'use strict';
|
||||
/*************************************************************************
|
||||
### Drone.door() method
|
||||
|
||||
|
@ -46,29 +47,43 @@ Create double iron doors
|
|||
|
||||
***/
|
||||
|
||||
var Drone = require('./drone').Drone;
|
||||
/*global require*/
|
||||
var Drone = require('./drone').Drone,
|
||||
blocks = require('blocks');
|
||||
/*global require, Packages*/
|
||||
function door( doorMaterial, hinge) {
|
||||
if ( typeof doorMaterial == 'undefined' ) {
|
||||
doorMaterial = 64; // wood
|
||||
doorMaterial = blocks.door_wood; // wood
|
||||
}
|
||||
if (typeof hinge == 'undefined') {
|
||||
hinge = 'left';
|
||||
}
|
||||
this.then(function(){
|
||||
this.setBlock(doorMaterial, this.dir);
|
||||
this.setBlock(doorMaterial, hinge=='left' ? 8 : 9, 0,1,0);
|
||||
var lower = this.setBlock(doorMaterial, this.dir, 0, 0, 0, false);
|
||||
var upper = this.setBlock(doorMaterial, hinge=='left' ? 8 : 9, 0,1,0, false);
|
||||
if (Drone.bountiful){
|
||||
var DoorHalf = Packages.net.minecraft.block.BlockDoor.EnumDoorHalf,
|
||||
HingePosition = Packages.net.minecraft.block.BlockDoor.EnumHingePosition,
|
||||
prop = require('blockhelper').property;
|
||||
prop(lower)
|
||||
.set('facing', this.dir)
|
||||
.set('half', DoorHalf.LOWER );
|
||||
prop(upper)
|
||||
.set('hinge', hinge == 'left' ? HingePosition.LEFT: HingePosition.RIGHT)
|
||||
.set('half', DoorHalf.UPPER);
|
||||
}
|
||||
lower.update();
|
||||
upper.update();
|
||||
});
|
||||
}
|
||||
Drone.extend( door );
|
||||
|
||||
Drone.extend( function door_iron( ) {
|
||||
this.door(71);
|
||||
this.door(blocks.door_iron);
|
||||
} );
|
||||
|
||||
Drone.extend( function door2( doorMaterial ) {
|
||||
if ( typeof doorMaterial == 'undefined' ) {
|
||||
doorMaterial = 64;
|
||||
doorMaterial = blocks.door_wood;
|
||||
}
|
||||
this
|
||||
.door( doorMaterial, 'left')
|
||||
|
@ -77,5 +92,5 @@ Drone.extend( function door2( doorMaterial ) {
|
|||
.left();
|
||||
} );
|
||||
Drone.extend( function door2_iron( ) {
|
||||
this.door2( 71 );
|
||||
this.door2( blocks.door_iron );
|
||||
} );
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*global __plugin, require, org, setTimeout, addUnloadHandler, exports, global, Packages*/
|
||||
/*global __plugin, require, org, setTimeout, addUnloadHandler, exports, global, Packages, server*/
|
||||
var utils = require('utils'),
|
||||
blocks = require('blocks'),
|
||||
THOUSAND = 1000,
|
||||
|
@ -314,7 +314,7 @@ function getDirFromRotation( location ) {
|
|||
return 0; // east
|
||||
return 1; // south
|
||||
}
|
||||
function putBlock( x, y, z, blockId, metadata, world, dir ) {
|
||||
function putBlock( x, y, z, blockId, metadata, world, dir, update ) {
|
||||
if ( typeof metadata == 'undefined' ) {
|
||||
metadata = 0;
|
||||
}
|
||||
|
@ -325,12 +325,18 @@ function putBlock( x, y, z, blockId, metadata, world, dir ) {
|
|||
block.type = BlockType.fromId(blockId);
|
||||
var applyProperties = require('blockhelper').applyProperties;
|
||||
applyProperties(block, metadata);
|
||||
if (typeof update === 'undefined'){
|
||||
update = true;
|
||||
}
|
||||
if (update){
|
||||
block.update();
|
||||
}
|
||||
}
|
||||
if (__plugin.bukkit) {
|
||||
block.setTypeIdAndData( blockId, metadata, false );
|
||||
block.data = metadata;
|
||||
}
|
||||
return block;
|
||||
}
|
||||
|
||||
function Drone( x, y, z, dir, world ) {
|
||||
|
@ -559,14 +565,23 @@ Drone.prototype.times = function( numTimes, commands ) {
|
|||
Drone.prototype.getBlock = function(){
|
||||
return this.world.getBlockAt(this.x,this.y,this.z);
|
||||
};
|
||||
Drone.prototype.setBlock = function(blockType, data, ox, oy, oz){
|
||||
if (typeof ox == 'undefined')
|
||||
ox = 0;
|
||||
if (typeof oy == 'undefined')
|
||||
oy = 0;
|
||||
if (typeof oz == 'undefined')
|
||||
oz = 0;
|
||||
putBlock(this.x + ox, this.y + oy, this.z + oz, blockType, data, this.world, this.dir);
|
||||
Drone.prototype.setBlock = function(blockType, data, ow, oh, od, update){
|
||||
if (typeof ow == 'undefined')
|
||||
ow = 0;
|
||||
if (typeof oh == 'undefined')
|
||||
oh = 0;
|
||||
if (typeof od == 'undefined')
|
||||
od = 0;
|
||||
this
|
||||
.right(ow)
|
||||
.up(oh)
|
||||
.fwd(od);
|
||||
var result = putBlock(this.x, this.y, this.z, blockType, data, this.world, this.dir, update);
|
||||
this
|
||||
.left(ow)
|
||||
.down(oh)
|
||||
.back(od);
|
||||
return result;
|
||||
};
|
||||
Drone.prototype.traverseWidth = function(width, callback){
|
||||
_traverse[this.dir].width(this, width, callback);
|
||||
|
@ -865,3 +880,4 @@ Drone.clone = function(origin) {
|
|||
// wph 20130130 - make this a method - extensions can use it.
|
||||
//
|
||||
Drone.prototype._getBlockIdAndMeta = _getBlockIdAndMeta;
|
||||
Drone.bountiful = __plugin.canary ? parseFloat(server.canaryModVersion) > 1.7 : false;
|
||||
|
|
|
@ -27,7 +27,6 @@ A ladder 10 blocks high will be created at the point you were looking at.
|
|||
***/
|
||||
var blocks = require('blocks');
|
||||
function ladder( height ){
|
||||
this.then(function(){
|
||||
var block = this.getBlock();
|
||||
if (block.typeId == blocks.air || block.typeId == blocks.ladder){
|
||||
this.box(blocks.ladder, 1, height, 1);
|
||||
|
@ -37,6 +36,5 @@ function ladder( height ){
|
|||
.box(blocks.ladder, 1, height, 1)
|
||||
.fwd();
|
||||
}
|
||||
});
|
||||
}
|
||||
Drone.extend( ladder );
|
||||
|
|
|
@ -68,8 +68,7 @@ function putSign( drone, texts, blockId, meta ) {
|
|||
if ( blockId != blocks.sign_post && blockId != blocks.sign ) {
|
||||
throw new Error( 'Invalid Parameter: blockId must be blocks.sign_post or blocks.sign' );
|
||||
}
|
||||
drone.setBlock( blockId, meta);
|
||||
block = drone.getBlock();
|
||||
block = drone.setBlock( blockId, meta);
|
||||
if (__plugin.canary){
|
||||
isSign = function(block){
|
||||
var sign = block.getTileEntity();
|
||||
|
@ -96,14 +95,17 @@ function putSign( drone, texts, blockId, meta ) {
|
|||
}
|
||||
};
|
||||
function signpost( message ){
|
||||
this.then(function(){
|
||||
this.sign(message, blocks.sign_post);
|
||||
});
|
||||
}
|
||||
function wallsign( message ){
|
||||
/*
|
||||
must allow for /js wallsign() while looking at a wall block
|
||||
*/
|
||||
this.then(function(){
|
||||
if (this.getBlock().typeId == blocks.air){
|
||||
var block = this.getBlock();
|
||||
if (block.typeId == blocks.air || block.typeId == blocks.sign){
|
||||
this.sign(message, blocks.sign);
|
||||
} else {
|
||||
this
|
||||
|
@ -129,9 +131,8 @@ function sign( message, block ) {
|
|||
console.error(usage);
|
||||
return;
|
||||
}
|
||||
this.then(function(){
|
||||
putSign( this, message, block, meta);
|
||||
});
|
||||
|
||||
}
|
||||
Drone.extend(sign);
|
||||
Drone.extend(signpost);
|
||||
|
|
Reference in a new issue