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 = {};
|
var lookup = {};
|
||||||
function initLookup(){
|
function initLookup(){
|
||||||
var Facing = Packages.net.minecraft.util.EnumFacing,
|
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;
|
DyeColor = Packages.net.minecraft.item.EnumDyeColor;
|
||||||
|
|
||||||
lookup = {
|
lookup = {
|
||||||
|
@ -28,8 +26,6 @@ function initLookup(){
|
||||||
up: Facing.UP,
|
up: Facing.UP,
|
||||||
down: Facing.DOWN
|
down: Facing.DOWN
|
||||||
},
|
},
|
||||||
half: { upper: DoorHalf.UPPER, lower: DoorHalf.LOWER },
|
|
||||||
hinge: { left: HingePosition.LEFT, right: HingePosition.RIGHT },
|
|
||||||
color: {
|
color: {
|
||||||
black: DyeColor.BLACK,
|
black: DyeColor.BLACK,
|
||||||
blue: DyeColor.BLUE,
|
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 ){
|
function applyProperties( block, metadata ){
|
||||||
if (!bountiful){
|
if (!bountiful){
|
||||||
block.data = metadata;
|
block.data = metadata;
|
||||||
|
@ -172,6 +149,5 @@ function applyProperties( block, metadata ){
|
||||||
applyFacing( block, metadata );
|
applyFacing( block, metadata );
|
||||||
applyColors( block, metadata );
|
applyColors( block, metadata );
|
||||||
applyRotation( block, metadata );
|
applyRotation( block, metadata );
|
||||||
applyDoors( block, metadata );
|
|
||||||
}
|
}
|
||||||
exports.applyProperties = applyProperties;
|
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 )
|
.box( blocks.glass_pane )
|
||||||
.left(5)
|
.left(5)
|
||||||
.up()
|
.up()
|
||||||
.prism0( blocks.stairs.oak, 7, 6)
|
.prism0( blocks.stairs.oak, 7, 6) // add a roof
|
||||||
.down()
|
.down()
|
||||||
.right(4)
|
.right(4)
|
||||||
.back()
|
.back()
|
||||||
.wallsign(['Home','Sweet','Home'])
|
.wallsign(['Home','Sweet','Home'])
|
||||||
.fwd()
|
.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
|
// a more complex script that builds an tree-lined avenue with
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
'use strict';
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
### Drone.door() method
|
### Drone.door() method
|
||||||
|
|
||||||
|
@ -46,29 +47,43 @@ Create double iron doors
|
||||||
|
|
||||||
***/
|
***/
|
||||||
|
|
||||||
var Drone = require('./drone').Drone;
|
var Drone = require('./drone').Drone,
|
||||||
/*global require*/
|
blocks = require('blocks');
|
||||||
|
/*global require, Packages*/
|
||||||
function door( doorMaterial, hinge) {
|
function door( doorMaterial, hinge) {
|
||||||
if ( typeof doorMaterial == 'undefined' ) {
|
if ( typeof doorMaterial == 'undefined' ) {
|
||||||
doorMaterial = 64; // wood
|
doorMaterial = blocks.door_wood; // wood
|
||||||
}
|
}
|
||||||
if (typeof hinge == 'undefined') {
|
if (typeof hinge == 'undefined') {
|
||||||
hinge = 'left';
|
hinge = 'left';
|
||||||
}
|
}
|
||||||
this.then(function(){
|
this.then(function(){
|
||||||
this.setBlock(doorMaterial, this.dir);
|
var lower = this.setBlock(doorMaterial, this.dir, 0, 0, 0, false);
|
||||||
this.setBlock(doorMaterial, hinge=='left' ? 8 : 9, 0,1,0);
|
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( door );
|
||||||
|
|
||||||
Drone.extend( function door_iron( ) {
|
Drone.extend( function door_iron( ) {
|
||||||
this.door(71);
|
this.door(blocks.door_iron);
|
||||||
} );
|
} );
|
||||||
|
|
||||||
Drone.extend( function door2( doorMaterial ) {
|
Drone.extend( function door2( doorMaterial ) {
|
||||||
if ( typeof doorMaterial == 'undefined' ) {
|
if ( typeof doorMaterial == 'undefined' ) {
|
||||||
doorMaterial = 64;
|
doorMaterial = blocks.door_wood;
|
||||||
}
|
}
|
||||||
this
|
this
|
||||||
.door( doorMaterial, 'left')
|
.door( doorMaterial, 'left')
|
||||||
|
@ -77,5 +92,5 @@ Drone.extend( function door2( doorMaterial ) {
|
||||||
.left();
|
.left();
|
||||||
} );
|
} );
|
||||||
Drone.extend( function door2_iron( ) {
|
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'),
|
var utils = require('utils'),
|
||||||
blocks = require('blocks'),
|
blocks = require('blocks'),
|
||||||
THOUSAND = 1000,
|
THOUSAND = 1000,
|
||||||
|
@ -314,7 +314,7 @@ function getDirFromRotation( location ) {
|
||||||
return 0; // east
|
return 0; // east
|
||||||
return 1; // south
|
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' ) {
|
if ( typeof metadata == 'undefined' ) {
|
||||||
metadata = 0;
|
metadata = 0;
|
||||||
}
|
}
|
||||||
|
@ -325,12 +325,18 @@ function putBlock( x, y, z, blockId, metadata, world, dir ) {
|
||||||
block.type = BlockType.fromId(blockId);
|
block.type = BlockType.fromId(blockId);
|
||||||
var applyProperties = require('blockhelper').applyProperties;
|
var applyProperties = require('blockhelper').applyProperties;
|
||||||
applyProperties(block, metadata);
|
applyProperties(block, metadata);
|
||||||
|
if (typeof update === 'undefined'){
|
||||||
|
update = true;
|
||||||
|
}
|
||||||
|
if (update){
|
||||||
block.update();
|
block.update();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (__plugin.bukkit) {
|
if (__plugin.bukkit) {
|
||||||
block.setTypeIdAndData( blockId, metadata, false );
|
block.setTypeIdAndData( blockId, metadata, false );
|
||||||
block.data = metadata;
|
block.data = metadata;
|
||||||
}
|
}
|
||||||
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Drone( x, y, z, dir, world ) {
|
function Drone( x, y, z, dir, world ) {
|
||||||
|
@ -559,14 +565,23 @@ Drone.prototype.times = function( numTimes, commands ) {
|
||||||
Drone.prototype.getBlock = function(){
|
Drone.prototype.getBlock = function(){
|
||||||
return this.world.getBlockAt(this.x,this.y,this.z);
|
return this.world.getBlockAt(this.x,this.y,this.z);
|
||||||
};
|
};
|
||||||
Drone.prototype.setBlock = function(blockType, data, ox, oy, oz){
|
Drone.prototype.setBlock = function(blockType, data, ow, oh, od, update){
|
||||||
if (typeof ox == 'undefined')
|
if (typeof ow == 'undefined')
|
||||||
ox = 0;
|
ow = 0;
|
||||||
if (typeof oy == 'undefined')
|
if (typeof oh == 'undefined')
|
||||||
oy = 0;
|
oh = 0;
|
||||||
if (typeof oz == 'undefined')
|
if (typeof od == 'undefined')
|
||||||
oz = 0;
|
od = 0;
|
||||||
putBlock(this.x + ox, this.y + oy, this.z + oz, blockType, data, this.world, this.dir);
|
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){
|
Drone.prototype.traverseWidth = function(width, callback){
|
||||||
_traverse[this.dir].width(this, 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.
|
// wph 20130130 - make this a method - extensions can use it.
|
||||||
//
|
//
|
||||||
Drone.prototype._getBlockIdAndMeta = _getBlockIdAndMeta;
|
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');
|
var blocks = require('blocks');
|
||||||
function ladder( height ){
|
function ladder( height ){
|
||||||
this.then(function(){
|
|
||||||
var block = this.getBlock();
|
var block = this.getBlock();
|
||||||
if (block.typeId == blocks.air || block.typeId == blocks.ladder){
|
if (block.typeId == blocks.air || block.typeId == blocks.ladder){
|
||||||
this.box(blocks.ladder, 1, height, 1);
|
this.box(blocks.ladder, 1, height, 1);
|
||||||
|
@ -37,6 +36,5 @@ function ladder( height ){
|
||||||
.box(blocks.ladder, 1, height, 1)
|
.box(blocks.ladder, 1, height, 1)
|
||||||
.fwd();
|
.fwd();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
Drone.extend( ladder );
|
Drone.extend( ladder );
|
||||||
|
|
|
@ -68,8 +68,7 @@ function putSign( drone, texts, blockId, meta ) {
|
||||||
if ( blockId != blocks.sign_post && blockId != blocks.sign ) {
|
if ( blockId != blocks.sign_post && blockId != blocks.sign ) {
|
||||||
throw new Error( 'Invalid Parameter: blockId must be blocks.sign_post or blocks.sign' );
|
throw new Error( 'Invalid Parameter: blockId must be blocks.sign_post or blocks.sign' );
|
||||||
}
|
}
|
||||||
drone.setBlock( blockId, meta);
|
block = drone.setBlock( blockId, meta);
|
||||||
block = drone.getBlock();
|
|
||||||
if (__plugin.canary){
|
if (__plugin.canary){
|
||||||
isSign = function(block){
|
isSign = function(block){
|
||||||
var sign = block.getTileEntity();
|
var sign = block.getTileEntity();
|
||||||
|
@ -96,14 +95,17 @@ function putSign( drone, texts, blockId, meta ) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
function signpost( message ){
|
function signpost( message ){
|
||||||
|
this.then(function(){
|
||||||
this.sign(message, blocks.sign_post);
|
this.sign(message, blocks.sign_post);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
function wallsign( message ){
|
function wallsign( message ){
|
||||||
/*
|
/*
|
||||||
must allow for /js wallsign() while looking at a wall block
|
must allow for /js wallsign() while looking at a wall block
|
||||||
*/
|
*/
|
||||||
this.then(function(){
|
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);
|
this.sign(message, blocks.sign);
|
||||||
} else {
|
} else {
|
||||||
this
|
this
|
||||||
|
@ -129,9 +131,8 @@ function sign( message, block ) {
|
||||||
console.error(usage);
|
console.error(usage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.then(function(){
|
|
||||||
putSign( this, message, block, meta);
|
putSign( this, message, block, meta);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
Drone.extend(sign);
|
Drone.extend(sign);
|
||||||
Drone.extend(signpost);
|
Drone.extend(signpost);
|
||||||
|
|
Reference in a new issue