Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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
};

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.