chromecide Posted December 18, 2015 Share Posted December 18, 2015 A Wireless Redstone script that includes a Transmitter, Receiver and channel support; Usage: Transmitter: var rsTransmitter; function init(event){ rsTransmitter = new WirelessRedstone.Transmitter(event, "My Channel Name"); } function redstone(event){ rsTransmitter.redstone(event); } Receiver: var rsReceiver; function init(event){ rsReceiver = new WirelessRedstone.Receiver(event, "My Channel Name"); } function broken(event){ rsReceiver.broken(event); } Script: Note: as of CustomNpcs_1.8.8_beta(17dec15) you cannot load external scripts, so you'll have to paste the following into the top of each ScriptedBlock you want to use this on. function RedstoneTransmitter(event, channel){ var world = event.block.getWorld(); this.block = event.block; this.channel = channel; var tempData = world.getTempdata(); var worldChannels = tempData.get("RedstoneChannels"); if(!worldChannels){ worldChannels = {}; } if(!worldChannels[this.channel]){ worldChannels[this.channel] = []; } tempData.put("RedstoneChannels", worldChannels); } RedstoneTransmitter.prototype.redstone = function(event) { var world = event.block.world; var worldChannels = world.getTempdata().get("RedstoneChannels"); if(!worldChannels){ worldChannels = {}; } var receiverList = worldChannels[this.channel]; if(receiverList.length>0){ for(var i=0;i<receiverList.length;i++){ var receiver = receiverList[i]; if(receiver){ receiver.redstone(event); } } } }; function RedstoneReceiver(event, channel){ var world = event.block.getWorld(); this.block = event.block; this.channel = channel; var tempData = world.getTempdata(); var worldChannels = tempData.get("RedstoneChannels"); if(!worldChannels){ worldChannels = {}; } if(!worldChannels[this.channel]){ worldChannels[this.channel] = []; } worldChannels[this.channel].push(this); tempData.put("RedstoneChannels", worldChannels); } RedstoneReceiver.prototype.redstone = function(event) { var world = this.block.getWorld(); this.block.setRedstonePower(event.power); }; RedstoneReceiver.prototype.broken = function(event) { var world = event.block.world; var worldChannels = world.getTempdata().get("RedstoneChannels"); if(!worldChannels){ worldChannels = {}; } var receiverList = worldChannels[this.channel]; if(receiverList.length>0){ for(var i=receiverList.length-1;i>=0;i--){ var receiver = receiverList[i]; if(receiver.block.getX()==this.block.getX() && receiver.block.getY()==this.block.getY() && receiver.block.getZ()==this.block.getZ()){ receiverList.splice(i, 1); } } } worldChannels[this.channel] = receiverList; world.getTempdata().put("RedstoneChannels", worldChannels); }; var WirelessRedstone = { Transmitter: RedstoneTransmitter, Receiver: RedstoneReceiver }; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.