Search in sources :

Example 1 with IPassive

use of org.thewdj.telecom.IPassive in project NyaSamaRailway by NSDN.

the class SignalBox method updateSignal.

public void updateSignal(World world, int x, int y, int z) {
    if (world.getTileEntity(x, y, z) == null)
        return;
    if (world.getTileEntity(x, y, z) instanceof TileEntitySignalBox) {
        TileEntitySignalBox signalBox = (TileEntitySignalBox) world.getTileEntity(x, y, z);
        int meta = world.getBlockMetadata(x, y, z);
        int old = meta;
        boolean isEnabled;
        if (signalBox.getSender() == null) {
            isEnabled = (meta & 0x8) != 0;
            meta &= 0x7;
        } else {
            isEnabled = signalBox.senderIsPowered();
            if (isEnabled)
                meta |= 0x8;
            else
                meta &= 0x7;
        }
        signalBox.isEnabled = isEnabled;
        if (signalBox.inverterEnabled)
            isEnabled = !isEnabled;
        if (!signalBox.tryControlFirst(isEnabled)) {
            if (!signalBox.tryControlSecond(isEnabled)) {
                if (!signalBox.setTargetSender(isEnabled)) {
                    if (!signalBox.setTargetGetter(isEnabled)) {
                        if (signalBox.getTarget() != null) {
                            TileEntity tileEntity = signalBox.getTarget();
                            if (tileEntity instanceof TileEntityReceiver) {
                                if (tileEntity instanceof IPassive) {
                                    signalBox.controlTarget(isEnabled);
                                }
                            } else {
                                signalBox.controlTarget(isEnabled);
                            }
                        }
                    }
                }
            }
        }
        if (old != meta || signalBox.prevInverterEnabled != signalBox.inverterEnabled) {
            signalBox.prevInverterEnabled = signalBox.inverterEnabled;
            world.markBlockForUpdate(x, y, z);
            world.setBlockMetadataWithNotify(x, y, z, meta, 3);
        }
        world.scheduleBlockUpdate(x, y, z, this, 1);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPassive(org.thewdj.telecom.IPassive) TileEntityReceiver(club.nsdn.nyasamatelecom.api.tileentity.TileEntityReceiver)

Aggregations

TileEntityReceiver (club.nsdn.nyasamatelecom.api.tileentity.TileEntityReceiver)1 TileEntity (net.minecraft.tileentity.TileEntity)1 IPassive (org.thewdj.telecom.IPassive)1